var xmlHttp
var http = getHTTPObject();
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 getHTTPObject() {
	var xmlhttp;
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
		try {
			xmlhttp = new XMLHttpRequest();
		} catch (e) {
			xmlhttp = false;
		}
	}
	return xmlhttp;
}
function stateChanged(location_id){
	var location_id = location_id;
	if(http.readyState == 4){
		document.getElementById('box'+location_id).innerHTML = http.responseText;
	}
}
function getLocation(location_id){
	var location_id = location_id;
	var content = document.getElementById(location_id).value;
	var state_id = document.getElementById('state_'+location_id).value;
	http.open("GET", "/get-location.php?content=" + escape(content) + "&location_id="+location_id+"&state_id="+state_id, true);
	http.onreadystatechange = function(){
		stateChanged(location_id);
	}
	http.send(null);
	if(content.length > 0){
		box('1', location_id);
	}else{
		box('0', location_id);
	}
}	
function box(act, location_id){
	var location_id = location_id;
	if(act == '0'){
		document.getElementById('box'+location_id).style.display = 'none';
	}else{
		document.getElementById('box'+location_id).style.display = 'block';
	}
}
function display(content_id, postcode, location_id){
	var content_id = content_id;
	var location_id = location_id;
	var postcode = postcode;
	document.getElementById(location_id).value = content_id + ", " + postcode;
	document.getElementById('box'+location_id).style.display = 'none';
}
