// JavaScript Document

<!--
function ShowHide(area){
	if (area.style.display=="none"){
		area.style.display="";
	}
	else{
		area.style.display="none";
	}
	return true;
}

//formata Telefone
var valores4 = {
  tel: "",
  tel2: ""
}

function formataTel(campo, tammax, event) {

  this.getKey = function(event) {
      return event?(event.keyCode?event.keyCode:(event.which?event.which:event.charCode)):null;
  }
    
    this.replaceNumpad = function(key) {
      if (key > 95 && key < 106) return key-96;
    else return String.fromCharCode(key);
    }

  var key = this.getKey(event);
    var caract = replaceNumpad(key);
    var tam = valores4[campo].length;
    
    if (key != 8) {
      var rule = /[^0-9]/.test(caract);
        if (tam < tammax)
          if (!rule) {
              valores4[campo] += caract;
                tam++;
            }
    } else {
      valores4[campo] = valores4[campo].substring(0,valores4[campo].length-1);
        tam--;
    }
    
	if ( tam <= 4 )                   document.formulario[campo].value = valores4[campo];
	if (tam > 4)  document.formulario[campo].value = valores4[campo].substr( 0, tam - 4 ) + '-' + valores4[campo].substr( tam - 4, tam );
  
    if (key != 9) return false;
    
}


//formata CPF
var valores3 = {
  cpf: "",
  cpfconjuge: ""
}

function formataCPF(campo, tammax, event) {

  this.getKey = function(event) {
      return event?(event.keyCode?event.keyCode:(event.which?event.which:event.charCode)):null;
  }
    
    this.replaceNumpad = function(key) {
      if (key > 95 && key < 106) return key-96;
    else return String.fromCharCode(key);
    }

  var key = this.getKey(event);
    var caract = replaceNumpad(key);
    var tam = valores3[campo].length;
    
    if (key != 8) {
      var rule = /[^0-9]/.test(caract);
        if (tam < tammax)
          if (!rule) {
              valores3[campo] += caract;
                tam++;
            }
    } else {
      valores3[campo] = valores3[campo].substring(0,valores3[campo].length-1);
        tam--;
    }
    
	if ( tam <= 2 )                   document.formulario[campo].value = valores3[campo];
	if ( (tam > 2) && (tam <= 5) )    document.formulario[campo].value = valores3[campo].substr( 0, tam - 2 ) + '-' + valores3[campo].substr( tam - 2, tam );
	if ( (tam >= 6) && (tam <= 8) )   document.formulario[campo].value = valores3[campo].substr( 0, tam - 5 ) + '.' + valores3[campo].substr( tam - 5, 3 ) + '-' + valores3[campo].substr( tam - 2, tam );
	if ( (tam >= 9) && (tam <= 11) )  document.formulario[campo].value = valores3[campo].substr( 0, tam - 8 ) + '.' + valores3[campo].substr( tam - 8, 3 ) + '.' + valores3[campo].substr( tam - 5, 3 ) + '-' + valores3[campo].substr( tam - 2, tam );
  
    if (key != 9) return false;
    
}


//formata RG
var valores2 = {
  rg: "",
  rgconjuge: ""
}

function formataRG(campo, tammax, event) {

  this.getKey = function(event) {
      return event?(event.keyCode?event.keyCode:(event.which?event.which:event.charCode)):null;
  }
    
    this.replaceNumpad = function(key) {
      if (key > 95 && key < 106) return key-96;
    else return String.fromCharCode(key);
    }

  var key = this.getKey(event);
    var caract = replaceNumpad(key);
    var tam = valores2[campo].length;
    
    if (key != 8) {
      var rule = /[^0-9]/.test(caract);
        if (tam < tammax)
          if (!rule) {
              valores2[campo] += caract;
                tam++;
            }
    } else {
      valores2[campo] = valores2[campo].substring(0,valores2[campo].length-1);
        tam--;
    }
    
	if ( tam <= 1 )                   document.formulario[campo].value = valores2[campo];
	if ( (tam > 1) && (tam <= 4) )    document.formulario[campo].value = valores2[campo].substr( 0, tam - 1 ) + '-' + valores2[campo].substr( tam - 1, tam );
	if ( (tam >= 5) && (tam <= 7) )   document.formulario[campo].value = valores2[campo].substr( 0, tam - 4 ) + '.' + valores2[campo].substr( tam - 4, 3 ) + '-' + valores2[campo].substr( tam - 1, tam );
	if ( (tam >= 8) && (tam <= 10) )  document.formulario[campo].value = valores2[campo].substr( 0, tam - 7 ) + '.' + valores2[campo].substr( tam - 7, 3 ) + '.' + valores2[campo].substr( tam - 4, 3 ) + '-' + valores2[campo].substr( tam - 1, tam );

    if (key != 9) return false;
    
}

//formata numeros
var valores1 = {
	area_util: "",
	num_dorm: "",
	area_total: "",
	num_garagem: "",
	dddtel: "",
	dddtel2: "",
	dia: "",
	mes: "",
	ano: "",
	cep1: "",
	cep2: ""
}
function formataNumero(campo, tammax, event) {

  this.getKey = function(event) {
      return event?(event.keyCode?event.keyCode:(event.which?event.which:event.charCode)):null;
  }
    
    this.replaceNumpad = function(key) {
      if (key > 95 && key < 106) return key-96;
    else return String.fromCharCode(key);
    }

  var key = this.getKey(event);
    var caract = replaceNumpad(key);
    var tam = valores1[campo].length;
    
    if (key != 8) {
      var rule = /[^0-9]/.test(caract);
        if (tam < tammax)
          if (!rule) {
              valores1[campo] += caract;
                tam++;
            }
    } else {
      valores1[campo] = valores1[campo].substring(0,valores1[campo].length-1);
        tam--;
    }
    document.formulario[campo].value = valores1[campo];
    if (key != 9) return false;
    
}

//formata valores financeiros
var valores = {
  valvenda: "",
  vallocacao: ""
}

function formularioataValor(campo, tammax, event) {

  this.getKey = function(event) {
      return event?(event.keyCode?event.keyCode:(event.which?event.which:event.charCode)):null;
  }
    
    this.replaceNumpad = function(key) {
      if (key > 95 && key < 106) return key-96;
    else return String.fromCharCode(key);
    }

  var key = this.getKey(event);
    var caract = replaceNumpad(key);
    var tam = valores[campo].length;
    
    if (key != 8) {
      var rule = /[^0-9]/.test(caract);
        if (tam < tammax)
          if (!rule) {
              valores[campo] += caract;
                tam++;
            }
    } else {
      valores[campo] = valores[campo].substring(0,valores[campo].length-1);
        tam--;
    }
    
	if ( tam <= 2 )                   document.formulario[campo].value = valores[campo];
	if ( (tam > 2) && (tam <= 5) )    document.formulario[campo].value = valores[campo].substr( 0, tam - 2 ) + ',' + valores[campo].substr( tam - 2, tam );
	if ( (tam >= 6) && (tam <= 8) )   document.formulario[campo].value = valores[campo].substr( 0, tam - 5 ) + '.' + valores[campo].substr( tam - 5, 3 ) + ',' + valores[campo].substr( tam - 2, tam );
	if ( (tam >= 9) && (tam <= 11) )  document.formulario[campo].value = valores[campo].substr( 0, tam - 8 ) + '.' + valores[campo].substr( tam - 8, 3 ) + '.' + valores[campo].substr( tam - 5, 3 ) + ',' + valores[campo].substr( tam - 2, tam );
	if ( (tam >= 12) && (tam <= 14) ) document.formulario[campo].value = valores[campo].substr( 0, tam - 11 ) + '.' + valores[campo].substr( tam - 11, 3 ) + '.' + valores[campo].substr( tam - 8, 3 ) + '.' + valores[campo].substr( tam - 5, 3 ) + ',' + valores[campo].substr( tam - 2, tam );
	if ( (tam >= 15) && (tam <= 17) ) document.formulario[campo].value = valores[campo].substr( 0, tam - 14 ) + '.' + valores[campo].substr( tam - 14, 3 ) + '.' + valores[campo].substr( tam - 11, 3 ) + '.' + valores[campo].substr( tam - 8, 3 ) + '.' + valores[campo].substr( tam - 5, 3 ) + ',' + valores[campo].substr( tam - 2, tam );
  
    if (key != 9) return false;
    
}


var oRegEmail = /^[a-z0-9\._\-]+\@[a-z0-9\._\-]+\.[a-z]{2,3}$/i;

		
function valida(){
	var bOK=true;
	

	if (!(document.formulario.locacao.checked || document.formulario.venda.checked || document.formulario.administrar.checked )) {
		alert("Escolha ao menos uma das Sugestões de negociação (Dados do Imóvel).");
		document.formulario.locacao.focus();
		bOK=false;
		return;
	}
	
	if (document.formulario.tipo.selectedIndex <= 0) {
		alert("Escolha o Tipo (Dados do Imóvel).");
		document.formulario.tipo.focus();
		bOK=false;		
		return;
	}
	
	if (!(document.formulario.comercial.checked || document.formulario.residencial.checked)) {
		alert("Escolha ao menos uma das Finalidades de ocupação (Dados do Imóvel).");
		document.formulario.comercial.focus();
		bOK=false;
		return;
	}

	if (document.formulario.enderecoimovel.value == ""){
		alert("Preencha o Endereço (Dados do Imóvel).");
		document.formulario.enderecoimovel.focus();
		bOK=false;
		return;
	}
	
	if (document.formulario.bairroimovel.value == ""){
		alert("Preencha o Bairro (Dados do Imóvel).");
		document.formulario.bairroimovel.focus();
		bOK=false;
		return;
	}
	
	if (document.formulario.cidadeimovel.value == ""){
		alert("Preencha a Cidade (Dados do Imóvel).");
		document.formulario.cidadeimovel.focus();
		bOK=false;
		return;
	}
	
	if (document.formulario.venda.checked && document.formulario.valvenda.value == ""){
		alert("Preencha o Valor de Venda (Dados do Imóvel).");
		document.formulario.valvenda.focus();
		bOK=false;
		return;
	}
	
	if (document.formulario.locacao.checked && document.formulario.vallocacao.value == ""){
		alert("Preencha o Valor de Locação (Dados do Imóvel).");
		document.formulario.vallocacao.focus();
		bOK=false;
		return;
	}

	if (document.formulario.como.selectedIndex <= 0) {
		alert("Diga como chegou até nós (Dados do Imóvel).");
		document.formulario.como.focus();
		bOK=false;		
		return;
	}
	
	if (document.formulario.nome.value == ""){
		alert("Preencha o Nome (Dados do Proprietário).");
		document.formulario.nome.focus();		
		bOK=false;
		return;
	}
	
	if (document.formulario.nacionalidade.value == ""){
		alert("Preencha a Nacionalidade (Dados do Proprietário).");
		document.formulario.nacionalidade.focus();		
		bOK=false;
		return;
	}
	
	if (document.formulario.profissao.value == ""){
		alert("Preencha a Profissão (Dados do Proprietário).");
		document.formulario.profissao.focus();		
		bOK=false;
		return;
	}
	
	if (document.formulario.rg.value == ""){
		alert("Preencha o RG (Dados do Proprietário).");
		document.formulario.rg.focus();		
		bOK=false;
		return;
	}
	
	if (document.formulario.cpf.value == ""){
		alert("Preencha o CPF (Dados do Proprietário).");
		document.formulario.cpf.focus();		
		bOK=false;
		return;
	}
	
	if (document.formulario.endereco.value == ""){
		alert("Preencha o Endereço (Dados do Proprietário).");
		document.formulario.endereco.focus();		
		bOK=false;
		return;
	}
	
	if (document.formulario.bairro.value == ""){
		alert("Preencha o Bairro (Dados do Proprietário).");
		document.formulario.bairro.focus();		
		bOK=false;
		return;
	}
	
	if (document.formulario.cidade.value == ""){
		alert("Preencha a Cidade (Dados do Proprietário).");
		document.formulario.cidade.focus();		
		bOK=false;
		return;
	}
	
	if (document.formulario.cep1.value == "" || document.formulario.cep2.value == ""){
		alert("Preencha o CEP (Dados do Proprietário).");
		document.formulario.cep1.focus();		
		bOK=false;
		return;
	}
	
	if (document.formulario.email.value == ""){
		alert("Preencha o E-mail (Dados do Proprietário).");
		document.formulario.email.focus();		
		bOK=false;
		return;
	}
			
	if (!oRegEmail.test(document.formulario.email.value)){
		alert("Por favor, confira o endereço de E-mail.");
		document.formulario.email.focus();
		bOK=false;
		return;
	}
	
	if (document.formulario.dddtel.value == "" || document.formulario.tel.value == ""){
		alert("Preencha o DDD e o Telefone (Dados do Proprietário).");
		document.formulario.dddtel.focus();		
		bOK=false;
		return;
	}
	
	if (document.formulario.dia.value == "" || document.formulario.mes.value == "" || document.formulario.ano.value == ""){
		alert("Preencha a Data de Nascimento (Dados do Proprietário).");
		document.formulario.dia.focus();		
		bOK=false;
		return;
	}
	
	if (!(document.formulario.casado[0].checked||document.formulario.casado[1].checked)) {
		alert("Diga-nos se é casado (Dados do Proprietário).");
		document.formulario.casado[0].focus();
		bOK=false;
		return;
	}

	if (document.formulario.casado[0].checked && document.formulario.nomeconjuge.value == ""){
		alert("Preencha o Nome do conjuge (Dados do Proprietário).");
		document.formulario.nomeconjuge.focus();		
		bOK=false;
		return;
	}
	
	if (document.formulario.casado[0].checked && document.formulario.nacionalidadeconjuge.value == ""){
		alert("Preencha a Nacionalidade do conjuge (Dados do Proprietário).");
		document.formulario.nacionalidadeconjuge.focus();		
		bOK=false;
		return;
	}
	
	if (document.formulario.casado[0].checked && document.formulario.profissaoconjuge.value == ""){
		alert("Preencha a Profissão do conjuge (Dados do Proprietário).");
		document.formulario.profissaoconjuge.focus();		
		bOK=false;
		return;
	}
	
	if (document.formulario.casado[0].checked && document.formulario.rgconjuge.value == ""){
		alert("Preencha o RG do conjuge (Dados do Proprietário).");
		document.formulario.rgconjuge.focus();		
		bOK=false;
		return;
	}
	
	if (document.formulario.casado[0].checked && document.formulario.cpfconjuge.value == ""){
		alert("Preencha o CPF do conjuge (Dados do Proprietário).");
		document.formulario.cpfconjuge.focus();		
		bOK=false;
		return;
	}
	
	if (!(document.formulario.exclusivo[0].checked||document.formulario.exclusivo[1].checked)) {
		alert("Informe-nos a forma de intermediação (exclusivo ou não exclusivo).");
		document.formulario.exclusivo[0].focus();
		bOK=false;
		return;
	}
			
	if (!(document.formulario.aceito[0].checked||document.formulario.aceito[1].checked)) {
		alert("Aceite os termos descritos ou não será possivel completar o cadastramento.");
		document.formulario.aceito[0].focus();
		bOK=false;
		return;
	}
	
	if (document.formulario.aceito[1].checked && document.formulario.ressalva.value == ""){
		alert("Diga-nos quais seriam as ressalvas (Autorização).");
		document.formulario.aceito.focus();		
		bOK=false;
		return;
	}

	if (bOK) {
		document.formulario.submit();
	}	
}

//-->