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;
}
	
var xmlHttp

function getSubAreas(field) { 
	xmlHttp=GetXmlHttpObject();

	if (xmlHttp==null) {
		alert ("Your browser does not support AJAX!");
		return;
	}

	var id = field.options[field.selectedIndex].value;
	var type = field.name;
	
	var url="getsubareas.php";
	url=url+"?id="+id;
	url=url+"&type="+type;
	url=url+"&sid="+Math.random();

	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}


/*function setSubAreas(id, type, selected) { 
	xmlHttp=GetXmlHttpObject();

	if (xmlHttp==null) {
		alert ("Your browser does not support AJAX!");
		return;
	}
	
	var url="getsubareas.php";
	url=url+"?id="+id;
	url=url+"&type="+type;
	url=url+"&loc="+selected;
	url=url+"&sid="+Math.random();

	xmlHttp.onreadystatechange=stateChanged2;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}*/

function stateChanged() {
	if (xmlHttp.readyState==4) {
		var xmlDoc = xmlHttp.responseXML.documentElement;
		var areatype = xmlDoc.getElementsByTagName("areatype")[0].childNodes[0].nodeValue;
		
		areabox = document.getElementById("sel"+areatype);
		areabox.options.length = 0;
		areabox.options[0] = new Option('All ' + areatype, '');
		
		for(i=0; i<xmlDoc.getElementsByTagName("aid").length; i++) {
			areabox.options[i+1] = new Option(xmlDoc.getElementsByTagName("name")[i].childNodes[0].nodeValue, xmlDoc.getElementsByTagName("aid")[i].childNodes[0].nodeValue)
		}
		
		if (areatype == "cities") {
			areabox = document.getElementById("sellocations");
			areabox.options.length = 0;
			areabox.options[0] = new Option('All Locations', '');
		}
	}
}
/*
function stateChanged2() {
	if (xmlHttp.readyState==4) {
		var xmlDoc = xmlHttp.responseXML.documentElement;
		var areatype = xmlDoc.getElementsByTagName("areatype")[0].childNodes[0].nodeValue;
		var currentloc = xmlDoc.getElementsByTagName("loc")[0].childNodes[0].nodeValue;

		areabox = document.getElementById("sel"+areatype);
		areabox.options.length = 0;
		areabox.options[0] = new Option('All ' + areatype, '');
	
		for(i=0; i<xmlDoc.getElementsByTagName("aid").length; i++) {
			areabox.options[i+1] = new Option(xmlDoc.getElementsByTagName("name")[i].childNodes[0].nodeValue, xmlDoc.getElementsByTagName("aid")[i].childNodes[0].nodeValue)
			if (areabox.options[i+1].value == currentloc) {
				areabox.options[i+1].selected = true;
			}
		}
		
		if (areatype == "cities") {
			areabox = document.getElementById("sellocations");
			areabox.options.length = 0;
			areabox.options[0] = new Option('All Locations', '');
		}
	}
}*/
