function enviarDados() {

    var nome 			= document.frmCadastro.nome;
    var cpf 			= document.frmCadastro.cpf;
    var sexo 			= document.frmCadastro.sexo;
    var escolaridade 	= document.frmCadastro.escolaridade;
    var dataNasc 		= document.frmCadastro.dataNasc;
    var fone 			= document.frmCadastro.fone;
    var celular 		= document.frmCadastro.celular;
    var profissao 		= document.frmCadastro.profissao;
    var endereco 		= document.frmCadastro.endereco;
    var numero 			= document.frmCadastro.numero;
    var complemento 	= document.frmCadastro.complemento;
    var bairro 			= document.frmCadastro.bairro;
    var cep 			= document.frmCadastro.cep;
    var cidade 			= document.frmCadastro.cidade;
    var estado 			= document.frmCadastro.estado;
    var email			= document.frmCadastro.email;

    if(nome.value == "") {
        alert("Informe o seu nome corretamente.");
        nome.focus();
        return false;
    }
    //if(cpf.value == "") {
     //   alert("Informe o seu cpf corretamente.");
     //   cpf.focus();
     //   return false;
   // }
    if(sexo.value == "") {
        alert("Selecione o seu sexo corretamente.");
        return false;
    }
    if(dataNasc.value != "" && !validaData(dataNasc.value)) {
        alert("Informe a data de nascimento corretamente.");
        dataNasc.focus();
        return false;
    }
    if(endereco.value == "") {
        alert("Informe o seu endereço corretamente.");
        endereco.focus();
        return false;
    }
    if(numero.value == "") {
        alert("Informe o número da sua residência.");
        numero.focus();
        return false;
    }
    if(bairro.value == "") {
        alert("Informe o seu bairro.");
        bairro.focus();
        return false;
    }
    if(cep.value == "") {
        alert("Informe o CEP.");
        cep.focus();
        return false;
    }
    if(cidade.value == "") {
        alert("Informe a sua cidade.");
        cep.focus();
        return false;
    }
    if(estado.value == "") {
        alert("Selecione o estado.");
        estado.focus();
        return false;
    }
    if(!validaEmailBO(email)) {
        alert("Informe o seu email corretamente.");
        email.focus();
        return false;
    }
    mudaCampos(document.frmCadastro,0);
    xhSend('modulos/promocoes/enviar.php?acao=cadastro','frmCadastro',enviarDadosRe);
}

function enviarDadosRe() {
    if (xhReq.readyState == 4 && xhReq.status == 200) {
        obj = xhReq.responseXML;
        var retorno = obj.getElementsByTagName('retorno')[0];

        if (retorno.getElementsByTagName('msg')[0].firstChild.nodeValue == 1) {

            document.frmCadastro.reset();
            mudaCampos(document.frmCadastro,1);

            alert(unescape(retorno.getElementsByTagName('mensagem')[0].firstChild.nodeValue));

            $('#divFrmCadastro').slideUp('slow');

            document.frmParticipe.email.value = unescape(retorno.getElementsByTagName('email')[0].firstChild.nodeValue);
            $('#divFrmParticipe').slideDown('slow');

        } else {
            mudaCampos(document.frmCadastro,1);
            alert(unescape(retorno.getElementsByTagName('mensagem')[0].firstChild.nodeValue));
        }
    }
}

function enviarResposta() {

    var pergunta 		= document.frmParticipe.pergunta;
    var resposta 		= document.frmParticipe.resposta;
    var email			= document.frmParticipe.email;

    if(pergunta.value == 1 && resposta.value.length < 3) {
        alert("Qual a sua resposta?");
        resposta.focus();
        return false;
    }
    if(!validaEmailBO(email)) {
        alert("Informe o seu email corretamente.");
        email.focus();
        return false;
    }
    mudaCampos(document.frmParticipe,0);
    xhSend('modulos/promocoes/enviar.php?acao=resposta','frmParticipe',enviarRespostaRe);
}

function enviarRespostaRe() {
    if (xhReq.readyState == 4 && xhReq.status == 200) {
        obj = xhReq.responseXML;
        var retorno = obj.getElementsByTagName('retorno')[0];

        if (retorno.getElementsByTagName('msg')[0].firstChild.nodeValue == 1) {
            document.frmParticipe.reset();
            mudaCampos(document.frmParticipe, 1);
            alert(unescape(retorno.getElementsByTagName('mensagem')[0].firstChild.nodeValue));

        } else if (retorno.getElementsByTagName('msg')[0].firstChild.nodeValue == 5) {
            mudaCampos(document.frmParticipe,1);
            alert(unescape(retorno.getElementsByTagName('mensagem')[0].firstChild.nodeValue));

            document.frmCadastro.email.value = unescape(retorno.getElementsByTagName('email')[0].firstChild.nodeValue);
            $('#divFrmParticipe').slideUp('slow');
            $('#divFrmCadastro').slideDown('slow');

        } else {
            document.frmParticipe.reset();
            mudaCampos(document.frmParticipe,1);
            alert(unescape(retorno.getElementsByTagName('mensagem')[0].firstChild.nodeValue));
        }
    }
}
