function validaFormReserva()
{
	var falta;
	falta = false;
    d = window.document.form;
    if (d.nome.value == "")
	{
	    alert("O campo nome deve ser preenchido!");
        d.nome.focus();
        return false;
    }
    if ((d.email.value == "") && (d.tel_res.value == ""))
	{
      	alert("É obrigatório o pereenchimento do campo e-mail ou telefone residencial!");
        d.email.focus();
        return false;
    }	
}


function validaEmail(email)
{
	if (typeof(email) != "string")
	{
    	return false;
	}
	else if (!email.match(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/))
	{
       	return false;
	}
	else
	{
        return true;
	}
}


function habilitaDataSaida(i)
{
    d = window.document.form;
	if(document.getElementById('atual_'+i+'').checked == true)
	{
		document.getElementById('dataSaida_'+i+'').value = "";
        document.getElementById('dataSaida_'+i+'').disabled = true;
	}	
	else
	{
        document.getElementById('dataSaida_'+i+'').disabled = false;
	}
}


function validaFormEditalNovo()
{
	var i,j,falta,contador,data_inicio,data_saida;
	falta 				= false;
	contador 			= 0;	
    d 					= window.document.form;
	
	var arrDataNasc 	= new Array();
	var dNasc 			= new String();
	dNasc 				= d.dataNasc.value;
	arrDataNasc			= dNasc.split("/");
	var dia				= arrDataNasc[0];	
	var mes				= arrDataNasc[1];
	var ano				= arrDataNasc[2];
	var Hj				= new Date();
	var diaHj			= new String();
	var mesHj			= new String();
	var anoHj			= new String();
	var diaHj			= String(Hj.getDate());
	var mesHj			= String(Hj.getMonth()+1); // no java script o mes começa no 0 janeiro =0, fevereiro =1....
	var anoHj			= String(Hj.getFullYear());
	if(diaHj.length == 1) {
		diaHj = String("0")+diaHj;
	}
	if(mesHj.length == 1) {
		
		mesHj = String("0") + mesHj;
	}
	var dataUsrCompara 	= ano + mes + dia;
	var dataHjeCompara 	= anoHj + mesHj + diaHj;
	if(ano < '1850') {
		alert("Sua data de nascimento está com o ano digitado incorretamente.");
        d.dataNasc.focus();
		return false;		
	}
	if(dataUsrCompara.length != 8) {
		alert("Verifique se sua data de nascimento está no formato: dd/mm/aaaa.");
        d.dataNasc.focus();
		return false;		
	}
	if(dataHjeCompara < dataUsrCompara) {
		alert("Sua data de nascimento está posterior a data atual.");
        d.dataNasc.focus();
		return false;		
	}	
    if (d.nome.value == ""){
              alert("O campo nome deve ser preenchido!");
              d.nome.focus();
              return false;
	}
	if (d.cpf.value == ""){
		alert("O campo CPF deve ser preenchido!");
		d.cpf.focus();
		return false;
	}	
	if (d.email.value == ""){
		alert("O campo e-mail deve ser preenchido!");
		d.email.focus();
		return false;
	}	
	if (validaEmail(d.email.value) == false){
		alert("O campo e-mail deve ser preenchido corretamente!");
		d.email.focus();
		return false;
	}			
	if((d.dataNasc.value == "") && (d.dataNasc.length != 10)){
		 alert("Preencha a data de nascimento!");
		 d.dataNasc.focus();
		 return false;			
	}
	if (validarData(d.dataNasc.value) == false)	{
		 alert("Preencha a data de nascimento de forma correta!");
		 d.dataNasc.focus();
		 return false;			
	}		
	if (d.estadoCivil.value == ""){
		      alert("O campo estado civil deve ser preenchido!");
		      d.estadoCivil.focus();
		      return false;
	}		
	if (d.deficienciaFisica.value == ""){
		      alert("O campo deficiência física deve ser preenchido!");
		      d.deficienciaFisica.focus();
		      return false;
	}			
	if ((d.telResidencial.value == "") && (d.telCelular.value == "")){
		      alert("Preencha um dos campos referente ao seu telefone!");
		      d.telResidencial.focus();
		      return false;
	}		
	if (d.endereco.value == ""){
		      alert("O campo endereço deve ser preenchido!");
		      d.endereco.focus();
		      return false;
	}		
	if (d.numero.value == ""){
		      alert("O campo número deve ser preenchido!");
		      d.numero.focus();
		      return false;
	}				
	if (d.bairro.value == ""){
		      alert("O campo Bairro deve ser preenchido!");
		      d.bairro.focus();
		      return false;
	}					
	if (d.cidade.value == ""){
		      alert("O campo Cidade deve ser preenchido!");
		      d.cidade.focus();
		      return false;
	}				
	if (d.estado.value == ""){
		      alert("Selecione um Estado!");
		      d.estado.focus();
		      return false;
	}
	if (d.cep.value == ""){
		      alert("O campo CEP deve ser preenchido!");
		      d.cep.focus();
		      return false;
	}
	if ((document.getElementById("escolaridade_1").checked == false) && (document.getElementById("escolaridade_2").checked == false) && (document.getElementById("escolaridade_4").checked == false) && (document.getElementById("escolaridade_5").checked == false)){
		      alert("O campo escolaridade deve ser selecionado!");
		      d.fundamental_status.focus();
		      return false;
	}					
	if ((document.getElementById("escolaridade_1").checked == true) && (d.fundamental_status.value == "")){
		      alert("Selecione o status do seu ensino fundamental!");
		      d.fundamental_status.focus();
		      return false;
	}	
	if ((document.getElementById("escolaridade_2").checked == true) && (d.medio_status.value == "")){
		      alert("Selecione o status do seu ensino médio!");
		      d.medio_status.focus();
		      return false;
	}		
	if ((document.getElementById("escolaridade_4").checked == true) && (d.incompletoFlag.value == "1") && (d.escolaridadeSelectIncompleto.value == "")){
		      alert("Selecione o curso que você está cursando no momento!");
		      d.escolaridadeSelectIncompleto.focus();
		      return false;
	}						
	if ((document.getElementById("escolaridade_4").checked == true) && (d.incompletoFlag.value == "2") && (d.incompOutro.value == "")){
		      alert("Preencha o curso que você está cursando no momento!");
		      d.incompOutro.focus();
		      return false;
	}								
	if ((document.getElementById("escolaridade_5").checked == true) && (d.completoFlag.value == "1") && (d.escolaridadeSelectCompleto.value == "")){
		      alert("Selecione a sua formação!");
		      d.escolaridadeSelectCompleto.focus();
		      return false;
	}						
	if ((document.getElementById("escolaridade_5").checked == true) && (d.completoFlag.value == "2") && (d.compOutro.value == "")){
		      alert("Preencha a sua formação!");
		      d.compOutro.focus();
		      return false;
	}		
	if((document.getElementById("escolaridade_5").checked == true) && (d.anoConclusao.value == "")){
		      alert("Preencha o ano de conclusão do seu curso!");
		      d.anoConclusao.focus();
		      return false;
	}				
	if((document.getElementById("escolaridade_5").checked == true) && (d.tipo_graduacao.value == "")){
		      alert("Preencha o tipo de graduação!");
		      d.tipo_graduacao.focus();
		      return false;
	}
	if ((document.getElementById("escolaridade_5").checked == false) && (document.getElementById("escolaridade_4").checked == false) && (document.getElementById("especializacao").checked == true)){
		      alert("Para você selecionar uma especialização é necessário o 3° grau completo ou incompleto!");
		      document.getElementById("especializacao").focus();
		      return false;
	}	
	if ((document.getElementById("escolaridade_5").checked == false) && (document.getElementById("escolaridade_4").checked == false) && (document.getElementById("mestrado").checked == true)){
		      alert("Para você selecionar um mestrado é necessário o 3° grau completo ou incompleto!");
		      document.getElementById("mestrado").focus();
		      return false;
	}			
	if ((document.getElementById("escolaridade_5").checked == false)  && (document.getElementById("doutorado").checked == true)){
		      alert("Para você selecionar um doutorado é necessário o 3° grau completo!");
		      document.getElementById("doutorado").focus();
		      return false;
	}			
	if ((document.getElementById("especializacao").checked == true) && (d.especializacaoTexto.value == "")){
		      alert("Preencha o campo especialização!");
		      d.especializacaoTexto.focus();
		      return false;
	}	
	if ((document.getElementById("especializacao").checked == true) && (d.especializacaoTexto.value == "")){
		      alert("Preencha o campo especialização!");
		      d.especializacaoTexto.focus();
		      return false;
	}	
	if ((document.getElementById("especializacao").checked == true) && (d.especializacaoStatus.value == "")){
		      alert("Preencha o a situação atual da sua especialização!");
		      d.especializacaoStatus.focus();
		      return false;
	}			
	if ((document.getElementById("especializacao").checked == true) && (document.getElementById("especializacaoStatus").value == "1") && (d.especializacao_ano.value == "")){
		      alert("Preencha o ano de conclusão da sua especialização!");
		      d.especializacao_ano.focus();
		      return false;
	}					
	if ((document.getElementById("mestrado").checked == true) && (d.mestradoTexto.value == "")){
		      alert("Preencha o campo mestrado!");
		      d.mestradoTexto.focus();
		      return false;
	}	
	if ((document.getElementById("mestrado").checked == true) && (d.mestradoStatus.value == "")){
		      alert("Preencha o a situação atual do seu mestrado!");
		      d.mestradoStatus.focus();
		      return false;
	}					
	if ((document.getElementById("mestrado").checked == true) && (document.getElementById("mestradoStatus").value == "1") && (d.mestrado_ano.value == "")){
		      alert("Preencha o ano de conclusão do seu mestrado!");
		      d.mestrado_ano.focus();
		      return false;
	}							
	if ((document.getElementById("doutorado").checked == true) && (d.doutoradoTexto.value == "")){
		      alert("Preencha o campo doutorado!");
		      d.doutoradoTexto.focus();
		      return false;
	}	
	if ((document.getElementById("doutorado").checked == true) && (d.doutoradoStatus.value == "")){
		      alert("Preencha o a situação atual do seu doutorado!");
		      d.doutoradoStatus.focus();
		      return false;
	}		
	if ((document.getElementById("doutorado").checked == true) && (document.getElementById("doutoradoStatus").value == "1") && (d.doutorado_ano.value == "")){
		      alert("Preencha o ano de conclusão do seu doutorado!");
		      d.doutorado_ano.focus();
		      return false;
	}
		//Validação de Experiência Profissional
		for(i=1;i<=d.total.value;i++){
			if((d.total.value > 1) || (document.getElementById('empresa_'+i+'').value != '')){
				if(document.getElementById('empresa_'+i+'').value == ''){
					 alert("Preencha corretamente o nome da empresa que você trabalhou ou trabalha!");
					 document.getElementById('empresa_'+i+'').focus();
					 return false;				
				}
				data_inicio = document.getElementById('dataInicio_'+i+'').value;
				if((document.getElementById('dataInicio_'+i+'').value == '') || (validarData(data_inicio) == false)){
					 alert("Preencha corretamente o período que você trabalhou na empresa "+document.getElementById('empresa_'+i+'').value+"!");
					 document.getElementById('dataInicio_'+i+'').focus();
					 return false;				
				} else {
					//Decompor data
					data_inicio = data_inicio.substring(6,10)+data_inicio.substring(3,5)+data_inicio.substring(0,2);
					if(data_inicio > dataHjeCompara) {
						alert("A data de início da empresa que você trabalhou não pode ser maior que a data atual.")						 
						document.getElementById('dataInicio_'+i+'').focus();
						return false;							
					}
					if(data_inicio.length != 8) {
						alert("A data de início na empresa parece não estar digitada corretamente. Formato esperado: dd/mm/yyyy.");
						document.getElementById('dataInicio_'+i+'').focus();
						return false;		
					}
				}
				data_saida = document.getElementById('dataSaida_'+i+'').value;
				if(document.getElementById('atual_'+i+'').checked == false)	{
					if((document.getElementById('dataSaida_'+i+'').value == '') || (validarData(data_saida) == false)){
						 alert("Preencha corretamente o período que você trabalhou na empresa "+document.getElementById('empresa_'+i+'').value+"!");
						 document.getElementById('dataSaida_'+i+'').focus();
						 return false;				
					} else {
						//Decompor data
						data_saida = data_saida.substring(6,10)+data_saida.substring(3,5)+data_saida.substring(0,2);
						if(data_saida < data_inicio){
							 alert("A data de início não pode ser maior que a data de saída da empresa "+document.getElementById('empresa_'+i+'').value+"!");
							 document.getElementById('dataInicio_'+i+'').focus();
							 return false;		
						}
						if(data_saida > dataHjeCompara) {
							alert("A data de saída não pode ser maior que a data atual.")						 
							document.getElementById('dataSaida_'+i+'').focus();
							return false;	
						}
						if(data_saida.length != 8) {
							alert("A data de saída da empresa parece não estar digitada corretamente. Formato esperado: dd/mm/yyyy.");
							document.getElementById('dataSaida_'+i+'').focus();
							return false;		
						}
					}
				}
				
				if(document.getElementById('cargo_'+i+'').value == '')
				{
					 alert("Preencha corretamente o cargo que você trabalhou na empresa "+document.getElementById('empresa_'+i+'').value+"!");
					 document.getElementById('cargo_'+i+'').focus();
					 return false;				
				}			
				
				if(document.getElementById('atribuicoes_'+i+'').value == '')
				{
					 alert("Preencha corretamente as funções e atribuições do cargo na empresa "+document.getElementById('empresa_'+i+'').value+"!");
					 document.getElementById('atribuicoes_'+i+'').focus();
					 return false;				
				}					
			}
		}	
		//Validação de Vagas
		for (i=0;i<d.total_vagas.value;i++)
		{
			if(document.getElementById('vaga_'+i+'').checked == true)
			{
				contador++;
			}
		}			
		if(contador == 0)
		{
			alert('Selecione pelo menos uma vaga do edital!');
			return false;				
		}		
		
		contador = 0;
		
		for (i=0;i<d.total_vagas.value;i++)
		{
			if(document.getElementById('vaga_'+i+'').checked == true)
			{
				contador++;
				falta = true;
				if(contador > 3)
				{
					alert('Apenas três vagas podem ser selecionadas por edital!');
					return false;				
				}
			}
		}	
		
		//Validação de senha
        if ((d.senha.value == "") && (d.confSenha.value == "")){
                  alert("Os campos senha de confirmação de senha devem ser preenchidos!");
                  d.senha.focus();
                  return false;
        }		
		
		if(d.senha.value.length < 6)
		{
                  alert("Os campos Senha deve conter no mínimo 6 caracteres!");
                  d.senha.focus();
                  return false;			
		}
		
		if(d.confSenha.value.length < 6)
		{
                  alert("Os campos Confimação de Senha deve conter no mínimo 6 caracteres!");
                  d.confSenha.focus();
                  return false;			
		}		
		
        if(d.senha.value != d.confSenha.value)
		{
                  alert("Sua confirmação de senha não é igual a sua senha!");
                  d.confSenha.focus();
                  return false;
        }		
		
}


function validarData(campo)
{
	var expReg = /^(([0-2]\d|[3][0-1])\/([0]\d|[1][0-2])\/[1-2][0-9]\d{2})$/;
	if ((campo.match(expReg)) && (campo != ''))
	{
		var dia = campo.substring(0,2);
		var mes = campo.substring(3,5);
		var ano = campo.substring(6,10);
		if((mes== "04" || mes== "06" || mes== "09" || mes== "11") && dia > 30)
		{
			return false;
		} 
		else
		{
			if(dia == 0)
			{
				return false;
			}
			
			if(ano%4!=0 && mes=="02" && dia>28)
			{
				return false;
			} 
			else
			{
				if(ano%4==0 && mes=="02" && dia>29)
				{
					return false;
				} 
				else
				{ 
					return true;
				}
			}
		}
	} 
	else 
	{
		return false;
	}
}

function ValidaDataEdital2(data)
{
	if(data.length != 10)
	{
		return false;
	}
	if(data.substr(2,1) != '/')
	{
		return false;
	}	
	if(data.substr(5,1) != '/')
	{
		return false;
	}		
	if(data.substr(2,1) != '/')
	{
		return false;
	}	
	return true;
}

function NumberFormat(fld, milSep, decSep, e) 
{
	var sep = 0;
	var key = '';
	var i = j = 0;
	var len = len2 = 0;
	var strCheck = '0123456789';
	var aux = aux2 = '';
	var whichCode = (window.Event) ? e.which : e.keyCode;
	if (whichCode == 13) return true;  // Enter
		key = String.fromCharCode(whichCode);  // Get key value from key code
	if (strCheck.indexOf(key) == -1) return false;  // Not a valid key
	return true;
}

function SaltaCampo (campo,prox,tammax,teclapres)
{
	var tecla = teclapres.keyCode;
	vr = document.form[campo].value;
	if( tecla == 109 || tecla == 188 || tecla == 110 || tecla == 111 || tecla == 223 || tecla == 108 )
	{
		document.form[campo].value = vr.substr( 0, vr.length - 1 ); 
	}
	else
	{
	 	vr = vr.replace( "-", "" );
	 	vr = vr.replace( "/", "" );
	 	vr = vr.replace( "/", "" );
	 	vr = vr.replace( ",", "" );
	 	vr = vr.replace( ".", "" );
	 	vr = vr.replace( ".", "" );
	 	vr = vr.replace( ".", "" );
	 	vr = vr.replace( ".", "" );
	 	tam = vr.length;	
		
	 	if (tecla != 0 && tecla != 9 && tecla != 16 && tecla != 144 )
		{
		
			if ( tam == tammax )
			{
				if ( prox == "senhaConta" || (document.form.elements[prox] && document.form.elements[prox].name == "senhaConta"))
				{
					if ( document.applets['tclJava'] )
						document.applets['tclJava'].setFocus();
					else if ( document.form.senhaConta )
						document.form.senhaConta.focus();
				}
				else if ( document.form[prox] )
					document.form[prox].focus();
			}
		}
	}
}

function FormataData(campo,teclapres) 
{
	var tecla = teclapres.keyCode;
	vr = document.form[campo].value;
	vr = vr.replace( ".", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	tam = vr.length + 1;

	if ( tecla != 9 && tecla != 8 ){
		if ( tam > 2 && tam < 5 )
			document.form[campo].value = vr.substr( 0, tam - 2  ) + '/' + vr.substr( tam - 2, tam );
		if ( tam >= 5 && tam <= 10 )
			document.form[campo].value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 4 ); 
	}
}

function validaSenha()
{
    d = window.document.form;
    if (d.cpf_candidato.value == "")
	{		
		alert('Digite o seu CPF!');
		d.cpf_candidato.focus();
		return false;		
	}
    else
	{	
		if ((d.cpf_candidato.length < 11) || (d.cpf_candidato.length > 11))
		{
			alert('CPF inválido!');
			d.cpf_candidato.focus();
			return false;							
		}
	}	
    if (d.senha.value != "")
	{	
		if (d.senha.length < 4)
		{
			alert('A senha deve conter no mínimo 4 dígitos!');
			d.senha.focus();
			return false;							
		}
	}
}

function validaSenhaEmail()
{
    d = window.document.form1;
    if (d.nome_candidato.value == "")
	{		
		alert('Digite o seu Nome!');
		d.nome_candidato.focus();
		return false;		
	}	
    if (d.cpf_candidato.value == "")
	{		
		alert('Digite o seu CPF!');
		d.cpf_candidato.focus();
		return false;		
	}
    else
	{	
		if ((d.cpf_candidato.value.length < 11) || (d.cpf_candidato.value.length > 11))
		{
			alert('CPF inválido!');
			d.cpf_candidato.focus();
			return false;							
		}
	}	
    if (d.email_candidato.value == "")
	{
      	alert("O campo e-mail deve ser preenchido!");
        d.email_candidato.focus();
        return false;
    }	
    if (validaEmail(d.email_candidato.value) == false)
	{
     	alert("O campo e-mail deve ser preenchido corretamente!");
        d.email_candidato.focus();
        return false;
    }
}

