function URLencode(sStr) {
    return sStr.replace(/\+/g, '%2B').replace(/\"/g,'%22').replace(/\'/g, '%27').replace(/\//g,'%2F');
 }

function HttpRequest(url){
	
	var req=null;
	this.url=(url)? url:"";
    this.method="GET";      
	this.listener=null;
	var userListener=null;
        
        this.load=function(dados){
             // Procura por um objeto nativo (Mozilla/Safari)
             if (window.XMLHttpRequest) {
                 req = new XMLHttpRequest();
             // Procura por uma versao ActiveX (IE)
             } else if (window.ActiveXObject) {
                 req = new ActiveXObject("Microsoft.XMLHTTP");
             }
             if (req) {
                 req.onreadystatechange = this.requestListener;
		 if (this.method=="POST"){
		         req.open(this.method, this.url, true);
		         req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	             req.send(dados);
		} if (this.method=="GET"){
		         req.open(this.method, this.url+"?"+dados, true);
	                 req.send("");
		}
             } 
        }
	this.addEventListener=function(listener){
 		userListener=listener;
	}

	this.requestListener=function(){
		if (req.readyState == 4){
			var evt=new HttpResponse(req);
			userListener(evt);
		}
	}

}

function HttpResponse(req){
	this.req=req;
	this.getData=function(){
		return (this.req.responseText);
	}
	this.getStatus=function(){
		return (this.req.status);
	}
	this.getXML=function(){
		return (this.req.responseXML);
	}
}

