/*var client_url="http://"+location.host+"/valleyrealty.com";go_to_page(1);return false;*/


// For save property feature
if(location.host == "localhost")
	var client_url="http://"+location.host+"/projects/tenace";
else if(location.host == "dev03.bspsrv.net" || location.host == "dev03.bspsrv.net")
	var client_url="http://"+location.host+"/c21tenace.com";
else
	var client_url="http://"+location.host;

/***********************************/
var block_ui_content='<div id="mains" align="middle"><h1><img src="images/busy.gif" align="absmiddle" class="processing_request" />Processing your request...</h1></div>';

function clear_search_box(val)
{
	if (val=="City or State or ZIP")
	{
		document.getElementById('qry2').value="";
	}
}

function reset_search_form()
{
	document.search_form.reset();
	remove_options(0);
}

function contactus_validation(lang){
	
	var firstname = trim(document.frmContactus.first_name.value);
	var last_name  = trim(document.frmContactus.last_name.value);
	var email     = trim(document.frmContactus.email.value);
	var phcountry=trim(document.frmContactus.tel1.value);
	var phstate=trim(document.frmContactus.tel2.value);
	var phonenumber=trim(document.frmContactus.tel3.value);
	var comments=trim(document.frmContactus.comments.value);
	var captcha = trim(document.frmContactus.txtFCaptcha.value);
	
//alert(contactu);
	if(firstname == "")
	{
		if(lang == 'spanish')
			alert("Proporcione por favor el nombre.");
		else
			alert("Please provide the First Name.");
		
		document.frmContactus.first_name.focus();
		return false;
	}
	else if(!isValidName(firstname))
	{
		if(lang == 'spanish')
			alert("Nombre inválido.");
		else
			alert("Invalid First Name.");
			
		document.frmContactus.first_name.focus();
		return false;
	}
	else if(last_name =="")
	{
		
		if(lang == 'spanish')
			alert("Proporcione por favor el apellido.");
		else
			alert("Please provide the Last Name.");
			
		document.frmContactus.last_name.focus();
		return false;
	}
	else if(!isValidName(last_name))
	{
		if(lang == 'spanish')
			alert("Apellido inv&aacute;lido.");
		else
			alert("Invalid Last Name.");
		document.frmContactus.last_name.focus();
		return false;
	}
	else if(email =="")
	{
		if(lang == 'spanish')
			alert("Proporcione por favor un email address v&aacute;lido.");
		else
			alert("Please provide a valid Email Address.");
		document.frmContactus.email.focus();
		return false;
	}
	else if(!isValidEmail(email))
	{
		if(lang == 'spanish')
			alert("Email address inv&aacute;lido.");
		else
			alert("Invalid Email Address.");
		document.frmContactus.email.focus();
		return false;
	}
	else if(phcountry =="")
	{
		if(lang == 'spanish')
			alert("Incorpore por favor el n&uacute;mero de teléfono.");
		else
			alert("Please enter the Phone Number.");
		document.frmContactus.tel1.focus();
		return false;
	}
	else if(phstate =="")
	{
		if(lang == 'spanish')
			alert("Incorpore por favor el n&uacute;mero de tel&eacute;fono.");
		else
			alert("Please enter the Phone Number.");
		document.frmContactus.tel2.focus();
		return false;
	}
	else if(phonenumber =="")
	{
		if(lang == 'spanish')
			alert("Incorpore por favor el número de tel&eacute;fono.");
		else
			alert("Please enter the Phone Number.");
		document.frmContactus.tel3.focus();
		return false;
	}
	
	else if (phcountry.length !=3)
	{
		if(lang == 'spanish')
			alert("El n&uacute;mero de teléfono debe ser 3 dígitos.");
		else
			alert("Phone Number should be 3 Digits.");
		document.frmContactus.tel1.focus();
		return false;
	}
	else if (phstate.length !=3)
	{
		if(lang == 'spanish')
			alert("El n&uacute;mero de teléfono debe ser 3 dígitos.");
		else
			alert("Phone Number should be 3 Digits.");
		document.frmContactus.tel2.focus();
		return false;
	}	
	else if (phonenumber.length !=4)
	{
		if(lang == 'spanish')
			alert("El n&uacute;mero de teléfono debe ser 4 dígitos.");
		else
			alert("Phone Number should be 4 Digits.");
		document.frmContactus.tel3.focus();
		return false;
	}
	
	else if(captcha =="")
	{
		if(lang == 'spanish')
			alert("Captcha es obligatoria.");
		else
			alert("Please Enter Security Code.");
		document.frmContactus.txtFCaptcha.focus();
		return false;
	}
	
	else
	{	
		//client_url="http://localhost/valleyrealty";
		//url = client_url+'/contact_agent_email.php';		
		//url="contact_agent_email.php";
		//Modalbox.show(url, {width: 500, params:Form.serialize('contact_agent')}); return false;
		
		strURL           = client_url + "/common_ajax.php";
		qstr             = 'p=contactus&first_name=' + escape(firstname) + '&last_name=' + escape(last_name) + '&email=' + escape(email) + '&tel1=' + escape(phcountry) + '&tel2=' + escape(phstate) + '&tel3=' + escape(phonenumber) + '&comments=' + escape(comments) + '&lang=' + escape(lang) + '&captcha=' + escape(captcha) ;
		
		var xmlHttpReq = false;
		var self = this;
		// Mozilla/Safari
		if (window.XMLHttpRequest) {
			self.xmlHttpReq = new XMLHttpRequest();
		}
		// IE
		else if (window.ActiveXObject) {
			self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
		}
		self.xmlHttpReq.open('POST', strURL, true);
		self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		self.xmlHttpReq.onreadystatechange = function() {
			if (self.xmlHttpReq.readyState == 4) {			
				alert(self.xmlHttpReq.responseText);
				if( (self.xmlHttpReq.responseText == "Su email se ha enviado con &eacute;xito. Conseguiremos en tacto con usted pronto.") || (self.xmlHttpReq.responseText == "Your email has been sent successfully. We will get in touch with you shortly.") )
				{
				document.frmContactus.first_name.value = '';
				document.frmContactus.last_name.value = '';
				document.frmContactus.email.value = '';
				document.frmContactus.tel1.value = '';
				document.frmContactus.tel2.value = '';
				document.frmContactus.tel3.value = '';
				document.frmContactus.comments.value = '';
				document.frmContactus.txtFCaptcha.value = '';	
				}
								
			}
		}	
		self.xmlHttpReq.send(qstr);
	}
	
	return false;
	
}

function go_to_page(page)
{
	/*qry1=document.search_form.qry.value;
	oid = document.search_form.oid.value
	if (oid=="")
		oid=document.pag_form.oid.value;
	if (qry1=="City or State or ZIP")
	{
		qry1="";
	}

	$j.blockUI(block_ui_content);
	$j.post("search.php",{pg: page, ajax:true, price_min:$j("#price_min").val(),price_max:$j("#price_max").val(),sb:$j("#sb").val(), beds:$j("#beds").val(), baths:$j("#baths").val(), sname:$j("#sname").val(), qry:qry1, oid:oid, mlsno:$j("#mlsno").val()},
    function(data)
    {	 
	 $j("#listing_contents").html(data);
	 load_tips();
    }    
    );
	$j().ajaxStop($j.unblockUI); */
	
	
	var qry1;
	if(document.getElementById('qry'))
		qry1 = "/"+document.getElementById('qry').value;
	if (qry1=="/City or State or ZIP")
	{
		qry1="";
	}
	
	if(document.getElementById('sb'))
		sbval = "/"+(document.getElementById('sb').value).replace(" ","+");
	else
		sbval = "/"+"price+desc";
		
	if(document.getElementById('price_min'))
		price_min = "/"+document.getElementById('price_min').value;
	else
		price_min = "/0";
		
	if(document.getElementById('price_max'))
		price_max = "/"+document.getElementById('price_max').value;
	else
		price_max = "/0";
		
	if(document.getElementById('beds'))
		beds = "/"+ document.getElementById('beds').value;
	else
		beds = "/0";
		
	if(document.getElementById('baths'))
		fbaths = "/"+document.getElementById('baths').value;
	else
		fbaths = "/0";
		
		
	oid  = document.search_form.oid.value;	
	if (oid=="")
		oid=document.pag_form.oid.value;
		querystring = sbval+price_min+price_max+beds+fbaths+qry1;
		/*alert("search/"+page+querystring);
		return false;*/
	window.location.href="search/"+page+querystring;
	
	
	
}




function pageSubmit(redirect, page, saveYN){
	
	if(document.getElementById('actionPage')){
		redirect = document.getElementById('actionPage').value;
	}
	
	if(saveYN == 1)
		document.getElementById('saveYN').value = 1;		
	else
		document.getElementById('saveYN').value = 0;		
	
	$j.blockUI(block_ui_content);
	
	qry = document.search_form.qry.value;
	
	if (qry == "City or State or ZIP"){
		document.search_form.qry.value = "";
	}
	
	if(page == 'listings'){
		if(redirect == "mapsearch.php"){	
			if(document.getElementById('hidSaveSearch')){			
				if(trim(document.search_form.sname.value) != ''){			
					document.getElementById('hidSaveSearch').value = 1;				
				}			
			}		
		}
		
		var element_sb = document.getElementsByName('sb');
		
		for(i=0;i<element_sb.length;i++)
		{
			if(element_sb[i]){
				element_sb[i].value = 'price desc';
			}
		}
		
	}
	
	if(redirect == ""){
		var redirect = "search.php";
	}
	
	redirect = client_url + '/' + redirect;
	
	document.search_form.action = redirect;		
		
	document.search_form.submit();
	
	$j().ajaxStop($j.unblockUI);
	
}

function go_to_map_page(page)
{
	
	/*$j.blockUI(block_ui_content);
	
	qry1=document.search_form.qry.value;
		
	if (qry1=="City or State or ZIP"){
		document.search_form.qry.value = "";
	}
	
	document.search_form.sb.value = document.pag_form.sb.value;
	
	document.getElementById('pg').value = page;
	
	document.search_form.submit();	
	
	$j().ajaxStop($j.unblockUI);*/
	
	var qry1;
	if(document.getElementById('qry'))
		qry1 = "/"+document.getElementById('qry').value;
	if (qry1=="/City or State or ZIP")
	{
		qry1="";
	}
	
	if(document.getElementById('sb'))
		sbval = "/"+(document.getElementById('sb').value).replace(" ","+");
	else
		sbval = "/"+"price+desc";
		
	if(document.getElementById('price_min'))
		price_min = "/"+document.getElementById('price_min').value;
	else
		price_min = "/0";
		
	if(document.getElementById('price_max'))
		price_max = "/"+document.getElementById('price_max').value;
	else
		price_max = "/0";
		
	if(document.getElementById('beds'))
		beds = "/"+ document.getElementById('beds').value;
	else
		beds = "/0";
		
	if(document.getElementById('baths'))
		fbaths = "/"+document.getElementById('baths').value;
	else
		fbaths = "/0";
		
		
	oid  = document.search_form.oid.value;	
	if (oid=="")
		oid=document.pag_form.oid.value;
		querystring = sbval+price_min+price_max+beds+fbaths+qry1;
		/*alert("mapsearch/"+page+querystring);
		return false;*/
	window.location.href="mapsearch/"+page+querystring;
	
	
}

function go_to_featured_page(page)
{
	$j.blockUI(block_ui_content);
	$j.post("view_featured_property.php",{pg:page, ajax:true, price_range:$j("#featured_property_price").val(), price_end:$j("#featured_property_price_end").val(), new_construction:$j("#featured_property_underconstruction").val()},
	//$j.post("search.php",{pg: page, ajax:true, price_min:$j("#price_min").val(),price_max:$j("#price_max").val(),sb:$j("#sb").val(), beds:$j("#beds").val(), baths:$j("#baths").val(), sname:$j("#sname").val(), qry:qry1, oid:oid},
    function(data)
    {	 
		 $j("#listing_contents").html(data);
	}    
    );
	$j().ajaxStop($j.unblockUI); 
}

function getResultsCount(page)
{
	qry1=document.search_form.qry.value;
	oid = document.search_form.oid.value
	if (oid=="")
	{
		if(document.pag_form != null)
			oid=document.pag_form.oid.value;
	}
	if (qry1=="City or State or ZIP")
	{
		qry1="";
	}
	var url = "search_inc.php?pg="+page+"&ajax=true&price_min="+$j("#price_min").val()+"&price_max="+$j("#price_max").val()+"&sb="+$j("#sb").val()+"&beds="+$j("#beds").val()+"&baths="+$j("#baths").val()+"&pagename="+$j("#pagename").val()+"&qry="+qry1+"&oid="+oid;
	$j.blockUI(block_ui_content);
	$j.ajax({
			  type: "POST",
			  url: url,
			  success: function(msg){
				  $j().ajaxStop($j.unblockUI);
					  document.getElementById('ResultsCount').innerHTML=msg ;
			  }
		   });
	
	
	/*$j.post("search_inc.php",{pg: page, ajax:true, price_min:$j("#price_min").val(),price_max:$j("#price_max").val(),sb:$j("#sb").val(), beds:$j("#beds").val(), baths:$j("#baths").val(), sname:$j("#sname").val(), qry:qry1, oid:oid},
    function(data)
    {	 
	 $j("#ResultsCount").html(data);
    }    
    );
	$j().ajaxStop($j.unblockUI); */
	 
	/* START - COMMENTED BY SATHIYAN ON 07-11-2008 (Result count for Listing) */
	/*go_to_page(1);
	document.search_form.submit();*/
	/* END - COMMENTED BY SATHIYAN ON 07-11-2008 (Result count for Listing) */
}

function resetChangeButton(){
	document.getElementById('spnSearchLabel').innerHTML = "Search By : ";
}

function searchImageChange(){

	if(document.getElementById('sname').value==''){
		document.getElementById('spnSearchLabel').innerHTML = "Search By : ";
	}else{
		document.getElementById('spnSearchLabel').innerHTML = "Save and Search By : ";
	}

}



function remove_options(value)
{
	var price = new Array();
	var txt_price = new Array();
	
	price[0]="0";
	price[1]="10000";
	price[2]="25000";
	price[3]="50000";
	price[4]="75000";
	price[5]="100000";
	price[6]="125000";
	price[7]="150000";
	price[8]="175000";
	price[9]="200000";
	price[10]="225000";
	price[11]="250000";
	price[12]="275000";
	price[13]="300000";
	price[14]="350000";
	price[15]="400000";
	price[16]="450000";
	price[17]="500000";
	price[18]="750000";
	price[19]="1000000";
	price[20]="1250000";
	price[21]="1500000";
	price[22]="1750000";
	price[23]="2000000";
	price[24]="3000000";
	price[25]="4000000";
	price[26]="5000000";
	price[27]="10000000";

	txt_price[0]="max";
	txt_price[1]="$10k";
	txt_price[2]="$25k";
	txt_price[3]="$50k";
	txt_price[4]="$75k";
	txt_price[5]="$100k";
	txt_price[6]="$125k";
	txt_price[7]="$150k";
	txt_price[8]="$175k";
	txt_price[9]="$200k";
	txt_price[10]="$225k";
	txt_price[11]="$250k";
	txt_price[12]="$275k";
	txt_price[13]="$300k";
	txt_price[14]="$350k";
	txt_price[15]="$400k";
	txt_price[16]="$450k";
	txt_price[17]="$500k";
	txt_price[18]="$750k";
	txt_price[19]="$1M";
	txt_price[20]="$1.25M";
	txt_price[21]="$1.5M";
	txt_price[22]="$1.75M";
	txt_price[23]="$2M";
	txt_price[24]="$3M";
	txt_price[25]="$4M";
	txt_price[26]="$5M";
	txt_price[27]="$10M+";
	
	

	$j("#price_max").subOptions(); 
	for (x in price)
	{
		if (parseInt(price[x]) >= parseInt(value))
		{
		$j("#price_max").addOption(price[x],txt_price[x]);
		}
	}
}


function LTrim( value ) {
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
}
// Removes ending whitespaces
function RTrim( value ) {
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
}
// Removes leading and ending whitespaces
function trim( value ) {
	return LTrim(RTrim(value));
}
// validate the firstname , middle name , last name  , country, state ,city
function isValidName(val) { 
	 validRegExp = /^[a-zA-Z ]+$/i;
   // search email text for regular exp matches
   val = trim(val);
    if (val.search(validRegExp) == -1) {
      return false;
    } 
    return true; 	
}
function isValidEmail(strEmail){

//alert("in"+strEmail);
	if(strEmail.length<5){
	//alert("less");
	
		return false;
	}
  validRegExp = /^[\w\.-]+@[a-z,A-Z,0-9-]+[\.]{1}[a-zA-Z]{2,}[[\.]?[a-zA-Z]{0,2}$/i;
   // search email text for regular exp matches
   strEmail = trim(strEmail);
    if (strEmail.search(validRegExp) == -1) {
	//alert("fail");
      return false;
    } 
    return true; 
}
////////////////// to validete the form //////////
function validate()
{
var way_contact  = trim(document.contact_agent.way_of_contact.value);
var best_time  = trim(document.contact_agent.best_time_to_contact.value);
var firstname = trim(document.contact_agent.first_name.value);
var last_name  = trim(document.contact_agent.last_name.value);
var email     = trim(document.contact_agent.email.value);
var phcountry=trim(document.contact_agent.tel1.value);
var phstate=trim(document.contact_agent.tel2.value);
var phonenumber=trim(document.contact_agent.tel3.value);

//alert(contactu);
	if(way_contact == "0")
	{
		alert("Please select your Contact Preference.");
		document.contact_agent.way_of_contact.focus();
		return false;
	}
	else if(best_time =="0")
	{
		alert("Please select the Best Time to Contact you.");
		document.contact_agent.best_time_to_contact.focus();
		return false;
	}
	else if(firstname =="")
	{
		alert("Please provide the First Name.");
		document.contact_agent.first_name.focus();
		return false;
	}
	else if(!isValidName(firstname))
	{
		alert("Invalid First Name.");
		document.contact_agent.first_name.focus();
		return false;
	}
	else if(last_name =="")
	{
		alert("Please provide the Last Name.");
		document.contact_agent.last_name.focus();
		return false;
	}
	else if(!isValidName(last_name))
	{
		alert("Invalid Last Name.");
		document.contact_agent.last_name.focus();
		return false;
	}
	else if(email =="")
	{
		alert("Please provide a valid Email Address.");
		document.contact_agent.email.focus();
		return false;
	}
	else if(!isValidEmail(email))
	{
		alert("Invalid Email Address.");
		document.contact_agent.email.focus();
		return false;
	}
	else if(phcountry =="")
	{
		alert("Please enter the Phone Number.");
		document.contact_agent.tel1.focus();
		return false;
	}
	else if(phstate =="")
	{
		alert("Please enter the Phone Number.");
		document.contact_agent.tel2.focus();
		return false;
	}
	else if(phonenumber =="")
	{
		alert("Please enter the Phone Number.");
		document.contact_agent.tel3.focus();
		return false;
	}
	
	else if (phcountry.length !=3)
	{
		alert("Phone Number should be 3 Digits.");
		document.contact_agent.tel1.focus();
		return false;
	}
	else if (phstate.length !=3)
	{
		alert("Phone Number should be 3 Digits.");
		document.contact_agent.tel2.focus();
		return false;
	}	
	else if (phonenumber.length !=4)
	{
		alert("Phone Number should be 4 Digits.");
		document.contact_agent.tel3.focus();
		return false;
	}		
	else
	{	
		//client_url="http://localhost/valleyrealty";
		//url = client_url+'/contact_agent_email.php';		
		url="contact_agent_email.php";
		Modalbox.show(url, {width: 500, params:Form.serialize('contact_agent')}); return false;
	}
	
	
//Modalbox.show('contact_agent_email.php', {width: 500, params:Form.serialize('contact_agent') });
}



////////////////// to validete the mls form //////////
function mls_validate()
{
var way_contact  = trim(document.contact_agent.way_of_contact.value);
var best_time  = trim(document.contact_agent.best_time_to_contact.value);
var firstname = trim(document.contact_agent.first_name.value);
var last_name  = trim(document.contact_agent.last_name.value);
var email     = trim(document.contact_agent.email.value);
var phcountry=trim(document.contact_agent.tel1.value);
var phstate=trim(document.contact_agent.tel2.value);
var phonenumber=trim(document.contact_agent.tel3.value);
var validate_page = "";

if(document.getElementById("cpage"))
	validate_page = document.getElementById("cpage").value;
	

//alert(contactu);
	if(way_contact == "0")
	{
		alert("Please select your Contact Preference.");
		document.contact_agent.way_of_contact.focus();
		return false;
	}
	else if(best_time =="0")
	{
		alert("Please select the Best Time to Contact you.");
		document.contact_agent.best_time_to_contact.focus();
		return false;
	}
	else if(firstname =="")
	{
		alert("Please provide the First Name.");
		document.contact_agent.first_name.focus();
		return false;
	}
	else if(!isValidName(firstname))
	{
		alert("Invalid First Name.");
		document.contact_agent.first_name.focus();
		return false;
	}
	else if(last_name =="")
	{
		alert("Please provide the Last Name.");
		document.contact_agent.last_name.focus();
		return false;
	}
	else if(!isValidName(last_name))
	{
		alert("Invalid Last Name.");
		document.contact_agent.last_name.focus();
		return false;
	}
	else if(email =="")
	{
		alert("Please provide a valid Email Address.");
		document.contact_agent.email.focus();
		return false;
	}
	else if(!isValidEmail(email))
	{
		alert("Invalid Email Address.");
		document.contact_agent.email.focus();
		return false;
	}
	else if(phcountry =="")
	{
		alert("Please enter the Phone Number.");
		document.contact_agent.tel1.focus();
		return false;
	}
	else if(phstate =="")
	{
		alert("Please enter the Phone Number.");
		document.contact_agent.tel2.focus();
		return false;
	}
	else if(phonenumber =="")
	{
		alert("Please enter the Phone Number.");
		document.contact_agent.tel3.focus();
		return false;
	}
	
	else if (phcountry.length !=3)
	{
		alert("Phone Number should be 3 Digits.");
		document.contact_agent.tel1.focus();
		return false;
	}
	else if (phstate.length !=3)
	{
		alert("Phone Number should be 3 Digits.");
		document.contact_agent.tel2.focus();
		return false;
	}	
	else if (phonenumber.length !=4)
	{
		alert("Phone Number should be 4 Digits.");
		document.contact_agent.tel3.focus();
		return false;
	}		
	else
	{	
		//client_url="http://localhost/valleyrealty";
		//url = client_url+'/contact_agent_email.php';	
		if(validate_page == "mlsfd_contact_agent")
			url="mlsfd_contact_agent_email.php";
		else
			url="mls_contact_agent_email.php";
			
		Modalbox.show(url, {width: 500, params:Form.serialize('contact_agent')}); return false;
	}
	
	
//Modalbox.show('contact_agent_email.php', {width: 500, params:Form.serialize('contact_agent') });
}




function validate_featured_form()
{
var way_contact  = trim(document.featured_contact_agent.way_of_contact.value);
var best_time  = trim(document.featured_contact_agent.best_time_to_contact.value);
var firstname = trim(document.featured_contact_agent.first_name.value);
var last_name  = trim(document.featured_contact_agent.last_name.value);
var email     = trim(document.featured_contact_agent.email.value);
var phcountry=trim(document.featured_contact_agent.tel1.value);
var phstate=trim(document.featured_contact_agent.tel2.value);
var phonenumber=trim(document.featured_contact_agent.tel3.value);

//alert(contactu);
	if(way_contact == "0")
	{
		alert("Please select your Contact Preference.");
		document.featured_contact_agent.way_of_contact.focus();
		return false;
	}
	else if(best_time =="0")
	{
		alert("Please select the Best Time to Contact you.");
		document.featured_contact_agent.best_time_to_contact.focus();
		return false;
	}
	else if(firstname =="")
	{
		alert("Please provide the First Name.");
		document.featured_contact_agent.first_name.focus();
		return false;
	}
	else if(!isValidName(firstname))
	{
		alert("Invalid First Name.");
		document.featured_contact_agent.first_name.focus();
		return false;
	}
	else if(last_name =="")
	{
		alert("Please provide the Last Name.");
		document.featured_contact_agent.last_name.focus();
		return false;
	}
	else if(!isValidName(last_name))
	{
		alert("Invalid Last Name.");
		document.featured_contact_agent.last_name.focus();
		return false;
	}
	else if(email =="")
	{
		alert("Please provide a valid Email Address.");
		document.featured_contact_agent.email.focus();
		return false;
	}
	else if(!isValidEmail(email))
	{
		alert("Invalid Email Address.");
		document.featured_contact_agent.email.focus();
		return false;
	}
	else if(phcountry =="")
	{
		alert("Please enter the Phone Number.");
		document.featured_contact_agent.tel1.focus();
		return false;
	}
	else if(phstate =="")
	{
		alert("Please enter the Phone Number.");
		document.featured_contact_agent.tel2.focus();
		return false;
	}
	else if(phonenumber =="")
	{
		alert("Please enter the Phone Number.");
		document.featured_contact_agent.tel3.focus();
		return false;
	}
	
	else if (phcountry.length !=3)
	{
		alert("Phone Number should be 3 Digits.");
		document.featured_contact_agent.tel1.focus();
		return false;
	}
	else if (phstate.length !=3)
	{
		alert("Phone Number should be 3 Digits.");
		document.featured_contact_agent.tel2.focus();
		return false;
	}	
	else if (phonenumber.length !=4)
	{
		alert("Phone Number should be 4 Digits.");
		document.featured_contact_agent.tel3.focus();
		return false;
	}		
	else
	{		
		url="featured_contact_agent_email.php";
		Modalbox.show(url, {width: 500, params:Form.serialize('featured_contact_agent')}); return false;
	}
	
	
//Modalbox.show('contact_agent_email.php', {width: 500, params:Form.serialize('contact_agent') });
}
/*function check(obj, decimalPlaces, allowNegative,declength)
{
	if(	obj.value.length < declength)
	{
	 alert('f');
	 return false;
	}
	
}*/
function extractNumber(obj, decimalPlaces, allowNegative,declength)
{	
	var temp = obj.value;
	// avoid changing things if already formatted correctly
	var reg0Str = '[0-9]*';
	if (decimalPlaces > 0) {
		reg0Str += '\\.?[0-9]{0,' + decimalPlaces + '}';
	} else if (decimalPlaces < 0) {
		reg0Str += '\\.?[0-9]*';
	}
	reg0Str = allowNegative ? '^-?' + reg0Str : '^' + reg0Str;
	reg0Str = reg0Str + '$';
	var reg0 = new RegExp(reg0Str);
	if (reg0.test(temp)) return true;

	// first replace all non numbers
	var reg1Str = '[^0-9' + (decimalPlaces != 0 ? '.' : '') + (allowNegative ? '-' : '') + ']';
	var reg1 = new RegExp(reg1Str, 'g');
	temp = temp.replace(reg1, '');

	if (allowNegative) {
		// replace extra negative
		var hasNegative = temp.length > 0 && temp.charAt(0) == '-';
		var reg2 = /-/g;
		temp = temp.replace(reg2, '');
		if (hasNegative) temp = '-' + temp;
	}
	
	if (decimalPlaces != 0) {
		var reg3 = /\./g;
		var reg3Array = reg3.exec(temp);
		if (reg3Array != null) {
			// keep only first occurrence of .
			//  and the number of places specified by decimalPlaces or the entire string if decimalPlaces < 0
			var reg3Right = temp.substring(reg3Array.index + reg3Array[0].length);
			reg3Right = reg3Right.replace(reg3, '');
			reg3Right = decimalPlaces > 0 ? reg3Right.substring(0, decimalPlaces) : reg3Right;
			temp = temp.substring(0,reg3Array.index) + '.' + reg3Right;
		}
	}
	
	obj.value = temp;
	
}
function blockNonNumbers(obj, e, allowDecimal, allowNegative,declength)
{
	var key;
	var isCtrl = false;
	var keychar;
	var reg;
	if(window.event) {
		key = e.keyCode;
		isCtrl = window.event.ctrlKey
	}
	else if(e.which) {
		key = e.which;
		isCtrl = e.ctrlKey;
	}
	
	if (isNaN(key)) return true;
	
	keychar = String.fromCharCode(key);
	// check for backspace or delete, or if Ctrl was pressed
	if (key == 8 || isCtrl)
	{
		return true;
	}

	reg = /\d/;
	var isFirstN = allowNegative ? keychar == '-' && obj.value.indexOf('-') == -1 : false;
	var isFirstD = allowDecimal ? keychar == '.' && obj.value.indexOf('.') == -1 : false;
	declength = declength-1;
	if(	obj.value.length > declength) return false;
		
	return isFirstN || isFirstD || reg.test(keychar);
}


function printDetails(url){
	var print_window = window.open(url,'print','status=1,scrollbars=1,width=790,height=600');
		print_window.focus();
}

function validate_email_to_friend()
{

var firstname = trim(document.email_friend.name.value);
var email     = trim(document.email_friend.email.value);
var resemail     = trim(document.email_friend.recipient_email.value);
	if(!isValidName(firstname))
	{
		alert("Invalid Name.");
		document.email_friend.name.focus();
		return false;
	}
	else if(!isValidEmail(email))
	{
		alert("Invalid Email Address.");
		document.email_friend.email.focus();
		return false;
	}
	else if(!isValidEmail(resemail))
	{
		alert("Invalid Recipient's Email Address.");
		document.email_friend.recipient_email.focus();
		return false;
	}
	else
	{
	Modalbox.show('send_to_friend.php', {width: 500, params:Form.serialize('email_friend') });
	}
}

function mls_validate_email_to_friend()
{

var firstname    = trim(document.email_friend.name.value);
var email        = trim(document.email_friend.email.value);
var resemail     = trim(document.email_friend.recipient_email.value);
var validate_page = "";

if(document.getElementById("cpage"))
	validate_page = document.getElementById("cpage").value;
	
	if(!isValidName(firstname))
	{
		alert("Invalid Name.");
		document.email_friend.name.focus();
		return false;
	}
	else if(!isValidEmail(email))
	{
		alert("Invalid Email Address.");
		document.email_friend.email.focus();
		return false;
	}
	else if(!isValidEmail(resemail))
	{
		alert("Invalid Recipient's Email Address.");
		document.email_friend.recipient_email.focus();
		return false;
	}
	else
	{

		if(validate_page == "mlsfd_email_friend")
			url="mlsfd_send_to_friend.php";
		else
			url="mls_send_to_friend.php";
			
		Modalbox.show(url, {width: 500, params:Form.serialize('email_friend') });
	}
}






function validate_email_to_friend_featured()
{

var firstname = trim(document.email_friend_featured.name.value);
var email     = trim(document.email_friend_featured.email.value);
var resemail     = trim(document.email_friend_featured.recipient_email.value);
	if(!isValidName(firstname))
	{
		alert("Invalid Name.");
		document.email_friend_featured.name.focus();
		return false;
	}
	else if(!isValidEmail(email))
	{
		alert("Invalid Email Address.");
		document.email_friend.email_featured.focus();
		return false;
	}
	else if(!isValidEmail(resemail))
	{
		alert("Invalid Recipient's Email Address.");
		document.email_friend_featured.recipient_email.focus();
		return false;
	}
	else
	{
	Modalbox.show('send_to_friend_featured.php', {width: 500, params:Form.serialize('email_friend_featured') });
	}
}
function chektopsearch()
{
	if(document.getElementById('qry2').value != 'City or State or ZIP' && document.getElementById('qry2').value != ''  )
	{
		document.getElementById('qry').value=document.getElementById('qry2').value;
		document.search_form.submit();
	}
	else
	{
		alert('Please enter a valid City or State or ZIP');
	}
}