var req;
//Parametros:
//url = Endereço do arquivo de processamento (ex.: news.php)
//id = Nome do Id onde será retornado a informação (ex.: <div id="nmId">)
function loadXMLDoc(url, id)
{
    req = null;
    idn = id;
    // Procura por um objeto nativo (Mozilla/Safari)
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChange;
        req.open("GET", url, true);
        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.send();
        }
    }
}


function processReqChange()
{
	var v = "";
	var cpf_nok = 0;
    // apenas quando o estado for "completado"
    if (req.readyState == 4) {
        // apenas se o servidor retornar "OK"
        if (req.status == 200) {
            // procura pela div id="<idn>" e insere o conteudo
            // retornado nela, como texto HTML
            if(idn == "alert()"){
            	if(req.responseText != '')
            		alert(req.responseText);
            }else if(idn == "confirm_cpf(to login)"){ //CONFIRMA CPF
            	if(req.responseText != 'CPF_OK'){
            		if(req.responseText != 'invalido'){
            			if(confirm(req.responseText)){
            				document.location.href='login.php';
            			}else{
            				document.cadastro.cpf_valid.value = 0;
            			}
            			cpf_nok = 1;
            		}else{
            			alert('CPF inválido');
            			cpf_nok = 1;
            		}
            	}else{
            		document.cadastro.cpf_valid.value = 1;
            		document.getElementById("link_verificacpf").innerHTML = "<strong>CPF OK, continue o cadastro.</strong>";
            	}
            	if(cpf_nok)
            		document.getElementById("link_verificacpf").innerHTML = "<strong><a href=\"javascript:checkCPF();\" class=\"link_1\">Clique aqui para validar o  CPF</a></strong>";
            }else if(idn == "valida_codpromo"){ //VALIDA CODIGO DE PROMOÇÃO
				if(req.responseText == "OK"){ 
            		document.getElementById("link_verificapromo").innerHTML = "Código OK";
					document.cadastro.codpromo_valid.value = 1;
            	}else{
					alert('Código inexistente.');
            		document.getElementById("link_verificapromo").innerHTML = "<strong><a href=\"javascript:codpromo_validate();\" tabindex=\"23\" class=\"link_1\">Clique aqui para validar</a></strong>";
            	}
			}else if(idn == "write"){
            	document.write(req.responseText);
            }else if(idn == "valida_identificacao"){ //VALIDA IDENTIFICAÇÃO
            	if(req.responseText == "valido"){
            		if(confirm('Identificação disponível.\nDeseja usar essa identificaçao?'))login_validate('aceito');
            	}else{
            		alert('Identificação já esta sendo usada! Favor escolher outra.');
            		document.getElementById("link_verificaid").innerHTML = "<strong><a href=\"javascript:login_validate('checar');\" tabindex=\"23\" class=\"link_1\">Clique aqui para validar</a></strong>";
            	}
            }else{
            	document.getElementById(idn).innerHTML = req.responseText;
            }
            	
        } else {
            alert("Houve um problema ao obter os dados:\n" + req.statusText);
        }
    }
}


//function buscarNoticias()
//{
//    loadXMLDoc("news.php");
//}

// Recarrega a cada 60000 milissegundo (60 segundos)
//setInterval("buscarNoticias()", 60000);
