//-----------------------------------------------------------------------------------------------//
/* Create a new XMLHttpRequest object to talk to the Web server */
var xmlHttp = false;
var status;

//Check if we are using IE.
try {
	//If the Javascript version is greater than 5.
	xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
	//If not, then use the older active x object.
	try {
		//If we are using Internet Explorer.
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	} catch (E) {
		//Else we must be using a non-IE browser.
		xmlHttp = false;
	}
}

//If we are using a non-IE browser, create a javascript instance of the object.
if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
	xmlHttp = new XMLHttpRequest();
}

var loadingImg = new Image(20,20);
	loadingImg.src = "images/loading.gif";
var loadedImg = new Image(20,20);
	loadedImg.src = "images/loading_blank.gif";

//-----------------------------------------------------------------------------------------------//
function callServer(string, async) {

	// Build the URL to connect to
	var url = string;

	// Open a connection to the server
	var request = xmlHttp.open("GET", url, async);

	// Setup a function for the server to run when it's done
	xmlHttp.onreadystatechange = updatePage;

	// Send the request
	xmlHttp.send(null);
}
//-----------------------------------------------------------------------------------------------//
function callServerPost(url, parameters) {

	xmlHttp.onreadystatechange = updatePagePost;

	xmlHttp.open('POST', url, true);

	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", parameters.length);
	xmlHttp.setRequestHeader("Connection", "close");

	xmlHttp.send(parameters);
}
//-----------------------------------------------------------------------------------------------//
/*function updatePage() {
	if (xmlHttp.readyState == 4) {
		if (xmlHttp.status == 200) {
			var response = xmlHttp.responseText;
			//alert("Server is done!");
			//showArtistInfo(response);
		} else if (xmlHttp.status == 404) {
			//alert("Request URL does not exist");
		} else {
			//alert("Error: status code is " + xmlHttp.status);
		}
		done();
	}
}*/
//-----------------------------------------------------------------------------------------------//
/* function updatePagePost() {
	if (xmlHttp.readyState == 4) {
		if (xmlHttp.status == 200) {
			var response = xmlHttp.responseText;
			//alert("Server is done!");
		} else if (xmlHttp.status == 404) {
			//alert("Request URL does not exist");
		} else {
			//alert("Error: status code is " + xmlHttp.status);
		}
		done();
	}
} */
//-----------------------------------------------------------------------------------------------//
function loading(url, async) {

	if (document.getElementById('throb')) {
		document.getElementById('throb').src = loadingImg.src;
	}

	callServer(url, async);
}
//-----------------------------------------------------------------------------------------------//
function load() {
	if (document.getElementById('throb')) {
		document.getElementById('throb').src = loadingImg.src;
	}
}
//-----------------------------------------------------------------------------------------------//
function done() {
	if (document.getElementById('throb')) {
		document.getElementById('throb').src = loadedImg.src;
	}
}
//-----------------------------------------------------------------------------------------------//
// GTG: added the following (taken from the Beginning Ajax with PHP book)
function makerequest(serverPage, objID) {

		var obj = document.getElementById(objID);
		xmlHttp.open("GET", serverPage);
		xmlHttp.onreadystatechange = function() {
			if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
				obj.innerHTML = xmlHttp.responseText;
			}
		}
		xmlHttp.send(null);
	}
//-----------------------------------------------------------------------------------------------//