function Letras_Grandes(){
  document.NOME_DO_FORM.NOME_DO_CAMPO.value = document.NOME_DO_FORM.NOME_DO_CAMPO.value.toUpperCase();
  document.NOME_DO_FORM.NOME_DO_CAMPO.value = document.NOME_DO_FORM.NOME_DO_CAMPO.value.toUpperCase();
  document.NOME_DO_FORM.NOME_DO_CAMPO.value = document.NOME_DO_FORM.NOME_DO_CAMPO.value.toLowerCase();
  document.NOME_DO_FORM.NOME_DO_CAMPO.value = document.NOME_DO_FORM.NOME_DO_CAMPO.value.toUpperCase();
}

function Letras_Pequenas(){
  document.NOME_DO_FORM.NOME_DO_CAMPO.value = document.NOME_DO_FORM.NOME_DO_CAMPO.value.toLowerCase();
  document.NOME_DO_FORM.NOME_DO_CAMPO.value = document.NOME_DO_FORM.NOME_DO_CAMPO.value.toLowerCase();
  document.NOME_DO_FORM.NOME_DO_CAMPO.value = document.NOME_DO_FORM.NOME_DO_CAMPO.value.toLowerCase();
  document.NOME_DO_FORM.NOME_DO_CAMPO.value = document.NOME_DO_FORM.NOME_DO_CAMPO.value.toLowerCase();
}

// exibe empresa
function empresa() {
document.getElementById('empresa').style.display='block';
document.getElementById('profliberal').style.display='none';
document.getElementById('info').style.display='none';
}
// exibe profissional liberal
function profliberal() {
document.getElementById('empresa').style.display='none';
document.getElementById('profliberal').style.display='block';
document.getElementById('info').style.display='none';
}

function Numeros(e){
    var tecla=(window.event)?event.keyCode:e.which;
     if((tecla > 47 && tecla < 58)) return true;
    else{
    if (tecla != 8) return false;
    else return true;
    }
}

function Numero_Traco(e){
    var tecla=(window.event)?event.keyCode:e.which;
     if((tecla == 45 || tecla > 47 && tecla < 58)) return true;
    else{
    if (tecla != 8) return false;
    else return true;
    }
}

function Valida_Formulario(){
  d = document.form_cad_empresa;
  
 if(d.sl_categorias.value == ""){
   alert('Você deve selecionar uma categoria!');
   d.sl_categorias.focus();
   return false;
 }
 
   if( (d.ra_pessoa[0].checked == false) && (d.ra_pessoa[1].checked == false) ){
    alert('Selecione o tipo de cadastro!');
    return false;
   }
   
//==============VALIDAÇÃO PESSOA JURIDICA=================//    
  
//==============VALIDAÇÃO CNPJ=================//  
  
  if( (d.ra_pessoa[0].checked == true) && (d.tx_cnpj.value == "") ){
    alert('Digite o CNPJ no seguinte formato: 00.000.000/0000-00');
	d.tx_cnpj.focus();
    return false;
  }
  
  var cnpj = /\d{2}\.\d{3}\.\d{3}\/\d{4}\-\d{2}/;
   if( (d.ra_pessoa[0].checked == true) && (!cnpj.test(d.tx_cnpj.value) ) ){
      alert('Formato de CNPJ Inválido. Ex: 00.000.000/0000-00!');
	  d.tx_cnpj.focus();
	  return false;
   }
  
  if ( (d.tx_cnpj.value == "11.111.111/1111-11") || (d.tx_cnpj.value == "22.222.222/2222-22") || (d.tx_cnpj.value == "33.333.333/3333-33") || (d.tx_cnpj.value == "44.444.444/4444-44") || (d.tx_cnpj.value == "55.555.555/5555-55") || (d.tx_cnpj.value == "66.666.666/6666-66") || (d.tx_cnpj.value == "77.777.777/7777-77") || (d.tx_cnpj.value == "88.888.888/8888-88") || (d.tx_cnpj.value == "99.999.999/9999-99") || (d.tx_cnpj.value == "00.000.000/0000-00") || (d.tx_cnpj.value == "11111111111111") || (d.tx_cnpj.value == "22222222222222") || (d.tx_cnpj.value == "33333333333333") || (d.tx_cnpj.value == "44444444444444") || (d.tx_cnpj.value == "55555555555555") || (d.tx_cnpj.value == "66666666666666") || (d.tx_cnpj.value == "77777777777777") || (d.tx_cnpj.value == "88888888888888") || (d.tx_cnpj.value == "99999999999999") || (d.tx_cnpj.value == "00000000000000") ) {
    alert("CNPJ Inválido!");
    d.tx_cnpj.focus();
    return false;
  } 
  
//==============VALIDAÇÃO CNPJ=================//  
 
   //valida campo razao social
  if( (d.tx_razaosocial.value == "") && (d.ra_pessoa[0].checked == true) ){
    alert('Você deve preencher o campo Razão Social!');
    d.tx_razaosocial.focus();
    return false;
  }
    //valida campo nome fantasia
  if( (d.tx_nomefantasia.value == "") && (d.ra_pessoa[0].checked == true) ){
    alert('Você deve preencher o campo Nome Fantasia!');
    d.tx_nomefantasia.focus();
    return false;
  }
    //valida campo nome do responsavel
  if( (d.tx_nomeresponsavel.value == "") && (d.ra_pessoa[0].checked == true) ){
    alert('Você deve preencher o campo Nome do Responsável!');
    d.tx_nomeresponsavel.focus();
    return false;
  }
     //valida campo usuario
  if( (d.tx_usuario.value == "") && (d.ra_pessoa[0].checked == true) ){
    alert('Você deve preencher o campo Usuário!');
    d.tx_usuario.focus();
    return false;
  }
    //valida campo senha
  if( (d.tx_senha.value == "") && (d.ra_pessoa[0].checked == true) ){
    alert('Você deve preencher o campo Senha!');
    d.tx_senha.focus();
    return false;
  }
    //valida campo confirmar senha
  if( (d.tx_confirmasenha.value == "") && (d.ra_pessoa[0].checked == true) ){
    alert('Você deve preencher o campo Confirmar Senha!');
    d.tx_confirmasenha.focus();
    return false;
  }
    //valida as senha iguais
  if( (d.tx_senha.value != d.tx_confirmasenha.value) && (d.ra_pessoa[0].checked == true) ){
    alert('As senhas digitadas não conferem!');
    d.tx_confirmasenha.focus();
    return false;
  }
  
  
//==============VALIDAÇÃO PESSOA JURIDICA=================// 

//============VALIDAÇÃO PROFISSIONAL LIBERAL==============//

  if( (d.ra_pessoa[1].checked == true) && (d.tx_cpf.value == "") ){
    alert('Digite o CPF no seguinte formato: 000.000.000-00');
	d.tx_cpf.focus();
    return false;
  }
  
   var cpf = /\d{3}\.\d{3}\.\d{3}\-\d{2}/;
   if( (d.ra_pessoa[1].checked == true) && (!cpf.test(d.tx_cpf.value)) ){
      alert('Formato de CPF Inválido. Ex: 000.000.000-00!');
	  d.tx_cpf.focus();
	  return false;
   }
  
  if ( (d.tx_cpf.value == "111.111.111-11") || (d.tx_cpf.value == "222.222.222-22") || (d.tx_cpf.value == "333.333.333-33") || (d.tx_cpf.value == "444.444.444-44") || (d.tx_cpf.value == "555.555.555-55") || (d.tx_cpf.value == "666.666.666-66") || (d.tx_cpf.value == "777.777.777-77") || (d.tx_cpf.value == "888.888.888-88") || (d.tx_cpf.value == "999.999.999-99") || (d.tx_cpf.value == "000.000.000-00") || (d.tx_cpf.value == "11111111111") || (d.tx_cpf.value == "22222222222") || (d.tx_cpf.value == "33333333333") || (d.tx_cpf.value == "44444444444") || (d.tx_cpf.value == "55555555555") || (d.tx_cpf.value == "66666666666") || (d.tx_cpf.value == "77777777777") || (d.tx_cpf.value == "88888888888") || (d.tx_cpf.value == "99999999999") || (d.tx_cpf.value == "00000000000") ) {
    alert("CPF Inválido!");
    d.tx_cpf.focus();
    return false;
  }
  
    //valida campo nome completo
  if( (d.tx_nomecompleto.value == "") && (d.ra_pessoa[1].checked == true) ){
    alert('Você deve preencher o campo Nome Completo!');
    d.tx_nomecompleto.focus();
    return false;
  }
    //valida campo nome fantasia
  if( (d.tx_nomefantasia1.value == "") && (d.ra_pessoa[1].checked == true) ){
    alert('Você deve preencher o campo Nome Fantasia!');
    d.tx_nomefantasia1.focus();
    return false;
  }
     //valida campo usuario
  if( (d.tx_usuario1.value == "") && (d.ra_pessoa[1].checked == true) ){
    alert('Você deve preencher o campo Usuário!');
    d.tx_usuario1.focus();
    return false;
  }
    //valida campo senha
  if( (d.tx_senha1.value == "") && (d.ra_pessoa[1].checked == true) ){
    alert('Você deve preencher o campo Senha!');
    d.tx_senha1.focus();
    return false;
  }
    //valida campo confirmar senha
  if( (d.tx_confirmasenha1.value == "") && (d.ra_pessoa[1].checked == true) ){
    alert('Você deve preecher o campo Confirmar Senha!');
    d.tx_confirmasenha1.focus();
    return false;
  }
    //valida as senha iguais
  if( (d.tx_senha1.value != d.tx_confirmasenha1.value) && (d.ra_pessoa[1].checked == true) ){
    alert('As senhas digitadas não conferem!');
    d.tx_confirmasenha1.focus();
    return false;
  }
  
//============VALIDAÇÃO PROFISSIONAL LIBERAL==============//  

//==================VALIDAÇÃO ENDEREÇO====================//

  //valida campo endereço
  if(d.tx_endereco.value == ""){
    alert('Você deve preencher o campo Endereço!');
    d.tx_endereco.focus();
    return false;
  }
    //valida campo numero
  if(d.tx_numero.value == ""){
    alert('Você deve preencher o campo Número!');
    d.tx_numero.focus();
    return false;
  }
     //valida campo bairro
  if(d.tx_bairro.value == ""){
    alert('Você deve preencher o campo Bairro!');
    d.tx_bairro.focus();
    return false;
  }
    // valida o campo cep
  var cs=''+document.getElementById('tx_cep').value+document.getElementById('tx_codcep').value;
  var inv="Por favor, informe um CEP válido e completo.";
  if (cs.length != 8) {
    alert(inv);
	document.getElementById('tx_cep').focus();
    return false;
  }
  for(i=0;i<8;i++) {
    dig = cs.charCodeAt(i);
    if ((dig < 48) || (dig > 57)) {
      alert(inv);
	  document.getElementById('tx_cep').focus();
      return false;
    }
  }

//==================VALIDAÇÃO ENDEREÇO====================//
  

//==================VALIDACAO CONTATOS====================//

   //validar ddd
  if (d.tx_ddd1.value == "") {
      alert("Você deve preencher o campo DDD para o telefone!");
      d.tx_ddd1.focus();
      return false;
   }
    //validar telefones
  if (d.tx_telefone1.value == "") {
     alert("Você deve preencher um o campo Telefone!");
     d.tx_telefone1.focus();
	 return false;
     } 
	 
  var telefone = /\d{4}\-\d{4}/;
  if(!telefone.test(d.tx_telefone1.value)){
        alert('Telefone inválido. Ex: 0000-0000');
	    d.tx_telefone1.focus();
	    return false;
   }
    //validar email
  if (d.tx_email1.value == ""){
	 alert("Digite um e-mail!");
	 d.tx_email1.focus();
	 return false;
  }		
    //validar tipo email
  if ((d.tx_email1.value.indexOf('@', 1) == -1) || (d.tx_email1.value.indexOf('.', 1) == -1)){
	  alert("Digite um Email valido!");
	  d.tx_email1.focus();
	  return false;
  }

  
//==================VALIDACAO CONTATOS====================//

}// FIM FUNCTION VALIDA FORMULARIO

//==================ALERTA PALAVRAS-CHAVE================//

function palavras_chave(){
	
if(document.getElementById('ta_descricao').value == ""){ // if 1
	
    if(confirm('Você não digitou nada no campo descrição. A descrição de sua empresa é importante para que seus clientes saibam quais produtos, serviços, sua empresa ofereçe, entre outros. Deseja concluir o cadastro com o campo vazio?')){ // if 2
       return true;
    } else {
	   document.form_cad_empresa.ta_descricao.focus();
	   return false;
	} // fim if 2
	
  } // fim if 1
  
  if (document.getElementById('ta_palavraschave').value == ""){ // if 3
	     if(confirm('Você não digitou nenhuma palavra-chave. As palavras-chave são importantes para que sua empresa seja mostrada em uma busca. Deseja concluir o cadastro sem cadastrar as palavras-chave?')){ // if 4
       return true;
    } else {
	   document.form_cad_empresa.ta_palavraschave.focus();
	   return false;
	}  // fim if 4
	  
  } // fim if 3
  
} // fim palavras_chave
  
//==================ALERTA PALAVRAS-CHAVE================//  

