///////////////////////////////////////////////////////////////////////////////////////////////////////////////
//cadastre-se
function fn_seleciona_tipo_pessoa(tipo){
	if(tipo == "fisica"){
		document.getElementById('oculta_empresa').style.display = 'none';
		document.getElementById('oculta_empresaa').style.display = 'none';
		document.getElementById('oculta_dado').style.display = '';
		document.getElementById('oculta_nome').style.display = '';
	}
	if(tipo == "juridica"){
		document.getElementById('oculta_empresa').style.display = '';
		document.getElementById('oculta_empresaa').style.display = '';
		document.getElementById('oculta_dado').style.display = 'none';
		document.getElementById('oculta_nome').style.display = 'none';
	}
}

function somenteLetras(evt){
	evt = (evt) ? evt : event;
	var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : ((evt.which) ? evt.which : 0));
	if (charCode < 46 || charCode > 65){
		return true;
	}
	if (charCode > 31 && (charCode < 64 || charCode > 90) && (charCode < 97 || charCode > 122)){
		alert("Somente letras por favor.");
		return false;
	}
	
	return true;
}

function trim(str) {
		return str.replace(/^\s+|\s+$/g,"");
	}

// valida cadastre-se
function ValidaCadastro(formCadastro){
	if((document.getElementById('pessoa_f').checked == false)&&(document.getElementById('pessoa_j').checked == false)){
		alert("Atenção!\nO campo PESSOA deve ser preenchido.");
		return false;
	}
	if(document.getElementById('pessoa_j').checked == true){
		if(trim(formCadastro.razao_social.value) == ''){
			alert("O campo RAZÃO SOCIAL deve ser preenchido.");
			formCadastro.razao_social.focus();
			return false;
		}
		if(trim(formCadastro.nome_contato.value) == ''){
			alert("O campo NOME DO CONTATO deve ser preenchido.");
			formCadastro.nome_contato.focus();
			return false;
		}
		if(trim(formCadastro.cnpj.value).length < 18){
			alert("O campo CNPJ deve ser preenchido.");
			formCadastro.cnpj.focus();
			return false;
		}
	}
	if(document.getElementById('pessoa_f').checked == true){
		if(trim(formCadastro.nome_cadastro.value) == ''){
			alert("O campo NOME deve ser preenchido.");
			formCadastro.nome_cadastro.focus();
			return false;
		}
		if(trim(formCadastro.sobrenome.value) == ''){
			alert("O campo Sobrenome deve ser preenchido.");
			formCadastro.sobrenome.focus();
			return false;
		}
		if(trim(formCadastro.cpf.value).length < 14){
			alert("O campo CPF deve ser preenchido.");
			formCadastro.cpf.focus();
			return false;
		}
		if(trim(formCadastro.rg.value).length < 7){
			alert("O campo RG deve ser preenchido.");
			formCadastro.rg.focus();
			return false;
		}
		if(trim(formCadastro.data_nasc.value).length < 10){
			alert("O campo DATA DE NASCIMENTO deve ser preenchido.");
			formCadastro.data_nasc.focus();
			return false;
		}
		var contador ;
			var flag ;

			flag = false ;

			for ( contador = 0 ; contador < formCadastro.sexo.length ; contador ++ )
			{
				if ( formCadastro.sexo[contador].checked )
				{
					flag = true ;
				}
			}

			if ( !flag )
			{
				alert("O campo Sexo deve estar preenchido corretamente.");
				return false ;
			}
	}
	if(trim(formCadastro.email_cadastro.value) == ''){
		alert("O campo EMAIL deve ser preenchido.");
		formCadastro.email_cadastro.focus();
		return false;
	}
	if(trim(formCadastro.email_cadastro.value).search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1){
		alert("Atenção!\nO campo E-MAIL deve ser preenchido corretamente.");
		formCadastro.email_cadastro.value = ('');
		formCadastro.email_cadastro.focus();
		return false;
 	}
	if(trim(formCadastro.senha_cadastro.value) == ''){
		alert("O campo SENHA deve ser preenchido.");
		formCadastro.senha_cadastro.focus();
		return false;
	}
	if(trim(formCadastro.endereco.value) == ''){
		alert("O campo ENDEREÇO deve ser preenchido.");
		formCadastro.endereco.focus();
		return false;
	}
	if(trim(formCadastro.numero.value) == ''){
		alert("O campo N° deve ser preenchido.");
		formCadastro.numero.focus();
		return false;
	}
	if(trim(formCadastro.bairro.value) == ''){
		alert("O campo BAIRRO deve ser preenchido.");
		formCadastro.bairro.focus();
		return false;
	}
	if(trim(formCadastro.cep.value).length < 9){
		alert("O campo CEP deve ser preenchido.");
		formCadastro.cep.focus();
		return false;
	}
	if(trim(formCadastro.cidade.value) == ''){
		alert("O campo CIDADE deve ser preenchido.");
		formCadastro.cidade.focus();
		return false;
	}
    if(trim(formCadastro.idestado.value) == ''){
		alert("O campo ESTADO deve ser preenchido.");
		formCadastro.idestado.focus();
		return false;
	}
	if(trim(formCadastro.telefone1.value) == ''){
		alert("O campo TELEFONE FIXO deve ser preenchido.");
		formCadastro.telefone1.focus();
		return false;
	}
}
