	var xmlhttp	
	var parse_id
	var parse_selected
	var parent
	var sta


function changeArea(div,div2,div3,tab) {

	navRoot = document.getElementById('tabnav');
	
	for (i=0; i<navRoot.childNodes.length; i++) {
		node = navRoot.childNodes[i];
		if (node.nodeName=="LI") {
			node.style.background="#e6e6e6";
			node.style.fontWeight="normal";
		}
	}

	
	tab.style.background='#ccdcfa';	

	document.getElementById(div).style.display='';
	document.getElementById(div2).style.display="none";
	document.getElementById(div3).style.display="none";

}


function populate_optimise(id, selected) {
	parse_id = id;
	parse_selected = selected;
	
	if(parse_id == "region") { 
		parent = "countries"
	}
	if(parse_id == "locality") { 
		parent = "region"
	}
	
	if(id == "null") {
			xmlhttp=null
			if (window.XMLHttpRequest){
				xmlhttp=new XMLHttpRequest()	
			} else if (window.ActiveXObject) {
				xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
			}
			
			if (xmlhttp!=null) {
				var url=SITE_ROOT+"subloc_optimise.ajax.php"
				url=url+"?i="+selected+"&p="+id;
				xmlhttp.open("POST",url,true)
				xmlhttp.setRequestHeader('Content-Type','text/xml'); 
				xmlhttp.send(null);
			} else {
				alert("Sorry, your browser does not support XMLHTTP.\n Please disable Javascript and try again.")
			}
	} else {
	
		if(selected != "null") {
		
			xmlhttp=null
			if (window.XMLHttpRequest){
				xmlhttp=new XMLHttpRequest()	
			} else if (window.ActiveXObject) {
				xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
			}
			
			if (xmlhttp!=null) {
				var url=SITE_ROOT+"subloc_optimise.ajax.php"
				url=url+"?i="+selected+"&p="+id;
				xmlhttp.onreadystatechange=parse_sublocs
				xmlhttp.open("POST",url,true)
				xmlhttp.setRequestHeader('Content-Type','text/xml'); 
				xmlhttp.send(null);
			} else {
				alert("Sorry, your browser does not support XMLHTTP.\n Please disable Javascript and try again.")
			}
		
		} else {
			
			if(parse_id == "region") {
				document.getElementById('submit_locality').style.visibility="hidden"
				document.getElementById('locality').options.length=0;
				document.getElementById('locality').options[0] = new Option("-- locality", "null");	
			}
			document.getElementById(parse_id).options.length=0;
			document.getElementById(parse_id).options[0] = new Option("-- "+parse_id, "null");

			
			xmlhttp=null
			if (window.XMLHttpRequest){
				xmlhttp=new XMLHttpRequest()	
			} else if (window.ActiveXObject) {
				xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
			}
			
			if (xmlhttp!=null) {
				var url=SITE_ROOT+"subloc_optimise.ajax.php"
				url=url+"?i="+selected+"&p="+id;
				xmlhttp.open("POST",url,true)
				xmlhttp.setRequestHeader('Content-Type','text/xml'); 
				xmlhttp.send(null);
			} else {
				alert("Sorry, your browser does not support XMLHTTP.\n Please disable Javascript and try again.")
			}
	
		}
	}
}


function populate(id, selected) {
	parse_id = id;
	parse_selected = selected;
	
	if(parse_id == "region") { 
		parent = "countries"
	}
	if(parse_id == "locality") { 
		parent = "region"
	}
	
	if(id == "null") {
		document.getElementById(selected).style.visibility="visible"
	} else {
	
		if(selected != "null") {
		
			xmlhttp=null
			if (window.XMLHttpRequest){
				xmlhttp=new XMLHttpRequest()	
			} else if (window.ActiveXObject) {
				xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
			}
			
			if (xmlhttp!=null) {
				var url=SITE_ROOT+"subloc.ajax.php"
				url=url+"?i="+selected+"&p="+id;
				xmlhttp.onreadystatechange=parse_sublocs
				xmlhttp.open("POST",url,true)
				xmlhttp.setRequestHeader('Content-Type','text/xml'); 
				xmlhttp.send(null);
			} else {
				alert("Sorry, your browser does not support XMLHTTP.\n Please disable Javascript and try again.")
			}
		
		} else {
			btn4 = "submit_"+parse_id;
			document.getElementById(btn4).style.visibility="hidden"
			btn5 = "submit_"+parent;
			document.getElementById(btn5).style.visibility="hidden"
			if(parse_id == "region") {
				document.getElementById('submit_locality').style.visibility="hidden"
				document.getElementById('locality').options.length=0;
				document.getElementById('locality').options[0] = new Option("-- locality", "null");	
			}
			document.getElementById(parse_id).options.length=0;
			document.getElementById(parse_id).options[0] = new Option("-- "+parse_id, "null");	
		}
	}
}

function parse_sublocs() {
	
	if (xmlhttp.readyState==1) {
		document.getElementById(parse_id).options.length=0;
		document.getElementById(parse_id).options[0] = new Option(" loading "+parse_id+" list", "null");
	}
			 
	if (xmlhttp.readyState==4) { 
		if (xmlhttp.status==200){ 	
					var parent=xmlhttp.responseXML.getElementsByTagName("PARENT")[0].childNodes[0].nodeValue;

			var count=xmlhttp.responseXML.getElementsByTagName("COUNTER")[0].childNodes[0].nodeValue;
			var parentname=xmlhttp.responseXML.getElementsByTagName("PARENTNAME")[0].childNodes[0].nodeValue;

			var locs=xmlhttp.responseXML.getElementsByTagName("LOC");
			var locsids=xmlhttp.responseXML.getElementsByTagName("LOCID");
			
			btn = "submit_"+parent;
			document.getElementById(btn).style.visibility="visible"
			
			if(count > 0) {
				document.getElementById(parse_id).options.length=0;
				document.getElementById(parse_id).options[0] = new Option("-- select a "+parse_id+" in "+parentname, "null");
				i=0;
				for ( var z=0, opt=locs.length; z<opt; ){
					z++; document.getElementById(parse_id).options[z] = new Option(locs[i].childNodes[0].nodeValue,locsids[i].childNodes[0].nodeValue); 
					document.getElementById(parse_id).options[z].setAttribute("id",parse_id+"_"+locsids[i].childNodes[0].nodeValue);
					
					try {
						if(parse_id+"_"+locsids[i].childNodes[0].nodeValue == USER_REGION) {
						
							document.getElementById(parse_id).options[z].selected="true";
							populate('locality',locsids[i].childNodes[0].nodeValue);
							
						} else if(parse_id+"_"+locsids[i].childNodes[0].nodeValue == USER_LOCALITY) {
						
							document.getElementById(parse_id).options[z].selected="true";
							
						}
					} catch(e) {}
					
					i++;
				} 
			
			} else {
				btn2 = "submit_"+parse_id;
				document.getElementById(btn2).style.visibility="hidden"
				document.getElementById(parse_id).options.length=0;
				document.getElementById(parse_id).options[0] = new Option(" -- no "+parse_id+" found", "null");
			}
			
		} else {
			document.getElementById(parse_id).options.length=0;
			document.getElementById(parse_id).options[0] = new Option(" -- no "+parse_id+" found", "null");
		}
	}
}