// JavaScript Document
var xhr = false;
var updateID



function makeRequest(url) {
// This is where the AJAX magic happens.  This function sends the request to the fetch  
// the dynamic content.
	document.getElementById(updateID).innerHTML = "<img src='loading.gif'>";
	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(updateID).innerHTML = "Sorry, but I couldn't create an XMLHttpRequest";
	}
}

function showContents() {
// Once the AJAX has retrieved the data, this function writes it to the proper DIV.
	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(updateID).innerHTML = outMsg;
	}
}
