
function preenchelista(elemento_pai, pagina, formulario)
 {
  /*----------------------------------------------------------------------------------------------*/
//     var oHTTPRequest = createXMLHTTP(); 
     var oHTTPRequest = testeajax(); 
	 var strData=DisplayFormValues(formulario);
	 
     oHTTPRequest.open("post", pagina, true);
     //oHTTPRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	 oHTTPRequest.setRequestHeader('Content-Type', "application/x-www-form-urlencoded; charset=iso-8859-1");
	 oHTTPRequest.setRequestHeader('Content-length', strData.length ); 
	 oHTTPRequest.setRequestHeader("Connection", "close");
     
	 oHTTPRequest.onreadystatechange=function(){
 
       if (oHTTPRequest.readyState==4){// abaixo o texto gerado no arquivo executa.asp e colocado no div
        if (oHTTPRequest.status == 200) {
         document.getElementById(elemento_pai).innerHTML = oHTTPRequest.responseText;
	      } else {
                alert('Problemas com a requesição da página');
            }


     }}
    oHTTPRequest.send(strData);
  /*---------------------------------------------------------------*/
 }

function DisplayFormValues(formulario)
    {
        var str = '';
        var elem = document.getElementById(formulario).elements;
        for(var i = 0; i < elem.length; i++)
        {
            //str += "<b>Type:</b>" + elem[i].type + "&nbsp&nbsp";
            //str += "<b>Name:</b>" + elem[i].name + "&nbsp;&nbsp;";
            //str += "<b>Value:</b><i>" + elem[i].value + "</i>&nbsp;&nbsp;";
            //str += "<BR>";
			str += elem[i].name + "=";
			str += elem[i].value + "&";
        } 
        return str;
    }


 function extraiScript(texto){
//Maravilhosa função feita pelo SkyWalker.TO do imasters/forum
//http://forum.imasters.com.br/index.php?showtopic=165277
    // inicializa o inicio ><
    var ini = 0;
    // loop enquanto achar um script
    while (ini!=-1){
        // procura uma tag de script
        ini = texto.indexOf('<script', ini);
        // se encontrar
        if (ini >=0){
            // define o inicio para depois do fechamento dessa tag
            ini = texto.indexOf('>', ini) + 1;
            // procura o final do script
            var fim = texto.indexOf('</script>', ini);
            // extrai apenas o script
            codigo = texto.substring(ini,fim);
            /**********************
            
            * Alterado por Micox - micoxjcg@yahoo.com.br
            * Alterei pois com o eval não executava funções.
            
            * Alterado por Everton D. Silva - everton.silva@streamingshop.com.br
            * não estava retornando o valor
            ***********************/
            var novo = document.createElement('script');
    novo.type         = 'text/javascript';
    novo.language    = 'javascript';
    novo.text = codigo;
	//alert(novo.text);
	
    document.body.appendChild(novo);
        }
    }

}

function createXMLHTTP() 
 {
  var ajax;
  try 
  {
   ajax = new ActiveXObject("Microsoft.XMLHTTP");
  } 
  catch(e) 
  {
   try 
   {
    ajax = new ActiveXObject("Msxml2.XMLHTTP");
    alert(ajax);
   }
   catch(ex) 
   {
    try 
    {
     ajax = new XMLHttpRequest();
    }
    catch(exc) 
    {
      alert("Esse browser não 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 is not installed on your system.");
 }
 



function testeajax() {

        http_request = false;

        if (window.XMLHttpRequest) { // Mozilla, Safari,...
            http_request = new XMLHttpRequest();
            if (http_request.overrideMimeType) {
                http_request.overrideMimeType('text/xml');
                // See note below about this line
            }
        } else if (window.ActiveXObject) { // IE
            try {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }

        if (!http_request) {
            alert('Giving up :( Cannot create an XMLHTTP instance');
            return false;
        }
	return http_request
}




