window.onload = initAjax;
var xhr = false;
var dest = "googlemap";

function initAjax(){
	document.getElementById("anorth").onclick = function(){
		getNewDirFile(this.href);
		return false;
	}
	document.getElementById("asouth").onclick = function(){
		getNewDirFile(this.href);
		return false;
	}
	document.getElementById("awest").onclick = function(){
		getNewDirFile(this.href);
		return false;
	}
}

function getNewDirFile(link){
	makeRequest(link);
	dest = "googlemap";
}

function makeRequest(url){
	if (window.XMLHttpRequest){
		xhr = new XMLHttpRequest();
	} else{
		if (window.ActiveXObject){
			try{
				xhr = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e){}
		}
	}

	if (xhr){
		xhr.onreadystatechange = showContents;
		xhr.open("GET", url, true);
		xhr.send(null);
	} else{
		document.getElementById(dest).innerHTML = "Sorry, but an error occured.";
	}	
}

function showContents(){
	if (xhr.readyState == 4){
		if (xhr.status == 200){
			var outMsg = (xhr.responseXML && xhr.responseXML.contentType=="text/xml") ? xhr.responseXML.getElementsByTagName("choices")[0].textContent : xhr.responseText;
		} else{
			var outMsg = "There was a problem with the request" + xhr.status;
		}
	document.getElementById(dest).innerHTML = outMsg;
	} 
}
