function Ajax(URL,IdRetorno,MostraCarreg){
	var ObjAjax = InstanAjax();
	var IdRetorno = document.getElementById(IdRetorno);
	var Carregando = "<div class='Carregando'><img src='_img/IconeCarregando.gif' alt='...' />&nbsp;</div>";
	if(ObjAjax){
		URL = AntiCache(URL);
		ObjAjax.onreadystatechange = AjaxOnReady;
		ObjAjax.open("GET", URL ,true);
         //ajax1.setRequestHeader("Content-Type", "text/html; charset=iso-8859-1");//"application/x-www-form-urlencoded");
		if(MostraCarreg){
			 ColocaVar(Carregando);
		}
		ObjAjax.send(null)
		return true;
	} else {
		return false;
	}
	function AjaxOnReady(){
		if(ObjAjax.readyState==4){
			if(ObjAjax.status == 200){
				var Texto=ObjAjax.responseText;
				//texto=unescape(texto); //descomente esta linha se tiver usado o urlencode no php ou asp
				ColocaVar(Texto);
			} else {
				if(MostraCarreg){
					ColocaVar("Falha no carregamento. " + StatusHttp(ObjAjax.status));
				}
			}
			ObjAjax = null;
		} else if(MostraCarreg) {
			ColocaVar(Carregando);
		}
	}
	function ColocaVar(Valor){
		if((typeof(IdRetorno)).toLowerCase()=="string"){
			if(Valor!="Falha no carregamento"){
				eval(IdRetorno+'=unescape("'+escape(Valor)+'")');
			}
		} else if(IdRetorno.tagName.toLowerCase()=="input"){
			Valor = escape(Valor).replace(/\%0D\%0A/g,"")
			IdRetorno.value = unescape(Valor);
		} else if(IdRetorno.tagName.toLowerCase()=="select"){        
			select_innerHTML(IdRetorno,Valor)
		} else if(IdRetorno.tagName){
			IdRetorno.innerHTML = Valor;
		}    
	}
	function InstanAjax(){
		if(typeof(XMLHttpRequest)!='undefined'){
			return new XMLHttpRequest();
		}
		var ArrayObj=['Microsoft.XMLHTTP','Msxml2.XMLHTTP','Msxml2.XMLHTTP.6.0','Msxml2.XMLHTTP.4.0','Msxml2.XMLHTTP.3.0'];
		for(var i=0;i<ArrayObj.length;i++){ 
			try{ 
				return new ActiveXObject(ArrayObj[i]);
			}
			catch(e){}
		}
		return null;
	}
	function StatusHttp(Status){
		switch(Status){
			case 0: 
				return "Erro desconhecido de javascript";
				break;
			case 400: 
				return "400: Solicita&ccedil;&atilde;o incompreensível"; 
				break;
			case 404: 
				return "404: N&atilde;o foi encontrada a URL solicitada"; 
				break;
			case 405: 
				return "405: O servidor n&atilde;o suporta o m&eacute;todo solicitado"; 
				break;
			case 500: 
				return "500: Erro desconhecido de natureza do servidor"; 
				break;
			case 503: 
				return "503: Capacidade m&aacute;xima do servidor alcançada"; 
				break;
			default: 
				return "Erro "+Status+"."; 
				break;
		}
	}
	function AntiCache(URL){
		var Data = new Date();
		if(URL.indexOf("?")>=0){
			return URL+"&"+encodeURI(Math.random()+"_"+Data.getTime());
		} else { 
			return URL+"?"+encodeURI(Math.random()+"_"+Data.getTime());
		}
	}
}