function ajaxDM(url,parametros,elemento_retorno,msgCarregando){
    var elementoRetorno = document.getElementById(elemento_retorno);
	var imgCarregando = '';//'<span><img border=\'0\' src=\'http://localhost/eventos/intranet/img/carregando.gif\'/>&nbsp;&nbsp;</span>';
	if(msgCarregando.length>0){
		msgCarregando = imgCarregando + msgCarregando;
	};
	var ajax1 = pegaAjax();
	if(ajax1){
		url = antiCacheRand(url);
		ajax1.onreadystatechange = ajaxOnReady;
		ajax1.open("POST", url ,true);
		ajax1.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=iso-8859-1");
		ajax1.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
		ajax1.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
		ajax1.setRequestHeader("Pragma", "no-cache");
		if(msgCarregando.length>0){put(msgCarregando)};
		ajax1.send(parametros);
		return true;
	}else{
		return false;
	};
	function ajaxOnReady(){
		if (ajax1.readyState==4){
			if(ajax1.status == 200){
				var texto=ajax1.responseText;
				if(texto.indexOf(" ")<0){
					texto=texto.replace(/\+/g," ");
				};
				texto=unescape(texto);
				put(texto);
				mudarTitulo(texto);
				extraiScript(texto);
			}else{
				var texto=ajax1.responseText;
				if(texto.indexOf(" ")<0){
					texto=texto.replace(/\+/g," ");
				};
				texto=unescape(texto);
				put(texto);
				mudarTitulo(texto);
				extraiScript(texto);
				//if(msgCarregando.length>0){put("Falha no carregamento. " + httpStatus(ajax1.status));}
			}
			ajax1 = null;
		}else if(msgCarregando.length>0){
			put(msgCarregando);
		};
	};
	function put(valor){
		if((typeof(elementoRetorno)).toLowerCase()=="string"){
			if(valor!="Falha no carregamento"){ 
				eval(elementoRetorno + '= unescape("' + escape(valor) + '")');
			};
		}else if(elementoRetorno.tagName.toLowerCase()=="input"){
			valor = escape(valor).replace(/\%0D\%0A/g,"");
			elementoRetorno.value = unescape(valor);
		}else if(elementoRetorno.tagName.toLowerCase()=="select"){        
			select_innerHTML(elementoRetorno,valor);
		}else if(elementoRetorno.tagName){
			elementoRetorno.innerHTML = valor;
		};
	};
	function pegaAjax(){
		if(typeof(XMLHttpRequest)!='undefined'){
			return new XMLHttpRequest();
		};
		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{
				return new ActiveXObject(axO[i]);
			}catch(e){};
		};
		return null;
	};
	function httpStatus(stat){
		switch(stat){
			case 0: return "Erro desconhecido de javascript";
			case 400: return "400: Solicita&ccedil;&atilde;o incompreensível"; break;
			case 403: 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 " + stat + ".\nMais informa&ccedil;&otilde;es em http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html"; break;
		};
	};
	function antiCacheRand(aurl){
		var dt = new Date();
		if(aurl.indexOf("?")>=0){
			return aurl + "&" + encodeURI(Math.random() + "_" + dt.getTime());
		}else{
			return aurl + "?" + encodeURI(Math.random() + "_" + dt.getTime());
		};
	};
	function mudarTitulo(texto){
		texto = texto.replace(/\n/g,"");
		var inicio = 0;
		inicio = texto.indexOf('<title', inicio);
		if (inicio >=0){
			inicio = texto.indexOf('>', inicio)+1;
			var fim = texto.indexOf('/title>', inicio);
			var fim = texto.indexOf('<', inicio);
			Titulo = texto.substring(inicio,fim);
			document.title=Titulo;
		};
	};
	function select_innerHTML(objeto,innerHTML){
		objeto.innerHTML = "";
		var selTemp = document.createElement("micoxselect");
		var opt;
		selTemp.id="micoxselect1";
		document.body.appendChild(selTemp);
		selTemp = document.getElementById("micoxselect1");
		selTemp.style.display="none";
		if(innerHTML.toLowerCase().indexOf("<option")<0){
			innerHTML = "<option>" + innerHTML + "</option>";
		};
		innerHTML = innerHTML.replace(/<option/g,"<span").replace(/<\/option/g,"</span");
		selTemp.innerHTML = innerHTML;
		for(var i=0;i<selTemp.childNodes.length;i++){
			if(selTemp.childNodes[i].tagName){
				opt = document.createElement("OPTION");
				for(var j=0;j<selTemp.childNodes[i].attributes.length;j++){
					opt.setAttributeNode(selTemp.childNodes[i].attributes[j].cloneNode(true));
				};
				opt.value = selTemp.childNodes[i].getAttribute("value");
				opt.text = selTemp.childNodes[i].innerHTML;
				if(document.all){
					objeto.add(opt);
				}else{
					objeto.appendChild(opt);
				};                
			};
		};
		document.body.removeChild(selTemp);
		selTemp = null;
	};
	function extraiScript(texto){
		var ini, pos_src, fim, codigo;
		var objScript = null;
		ini = texto.indexOf('<script', 0);
		while (ini!=-1){
			var objScript = document.createElement("script");
			pos_src = texto.indexOf(' src', ini);
			ini = texto.indexOf('>', ini) + 1;
			if (pos_src < ini && pos_src >=0){
				ini = pos_src + 4;
				fim = texto.indexOf('.', ini)+4;
				codigo = texto.substring(ini,fim);
				codigo = codigo.replace("=","").replace(" ","").replace("\"","").replace("\"","").replace("\'","").replace("\'","").replace(">","");
				objScript.src = codigo;
			}else{
				fim = texto.indexOf('</script>', ini);
				codigo = texto.substring(ini,fim);
				objScript.text = codigo;
			};
			document.body.appendChild(objScript);
			ini = texto.indexOf('<script', fim);
			objScript = null;
		};
	};
};