
//Global XMLHTTP Request object
var XmlHttp;
var ajaxServerPageName;

//Creating and setting the instance of appropriate XMLHTTP Request object to a “XmlHttp” variable  
function CreateXmlHttp()
{
	//Creating object of XMLHTTP in IE
	try
	{
		XmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			XmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch(oc)
		{
			XmlHttp = null;
		}
	}
	//Creating object of XMLHTTP in Mozilla and Safari 
	if(!XmlHttp && typeof XMLHttpRequest != "undefined") 
	{
		XmlHttp = new XMLHttpRequest();
	}
}

//Called when response comes back from server
function HandleResponse()
{
	// To make sure receiving response data from server is completed
	if(XmlHttp.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		if(XmlHttp.status == 200)
		{			
			OnSuccess(XmlHttp);
		}
		else
		{
			// we'd rather handle this silently for production (wb)
			//alert("There was a problem retrieving data from the server. status" + XmlHttp.status );
		}
	}
}

    function DataSubmit(data)
	{
		// send the request to the callback page if browser supports XMLHTTPRequest object
		CreateXmlHttp();
		if(XmlHttp)
		{
			//Setting the event handler for the response
			XmlHttp.onreadystatechange = HandleResponse;
			
			//Initializes the request object with POST, 
			//Request URL and sets the request as asynchronous.
			if(ajaxServerPageName) 
			{
				XmlHttp.open("POST", ajaxServerPageName, true);
				XmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
			
				//Sends the request to server
				XmlHttp.send(data);					
			}
			else
			{
				//Error: ajaxServerPageName is not define. 
				alert("ajaxServerPageName is not set to a value. Please assign it to your AJAX server page.");
			}
		}
	}

