/*
Filename:                                                                       
    ajaxUtil.js                                                                
                                                                                
Description:

    This file supports AJAX functionality.  Typically we use ajax.js to do this. 
    The difference with this file is it encapsulates the functionality into an object
    which can be useful if you're doing multiple AJAX calls that could cause the global
    variables in ajax.js to be over-written. 
                                                                                
    History:                                                                        
    Ver         Inits   Date        Comments                                        
    1.00.00     jwl     6/14/07     Created.   

*/
     
// AJAXutil:
//
// This is the init method.
//
function AJAXutil()
{
    this.request = new Object();   

} // AJAXutil


// initReq:
//
// Initialize a request object that is already constructed.
//		Parameters:
//			reqType:	The HTTP request type, such as GET or POST.
//			url:		The URL of the server program.
//			isAsynch:	Whether to send the request asynchronously or not.
//
AJAXutil.prototype.initReq = function(reqType, url, callback, isAsync)
{
	// Specify the function that will handle the HTTP response.
	this.request.onreadystatechange = callback;
	this.request.open(reqType, url, isAsync);
	
	// Set the Content-Type header for a POST request
	if(reqType == "POST")
	{
		this.request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
		this.request.send(queryString);
	}
	else
		this.request.send(null); // Not posting anything to the page.
	
} // initReq


// httpRequest:
//
// This creates the XMLHttpRequest object.
//
//	Wrapper function for constructing a request object.
//		Parameters:
//			reqType:	The HTTP request type, such as GET or POST.
//			url:		The URL of the server program.
//			asynch:		Whether to  send the request asynchronously or not.
// 
AJAXutil.prototype.httpRequest = function(reqType, url, callback, async)
{
	// Mozilla-based browsers
	if(window.XMLHttpRequest)
		this.request = new XMLHttpRequest();
	else if(window.ActiveXObject)
	{
		this.request = new ActiveXObject("Msxml2.XMLHTTP");
		if(!this.request)
			this.request = new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	// Initialization succeeded
	if(this.request)
    	this.initReq(reqType, url, callback, async);
	else
		alert("Your browser does not permit the use of all of this application's features!");
	
} // httpRequest

