/*
	FUNCTION: 	getXMLHttpObject
	DESC:			takes no arguments and returns a XmlHttp object: objXmlHttp
*/
function getXmlHttpObject () {
	var objXMLHttp=null;
	//Generate an object for non IE browsers
	if (window.XMLHttpRequest) {
		  objXMLHttp=new XMLHttpRequest();
	}
	//Otherwise go with an IE version
	else if (window.ActiveXObject)  {
		//Here we try to see whether we have IE6 which uses a faster version of the interface
		try {
			objXMLHttp=new ActiveXObject("Msxml2.XMLHTTP")
		}
		//otherwise go with the base on in IE5.5
		catch(e) {
			 objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
		}
	}
	
	//return the object ready for use
	return objXMLHttp;
}

/*
	FUNCTION: 	stateChanged
	DESC:			Calls a processing function once the object is ready to be used.
*/
function stateChanged() { 
	//a readyState value of 4 or "complete" means our object is ready to use so change the boolean to true
	//alert(xmlHttp.readyState + '\n' + xmlHttp.responseText + '\n' + xmlHttp.status + '\n' + xmlHttp.statusText);
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
		//readyState is complete - but let's double check we got a 200 status
		if (xmlHttp.status == 200 && xmlHttp.statusText == "OK") {
				processResponse(xmlHttp);
		}
		else {
			//alert the error in retrieving the xml data
			alert('Problem retieving XML data. Error reported as: \n status: ' + xmlHttp.status + '\n status text: ' + xmlHttp.statusText);
		}
	} 
} 

/* 	FUNCTION:	processResponse
	DESC:		Empty function which is overloaded by calling code to the stateChanged function to handle AJAX 			
				response
*/
function processResponse() {
}

/*
	FUNCTION: 	parseXML
	DESC:			Not strictly speaking an AJAX function but as most of what we do with AJAX involves XML seems logical to have it here.
						This function takes a string of XML calls the REXML method from the rexml.js library and creates an xmlDoc object which is then parsed into a JS object and returned as xmlDoc.
						
						NOTE: Requires rexml.js file including
*/
function parseXML (strXML) {
	var xmlDoc = new REXML();
    xmlDoc.XML = strXML;
    xmlDoc.parse();
    
    return xmlDoc
}

