/*****************************************/
/* BIBLIOTECA PARA USO DO XMLHTTPREQUEST */
/*****************************************/

var xmlhttp;//instancia do objeto XmlHttpRequest
var idToGo;//elemento de destino

function DoReq(url,idElemento)
{
  
	idToGo = idElemento;
	xmlhttp = null;
    // Procura por um objeto nativo (Mozilla/Safari)
    if (window.XMLHttpRequest){
        xmlhttp = new XMLHttpRequest();
        xmlhttp.onreadystatechange = ProcessaReq;
        xmlhttp.open("GET", url, true);
		xmlhttp.send(null);
    // Procura por uma versão ActiveX (IE)
    } else if (window.ActiveXObject) {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        if (xmlhttp){
            xmlhttp.onreadystatechange = ProcessaReq;
            xmlhttp.open("GET", url, true);
            xmlhttp.send(null);
        }
    }
}//fim da função DoReq()

function DoReq(url,idElemento,funcao)
{
  eval_funcao = funcao;
	idToGo = idElemento;
	xmlhttp = null;
    // Procura por um objeto nativo (Mozilla/Safari)
    if (window.XMLHttpRequest){
        xmlhttp = new XMLHttpRequest();
        xmlhttp.onreadystatechange = ProcessaReq;
        xmlhttp.open("GET", url, true);
		xmlhttp.send(null);
    // Procura por uma versão ActiveX (IE)
    } else if (window.ActiveXObject) {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        if (xmlhttp){
            xmlhttp.onreadystatechange = ProcessaReq;
            xmlhttp.open("GET", url, true);
            xmlhttp.send(null);
        }
    }
}//fim da função DoReq()

function ProcessaReq()
{
    //coloca mensagem de carregando caso demore
    document.getElementById(idToGo).innerHTML = '<span style="font-family:verdana; font-size:10px;">Aguarde...</span>';
	// apenas quando o estado for "completado"
    if (xmlhttp.readyState == 4){
        // apenas se o servidor retornar "OK"
        if (xmlhttp.status == 200){
            //insere o conteúdo retornado no elemento, como texto html
            document.getElementById(idToGo).innerHTML = xmlhttp.responseText;
            eval(eval_funcao);
        }else{
            alert("Houve um problema ao obter os dados:\n" + xmlhttp.statusText);
        }
    }
}//fim da função processRedChange()

