// Pega Id
function $Peg(StrId){		
	return document.getElementById(StrId);
}

// Funcao para permitir somente numeros
//
function somente_numero(campo){  
var digits="0123456789"  
var campo_temp   
 for (var i=0;i<campo.value.length;i++){  
     campo_temp=campo.value.substring(i,i+1)   
     if (digits.indexOf(campo_temp)==-1){  
         campo.value = campo.value.substring(0,i);  
     }  
 }  
} 

// Formata data
function formatData(StrId){
	
	var StrId;
	var par1;
	var par2;
	
	if($Peg(StrId).value.length == "2"){	
		par1 = $Peg(StrId).value;		
		$Peg(StrId).value = par1+"/";				
	}
	if($Peg(StrId).value.length == "5"){			
		par1 = $Peg(StrId).value;	
		$Peg(StrId).value = par1+"/";
	}	
}

// Somente numeros
function somente_numero(campo){  
var digits="0123456789/"  
var campo_temp   
 for (var i=0;i<campo.value.length;i++){  
     campo_temp=campo.value.substring(i,i+1)   
     if (digits.indexOf(campo_temp)==-1){  
         campo.value = campo.value.substring(0,i);  
     }  
 }  
} 

function validaInscricaoCPF(){
	// testá campo senha
	if($Peg('InsVest_cpf').value.length != 11){
		alert('O CPF informado nâo é valido!');				
		$Peg('InsVest_cpf').Focus
		return false;
	}
}	
// Funcao para validar Inscricao candidato
function validaInscricao(){
	
	// testá campo nome	
	if($Peg('InsVest_nome').value.length < 5){
		alert('O campo nome está inválido');				
		$Peg('InsVest_nome').Focus
		return false;
	}
	// testá campo data nascimento
	var data;
	var validaData;
	data = $Peg('InsVest_dataNasc');		
	if(data.value != ""){	
			
		if(data.value.charAt(0) < "4"){
			if(data.value.charAt(0) == "0" && data.value.charAt(1) == "0"){
				alert("O dia informado é inválido!");
				data.value ='';
				return false;
			}
			if(data.value.charAt(0) == "3" && data.value.charAt(1) >= "2"){
				alert("O dia informado é inválido!");
				data.value ='';
				return false;
			}					
			if(data.value.charAt(3) < "2"){				
				if(data.value.charAt(3) == "0" && data.value.charAt(4) == "0"){
					alert("O mes informado é inválido!");
					data.value ='';
					return false;
				}
				if(data.value.charAt(3) == "1" && data.value.charAt(4) >= "3"){
					alert("O mes informado é inválido!");
					data.value ='';
					return false;
				}			
				if(data.value.charAt(6) < "3"){					
					if((data.value.charAt(6) == "1" && data.value.charAt(7) == "9") || (data.value.charAt(6) == "2" && data.value.charAt(7) == "0" && data.value.charAt(8) == "0")){										
						validaData = 1;
						//return true;
					}else{
						alert("O ano informado é inválido!");
						data.value ='';
						return false;
					}
						
				}else{
					alert("O ano informado é inválido!");
					return false;
				}				
			}else{
				alert("O mes informado é inválido!");
				data.value ='';
				return false;
			}			
			
		}else{
			alert("O dia informado é inválido!");
			data.value ='';
			return false;
		}	
		
	}else{
		alert("O data de nascimento está vazia!");
		data.value ='';
		return false;
	}
	
	// testá campo rg	
	if($Peg('InsVest_identidade').value.length < 5){
		alert('O campo identidade está inválido');				
		$Peg('InsVest_identidade').Focus
		return false;
	}
	// testá campo orgao emissor
	if($Peg('InsVest_orgEmissor').value.length < 2){
		alert('O campo orgâo emissor está inválido');				
		$Peg('InsVest_orgEmissor').Focus
		return false;
	}
	// testá campo estadoEmissor
	if($Peg('InsVest_estadoEmissor').value == '-1'){
		alert('Selecione o estado emissor!');				
		$Peg('InsVest_estadoEmissor').Focus
		return false;
	}	
	// testá campo sexo
	if($Peg('InsVest_slcSexo').value == '-1'){
		alert('Selecione o sexo!');				
		$Peg('InsVest_slcSexo').Focus
		return false;
	}
	// Testá email
	if($Peg('InsVest_email').value.length < 5){
		alert('O campo e-mail deve conter um endereço eletrônico!');				
		$Peg('InsVest_email').Focus
		return false;
	}
	parte1 = $Peg('InsVest_email').value.indexOf("@");
    parte2 = $Peg('InsVest_email').value.indexOf(".");
    parte3 = $Peg('InsVest_email').value.length;
    if (!(parte1 >= 3 && parte2 >= 6 && parte3 >= 9)) {
          alert ("O campo e-mail deve conter um endereço eletrônico!");
          $Peg('InsVest_email').focus();
          return false;
    }
	// testá campo endereco
	if($Peg('InsVest_endereco').value.length < 5){
		alert('O campo endereço está inválido!');				
		$Peg('InsVest_endereco').Focus
		return false;
	}
	// testá campo numero
	if($Peg('InsVest_numero').value == ''){
		alert('O campo número está vazio!');				
		$Peg('InsVest_numero').Focus
		return false;
	}
	// testá campo bairro
	if($Peg('InsVest_bairro').value.length < 3){
		alert('O campo bairro está inválido!');				
		$Peg('InsVest_bairro').Focus
		return false;
	}
	// testá campo CEP
	if($Peg('InsVest_CEP').value.length < 7){
		alert('O campo CEP está inválido!');				
		$Peg('InsVest_CEP').Focus
		return false;
	}
	// testá campo cidade
	if($Peg('InsVest_cidade').value.length < 5){
		alert('O campo cidade está inválido!');				
		$Peg('InsVest_cidade').Focus
		return false;
	}
	// testá campo estado
	if($Peg('InsVest_estado').value == '-1'){
		alert('Selecione o seu estado!');				
		$Peg('InsVest_estado').Focus
		return false;
	}
	// testá campo ddd1
	if($Peg('InsVest_ddd1').value.length <= 1){
		alert('O campo DDD está inválido!');				
		$Peg('InsVest_ddd1').Focus
		return false;
	}
	// testá campo telefone1
	if($Peg('InsVest_tel1').value.length <= 7){
		alert('O campo telefone1 está inválido!');				
		$Peg('InsVest_tel1').Focus
		return false;
	}
	// testá campo Portador de Necessidade Especial
	if($Peg('InsVest_portadorNeceEspecial').value == '-1'){
		alert('Selecione uma opçâo para o campo Portador de Necessidade Especial!');				
		$Peg('InsVest_portadorNeceEspecial').Focus
		return false;
	}
	// testá campo destroCanhoto
	if($Peg('InsVest_destroCanhoto').value == '-1'){
		alert('Selecione uma opçâo para o campo Destro/Canhoto!');				
		$Peg('InsVest_destroCanhoto').Focus
		return false;
	}
	// testá campo curso
	if($Peg('InsVest_slcCurso').value == '-1'){
		alert('Selecione uma opçâo de curso!');				
		$Peg('InsVest_slcCurso').Focus
		return false;
	}else{
		return true;	
	}
}

// Funcao para validar questionario socio/economico
function validaQuestionarioSocioEco(){
		
	// testá campo EstadoCivil
	if($Peg('qst_EstadoCivil').value == '-1'){
		alert('Selecione o estado civil!');				
		$Peg('qst_EstadoCivil').Focus
		return false;
	}
	// Testá localEstudos
	if($Peg('qst_localEstudos').value == '1'){
		alert('Informe uma opçâo válida ao campo local de estudos !');				
		$Peg('qst_localEstudos').Focus
		return false;
	}
	// testá campo numProceSeletivo
	if($Peg('qst_numProceSeletivo').value == '-1'){
		alert('Selecione o número de processos seletivos que pretende prestar!');				
		$Peg('qst_numProceSeletivo').Focus
		return false;
	}
	// testá campo comoConheceFaseh
	if($Peg('qst_comoConheceFaseh').value == '-1'){
		alert('Informe como conheceu a FASEH!');				
		$Peg('qst_comoConheceFaseh').Focus
		return false;
	}
	// testá campo motivoInscricao
	if($Peg('qst_motivoInscricao').value.length < 5){
		alert('Informe o interesse pela FASEH!');				
		$Peg('qst_motivoInscricao').Focus
		return false;
	}
	// testá campo rendaFml
	if($Peg('qst_rendaFml').value == '-1'){
		alert('Informe a média da renda de sua família!');				
		$Peg('qst_rendaFml').Focus
		return false;
	}
	// testá campo totPessoalFamilisaRenda
	if($Peg('qst_totPessoalFamilisaRenda').value == '-1'){
		alert('Informe quantas pessoas se mantém com a renda de sua família!');				
		$Peg('qst_totPessoalFamilisaRenda').Focus
		return false;
	}
	// testá campo situaEconomica
	/*if($Peg('qst_situaEconomica').value == '-1'){
		alert('Informe sua situaçâo econômica!');				
		$Peg('qst_situaEconomica').Focus
		return false;
	}*/
	// testá campo instrucpai
	if($Peg('qst_instrucpai').value == '-1'){
		alert('Informe o nível de instruçâo de seu pai!');				
		$Peg('qst_instrucpai').Focus
		return false;
	}
	// testá campo grupoEcono_pai
	/*if($Peg('qst_grupoEcono_pai').value == '-1'){
		alert('Informe o grupo de ocupações no qual seu pai se encontra!');				
		$Peg('qst_grupoEcono_pai').Focus
		return false;
	}*/
	// testá campo grupoEcono_mae
	if($Peg('qst_grupoEcono_mae').value == '-1'){
		alert('Informe o nível de instruçâo de sua mâe');				
		$Peg('qst_grupoEcono_mae').Focus
		return false;
	}
	// testá campo meioInfo
	if($Peg('qst_meioInfo').value == '-1'){
		alert('Informe o seu principal meio de informação!');				
		$Peg('qst_meioInfo').Focus
		return false;
	}
	// testá campo acessoInternet
	if($Peg('qst_acessoInternet').value == '-1'){
		alert('Informe seu acesso à internet!');				
		$Peg('qst_acessoInternet').Focus
		return false;
	}else{
		return true;	
	}
}