var link_num=new Array();

var current_link='';

var current_page='view.php';

var totrec = 0;

// Removes leading whitespaces

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));

}



/// ajax script ////

var xmlhttp = new XMLHttpRequest();

var str='';

function ajaxCall(url) {

	if(xmlhttp){

		xmlhttp.open('POST',url,true);

		xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');

    	xmlhttp.onreadystatechange = stateChanged;

    	xmlhttp.send(null);

  }

} 



function closeparent() {

	if (window.opener != null && !window.opener.closed) {

		window.open('','main','');

		window.name="main";

		if(document.all) {

			window.opener.opener = '';

		}

		window.opener.close();

	}

}		

function stateChanged() { 

	if (xmlhttp.readyState==1){ 

		document.getElementById("output").innerHTML='Processing...';

		document.getElementById("output").className='ajax-success';

	}

	if (xmlhttp.readyState==4){ 

			var str =xmlhttp.responseText;



			if (str.match('mls_property_details.php'))

			{

				location.href = str+'&redirect=login';

			}

			

			else if (str.match('.php')){

					location.href = str;

			}

			else if(str.match('detail')) {

					location.href = str;			

			}

			else if(str.match('1')) {

					location.href = 'message.php?page=profile';			

			}

			else if(str.match('2')) {

					location.href = 'message.php?page=editprofile';			

			}

			else if(str.match('3')) {

					location.href = 'view.php';			

			}

			else if(str.match('4')) {

					document.getElementById("output").style.display='inline';

			}

			else {

					document.getElementById("output").innerHTML=str;

					document.getElementById("output").className='ajax-failure';

			}

			str='';

	}

}

/// add to comparelist

function compare_ajaxCall(url) {

	if(xmlhttp){

		xmlhttp.open('POST',url,true);

		xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');

    	xmlhttp.onreadystatechange = compare_stateChanged;

    	xmlhttp.send(null);

  }

} 

function compare_stateChanged() { 

	

	if (xmlhttp.readyState==4){ 

		var str = xmlhttp.responseText;

		var st='';

		document.getElementById('im_'+current_link).innerHTML="";

		document.getElementById('compare_content').innerHTML = str;

		if (str!='') {

			//alert('Property added successfully to compare list'); //EDITED BY SATHIYAN ON 30-10-2007

			showHideCompare(1); //ADDED BY SATHIYAN ON 30-10-2007

			Set_Cookie( 'flag_child', '1', '', '/', '', '' );

			document.getElementById('link_'+current_link).style.display='none';

			showHideLinks(totrec,'');

			document.getElementById('sort_order').style.display='';

		}

		str='';

	}

}





/// add to comparelist

function compareSingle_ajaxCall(url) {

	if(xmlhttp){

		xmlhttp.open('POST',url,true);

		xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');

    	xmlhttp.onreadystatechange = compareSingle_stateChanged;

    	xmlhttp.send(null);

  }

} 

function compareSingle_stateChanged() { 

	if (xmlhttp.readyState==4){ 

		var str = xmlhttp.responseText;

		var st='';

		document.getElementById('compare_content').innerHTML = str;

		if (str!='') {

			//alert("one");

			alert('Property added successfully to compare list');	

			document.getElementById('link_compare').style.display='none';

			if (window.opener != null && !window.opener.closed) {

				//alert("two");

				if(window.opener.document.URL.match("view.php") != null || window.opener.document.URL.match("rentals.php") != null) {

					//alert("three");

					//alert(document.ff.prp.length);

					var sublen = window.opener.document.ff.prp.length;

					for (j=0;j<sublen;j++){

						if (window.opener.document.ff.prp[j].value==current_link) {

							window.opener.document.getElementById('link_'+current_link).style.display='none';	

						}

					}

					window.opener.document.getElementById('compare_content').innerHTML = str;

				}

			}

			document.getElementById('im_1').innerHTML="";			

		}

		str='';

	}

}

/// remove from savelist

/// add to comparelist

function remove_ajaxCall(url) {

	if(xmlhttp){

		xmlhttp.open('POST',url,true);

		xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');

    	xmlhttp.onreadystatechange = remove_stateChanged;

    	xmlhttp.send(null);

  }

} 

function remove_stateChanged() { 

	if (xmlhttp.readyState==4){ 

		var str = xmlhttp.responseText;

		document.getElementById('compare_content').innerHTML = str;

		if (window.opener != null && !window.opener.closed) {

			if(document.URL.match("detail") != null && window.opener.document.URL.match("view") != null && window.opener.document.URL.match("rental") != null)

			{

				window.opener.document.getElementById('compare_content').innerHTML = str;

				var sublen = window.opener.document.ff.prp.length;

			}

		}

		else if(document.URL.match("view") != null  || document.URL.match("rental") != null)

		{

			var sublen = document.ff.prp.length;

		}

		if (str!='') {

			document.getElementById('sort_order').style.display='';

			alert('Property removed successfully from compare list');	

			rcurrent_link = current_link.split(',');

			for(i=0;i<rcurrent_link.length;i++){

				if (document.URL.match("detail") != null) {

					if (document.getElementById('prid').value==rcurrent_link[i]){

						document.getElementById('link_compare').style.display='';	

					}

				}

				for (j=0;j<sublen;j++) {

					if (window.opener != null && !window.opener.closed) {

						if (document.URL.match("detail") != null && window.opener.document.URL.match("view") != null && window.opener.document.URL.match("rentals") != null) {

							

							if (window.opener.document.ff.prp[j].value==rcurrent_link[i]) {		

								window.opener.document.getElementById('link_'+rcurrent_link[i]).style.display='';

							}

						}

					}

					else if (document.URL.match("view.php") != null || document.URL.match("rentals.php") != null){

						//alert(document.URL.match("view.php"));

						if(document.ff.prp[j].value==rcurrent_link[i])

							document.getElementById('link_'+rcurrent_link[i]).style.display='';

							Set_Cookie( 'flag_child', '1', '', '/', '', '' );

					}

					else if(document.URL.match("rentals.php") != null)

					{

						//alert('aa');

						if(document.ff.prp[j].value==rcurrent_link[i])

							document.getElementById('link_'+rcurrent_link[i]).style.display='';

							Set_Cookie( 'flag_child', '1', '', '/', '', '' );

					}

				}

			}

		}

		showHideCompare(1); //ADDED BY SATHIYAN ON 30-10-2007

		str='';

	}

}



///save 

/// add to comparelist

function save_ajaxCall(url) {

	if(xmlhttp){

		xmlhttp.open('POST',url,true);

		xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');

    	xmlhttp.onreadystatechange = save_stateChanged;

    	xmlhttp.send(null);

  }

} 

function save_stateChanged() { 

	if (xmlhttp.readyState==4){ 

		var str =xmlhttp.responseText;

		//alert(str);

		if (str==1) {

			document.getElementById('CompareTool_m_ibSave').disabled = false;

			alert('Properties added successfully');		

		}

		else if (str==2){

			document.getElementById('CompareTool_m_ibSave').disabled = false;

			alert('Login to save property');	

		}

		 	else if(str == 'Property Already Exist'){

				//alert(str);

				document.getElementById('CompareTool_m_ibSave').disabled = false;

			//alert('One or more selected Property already saved');	

		}

	}

}



///save 

/// add to comparelist

function savesingle_ajaxCall(url) {

	if(xmlhttp){

		xmlhttp.open('POST',url,true);

		xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');

    	xmlhttp.onreadystatechange = savesingle_stateChanged;

    	xmlhttp.send(null);

  }

} 

function savesingle_stateChanged() { 

	if (xmlhttp.readyState==4){ 

		var str =xmlhttp.responseText;

		if (str==1) {

			alert('Property added successfully');		

		}

		else if (str==2){

			alert('Login to save property');

			closeparent();

			//location.href='login.php?url='+current_page; //Edited BY Sathiyan on 12-11-2007

			location.href='profile.php?url='+current_page; 

		}

		else if (str=="Property Already Exists") {

			alert('Property already saved');	

		}

		document.getElementById('im_'+current_link).innerHTML="";

		showHideLinks(totrec,'');

	}

}



function menuDetails(id){

	

	if (document.getElementById(id+'_val').value==1) {

		document.getElementById(id+'_flag').className='view_default';

		 if(document.getElementById(id+'_flag').className == 'view_default'){

		  location.reload();}

		document.getElementById(id+'_arrow').className='arrow';

		document.getElementById(id+'_val').value=0;

		switch (id){

			case 'location':

					//getState();

					//document.getElementById('state_cntrl').className='button-table';

					getCities();

					document.getElementById('city_cntrl').className='button-table';

				break;

			case 'price':	

					getPrice();

				break;

			case 'lifestyle':

					getLifeStyle();

				break;

			case 'propertytype':

					getPropertyType();

				break;

			case 'bedrooms':

					getBedRooms();

				break;

			case 'bathrooms':

					getBathRooms();

				break;	

			case 'amenities':

					getAmenities();

				break;

			case 'propertystyles':

					getPropertyStyles();

				break;

			case 'listingtypes':

					getListingTypes();

				break;

			case 'save_search':

					var inputctrl = "Name this search:<br /><input type='text' name='savedsearch' id='savedsearch' class='input' maxlenght=30 />";

					var cb    = "<input type='checkbox' name='watchlst' id='watchlst' checked='checked' />Email new listings that match this search";

					document.getElementById('save_search_cntrl').innerHTML=inputctrl+"<br />"+cb;	

					document.getElementById('save_search_cntrl').className='button-table';

				break;

		 }

	}

	else {

		 document.getElementById(id+'_flag').className='view_content';

        

		 document.getElementById(id+'_arrow').className='arrow-changed';

		 document.getElementById(id+'_val').value=1;

		 switch (id){

			case 'location':

					//getState();

					//document.getElementById('state_cntrl').className='button-table';

					getCities();

					document.getElementById('city_cntrl').className='button-table';

				break;

			case 'price':	

					getPrice();

				break;

			case 'lifestyle':

					getLifeStyle();

				break;

			case 'propertytype':

					getPropertyType();

				break;

			case 'bedrooms':

					getBedRooms();

				break;

			case 'bathrooms':

					getBathRooms();

				break;	

			case 'amenities':

					getAmenities();

				break;

			case 'propertystyles':

					getPropertyStyles();

				break;

			case 'listingtypes':

					getListingTypes();

				break;	

			case 'save_search':

				var inputctrl = "Name this search:<br /><input type='text' name='savedsearch' id='savedsearch'   class='input' maxlength='30' />";

				var cb    = "<input type='checkbox' name='watchlst' id='watchlst' checked='checked' />Email new listings that match this search";

				document.getElementById('save_search_cntrl').innerHTML=inputctrl+"<br />"+cb;	document.getElementById('save_search_cntrl').className='button-table';

			break;

		 }

	}	

}



function chkExists(arr, val)

{

	flag = 0;

	for (i in arr)

	{

		if (val == arr[i].name)

		{

			flag = '1'

		}

		return flag;

	}

}

var xmlhttp = new XMLHttpRequest();

var mytext;

function searchByID()

{

	textfield	= (document.fd.textfield.value == 'Search Location: City, ST. or MLS ID') ? '' : document.fd.textfield.value;

	if(textfield.length>0) {

		document.fd.submit();

	}

	else {

		alert("Please enter Location or Property ID");

		return false;

	}

}

function sortCriteria()

{

	

	document.getElementById('spinner_go').innerHTML="<img src='images/common/loading.gif'>";

	sort_order			= document.ff.sort_order.value;

	var ssrch           = document.getElementById('ssrch_val').value;

	srch_id = document.getElementById('srch_id').value;

	/* 

		Modified By K.Srinivasan

		For Rental Section

	*/

	var Rentalurl=window.location.href;

	var Rentalarrsplitted = Rentalurl.split('/');

	split_url             = Rentalarrsplitted[Rentalarrsplitted.length-1];

	split_page            = split_url.split('?');

		if(split_page[0] == 'rentals.php')

			url = "viewrental_inc.php?pst=1&page=1&sort_order="+sort_order;

		else

			url = "view_inc.php?pst=1&page=1&sort_order="+sort_order;

	/*

	End

	*/

	if (ssrch >0) {

			url +="&ssrch=1&pst=1&search_id="+srch_id;

		}

	if(xmlhttp){

		xmlhttp.open('POST',url,true);

		xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');

		xmlhttp.onreadystatechange = httpstatechange;

		xmlhttp.send(null);

	}

}



function searchCriteria(page_no)

{

	var Rentalurl=window.location.href;

	var Rentalarrsplitted=Rentalurl.split('/');



	

	document.getElementById('spinner_go').innerHTML="<img src='images/common/loading.gif'>";	



	go_click 			= document.ff.go_click.value;

	var ssrch           = document.getElementById('ssrch_val').value;

	var goSearch        = document.getElementById('goSearch').value;

	arrElements			= document.ff.elements;

	textfield			= (document.fd.textfield.value == 'Search Location: City, ST. or MLS ID') ? '' : document.fd.textfield.value;

	sort_order			= document.ff.sort_order.value;

	state				= (document.ff.location_val.value == 1) ? document.ff.state.value : '';

	rcity				= (document.ff.location_val.value == 1 && document.ff.state.value != '') ? document.ff.rcity.value : '';

	//price				= (document.ff.price_val.value == 1) ? document.ff.price.value : ''; Edited By Sathiyan on 05-11-2007

	lifestyle			= (document.ff.lifestyle_val.value == 1) ? document.ff.lifestyle.value : '';

	propertytype		= (document.ff.propertytype_val.value == 1) ? document.ff.propertytype.value : '';

	bedrooms			= (document.ff.bedrooms_val.value == 1) ? document.ff.bedrooms.value : '';

	bathrooms			= (document.ff.bathrooms_val.value == 1) ? document.ff.bathrooms.value : '';

	amenities			= (document.ff.amenities_val.value == 1) ? document.ff.amenities.value : '';

	propertystyles		= (document.ff.propertystyles_val.value == 1) ? document.ff.propertystyles.value : '';

	searchname		= (document.getElementById('save_search_val').value == 1) ? document.getElementById('savedsearch').value : '';

	email_flag      = (document.getElementById('save_search_val').value == 1) ? document.getElementById('watchlst').checked : '';

	

	/* Created By Sathiyan on 05-11-2007 (For Price)*/

	

	if(document.ff.price_val.value == 1){

		

		if(document.ff.maxprice.value == "g-20000000" || document.ff.maxprice.value == ""){

			/*if(document.ff.maxprice.value == "0"){

				maxprice = document.ff.maxprice.value;

			}else{

				maxprice = parseInt(document.ff.maxprice.value);

			}*/

			maxprice = document.ff.maxprice.value;

		}else{

			maxprice = parseInt(document.ff.maxprice.value);

		}

		

		if(document.ff.minprice.value == ""){

			minprice = document.ff.minprice.value;

		}else{

			minprice = parseInt(document.ff.minprice.value);

		}

		var price = '';



		if(minprice != "" || maxprice != ""){	

			if(maxprice == "g-20000000"){

				if(minprice != "" && minprice != 0){

					price = "g-"+minprice;				

				}else{

					//price = maxprice;

					price = '';

				}

			}else

			if(minprice == "" && maxprice != ""){

				price = "0-"+maxprice;

			}else

			if(minprice != "" && maxprice == ""){

				if(minprice > 0 && maxprice == "0"){

					alert('Maximum value should be greater than Minimum value');

					price  = '';

					document.getElementById('spinner_go').innerHTML="";

					return false;

				}else{

					//price = minprice+"-20000000";

					price = minprice+"-999999999999";

				}

			}else

			if(minprice != "" && maxprice != ""){	

				if(minprice>maxprice){

					alert('Maximum value should be greater than Minimum value');

					//price = minprice+"-"+maxprice;

					//alert(price);

					price  = '';

					document.getElementById('spinner_go').innerHTML="";

					return false;

				}else{

					//alert('correct');

					price = minprice+"-"+maxprice;

				}			

			}else{

				price = '';

			}		

		}else{

			//alert("hi");

			if(minprice == "0" && maxprice == "0"){

				price = '0-0';

			}else

			if(minprice == "" && maxprice == "0"){

				price = '0-0';

			}else

			if(minprice == "0" && maxprice == ""){

				//price = '0-20000000';

				price = '0-999999999999';

			}

			else{

				price = '';

			}

		}

	}else{

		price = '';

	}

	//alert(price);

	//return false;

	

	/*  End Price */

	

	/******************

		Modified By K.Srinivasan

		For Rental Section

	*/

	var Rentalurl=window.location.href;

	var Rentalarrsplitted=Rentalurl.split('/');

	split_url   = Rentalarrsplitted[Rentalarrsplitted.length-1];

	split_page  = split_url.split('?');

	if (split_page[0] == 'rentals.php')

		Page = "viewrental_inc.php";

	else

		Page = "view_inc.php";

	/*

		End

	*/

	if(!isValidSearchName(searchname) && searchname.length>0) {

		alert('Invalid search name');		

		 document.getElementById('spinner_go').innerHTML="";	

	}

	else{

		srch_id = document.getElementById('srch_id').value;

	/******************

		Modified By K.Srinivasan

		For Rental Section

	*/

		if(page_no>=1)

			url = Page+"?pgn=1&page="+page_no+"&sort_order="+sort_order+"&goSearch="+goSearch;

		else

			url = Page+"?textfield="+textfield+"&sort_order="+sort_order+"&state="+state+"&rcity="+rcity+"&price="+price+"&lifestyle="+lifestyle+"&propertytype="+propertytype+"&bedrooms="+bedrooms+"&bathrooms="+bathrooms+"&amenities="+amenities+"&propertystyles="+propertystyles+"&searchname="+searchname+"&email_flag="+email_flag+"&goSearch="+goSearch;

	/******************

		End

	*/

		if (ssrch >0 && go_click!=1) {

			url +="&ssrch=1&pst=1&search_id="+srch_id;

		}



		if(xmlhttp){

			xmlhttp.open('POST',url,true);

			xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');

			xmlhttp.onreadystatechange = httpstatechange;

			xmlhttp.send(null);

		}

	}

	if(page_no<1)

	{

		return false;

	}	

}

function sortControl()

{

	var Rentalurl=window.location.href;

	var Rentalarrsplitted=Rentalurl.split('/');

	split_url   = Rentalarrsplitted[Rentalarrsplitted.length-1];

	split_page  = split_url.split('?');

	if (split_page[0] == 'rentals.php')

		document.getElementById('sort_order').value = 'city-asc';

	

	

}

function httpstatechange(){

if (xmlhttp.readyState==1){

		document.getElementById('spinner_go').style.display='inline';

		//lgx(1);

}

	

  if (xmlhttp.readyState == 4){

	  document.getElementById('spinner_go').innerHTML="";	

	  

		mytext = xmlhttp.responseText;

		var msg = mytext.split('~!^zz');

		var teststr = msg[0];

		var msgstr ='';

		var cont ='';

		if (teststr.match('<table')){

			cont = msg[0];			

			document.getElementById('savename_content').innerHTML='';

			document.getElementById('savename_flag').style.display='none';

		}

		else{

			msgstr=msg[0];

			cont = msg[1];

			document.getElementById('savename_content').innerHTML=msgstr;

			document.getElementById('savename_flag').style.display='';

			

		}

		

		

    	var objMore = document.getElementById("listingResults");

    	objMore.innerHTML = cont;

		//lgx(0);



/*		Element.hide('spinner_go');

		Element.hide('spinner_sort');*/

		//document.getElementById('spinner_go').style.display = 'none';

		//document.getElementById('spinner_sort').style.display = 'none';

    	mytext="";

	}

}



function clearTextBox(){

	alert(document.getElementById('textfield').value);

	//document.getElementById('textfield').value='';

}



function isValidEmail(strEmail){

  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

    if (strEmail.search(validRegExp) == -1) {

      return false;

    } 

    return true; 

}

function isValidSearchName(searchname){

 validRegExp = /^[\w]+$/;

    if (searchname.match(validRegExp) == null) {

      return false;

    } 

    return true;

}

// user - add/ modify/delete

function addUser(){

	

	document.getElementById('username_msg').innerHTML='';

	document.getElementById('email_msg').innerHTML='';

	document.getElementById('password_msg').innerHTML='';

	document.getElementById('confirm_password_msg').innerHTML='';

	//document.getElementById('state_msg').innerHTML='';

	//document.getElementById('city_msg').innerHTML='';

	//document.getElementById('address_msg').innerHTML='';

	//document.getElementById('country_msg').innerHTML='';

	document.getElementById('residence_msg').innerHTML='';

	document.getElementById('area_msg').innerHTML='';

	document.getElementById('buyingtimeframe_msg').innerHTML='';

	document.getElementById('pricelowend_msg').innerHTML='';

	document.getElementById('pricehighend_msg').innerHTML='';

	document.getElementById('season_msg').innerHTML='';

	document.getElementById('zipcode_msg').innerHTML='';

	document.getElementById('confirm_email_msg').innerHTML='';

	var passflag=1;

	var flag=true;

	

	var username =trim( document.getElementById('username').value);

	var email    = trim(document.getElementById('email').value);

	var confirm_email=trim(document.getElementById('confirm_email').value);

	

	

	var passwordws = document.getElementById('password').value;

	var password = trim(document.getElementById('password').value);

	

	if(passwordws!=password)

	{

		document.getElementById('password_msg').innerHTML='Password should not prefix with spaces';

		document.getElementById('password_msg').style.color='red';

		flag=false;

		

	}

	

	

	var confirm_password = trim(document.getElementById('confirm_password').value);

	var zipcode=trim(document.getElementById('zipcode').value);

	

	//var country  = trim(document.getElementById('country').value);

	//var state    = trim(document.getElementById('state').value);

	//var city     = trim(document.getElementById('city').value);

	//var address  = escape(trim(document.getElementById('address').value));

	

	

	

/*------- areas of interest validation--------*/

	

	var arr_areas=new Array();

	var j=0;

	var areas_selected=false;

	var arr=document.getElementsByName('area[]');

	for(i=0;i<arr.length;i++)

	{

			if(arr[i].checked && arr[i].value!='')

			{

				arr_areas[j]=arr[i].value;

				j++;

				areas_selected=true;

			}

	}

	if(!areas_selected)

	{

		document.getElementById('area_msg').innerHTML='Please select list of areas';

		document.getElementById('area_msg').style.color='red';

		flag=false;

		

	}

	

	

	

	

/*------- areas of interest validation--------*/



/*------- Seasons  validation--------*/

	var arr_seasons=new Array();

	var j=0;

	var seasons_selected=false;

	arr=document.getElementsByName('season[]');

	for(i=0;i<arr.length;i++)

	{

			if(arr[i].checked && arr[i].value!='')

			{

				arr_seasons[j]=arr[i].value;

				j++;

				seasons_selected=true;

				

			}

	}

	if(!seasons_selected)

	{

		document.getElementById('season_msg').innerHTML='Please select seasons';

		document.getElementById('season_msg').style.color='red';

		flag=false;

		

	}

/*------- Seasons  validation--------*/







	var residence=radio_button_residence_checker();

	if(!residence)

	{

		document.getElementById('residence_msg').innerHTML='Please select residence type';

		document.getElementById('residence_msg').style.color='red';

		flag=false;

		

	}

	

	var buyingtimeframe=radio_button_buyingtimeframe_checker();

	if(!buyingtimeframe)

	{

		document.getElementById('buyingtimeframe_msg').innerHTML='Please select Buying timeframe';

		document.getElementById('buyingtimeframe_msg').style.color='red';

		flag=false;

		

	}

	

	var pricelowend=radio_button_pricelowend_checker();

	if(!pricelowend)

	{

		document.getElementById('pricelowend_msg').innerHTML='Please select price range (low end)';

		document.getElementById('pricelowend_msg').style.color='red';

		flag=false;

		

	}

	

	var pricehighend=radio_button_pricehighend_checker();

	if(!pricehighend)

	{

		document.getElementById('pricehighend_msg').innerHTML='Please select price range (high end)';

		document.getElementById('pricehighend_msg').style.color='red';

		flag=false;

		

	}

	

	

	var bttn     = document.getElementById('reg_button').value;

		

	

	

	var old_password ='';

	if (!isValidUserName(username) || username.length<3){

		document.getElementById('username_msg').innerHTML='Invalid Name';

		document.getElementById('username_msg').style.color='red';

		flag=false;

		

	}

	

		/*if (!isValidUserNametwo(username)){

		document.getElementById('username_msg').innerHTML='Invalid Name';

		document.getElementById('username_msg').style.color='red';

		flag=false;

		

	}*/



	

	if (!isValidEmail(email) || email.length<5){

		document.getElementById('email_msg').innerHTML='Invalid Email';

		document.getElementById('email_msg').style.color='red';

		flag=false;

	}

	if (bttn=='add') { 

		passflag=1 ;

	}

	else 

	if (bttn=='Update') { 

		if (document.getElementById('pass_group1').style.display=='') {

			old_password = trim(document.getElementById('old_password').value);

			document.getElementById('old_password_msg').innerHTML='';

			if (old_password.length<6){

				document.getElementById('old_password_msg').innerHTML='Password should have min 6 char(s)';

				document.getElementById('old_password_msg').style.color='red';

			}

		}

		else {

			passflag=0;	

		}

	}

	if (password.length<6  && passflag==1){

		document.getElementById('password_msg').innerHTML='Password should have min 6 char(s)';

		document.getElementById('password_msg').style.color='red';

		flag=false;

		

	}

	

	

	if (confirm_password!=password){

		document.getElementById('confirm_password_msg').innerHTML='Confirmed password does not match with password';

		document.getElementById('confirm_password_msg').style.color='red';

		flag=false;

		

	}





if(bttn!='Update')

{

 if(confirm_email!=email){

		document.getElementById('confirm_email_msg').innerHTML='Confirmed email does not match with mail';

		document.getElementById('confirm_email_msg').style.color='red';

		flag=false;

	

	}

}

	

	

	if(zipcode=='')

	{

		document.getElementById('zipcode_msg').innerHTML='Zipcode should not empty';

		document.getElementById('zipcode_msg').style.color='red';

		flag=false;

	}

	/*if (country.length<1 ) {

		document.getElementById('country_msg').innerHTML='Select a country';

		document.getElementById('country_msg').style.color='red';

		flag=false;

	}

	if (!isValidName(state) || state.length<3){

		document.getElementById('state_msg').innerHTML='Invalid State Name';

		document.getElementById('state_msg').style.color='red';

		flag=false;

	}

	if (!isValidName(city) || city.length<3){

		document.getElementById('city_msg').innerHTML='Invalid City name';

		document.getElementById('city_msg').style.color='red';

		flag=false;

	}

	if (address.length<1) {

		document.getElementById('address_msg').innerHTML='Address cannot be empty';

		document.getElementById('address_msg').style.color='red';

		flag=false;

	}

	else 

	if(!isValidAddress(address) && address.length>1){

		document.getElementById('address_msg').innerHTML='Invalid Address';

		document.getElementById('address_msg').style.color='red';

		flag=false;	

	}

	*/

	if (flag) {



		

		//pricelowend and pricehighend validation

		if(parseInt(pricehighend) <= parseInt(pricelowend))

		{

				alert('High end price range should be greater than low end price range');

				return false;

		}

		

		var state='';

		var country='';

		var city='';

		var address='';

		

		querystring ="username="+username+"&password="+password+"&email="+email+"&country="+country+"&state="+state+"&city="+city+"&address="+address+"&old_password="+old_password+"&residence="+residence+"&buyingtimeframe="+buyingtimeframe+"&pricelowend="+pricelowend+"&pricehighend="+pricehighend+"&area="+arr_areas+"&season="+arr_seasons+"&zipcode="+zipcode;

		//alert(querystring);

		

		if (bttn=='Update') {

			option='update&';	

		}

		else {

			option='adduser&';		

		}

		ajaxCall('profile.php?option='+option+querystring);

		return false;

	}

	else {

		return flag;

	}

}







function checkUncheckSeasons()

{

		if(document.getElementById('season_all_checkbox').checked)

		{

				/*------- Seasons all check--------*/

				var arr=document.getElementsByName('season[]');

				for(i=0;i<arr.length;i++)

				{

					arr[i].checked=true;

				

				}

				/*------- Seasons all check--------*/



		}

		else

		{

				/*------- Seasons all Uncheck--------*/

				var arr=document.getElementsByName('season[]');

				for(i=0;i<arr.length;i++)

				{

					arr[i].checked=false;

				

				}

				/*------- Seasons all Uncheck--------*/



		}

}



function checkUncheckAreas()

{

		

		if(document.getElementById('area_all_checkbox').checked)

		{

				/*------- areas all check--------*/

				var arr=document.getElementsByName('area[]');

				for(i=0;i<arr.length;i++)

				{

					arr[i].checked=true;

				

				}

				/*------- areas all check--------*/



		}

		else

		{

				/*------- areas all Uncheck--------*/

				var arr=document.getElementsByName('area[]');

				for(i=0;i<arr.length;i++)

				{

					arr[i].checked=false;

				

				}

				/*------- areas all Uncheck--------*/



		}

}





//get residence radio value

function radio_button_residence_checker()

{

				

	if ( document.ff.residence.selectedIndex == 0 )

    {

               return false;

    }	

	else

	{

			   return document.ff.residence.options[document.ff.residence.selectedIndex].value;

	}

			

}





function radio_button_buyingtimeframe_checker()

{

	if ( document.ff.buyingtimeframe.selectedIndex == 0 )

    {

               return false;

    }	

	else

	{

			return document.ff.buyingtimeframe.options[document.ff.buyingtimeframe.selectedIndex].value;

	}	

			

			

			

}

function radio_button_pricelowend_checker()

{

	if ( document.ff.pricelowend.selectedIndex == 0 )

    {

               return false;

    }	

	else

	{

			return document.ff.pricelowend.options[document.ff.pricelowend.selectedIndex].value;

	}	

			

			

}

function radio_button_pricehighend_checker()

{

	if ( document.ff.pricehighend.selectedIndex == 0 )

    {

               return false;

    }	

	else

	{

			return document.ff.pricehighend.options[document.ff.pricehighend.selectedIndex].value;

	}		

			

			

}













// validate uset

function validateUser(){

	

	

	var email = trim(document.getElementById('emailx').value);

	var password = trim(document.getElementById('passwordx').value);

	var url = trim(document.getElementById('strurl').value);

	var persistentcookie='no';

	if(document.getElementById('persistentcookie').checked)

	{			

			persistentcookie='yes';

	}

	

	var flag=true;

	if (!isValidEmail(email) || email.length<5){

		flag=false;

	}

	if (password.length<6){

		flag=false;

	}

	if (flag) {

		querystring ="email="+email+"&password="+password+"&strurl="+url+"&persistentcookie="+persistentcookie;	

		ajaxCall('login.php?option=validate&'+querystring);

		return false;

	}

	else {

		document.getElementById('output').innerHTML='Invalid Login';

		document.getElementById('output').className='ajax-failure';

		return false;

	}

}



function changePassword(flag){

	//document.getElementById('pass_link').style.display='table-row';

	if (flag) {

		document.getElementById('link_content').innerHTML="<a href='javascript:changePassword(0)'> No need to change password </a>";

		document.getElementById('pass_group1').style.display='';

		document.getElementById('pass_group2').style.display='';

		//document.getElementById('pass_group3').style.display='';

	}

	else {

		document.getElementById('link_content').innerHTML="<a href='javascript:changePassword(1)'> Click here to change password </a>";

		document.getElementById('pass_group1').style.display='none';

		document.getElementById('pass_group2').style.display='none';

//		document.getElementById('pass_group3').style.display='none';	

	}

	

}

function sendPassword(){

	var email = document.getElementById('email').value;

	document.getElementById('email_msg').innerHTML='';

	var flag=true;

	if (!isValidEmail(email) || email.length<3) {

		document.getElementById('email_msg').innerHTML=' Invalid Email';

		document.getElementById('email_msg').style.color='red';

		flag=false;

	}

	if (flag) {

		querystring ="email="+email;

		ajaxCall('profile.php?option=resetpassword&'+querystring);			

	}

	return false;

}



function showHideCompare(flag){

	if (flag==1) {

		document.getElementById('compareTool').style.display='inline';

		//document.getElementById('sort_order').style.display='none';

		document.getElementById('compareBtn').innerHTML="<img src='images/buttons/btn_compareproperties_dn.gif' name='compareImage' id='compareImage' width=129 height=16 alt='' onClick='showHideCompare(0);'>";

	}

	else {

		document.getElementById('compareTool').style.display='none';

		document.getElementById('sort_order').style.display='';

		document.getElementById('compareBtn').innerHTML="<img src='images/buttons/btn_compareproperties_up.gif' name='compareImage' id='compareImage' width=129 height=16 alt='' onClick='showHideCompare(1);'>";	

	}

}



/*function compareList(prpid,option){

	querystring ="prpid="+prpid;

	if (option=='add'){

		document.getElementById('link'+prpid).style.display='none';		

		//Element.show('spinner_sort');

	}

	compare_ajaxCall('comparelist.php?option='+option+'&'+querystring);

}

*/

function showHideLinks(total,display){

	for (i=1;i<=total;i++){

		document.getElementById('sidx_'+i).style.display=display;	

	}



}

function compareList(prpid,option,nm,totalrec){

	querystring ="prpid="+prpid;

	current_link = nm;

    totrec= totalrec;

	var st='';

	if (option=='add'){

		//for (i=1;i<=totrec;i++) {

			//if(document.getElementById('link_'+i).style.display=='none'){

				//link_num[i] = 'none';

				//st +=link_num[i]+',';

		//	}

			//else {

				//link_num[i] ='';	

				//st +=link_num[i]+',';

				//document.getElementById('link_'+nm).style.display='none';

			//}

			document.getElementById('link_'+nm).style.display='none';

			document.getElementById('im_'+current_link).innerHTML="<img src='images/common/loading.gif'>";

			showHideLinks(totrec,'none');

		}

		

		//Element.show('spinner_sort');

	compare_ajaxCall('comparelist.php?option='+option+'&'+querystring);

}



function compareSingleList(prpid,nm){

	current_link = nm;

	querystring ="prpid="+prpid;

	compareSingle_ajaxCall('comparelist.php?option=add&'+querystring);

	document.getElementById('im_1').innerHTML="<img src='images/common/loading.gif'>";

}









function removeList(tot){

	document.getElementById('remove').disabled = true ;

	var str='';

	var lnk='';

	var count=0;

	if (tot>0) {

		flag = document.getElementById('cbx1');

		if (flag.checked) {

			var st = document.getElementById('cbx1').value;

			st = st.split('|');

			str = st[0];

			lnk = st[1];

			count++;

		}

		for (i=2;i<=tot;i++){

			flag = document.getElementById('cbx'+i);

			if (flag.checked) {

				if (str!='') {	

					str += ',';

					lnk += ',';

				}

				var st = document.getElementById('cbx'+i).value;

				st = st.split('|');

				str += st[0];

				lnk += st[1];

			}

		}

		if (str!='') {	

			querystring ="prpid="+str;

			remove_ajaxCall('comparelist.php?option=delete&'+querystring);

			current_link = lnk;

			//str.split(',');

		}

		else {

			document.getElementById('remove').disabled = false ;

			alert('You must select atleast one property to remove');	

		}

   }

   else {

	   		document.getElementById('remove').disabled = false ;

			alert('You must select atleast one property to remove');	

		}

		return false;

}



function compareProperties(tot){

	var str ='';

	var count=0;

	

	if (tot>0) {

		flag = document.getElementById('cbx1');

		if (flag.checked) {

			var st = document.getElementById('cbx1').value;

			st = st.split('|');

			str = st[0]; 

			count++;

		}

		for (i=2;i<=tot;i++){

			flag = document.getElementById('cbx'+i);

			if (flag.checked) {

				count++;

				if (str!='') {	

					str += ',';

				}

				var st = document.getElementById('cbx'+i).value;

				st = st.split('|');

				str += st[0];

			}

		}

	}

	if (count <2 || tot <1 ) {

		alert('You must select atleast two properties to compare');

	}

	else 

	if (count >4 ) {

		alert('Maximum four properties can be compared at a time');

	}

	else {

		var win_url = "compare_details.php?prpid="+str;

		newPopUpWindow(win_url,'compare Properties',716,780,'yes');

	}

	return false;

}



function saveProperty(tot){

	if(document.getElementById('CompareTool_m_ibSave') != null)

	{

		document.getElementById('CompareTool_m_ibSave').disabled = true;

	}



	var str ='';

	var count=0;

	if (tot>0) {

		flag = document.getElementById('cbx1');

		if (flag.checked) {

			var st = document.getElementById('cbx1').value;

			st = st.split('|');

			str = st[1]; 

			count++;

		}

		for (i=2;i<=tot;i++){

			flag = document.getElementById('cbx'+i);

			if (flag.checked) {

				count++;

				if (str!='') {	

					str += ',';

				}

				var st = document.getElementById('cbx'+i).value;

				st = st.split('|');

				str += st[1];

			}

		}

	}

	if (count <1 || tot <1 ) {

		alert('You must select atleast one property to save');			

	}

	else {

		querystring = "property_id="+str;

		save_ajaxCall('save_property.php?option=save&'+querystring);

	}

	return false;

}



function saveSingleProperty(propertyid,nm,page,total){

	totrec=total;

	current_link = nm;

	current_pagea = page;

	var current_pagea_Splited  = current_pagea.split('?');	

	var gser = document.getElementById('goSearch').value;

	

	var Rentalurl=window.location.href;

	var Rentalarrsplitted=Rentalurl.split('/');

					

	if(Rentalarrsplitted[Rentalarrsplitted.length-1] == 'rentals.php')

		current_page = "rentals.php";

	else

		current_page = "view.php?goSearch="+gser;

		

	querystring = "property_id="+propertyid;

	document.getElementById('im_'+current_link).innerHTML="<img src='images/common/loading.gif'>";

	savesingle_ajaxCall('save_property.php?option=save&'+querystring);

	showHideLinks(totrec,'none');

}



function isValidUserName(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 isValidUserNametwo(val) {

	var illegalChars = /\W/; // allow letters, numbers, and underscores

	 //validRegExp = /^.*\s.*$/i;

   // search email text for regular exp matches

   val = trim(val);

   

   if (illegalChars.test(val))

   {

	   	return false;

   }

   // if (val.search(validRegExp) == -1) {

	 //return false;

    //} 

    return true; 	

}







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 newPopUpWindow(page, name, w, h, scroll) { 

	name = "foo";

	page = page.split(" ").join("%20");

	var winl = (screen.width - w) / 2;

	var wint = (screen.height - h) / 2;

	//var resizable = false;

	winprop  = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable=yes';

	win = window.open(page, name, winprop);

    win.focus();

 }

function  isValidAddress(addr){

	//validRegExp = /^[0-9a-zA-Z\s\,./-]+$/;

	validRegExp = /^[0-9a-zA-Z \s,.\!\@\#\$\%\^\&\*\(\)\?\_\'\"/-]+$/;

    if (addr.match(validRegExp) == null) {

      return false;

    } 

    return true;

}

function  isValidComment(commt){

	validRegExp = /^[0-9a-zA-Z \s,.\!\@\#\$\%\^\&\*\(\)\?\_\'\"/-]+$/;

    if (commt.match(validRegExp) == null) {

      return false;

    } 

    return true;

}

function isValidPhone(val) {

	 validRegExp = /^[0-9 -]+$/;

   // search email text for regular exp matches

   val = trim(val);

    if (val.match(validRegExp) == null) {

      return false;

    } 

    return true; 	

}

function validateContact(){

	var result_ajax = '';

	var email 	 = document.contact.email.value;

	var fname 	 = document.contact.fname.value;

	var lname 	 = document.contact.lname.value;

	var newsletter_interest = (document.contact.newsletter_interest.checked)?'Yes':'No';

	//var hphone 	 = document.contact.hphone.value;

	var comments = escape(document.contact.comments.value);

	var flag = true;

	document.getElementById('email_err').innerHTML ='';

	document.getElementById('fname_err').innerHTML ='';

	document.getElementById('lname_err').innerHTML ='';

	//document.getElementById('hphone_err').innerHTML ='';

	document.getElementById('comments_err').innerHTML ='';

	if (!isValidEmail(email) || email.length<3) {

		document.getElementById('email_err').innerHTML=' Invalid Email';

		flag = false;

	}

	if (!isValidName(fname) && fname.length>0){

		document.getElementById('fname_err').innerHTML='Invalid First name';

		flag = false;

	}

	if (!isValidName(lname) && lname.length>0){

		document.getElementById('lname_err').innerHTML='Invalid Last name';

		flag = false;

	}

	/*if (hphone.length>1){

		if(hphone.length<6 || !isValidPhone(hphone)) {

		document.getElementById('hphone_err').innerHTML='Invalid Phone No.';

		flag = false;

		}

	}*/

	if (!isValidComment(comments) && comments.length>0){

		document.getElementById('comments_err').innerHTML='Invalid Comments';

		flag = false;

	}

	

	if (flag) {

		querystring ="email="+email+"&fname="+fname+"&lname"+lname+"&comments="+comments+"&newsletter_interest="+newsletter_interest;

		url= 'contactus.php?option=contactus&'+querystring;	

		if(xmlhttp){

			xmlhttp.open('POST',url,true);

			xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');

			xmlhttp.onreadystatechange = httpcontactchange;

			xmlhttp.send(null);

		}

		return false;

	}

	return false;

}

function httpcontactchange(){

	if (xmlhttp.readyState==1){

			document.getElementById('spinner').innerHTML = "<img src='images/common/loading.gif' alt='Loading...'>";

	}

		

	if (xmlhttp.readyState == 4){

		mytext = xmlhttp.responseText;

		document.getElementById("contact_us").innerHTML = mytext;

		mytext="";

	}

}



function lgx(flag){

	if (flag){	

	     var fileLoadingImage = "images/loading.gif";

		 var objBody = document.getElementsByTagName("body").item(0);

		 var objOverlay = document.createElement("div");

  		 objOverlay.setAttribute('id','overlay');

	     objBody.appendChild(objOverlay);

		  var objLoadingImage = document.createElement("img");

		  objLoadingImage.setAttribute('src', fileLoadingImage);

		  objLoadingImage.setAttribute('vspace', "278");

		  objOverlay.appendChild(objLoadingImage);

		  document.getElementById('overlay').style.top = window.screen.height-500;

	      document.getElementById('overlay').style.height=window.screen.height;

	}

	

	else {

		     document.getElementById('overlay').style.display='none';

	  	 }

}



function idsearch(){

    var val = trim(document.getElementById('textfield').value);

	closeparent();

/* Z&Z
    if (val=='' || val=='Search Location: City, ST. or MLS ID') {

        alert('Invalid search parameter');

		return false;

    }

     else {
*/
		url=window.location.href;

		arrsplitted=url.split('/');

		if (arrsplitted[arrsplitted.length-2]=='agents')

// Z&Z			document.fd.action='../mlsquick_search_results.php?pst=1&mls_number='+val+'&goSearch=1';
			document.fd.action='../property.html'; // Z&Z added

		else

// Z&Z			document.fd.action='mlsquick_search_results.php?pst=1&mls_number='+val+'&goSearch=1';
			document.fd.action='../property.html'; // Z&Z added
			
		document.fd.submit()

		return true;

    }

//Z&Z }

function idsearchblog(){

    var val = trim(document.getElementById('textfield').value);

	closeparent();

/* Z&Z
    if (val=='' || val=='Search Location: City, ST. or MLS ID') {

        alert('Invalid search parameter');

		return false;

    }

    else {
*/
// Z&Z        document.fd.action='../mlsquick_search_results.php?pst=1&mls_number='+val;
			document.fd.action='/property.html'; // Z&Z added
			
        document.fd.submit()

		return true;

// Z&Z    }

}

function deleteSearch(id) {

	if(confirm("Are you sure you want to delete?")) {

		location.href="mysavedsearches.php?option=delete&id="+id;

	}

}





function Set_Cookie( name, value, expires, path, domain, secure ) 

{

// set time, it's in milliseconds

var today = new Date();

today.setTime( today.getTime() );



if ( expires )

{

expires = expires * 1000 * 60 * 60 * 24;

}

var expires_date = new Date( today.getTime() + (expires) );



document.cookie = name + "=" +escape( value ) +

( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 

( ( path ) ? ";path=" + path : "" ) + 

( ( domain ) ? ";domain=" + domain : "" ) +

( ( secure ) ? ";secure" : "" );

}



function Get_Cookie( name ) {

	

var start = document.cookie.indexOf( name + "=" );

var len = start + name.length + 1;

if ( ( !start ) &&

( name != document.cookie.substring( 0, name.length ) ) )

{

return null;

}

if ( start == -1 ) return null;

var end = document.cookie.indexOf( ";", len );

if ( end == -1 ) end = document.cookie.length;

return unescape( document.cookie.substring( len, end ) );

}

