function Ajax(url,method,cbf){
	this.act = false;
	this.xml = null;
    this.cbf = cbf;
    this.url = url;
	this.method = method;
	this.init();
	return this;
}
Ajax.prototype.init = function(){
	this.xml = (window.XMLHttpRequest ? new XMLHttpRequest : (window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : null));
	if(!this.xml){
		this.act = false;
	}else{
		this.act = true;
		//this.xml.owner = this;
	}
	this.encFunc = encodeURIComponent ? encodeURIComponent : escape;
}
Ajax.prototype.sendRQ = function (parameters,async){
    oAjax = this;
	if(!this.act){ return; }
	if(this.xml.readyState != 0){ this.xml.abort(); }
	
    //this.xml.onreadystatechange = function(){ajax.handleResponse(ajax);}
    //this.xml.onreadystatechange = new Function(this.name+".handleResponse("+this.name+");")
	//this.xml.onreadystatechange = function(){this.owner.handleResponse(this.owner);}
	this.xml.onreadystatechange = function(){oAjax.handleResponse(oAjax);};
	
	var sParams = '';
    for(var i=0; i<parameters.length; i++){
        sParams += (sParams.length > 0 ? "&" : "") + parameters[i][0] +"="+ this.encFunc(parameters[i][1]);
    }
    //alert(this.url +"?"+ sParams);
    if(async == null){async = true} 
	if(this.method.toUpperCase() == "GET"){
    	this.xml.open("GET",this.url +"?"+ sParams,async);
       	this.xml.send(null);
    }else{
        this.xml.open("POST",this.url,async);
        this.xml.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        this.xml.setRequestHeader("Content-length", sParams.length);
   	    this.xml.send(sParams);
    }
}

Ajax.prototype.handleResponse = function(ajax){
    switch(ajax.xml.readyState){
        case 0:
            //unitialized
            break;
        case 1:
            //loading
            break;
        case 2:
            //loaded
            break;
        case 3:
            //interactive
            break;
        case 4:
            //complete
            if(ajax.xml.status==200){
                if(typeof(ajax.cbf)=='function'){
                    ajax.cbf(ajax.xml.responseText)
                }
            }else{
                //alert(ajax.xml.responseText);
            }
    }
}


