// INICIO DE FUNCAO PARA VALIDAR CADASTRO DE PESSOA FISICA
function validaPessoaFisica()
{
	if (document.cad1.nome.value.length == 0)
	{
		alert("O campo NOME deve ser preenchido!");
		document.cad1.nome.focus();
		return false;
	}
	var xcpfPessoa = trim(document.cad1.cpf.value);
	xcpfPessoa = replaceString(".","",xcpfPessoa);
	xcpfPessoa = replaceString(",","",xcpfPessoa);	
	xcpfPessoa = replaceString("-","",xcpfPessoa);	
	xcpfPessoa = replaceString(" ","",xcpfPessoa);
	xcpfPessoa = replaceString("/","",xcpfPessoa);			
	if (!(isPositiveInteger(xcpfPessoa))){
		mensagem("CPF contém caracteres inválidos!");
		document.cad1.cpf.focus();
		return false;	
	}
	if (xcpfPessoa.length == 11){
		if (!(checaCPF(xcpfPessoa))) {
			mensagem("CPF inválido!");	
			document.cad1.cpf.value.focus();
			return false;
		}
	} else {
		if (xcpfPessoa.length == 14){
			if (!(checkCNPJ(xcpfPessoa))){
				mensagem("CNPJ inválido!");
				document.cad1.cpf.value.focus();
				return false;
			}
		} else {
			mensagem("O número de caracteres no campo CPF é inválido!");
			document.cad1.cpf.value.focus();
			return false;
		}		
	}
	if (document.cad1.rg.value.length == 0)
	{
		alert("O campo RG deve ser preenchido!");
		document.cad1.rg.focus();
		return false;
	}
	if (document.cad1.dataNascimento.value.length == 0)
	{
		alert("O campo DATA DE NASCIMENTO deve ser preenchido!");
		document.cad1.dataNascimento.focus();
		return false;
	}
	if (document.cad1.endereco.value.length == 0)
	{
		alert("O campo ENDEREÇO deve ser preenchido!");
		document.cad1.endereco.focus();
		return false;
	}
	if (document.cad1.bairro.value.length == 0)
	{
		alert("O campo BAIRRO deve ser preenchido!");
		document.cad1.bairro.focus();
		return false;
	}
	if (document.cad1.cep.value.length == 0)
	{
		alert("O campo CEP deve ser preenchido!");
		document.cad1.cep.focus();
		return false;
	}
	if (document.cad1.cidade.value.length == 0)
	{
		alert("O campo CIDADE deve ser preenchido!");
		document.cad1.cidade.focus();
		return false;
	}
	if (document.cad1.uf.value.length == 0)
	{
		alert("O campo ESTADO deve ser preenchido!");
		document.cad1.uf.focus();
		return false;
	}
	if (document.cad1.pais.value.length == 0)
	{
		alert("O campo PAÍS deve ser preenchido!");
		document.cad1.pais.focus();
		return false;
	}
	if (document.cad1.ddd.value.length == 0)
	{
		alert("O campo DDD deve ser preenchido!");
		document.cad1.ddd.focus();
		return false;
	}
	if (document.cad1.fone.value.length == 0)
	{
		alert("O campo TELEFONE deve ser preenchido!");
		document.cad1.fone.focus();
		return false;
	}
	if (document.cad1.complemento.value.length == 0)
	{
		alert("O campo INFO. COMPLEMENTARES deve ser preenchido!");
		document.cad1.complemento.focus();
		return false;
	}
	if (document.cad1.patrimonio.value.length == 0)
	{
		alert("O campo BENS deve ser preenchido!");
		document.cad1.patrimonio.focus();
		return false;
	}
	/*
	if (document.cad1.nomeConjuge.value.length == 0)
	{
		alert("O campo NOME DO CONJUGE deve ser preenchido!");
		document.cad1.nomeConjuge.focus();
		return false;
	}
	var xcpfConjuge = trim(document.cad1.cpfConjuge.value);
	xcpfConjuge = replaceString(".","",xcpfConjuge);
	xcpfConjuge = replaceString(",","",xcpfConjuge);	
	xcpfConjuge = replaceString("-","",xcpfConjuge);	
	xcpfConjuge = replaceString(" ","",xcpfConjuge);
	xcpfConjuge = replaceString("/","",xcpfConjuge);			
	if (!(isPositiveInteger(xcpfConjuge))){
		mensagem("CPF DO CONJUGE contém caracteres inválidos!");
		document.cad1.cpfConjuge.focus();
		return false;	
	}
	if (xcpfConjuge.length == 11){
		if (!(checaCPF(xcpfConjuge))) {
			mensagem("CPF DO CONJUGE inválido!");	
			document.cad1.cpfConjuge.value.focus();
			return false;
		}
	} else {
		if (xcpfConjuge.length == 14){
			if (!(checkCNPJ(xcpfConjuge))){
				mensagem("CPF DO CONJUGE inválido!");
				document.cad1.cpfConjuge.value.focus();
				return false;
			}
		} else {
			mensagem("O número de caracteres no campo CPF DO CONJUGE é inválido!");
			document.cad1.cpfConjuge.value.focus();
			return false;
		}		
	}
	if (document.cad1.rgConjuge.value.length == 0)
	{
		alert("O campo RG DO CONJUGE deve ser preenchido!");
		document.cad1.rgConjuge.focus();
		return false;
	}
	*/
	if (document.cad1.banco.value.length == 0)
	{
		alert("O campo BANCO deve ser preenchido!");
		document.cad1.banco.focus();
		return false;
	}
	if (document.cad1.agencia.value.length == 0)
	{
		alert("O campo AGÊNCIA deve ser preenchido!");
		document.cad1.agencia.focus();
		return false;
	}
	if (document.cad1.numeroConta.value.length == 0)
	{
		alert("O campo NÚMERO DA CONTA deve ser preenchido!");
		document.cad1.numeroConta.focus();
		return false;
	}	
}
// FIM DE FUNCAO PARA VALIDAR CADASTRO DE PESSOA FISICA

// INICIO DE FUNCAO PARA VALIDAR CADASTRO DE PESSOA JURIDICA
function validaPessoaJuridica()
{
	if (document.cad1.razaoSocial.value.length == 0)
	{
		alert("O campo RAZÃO SOCIAL deve ser preenchido!");
		document.cad1.razaoSocial.focus();
		return false;
	}
	if (document.cad1.nomeFantasia.value.length == 0)
	{
		alert("O campo NOME FANTASIA deve ser preenchido!");
		document.cad1.nomeFantasia.focus();
		return false;
	}	
	var xcnpjPessoa = trim(document.cad1.cnpj.value);
	xcnpjPessoa = replaceString(".","",xcnpjPessoa);
	xcnpjPessoa = replaceString(",","",xcnpjPessoa);	
	xcnpjPessoa = replaceString("-","",xcnpjPessoa);	
	xcnpjPessoa = replaceString(" ","",xcnpjPessoa);
	xcnpjPessoa = replaceString("/","",xcnpjPessoa);			
	if (!(isPositiveInteger(xcnpjPessoa))){
		mensagem("CNPJ contém caracteres inválidos!");
		document.cad1.cpf.focus();
		return false;	
	}
	if (xcnpjPessoa.length == 11){
		if (!(checaCPF(xcnpjPessoa))) {
			mensagem("CNPJ inválido!");	
			document.cad1.cnpj.value.focus();
			return false;
		}
	} else {
		if (xcnpjPessoa.length == 14){
			if (!(checkCNPJ(xcnpjPessoa))){
				mensagem("CNPJ inválido!");
				document.cad1.cnpj.value.focus();
				return false;
			}
		} else {
			mensagem("O número de caracteres no campo CNPJ é inválido!");
			document.cad1.cnpj.value.focus();
			return false;
		}		
	}
	if (document.cad1.inscricaoEstadual.value.length == 0)
	{
		alert("O campo INSCRIÇÃO ESTADUAL deve ser preenchido!");
		document.cad1.inscricaoEstadual.focus();
		return false;
	}
	if (document.cad1.endereco.value.length == 0)
	{
		alert("O campo ENDEREÇO deve ser preenchido!");
		document.cad1.endereco.focus();
		return false;
	}
	if (document.cad1.bairro.value.length == 0)
	{
		alert("O campo BAIRRO deve ser preenchido!");
		document.cad1.bairro.focus();
		return false;
	}
	if (document.cad1.cep.value.length == 0)
	{
		alert("O campo CEP deve ser preenchido!");
		document.cad1.cep.focus();
		return false;
	}
	if (document.cad1.cidade.value.length == 0)
	{
		alert("O campo CIDADE deve ser preenchido!");
		document.cad1.cidade.focus();
		return false;
	}
	if (document.cad1.uf.value.length == 0)
	{
		alert("O campo ESTADO deve ser preenchido!");
		document.cad1.uf.focus();
		return false;
	}
	if (document.cad1.pais.value.length == 0)
	{
		alert("O campo PAÍS deve ser preenchido!");
		document.cad1.pais.focus();
		return false;
	}
	if (document.cad1.ddd.value.length == 0)
	{
		alert("O campo DDD deve ser preenchido!");
		document.cad1.ddd.focus();
		return false;
	}
	if (document.cad1.fone.value.length == 0)
	{
		alert("O campo TELEFONE deve ser preenchido!");
		document.cad1.fone.focus();
		return false;
	}
	if (document.cad1.complemento.value.length == 0)
	{
		alert("O campo INFO. COMPLEMENTARES deve ser preenchido!");
		document.cad1.complemento.focus();
		return false;
	}
	if (document.cad1.patrimonio.value.length == 0)
	{
		alert("O campo BENS deve ser preenchido!");
		document.cad1.patrimonio.focus();
		return false;
	}
	if (document.cad1.nomeSocio.value.length == 0)
	{
		alert("O campo NOME DO SÓCIO OU TITULAR deve ser preenchido!");
		document.cad1.nomeSocio.focus();
		return false;
	}
	var xcpfSocio = trim(document.cad1.cpfSocio.value);
	xcpfSocio = replaceString(".","",xcpfSocio);
	xcpfSocio = replaceString(",","",xcpfSocio);	
	xcpfSocio = replaceString("-","",xcpfSocio);	
	xcpfSocio = replaceString(" ","",xcpfSocio);
	xcpfSocio = replaceString("/","",xcpfSocio);			
	if (!(isPositiveInteger(xcpfSocio))){
		mensagem("CPF DO SÓCIO OU TITULAR contém caracteres inválidos!");
		document.cad1.cpfSocio.focus();
		return false;	
	}
	if (xcpfSocio.length == 11){
		if (!(checaCPF(xcpfSocio))) {
			mensagem("CPF DO SÓCIO OU TITULAR inválido!");	
			document.cad1.cpfSocio.value.focus();
			return false;
		}
	} else {
		if (xcpfSocio.length == 14){
			if (!(checkCNPJ(xcpfSocio))){
				mensagem("CPF DO SÓCIO OU TITULAR inválido!");
				document.cad1.cpfSocio.value.focus();
				return false;
			}
		} else {
			mensagem("O número de caracteres no campo CPF DO SÓCIO OU TITULAR é inválido!");
			document.cad1.cpfSocio.value.focus();
			return false;
		}		
	}
	if (document.cad1.rgSocio.value.length == 0)
	{
		alert("O campo RG DO SÓCIO OU TITULAR deve ser preenchido!");
		document.cad1.rgSocio.focus();
		return false;
	}
	if (document.cad1.banco.value.length == 0)
	{
		alert("O campo BANCO deve ser preenchido!");
		document.cad1.banco.focus();
		return false;
	}
	if (document.cad1.agencia.value.length == 0)
	{
		alert("O campo AGÊNCIA deve ser preenchido!");
		document.cad1.agencia.focus();
		return false;
	}
	if (document.cad1.numeroConta.value.length == 0)
	{
		alert("O campo NÚMERO DA CONTA deve ser preenchido!");
		document.cad1.numeroConta.focus();
		return false;
	}	
}
// FIM DE FUNCAO PARA VALIDAR CADASTRO DE PESSOA FISICA
//Tratamento de números
function soNumero()  
{
	if (!(event.keyCode>47 && event.keyCode<58)) event.keyCode=0;
}

// Função para tratamento do formato de telefone (com 3 ou 4 números de prefixo)
function formataTelefone(obj)
{
	numero = _extraiNumero(obj.value)
	if (numero.length >= 10) {
		formataCampo(obj, "(XX)XXXX-XXXX")
	} else if (numero.length == 9) {
		formataCampo(obj, "(XX)XXX-XXXX")
	} else if (numero.length == 8) {
		formataCampo(obj, "XXXX-XXXX")
	} else if (numero.length > 4) {
		formataCampo(obj, "XXX-XXXX")
	} else {
		if (obj.value != numero)
		{
			obj.value = numero
		}
	}
}

function formataCampo(obj, mascara)
{
	var valor = ''
	var tamValor = 0
	var tamMascara = 0
	var resultado = ''
	var aux1 = ''
	var aux2 = ''
	var posMas = 1
	var posVal = 1
	var tecla = obj.value.substr( obj.value.length - 1, 1)
	var masclen = mascara.length

	if(obj.value.length > mascara.length)
	{
		valor = _extraiNumero(obj.value.substring(0, obj.value.length-(obj.value.length-mascara.length)))
	} else {
		valor = _extraiNumero(obj.value)
	}

	//muda formatação somente quando receber uma tecla válida 
	if( !_teclaValida(tecla) && (obj.value != ''))
	{
		tamValor = valor.length
		tamMascara = mascara.length
		while((posVal <= tamValor) && (posMas <= tamMascara))
		{
			// percorre caracter por caracter no valor dado (do fim p/ começo)
			aux1 = valor.substring(tamValor - posVal, (tamValor - posVal) + 1)
			// percorre caracter por caracter na máscara (do fim p/ começo)
			aux2 = mascara.substring(tamMascara - posMas, (tamMascara - posMas) + 1)
			if(aux2 == 'X')
			{
				resultado = aux1 + resultado
				posVal = posVal + 1
			}else if((aux2 == '-') || (aux2 == '/') || (aux2 == '.' ) || (aux2 == '(') || (aux2 == ')') || (aux2 == ',')) // símbolos presentes nas máscaras
			{
				resultado = aux2 + resultado
			}
			posMas = posMas + 1
		}
		//  colocando "posMas" e "posVal" em suas posições atuais
		posVal = posVal - 1
		posMas = posMas - 1
		// caso especial para número de telefone (máscara começa com símbolo)
		if((posMas == tamMascara - 1) && (mascara.substring(0, 1) == '('))
		{
			resultado = '(' + resultado
		}
		
		if (obj.value != resultado)
		{
			if ( (resultado.length>=obj.maxLength) && (masclen>=resultado.length) )
			{
				if (masclen == resultado.length)
				{
					obj.maxLength = masclen
				} else{
					obj.maxLength = resultado.length+1
				}
			}
			obj.value = resultado
		}
		
	}
}

// Retorna true quando for um número
function _somenteNumero(numero)
{
	// numeros aceitos 0,1,2,3,4,5,6,7,8,9,37,38,39,40,46
	ER=/(^[0-2]$|^3[789]{0,1}$|^4[06]{0,1}$|^[5-9]$)/
	return ER.test(numero)
}

//  teclas que podem ser pressionadas
function _teclaValida(tecla)
{
	// 8  backspace			9  Tab				33 PageUp				34 PageDown	
	// 35 End				36 Home 			37 seta para esquerda	38 seta para cima 
	// 39 seta para direita 40 seta para baixo	46 Delete
	ER=/(^[8-9]$|^3[3-9]{1}$|^4[06]{1}$)/
	return ER.test(numero)
}

// retorna somente números [0..9]
function _extraiNumero(dado)
{
	var aux = ''
	for(n=0; n < dado.length; n++){
		if(_somenteNumero(dado.substr(n,1))){
			aux += dado.substr(n,1)
		}
	}
	return aux
}

// Validação de e-mail
function validaEmail(obj, alerta)
{
	var str = obj.value;

	// @ deve estar pelo menos na posição 1 de str,
	// deve estar pelo menos na posição 3 de str e não pde pode estar na última posição de str.
	if(str.length>0 && (str.indexOf('@') < 1 || str.indexOf('.') < 3 || (str.length < 5) || (str.substr(str.length-1, 1) == '.')))
	{
		// exibe mensagem ao usuário.
		if(alerta)
		{
			alert('E-mail inválido: ' + str);
		}
		if(obj != null)
		{
			obj.focus();
		}
		return false;
	} else {
		return true;
	}
}
// formatacao de datas
function mascara_data(param){
	var mydata = '';
	mydata = mydata + param.value;
	if (mydata.length == 2){
		mydata = mydata + '/';
		param.value = mydata;
	}
	if (mydata.length == 5){
		mydata = mydata + '/';
		param.value = mydata;
	}
	if (mydata.length == 10){
		verifica_data(param);
	}
}

function verifica_data (param) 
{
	dia = (param.value.substring(0,2));
	mes = (param.value.substring(3,5));
	ano = (param.value.substring(6,10));

	situacao = "";
	// verifica o dia valido para cada mes
	if ((dia < 01)||(dia < 01 || dia > 30) && (  mes == 04 || mes == 06 || mes == 09 || mes == 11 ) || dia > 31) {
		situacao = "falsa";
	}

	// verifica se o mes e valido
	if (mes < 01 || mes > 12 ) {
		situacao = "falsa";
	}

	// verifica se e ano bissexto
	if (mes == 2 && ( dia < 01 || dia > 29 || ( dia > 28 && (parseInt(ano / 4) != ano / 4)))) {
		situacao = "falsa";
	}

	// verifica se e ano esta correto
	if (situacao == "" && ano.length != 4) {
		alert("O ano deve possuir quatro dígitos!");
		param.value = dia + "/" + mes + "/";
		param.focus();
		return
	}

	if (situacao == "falsa") {
		if (param.value != "") 
		{
			alert("Data inválida!");
			param.value="";
			param.focus();
		}
	}
}

function checaCPF (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")
		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)))
		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)))
		return false;
	return true;
}

/**/

function checkEmailAddress(field) {
	var good;
	var goodEmail = field.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
	if (goodEmail){
		good = true
	} else {
		alert('Entre com um E-mail Válido.')
		field.focus()
		field.select()
		good = false
	}
	return good;
}

/**/

function isLength(str,tam) {
	if (str.length < tam) {
		return true;
	}
	return false;
}

/*
   A função mensagem recebe um texto como parâmetro e emite um alerta
   com este texto usando a função interna do java script alert()
*/
function mensagem( msg ) {
	alert( msg );
}

/*
   A função isEmpty recebe uma variavel como parâmetro e verifica se a
   mesma possui algum conteúdo caso a valiarel possua conteúdo a função
   da um retorno false e caso contrário um retorno true, ou seja, se 
   avariavel for nula ou em branco returna verdadeiro se a varivel possuir
   algum valor ou conteúdo retorna falso.
*/
function isEmpty(str) {
	if (str==null || str=="") {
		return true;
	}
	return false;
}

/*
   A função trim aceita um parâmetro str que é uma string que precisa ser
   aparada. A primeira loop while verifica continuamente  o último caracter
   da string e trunca o último caracter, se ele for um espaço em branco. A
   segunda loop while verifica o primeiro caractere na string, remove o
   primeiro caractere, se ele for um espaço, e troca o restante da string um
   caracter para a esquerda. Ao final a função retorna a String devidamente
   aparada.
*/
function trim(str) {
	while (str.charAt(str.length - 1)==" ") {
		str = str.substring(0, str.length - 1);
	}
	while (str.charAt(0)==" ") {
		str = str.substring(1, str.length);
	}
	return str;
}

/*
   A função isPositiveInteger só retorna true se todos os caracteres que compõem
   o argumento string passados a ela forem numéricos. A função faz um loop através
   do argumento string do primeiro ao último caracter. Ela compara cada caracter
   com um padrão e pára e tetorna falso se encontrar um caracter que não combine
   com qualquer composição de caracteres do padrão.
*/
function isPositiveInteger(str) {
	var pattern = "0123456789";
	var i = 0;
	do {
		var pos = 0;
		for (var j=0; j<pattern.length; j++) {
			if (str.charAt(i)==pattern.charAt(j)) {
				pos = 1;
				break;
			}
		}
		i++;
	} while (pos==1 && i<str.length)
	if (pos==0) {
		return false;
	}
	return true;
}

/*
   Valida um campo
*/
function validaCampoInput(field,msg,tam) {
	if (isEmpty(field.value)) {
		mensagem("O Campo "+msg+" deve ser preenchido.\nTente novamente.");
		field.focus();
		return false;
	}
	if (isLength(field.value,tam)) {
		mensagem("O Campo "+msg+" deve ter no mínimo "+tam+" caracteres.\nTente novamente.");
		field.focus();
		return false;
	}
	return true;
}

function validaCampoSelect(field,msg) {
	if (field.value == 0) {
		mensagem(msg+"\nTente novamente.");
		field.focus();
		return false;
	}
	return true;
}

function replaceString(oldS,newS,fullS) {
	for (var i=0; i<fullS.length; i++) {
		if (fullS.substring(i,i+oldS.length) == oldS) {
			fullS = fullS.substring(0,i)+newS+fullS.substring(i+oldS.length,fullS.length);
		}
	}
	return fullS;
}


function getNumber( number , len ) {
	var result = '';
	var num, i;
	for ( i = 0 ; i < number.length ; i++ ) {
		try	{
			num = parseInt( number.substring( i, i + 1 ) );
			result += num;
		} catch (exception) { }
	}
	if ( result.length != len ) {
		// Complet with zeros
		result = '000000000000000' + result;
		var newLen = result.length;
		result = result.substring ( newLen - len , newLen );
	}
	return result;
}
   
function check1( value ) {
	var count = 1;
	var len = value.length;
	var first;
	if ( len > 1 ) {
		first = value.charAt( 0 );
	} else {
		return false;
	}
	for ( var i = 1; i < value.length ; i++ ) {
		if ( value.charAt( i ) == first ) {
			count++;
		}
	}
 	if ( count == len ) {
		return false;
	}
	return true;
}

function checkCNPJ( cnpj ) { 
	var cnpjCalc; 
	var cnpjAdd; 
	var i; 
	var cnpjDigit; 
	cnpj = getNumber( cnpj , 14 );
	check1( cnpj );
    // Get only numeric digits
	cnpjCalc = cnpj.substring( 0 , 12 );
	// First part of digit verification
	cnpjAdd = 0; 
	for( i = 0 ; i < 4 ; i++ ) { 
		cnpjAdd += parseInt( cnpjCalc.substring( i , i + 1 ) ) * (5 - i); 
	}
	for( i = 0 ; i < 8 ; i++ ) { 
		cnpjAdd += parseInt( cnpjCalc.substring( i + 4 , i + 4 + 1 ) ) * (9 - i); 
	} 
    // Fisrt digit
	cnpjDigit = 11 - (cnpjAdd % 11); 
    if ( cnpjDigit == 10 || cnpjDigit == 11 ) { 
		cnpjCalc += '0'; 
	} else { 
		cnpjCalc += cnpjDigit; 
	} 
	// Second part of digit verification
	cnpjAdd = 0; 
	for ( i = 0 ; i < 5 ; i++ ) { 
		cnpjAdd += parseInt( cnpjCalc.substring( i , i + 1 ) ) * (6 - i); 
	} 
	for ( i = 0 ; i < 8 ; i++ ) { 
		cnpjAdd += parseInt( cnpjCalc.substring( i + 5, i + 5 + 1 ) ) * (9 - i); 
	} 
    // Second digit
	cnpjDigit = 11 - (cnpjAdd % 11); 
	if ( cnpjDigit == 10 || cnpjDigit == 11 ) { 
		cnpjCalc += '0'; 
	} else { 
		cnpjCalc += cnpjDigit; 
	} 
	return ( cnpj == cnpjCalc ); 
}

function pulaCep2() {
		if (document.cad.cep1.value.length == 5) {
			document.cad.cep2.focus();
		}
	}
	function pulaEstado() {
		if (document.cad.cep2.value.length == 3) {
			document.cad.uf.focus();
		}
	}
	function zera() {
                for (i = 0; i < (document.forms[0].elements.length -2); i++) { 
                        document.forms[0].elements[i].value = ""
                }
		document.cad.categoria.focus()
}