// JavaScript Document
var isNN = (navigator.appName.indexOf("Netscape")!=-1);
function autoTab(input,len, e) {
var keyCode = (isNN) ? e.which : e.keyCode; 
var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
if(input.value.length >= len && !containsElement(filter,keyCode)) {
input.value = input.value.slice(0, len);
input.form[(getIndex(input)+1) % input.form.length].focus();
}

function containsElement(arr, ele) {
var found = false, index = 0;
while(!found && index < arr.length)
if(arr[index] == ele)
found = true;
else
index++;
return found;
}

function getIndex(input) {
var index = -1, i = 0, found = false;
while (i < input.form.length && index == -1)
if (input.form[i] == input)index = i;
else i++;
return index;
}
return true;
}
function trim(str){
   return str.replace(/^\s*|\s*$/g,"");
}
 
 
function validacpf(cpf){
   var filtro = /^\d{3}.\d{3}.\d{3}-\d{2}$/i;
   if(!filtro.test(cpf)){
     window.alert("CPF inválido.");
	 return false;
   }
   
   cpf = remove(cpf, ".");
   cpf = remove(cpf, "-");
    
   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");
	  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");
	 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");
	 return false;
   }
   return true;
 }
 
 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;
 }

 

function verifica1(frm){
	if(trim(frm.txtrg.value)==""){
		 alert("O Preenchimento do RG é Obrigatório!");
		 frm.txtrg.focus();
		 return false;
	}
	if(trim(frm.txtnome.value)==""){
		 alert("O Preenchimento do Nome é Obrigatório!");
		 frm.txtnome.focus();
		 return false;
	}
	if((!frm.rad_sexo[0].checked) && (!frm.rad_sexo[1].checked)){
		 alert("Selecione o Sexo!");
		 return false;
	}
    if(frm.select_dia.selectedIndex==0){
		 alert("Selecione o Dia de Nascimento!");
		 return false;
	}
	if(frm.select_mes.selectedIndex==0){
		 alert("Selecione o Mês de Nascimento!");
		 return false;
	}

	if(frm.select_ano.selectedIndex==0){
		 alert("Selecione o Ano de Nascimento!");
		 return false;
	}

	if((trim(frm.txtnome_mae.value)=="")&&(trim(frm.txtcpf.value)=="")){
		 alert("Preencha o CPF ou o Nome da Mãe");
		 frm.txtnome.focus();
		 return false;
	}
	
	if(trim(frm.txtcpf.value)!=""){
		
		if(!validacpf(frm.txtcpf.value)){
			return false;
		}
	}
	

	if(frm.select_estado_nasc.value==""){
		 alert("Selecione o Estado de Nascimento!");
		 return false;
	}
	
	if(frm.select_cidade_nasc.value==""){
		 alert("Selecione a Cidade de Nascimento!");
		 return false;
	}

   if((!frm.rad_ensino[0].checked) && (!frm.rad_ensino[1].checked)){
		 alert("Selecione a Opção do Ensino Médio: Rede Particular ou Rede Pública");
		 return false;
	}
	
   if((!frm.rad_concluiu[0].checked) && (!frm.rad_concluiu[1].checked)){
		 alert("Selecione uma Opção para o Ano de Conclusão do Ensino Médio");
		 return false;
	}	
	/*
   if((!frm.rad_treineiro[0].checked) && (!frm.rad_treineiro[1].checked)){
		 alert("Selecione a Opção de Treineiro(Sim ou Não)!");
		 return false;
	}
  */
	if(trim(frm.txtnum.value)==""){
		 alert("O Preenchimento do Número é Obrigatório!");
		 frm.txtnum.focus();
		 return false;
	}
 return true;	
}

function checkIt(evt) {
    evt = (evt) ? evt : window.event
    var charCode = (evt.which) ? evt.which : evt.keyCode
    if (charCode == 34 || charCode == 39) {
        return false
    }
    status = ""
    return true
}

function verifica2(frm){
	if(frm.select_op1.selectedIndex==0){
		 alert("A Escolha da Primeira Opção é Obrigatória!");
		 return false;
	}
 return true;	
}

 function lettersOnly(evt) {
       evt = (evt) ? evt : event;
       var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode :
          ((evt.which) ? evt.which : 0));
       if (charCode > 32 && (charCode < 65 || charCode > 90 || charCode < 9 ) && (charCode < 97 || charCode > 122)) {
          //alert("Enter letters only.");
          return false;
       }
       return true;
     }

