// JavaScript Document
function getHTTPObject() {
	var xmlhttp;
	var browser=	 navigator.appName;
	if ( browser == "Microsoft Internet Explorer" ) {
		xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
	}
	else {
		xmlhttp= new XMLHttpRequest();
		xmlhttp.overrideMimeType('text/xml');
	}
	return xmlhttp;
}

var http = getHTTPObject();  //We create the HTTP Object

function doAJAX(param) {
	http.open("POST", "/admin/includes/ajax_functions.php", true);
	http.onreadystatechange = handleAJAX;
	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	http.send(param);
}

function handleAJAX() {
	if ( http.readyState == 4 ) {
		var xml = http.responseXML.getElementsByTagName('result')[0];
		var action = http.responseXML.getElementsByTagName('result')[0].getAttribute("action");
		switch(action) {
			case 'getNeighbourhoods':
				displayNeighbourhoods(xml);
				break;
			case 'getGMapsPointers':
				displayGMapPointers(xml);
				break;
			case 'getGMapsHomes':
				displayGMapPointers(xml);
				break;
		}
	}
}

function displayGMapPointers(xml) {
	showMarkers(xml);
}

function displayNeighbourhoods(xml) {
	var inputN = document.getElementById("neighbourhood");
	inputN.options.length = 0;
	var resultcount = xml.getElementsByTagName("Neighbourhood").length;
	var newOpt;
	for(i = 0; i<resultcount; i++) {
		newOpt= document.createElement('option');
		tmpNode = xml.getElementsByTagName("Neighbourhood")[i];
		newOpt.value = tmpNode.getElementsByTagName("ID")[0].childNodes[0].nodeValue;
		newOpt.text = tmpNode.getElementsByTagName("Name")[0].childNodes[0].nodeValue;
		try {
			inputN.add(newOpt, null);
		} catch(ex) {
			inputN.add(newOpt);
		}
	}
}