
function getXmlhttp(){
	var xmlhttp;
	try{
		xmlhttp = new XMLHttpRequest();
	}catch(ee){
		try{
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e){
			try{
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			}catch(E){
				xmlhttp = false;
			}
		}
	}
	return xmlhttp;
}




function acaoAjax(url){
	var xmlhttp = getXmlhttp();
	xmlhttp.open("GET", url,true);
	xmlhttp.send(null)
}


function acaoAjaxComResposta(url){
	var xmlhttp = getXmlhttp();
    xmlhttp.open("GET", url,true);
    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4){
            var texto=xmlhttp.responseText;
			texto=texto.replace(/\+/g," ")
            texto=unescape(texto);
			if(texto=="banir"){sairUnload();}
        }
    }
    xmlhttp.send(null)
}


function Trim(str){return str.replace(/^\s+|\s+$/g,"");}

function acaoPopAjax(url, urlPop, localMsg){
	var janela = Math.round(1000*Math.random())
   	var conteudo=document.getElementById(localMsg)
	conteudo.innerHTML='processando...'
	var xmlhttp = getXmlhttp();
    xmlhttp.open("GET", url,true);
    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4){
			var texto=xmlhttp.responseText;
			texto=texto.replace(/\+/g," ")
            texto=unescape(texto);
			if (Trim(texto) == 'ok'){
				conteudo.innerHTML = ""
				window.open(urlPop, "pop_chat"+janela, "width=774, height=550, scrollbars=yes,location=no,directories=no,status=no,menubar=no,resizable=yes,toolbar=no")
			}else{
				
				conteudo.innerHTML = texto
			}
			
		}
    }
    xmlhttp.send(null)
}



function selectAjax(url, container){
	var xmlhttp = getXmlhttp();
    xmlhttp.open("GET", url,true);
    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4){
            var texto=xmlhttp.responseText;
			texto=texto.replace(/\+/g," ")
            texto=unescape(texto);
			container.innerHTML = texto
        }
    }
    xmlhttp.send(null)
}


function selectAcumulaAjax_bkp(url, container){
	var xmlhttp = getXmlhttp();
    xmlhttp.open("GET", url,true);
    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4){
            var texto=xmlhttp.responseText;
			texto=texto.replace(/\+/g," ")
            texto=unescape(texto);
			if (texto == "fechar"){
				window.close();
			}
			else{
				if (texto != "") {container.innerHTML += texto}
			}
        }
    }
    xmlhttp.send(null)
}

function selectAcumulaAjax(url, container){
	var xmlhttp = getXmlhttp();
    xmlhttp.open("GET", url,true);
    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4){
            var texto=xmlhttp.responseText;
			texto=texto.replace(/\+/g," ")
            texto=unescape(texto);
			//alert(texto);
			if (texto == "fechar"){		
				var url = "acoes.asp?acao=LimpaSessao";
				acaoAjax(url);			
				window.close();
			}
			else{
				if (texto != "") {
					var el = document.createElement('div');
					el.innerHTML = texto;
					container.appendChild(el);
				}
			}
        }
    }
    xmlhttp.send(null)
}


//modifica 1 drop
function insereDropDownAjax(url, localMsg, msgErro, drop1){
    var conteudo=document.getElementById(localMsg)
	conteudo.innerHTML='processando...'
	var xmlhttp = getXmlhttp();
    xmlhttp.open("GET", url,true);
    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4){
            var texto=xmlhttp.responseText;
			texto=texto.replace(/\+/g," ")
            texto=unescape(texto)
            var local_Msg =document.getElementById(localMsg)
			var matTexto = texto.split("|"); // separa em id e texto
			var drop_1 = document.getElementById(drop1);
			drop_1.options[drop_1.options.length] = new Option(matTexto[1], matTexto[0]);
			drop_1.selectedIndex = drop_1.options.length - 1
			local_Msg.innerHTML = ""
        }
    }
    xmlhttp.send(null)
}



function carregaajax(url,mostrar){
	var xmlhttp = getXmlhttp();
	var conteudo = document.getElementById(mostrar)
    conteudo.innerHTML='<center><div class="v8"><br><br><img src="../images/loading2.gif"><br>&nbsp;&nbsp;Carregando...</div></center>'
	xmlhttp.open("GET", url,true);
	
    xmlhttp.onreadystatechange=function() {
       if (xmlhttp.readyState==4){
            var texto=xmlhttp.responseText
            texto=texto.replace(/\+/g," ")
            texto=unescape(texto)			
            var conteudo=document.getElementById(mostrar)			
            conteudo.innerHTML=texto
       }
    }
    xmlhttp.send(null);
}






