
var xmlHttp;

function getStates(str){
/*
	if (str.length==0){ 
		document.getElementById("lblwaitst").innerHTML="&nbsp;";
		return;
	}
*/

	//document.getElementById("lblwaitst").innerHTML="Loading...";
	xmlHttp=GetXmlHttpObject();

	if (xmlHttp==null){
		alert ("Your browser does not support AJAX!");
		return;
	} 

	var url="ajaxcode/state.php";
	url=url+"?id="+str;
	xmlHttp.onreadystatechange=stateChangedSt;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
} 

function getCities(st, cntryid){

	document.getElementById("lblwaitct").innerHTML="Loading...";
	xmlHttp=GetXmlHttpObject();

	if (xmlHttp==null){
		alert ("Your browser does not support AJAX!");
		return;
	} 

	var url="ajaxcode/city.php";
	url=url+"?st="+st+"&cntryid="+cntryid;
	xmlHttp.onreadystatechange=stateChangedCt;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
} 

function stateChangedSt(){ 
	if (xmlHttp.readyState==4){ 
		//document.getElementById("lblwaitst").innerHTML="&nbsp;";
		/*******************************************************************************/
		//BUG: Internet Explorer Fails to Set the innerHTML Property of the Select Object
		//Please refer to "http://support.microsoft.com/kb/276228"
		/*******************************************************************************/
		var stateText = '<select id="states" class="input_select" onchange="getCities(this.value)">' + xmlHttp.responseText + '</select>';
		document.getElementById("div_states").innerHTML=stateText;
	}
} 

function stateChangedCt(){ 
	if (xmlHttp.readyState==4){ 
		document.getElementById("lblwaitct").innerHTML="&nbsp;";
		var cityText = '<select id="cities" class="input_select">' + xmlHttp.responseText + '</select>';
		document.getElementById("div_cities").innerHTML=cityText;
	}
}

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 FetchDetails(varZip){
	
	xmlHttp=GetXmlHttpObject();

	if (xmlHttp==null){
		alert ("Your browser does not support AJAX!");
		return;
	}
	
	document.getElementById("region").value = "";
	document.getElementById("City").value = "";
	
	var url="ajaxcode/location.php";
	url=url+"?zip="+varZip;
	xmlHttp.onreadystatechange=stateChangedDt;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function stateChangedDt(){
	if (xmlHttp.readyState==4){
		var loc = xmlHttp.responseText.split("~");
		document.getElementById("region").value = loc[0];
		document.getElementById("City").value = loc[1];
	}
}