function Ajax() {
    this.req = null;
    this.url = null;
    this.method = 'GET';
    this.async = true;
    this.status = null;
    this.statusText = '';
    this.postData = null;
    this.readyState = null;
    this.responseText = null;
    this.responseXML = null
    this.handleResp = null;
    this.responseFormat = 'text'; //'text', 'xml', or 'object'
    this.mimeType = null;
    
    /* Initialize the ajax object based on what browser the client is using. */
    this.init = function() {
        if(!this.req) {
        
            try {
                //Firefox, IE7, Safari
                this.req = new XMLHttpRequest();    
            } catch(e) {        
                try{
                    //IE6
                    this.req = new ActiveXObject('MSXML2.XMLHTTP');
                } catch(e) {
                    try {
                        //Earlier versions of IE                        
                        this.req = new ActiveXObject('Microsoft.XMLHTTP');
                    } catch(e) {
                        //All options have failed, return false
                        return false;
                    }
                }
            }//end nested try/catch blocks
            
        }//end if
        
        return this.req;
        
    };//end this.init
    
    /* Use this to make a request.*/
    this.doReq = function() {
        
        //call init to build object can check it's return state.
        if(!this.init()) {
            alert('Failed to build request object, please check browser compatibility.');
            return;
        }//end if
        
        //use the request object api to initialize a request
        this.req.open(this.method, this.url, this.async);
        if(this.mimeType) {
            try {
                req.overrideMimeType(this.mimeType);
            } catch(e) {
                //couldnt override MIME type -- IE6 or Opera
            }
        }
        var self = this;//Fix loss-of-scope in inner function
        this.req.onreadystatechange = function() {
            
            if(self.req.readyState == 4) {
                
                switch (self.responseFormat) {
                    case 'text':
                        resp = self.req.responseText;
                        break;
                    case 'xml':
                        resp = self.req.respoonseXML;
                        break;
                    case 'object':
                        resp = req;
                        break;
                }//end switch
                
                if(self.req.status >= 200 && self.req.status <= 299) {
                	
                    self.handleResp(resp);
                } else {
                    self.handleErr(resp);
                }//end if else
                
            }//end if
            
        }//end function
        
        this.req.send(this.postData);
    };//end doReq
    
    this.setMimeType = function(mimeType) {
        this.mimeType = mimeType;
    };
    
    this.handleErr = function() {
        var errorWin;
        try {
            errorWin = window.optin('', 'errorWin');
            errorWin.document.body.innerHTML = this.responseText;
        } catch(e) {
            alert('An error occurred, but the error message cannot be '
                + 'displayed. This is probably because of your browser\'s '
                + 'pop-up blocker.\n'
                + 'Please allow pop-ups from this web site if you want to '
                + 'see the full error messages.\n'
                + '\n'
                + 'Status Code: ' + this.req.status + '\n'
                + 'Status Description: ' + this.req.statusText);
        }
    }//end handleErr function
    
    this.setHandlerBoth = function(funcRef) {
        this.handleResp = funcRef;
        this.handleErr = funcRef;
    };
    
    this.abort = function() {
        if (this.req) {
            this.req.onreadystatechange = function() { };
            this.req.abort();
            this.req = null;
        }
    };
    
    this.doGet = function(url, hand, format) {
        this.url = url;
        this.handleResp = hand;
        this.responseFormat = format || 'text';
        this.doReq();
    };
}

