function clearText(cond)
{
	if(cond == 1)
		document.frmLogin.txtUID.value	= '';
	
	if(cond == 2)
		document.frmLogin.txtPWD.value	= '';
}

function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}

function checkUKTelephone (telephoneNumber) 
{
	  // Convert into a string and check that we were provided with something
	  var telnum = telephoneNumber + " ";
	  if (telnum.length == 1)  {
		 telNumberErrorNo = 1;
		 return false
	  }
	  telnum.length = telnum.length - 1;
	  
	  // Don't allow country codes to be included (assumes a leading "+")
	  var exp = /^(\+)[\s]*(.*)$/;
	  if (exp.test(telnum) == true) {
		 telNumberErrorNo = 2;
		 return false;
	  }
	  
	  // Remove spaces from the telephone number to help validation
	  while (telnum.indexOf(" ")!= -1)  {
		telnum = telnum.slice (0,telnum.indexOf(" ")) + telnum.slice (telnum.indexOf(" ")+1)
	  }
	  
	  // Remove hyphens from the telephone number to help validation
	  while (telnum.indexOf("-")!= -1)  {
		telnum = telnum.slice (0,telnum.indexOf("-")) + telnum.slice (telnum.indexOf("-")+1)
	  }  
	  
	  // Now check that all the characters are digits
	  exp = /^[0-9]{10,11}$/
	  if (exp.test(telnum) != true) {
		 telNumberErrorNo = 3;
		 return false;
	  }
	  
	  // Telephone number seems to be valid - return the stripped telehone number  
	  return telnum;
}

function checkPostCode (toCheck) {

  // Permitted letters depend upon their position in the postcode.
  var alpha1 = "[abcdefghijklmnoprstuwyz]";                       // Character 1
  var alpha2 = "[abcdefghklmnopqrstuvwxy]";                       // Character 2
  var alpha3 = "[abcdefghjkstuw]";                                // Character 3
  var alpha4 = "[abehmnprvwxy]";                                  // Character 4
  var alpha5 = "[abdefghjlnpqrstuwxyz]";                          // Character 5
  

  // Array holds the regular expressions for the valid postcodes
  var pcexp = new Array ();

  // Expression for postcodes: AN NAA, ANN NAA, AAN NAA, and AANN NAA
  pcexp.push (new RegExp ("^(" + alpha1 + "{1}" + alpha2 + "?[0-9]{1,2})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));
  
  // Expression for postcodes: ANA NAA
  pcexp.push (new RegExp ("^(" + alpha1 + "{1}[0-9]{1}" + alpha3 + "{1})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));

  // Expression for postcodes: AANA  NAA
  pcexp.push (new RegExp ("^(" + alpha1 + "{1}" + alpha2 + "?[0-9]{1}" + alpha4 +"{1})(\\s*)([0-9]{1}" + alpha5 + "{2})$","i"));
  
  // Exception for the special postcode GIR 0AA
  pcexp.push (/^(GIR)(\s*)(0AA)$/i);
  
  // Standard BFPO numbers
  pcexp.push (/^(bfpo)(\s*)([0-9]{1,4})$/i);
  
  // c/o BFPO numbers
  pcexp.push (/^(bfpo)(\s*)(c\/o\s*[0-9]{1,3})$/i);

  // Load up the string to check
  var postCode = toCheck;

  // Assume we're not going to find a valid postcode
  var valid = false;
  
  // Check the string against the types of post codes
  for ( var i=0; i<pcexp.length; i++) {
    if (pcexp[i].test(postCode)) {
    
      // The post code is valid - split the post code into component parts
      pcexp[i].exec(postCode);
      
      // Copy it back into the original string, converting it to uppercase and
      // inserting a space between the inward and outward codes
      postCode = RegExp.$1.toUpperCase() + " " + RegExp.$3.toUpperCase();
      
      // If it is a BFPO c/o type postcode, tidy up the "c/o" part
      postCode = postCode.replace (/C\/O\s*/,"c/o ");
      
      // Load new postcode back into the form element
      valid = true;
      
      // Remember that we have found that the code is valid and break from loop
      break;
    }
  }
  
  // Return with either the reformatted valid postcode or the original invalid 
  // postcode
  if (valid)
   { 
  	 return   postCode;
     } 
  else return false;
  
}


function Chkfrm(frm)
{
	var telNumberErrorNo = 0;
	var telNumberErrors = new Array ();
	telNumberErrors[0] = "Valid UK telephone number";
	telNumberErrors[1] = "Telephone number not provided";
	telNumberErrors[2] = "UK telephone number without the country code, please";
	telNumberErrors[3] = "UK telephone numbers should contain 10 or 11 digits";
	telNumberErrors[4] = "The telephone number should start with a 0";
	telNumberErrors[5] = "The telephone number is either invalid or inappropriate";

	// ----------------------- Name -------------------------------
	if (trim(frm.txtName.value)=='')
		 {
			  alert('Please enter Your Name.');
			  frm.txtName.focus();
			  return false;  
		 } 
		  		  
	if (trim(frm.txtName.value)!="")
		 {
			  if (!isNaN(frm.txtName.value))
			  {
				   alert('Use alphabets only.');
				   frm.txtName.select();
				   return false;  
			  }  
		 }  

	// --------------------- Email Address ------------------------
 	if (trim(frm.txtEmailId.value) == '')
	  {
		  alert('Please enter Email id.');
		  frm.txtEmailId.focus();
		  return false;  
	   }  
	   
	 if(trim(frm.txtEmailId.value).indexOf('@')==-1 || trim(frm.txtEmailId.value).indexOf('.')==-1 || trim(frm.txtEmailId.value).indexOf('@')!=trim(frm.txtEmailId.value).lastIndexOf('@') || trim(frm.txtEmailId.value).indexOf('@')>trim(frm.txtEmailId.value).lastIndexOf('.') || trim(frm.txtEmailId.value).length-trim(frm.txtEmailId.value).lastIndexOf('.')<=1)
	  {
		  alert('Your Email ID appears to be invalid, please re-enter');
		  frm.txtEmailId.select();
		  return false;
	  }
	  		 		 
	//-----------------------Contact Telephone ---------------------
		if(trim(frm.txtContact.value) == '')
		{
			  alert('Please enter the Contact Telephone Number.');
			  frm.txtContact.focus();
			  return false;  		 
		}
		else
		{
			if (!checkUKTelephone (trim(frm.txtContact.value))) 
			{
				 alert (telNumberErrors[telNumberErrorNo]);
				 frm.txtContact.select();
				 return false;  
			}
			
			if((frm.txtContact.value.length) < 9 )
			{
				  alert('Please enter the Contact Telephone Number more than 9 Digits Only.');
				  frm.txtContact.select();
				  return false; 
			}
		}		

	// ------------------------- Name of Block -------------------
		if(trim(frm.txtBlockName.value) == "")
		{
			alert("Please enter block name");
			frm.txtBlockName.focus();
			return false;
		}	
		
	// ------------------------- Address for Sale ------------------
     if (trim(frm.txtLine1.value) =='')
		 {
			  alert('Please enter Address Line 1.');
			  frm.txtLine1.focus();
			  return false;  
		 } 	
		 
	// ------------------------ Town ------------------------------
	if (trim(frm.txtTown.value)=='')
		 {
			  alert('Please enter Town or city of Property to sell.');
			  frm.txtTown.focus();
			  return false;  
		 } 		 
	// ------------------------- Postal Code ------------------
     if (trim(frm.txtPostcode.value)=='')
	 {
		  alert('Please enter Postcode.');
		  frm.txtPostcode.focus();
		  return false;  
	 } 
	else
	{
	    if (!checkPostCode(trim(frm.txtPostcode.value))) 
		{
		   	alert ("Postcode has invalid format") ;
			return false;  
		} 
	}	
	
	// ---------- Management company name --------------------------
	if(trim(frm.txtCompName.value) == "")
	{
		alert("Please enter management company name");
		frm.txtCompName.focus();
		return false;
	}
	
	// ---------- Company Registration number ----------------------
	if(trim(frm.txtRegNumber.value) == "")
	{
		alert("Please enter Company Registartion number");
		frm.txtRegNumber.focus();
		return false;
	}
	else
	{
		if(isNaN(frm.txtRegNumber.value))
		{
			alert('Please enter only digits in company registration number.');
		   	frm.txtRegNumber.select();
		   	return false;  
		}
	}
	
	// ---------- Number of Units ----------------------------------
	if(trim(frm.txtTotalUnits.value) == "")
	{
		alert("Please enter Total number of Units");
		frm.txtTotalUnits.focus();
		return false;
	}
	else
	{
		if(isNaN(frm.txtTotalUnits.value))
		{
		   alert('Please enter digits only.');
		   frm.txtTotalUnits.select();
		   return false;  
		} 
		else
		{
			if((trim(frm.txtTotalUnits.value) > 100) || (trim(frm.txtTotalUnits.value) <= 0))
			{
				alert("Total number of units should be between 0 and 100");
				frm.txtTotalUnits.select();
			   	return false;  
			}
		}
	} 
	
	// ---------- Service required ---------------------------------
	if(frm.selService.value == "")
	{
		alert("Please select which service you required.");
		frm.selService.focus();
		return false;
	}
	
	return true;
	
} 
function chkOwner(unitObj)
{
	var unitIds	= document.frmBlock['chkUnit[]'];
	
	for(i=0;i<unitIds.length;i++)
	{
		if(unitIds[i].value != unitObj.value)
			unitIds[i].checked = false;
	}
}

function chkFee(serviceFee)
{
	var feeArray	= serviceFee.split(",");
	document.getElementById("ServiceFee").innerHTML	= feeArray[1];
}	

function CheckIsIE() 
{ 
	if (navigator.appName.toUpperCase() == 'MICROSOFT INTERNET EXPLORER') 
	{ 
		return true;
	} 
	else 
	{ 
		return false; 
	} 
} 

function mycenteralpopwinVHS(fname,width,height)
{
	var file
	var sWidth	= 200
	var sHeight = 200
	
	if(width.length > 0)
	{
		sWidth = width;
	}
	else
	{
		width =100;
	}
	
	if(height.length > 0)
	{
		sHeight = height;
	}
	else
	{
		height =100;
	}
	
	file = fname
	file =file	
	
	var wintop  =window.screen.availHeight;
	var winleft =window.screen.availWidth;
	wintop  =(wintop/2) -(height/2)
	winleft =(winleft/2) -(width/2)
	//wintop  = 0
	//winleft = 0
	
	if ( sWidth > window.screen.availWidth )
		{ sWidth = window.screen.availWidth; }
	if (sHeight > window.screen.availHeight )
		{ sHeight = window.screen.availHeight; }
	if ( parseInt(sWidth) < width )
		{ sWidth = width; }
	if ( parseInt(sHeight) < height )
		{ sHeight = height; }
	
	if ( navigator.appName == "Microsoft Internet Explorer" )
		{ window.open(file, "_blank", "status=no, addressbar=no, scrollbars=yes, toolbar=no, resizable=yes, location=no, menubar=no, top=" + wintop + ", left= "+ winleft +", height=" + sHeight + ", width=" + sWidth); 
		}
	if ( navigator.appName == "Netscape" ) 
		{ 
		window.open(file,"_blank","scrollbars=yes,alwaysRaised,dependant,innerheight=" + sHeight + ",innerwidth=" + sWidth); 		 
		//window.open(file,"_blank","alwaysRaised,dependant,scrollbars=yes,innerheight=" + sHeight + ",innerwidth=" + sWidth); 
		}
}

function PrintThisPage() 
{ 
	mycenteralpopwinVHS('termsofservice.php','600','600');
	
	/*if (CheckIsIE() == true) 
	{ 
		document.ifWorkspace.focus(); 
		document.ifWorkspace.print(); 
	} 
	else 
	{ 
		mycenteralpopwinVHS('termsofservicesprint.php','500','600');
	} */
} 

function loginValidations(frm)
{
	if(!(frm.chkAcceptTerms.checked))
	{
		alert("Please accept Terms of Services to proceed further.");
		frm.chkAcceptTerms.focus();
		return false;
	}
	
	if(trim(frm.txtNewPwd.value) == "")
	{
		alert("Please enter new password value");
		frm.txtNewPwd.focus();
		return false;
	}
	
	if(trim(frm.txtConfirmPwd.value) == "")
	{
		alert("Please enter confirm password value");
		frm.txtConfirmPwd.focus();
		return false;
	}
	
	if((trim(frm.txtNewPwd.value) != "") && (trim(frm.txtConfirmPwd.value) != ""))
	{
		var newpwd 		= trim(frm.txtNewPwd.value);
		var confrimPwd	= trim(frm.txtConfirmPwd.value);

		if(!isTheSame(newpwd,confrimPwd)) 
		{
			alert("Both password should be same");
			return false;		
		} 
	}
	
	return true;
}

/*
 * Function added by SR to validate Call Me form created in the Header.
 */
function chkCallBackFrm(frm)
{
	var telNumberErrorNo = 0;
	var telNumberErrors = new Array ();
	telNumberErrors[0] = "Invalid UK telephone number";
	telNumberErrors[1] = "Telephone number not provided";
	telNumberErrors[2] = "UK telephone number without the country code, please";
	telNumberErrors[3] = "UK telephone numbers should contain 10 or 11 digits";
	telNumberErrors[4] = "The telephone number should start with a 0";
	telNumberErrors[5] = "The telephone number is either invalid or inappropriate";
        // ----------------------- Name -------------------------------
	if (trim(frm.txtCallerName.value)=='')
		 {
			  alert('Please enter Requesting Person Name.');
			  frm.txtCallerName.focus();
			  return false;
		 }

	if (trim(frm.txtCallerName.value)!='')
		 {
			  if (!isNaN(frm.txtCallerName.value))
			  {
				   alert('Use alphabets only.');
				   frm.txtCallerName.select();
				   return false;
			  }
		 }

	//-----------------------Contact Telephone ---------------------
		if(trim(frm.txtCallerPhone.value) == '')
		{
			  alert('Please enter the Telephone Number.');
			  frm.txtCallerPhone.focus();
			  return false;
		}
		else
		{
			if (!checkUKTelephone (trim(frm.txtCallerPhone.value)))
			{
				 alert (telNumberErrors[telNumberErrorNo]);
				 frm.txtCallerPhone.select();
				 return false;
			}

			if((frm.txtCallerPhone.value.length) < 9 )
			{
				  alert('Please enter the Telephone Number more than 9 Digits Only.');
				  frm.txtCallerPhone.select();
				  return false;
			}
		}

	return true;

}
/*
 * End of Call Me validation function.
 */

function isTheSame(string1,string2)
{
	string1 = new RegExp(string1)
	return string1.test(string2);
}
