//-----------------------------------------------------
//    A funcao abaixo funciona em qualquer
//    browser ou versao.  
//-----------------------------------------------------
function createXMLHTTP() {

   var ajax;

   try { 
      ajax = new ActiveXObject("Microsoft.XMLHTTP"); 
   } 
   catch(e) {
      try {
         ajax = new ActiveXObject("Msxml2.XMLHTTP");
      }
      catch(ex) {
         try {
            ajax = new XMLHttpRequest();
         }
         catch(exc) {
            alert("Esse browser nao tem recursos para uso do Ajax");
            ajax = null;
         }
      }
      return ajax;
   }

   var arrSignatures = ["MSXML2.XMLHTTP.5.0", "MSXML2.XMLHTTP.4.0",
   "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP",
   "Microsoft.XMLHTTP"];

   for (var i=0; i < arrSignatures.length; i++) {
      try {
         var oRequest = new ActiveXObject(arrSignatures[i]);
         return oRequest;
      } 
      catch (oError) {
      }
   }

   throw new Error("MSXML não está instalado no seu sistema.");
}


//------------------------------------------------
//
//    Executa o script pelo AJAX e coloca o
//    retorno numa div
//
//    pScript     - script a ser executado
//    pDiv        - DIV que vai receber o retorno do AJAX
//    pParametros - string com parametros a serem passados ao
//             script em oHTTPRequest.send(pParametros)
//
//------------------------------------------------
function execAjax(pScript, pDiv, pParametros) {

   // pre loader
   //document.getElementById(pDiv).innerHTML = "<img src='js/loading_bar.gif' class='centraliza' style='margin-top:-30px; margin-left:-47px;' width='94px' height='17px' alt='' />" +
   //         "<br /><p class='centraliza' style='display:block; width:50px; border:0px solid #0FF; margin-left:-25px; font-size:10px; font-family:tahoma; color:#666;'>aguarde...</p>";
   document.getElementById(pDiv).innerHTML = "<br /><p class='centraliza' style='display:block; width:50px; border:0px solid #0FF; margin-left:-25px; font-size:10px; font-family:tahoma; font-weight:bold; color:#666;'>aguarde...</p>";

   // criacao do objeto XMLHTTP do arquivo ajax.js
   var oHTTPRequest = createXMLHTTP();
   oHTTPRequest.open("post", pScript, true);   //enviamos para a p gina que faz o select do que foi digitado e traz a lista preenchida.

   // para solicitacoes utilizando o metodo post deve
   // ser acrescentado este cabecalho HTTP
   oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

   // a funcao abaixo e executada sempre que o estado do objeto muda (onreadystatechange)
   oHTTPRequest.onreadystatechange=function(){

   // o valor 4 significa que o objeto ja completou a solicitacao
   if (oHTTPRequest.readyState==4) {
      // abaixo o texto gerado no arquivo executa.asp e colocado no div
//      document.all.divRetorno.innerHTML = oHTTPRequest.responseText;
      document.getElementById(pDiv).innerHTML = oHTTPRequest.responseText;
   }}
   oHTTPRequest.send(pParametros);
}

