//This script file is used to provide Ajax services

//This function inistantiates and returns a XMLHTTPRequest object
function ajaxGetRequestObject(){

	var XMLHTTPRequest; 
	
	try{
		// Opera 8.0+, Firefox, Safari
		XMLHTTPRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			XMLHTTPRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				XMLHTTPRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Was not able to get a XMLHTTPRequest object
				alert("You browser does not meet the minimum requirements for this application.\nPlease contact the help desk.");
				return false;
			}
		}
	}

	//We have an object, return it
	return XMLHTTPRequest;
}

//This function sends the Ajax request.  The parameters for this method are:
//  XMLHTTPRequest = The XMLHTTPRequest object created from the ajaxGetRequestObject (or another method)
//  requestMethod = String value of "POST" or "GET", used to determine the type of request to process
//  URL = String value of the URL to send with the request
//  asyncMode = Boolean value specifying if asynchronous mode should be used
//
//The function ajaxReturn is called onReadyStateChange

function ajaxSendRequest(XMLHTTPRequest, requestMethod, URL, asyncMode) {

	//The response from the servlet will be passed back.  The ajaxReturn function must
	//exist in the calling script in order to get the reponse.
	XMLHTTPRequest.onreadystatechange = function() {ajaxReturn(XMLHTTPRequest);};

	if (requestMethod == "POST") {
		XMLHTTPRequest.open('POST', URL, asyncMode);
	} else {
		XMLHTTPRequest.open('GET', URL, asyncMode);
	}

	if (requestMethod == "POST") {
		XMLHTTPRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	}

	XMLHTTPRequest.send(null);

}
