// JavaScript Document

//Esta funcao realiza a busca 

function buscar(f){
	var tipo_negocio = f.select_tipo_negocio.value;
	var tipo_imovel = f.select_tipo_imovel.value;
	var localizacao = f.select_localizacao.value;
	// se nao for selecionado pelo menos uma opcao
	if (tipo_negocio==0 && tipo_imovel==0 && localizacao==0){
	alert("Por favor selecione algum item para realizar a busca!");
	f.select_tipo_negocio.focus();
	return false;
	}else{
		window.frames["Lista_Informacao"].location.replace('iframe/imoveis.asp?tipo_negocio='+tipo_negocio+'&tipo_imovel='+tipo_imovel+'&localizacao='+localizacao+'&finalidade='+0+'&situacao='+0);
	}
 }
//************************************************************************
//Esta funcao realiza a busca 

function buscar_avancado(f){
	var tipo_negocio = f.select_tipo_negocio.value;
	var tipo_imovel = f.select_tipo_imovel.value;
	var localizacao = f.select_localizacao.value;
	var finalidade = f.select_finalidade.value;
	var situacao = f.select_situacao.value;
	var valor = f.text_valor.value;	
	// se nao for selecionado pelo menos uma opcao
	if (tipo_negocio==0 && tipo_imovel==0 && localizacao==0 && finalidade==0 && situacao==0 && valor == ""){
	alert("Por favor selecione algum item para realizar a busca!");
	f.select_tipo_negocio.focus();
	return false;
	}else{
		return;
		//window.self.location = 'imoveis.asp?tipo_negocio='+tipo_negocio+'&tipo_imovel='+tipo_imovel+'&localizacao='+localizacao+'&finalidade='+finalidade+'&situacao='+situacao+'&valor='+valor;
	}
	
 }
//************************************************************************
//Esta funcao valida o formulario para excluir
function valida_excluir(frm){
	var cont = 0;
	var	f = frm;
	 
		for (i=0; i<f.length; i++){
		
		 if ((f.elements[i].checked == true) && (f.elements[i].type == "checkbox")){
			cont = cont + 1 ; 
		  }
		}
	
	if (cont<1) {
		alert("Por favor selecione uma opção!");
		return false;
	} 
	
 if (confirm('Tem certeza que deseja excluir este(s) registro(s)?')){
   return true;
  }else
   return false;

	
}//fim da funcao*/
//************************************************************************

//Esta funcao valida o formulario de e-mail
function valida_email(frm){
var email = frm.text_email;

if (email.value=="" || email.value==" "){
  alert("Informe seu email!");
  email.focus();
  return false;
} else if(email.value.indexOf("@")<0 || email.value.indexOf(".")<0){
  alert("Email inválido!");
  email.focus();
  return false;
} 
return true;
}
//**********************************************
//Esta funcao valida o formulario do contato
function valida_formulario(frm){
var nome = frm.text_nome;
var email = frm.text_email;
var membro = frm.select_membro;
var assunto = frm.text_assunto;
var mensagem = frm.textarea_mensagem;

if (nome.value=="" || nome.value==" "){
  alert("Informe seu nome!");
  nome.focus();
  return false;
} 

if (email.value=="" || email.value==" "){
  alert("Informe seu e-mail!");
  email.focus();
  return false;
} else if (email.value.indexOf("@")<0 || email.value.indexOf(".")<0){
  alert("E-mail inválido!");
  email.focus();
  return false;
 }

if (membro.value=="" || membro.value==" "){
  alert("Selecione o membro!");
  membro.focus();
  return false;
}

if (assunto.value=="" || assunto.value==" "){
  alert("Informe o assunto");
  assunto.focus();
  return false;
}


if (mensagem.value=="" || mensagem.value==" "){
  alert("Escreva a mensagem desejada!");
  mensagem.focus();
  return false;
}

return true;
}
//****************************************************************
// Esta funcao valida o formulario de logon de usuario na pagina principal
function valida_logon(frm){
var login = frm.text_login;
var senha = frm.text_senha;

if (login.value=="" || login.value==" "){
  alert("Informe seu login!");
  login.focus();
  return false;
} 

if (senha.value=="" || senha.value==" "){
  alert("Informe sua senha!");
  senha.focus();
  return false;
} 
return true;
}
//****************************************************************
// Esta funcao valida busca de imovel interna
function valida_busca(frm){
var busca = frm.text_busca;

if (busca.value=="" || busca.value==" "){
  alert("Informe o nome do imóvel para busca");
  busca.focus();
  return false;
} 

return true;
}

//************************************************************
//Funcoes de navegacao usando javascript 

function carrega_pagina()
{
 window.parent.location = '../administracao.asp?pagina=links/links.asp';
}

function Link(pagina)
{
 window.self.location = pagina;
}
//************************************************************
//Funcoes de validação - cadastro de imóveis externo
function valida_cadastro_imoveis(form){

var nome = form.text_nome_imovel;
var endereco = form.text_endereco;
var cep = form.text_cep;
var localizacao = form.select_localizacao;
var tipo_imovel = form.select_tipo_imovel;
var tipo_negocio = form.select_tipo_negocio;
var finalidade = form.select_finalidade;
var situacao = form.select_situacao;
var area = form.text_area;
var valor = form.text_valor;
var email = form.text_email;


if (nome.value=="" || nome.value==" "){
  alert("Informe o nome do imóvel ou Empreendimento!");
  nome.focus();
  return false;
}

if (endereco.value=="" || endereco.value==" "){
  alert("Informe o endereço do imóvel");
  endereco.focus();
  return false;
}

if (cep.value=="" || cep.value==" "){
  alert("Informe o cep do imóvel");
  cep.focus();
  return false;
}

if (localizacao.value==0){
  alert("Selecione a localização do imóvel");
  localizacao.focus();
  return false;
}

if (tipo_imovel.value==0){
  alert("Selecione o tipo do imóvel");
  tipo_imovel.focus();
  return false;
}

if (tipo_negocio.value==0){
  alert("Selecione o tipo do negócio");
  tipo_negocio.focus();
  return false;
}

if (finalidade.value==0){
  alert("Selecione a finalidade do imóvel");
  finalidade.focus();
  return false;
}

if (situacao.value==0){
  alert("Selecione a situação do imóvel");
  situacao.focus();
  return false;
}

if (area.value=="" || area.value==" "){
  alert("Informe a área do imóvel");
  area.focus();
  return false;
}

if (valor.value==0){
  alert("Informe o valor desejado para este imóvel");
  valor.focus();
  return false;
}
// valida e-mail
 if (email.value =="" || email.value ==" "){
  		alert("Informe seu e-mail ");
  		email.focus();
 	 return false;
 }else if (email.value.indexOf("@")<0 || email.value.indexOf(".")<0){
  		alert("E-mail inválido!");
  		email.focus();
 	 return false;
 }

return true;
}//fim da funcao de cadastro de imovel
 
//******************************************************************
//Funcoes de validação - cadastro de visitante externo
function valida_cadastro_visitante(form){

var nome = form.text_nome;
var email = form.text_email;
var cpf_cnpj = form.text_cpf_cnpj;
var pessoa = form.select_pessoa;
var tel_comercial = form.text_tel_comercial;
var tel_residencial = form.text_tel_residencial;
var tel_celular = form.text_tel_celular;
var estado = form.select_estado;

if (nome.value=="" || nome.value==" "){
  alert("Informe o seu nome ou a sua Empresa");
  nome.focus();
  return false;
}

if (cpf_cnpj.value=="" || cpf_cnpj.value==" "){
  if (pessoa.value=='F'){
  alert("Informe seu CPF");
  }
  else
  {
  alert("Informe o CNPJ");
  }
  cpf_cnpj.focus();
  return false;
}

//verifica se  existe e é valido
 if (email.value =="" || email.value ==" "){
  		alert("Informe seu e-mail ");
  		email.focus();
 	 return false;
 } else if (email.value.indexOf("@")<0 || email.value.indexOf(".")<0){
  		alert("E-mail inválido!");
  		email.focus();
 	 return false;
 }
 
 if (tel_comercial.value =="" && tel_residencial.value =="" && tel_celular.value =="" ){
  alert("Informe pelo menos um telefone para contato!");
  tel_comercial.focus();
  return false;
 }
 
if ( estado.value == 0 ){
  alert("Por favor, selecione o estado. ");
  estado.focus();
  return false;
} 

return true;
}//fim da funcao de cadastro de visitante
//************************************************************************

// Estas funcoes mudam a cor da linha da tabela
function mOvr(src,clrOver) {
    if (!src.contains(event.fromElement)) {
	  src.style.cursor = 'hand';
	  src.bgColor = clrOver;
	}
  }
  function mOut(src,clrIn) {
	if (!src.contains(event.toElement)) {
	  src.style.cursor = 'default';
	  src.bgColor = clrIn;
	}
  }
  function mClk(src) {
    if(event.srcElement.tagName=='TD'){
	  src.children.tags('A')[0].click();
    }
  }
//************************************************************

function escreve_campos()
{
if (form.checkbox_mala_direta.checked)
	campos.innerHTML = form.hidden_campos.value;
else
	campos.innerHTML = "";
}
//************************************************************
//Funcoes de validação - cadastro de imóveis interno
function valida_imoveis(form){

var nome = form.text_nome_imovel;
var chamada = form.textarea_chamada;
var endereco = form.text_endereco;
var cep = form.text_cep;
var localizacao = form.select_localizacao;
var tipo_imovel = form.select_tipo_imovel;
var tipo_negocio = form.select_tipo_negocio;
var finalidade = form.select_finalidade;
var situacao = form.select_situacao;
var valor = form.text_valor;
var area = form.text_area;
var proprietario = form.select_proprietario;

if (nome.value=="" || nome.value==" "){
  alert("Informe o nome do imóvel ou Empreendimento!");
  nome.focus();
  return false;
}

if (chamada.value=="" || chamada.value==" "){
  alert("Preencha o campo chamada do imóvel!");
  chamada.focus();
  return false;
}

if (endereco.value=="" || endereco.value==" "){
  alert("Informe o endereço do imóvel");
  endereco.focus();
  return false;
}

if (cep.value=="" || cep.value==" "){
  alert("Informe o cep do imóvel");
  cep.focus();
  return false;
}

if (localizacao.value==0){
  alert("Selecione a localização do imóvel");
  localizacao.focus();
  return false;
}

if (tipo_imovel.value==0){
  alert("Selecione o tipo do imóvel");
  tipo_imovel.focus();
  return false;
}

if (tipo_negocio.value==0){
  alert("Selecione o tipo do negócio");
  tipo_negocio.focus();
  return false;
}

if (finalidade.value==0){
  alert("Selecione a finalidade do imóvel");
  finalidade.focus();
  return false;
}

if (situacao.value==0){
  alert("Selecione a situação do imóvel");
  situacao.focus();
  return false;
}

if (area.value=="" || area.value==" "){
  alert("Informe a área do imóvel");
  area.focus();
  return false;
}

if (valor.value=="" || valor.value==" "){
  alert("Informe o valor desejado para este imóvel");
  valor.focus();
  return false;
}

if (proprietario.value==0){
  alert("Selecione o proprietário do imóvel");
  proprietario.focus();
  return false;
}

return true;
}//fim da funcao de cadastro de imovel interno

//******************************************************
function FormataValor(campo,tammax,teclapres) {
	var tecla = teclapres.keyCode;
	vr = document.form[campo].value;
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	tam = vr.length;

	if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

	if (tecla == 8 ){	tam = tam - 1 ; }
		
	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
		if ( tam <= 2 ){ 
	 		document.form[campo].value = vr ; }
	 	if ( (tam > 2) && (tam <= 5) ){
	 		document.form[campo].value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 6) && (tam <= 8) ){
	 		document.form[campo].value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 9) && (tam <= 11) ){
	 		document.form[campo].value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 12) && (tam <= 14) ){
	 		document.form[campo].value = vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 15) && (tam <= 17) ){
	 		document.form[campo].value = vr.substr( 0, tam - 14 ) + '.' + vr.substr( tam - 14, 3 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ;}
	}
		
	for (var ct = 0; ct < document.form.elements.length; ct++) {
		if (document.form.elements[ct].name == document.form.elements[campo].name) {
			if ( !teclapres.shiftKey && tecla == 9 && document.form.elements[ct+1] && document.form.elements[ct+1].name == "senhaConta" && document.applets['tclJava'] ){
				document.applets['tclJava'].setFocus();
			}	
		}
	}
}
//************************************************************************
//Filtra os caracteres digitados mostra, retorna apenas numeros
function Filtro(Objeto,event)
{
  var tecla;
  var key;
  var strValidos = "0123456789"

  if( navigator.appName.indexOf("Netscape")!= -1 )
    tecla= event.which;
  else
    tecla= event.keyCode;
  return IsNum( String.fromCharCode( tecla) );
}


function IsNum( caractere )
{
   var strValidos = "0123456789"
   if ( strValidos.indexOf( caractere ) == -1 )
     return false;
   else
     return true;
}