function getXMLHttpRequestObject() {
	var ajax = false;
	if (window.XMLHttpRequest) {
		// IE 7, Mozilla, Safari, Firefox, Opera, most browsers:
		ajax = new XMLHttpRequest();
	} else if (window.ActiveXObject) { // Older IE browsers
		// Create type Msxml2.XMLHTTP, if possible:
		try {
			ajax = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) { // Create the older type instead:
			try {
				ajax = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) { }
		}	
	} // End of main IF-ELSE IF.
	// Return the value:
	return ajax;
} // End of getXMLHttpRequestObject() function.

function handleResponse(ajax, div) {
	// Check that the transaction is complete:
	if (ajax.readyState == 4) {
		// Check for a valid HTTP status code:
		if ((ajax.status == 200) || (ajax.status == 304) ) {
			// Put the received response in the DOM:
			var thisdiv = document.getElementById(div);
			thisdiv.innerHTML = ajax.responseText;
			// Make the results box visible:
			thisdiv.style.display = 'block';
		} else { // Bad status code, submit the form.
			//document.getElementById('dept_form').submit();
		}
	} // End of readyState IF.
} // End of handleResponse() function.

function runajax(getVars, phpfile, div) {
	// getVars: string of form arg1=val1&arg2=val2& ...
	// phpfile: php script that generates updated text
	// div: the ID of the div to display the updated text
	var ajax = getXMLHttpRequestObject();
	var ajaxMsg = false;
	if (ajax) {
		geturl = phpfile;
		vars = getVars.split("&");
		for(i=0; i<vars.length; i++) {
			thisvar = vars[i].split("=");
			if(i == 0) geturl += "?";
			else geturl += "&";
			geturl += thisvar[0] + "=" + encodeURIComponent(thisvar[1]);
		}
        ajax.open('get', geturl);
        ajax.onreadystatechange = function() {
			handleResponse(ajax, div);
        }
		ajax.send(null);
	} // End of ajax IF.
	else {
		alert('AJAX not working...');
	}
}

