var xmlHttp;
var myselect;

function getLoc(url) {
	if (window.ActiveXObject) {        
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");   
	} else if (window.XMLHttpRequest) {       
		xmlHttp = new XMLHttpRequest();     
	}  
	xmlHttp.onreadystatechange = getLocXML;		
	xmlHttp.open("GET",url, true);   
	xmlHttp.send(null); 	
} 


function getLocXML() {
	var strText="";
	if (xmlHttp.readyState == 4) {      
		if (xmlHttp.status == 200) {        
			xmlDoc = xmlHttp.responseXML;

			var options = [];
			options = xmlDoc.documentElement.getElementsByTagName("Option");
				
			for (var i = 0; i < options.length; i++) {
				
				var AreaName = options[i].getAttribute("AreaName");
				var AreaID = AreaName//options[i].getAttribute("AreaID");
							
				var theOption=document.createElement("OPTION");
				var theText=document.createTextNode(AreaName);
				theOption.appendChild(theText);
				theOption.setAttribute("value", AreaID);
				
				myselect.appendChild(theOption);

			}

		}   
	} 
}

function changeStates(country_id, state_id, size){
	
	url = "/include/get-loc.php?task=state&country_id="+country_id+"&state_id="+state_id+"&size="+size+"&r="+Math.random();

	var request = new XHRequest().getObject();		
	request.onreadystatechange = function() {
		if (request.readyState == 4) {      
			if (request.status == 200) { 
				var text = request.responseText;
				document.getElementById("state_div").innerHTML = text;
			}
		}
	}
	request.open("GET", url, true);
	request.send(null);

}

function changeCities(state_id, city_id, size){

	url = "/include/get-loc.php?task=city&state_id="+state_id+"&city_id="+city_id+"&size="+size+"&r="+Math.random();

	var request = new XHRequest().getObject();		
	request.onreadystatechange = function() {
		if (request.readyState == 4) {      
			if (request.status == 200) { 
				var text = request.responseText;
				document.getElementById("city_div").innerHTML = text;
			}
		}
	}
	request.open("GET", url, true);
	request.send(null);
}

function submitLocForm(){
	document.theForm.alt_state_id.value = document.getElementById("state_id").value;
	document.theForm.alt_city_id.value = document.getElementById("city_id").value;

	//document.theForm.submit();
}