/*Advanced Search Validation*/
function numbersonly(e, decimal) {
var key;
var keychar;

if (window.event) {
   key = window.event.keyCode;
}
else if (e) {
   key = e.which;
}
else {
   return true;
}
keychar = String.fromCharCode(key);

if ((key==null) || (key==0) || (key==8) ||  (key==9) || (key==13) || (key==27) ) {
   return true;
}
else if ((("0123456789").indexOf(keychar) > -1)) {
   return true;
}
else if (decimal && (keychar == ".")) { 
  return true;
}
else
   return false;
}
function checkselect(strng,defvalue)
{
var dis= strng.value;
 if(dis==defvalue)
 {
	 alert("Select the "+strng.id);
	 strng.focus();
	 return(0);
 }
 else
  return(1);	
}
function checkdistrict()
{
var district=document.advsearch.district.value;
var error = "";
if (district == "0") {
   error = "Select the District.\n";
 }
if(error!="")
	{
	document.advsearch.district.focus();
	alert(error);
	return(0);
	}
	else
	return(1);
}
function checktown()
{
var town=document.advsearch.town.value;
var error = "";
if (town == "0") {
   error = "Select the Town.\n";
 }
if(error!="")
	{
	document.advsearch.town.focus();
	alert(error);
	return(0);
	}
	else
	return(1);
}
function checkproptype()
{
var property=document.advsearch.property.value;

var error = "";
if (property == "0") {
   error = "Select the Property type.\n";
 }
if(error!="")
	{
	document.advsearch.property.focus();
	alert(error);
	return(0);
	}
	else
	return(1);
}
function checkproparea()
{
var proparea=document.advsearch.proparea.value;
var res=isNaN(proparea);
if ((res==true)&&(proparea!="")) {
	alert("Enter Property Area in numeric digits.");
   return 0;
 }	
 else
return 1;
}
function checkcopy2(from) { 
	if (!hasOptions(from)) { return; }
	var sellength = from.options.length;
	var selvalue = from.options[0].value;
	if((sellength==1)&&(selvalue=="sel"))
	{
		alert("Select atleast one Location");
	return 0;
	}
	else
	{
		return 1;
	}
	}
function retriveAllOptions(from) { 
	if (!hasOptions(from)) { return; }
	var str="";
	
	for (var i=(from.options.length-1); i>=0; i--) {
		str+=from.options[i].value+",";
		} 
	
		return str;
	} 
function advsearchvalid()
{
val=checkselect(document.advsearch.district,"0");
	if(val==0)
	{
	return;
	}
	else
	{
		val=checkselect(document.advsearch.town,"0");
			if(val==0)
			{
			return;
			}
			else
			{
				val=checkselect(document.advsearch.property,"0");
				if(val==0)
				{
				return;
				}
				else
				{
					val=checkproparea();
					if(val==0)
					{
						return;
					}
					else
					{
				
					val=checkcopy2(document.advsearch['copy2']);
					if(val==0)
					{
						return;
					}
					else
					{
					var areaall=retriveAllOptions(document.advsearch['copy2']);
					document.advsearch.arealist.value=areaall;
					document.advsearch.submyes.value="subyes";
					dispsearchresults('','','','yes',document.advsearch.district.value,document.advsearch.town.value,document.advsearch.arealist.value,document.advsearch.property.value,document.advsearch.proparea.value,'1','','yes');
					window.location="#search";
					//dispsearchresults(qs,);
					//document.advsearch.action="#search";
					//document.advsearch.method="POST";
					//document.advsearch.submit();
					}
				}
				}
		  	}
		}
	}
function checkbrowseby(distid,proptype)
{
	dispsearchresults('yes',distid,proptype,'','','','','','','1','','yes');
}

/*Quick Search Validation*/
function checkqsproperty()
{
var qsprop=document.qssearch.qsproperty.value;
var error = "";
if (qsprop == "0") {
   error = "Select the Property Type for Search.\n";
 }
if(error!="")
	{
	document.qssearch.qsproperty.focus();
	alert(error);
	return(0);
	}
	else
	return(1);
}

function checkcity()
{
var city=document.qssearch.city.value;
var error = "";
if (city == "0") {
   error = "Select City for Search.\n";
 }
if(error!="")
	{
	document.qssearch.city.focus();
	alert(error);
	return(0);
	}
	else
	return(1);
}

function qssearchvalid()
{
val=checkcity();
	if(val==0)
	{
	return;
	}
	else
	{
		val=checkqsproperty();
		if(val==0)
		{
		return;
		}
		else
		{
			//document.qssearch.action="#search";
			
			document.qssearch.qsubyes.value="yes";
			dispsearchresults('yes',document.qssearch.city.value,document.qssearch.qsproperty.value,'','','','','','','1','','yes');
			window.location="#search";
			//document.qssearch.method="POST";
			//document.qssearch.submit();	
		}
	}
}
var xmlhttp

function dispsearchresults(qs,city,proptype,advs,dist,town,areas,proptype1,proparea,pno,viscnt,goto)
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  }
 
var url="ajax/search_results.php";
url=url+"?pno="+pno;
url=url+"&city="+city;
url=url+"&proptype="+proptype;
url=url+"&advs="+advs;
url=url+"&dist="+dist;
url=url+"&town="+town;
url=url+"&areas="+areas;
url=url+"&proptype1="+proptype1;
url=url+"&proparea="+proparea;
url=url+"&qs="+qs;
url=url+"&viscnt="+viscnt;
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=function () {
stateChanged(goto);
};
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}

function stateChanged(str1)
{
if (xmlhttp.readyState==1)
  {
	/* if(document.qssearch.qsubyes.value=="yes")
	 {*/
	if(str1=="yes")
	{
		
		 document.getElementById('searchresults_box').innerHTML = document.getElementById('hideimg').innerHTML;
	}
	/* }*/
	  /*if(document.advsearch.submyes.value=="subyes")
	 {
		 document.getElementById('searchresults_box').innerHTML = document.getElementById('hideimg1').innerHTML;
	 }*/
	  
  }
if (xmlhttp.readyState==4)
  {
	document.getElementById('searchresults_box').innerHTML =  xmlhttp.responseText;
	if(str1=="yes")
	{
	window.location="#search";
	}
	return;

  }
}

function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}

