// JavaScript Document
function SomenteNumero(e){
    var tecla=(window.event)?event.keyCode:e.which;
    if((tecla > 47 && tecla < 58)) return true;
    else{
    if (tecla != 8) return false;
    else return true;
    }
}
function validaForm(){
	d = document.cadastro;
           //validar nome
           if (d.nome.value.length < 5){
                     alert("O campo Nome Completo deve ser preenchido!");
                     d.nome.focus();
                     return false;
           }
	var cpf = d.cpf.value;
   	if(cpf.length != 11 || cpf == "00000000000" || cpf == "11111111111" ||
		cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" ||
	  	cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" ||
	  	cpf == "88888888888" || cpf == "99999999999"){
	  	window.alert("CPF inválido. Tente novamente.");
	  	d.cpf.focus();
	  	return false;
   }
   soma = 0;
   for(i = 0; i < 9; i++)
   	 soma += parseInt(cpf.charAt(i)) * (10 - i);
   resto = 11 - (soma % 11);
   if(resto == 10 || resto == 11)
	 resto = 0;
   if(resto != parseInt(cpf.charAt(9))){
	 window.alert("CPF inválido. Tente novamente.");
	 d.cpf.focus();
	 return false;
   }
   soma = 0;
   for(i = 0; i < 10; i ++)
	 soma += parseInt(cpf.charAt(i)) * (11 - i);
   resto = 11 - (soma % 11);
   if(resto == 10 || resto == 11)
	 resto = 0;
   if(resto != parseInt(cpf.charAt(10))){
     window.alert("CPF inválido. Tente novamente.");
	 d.cpf.focus();
	 return false;
   }
 function remove(str, sub) {
   i = str.indexOf(sub);
   r = "";
   if (i == -1) return str;
   r += str.substring(0,i) + remove(str.substring(i + sub.length), sub);
   return r;
 }
 if (d.ano.value == "" || d.ano.value.length <4){
                     alert("Ano Incorreto!");
                     d.ano.focus();
                     return false;
           }		   
		   if (d.estado.options.selectedIndex == 0){
                     alert("Selecione um estado!");
                     d.estado.focus();
                     return false;
           }
		   if (d.cidade.options.selectedIndex == 0){
                     alert("Selecione uma cidade!");
                     d.estado.focus();
                     return false;
           }
		   if (d.bairro.value == ""){
                   alert("O campo Bairro deve ser preenchido corretamente!");
                   d.bairro.focus();
                   return false;
         	}
			if (d.cep.value == "" || d.cep.value.length < 8){
                   alert("O campo CEP deve ser preenchido corretamente!");
                   d.cep.focus();
                   return false;
         	}
			if (d.logradouro.value == ""){
                   alert("O campo Logradouro deve ser preenchido corretamente!");
                   d.logradouro.focus();
                   return false;
         	}
		  if (d.codTelefone.value == "" || d.codTelefone.value.length <2){
                   alert("O campo Código do Telefone deve ser preenchido corretamente!");
                   d.codTelefone.focus();
                   return false;
         }
		 if (d.telefone.value == "" || d.telefone.value.length <8){
                   alert("O campo Telefone deve ser preenchido corretamente!");
                   d.telefone.focus();
                   return false;
         }
		 if (d.codCelular.value == "" || d.codCelular.value.length <2){
                   alert("O campo Código do Celular deve ser preenchido corretamente!");
                   d.codCelular.focus();
                   return false;
         }
		 if (d.celular.value == "" || d.celular.value.length <8){
                   alert("O campo Celular deve ser preenchido corretamente!");
                   d.celular.focus();
                   return false;
         }
		 if (d.email.value == ""){
                   alert("O campo Email deve ser preenchido corretamente!");
                   d.email.focus();
                   return false;
         }
		 parte1 = d.email.value.indexOf("@");
         parte2 = d.email.value.indexOf(".");
         parte3 = d.email.value.length;
         if (!(parte1 >= 3 && parte2 >= 6 && parte3 >= 9)) {
                   alert ("O campo Email deve conter um endereco eletronico válido!");
                   d.email.focus();
                   return false;
         }
		 if (d.tipoFormacao1.options.selectedIndex == 0){
                   alert("Selecione um tipo de formação!");
                   d.tipoFormacao1.focus();
                   return false;
         }
		 if (d.instituicao1.value.length <= 1){
                   alert("O campo Instituição deve ser preenchido corretamente!");
                   d.instituicao1.focus();
                   return false;
         }
		 if (d.anoConclusao.value == "" || d.anoConclusao.value.length <4){
                   alert("O campo Ano de Conclusão deve ser preenchido corretamente!");
                   d.anoConclusao.focus();
                   return false;
         }
}
function habilita(){
	if (document.getElementById('formacao1').value != "Outros"){
		document.getElementById('outroFormacao1').disabled = "disabled";
		document.getElementById('outroFormacao1').value = "";
	}else{
		document.getElementById('outroFormacao1').disabled = false;
	}
}

function habilita2(){
	if (document.getElementById('formacao2').value != "Outros"){
		document.getElementById('outroFormacao2').disabled = "disabled";
		document.getElementById('outroFormacao2').value = "";
	}else{
		document.getElementById('outroFormacao2').disabled = false;
	}
}
function habilita3(){
	if (document.getElementById('formacao3').value != "Outros"){
		document.getElementById('outroFormacao3').disabled = "disabled";
		document.getElementById('outroFormacao3').value = "";
	}else{
		document.getElementById('outroFormacao3').disabled = false;
	}
}

function habilitaTeste(e){
	
	if(document.getElementById('tipoFormacao1').value != "Selecione um tipo de formação" && document.getElementById('instituicao1').value != "" && document.getElementById('anoConclusao').value.length>2){
	  document.getElementById('tipoFormacao2').disabled = false;
	  }else{
		  document.getElementById('tipoFormacao2').disabled = true;
	  }
	
	var tecla=(window.event)?event.keyCode:e.which;
    if((tecla > 47 && tecla < 58)){
		return true;
	}else{
    	if (tecla != 8){
			return false;
		}else{
			return true;
    	}
	}
}