function AjaxReq(url,boxGeral,paramEspera,metodo,param,modo,boxResult,boxErro,processa){
	this.url = url;
	this.boxGeral = boxGeral;
	this.paramEspera = (paramEspera)? true : false;
	this.metodo = (metodo)? metodo : 'GET';
	this.param = (metodo == 'GET')? null : param;
	this.modo = (modo)? modo : 'T';
	this.boxResult = (boxResult)? boxResult : this.boxGeral;
	this.boxErro = (boxErro)? boxErro : this.boxGeral;
	this.processaRes = processa;
	
	//this.conectar();
}

AjaxReq.prototype = {
	conectar: function(){
		if(typeof(this.url)=='undefined' || this.url == ''){
			return false;
		}
		
		this.httpRequest = null;
		
		if(typeof(XMLHttpRequest)!='undefined'){
			this.httpRequest = new XMLHttpRequest();
		}else{
			var axO=['Microsoft.XMLHTTP','Msxml2.XMLHTTP','Msxml2.XMLHTTP.6.0','Msxml2.XMLHTTP.4.0','Msxml2.XMLHTTP.3.0'];
			
			for(var i=0;i<axO.length;i++){ 
				try{ 
						this.httpRequest = new ActiveXObject(axO[i]);
					}
				catch(e){} 
			}
		}
		
		if((typeof(this.httpRequest)!='undefined') || (this.httpRequest != null) || (this.httpRequest != '')){
			var objeto = this;
			this.httpRequest.onreadystatechange = function(){
				objeto.procRetorno.call(objeto);
			}
			this.httpRequest.open(this.metodo,this.url,true);
			if(this.metodo == 'POST'){
				this.httpRequest.setRequestHeader('Content-Type','application/x-www-form-urlencoded');	
			}
			
			if(this.metodo == 'GET' && this.modo == 'X'){
				this.httpRequest.setRequestHeader('Content-Type','application/xml');
			}else if(this.metodo == 'GET' && this.modo == 'T'){
				//this.httpRequest.setRequestHeader('Content-Type','application/xhtml+xml');
			}
			this.httpRequest.send(this.param);
		}
	},
	procRetorno: function(){
		if(this.httpRequest.readyState == 1){
			if(this.paramEspera == true){
				this.loading(false,this.boxGeral,true);
			}else{
				this.loading(true,this.boxErro,false);
			}
		}
		if(this.httpRequest.readyState == 4){
			if(this.httpRequest.status == 200){
				var resposta = (this.modo == 'T')? this.httpRequest.responseText : this.httpRequest.responseXML;
				this.loading(false,this.boxErro,false);
				if((typeof(this.processaRes)!='undefined') || (this.processaRes != null) || (this.processaRes != '')){
					//alert(resposta);
					this.processaRes(resposta);
				}else{
					alert("Erro: \n"+resposta);
				}
			}else{
				this.processaErro();
			}
		}
	},
	processaErro: function(){
		alert(this.httpRequest.status+" - "+this.httpRequest.statusText+" => "+this.url);
		document.getElementById(this.boxGeral).innerHTML = 'ERRO '+this.httpRequest.status+' - '+this.httpRequest.statusText;
	},
	loading: function(c,b,carrega){
		var df = document.getElementById(b);
		if(c == true){
			var i = document.createElement("IMG");
			i.setAttribute("src","../imagens/imgLoading.gif");
			i.setAttribute("id","loading");
			i.setAttribute("width","16");
			i.setAttribute("height","16");
			if(!document.getElementById('loading')){
				df.innerHTML = '&nbsp;';
				df.insertBefore(i, df.firstChild);
			}
		}else if(carrega == true){
			df.innerHTML = 'Carregando...';
		}else{
			var img = document.getElementById('loading');
			if(img){
				img.parentNode.removeChild(img);
			}else{
				df.innerHTML = '&nbsp;';
			}
		}
	}
}