function ZHTTPRequest(method,type_res,async){
	this.method = method;
	this.async = async;
	this.timeout = 20000;
	this.responseFormat = type_res;
	this.onStartCallback_ = null;
	this.onCompleteCallback_ = null;
	this.onTimeoutCallback_ = null;
	this.onFailureCallback_ = null;
	this.xhr = null;
	
    if(typeof XMLHttpRequest != "undefined")
        this.xhr = new XMLHttpRequest();
    else if(window.ActiveXObject){
      	var xmlhttp_versions = ["Msxml2.XMLHTTP.7.0","Msxml2.XMLHTTP.6.0","MSXML2.XMLHttp.5.0","MSXML2.XMLHttp.4.0",
      							"MSXML2.XMLHttp.3.0","MSXML2.XMLHttp","Microsoft.XMLHttp"];

	    for(var i = 0; !this.xhr && i < xmlhttp_versions.length; i++){
	        try{
				this.xhr = new ActiveXObject(xmlhttp_versions[i]);
	        } 
	        catch (error){}
		}
    }
}

ZHTTPRequest.prototype = ZHTTPRequest;

ZHTTPRequest.prototype.setTimeout = function(value){
	this.timeout=value;
}

ZHTTPRequest.prototype.onTimeoutCallback_ = function(){
	alert('Server query timeout');
}	
	
ZHTTPRequest.prototype.setCompleteCallback = function(func){
	this.onCompleteCallback_ = func;
}

ZHTTPRequest.prototype.setTimeoutCallback = function(func){
	this.onTimeoutCallback_ = func;
}

ZHTTPRequest.prototype.setFailureCallback = function(func){
	this.onFailureCallback_ = func;
}

ZHTTPRequest.prototype.setStartCallback = function(func){
	this.onStartCallback_ = func;
}

ZHTTPRequest.prototype.query = function(url,data){                    
	
	if (this.method == "POST"){
		this.xhr.open(this.method,url,this.async);
		this.xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	}
	else
		this.xhr.open(this.method,url+'?'+data,this.async);	
									
	if (this.async){
		var ZHTTPRequest_ = this;
		if(this.timeout)
			var timeoutId = window.setTimeout(ZHTTPRequest_.abort, this.timeout);
			
		this.xhr.onreadystatechange = function () {
										if(ZHTTPRequest_.xhr.readyState == 4){
											if(ZHTTPRequest_.timeout)
												window.clearTimeout(timeoutId);
											if(ZHTTPRequest_.xhr.status == 200 || ZHTTPRequest_.xhr.status == 304){
												if(ZHTTPRequest_.responseFormat == "text")
													var response = ZHTTPRequest_.xhr.responseText;
												else
													var response = ZHTTPRequest_.xhr.responseXML;
												ZHTTPRequest_.onCompleteCallback_(response);
											}
											else if(ZHTTPRequest_.onFailureCallback_)
												ZHTTPRequest_.onFailureCallback_(ZHTTPRequest_.xhr.status);
										}
										else if(ZHTTPRequest_.xhr.readyState == 1 && ZHTTPRequest_.onStartCallback_)
											ZHTTPRequest_.onStartCallback_();
									  };
		if (this.method == "POST")
			this.xhr.send(data);
		else
			this.xhr.send(null);
	}
	else{
		if(this.timeout){
			var ZHTTPRequest_ = this;
			var timeoutId = window.setTimeout(ZHTTPRequest_.abort, this.timeout);
		}
		
		if (this.method == "POST"){
			this.xhr.open(this.method,url,this.async);
			this.xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			this.xhr.send(data);
		}
		else{
			this.xhr.open(this.method,url+'?'+data,this.async);
			this.xhr.send(null);
		}
		
		if (this.xhr.status == 200 || this.xhr.status == 304){
			if(this.timeout)
				window.clearTimeout(timeoutId);
			if (this.xhr.responseFormat == "text")
				var response = this.xhr.responseText;
			else
				var response = this.xhr.responseXML;
			
			this.onCompleteCallback_(response);
		}
		else if (this.onFailureCallback_)
			this.onFailureCallback_(this.xhr.status);
	}
}

ZHTTPRequest.prototype.abort = function(){
	if(this.xhr.readyState==1 || this.xhr.readyState==2 || this.xhr.readyState==3){
		this.xhr.abort();
		if(this.onTimeoutCallback_)
			this.onTimeoutCallback_();
	}
}


ZHTTPRequest.prototype.go = function(c){
	if(!c.data.replace(/\s/g,''))
		c.parentNode.removeChild(c);
}

ZHTTPRequest.prototype.cleanXML = function(d){
	var balises=d.getElementsByTagName('*');
	for(var i=0;i<balises.length;i++){
		a=balises[i].previousSibling;
		if(a && a.nodeType==3)
			ZHTTPRequest.go(a);
		b=balises[i].nextSibling;
		if(b && b.nodeType==3)
			ZHTTPRequest.go(b);
	}
	return d;
}