try{
    xmlhttp = new XMLHttpRequest();
}catch(ee){
    try{
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }catch(e){
        try{
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }catch(E){
            xmlhttp = false;
        }
    }
}

function formataCep(){
	cepL = document.cadastro.cep.value.length;
	cep = document.cadastro.cep.value.replace("-","");
	for(i=0; i<=cepL; i++){
		cep = cep.replace("-","");
	}
	query(cep)
}


function query(cep){
	document.cadastro.cep.value = "...carregando";
	document.getElementById("cepIn").disabled = true;
	
	url = "cep.php?cep="+cep;
	xmlhttp.open("GET", url, true);
	xmlhttp.onreadystatechange=function() {
	    if (xmlhttp.readyState==4){
		    document.getElementById("resultado").style.display = 'block';
			document.getElementById("resultado").innerHTML = xmlhttp.responseText;	
			document.getElementById("cepIn").disabled = false;
			document.cadastro.cep.value = cep;			

	    }
	}
	 xmlhttp.send(null)
}

function checkcpf(cpf){
 if (document.cadastro.icpf.value!="") {	
	//document.cadastro.icpf.value = "...carregando";
	document.getElementById("icpf").disabled = true;
	
	url = "cpf.php?cpf="+cpf;
	xmlhttp.open("GET", url, true);

	    if (xmlhttp){
            alert('Esse usuario JA esta cadastrado');
            document.getElementById("icpf").disabled = false;
			document.cadastro.icpf.value = "";
			document.cadastro.icpf.focus(); 
			}
		else{
            document.getElementById("icpf").disabled = false;
			document.cadastro.icpf.value = "";
            alert('Esse usuario nao esta cadastrado');
         }
      }
 }



