
function hxjAjax(async) {
    this.xmlhttp = null;
    this.async = (async) ? async : false;
    this.oncomplate = null;
    
    this._getHttpObj = function(){
    	if (typeof(XMLHttpRequest) != 'undefined')
    		return new XMLHttpRequest();
    
    	var axO = new Array('Msxml2.XMLHTTP.6.0', 'Msxml2.XMLHTTP.4.0', 'Msxml2.XMLHTTP.3.0', 'Msxml2.XMLHTTP', 'Microsoft.XMLHTTP');
    	for (var i=0; i<axO.length; i++) {
            try {
                return new ActiveXObject(axO[i]);
            }
            catch(e){
                //
            }
        }
        
    	return null;
    }
    this._onstatechangeHTTP = function() {
        if (this.xmlhttp.readyState == 4) {
            // Your callback code goes here
            if (this.oncomplate)
                this.oncomplate(this, this.xmlhttp.status);
        }
    }
    
    this.openURL = function(method, url, postbody){
        if (this.xmlhttp) {
            delete this.xmlhttp;
            this.xmlhttp = null;
        }
        
        this.xmlhttp = this._getHttpObj();
        if (!this.xmlhttp)
            return false;
        
        if (!postbody || postbody.length <= 0)
            postbody = null;

		if (url.charAt(0) == '/') {
        	url = "http://" + location.host + url;
        }
    	else {
    		if (url.substring(0,7) != "http://") {
    			var path = location.pathname;

				if (path.charAt(0) != '/')
					path = "/" + path;
    			path = path.substring(0, path.lastIndexOf("/")+1);    			
    			url = "http://" + location.host + path + url;
    		}
    	}
    	
    	try {
        	this.xmlhttp.open(method, url, this.async);
		
	        if (method.toUpperCase() == "POST") {
	            this.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	            if (postbody)
	                this.xmlhttp.setRequestHeader("Content-length", postbody.length);
	            
	            /* Force "Connection: close" for Mozilla browsers to work around
		         * a bug where XMLHttpReqeuest sends an incorrect Content-length
		         * header. See Mozilla Bugzilla #246651.
		         */
		      	if (this.xmlhttp.overrideMimeType)
		        	this.xmlhttp.setRequestHeader('Connection', 'close');
	        }
	        
	        if (this.async)
	            this.xmlhttp.onreadystatechange = this._onstatechangeHTTP;
	        this.xmlhttp.send(postbody);
	    }
	    catch(e){
            return false;
        }

        return true;
    }
    this.abort = function(){
        this.xmlhttp.abort();
    }
    this.response = function(xml){
        return (xml) ? this.xmlhttp.responseXML : this.xmlhttp.responseText;
    }
    this.getStatus = function(){
        return this.xmlhttp.status;
    }
}
