Request = function()
{
    var req_ = null;    
    var callbackSuccess_ = null;
    var callbackFail_ = null;
    var error = null;
    
    this.SetErrorHandle = function(callback)
    {
        callbackFail_ = callback;
    }
    
    this.SetSuccessHandle = function(callback)
    {
        callbackSuccess_ = callback;
    }
    
    // initialize engine
    this.Initialize = function()
    {
        if(window.XMLHttpRequest)
        { 
            try {
			    req_ = new XMLHttpRequest();
            } catch(e) {
			    req_ = null;
            }
        } else if(window.ActiveXObject) {
       	    try {
        	    req_ = new ActiveXObject("Msxml2.XMLHTTP");
      	    } catch(e) {
        	    try {
          		    req_ = new ActiveXObject("Microsoft.XMLHTTP");
        	    } catch(e) {
          		    req_ = null;
        	    }
		    }
        }
    }   
        
    // POST request
    this.Post = function(url, callbackSuccess, callbackFail, data)
    {
        this.Send(url, callbackSuccess, callbackFail, true, data);
    }
    
    // GET request
    this.Get = function(url, callbackSuccess, callbackFail)
    {
        this.Send(url, callbackSuccess, callbackFail, false);
    }
    
    // send    
    this.Send = function(url, callbackSuccess, callbackFail, isPost, data)
    {        
        this.Initialize();
	    if(req_ == null) return;

        callbackSuccess_ = callbackSuccess;
        callbackFail_ = callbackFail;
        	        
	    var currentCall = this;
	    	            	    	    
	    req_.onreadystatechange = OnReadyStateChange;
	    try
	    {
	        if (isPost == true)
	        {
	            req_.open("POST", url, true);
	            req_.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
                req_.send(data);
	        }
	        else
	        {	
	            req_.open("GET", url, true);
                req_.send(null);
	        }
		    
        }
        catch (e) 
        { 
            if (callbackFail_ != null)
            {
                callbackFail_("Exception thrown while getting information from the server.");
            }
            return;
        }
                                
        function OnReadyStateChange()
        {        
            var request = req_;
            if (request && request.readyState != 4) return;
            
            if (request.status == 200)
		    {		
		        var response = request.responseText;	            	
		        if(response != "")
			    {
			        ParseResponse(response);			        
			    }
		    }
		    else
		    {
		        if (callbackFail_ != null)
		        {
		            callbackFail_(request.status);
                }
		    }
        }
        
        // parse response
        function ParseResponse(response)
        {
            var start = response.indexOf("<Fail>");
            var end = response.indexOf("</Fail>");
            
            if (start != -1 && end != -1)
            {
                if (callbackFail_ != null)
                {
                    start = response.indexOf("<Message>");
                    end = response.indexOf("</Message>");
                    
                    var data = response.substring(start + 9, end);                
                    callbackFail_(data);
                }                
            }
            else
            {
                if (callbackSuccess_ != null)
                {
                    start = response.indexOf("<Success>");
                    end = response.indexOf("</Success>");
                       
                    var data = response.substring(start + 9, end);
                    callbackSuccess_(data);
                }
            }            
        }    
    }            
}

GetXMLHTTP = function()
{
    var xmlHTTP = null;
    
    if (window.XMLHttpRequest)
    {
        try
        {
	        xmlHTTP = new XMLHttpRequest();
        } 
        catch(e)
        {
	        xmlHTTP = null;
        }
    }
    else if(window.ActiveXObject)
    {
        try
        {
	        xmlHTTP = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch(e)
        {
	        try
	        {
  		        xmlHTTP = new ActiveXObject("Microsoft.XMLHTTP");
	        }
	        catch(e)
	        {
  		        xmlHTTP = null;
	        }
        }
    }
    return xmlHTTP;
}   