// JavaScript Document
/*********************
This AJAX function allows you to pass a URL for an XML document and a function
to execute after the data has been loaded.
To call this function from your page, add this code to it
getData("mydocument.xml",theFunctionToRun, resType);
**********************/
var ajaxRequest;	// The request object made public to access it from other functions
var xmldata;		// Returned XML data
var responseType;	// responseText or responseXML
var execFunct;		// Function to execute after data's been received
var async;

function getData(url, funct, resType, aSync) {
	var now = new Date();
	responseType = resType;
	async = aSync;
	createRequest();
	execFunct = funct;
	ajaxRequest.onreadystatechange = myFunction;
	
	if(document.all) {
		url = url + "?blah=" + (new Date()).getTime();
	}
	
	(!async) ? ajaxRequest.open("GET", url , true) : ajaxRequest.open("GET", url , false)
	ajaxRequest.send(null);
}

function createRequest(){
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Your browser doesn't support XML requests. In other words, you need a modern browser");
				return false;
			}
		}
	}
}
  

function myFunction() {
	// The following will check if the data has been received
	if(ajaxRequest.readyState == 4) {
		
		(responseType == 'responseText') ? xmldata = ajaxRequest.responseText : xmldata = ajaxRequest.responseXML;
	
	execFunct(); // The variable execFunct holds the name of the function to run after getting data

	}
}
