<!--

function submete(form) {
	
		if(document.cadastro.email.value== "") {window.alert("Preencha o e-mail."); return;
		} else if(!document.cadastro.pessoa[0].checked && !document.cadastro.pessoa[1].checked) {window.alert("Selecione pessoa Física ou Jurídica."); return;
		} else if(document.cadastro.nome.value== "") {window.alert("Preencha o nome."); return;		
		} else if(document.cadastro.nome.value.length <2) {window.alert("O nome deve ter mais de 1 letra."); return;
		} else if(document.cadastro.sobrenome.value== "") {window.alert("Preencha o sobrenome."); return;
		} else if(document.cadastro.sobrenome.value.length < 2) {window.alert("O sobrenome deve ter mais de 1 letra."); return;
		} else if(document.cadastro.cpf_cnpj.value== "") {window.alert("Preencha o CPF/ CNPJ."); return;
		} else if(document.cadastro.cargo.value== "") {window.alert("Preencha o cargo."); return;
		} else if(document.cadastro.cargo.value.length <2) {window.alert("O cargo deve ter mais de 1 letra."); return;		
		} else if(document.cadastro.endereco_rua.value== "") {window.alert("Preencha o endereço."); return;
		} else if(document.cadastro.endereco_rua.value.length < 2) {window.alert("O endereço deve ter mais de 1 letra."); return;
		} else if(document.cadastro.endereco_numero.value== "") {window.alert("Preencha o número."); return;
		} else if(document.cadastro.endereco_bairro.value== "") {window.alert("Preencha o bairro."); return;
		} else if(document.cadastro.endereco_bairro.value.length < 2) {window.alert("O bairro deve ter mais de 1 letra."); return;
		} else if(document.cadastro.endereco_cidade.value== "") {window.alert("Preencha a cidade."); return;
		} else if(document.cadastro.endereco_cidade.value.length < 2) {window.alert("A cidade deve ter mais de 1 letra."); return;
		} else if(document.cadastro.endereco_estado.value== "") {window.alert("Selecione o estado."); return;
		} else if(document.cadastro.endereco_cep.value== "") {window.alert("Preencha o CEP."); return;
		} else if(document.cadastro.endereco_cep.value.length < 8) {window.alert("O CEP deve ter 8 dígitos."); return;
		} else if(document.cadastro.telefone_ddd.value== "") {window.alert("Preencha o DDD."); return;
		} else if(document.cadastro.telefone_ddd.value.length < 2) {window.alert("O DDD deve ter 2 dígitos."); return;
		} else if(document.cadastro.telefone_numero.value== "") {window.alert("Preencha o telefone."); return;
		} else if(document.cadastro.telefone_numero.value.length < 8) {window.alert("O telefone deve ter 8 dígitos."); return;
		} else {


		if(document.cadastro.senha.value != "") {

		if(document.cadastro.senha.value.length > 3||
           document.cadastro.senha.value.length >11)

        {

        if(document.cadastro.senha.value == document.cadastro.confirma_senha.value) {


					    var test = false;
                        var error_msg = "";

						if(document.cadastro.pessoa[1].checked) {

							test = verificaCGC(document.cadastro.cpf_cnpj.value);
							error_msg = "Número de CNPJ inválido!";

						} else {
							test = verificaCPF(document.cadastro.cpf_cnpj.value);
							error_msg = "Número de CPF inválido!";
						}
	
					   if(test) {

							document.cadastro.confirma_senha.value = document.cadastro.senha.value;
							document.cadastro.submit();

						} else {

							window.alert(error_msg);
							return;
						}

	
		            } else { 



				     window.alert("As senhas precisam ser iguais!");

		            }

                 }else{

					window.alert("A senha precisa ter de 04 a 10 caracteres!");

		        }



      		}else{  window.alert("Você precisa especificar uma Senha!"); }



	   }
}

// -----------------------------------

function ValChar(ch) {
if (ch=="0") return 0
else if (ch=="1") return 1
else if (ch=="2") return 2
else if (ch=="3") return 3
else if (ch=="4") return 4
else if (ch=="5") return 5
else if (ch=="6") return 6
else if (ch=="7") return 7
else if (ch=="8") return 8
else if (ch=="9") return 9
else return 10
}

//Verifica se o argumento é um CPF válido
function verificaCPF (CKCPF) {

  for (var x= 0; x <= CKCPF.length; x++) {
	CKCPF=CKCPF.replace(' ','');
	CKCPF=CKCPF.replace('/','');
	CKCPF=CKCPF.replace('-','');
	if(CKCPF.charAt(x) == ".") {
	   var p1 = CKCPF.substring(0,x);
	   var p2 = CKCPF.substring(x+1,CKCPF.length);
       CKCPF = p1+p2;   
	}
  }


  var CPF = CKCPF;
  var NewCPF = "";

//Verifica tamanho do CPF
if (CPF.length!=11) {
return false;
}
//Calcula os dígitos verificadores
//Guarda os 09 primeiros digitos
var DVCPF = CPF.substring(0,9);
var s1 = 0
for (i=1;i<=9;i++) s1 = s1 + (ValChar(DVCPF.charAt(i-1))*(11-i))
r1 = s1 % 11
if (r1<2) dv1=0
else dv1 = 11 - r1
var s2 = dv1*2
for (i=1;i<=9;i++) s2 = s2 + (ValChar(DVCPF.charAt(i-1))*(12-i))
r2 = s2 % 11
if (r2<2) dv2=0
else dv2 = 11 - r2
var DV = ""
DV = DV + dv1 + dv2
var NewDV = CPF.substring(9,11)
if (NewDV==DV) return true
else {
return false
}
}


//Verifica se o argumento é um CGC válido de 8 dígitos
function verificaCGC8 (CKCGC) {
var CGC = CKCGC;
var NewCGC = "";
//Elimina todos os espaços, pontos, barras e traços do CGC
for (i=0;i<CGC.length;i++) { //>
if (CGC.charAt(i) != " " && CGC.charAt(i) != "." && CGC.charAt(i) !=
"/" && CGC.charAt(i) != "-") NewCGC = NewCGC + CGC.charAt(i);
}
//Verifica tamanho do CGC
if (NewCGC.length!=8) {
return false;
}
//verifica se todos os caracteres são numéricos
var Numerico = false;
var Numeros = "0123456789";
for (i=0;i<NewCGC.length;i++) { //>
Numerico = false;
for (j=0;j<Numeros.length;j++) { //>
if (NewCGC.charAt(i) == Numeros.charAt(j)) {
Numerico = true;
break;
}
}
if (!Numerico) {
return false;
}
}
//Calcula os dígitos verificadores
var s1 = 0;
aux = 0;
soma = 0
for (i=1;i<=8;i++) {
//alert("i="+i+" - char(i-1)="+NewCGC.charAt(i-1));
aux = (ValChar(NewCGC.charAt(i-1)))*((i % 2)+1);
//alert ("aux="+aux);
if (aux>9) aux = aux-9;
//alert ("aux="+aux);
soma = soma + aux;
}
r1 = soma % 10;
//alert("soma="+soma+" - resto="+r1);
if (r1==0) return (true)
else {
return (false);
}
}

//Verifica se o argumento é um CGC válido
function verificaCGC (CKCGC) {

  for (var x= 0; x <= CKCGC.length; x++) {
	CKCGC=CKCGC.replace(' ','');
	CKCGC=CKCGC.replace('/','');
	CKCGC=CKCGC.replace('-','');
	if(CKCGC.charAt(x) == ".") {
	   var p1 = CKCGC.substring(0,x);
	   var p2 = CKCGC.substring(x+1,CKCGC.length);
       CKCGC = p1+p2;   
	}
  }

var CGC = CKCGC;
var NewCGC = "";
//Verifica tamanho do CGC
if (CGC.length!=14) {
return false;
}
//Calcula os dígitos verificadores
//Guarda os 12 primeiros digitos
var DVCGC = CGC.substring(0,12);
//calcula o primeiro digito verificador
var s1 = 0;
for (i=1;i<=4;i++) s1 = s1 + (ValChar(DVCGC.charAt(i-1))*(6-i));
for (i=5;i<=12;i++) s1 = s1 + (ValChar(DVCGC.charAt(i-1))*(14-i));
r1 = s1 % 11;
if (r1<2) dv1=0;
else dv1 = 11 - r1;
//calcula o segundo digito verificador
var s2 = dv1*2;
for (i=1;i<=5;i++) s2 = s2 + (ValChar(DVCGC.charAt(i-1))*(7-i));
for (i=6;i<=12;i++) s2 = s2 + (ValChar(DVCGC.charAt(i-1))*(15-i));
r2 = s2 % 11;
if (r2<2) dv2=0;
else dv2 = 11 - r2;
//junta os digitos verificadores
var DV = "";
DV = DV + dv1 + dv2;
//guarda os digitos verificadores do CGC digitado (últimas duas posições no string)
var NewDV = CGC.substring(12,14)
if (NewDV==DV) { //se o DV calculado for igual ao digitado, retorna true
return true
}
else {
return false
}
}

// -----------------------------------

function isEmailAddress(theElement, theElementName)
{

   var s = document.cadastro.email.value;
   var filter=/^[A-Za-z][A-Za-z0-9_.-]*@[A-Za-z0-9_-]+\.[A-Za-z0-9_.-]+[A-Za-z]$/;

   if (s.length == 0 ) 
       return true;
 
   if (filter.test(s)) {
       return true;
   } else {

     window.alert("E-mail inválido. Preencha o campo corretamente.");
     document.cadastro.email.focus(); 
     return false;
  }

}

//------------------------------

function Reseta()	{

	document.cadastro.reset();

}

//-------------------------------


function pulaFone() {
	
	var nm_telefone = document.cadastro.telefone_ddd.value;
	
	if (nm_telefone.length == 2) {
		document.cadastro.telefone_numero.focus();
	}

}

//--------------------------------


function pulaCep() {
	
	var nm_cep = document.cadastro.endereco_cep.value;
	
	if (nm_cep.length == 8) {
		document.cadastro.telefone_ddd.focus();
	}

}




//--------------------------------


function pulaData1() {
	
	var nm_mes = document.cadastro.dia_nascimento.value;

	if (nm_mes.length == 2) {
    	document.cadastro.mes_nascimento.focus();
	}
}


//--------------------------------


function pulaData2() {
	
	var nm_ano = document.cadastro.mes_nascimento.value;

	if (nm_ano.length == 2) {
		document.cadastro.ano_nascimento.focus();
	}
}


//--------------------------------


function pulaData3() {
	
	var nm_cargo = document.cadastro.ano_nascimento.value;

	if (nm_cargo.length == 4) {
		document.cadastro.cargo.focus();
	}
}


//-->
