function getState(country_id)
{
	xmlHttps=GetXmlHttpObject();
	if (xmlHttps==null)
  	{
  		alert ("Your browser does not support AJAX!");
  		return;
  	}
  
  		var url="topsearchdata.php"; 
	  	url=url+"?country_id="+country_id+"&action=getstate&pseudoParam="+new Date().getTime();
	  	xmlHttps.onreadystatechange=stateStateChanged;
	  	xmlHttps.open("GET",url,true);
	  	xmlHttps.send(null);
}

function stateStateChanged()
{
	if (xmlHttps.readyState==4)
	{	
		document.getElementById("state_div").innerHTML=xmlHttps.responseText;
		document.getElementById("city_div").innerHTML='<select name="cityselect"><option>City</option>';
		document.getElementById("locality_div").innerHTML='<select name="localityselect"><option>Locality</option>';
	}
}

function getCity(state_id)
{
	xmlHttpc=GetXmlHttpObject();
	if (xmlHttpc==null)
  	{
  		alert ("Your browser does not support AJAX!");
  		return;
  	}
  
  		var url="topsearchdata.php"; 
	  	url=url+"?state_id="+state_id+"&action=getcity&pseudoParam="+new Date().getTime();
	  	xmlHttpc.onreadystatechange=cityStateChanged;
	  	xmlHttpc.open("GET",url,true);
	  	xmlHttpc.send(null);
}

function cityStateChanged()
{
	if (xmlHttpc.readyState==4)
	{	
		document.getElementById("city_div").innerHTML=xmlHttpc.responseText;
		document.getElementById("locality_div").innerHTML='<select name="localityselect"><option>Locality</option>';
	}
}

function getLocality(city_id)
{
	xmlHttpl=GetXmlHttpObject();
	if (xmlHttpl==null)
  	{
  		alert ("Your browser does not support AJAX!");
  		return;
  	}
  
  		var url="topsearchdata.php"; 
	  	url=url+"?city_id="+city_id+"&action=getlocality&pseudoParam="+new Date().getTime();
	  	xmlHttpl.onreadystatechange=localityStateChanged;
	  	xmlHttpl.open("GET",url,true);
	  	xmlHttpl.send(null);
}

function localityStateChanged()
{
	if (xmlHttpl.readyState==4)
	{	
		document.getElementById("locality_div").innerHTML=xmlHttpl.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;
}


function trim(sString)
{
	while (sString.substring(0,1) == ' ')
	{
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}

function validateSearch()
{
	if(trim(document.getElementById("keyword_textb").value).length<1)
	{
		alert("Please enter the search text");
		return false;
	}
	if(document.getElementById("countryselect").selectedIndex==0)
	{
		alert("Please select the country");
		return false;
	}
	if(document.getElementById("stateselect").selectedIndex==0)
	{
		alert("Please select the state");
		return false;
	}
	if(document.getElementById("cityselect").selectedIndex==0)
	{
		alert("Please select the city");
		return false;
	}
}