/**************************************************************/
/*   class HttpRequest										*/
/**************************************************************/
var reqParent = null;
var req;
function HttpRequest(window)
{
	this.responseText	 = "empty";
	this.responseXML	 = "";
	this.method   		 = "POST";
	this.endpoint 		 = null; 
//	this.errorStatus 	 = null;
//	this.errorStatusText = null;

	this.init = function InitHttpRequest()
	{
	    if (window.XMLHttpRequest)
	        req = new XMLHttpRequest();
	    else
		{
 			var XmlHttpVersion = new Array ("MSXML2.XMLHTTP.6.0",
											"MSXML2.XMLHTTP.5.0",
											"MSXML2.XMLHTTP.4.0",
											"MSXML2.XMLHTTP.3.0",
											"MSXML2.XMLHTTP",
											"Microsoft.XMLHTTP");
			for (var i_xml = 0; i_xml < XmlHttpVersion.length; i_xml++)
			{
				try
				{
					req = new ActiveXObject (XmlHttpVersion[i_xml])
				}
				catch (e)
				{
				}
			}
		}
		if (!req) 
		{
        	 alert('Cannot create XMLHTTP instance');
        	 return false;
      	}	    
		reqParent = this;
	    req.onreadystatechange = processResponse;
	}
	
	this.loadAsync = function LoadAsyncHttpRequest(body, callBackFunc)
	{
		this.load(body, true);
		if (this.responseXML != "")
			callBackFunc(this.responseXML);
	}
	
	this.load = function LoadHttpRequest(body, async)
	{
		if (async == null || async == 'undefined') 
			async = false;
		if (this.method == "GET")
		{
			try
			{		
				req.open(this.method, this.endpoint + "?" + body, async);
		    	req.send(null);
			}
			catch (e)
			{
				req.open(this.method, this.endpoint + "?" + body, async);
	    		req.send(null);
			}
		}
		else
		{
			try
			{
			    req.open(this.method, this.endpoint, async);
				req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; text/xml; charset=utf-8");
				req.setRequestHeader("Content-length", body.length);
		  	    req.send(body);
			}
			catch (e)
			{
			    req.open(this.method, this.endpoint, async);
				req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; text/xml; charset=utf-8");
				req.setRequestHeader("Content-length", body.length);
		  	    req.send(body);
			}
		}
		if (!async)	this.getResponse();
	}
	
	this.getResponse = function GetResponseHttpRequest()
	{
		if (req.readyState == 4)
			if (req.status == 200)
			{
//				alert(this.request.getAllResponseHeaders());
				this.responseText = req.responseText;
				this.responseXML  = req.responseXML;
				req.abort();
			}
	}
	
	this.getXML = function GetXMLHttpRequest()
	{
		return this.responseXML;
	}
	
	this.getText = function GetTextHttpRequest()
	{
		return this.responseText;
	}

	this.setMethodRequest = function SetMethodRequestHttpRequest(method)
	{
		this.method = method;
	}
	
	this.setEndPoint = function SetEndPointHttpRequest(endpoint)
	{
		this.endpoint = endpoint;
	}
	this.init();
}

function processResponse()
{
	if (req.readyState == 4)
	{
		if (req.status == 200)
		{
			reqParent.responseText = req.responseText;
			reqParent.responseXML  = req.responseXML;
		}
		else
			reqParent.responseText = "Error " + req.status + ":" + req.statusText;
	}
}


