var xmlHttp;
function clearText()
{
	var frm = document.frm;
	frm.emailaddress.value = "";
}


function submitForm()
{
	var frm = document.frm;
	var emailaddr = frm.emailaddress.value;
	if ((emailaddr==null)||(emailaddr=="")){
		alert("Please enter your email address");
		return false;
	}
	if (echeck(emailaddr)==false){
		frm.emailaddress.value="";
		return false;
	}
	return true;
}
function submitCreateForm()
{
	var frm = document.createfrm;
	var emailaddr = frm.cb_email.value;
	
	if(frm.cb_name.value == "")
	{
		alert("Please enter your name");
		return false;
	}
	else if (emailaddr!="")
	{
		if (echeck(emailaddr)==false)
		{
			alert("Please enter a valid email address");
			return false;
		}
	}
	else if(frm.cb_contact1.value == null || frm.cb_contact1.value == "")
	{
		alert("Please enter a contact number");
		return false;
	}
	else if(Validate_String(frm.cb_contact1.value) == false)
	{
		alert("Please enter a valid contact number. (Eg: 91234567)");
		return false;
	}
	else if(frm.cb_password1.value == null || frm.cb_password1.value == "" || frm.cb_password1.value.length < 6)
	{
		alert("Please enter password. Minimum 6 characters.");
		return false;
	}
	else if(frm.cb_password2.value == null || frm.cb_password2.value == "")
	{
		alert("Please re-enter password to confirm.");
		return false;
	}
	else if(frm.cb_password1.value != frm.cb_password2.value)
	{
		alert("Password different. Please try again.");
		return false;
	}

	else if(frm.cb_company.value == null || frm.cb_company.value == "")
	{
		alert("Please enter a valid real estate company name.");
		return false;
	}
	else
		return true;
}
function submitCreateLeadForm()
{
	var frm = document.createleadfrm;
	var emailaddr = frm.cb_email.value;
	
	if ((emailaddr!=null)||(emailaddr!="")){
		if (echeck(emailaddr)==false){
			alert("Please enter a valid email address");
			return false;
		}
	}
	else if(frm.cb_contact1.value == null || frm.cb_contact1.value == "")
	{
		alert("Please enter a contact number");
		return false;
	}
	else if(Validate_String(frm.cb_contact1.value) == false)
	{
		alert("Please enter a valid contact number. (Eg: 91234567)");
		return false;
	}
	else
		return true;
}
function submitMobileForm()
{
	var frm = document.mobilefrm;
	if(frm.cb_contact1.value == null || frm.cb_contact1.value == "")
	{
		alert("Please enter a contact number");
		return false;
	}
	else if(frm.cb_contact1.value.length < 8)
	{
		alert("Please enter a valid contact number. (Minimum 8 digits)");
		return false;
	}
	else if(Validate_String(frm.cb_contact1.value) == false)
	{
		alert("Please enter a valid contact number. (Eg: 91234567)");
		return false;
	}
	else
		return true;
}
function submitCreateCMAForm()
{
	var frm = document.createcmafrm;

	if(frm.cb_name.value == null || frm.cb_name.value == "")
	{
		alert("Please specify your name.");
		frm.cb_name.focus();
		return false;
	}
	else if(frm.cb_contact1.value == null || frm.cb_contact1.value == "")
	{
		alert("Please enter a contact number.");
		frm.cb_contact1.focus();
		return false;
	}
	else if(Validate_String(frm.cb_contact1.value) == false)
	{
		alert("Please enter a valid contact number. (Eg: 91234567)");
		return false;
	}
	else if(frm.cust_name.value == "" || frm.cust_name.value.length <= 0)
	{
		alert("Please specify your customer's name.");
		frm.cust_name.focus();
		return false;
	}
	else if (frm.cust_postal.value.length > 0 && Validate_String(frm.cust_postal.value) == false)
	{
		alert("Please enter a valid Postal Code. Eg: 123456 (No Spacing)");
		frm.cust_postal.focus();
		return false;
	}
	else if (frm.areafrom.value.length > 0 && Validate_String(frm.areafrom.value) == false)
	{
		alert("Please enter a valid area sqm. Eg: 123 (No Spacing)");
		frm.areafrom.focus();
		return false;
	}
	else if (frm.areato.value.length > 0 && Validate_String(frm.areato.value) == false)
	{
		alert("Please enter a valid area in sqm. Eg: 123 (No Spacing)");
		frm.areato.focus();
		return false;
	}
	else if (frm.blockfrom.value.length > 0 && Validate_String(frm.blockfrom.value) == false)
	{
		alert("Please enter a valid block. Eg: 123 (No Spacing)");
		frm.blockfrom.focus();
		return false;
	}
	else if (frm.blockto.value.length > 0 && Validate_String(frm.blockto.value) == false)
	{
		alert("Please enter a valid block. Eg: 123 (No Spacing)");
		frm.blockto.focus();
		return false;
	}
	else if (frm.pricefrom.value.length > 0 && Validate_String(frm.pricefrom.value) == false)
	{
		alert("Please enter a valid Price. Eg: 12345 or 12345.67 (No Spacing)");
		frm.pricefrom.focus();
		return false;
	}
	else if (frm.priceto.value.length > 0 && Validate_String(frm.priceto.value) == false)
	{
		alert("Please enter a valid Price. Eg: 12345 or 12345.67 (No Spacing)");
		frm.priceto.focus();
		return false;
	}
	else
		return true;
}

function submitCreateCMAPrivateForm()
{
	var frm = document.createcmaprivatefrm;

	if(frm.cb_name.value == null || frm.cb_name.value == "")
	{
		alert("Please specify your name.");
		frm.cb_name.focus();
		return false;
	}
	else if(frm.cb_contact1.value == null || frm.cb_contact1.value == "")
	{
		alert("Please enter a contact number.");
		frm.cb_contact1.focus();
		return false;
	}
	else if(Validate_String(frm.cb_contact1.value) == false)
	{
		alert("Please enter a valid contact number. (Eg: 91234567)");
		return false;
	}
	else if(frm.cust_name.value == "" || frm.cust_name.value.length <= 0)
	{
		alert("Please specify your customer's name.");
		frm.cust_name.focus();
		return false;
	}
	else if (frm.cust_postal.value.length > 0 && Validate_String(frm.cust_postal.value) == false)
	{
		alert("Please enter a valid Postal Code. Eg: 123456 (No Spacing)");
		frm.cust_postal.focus();
		return false;
	}
	else if (frm.areafrom.value.length > 0 && Validate_String(frm.areafrom.value) == false)
	{
		alert("Please enter a valid area sqm. Eg: 123 (No Spacing)");
		frm.areafrom.focus();
		return false;
	}
	else if (frm.areato.value.length > 0 && Validate_String(frm.areato.value) == false)
	{
		alert("Please enter a valid area in sqm. Eg: 123 (No Spacing)");
		frm.areato.focus();
		return false;
	}
	else if (frm.pricefrom.value.length > 0 && Validate_String(frm.pricefrom.value) == false)
	{
		alert("Please enter a valid Price. Eg: 12345 or 12345.67 (No Spacing)");
		frm.pricefrom.focus();
		return false;
	}
	else if (frm.priceto.value.length > 0 && Validate_String(frm.priceto.value) == false)
	{
		alert("Please enter a valid Price. Eg: 12345 or 12345.67 (No Spacing)");
		frm.priceto.focus();
		return false;
	}
	else
		return true;
}
function echeck(str) 
{

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid email address");
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid email address");
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid email address");
		    return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid email address");
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid email address");
		    return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid email address");
		    return false;
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid email address");
		    return false;
		 }
}

function Validate_String(string, return_invalid_chars) {
  valid_chars = '1234567890';
  invalid_chars = '';
  if(string == null || string == '')
     return(true);

  //For every character on the string.   
  for(index = 0; index < string.length; index++) {
    char = string.substr(index, 1);                        
     
    //Is it a valid character?
    if(valid_chars.indexOf(char) == -1) {
      //If not, is it already on the list of invalid characters?
      if(invalid_chars.indexOf(char) == -1) {
        //If it's not, add it.
        if(invalid_chars == '')
          invalid_chars += char;
        else
          invalid_chars += ', ' + char;
      }
    }
  }
            
  //If the string does not contain invalid characters, the function will return true.
  //If it does, it will either return false or a list of the invalid characters used
  //in the string, depending on the value of the second parameter.
  if(return_invalid_chars == true && invalid_chars != '') {
    last_comma = invalid_chars.lastIndexOf(',');
    if(last_comma != -1)
      invalid_chars = invalid_chars.substr(0, $last_comma) + 
      ' and ' + invalid_chars.substr(last_comma + 1, invalid_chars.length);
    return(invalid_chars);
    }
  else
    return(invalid_chars == ''); 
}

function stateChanged() 
{ 
if (xmlHttp.readyState==4)
{ 
document.getElementById("main").innerHTML=xmlHttp.responseText;
}
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}