
var http_request = new Array();
var whatFunction = new Array();
/**
  * Function for making an XMLHTTP Request
  *
  * url	Url for the request
  * args Arguments passed to url and used in document location for bookmarking
  * myFunction Function to execute upon successful return of request
  *
  * Returns a true if required version or greater is installed, otherwise false.
  */
function makeRequest(url, args, myFunction) {
	nextReq = http_request.length;
	http_request[nextReq] = false;
    whatFunction[nextReq] = myFunction;
	//bookmarkVal  =  window.location.href.split("#")[0] + "#" + args;
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_request[nextReq] = new XMLHttpRequest();
	} else if (window.ActiveXObject) { // IE
		try {
			http_request[nextReq] = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request[nextReq] = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	if (!http_request[nextReq]) {
		alert('Giving up :( Cannot create an XMLHTTP instance');
	}
	try {
	http_request[nextReq].onreadystatechange = checkStatus;
	http_request[nextReq].open('GET', url + "?" + args, true);
	http_request[nextReq].send(null);
	} catch(e) {}
}

function makePOSTRequest(url, parameters, myFunction) {
	nextReq = http_request.length;
	http_request[nextReq] = false;
    whatFunction[nextReq] = myFunction;
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		 http_request[nextReq] = new XMLHttpRequest();
		 if (http_request[nextReq].overrideMimeType) {
			// set type accordingly to anticipated content type
				//http_request.overrideMimeType('text/xml');
				http_request[nextReq].overrideMimeType('text/html');
		 }
	} else if (window.ActiveXObject) { // IE
		 try {
				http_request[nextReq] = new ActiveXObject("Msxml2.XMLHTTP");
		 } catch (e) {
				try {
					 http_request[nextReq] = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {}
		 }
	}
	if (!http_request[nextReq]) {
		 alert('Cannot create XMLHTTP instance');
		 return false;
	}
	
	http_request[nextReq].onreadystatechange = checkStatus;
	http_request[nextReq].open('POST', url, true);
	http_request[nextReq].setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http_request[nextReq].setRequestHeader("Content-length", parameters.length);
	http_request[nextReq].setRequestHeader("Connection", "close");
	http_request[nextReq].send(parameters);
}

/**
  * Function for checking status of XMLHTTP Request
  *
  * Evaluates whatFunction upon successful request return.
  */
function checkStatus() {
	for (var i=0; i<http_request.length; i++) {
		if (http_request[i] != null) {
			if (http_request[i].readyState == 4) {
				// alert(http_request[i].status);
				if (http_request[i].status == 200) {
					if (whatFunction[i] != null) {
						var tempHolder = whatFunction[i]; 
						whatFunction[i] = null;
						try {
							eval(tempHolder);
						}
						catch(e) { }
						//Prevent return
						http_request[i] = null;
					}
					
				} else {
					//alert("Failed to load content!");
				}
			}
		}
	}
}

/**
  * Writes to the innerHTML of a DIV
  *
  * content Content to write into the DIV
  * divName Identifier of the DIV to write to
  *
  * Evaluates whatFunction upon successful request return.
	* Sets window URL to value of bookmarkVal.
  */
function writeInnerHTML(content, divName) {
	myDiv = document.getElementById(divName);
	myDiv.innerHTML = content;
	//window.location = bookmarkVal;
	//lastHref = window.location.href;
}


