//FUNCTIONS FOR HANDLING AJAX STUFF
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

//============================================================================================================
//THIS CODE COMES FROM THE QUIRKSMODE WEBSITE - LET'S SEE IF IT WORKS BETTER THAN MY SHABBY EFFORTS
var XMLHttpFactories = [
	function () {return new XMLHttpRequest()},
	function () {return new ActiveXObject("Msxml2.XMLHTTP")},
	function () {return new ActiveXObject("Msxml3.XMLHTTP")},
	function () {return new ActiveXObject("Microsoft.XMLHTTP")}
	];

function createXMLHTTPObject() {
	var xmlhttp = false;
	for (var i=0;i<XMLHttpFactories.length;i++) {
		try {
			xmlhttp = XMLHttpFactories[i]();
			}
		catch (e) {
			continue;
			}
		break;
		}
	return xmlhttp;
	}
//END OF QUIRKSMODE CODE
//==================================================================================================


/*
rCallAjax
~~~~~~~~~
Function: creates an Ajax handle then calls Ajax
Arguments: 
	URL of the script that will return the new code
Returns: none
	instead, it invokes a second function, rHandleAjaxReturn, which must be coded up and included on the
	webpage or the webpage's associated js file - the stuff returned by the ajax call is sent to rHandleAjaxReturn
	as a parameter ...
*/
function rCallAjax(rUrl, rAjaxHandle) {
	rAjaxHandle.open('GET', rUrl, true);
	rAjaxHandle.send(null);
	rAjaxHandle.onreadystatechange = function() {
		if(rAjaxHandle.readyState == 4) {
			if (rAjaxHandle.status == 200) {
				var rNewStuff = rAjaxHandle.responseXML;
				rHandleAjaxReturn(rNewStuff);
				}
			else {
				alert('There was a problem with the AJAX call ...\nURL: '
					+ rUrl
					+ '\nState: ' 
					+ rAjaxHandle.readyState 
					+ '\nStatus: ' 
					+ rAjaxHandle.status);
				}
			}
		};
	}

function sCallAjax(sUrl, sAjaxHandle) {
	sAjaxHandle.open('GET', sUrl, true);
	sAjaxHandle.send(null);
	sAjaxHandle.onreadystatechange = function() {
		if(sAjaxHandle.readyState == 4) {
			if (sAjaxHandle.status == 200) {
				var sNewStuff = sAjaxHandle.responseXML;
				sHandleAjaxReturn(sNewStuff);
				}
			else {
				alert('There was a problem with the AJAX call ...\nURL: '
					+ sUrl
					+ '\nState: ' 
					+ sAjaxHandle.readyState 
					+ '\nStatus: ' 
					+ sAjaxHandle.status);
				}
			}
		};
	}
