// ------------------------------------------------------------------------------------------------ Bloco AJAX
var req; 
var vCRet;

function loadXMLDoc(url) 
{ 
    req = null; 
    // Procura por um objeto nativo (Mozilla/Safari) 
    if (window.XMLHttpRequest) { 
        req = new XMLHttpRequest(); 
        req.onreadystatechange = processReqChange; 
        req.open("GET", url, true); 
	req.setRequestHeader( "Content-Type","text/html; charset=UTF-8" );
        req.send(null); 
    // Procura por uma versão ActiveX (IE) 
    } else if (window.ActiveXObject) { 
        req = new ActiveXObject("Microsoft.XMLHTTP"); 
        if (req) {
            req.onreadystatechange = processReqChange; 
            req.open("GET", url, true);
	    req.setRequestHeader( "Content-Type","text/html; charset=iso-8859-1" );
            req.send(); 
        } 
    } 
} 

function processReqChange() 
{ 
    // apenas quando o estado for "completado" 
    //document.getElementById(vCRet).innerHTML='carregando...'
    if (req.readyState == 4) { 
        // apenas se o servidor retornar "OK" 
        if (req.status == 200) { 
            // procura pela div id= e insere o conteudo 
            // retornado nela, como texto HTML 
            var texto = req.responseText;
            texto=texto.replace(/\+/g," ");
            document.getElementById(vCRet).innerHTML = unescape(texto);
	    //document.getElementById(vCRet).innerHTML = decodeURI(texto);
        } else { 
            alert("Houve um problema ao obter os dados:\n" + req.statusText); 
        } 
    } 
} 

function BuscaDados_Ajax(vLink,vR) 
{ 
  vCRet = vR;
  loadXMLDoc(vLink);
  vCRet = vR;
}

function Ajax_Pega(vCampo,vDiv,vUrl)
{
// vCampo = 'form.campo' dos dados a serem capturados do formulario
// vDiv = Nome da div de retorno
// vUrl = Caminho do arquivo q o AJAX vai buscar o novo corpo para a vDiv

  var vValor;
  vValor = eval(vCampo+'.value');
  if (vValor.length > 0)
  {
  BuscaDados_Ajax(vUrl+'&V='+ vValor,vDiv);
  }
}