//Verificacao de CPF com Ajax 

try{
    xmlhttp = new XMLHttpRequest();
}catch(ee){
    try{
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }catch(e){
        try{
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }catch(E){
            xmlhttp = false;
        }
    }
}

var campo = null
var cpf_proprio = 1

function verifica_cpf(c){
  if(xmlhttp){
    campo = c
    if(document.forms[0].cpf_proprio[0].checked == 1){
      cpf_proprio = 1
    }else{
      cpf_proprio = 0
    }
    
    //Exibe o texto carregando no div conteúdo
    var conteudo=document.getElementById("div_"+campo.name)
    conteudo.innerHTML='Aguarde...'

    //Abre a url
    xmlhttp.open("GET", "verifica_cpf.php?cpf="+campo.value+"&cpf_proprio="+cpf_proprio,true);
    //Executada quando o navegador obtiver o código
    xmlhttp.onreadystatechange=function(){
      if(xmlhttp.readyState==4){
        //Lê o texto
        var texto=xmlhttp.responseText
        //Desfaz o urlencode
        texto=texto.replace(/\+/g," ")
        texto=unescape(texto)
        //Exibe o texto no div conteúdo
        var conteudo=document.getElementById("div_"+campo.name)
        conteudo.innerHTML=texto
      }
    }
    xmlhttp.send(null);  
  }
}

