﻿
var Ajax =  
{
	GetXMLHTTPRequest : function()
	{
		var oXMLHTTPRequest = null;
		try //IE
		{
			oXMLHTTPRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} 
		catch(err) 
		{
			try 
			{
				oXMLHTTPRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} 
			catch(err) 
			{
				oXMLHTTPRequest = null;
			}
		}
		
		if(!oXMLHTTPRequest) //Mozilla
		{
			oXMLHTTPRequest = new XMLHttpRequest();
		}
		
		return oXMLHTTPRequest;
	},
	
	HTTPServerRequest : function(strURL,strPostParams,bIsResponseXML,oCallBackFunction)
	{
		var oResponseData	= null;
		var oXMLHTTPRequest = this.GetXMLHTTPRequest();
		
		if(oXMLHTTPRequest)
		{
			var strMethod		= strPostParams ? 'POST' : 'GET';
			
			oXMLHTTPRequest.open(strMethod, strURL, true);
			oXMLHTTPRequest.onreadystatechange = function()
			{
				var bComplete = false;
				try
				{
  					if(oXMLHTTPRequest.readyState == 4 && oXMLHTTPRequest.status == 200)
  					{
  						bComplete = true;
  						if(bIsResponseXML)
  						{
	  						oResponseData = oXMLHTTPRequest.responseXML;
	  					}
	  					else
	  					{
	  						oResponseData = oXMLHTTPRequest.responseText;
	  					}
 	 				}
 	 			}
 	 			catch(ex)
 	 			{	
 	 				oResponseData	= null;
 	 				bComplete		= true;
 	 			}

 	 			if(bComplete && oCallBackFunction)
 	 			{
 	 				oCallBackFunction(oResponseData);
 	 			}
 	 		}
 	 		
 	 		if(strPostParams)
 			{
 				oXMLHTTPRequest.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
 			}
			oXMLHTTPRequest.send(strPostParams);
			
			
		}
		
		//return the request object
		return oXMLHTTPRequest;
	}
	
	
}

