//Validação dos campos de email

var reEmail1 = /^[\w!#$%&'*+\/=?^`{|}~-]+(\.[\w!#$%&'*+\/=?^`{|}~-]+)*@(([\w-]+\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
var reEmail2 = /^[\w-]+(\.[\w-]+)*@(([\w-]{2,63}\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
var reEmail3 = /^[\w-]+(\.[\w-]+)*@(([A-Za-z\d][A-Za-z\d-]{0,61}[A-Za-z\d]\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
var reEmail = reEmail3;

function doEmail(pStr, pFmt)
{
	eval("reEmail = reEmail" + pFmt);
	if (reEmail.test(pStr)) {
	} else if (pStr != null && pStr != "") {
		alert(pStr + " NÃO é um endereço de e-mail válido.");
		document.formulario.email.focus();
	}
} // doEmail

function doConfirmaEmail(pStr, pFmt)
{
	eval("reEmail = reEmail" + pFmt);
	if (reEmail.test(pStr)) {
	} 
	else if (pStr != null && pStr != "") {
		alert(pStr + " NÃO é um endereço de e-mail válido.");
		document.formulario.confirmaemail.focus();
	}
} // doEmail


//FIM da validação dos campos de email



//Validação do campo Data de Nascimento


var reDate4 = /^((0?[1-9]|[12]\d)\/(0?[1-9]|1[0-2])|30\/(0?[13-9]|1[0-2])|31\/(0?[13578]|1[02]))\/(19|20)?\d{2}$/;

function doDate(pStr, pFmt)
{
	eval("reDate = reDate" + pFmt);
	if (reDate.test(pStr)) {
	} else if (pStr != null && pStr != "") {
		alert(pStr + " NÃO é uma data válida.");
		document.formulario.data_nascimento.focus();
	}
}


//FIM da validação do campo Data de Nascimento


//Validação de todos os campos (preenchimento)

function validaForm(){
d = document.formulario;

d.nome.style.background="white";
d.email.style.background="white";
d.confirmaemail.style.background="white";
d.data_nascimento.style.background="white";
d.pais.style.background="white";
d.cidade.style.background="white";
d.estado.style.background="white";
d.apelido.style.background="white";
d.senha.style.background="white";
d.confirmasenha.style.background="white";
d.time.style.background="white";
d.quemindicou.style.background="white";

	if (d.nome.value == ""){
		alert("Informe o seu Nome Completo!!!");
		d.nome.style.background="yellow";
		d.nome.focus();
		d.nome.select();
		return false;
	}

	if (d.email.value == "") {
		alert("Informe seu e-mail.");
		d.email.style.background="yellow";
		d.email.focus();
		return false;
	}

	if (d.confirmaemail.value == "") {
		alert("Confirme o seu e-mail.");
		d.confirmaemail.style.background="yellow";
		d.confirmaemail.focus();
		return false;
	} 

	if (d.confirmaemail.value != d.email.value){
			alert("Os campos E-mail e Confirmação de E-mail devem ser iguais.");
			d.email.style.background="yellow";
			d.confirmaemail.style.background="yellow";
			d.email.focus();
			d.confirmaemail.select();
			return false;
		}

	if (d.data_nascimento.value == ""){
		alert("Informe a Data de Nascimento!!!");
		d.data_nascimento.style.background="yellow";
		d.data_nascimento.focus();
		d.data_nascimento.select();
		return false;
	}

	if (d.pais.value == ""){
		alert("Selecione o País!!!");
		d.pais.style.background="yellow";
		d.pais.focus();
		return false;
	}

if (d.estado1.value == ""){	
	if (d.estado.value == ""){
		alert("Selecione o Estado!!!");
		d.estado.style.background="yellow";
		if (d.estado.style.display!='none')
		{d.estado.focus();}
		return false;
	}
d.estado1.style.background="yellow";

}

if (d.cidade1.value == ""){	
	if (d.cidade.value == ""){
		alert("Selecione a Cidade!!!");
		d.cidade.style.background="yellow";
		if (d.cidade.style.display!='none')
		{d.cidade.focus();}
		return false;
	}
d.cidade1.style.background="yellow";
}

	if (d.apelido.value == ""){
		alert("Informe o seu Apelido!!!");
		d.apelido.style.background="yellow";
		d.apelido.focus();
		d.apelido.select();
		return false;
	}

	if (d.senha.value == ""){
		alert("Informe a Senha!!!");
		d.senha.style.background="yellow";		
		d.senha.focus();
		d.senha.select();
		return false;
	}

	if (d.confirmasenha.value == ""){
		alert("Informe a Confirmação da Senha!!!");
		d.confirmasenha.style.background="yellow";
		d.confirmasenha.focus();
		d.confirmasenha.select();
		return false;
	}

	if (d.confirmasenha.value != d.senha.value){
			alert("Os campos Senha e Confirmação da Senha devem ser idênticos !!!");
			d.senha.style.background="yellow";
			d.confirmasenha.style.background="yellow";
			d.senha.focus();
			d.senha.select();
			return false;
		}

	if (d.time.value == ""){
		alert("Selecione o seu Time!!!");
		d.time.style.background="yellow";
		d.time.focus();
		return false;
	}

	if ((d.sexo[0].checked == false) && (d.sexo[1].checked == false)) {
		alert("Selecione o seu SEXO!!!");
		d.time.focus();
		return false;
	}

if (d.quemindicou.value == ""){
		alert("De algum jeito você chegou aqui! Diga lá.. é importante para nós!");
		d.quemindicou.style.background="yellow";
		d.quemindicou.focus();
		return false;
	}

if (d.renda.value == ""){
		alert("Informe a renda aproximada.");
		d.renda.style.background="yellow";
		d.renda.focus();
		return false;
	}
if (d.local.value == ""){
		alert("Informe a local de onde mais vai apostar no Futgame.");
		d.local.style.background="yellow";
		d.local.focus();
		return false;
	}
	
	if (d.velo.value == ""){
		alert("Informe a velocidade de sua conexão.");
		d.velo.style.background="yellow";
		d.velo.focus();
		return false;
	}
	if (d.escol.value == ""){
		alert("Informe sua escolaridade.");
		d.escol.style.background="yellow";
		d.escol.focus();
		return false;
	}
		if (d.civil.value == ""){
		alert("Informe seu estado civil.");
		d.civil.style.background="yellow";
		d.civil.focus();
		return false;
	}
		if (d.ocup.value == ""){
		alert("Informe sua ocupação.");
		d.ocup.style.background="yellow";
		d.ocup.focus();
		return false;
	}
}

//FIM da validação de todos os campos (preenchimento)

//Função de Máscara dos campos

function txtBoxFormat(strField, sMask, evtKeyPress) {
    var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;

   if(window.event) { // Internet Explorer
    nTecla = evtKeyPress.keyCode; }
   else if(evtKeyPress.which) { // Nestcape / firefox
    nTecla = evtKeyPress.which;
    




    }
//se for backspace não faz nada
if (nTecla != 8){
    sValue = document.getElementById(strField).value;
// alert(sValue);

    // Limpa todos os caracteres de formatação que
    // já estiverem no campo.
    sValue = sValue.toString().replace( "-", "" );
    sValue = sValue.toString().replace( "-", "" );
    sValue = sValue.toString().replace( ".", "" );
    sValue = sValue.toString().replace( ".", "" );
    sValue = sValue.toString().replace( "/", "" );
    sValue = sValue.toString().replace( "/", "" );
    sValue = sValue.toString().replace( "(", "" );
    sValue = sValue.toString().replace( "(", "" );
    sValue = sValue.toString().replace( ")", "" );
    sValue = sValue.toString().replace( ")", "" );
    sValue = sValue.toString().replace( " ", "" );
    sValue = sValue.toString().replace( " ", "" );
    fldLen = sValue.length;
    mskLen = sMask.length;

    i = 0;
    nCount = 0;
    sCod = "";
    mskLen = fldLen;

    while (i <= mskLen) {
      bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/"))
      bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))

      if (bolMask) {
        sCod += sMask.charAt(i);
        mskLen++; }
      else {
        sCod += sValue.charAt(nCount);
        nCount++;
      }

      i++;
    }

    document.getElementById(strField).value = sCod;

    if (nTecla != 8) { // backspace
      if (sMask.charAt(i-1) == "9") { // apenas números...
        return ((nTecla > 47) && (nTecla < 58)); } // números de 0 a 9
      else { // qualquer caracter...
        return true;
      } }
    else {
      return true;
    }
}//fim do if que verifica se é backspace
}
//Fim da Função Máscaras Gerais//Fim da Função de Máscara dos campos