
function WebResponse(eId, eMesg)
{
    this.eId = eId;
    this.eMesg = eMesg;
    this.webResponse = null;
	this.xmlResponse = null;
	
	function SetError(eId, eMesg)
	{
		this.eId = eId;
		this.eMesg = eMesg;
	}
} 


var xhttp =
{
    //xmlhttp : null,
    handler : null,
    uri     : "/ext/ext_services.php",
    init    : function ()
    {
        var xmlhttp;
        /*@cc_on @*/
	    /*@if (@_jscript_version >= 5)
	    try {
	        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP")
	    }   catch (e) {
	                try {
		                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP")
	                } catch (E) {
	                            xmlhttp = null
	                }
	        }
	    @else
	        xmlhttp = null
	    @end @*/
	    if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
	                try {
	                    xmlhttp = new XMLHttpRequest();
	                }   catch (e) {
	                            xmlhttp = null
	                    }
	    }
		
	    return xmlhttp;
    },
    
    doAsyncPost  : function (postData, getData, handler, uri)
    {
		try
		{
			var objResp = new WebResponse(0, "");
			var aHandler = handler, aUri = uri;
			var xmlhttp = this.init();
			if (handler == null)
				aHandler = this.handler;
			if (uri == null)
				aUri = this.uri;

			
			if (xmlhttp == null)
				throw "Error initializing the object";	 
				  	
			xmlhttp.open("POST", aUri + "?" + getData, true); 
			xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			xmlhttp.onreadystatechange = function() {
							if (xmlhttp.readyState != 4) 
								return;
							if (xmlhttp.status == 200)
							{
								if (aHandler != null)
								{
									var text = xmlhttp.responseText; 
									objResp.webResponse = text;
									objResp.xmlResponse = xmlhttp.responseXML;
									aHandler(objResp);
									
								}
							}
							else
								throw "Error occurred while retrieving from the server!";
								
						};
			xmlhttp.send(postData);
		}
		catch (ex)
		{
			return new WebResponse(1, ex);
		}
		return objResp;
    },
    
    
    doAsyncGet  : function (getData, handler, uri)
    {
		try
		{
			var objResp = new WebResponse(0, "");
			var aHandler = handler, aUri = uri;
			var xmlhttp = this.init();
			if (handler == null)
				aHandler = this.handler;
			if (uri == null)
				aUri = this.uri;
		   
			if (xmlhttp == null)
				throw "Error initializing the object";
		    		    
			if (getData != "")
			{
				aUri += "?" + getData;
			}
		    
			xmlhttp.open("GET", aUri, true); 
			xmlhttp.onreadystatechange = function() {
	        				if (xmlhttp.readyState != 4) 
								return;
							if (xmlhttp.status == 200)
							{
								if (aHandler != null)
								{
									var text = xmlhttp.responseText; 
									objResp.xmlResponse = xmlhttp.responseXML;
									objResp.webResponse = text;
									aHandler(objResp);
								}
							}
							else
								throw "Error occurred while retrieving from the server!";
						};
			xmlhttp.send(null);
		}
		catch (ex)
		{
			return new WebResponse(1, ex);
		}
		return objResp;
    },
    
    doSyncGet  : function (getData, uri)
    {
		try
		{
			var objResp = new WebResponse(0, "");
			var aUri = uri, respText = null;
			var xmlhttp = this.init();
			
			//if (this.xmlhttp == null)
			//	this.xmlhttp = this.init();
			if (uri == null)
				aUri = this.uri;
		   
			if (xmlhttp == null)
				throw "Error initializing the object";
					
			if (getData != "")
			{
				aUri += "?" + getData;
			}
		    
			xmlhttp.open("GET", aUri, false);
			xmlhttp.send(null);
		    
			if (xmlhttp.status == 200)
			{
				objResp.webResponse = xmlhttp.responseText;
				objResp.xmlResponse = xmlhttp.responseXML;
			}
			else
			{
				throw "Error occurred while retrieving from the server!";
			}
		}
		catch (ex)
		{
			return new WebResponse(1, ex);
		}
		return objResp;
    },
    
    doSyncPost  : function (postData, getData, uri)
    {
		try
		{
			var objResp = new WebResponse(0, "");
			var  aUri = uri, respText = null;
			var xmlhttp = this.init();
			//if (this.xmlhttp == null)
			//	this.xmlhttp = this.init();
			if (uri == null)
				aUri = this.uri;
		   
			if (xmlhttp == null)
				throw "Error initializing the object";
			if (getData != "")
			{
				aUri += "?" + getData;
			}
			
			xmlhttp.open("POST", aUri, false); 
			xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			xmlhttp.send(postData);
			if (xmlhttp.status == 200)
			{
				objResp.xmlResponse = xmlhttp.responseXML;
				objResp.webResponse =  xmlhttp.responseText;	
			}
			else
			{
				throw "Error occurred while retrieving from the server!";
			}
		}
		catch (ex)
		{
			return new WebResponse(1, ex);
		}
		
		return objResp;
    }
};
    
    
