// JavaScript Document
// JavaScript Document

// Verifica se o dia foi digitado corretamente
function verificaRegDia() {
valor = document.IncluiCliente.dia_registro.value;
tam = document.IncluiCliente.dia_registro.value.length;
re = /[a-z]/gi
resultado = re.exec(valor);
resultadonum = valor.split(re);
     if(resultado || tam != "2" || resultadonum > 31 || resultadonum == 00)
{
   alert ("Digite o dia corretamente");
   document.IncluiCliente.dia_registro.select();
   document.IncluiCliente.dia_registro.value="";
   document.IncluiCliente.dia_registro.focus();
     }
}

// Verifica se o Mes foi digitado corretamente
function verificaRegMes() {
valor = document.IncluiCliente.mes_registro.value;
tam = document.IncluiCliente.mes_registro.value.length;
re = /[a-z]/gi
resultado = re.exec(valor);
resultadonum = valor.split(re);
     if(resultado || tam != "2" || resultadonum > 12 || resultadonum == 00)
{
   alert ("Digite o mês corretamente");
   document.IncluiCliente.mes_registro.select();
   document.IncluiCliente.mes_registro.value="";
   document.IncluiCliente.mes_registro.focus();
     }
}

// Verifica se o Ano foi digitado corretamente
function verificaRegAno() {
valor = document.IncluiCliente.ano_registro.value;
tam = document.IncluiCliente.ano_registro.value.length;
re = /[a-z]/gi
resultado = re.exec(valor);
resultadonum = valor.split(re);
     if(resultado || tam != "4" || resultadonum < 1900 || resultadonum >
2002) {
   alert ("Digite o ano corretamente");
   document.IncluiCliente.ano_registro.select();
   document.IncluiCliente.ano_registro.value="";
   document.IncluiCliente.ano_registro.focus();

  }else{
   diaReg=document.IncluiCliente.dia_registro.value;
   mesReg=document.IncluiCliente.mes_registro.value;
   anoReg=document.IncluiCliente.ano_registro.value;
   ok=checkRegdate(diaReg,mesReg,anoReg);
     }
}

// Verifica se a data completa é válida
function checkRegdate(diaReg,mesReg,anoReg) {
if (chkRegdate(diaReg,mesReg,anoReg) == false) {
  alert("A data digitada é inválida. Digite novamente");
  document.IncluiCliente.dia_registro.value="";
  document.IncluiCliente.mes_registro.value="";
  document.IncluiCliente.ano_registro.value="";
  document.IncluiCliente.dia_registro.select();
  document.IncluiCliente.dia_registro.focus();
  return false;
}
else {
  return true;
    }
}

// Verifica se a data completa é válida
function chkRegdate(diaReg,mesReg,anoReg) {
var intDay = parseInt(diaReg, 10);
var intMonth = parseInt(mesReg, 10);
var intYear = parseInt(anoReg, 10);

if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 ||
intMonth == 8 || intMonth == 10 || intMonth == 12) && (intDay > 31 || intDay
< 1)) {
  return false;
}
if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) &&
(intday > 30 || intDay < 1)) {
  return false;
}
if (intMonth == 2) {
  if (intDay < 1) {
   return false;
  }
  if (LeapRegYear(intYear) == true) {
   if (intDay > 29) {
    return false;
   }
  }
  else {
   if (intDay > 28) {
    return false;
   }
  }
}
return true;
}

// Verifica se o ano é bissexto
function LeapRegYear(intYear) {
if (intYear % 100 == 0) {
  if (intYear % 400 == 0) { return true; }
} else {
  if ((intYear % 4) == 0) { return true; }
}
return false;
}





// Verifica se o dia foi digitado corretamente
// JavaScript Document

// Verifica se o dia foi digitado corretamente
function verificaDia() {
valor = document.IncluiCliente.dia_nascimento.value;
tam = document.IncluiCliente.dia_nascimento.value.length;
re = /[a-z]/gi
resultado = re.exec(valor);
resultadonum = valor.split(re);
     if(resultado || tam != "2" || resultadonum > 31 || resultadonum == 00)
{
   alert ("Digite o dia corretamente");
   document.IncluiCliente.dia_nascimento.select();
   document.IncluiCliente.dia_nascimento.value="";
   document.IncluiCliente.dia_nascimento.focus();
     }
}

// Verifica se o Mes foi digitado corretamente
function verificaMes() {
valor = document.IncluiCliente.mes_nascimento.value;
tam = document.IncluiCliente.mes_nascimento.value.length;
re = /[a-z]/gi
resultado = re.exec(valor);
resultadonum = valor.split(re);
     if(resultado || tam != "2" || resultadonum > 12 || resultadonum == 00)
{
   alert ("Digite o mês corretamente");
   document.IncluiCliente.mes_nascimento.select();
   document.IncluiCliente.mes_nascimento.value="";
   document.IncluiCliente.mes_nascimento.focus();
     }
}

// Verifica se o Ano foi digitado corretamente
function verificaAno() {
valor = document.IncluiCliente.ano_nascimento.value;
tam = document.IncluiCliente.ano_nascimento.value.length;
re = /[a-z]/gi
resultado = re.exec(valor);
resultadonum = valor.split(re);
     if(resultado || tam != "4" || resultadonum < 1900 || resultadonum >
2002) {
   alert ("Digite o ano corretamente");
   document.IncluiCliente.ano_nascimento.select();
   document.IncluiCliente.ano_nascimento.value="";
   document.IncluiCliente.ano_nascimento.focus();

  }else{
   dia=document.IncluiCliente.dia_nascimento.value;
   mes=document.IncluiCliente.mes_nascimento.value;
   ano=document.IncluiCliente.ano_nascimento.value;
   ok=checkdate(dia,mes,ano);
     }
}

// Verifica se a data completa é válida
function checkdate(dia,mes,ano) {
if (chkdate(dia,mes,ano) == false) {
  alert("A data digitada é inválida. Digite novamente");
  document.IncluiCliente.dia_nascimento.value="";
  document.IncluiCliente.mes_nascimento.value="";
  document.IncluiCliente.ano_nascimento.value="";
  document.IncluiCliente.dia_nascimento.select();
  document.IncluiCliente.dia_nascimento.focus();
  return false;
}
else {
  return true;
    }
}

// Verifica se a data completa é válida
function chkdate(dia,mes,ano) {
var intDay = parseInt(dia, 10);
var intMonth = parseInt(mes, 10);
var intYear = parseInt(ano, 10);

if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 ||
intMonth == 8 || intMonth == 10 || intMonth == 12) && (intDay > 31 || intDay
< 1)) {
  return false;
}
if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) &&
(intday > 30 || intDay < 1)) {
  return false;
}
if (intMonth == 2) {
  if (intDay < 1) {
   return false;
  }
  if (LeapYear(intYear) == true) {
   if (intDay > 29) {
    return false;
   }
  }
  else {
   if (intDay > 28) {
    return false;
   }
  }
}
return true;
}

// Verifica se o ano é bissexto
function LeapYear(intYear) {
if (intYear % 100 == 0) {
  if (intYear % 400 == 0) { return true; }
} else {
  if ((intYear % 4) == 0) { return true; }
}
return false;
}


function valida_cpf(){
	var datanascimento = document.IncluiCliente.ano_nascimento.value + "-" + document.IncluiCliente.mes_nascimento.value + "-" + document.IncluiCliente.dia_nascimento.value;
	IncluiCliente.datanascimento.value = datanascimento;	

	var datadiplomacao = document.IncluiCliente.ano_registro.value + "-" + document.IncluiCliente.mes_registro.value + "-" + document.IncluiCliente.dia_registro.value;
	IncluiCliente.dataregistrocrea.value = datadiplomacao;

	var cpf = IncluiCliente.cpf.value;
	var nome = IncluiCliente.nome.value;
	var tamsenha = IncluiCliente.senha.length;
	var senha = IncluiCliente.senha.value;
	var confirmasenha = IncluiCliente.confirmasenha.value;
	var email = IncluiCliente.email.value;
	var endereco = IncluiCliente.enderecores.value;
	var cidade = IncluiCliente.cidaderes.value;
	var cep = IncluiCliente.cepres.value;
	var nacionalidade = IncluiCliente.nacionalidade.value;
	var naturalidade = IncluiCliente.naturalidade.value;
	var estadocivil = IncluiCliente.estadocivil.value;
	var dependentes = IncluiCliente.dependentes.value;
	var rg = IncluiCliente.rg.value;
	var filiacaopais = IncluiCliente.filiacaopais.value;
	var foneres = IncluiCliente.foneres.value;
	var uf = IncluiCliente.uf.value;
	var empresa = IncluiCliente.empresa.value;
	var enderecocom = IncluiCliente.enderecocom.value;
	var foneempresa = IncluiCliente.foneempresa.value;
	var titulo = IncluiCliente.titulo.value;
	var universidadediploma = IncluiCliente.universidadediploma.value;
	var numerocrea = IncluiCliente.numerocrea.value;
	var qualtitulo = IncluiCliente.qualtitulo.value;

// check to see if the field is blank
	if (datanascimento == "")	{
		alert("O campo 'Data de Nacimento' não pode ficar em branco!");
		return (false);
	}
// check to see if the field is blank
	if (nacionalidade == "")	{
		alert("O campo 'Nacionalidade' não pode ficar em branco!");
		return (false);
	}
	// check to see if the field is blank
	if (naturalidade == "")	{
		alert("O campo 'Naturalidade' não pode ficar em branco!");
		return (false);
	}
	// check to see if the field is blank
	if (estadocivil == "")	{
		alert("O campo 'Estado Civil' não pode ficar em branco!");
		return (false);
	}
	// check to see if the field is blank
	if (dependentes == "")	{
		alert("O campo 'Dependentes' não pode ficar em branco!");
		return (false);
	}
	// check to see if the field is blank
	if (rg == "")	{
		alert("O campo 'RG' não pode ficar em branco!");
		return (false);
	}
		
// check to see if the field is blank
	if (filiacaopais == "")	{
		alert("O campo 'Filiação' não pode ficar em branco!");
		return (false);
	}
	// check to see if the field is blank
	if (foneres == "")	{
		alert("O campo 'Telefone Residencial' não pode ficar em branco!");
		return (false);
	}
	// check to see if the field is blank
	if (uf == "")	{
		alert("O campo 'UF' não pode ficar em branco!");
		return (false);
	}
	// check to see if the field is blank
	if (empresa == "")	{
		alert("O campo 'Empresa' não pode ficar em branco!");
		return (false);
	}
	
// check to see if the field is blank
	if (enderecocom == "")	{
		alert("O campo 'Endereço Comercial' não pode ficar em branco!");
		return (false);
	}
	
	// check to see if the field is blank
	if (foneempresa == "")	{
		alert("O campo 'Telefone Comercial' não pode ficar em branco!");
		return (false);
	}
	
	// check to see if the field is blank
	if (titulo == "")	{
		alert("O campo 'Título' não pode ficar em branco!");
		return (false);
	}
	
	if(titulo == "607") {
		 if (qualtitulo == "")	{
			alert("O campo 'Qual titulo?' não pode ficar em branco!");
			return (false);
	}  
	   
	}
	
	// check to see if the field is blank
	if (datadiplomacao == "")	{
		alert("O campo 'Data do Registro' não pode ficar em branco!");
		return (false);
	}
	
	// check to see if the field is blank
	if (universidadediploma == "")	{
		alert("O campo 'Faculdade' não pode ficar em branco!");
		return (false);
	}
	
	// check to see if the field is blank
	if (numerocrea == "")	{
		alert("O campo 'Registro no CREA' não pode ficar em branco!");
		return (false);
	}
	
		// check to see if the field is blank
	if (nome == "")	{
		alert("O campo 'Nome' não pode ficar em branco!");
		return (false);
	}
	
	// check to see if the field is blank
	if (endereco == "")	{
		alert("O campo \"Endereço\" não pode ficar em branco");
		return (false);
	}

	// check to see if the field is blank
	if (cidade == "")	{
		alert("O campo \"Cidade\" não pode ficar em branco");
		return (false);
	}
	
	
	// check to see if the field is blank
	if (cep == "")	{
		alert("O campo \"CEP\" não pode ficar em branco");
		return (false);
	}

	// require at least 6 characters in the field
	if (tamsenha < 6){
		alert("Por favor inclusa pelo menos 6 caracteres no campo \"Senha\" ");
		return (false);
	}
	
	// check if both password fields are the same
	if (senha != confirmasenha)	{
		alert("As senhas digitadas não são iguais");
		return (false);
	}
	
	// check if email field is blank
	if (email == ""){
		alert("O campo \"Email\" não pode ficar em branco");
		return (false);
	} else {	
	// test if valid email address, must have @ and .
			var checkEmail = "@.";
			var checkStr = IncluiCliente.email.value;
			var EmailValid = false;
			var EmailAt = false;
			var EmailPeriod = false;
			for (i = 0;  i < checkStr.length;  i++)	{
				ch = checkStr.charAt(i);
				for (j = 0;  j < checkEmail.length;  j++){
					if (ch == checkEmail.charAt(j) && ch == "@") EmailAt = true;
					if (ch == checkEmail.charAt(j) && ch == ".") EmailPeriod = true;
					if (EmailAt && EmailPeriod)	break;
					if (j == checkEmail.length)	break;
				}
				// if both the @ and . were in the string
				if (EmailAt && EmailPeriod)	{
					EmailValid = true
					break;
				}
			}
			if (!EmailValid){
		5    ý ôù  " È6         ðÎù    ýÄ6         ðù    ðýâ6  þŠ  I   ðý 	ñ5    ý 9ú  à6         ð4ù     â6  þŠ  E   ðý ñ5  n  ü  ù    Ó6  þŠ  S " ð3ù    ýÊ6  þŠ  J " ð+ù    ðýÂ6  þŠ  H " ðù      à6  þŠ  F " ð9ù    
ý¼6         ðù    ðýÄ6  þŠ  P " ðù      È6  þŠ  G " ð%ù    À6  þŠ  C " ðù    ðýÆ6  þŠ  K " ðù      Ý6  þŠ  V " ð4ù    ¨NÂ6         ðù    ðýà6         ðsù      ¾6         ðù    à6         ð/ù    ðý¼6          ðý ñ5    þR  ù ðýà6          ðý 	ñ5    ý 4ú ðý¼6          ðý ñ5    ,  ù ðý¼6          ðý ñ5    ¦Y  ù ðý¼6          ðý ñ5    %
  ù ðý¼6          ðý ñ5    ÿ  ù ðý¼6          ðý 	ñ5    ý ù ðý¼6          ðý ñ5    ?|  ù ðý¼6          ðý ñ5    0  ù ðý¼6          ðý ñ5    ÿ  ù ðý¼6          ðý 	ñ5    zý ù ðý¼6          ðý ñ5    Ã  ù ðý¼6          ðý ñ5    ž  ù ðýÆ6          ðý 	ñ5  Ä  ý šù ðý¼6          ðý ñ5  Ä  D
 ù ðý¼6          ðý ñ5  Ä  ò  ù ðý¼6          ðý ñ5  Ä  â  ù ðý¼6          ðý ñ5  Ä  ‰  ù ðý¾6          ðý 	ñ5  A   ý &ù ðý¼6          ðý 	ñ5  A  Àý ù ðý¼6          ðý 	ñ5  A  ý ù ðý¾6          ðý ñ5  A  ’  	ù ðýÊ6          ðý 	ñ5     ý $ù ðý¾6          ðý 	ñ5  ›  ý ù ðý¼6          ðý ñ5  ›  ˆ  ù ðýÓ6          ðý 	ñ5  ›  
ý #ù ðýÓ6          ðý ñ5  ›  è  ù ðýÓ6          ðý ñ5  ›  ÿ  ù ðýÓ6          ðý ñ5  ›  9Í ù ðýÓ6          ðý 	ñ5  ›  Þý ù 	†Ó6          ðý ñ5  ›  i³ ù 	Ó6          ðý 	ñ5  ›  ý ù ¾6          ðý 	ñ5  ‹  ý ù 	†¼6          ðý 	ñ5  ‹  ý ù 	¼6          ðý 	ñ5  ‹  ý ù †¾6          ðý ñ5  ‰  >Í  ù 	†¼6          ðý 	ñ5  ‰  ±ý ù 	¾¼6          ðý ñ5  ‰  S  ù †Ó6          ðý 	ñ5  „  	ý /ù 	¼6          ðý ñ5  ‚  Í  ù 	†¾6          ðý ñ5  ‚  ¦  ù 	‘¼6          ðý ñ5  ‚  È  ù êÆ6          ðý 	ñ5  Ú  Yý ù 	¾à6          ðý ñ5  ©  Ë	  $ù 	êÂ6          ðý 	ñ5  Ã  ý Jù 	Â6          ðý ñ5  Ã  m  ù 	‘Â6          ðý 	ñ5  Ã  ý ù êÈ6          ðý 	ñ5  Ã  ý ù 	À6          ðý 	ñ5  a  ý Èù ê¼6          ðý 	