// JavaScript Document
function busca_cep()
	{
	window.open('busca_cep.htm','window_cep','toolbar=0,directories=0,menubar=0, height=360,width=355,top=50,left=300,status=0,resizable=0')
	}

function CaixaAlta(cmp) 
	{
	cmp.value = cmp.value.toUpperCase();
	}

function numericInput() // aceita apenas dados numéricos
	{
	if ((this == null) || (event == null)) return false;
	var ch = event.keyCode;
	if 	( (ch < 48) || (ch > 57)) 
		{
		event.keyCode = 0;
		alert("Digite apenas os números!!!");	
		return false;
		} 
	return true;
	}

function alfaInput() // aceita apenas dados alfa
	{
	if ((this == null) || (event == null)) return false;
	var ch = event.keyCode;
	switch (ch)
		{
		case 32:		
		case 65:
		case 66:
		case 67:
		case 68:
		case 69:
		case 70:
		case 71:
		case 72:
		case 73:
		case 74:
		case 75:
		case 76:
		case 77:
		case 78:
		case 79:
		case 80:
		case 81:
		case 82:
		case 83:
		case 84:
		case 85:
		case 86:
		case 87:
		case 88:
		case 89:
		case 90:
		case 97:
		case 98:
		case 99:
		case 100:
		case 101:
		case 102:
		case 103:
		case 104:
		case 105:
		case 106:
		case 107:
		case 108:
		case 109:
		case 110:
		case 111:
		case 112:
		case 113:
		case 114:
		case 115:
		case 116:
		case 117:
		case 118:
		case 119:
		case 120:
		case 121:
		case 122:
		case 199:
		case 231:
			return true;
			break;
		default:
			event.keyCode = 0;
	 		var at =  " Este campo deve ser preenchido somente com letras, não devem\n "
			at = at + " ser incluídos acentos gráficos, sinais de pontuação ou números."   
			alert(at);	
			return false;
		}
	}
	

//********************************************************************************* MASCARAS
function mask_cpf() {
	var valor
	valor = document.getElementById("_cpf").value; 	
	switch (valor.length) {
		case 9:
			valor+= "-";
		break;
	}
	document.getElementById("_cpf").value = valor;
}

function mask_cep(cep) {
	var valor
	valor = document.getElementById("_cep").value;
	switch (valor.length) {
		case 5:
			valor+= "-";
		break;
	}
	document.getElementById("_cep").value = valor;
}

function mask_fone(fone)	
	{
	var valor;
	var aux;
	valor = fone.value;
	switch (valor.length)		
		{
		case 0:
			aux=valor;
			valor="(" + aux;
		break;
		case 3:
			valor+=") ";
			break;
		case 9:
			valor+="-";
			break;
		}
	fone.value = valor;
	}
	
function mask_data(data)	
	{
	var valor
	valor = data.value;
	switch (valor.length)		
		{
		case 2:
			valor += "/";
			break;
		case 5:
			valor+= "/";
		break;
		}
		data.value = valor;
	}

function mask_titulo(titulo)	
	{
	var valor;
	var aux;
	valor = titulo.value;
	if  (valor.length < 10)
		{
		alert(valor+ "  Nº Título Invalido Verifique!!!");
		document.getElementById("_teinscr").value ="";
		document.getElementById("_teinscr").focus();
		document.getElementById("_teinscr").select();
		return false;
		}
	if  (valor.length == 10)
		{
		valor = "00" + valor
		}
	if  (valor.length == 11)
		{
		valor = "0" + valor
		}
	titulo.value = valor;
	}

function ins_cep() // usado quando é escolhido a cidade
	{
	cb = document.getElementById("_cidade").value;
	cp = cb.substr(0,9);
	document.getElementById("_cep").value = cp;
	document.getElementById("_cep").focus();
	document.getElementById("_cep").select();
	return true
	}

//********************************************************************************* VALIDAÇÕES
function validacpf()
	{ 
	var i; 
	s = document.getElementById("_cpf").value; 
	var c = s.substr(0,9); 
	var dv = s.substr(10,2); 
	var d1 = 0; 
	for (i = 0; i < 9; i++) 
		{ 
		d1 += c.charAt(i)*(10-i); 
		} 
	d1 = 11 - (d1 % 11); 
	if (d1 > 9) d1 = 0; 
	if (dv.charAt(0) != d1) 
		{ 
		alert(s +" CPF Inválido !!!")
		document.getElementById("_cpf").value = "";
		document.getElementById("_cpf").focus();
		return false; 
		} 
	d1 *= 2; 
	for (i = 0; i < 9; i++) 
		{ 
		d1 += c.charAt(i)*(11-i); 
		} 
	d1 = 11 - (d1 % 11); 
	if (d1 > 9) d1 = 0; 
	if (dv.charAt(1) != d1) 
		{
		alert(s+" CPF Invalido !!!") 
		document.getElementById("_cpf").value = "";
		document.getElementById("_cpf").focus();
		return false; 
		} 
	return true; 
	} 

function validaData() // validar data de nascimento
	{
	data = document.getElementById("_dtnasc").value;
	if (data.length < 10)
		{
		alert("Informe a data de nascimento na forma dd/mm/aaaa\n    informando apenas os números ddmmaaaa       ");
		document.getElementById("_dtnasc").value = "";
		document.getElementById("_dtnasc").focus();
		return false;
		}

	hoje = new Date();
	var dtBaseDia = 31;
	var dtBaseMes = 12;
	var dtBaseAno = 2010;
	anoAtual = hoje.getFullYear();
	barras = data.split("/");
	dia = barras[0];
	mes = barras[1];
	ano = barras[2];
	idade = dtBaseAno - ano;
	if((mes==4 || mes==6 || mes==9 || mes==11) && dia > 30)
		{
		alert("Dia incorreto !!! O mês especificado contém no máximo 30 dias.");
		document.getElementById("_dtnasc").value = "";
		document.getElementById("_dtnasc").focus();
		return false;
	} 
	if(ano%4==0 && mes==2 && dia > 29) {
		alert("Data incorreta!! O mês especificado contém no máximo 29 dias.");
		document.getElementById("_dtnasc").value = "";
		document.getElementById("_dtnasc").focus();
		return false;
	}	
	if(ano%4!=0 && mes==2 && dia > 28) {
		alert("Data incorreta!!! "+ano+" - Não é um ano bissesto");
		document.getElementById("_dtnasc").value = "";
		document.getElementById("_dtnasc").focus();
		return false;
	}
	if (idade < 17)
		{
		alert("Por favor confira sua data de nascimento "+data+"\nCandidato não habilitado a se increver neste\nConcurso, pelo motivo de ser menor de idade!");
		document.getElementById("_dtnasc").value = "";
		document.getElementById("_dtnasc").focus();
		return false;
		}
	if (idade > 69)
		{
		alert("Por favor confira sua data de nascimento "+data+"\nCandidato não habilitado a se increver neste Concurso, por possuir\n idade igual ou superior para aposentadoria compulsória!");
		document.getElementById("_dtnasc").value = "";
		document.getElementById("_dtnasc").focus();
		return false;
		}
	if (barras.length == 3)
		{
        resultado = (!isNaN(dia) && (dia > 0) && (dia < 32)) && (!isNaN(mes) && (mes > 0) && (mes < 13)) && (!isNaN(ano) && (ano.length == 4) && (ano <= anoAtual && ano >= 1900));
		if (!resultado) 	
			{
			alert("Data inválida, por favor entre novamente com sua data de nascimento");
			document.getElementById("_dtnasc").value = "";
			document.getElementById("_dtnasc").focus();
			return false;
			}
		}
		else 
			{
			alert("Formato de data invalido!");
			document.getElementById("_dtnasc").value = "";
			document.getElementById("_dtnasc").focus();
			return false;
		}
	return true;
	}

function ValidaDados() {
  if (document.getElementById("_nome").value == "") { // VERIFICA O NOME
    alert("Preencha o nome completo !!!");	
 	document.getElementById("_nome").focus();
   	return false;
  } 
  if (document.getElementById("_end").value == "" ) {  // VERIFICA O ENDEREÇO
    alert("Preencha o nome do logradouro onde mora !!!");	
    document.getElementById("_end").focus();
   	return false;
  }	
  if (document.getElementById("_end_num").value == "" ) { // VERIFICA O NÚMERO DO ENDEREÇO
    alert("Informe o número de sua residência, caso seja sem número, ponha o 0 (zero)!!!");	
    document.getElementById("_end_num").focus();
   	return false;
  }	
  if (document.getElementById("_bairro").value == "" ) { // VERIFICA O BAIRRO
    alert("Informe o bairro em que você reside !!!");	
    document.getElementById("_bairro").focus();
   	return false;
  }	
  if (document.getElementById("_cep").value == "" ) { // VERIFICA O CEP
    alert("Informe o CEP, caso não saiba, use o link ? ao lado !!!");	
    document.getElementById("_cep").focus();
	document.getElementById("_cep").select();
   	return false;
  }
  if (document.getElementById("_dtnasc").value == "" ) { // VERIFICA A DATA NASCIMENTO
    alert("Informe a data de nascimento no formato ddmmaaaa, digite apenas os números !!!");	
    document.getElementById("_dtnasc").focus();
 	document.getElementById("_dtnasc").select();	
   	return false;
  }	
  if (document.getElementById("_sexo").value == "0" ) { // VERIFICA O SEXO
    alert("Selecione o sexo !!!");	
    document.getElementById("_sexo").focus();
   	return false;
  }	
  if (document.getElementById("_teinscr").value == "" ) { // VERIFICA A NACIONALIDADE
    alert("Informe o número do título de eleitor !!!");	
    document.getElementById("_teinscr").focus();
	document.getElementById("_teinscr").select();
   	return false;
  }
  if (document.getElementById("_identidade").value == ""  ) { // VERIFICA O TIPO DE IDENTIDADE
    alert("Informe o número da identidade !!!");	
    document.getElementById("_identidade").focus();
	document.getElementById("_identidade").select();
   	return false;
  }
  if (document.getElementById("_identidadeuf").value == "0" ) { // VERIFICA A NACIONALIDADE
    alert("Selecione a UF de sua identidade !!!");	
    document.getElementById("_identidadeuf").focus();
   	return false;
  }	
  if (document.getElementById("_identidadetipo").value == "0" ) { // VERIFICA O TIPO DE IDENTIDADE
    alert("Selecione o tipo de identidade !!!");	
    document.getElementById("_identidadetipo").focus();
   	return false;
  }	
  if (document.getElementById("_email").value != document.getElementById("_email2").value) { // VERIFICA A NACIONALIDADE
     alert("email não corresponde!!! por favor reinforme o seu email...");
	 document.getElementById("_email").focus();
	 document.getElementById("_email").select();
   	 return false;
  }
  if (document.getElementById("_modo").value == "incluir") 
  {
	  IncluiDados()
  }
  else 
  { 
      AlteraDados() 
  }
  return true;
}

function IncluiDados() {
	document.fDados.submit();
	return true;
}

function AlteraDados() {
	document.fAlter.submit();
	return true;
}

