function ajax()
{

    var _request = null;
    var _this = null;
    
    this.get_responseXML = function()
    {
        return (_request) ? _request.responseXML : null;
    }
    
    this.get_responseText = function()
    {
        return (_request) ? _request.responseText : null;
    }
    
    this.get_request = function()
    {
        return _request;
    }
    
    this.set_request_header = function(field, value)
    {
        if(_request) _request.setRequestHeader(field, value);
    }
    
    this.open_request = function(url)
    {
        _initialize_request()
        _this = this;
        
        _request.open('GET', url, true);
        this.set_request_header("Content-Type", "application/x-www-form-urlencoded; charset=ISO-8859-1");
    }
    
    this.commit = function(data)
    {
        if (_request) _request.send(data);
    }
    
    this.close = function()
    {
        if (_request) _request.abort();
    }
    
    
    
    // Public event declarations
    
    this.OnUninitialize = function() { };
    this.OnLoading = function() { };
    this.OnLoaded = function() { };
    this.OnInteractive = function() { };
    this.OnSuccess = function() {};
    this.OnFailure = function() {};
    
    
    
    // Private event declarations
    
    function _on_uninitialize() { _this.OnUninitialize(); };
    function _on_loading() { _this.OnLoading(); };
    function _on_loaded() { _this.OnLoaded(); };
    function _on_interactive() { _this.OnInteractive(); };
    function _on_success() { _this.OnSuccess(); };
    function _on_failure() { _this.OnFailure(); };
    
    
    
    // Privates functions
    
    function _get_XMLHttpRequest()
    {
        var xhr_object = null;

        try {xhr_object = new XMLHttpRequest();}
        catch (error)
        {
            try{xhr_object = new ActiveXObject("Msxml2.XMLHTTP");}
            catch (error)
            {
                try {xhr_object = new ActiveXObject("Microsoft.XMLHTTP");}
                catch (error)
                {
                    alert("ERROR: Your webbrowser does not support XMLHttpRequest object.");
                }
            }
        }
        return xhr_object;
    }
    
    function _state_handler()
    {
        switch (_request.readyState)
        {
            case 0:
                window.setTimeout("void(0)", 100);
                _on_uninitialize();
                break;
                                
            case 1:
                window.setTimeout("void(0)", 100);
                _on_loading();
                break;
                                
            case 2:
                window.setTimeout("void(0)", 100);
                _on_loaded();
                break;
                        
            case 3:
                window.setTimeout("void(0)", 100);
                _on_interactive();
                break;
                                
            case 4:
                if (_request.status == 200)
                {
                    _on_success();
                }
                else
                {
                    _on_failure();
                }
                                            
                return;
                break;
        }
    }
   
    function _initialize_request()
    {
        _request = _get_XMLHttpRequest();
        _request.onreadystatechange = _state_handler;
    }

}

