var request = null;	
function createRequestObject()
{
	try
	{
		request = new XMLHttpRequest();
	
	}
	catch ( tryMicrosoft )
	{
		try
		{
			request = new ActiveXObject("Msxml2.XMLHTTP");
		
		}
		catch ( otherMicrosoft )
		{
			try
			{
				request = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch ( failed )
			{
				request = null;
			}
		}
	}
	
	if ( request == null )
	{
	}
	else
	{
	  return request;
	}

}

/*
	sendRequest sends the request to the backend server for processing.
	The action parameter should be the application the request should go to.
	formParameters should be the formatted form variables to be sent to the server.
	stateChangeMethod is the method to be called when the request is complete and 
	and a response has been received. The form for this viriable should be method name only (ie updatePage )
	with no parenthesis. stateChangeErrorMethod is the method name that should be called
	when the server responds with an error, this being a status <>200.
	asynchronous should be true or false, dictating 
	if the browser should for a response or not.
*/
function sendRequest( action, formParameters, stateChangeMethod, stateChangeErrorMethod, asynchronous )
{
	request = createRequestObject();

	if ( request != null )
	{
		request.open("POST", action , asynchronous );
		request.onreadystatechange = function()
									{
										if ( request.readyState == 4 )
										{
											if ( request.status == 200 )
											{
												if ( stateChangeMethod != '' )
												{
													eval( stateChangeMethod )
												}
											}
											else
											{
												if ( stateChangeErrorMethod != '' )
												{
													eval( stateChangeErrorMethod );
												}
											}
										}
									
									}
									
		request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		request.send( formParameters );
	}	
}

function formatFormParametersToURI( form )
{
	var formStr = ""
	for ( var i=0; i<form.elements.length; i++ )
	{
		if ( i != 0 )
		{
			formStr += '&';
		}
		formStr += form.elements[i].name + '=' + escape( form.elements[i].value );
	}
	
	return formStr;
}

function SendRequest()
{
	this.request = null;
	this.stateChangeSuccess = null;
	this.stateChangeError = null;
}

SendRequest.prototype.createRequestObj = function()
{
	try
	{
		this.request = new XMLHttpRequest();
	
	}
	catch ( tryMicrosoft )
	{
		try
		{
			this.request = new ActiveXObject("Msxml2.XMLHTTP");
		
		}
		catch ( otherMicrosoft )
		{
			try
			{
				this.request = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch ( failed )
			{
				this.request = null;
			}
		}
	}		
}
//end createRequestObj


	/*
	sendRequest sends the request to the backend server for processing.
	The action parameter should be the application the request should go to.
	formParameters should be the formatted form variables to be sent to the server.
	stateChangeMethod is the method to be called when the request is complete and 
	and a response has been received. The form for this viriable should be method name only (ie updatePage )
	with no parenthesis. stateChangeErrorMethod is the method name that should be called
	when the server responds with an error, this being a status <>200.
	asynchronous should be true or false, dictating 
	if the browser should for a response or not.
	*/
SendRequest.prototype.sendRequest = function( action, formParameters, stateChangeMethod, stateChangeErrorMethod, asynchronous )
{
	this.createRequestObj();
	this.stateChangeError = stateChangeErrorMethod;
	this.stateChangeSuccess = stateChangeMethod;
	var req = this.request;
	if ( req != null )
	{
		req.open("POST", action , asynchronous );
		if ( asynchronous )
		{
			req.onreadystatechange = this.processStateChange();
		}
									
		req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		req.send( formParameters );
		
		if ( asynchronous == false )
		{
			this.processStateChange();
		}
	}	
}
	//end sendRequest

SendRequest.prototype.processStateChange = function()
{
	if ( this.request.readyState == 4 )
	{
		if ( this.request.status == 200 )
		{
			if ( this.stateChangeSuccess != '' )
			{
				eval( this.stateChangeSuccess )
			}
		}
		else
		{
			if ( this.stateChangeError != '' )
			{
				eval( this.stateChangeError );
			}
		}
	}
	
}
	
SendRequest.prototype.getResponseText = function()
{
	return this.request.responseText;
}
//end getResponseText
	
SendRequest.prototype.getResponseXML = function()
{
	return this.request.responseXML;
}
//end getResponseXML



