var lbCarregando = new LightBox('msgBusca','lbCarregando'); // lighbox de 'carregando...'
var lbMapa  	 = new LightBox('mapa_curitiba','lbMapa'); // lighbox do mapa de curitiba
var lbMapaRmc	 = new LightBox('mapa_rmc','lbMapaRmc'); // lighbox do mapa da região metropolitana
var lbSucesso 	 = new LightBox('msgSucesso','lbSucesso'); // lighbox de mensagem de sucesso
lbMapa.setOverFlow(false,false,'605px','640px');
lbMapa.setBorderDiv('8px solid #FCE5A4');
lbMapaRmc.setOverFlow(false,false,'700px','750px');
lbMapaRmc.setBorderDiv('8px solid #FCE5A4');
lbSucesso.setOverFlow(false,false,'400px');
	
function troca_aba(aba) {
	
	var ajax 	 = new Ajax();
	var params = "";
	
	params += "intAba="+aba;
	params += "&cmd=aba";
	
	ajax.load('POST', SITE+'busca/geral.php', params ,'campos_busca', SITE+'imagens/loading.gif');
	var objAba = document.getElementById('aba1');
	if(objAba != 'undefined' && objAba != null) {
		objAba.className = 'aba centro';
	}
	var objAba = document.getElementById('aba2');
	if(objAba != 'undefined' && objAba != null) {
		objAba.className = 'aba centro';
	}
	var objAba = document.getElementById('aba3');
	if(objAba != 'undefined' && objAba != null) {
		objAba.className = 'aba centro';
	}
	document.getElementById('aba' + aba).className = 'aba centro selecionado';
	if(aba == 3) {
		document.getElementById('caracteristicas').style.display = 'none';
		document.getElementById('todos').innerHTML = 'Ver no Mapa';
		document.getElementById('busca_foto').innerHTML = 'Ver no Mapa - Somente com Fotos';
	}
	else {
		document.getElementById('caracteristicas').style.display = 'block';
		document.getElementById('todos').innerHTML = 'Buscar Todos os Imóveis';
		document.getElementById('busca_foto').innerHTML = 'Buscar Somente Imóveis com Fotos';
	}
}

function troca_tipo_busca(tipo) {
	
	var ajax 	 = new Ajax();
	var params = "";
	
	params += "tipo="+tipo;
	params += "&cmd=tipoBusca";
	
	ajax.load('POST', SITE+'busca/geral.php', params ,'campos_busca', SITE+'imagens/loading.gif');
}

function troca_categoria(id) {
	
	var ajax 	 = new Ajax();
	var params = "";
	
	params += "idCategoria="+id;
	params += "&cmd=cmbTiposImoveis";
	
	ajax.load('POST', SITE+'busca/geral.php', params ,'cmbTiposImoveis', SITE+'imagens/loading.gif');
}

function troca_opcao_negocio(obj) {
	
	var obj1 = document.getElementById("cmbFxaVlrMin");
	if(obj1 != null) {
		var ajax	 = new Ajax();
		var ajax2	 = new Ajax();
		var params = "";			
		params += "idOpcaoNegocio="+obj.value;
		params1 = params + "&cmd=cmbFxaVlrMin";
		ajax.load('POST', SITE+'busca/geral.php', params1 ,'cmbFxasVlrMin', SITE+'imagens/loading.gif');
		params1 = params + "&cmd=cmbFxaVlrMax";
		ajax2.load('POST', SITE+'busca/geral.php', params1 ,'cmbFxasVlrMax', SITE+'imagens/loading.gif');
	}
		if(document.getElementById("periodo") != null) {
			if(obj.value == 3) {
				document.getElementById("periodo").style.display='';
			}
			else {
				document.getElementById("periodo").style.display='none';
			}
		}
}

function troca_tipo_imovel(obj, aba) {

		var ajax   = new Ajax();
		var params = "";
		
		params += "idTipoImovel=" + obj.value;
		if(aba != 'undefined') {
			params += "&aba=" + aba;
		}
		params += "&cmd=caracteristicas";
		
		ajax.load('POST', SITE+'busca/geral.php', params ,'caracteristicas', SITE+'imagens/loading.gif');
}
  
function troca_regiao(obj) {
	
	var ajax 	  = new Ajax();
	var params  = "";
	var retorno = document.getElementById("controle_bairro");
	if (retorno != null && retorno != 'undefined') {
		retorno.value = 'false';
	}
	
	params += "idRegiao=" + obj.value;
	params += "&cmd=cmbMunicipios";
	
	ajax.load('POST', SITE+'busca/geral.php', params, 'cmbMunicipios', SITE+'imagens/loading.gif');
  	params = "";
	if(obj.value == 1) {// capital, selecionar Curitiba
		params  = "idMunicipio=1";
	  	var ajax1 	 = new Ajax();
		params += "&cmd=cmbBairros";
		ajax1.load('POST', SITE+'busca/geral.php', params, 'cmbBairros1');
		troca_regiao_controle();
	}
  	var ajax2 	 = new Ajax();
	params = "idRegiao=" + obj.value;
	params += "&cmd=cmbOpcoesNegocios";
	ajax2.load('POST', SITE+'busca/geral.php', params, 'cmbOpcoesNegocio');
	troca_regiao_controle('opc');
}

// para a lista de bairros com checkbox (buscamos para você)
function troca_regiao1(obj) {
	
	var ajax 	  = new Ajax();
	var params  = "";
	var retorno = document.getElementById("controle_bairro");
	if (retorno != null && retorno != 'undefined') {
		retorno.value = 'false';
	}
	
	params += "idRegiao=" + obj.value;
	params += "&cmd=cmbMunicipios";
	
	ajax.load('POST', SITE+'busca/geral.php', params, 'cmbMunicipios', SITE+'imagens/loading.gif');
  	params = "";
	if(obj.value == 1) {// capital, selecionar Curitiba
		params  = "idMunicipio=1";
	}
	else {
		params  = "idMunicipio=";
	}
  	var ajax1 	 = new Ajax();
	params += "&cmd=lstBairros";
	ajax1.load('POST', SITE+'busca/geral.php', params, 'lstBairros');
	troca_regiao_controle('lst');
	params = "idRegiao=" + obj.value;
  	var ajax2 	 = new Ajax();
	params += "&cmd=cmbOpcoesNegocios";
	ajax2.load('POST', SITE+'busca/geral.php', params, 'cmbOpcoesNegocio');
	troca_regiao_controle('opc');
}

function troca_regiao_controle(tipo) {
	var retorno = document.getElementById("controle_bairro");
	if(tipo == 'lst') {
		var select  = document.getElementById("lstBairro");
		if (retorno != null && retorno != 'undefined') {
			if(retorno.value == 'true') {
				$("#lstBairro").multiSelect({
		      		selectAll: false,
		      		noneSelected: 'Selecione...',
		      		oneOrMoreSelected: '% bairro(s) selecionados(s)'
		    	});
		    	select.style.display = "block";
			}
			else {
				reload("troca_regiao_controle('lst')",1);
			}
		} else {
			reload("troca_regiao_controle('lst')",1);
		}
	}
	else if(tipo == 'opc') { // opções de negócios
		var select  = document.getElementById("cmbOpcoesNegocio");
		if (retorno != null && retorno != 'undefined') {
			if(retorno.value == 'true') {
				// 
			}
			else {
				reload("troca_regiao_controle('opc')",1);
			}
		} else {
			reload("troca_regiao_controle('opc')",1);
		}
	}
	else {
		var select  = document.getElementById("cmbBairro1");
		if (retorno != null && retorno != 'undefined') {
			if(retorno.value == 'true') { 
				//
			}
			else {
				reload("troca_regiao_controle()",1);
			}
		} else {
			reload("troca_regiao_controle()",1);
		}
	}
}

function verifica_bairros_selecionados() {
	var bairros = document.getElementById("cmbBairro1");
}

function troca_regiao_bairro(obj) {
	var ajax 	 = new Ajax();
	var params = "";
	params += "idRegiaoBairro=" + obj.value;
	params += "&cmd=regiaoBairro";
	
	ajax.load('POST', SITE+'busca/geral.php', params, 'msgBusca', SITE+'imagens/loading.gif');
	var cmbBairros2 = document.getElementById("cmbBairros2");
	if(cmbBairros2 != null && cmbBairros2 != "undefined") {
   	   cmbBairros2.style.display="none";
	}
	var cmbBairros3 = document.getElementById("cmbBairros3");
	if(cmbBairros3 != null && cmbBairros3 != "undefined") {
   	   cmbBairros3.style.display="none";
	}
}

function troca_municipio(obj) {
	
	var params  = "";
	
	params += "idMunicipio=" + obj.value;
	if(document.getElementById('lstBairros') == null) {
	    var cmd = 'cmbBairros';
	    var nDiv = 'cmbBairros1';
	}
	else {
		var cmd = "lstBairros";
		var nDiv = 'lstBairros';
	}
	var ajax    = new Ajax();
	ajax.load('POST', SITE+'busca/geral.php', params + "&cmd=" + cmd, nDiv, SITE+'imagens/loading.gif');
	
	if(document.getElementById('cmbImobiliarias') != null) {
	   var ajax2   = new Ajax();
	   var params2 = "";
	   params2 += "idMunicipio=" + obj.value;
	   params2 += "&cmd=cmbImobiliarias";
	   ajax2.load('POST', SITE+'busca/geral.php', params2, 'cmbImobiliarias', SITE+'imagens/loading.gif');
	}
   	document.getElementById("cmbBairros2").style.display="none";
   	document.getElementById("cmbBairros3").style.display="none";
}

function troca_bairro(obj) {
	if(obj.name == "cmbBairro1") {
		 // verificar se precisa carregar os bairros
		 if(document.getElementById("cmbBairro2") == null || (document.getElementById("cmbBairro2") != null && document.getElementById("cmbBairro2").length !=  obj.length && obj.value != '999999')) { // bairros tem que ser da mesma cidade
	      	var ajax = new Ajax();
	      	var params  = "";
	      	params += "&cmbBairro=" + obj.name;
	      	params += "&cmd=cmbOutrosBairros";
         	ajax.load('POST', SITE+'busca/geral.php', params, 'cmbBairros2', SITE+'imagens/loading.gif');
		 }
		 if(obj.value != '999999') { // todos
	   		document.getElementById("cmbBairros2").style.display="";
		 }
	   	 else {
	   		document.getElementById("cmbBairros2").style.display="none";
	   		document.getElementById("cmbBairros3").style.display="none";
		 }
	}
	else if(obj.name == "cmbBairro2") {
		 // verificar se precisa carregar os bairros
		 if(document.getElementById("cmbBairro3") == null || (document.getElementById("cmbBairro3") != null && document.getElementById("cmbBairro3").length !=  obj.length)) { // bairros tem que ser da mesma cidade
	      var ajax = new Ajax();
	      var params  = "";
	      params += "&cmbBairro=" + obj.name;
	      params += "&cmd=cmbOutrosBairros";
	      ajax.load('POST', SITE+'busca/geral.php', params, 'cmbBairros3', SITE+'imagens/loading.gif');
		 }
	   document.getElementById("cmbBairros3").style.display="";
	}
}

function selecionar_bairro(obj) {
	var num = 0;
	var objs = document.getElementsByName('lstBairro');
	for(var i = 0; i < objs.length; i++) {
		if(objs.item(i).checked == true) {
			num++;
		}
	}
	if(num > 5) {
		alert("Você pode selecionar no máximo 5 bairros");
		obj.checked = false;
	}
}

function troca_area(obj) {
	  var  obj = document.getElementById("cmbFxaArea");
	  if(obj.value == 'nao-importa')
	     mostra_importante('area');
	  else
	     mostra_importante('area', true); // tirar
}

function muda_cidade_vendas(obj) {
    window.location=SITE+"vendas-imoveis-" + obj.value; 
}

function muda_cidade_aluguel(obj) {
    window.location=SITE+"aluguel-imoveis-" + obj.value; 
}

function muda_cidade_aluguel_temporada(obj) {
    window.location=SITE+"aluguel-imoveis-temporada-" + obj.value; 
}

function seleciona_imobiliaria(id, nome) {
	  var ajax = new Ajax();
	  var params = "";
	
	  params += "idImobiliaria=" + id;
	  params += "&nomeImobiliaria=" + nome;
	  params += "&cmd=imobiliaria";
	  ajax.load("POST",SITE+"busca/geral.php",params,"cmbImobiliarias",SITE+'imagens/loading.gif');
}

/*
* Metodo: submeter_busca
* Descrição: Envia o form de busca de imóveis
* @param comFoto - S ou N - se somente busca imóveis com foto ou não
* @param obj - objeto (botão), para desativa-lo até que a busca esteja concluída
*/
function submeter_busca(comFoto, obj) {
	if(comFoto == 'undefined' || comFoto == null ) {
		comFoto = false;
	}
	var ajax 	 = new Ajax();
	var params = "";
	if(obj != 'undefined' && obj != null ) {
	   	params += montar_parametros();
		var arr 	 = params.split('&');
		var objParametrosBusca = null;
		var objTexto = null;
		if(arr[arr.length - 1] == 'erro') {
			 alert("Há itens obrigatórios não informados ou campos inválidos - Por favor, verifique os itens em vermelho");	
		     return false;
		} else {
			
			objParametrosBusca = obj.onclick.toString(); // transformar em string
			objParametrosBusca = objParametrosBusca.substr(objParametrosBusca.indexOf("{")+1, objParametrosBusca.indexOf("}") - objParametrosBusca.indexOf("{") - 1); // tirar o nome da função 'submeter_busca'
			objParametrosBusca = objParametrosBusca.substr(objParametrosBusca.indexOf("(")+1, objParametrosBusca.indexOf(")") - objParametrosBusca.indexOf("(") - 1); // tirar os parâmetros da função
			objTexto = obj.innerHTML;
			obj.setAttribute("onclick", ";");
			obj.innerHTML = "Buscando...";
		}
	}
	if(comFoto == true) {
	   params += "&comFoto=true";
	}
    params += "&cmd=submeterBusca";
	if(obj != 'undefined' && obj != null ) {
    	ajax.load('POST',SITE+"busca/geral.php",params,"msgBusca",SITE+"imagens/loading.gif","submeter_busca_fim('" + obj.id + "', '" + objParametrosBusca + "', '" + objTexto + "')");
	}
	else {
    	ajax.load('POST',SITE+"busca/geral.php",params,"msgBusca",SITE+"imagens/loading.gif","submeter_busca_fim()");
	}
    return false; // por causa do 'enter'
}
/*
* Metodo: controleSubmeter_busca
* Descrição: Verifica se o form de resultado de busca foi carregado com sucesso
*/
function submeter_busca_fim(id, objParametrosBusca, objTexto) {
	var obj = document.getElementById('url_resultados');
	if(obj != 'undefined' && obj != null && obj != '') {// sucesso na busca
		window.location=SITE + obj.value; 
	} 
	else {
	  var obj = document.getElementById('pedir_captcha');
	  if(obj != 'undefined' && obj != null && obj != '') {//pedir captcha - suspeita de robô ou texto digitado errado
          var ajax 	 = new Ajax();
	      var params   = "cmd=gerarCaptcha";
	      ajax.load('POST',SITE+"busca/geral.php",params,"captcha_busca",SITE+"imagens/loading.gif","mostrar_captcha('" + id + "', '" + objParametrosBusca + "', '" + objTexto + "')");
	  }
	  else {
	  }
	}
}

function mostrar_captcha(id, objParametrosBusca, objTexto) {
 	var botao = document.getElementById(id);
  	// restaura opções iniciais do botão
       botao.setAttribute("onclick","submeter_busca("+objParametrosBusca+");");
       botao.innerHTML = objTexto;
  	   
  	//
	document.getElementById('captcha_busca').style.display="block";
	if(document.getElementById('pedir_captcha').value == "S") { // pedir captcha
	   var obj = document.getElementById('msgBusca');
	   document.getElementById("textoCaptchaDigitado").style.border = '2px solid #FF0000';
	   obj.style.display = 'block';
	   alert('Texto digitado não confere. Por favor, redigite o texto que está na figura');
	}
}

function submeter_contato() {
	var formulario = document.getElementById('frmContato');
	var params = montar_parametros();
	var arr = params.split('&');
	var erro = false;
	if(arr[arr.length - 1] == 'erro') 
	   erro = true;
	params += montar_parametros_envio();
	var arr = params.split('&');
	if(arr[arr.length - 1] == 'erro') 
	   erro = true;
	if(erro) {
	   alert("Há itens obrigatórios não informados ou campos inválidos - Por favor, verifique os itens em vermelho");	
	   return false;
	}
	else {
       params += "&cmd=submeterEnvio";
	   var ajax = new Ajax();
       ajax.load('POST',SITE+'busca/geral.php',params,'msgBuscamosParaVoce',SITE+'imagens/loading.gif');
       lbSucesso.show();
       registro_ga('/busca-vip/mensagens-enviada-sucesso/'); // registrar mensagem com sucesso no google
	}
	formulario.reset();
}

function fechar_mensagem_sucesso() {
	lbSucesso.close();
}

function salvar_busca(divResposta) {
	var ajax = new Ajax();
	var params = montar_parametros();
	var arr = params.split('&');
	if(arr[arr.length - 1] == 'erro') {
		 alert("Há itens obrigatórios não informados ou campos inválidos - Por favor, verifique os itens em vermelho");	
	   return false;
	}
	else {
	  params += "&cmd=salvarBusca";
	  ajax.load('POST',SITE+'busca/geral.php',params,divResposta,SITE+'imagens/loading.gif');
	  document.getElementById(divResposta).style.display = "block";
	}
}

function montar_parametros() {
	var categorias 		= document.getElementsByName("rdoCategoria");
	var opcoesNegocio   = document.getElementById("cmbOpcaoNegocio");
	var tipoImovel 		= document.getElementById("cmbTipoImovel");
	var regiao     		= document.getElementById("cmbRegiao");
	var municipio 		= document.getElementById("cmbMunicipio");
	var imobiliaria 	= document.getElementById("cmbImobiliaria");
	var idImobiliaria	= document.getElementById("idImobiliaria");
	var bairros 		= document.getElementsByName("lstBairro"); // para o 'buscamos para você', onde os bairros são em checkbox
	var bairro1 		= document.getElementById("cmbBairro1");
	var bairro2 		= document.getElementById("cmbBairro2");
	var bairro3 		= document.getElementById("cmbBairro3");
	var fxaVlrMin 		= document.getElementById("cmbFxaVlrMin");
	var fxaVlrMax 		= document.getElementById("cmbFxaVlrMax");
	var vlrImovel		= document.getElementById("vlrImovel");
	var fxaArea 		= document.getElementById("cmbFxaArea");
	var umQuarto 		= document.getElementById("um-quarto");
	var doisQuartos 	= document.getElementById("dois-quartos");
	var tresQuartos 	= document.getElementById("tres-quartos");
	var quatroQuartos 	= document.getElementById("quatro-quartos");
	var maisQuartos 	= document.getElementById("mais-quartos");
	var umaVaga 		= document.getElementById("uma-vaga");
	var duasVagas 		= document.getElementById("duas-vagas");
	var tresVagas 		= document.getElementById("tres-vagas");
	var maisVagas 		= document.getElementById("mais-vagas");
	var mobiliado 		= document.getElementById("mobiliado");
	var cobertura 		= document.getElementById("cobertura");
	var condFechado		= document.getElementById("condFechado");
	var textoCaptcha    = document.getElementById("textoCaptchaDigitado");
	var periodoInicial  = document.getElementById("periodo_inicial");
	var periodoFinal    = document.getElementById("periodo_final");
	
	
	var params = "";
	var erros = false;
    // categorias
      var obj =  document.getElementById('rdoCategorias');
	  if(categorias != null && obj != null) {
	     var id = 0;
	     for(var i = 0; i < categorias.length; i++) {
	        if(categorias.item(i).checked == true) {
	           id = categorias.item(i).value;
	        }
	     }
	     if(id > 0)
	        obj.style.color = '';
	     else {
	        obj.style.color = 'red';
	        erros = true;
	     }
	  	 if(id > 0) {
	        params += "idCategoria=" + id;
	  	 }
	  }
	  
    // opções de negócio
	  var id = 0;
	  if(opcoesNegocio != null) {
       id = opcoesNegocio.value;
	     if(id > 0)
	        opcoesNegocio.style.color = '';
	     else {
	        opcoesNegocio.style.color = 'red';
	        erros = true;
	     }
	  }
	  if(id > 0)
       params += "&idOpcaoNegocio=" + id;
    
    // tipo de imóvel
	  if(tipoImovel != null) {
	     id = tipoImovel.value;
		   if(id > 0) {
		      params += "&idTipoImovel=" + id;
//		      tipoImovel.style.border = '';
	        tipoImovel.style.color = '';
		   }
	     else {
//	        tipoImovel.style.border = '2px solid #FF0000';  //NÃO FUNCIONA NO IE!
	        tipoImovel.style.color = 'red';
	        erros = true;
	     }
	  }

	  // região 
	  if(regiao != null) {
	  	id = regiao.value;
		  if(id > 0) {
		     params += "&idRegiao=" + id;
//		     regiao.style.border = '';
		     regiao.style.color = '';
		  }
		  else {
//		     regiao.style.border = '2px solid #FF0000'; //NÃO FUNCIONA NO IE!
	        regiao.style.color = 'red';
		     erros = true;
		  }
	  }
	  
	  // municipio
	  if(municipio != null) {
	    id = municipio.value;
		if(id > 0) {
	       params += "&idMunicipio=" + id;
//		   municipio.style.border = '';
		   municipio.style.color = '';
		}
		else {
//		   municipio.style.border = '2px solid #FF0000'; //NÃO FUNCIONA NO IE!
           municipio.style.color = 'red';
		   erros = true;
		}
	  }

	  // imobiliária
    if(idImobiliaria != null) {
       params += "&idImobiliaria=" + idImobiliaria.value;
    }
    if(imobiliaria != null) {
      id = imobiliaria.value;
		  if(id > 0) {
		     params += "&idImobiliaria=" + id;
//		     imobiliaria.style.border = '';
		     imobiliaria.style.color = '';
		  }
		  else {
//		     imobiliaria.style.border = '2px solid #FF0000'; //NÃO FUNCIONA NO IE!
	        imobiliaria.style.color = 'red';
		     erros = true;
		  }
    }
   
    if(bairros != null) {
    	  var j = 1;
		  for(var i = 0; i < bairros.length; i++) {
			 if(bairros.item(i).checked == true) {
				params += "&idBairro" + (j++) + "=" + bairros.item(i).value;
			 }
		  }
		//var objBairros = document.getElementById("listbox-bairros");
/*		-- bairros não é obrigatório - Valmir 31/08/09 */
/*      -- bairros é obrigatorio - Fernando 05/07/10 */
/*      -- bairros não é obrigatorio - Fernando (Cássia) 17/08/10 */
		/*if( objBairros!=null && objBairros !="undefined" ){
			if( j==1 ){
				document.getElementById("listbox-bairros").style.border = "2px solid red";
				erros = true;
			}
			else	
				document.getElementById("listbox-bairros").style.border = "1px solid #F9BC15";
		}*/
		
    }
        
    
 	  // bairro1
    //if(bairro1 != null && municipio != null) {
    if(bairro1 != null) {
      id = bairro1.value;
      if(id == 0) { // se não for escolhido bairro, assumir 'todos'
         id = 999999;
      }
		  if(id > 0 || (municipio != null && municipio.value.toUpperCase() == 'TODOS')) {
		     params += "&idBairro1=" + id;
//		     bairro1.style.border = '';
		     bairro1.style.color = '';
		  }
		  else {
//		     bairro1.style.border = '2px solid #FF0000'; //NÃO FUNCIONA NO IE!
	       bairro1.style.color = 'red';
		     erros = true;
		  }
	 	  // bairro2
	    if(bairro2 != null && bairro1.value != 999999) {
	      id = bairro2.value;
			  if(id > 0) {
			     params += "&idBairro2=" + id;
			  }
	    }
	
	 	  // bairro3
	    if(bairro3 != null && bairro1.value != 999999) {
	      id = bairro3.value;
			  if(id > 0) {
			     params += "&idBairro3=" + id;
			  }
	    }
    }

 	  // faixa de valor minimo
    if(fxaVlrMin != null) {
		  if(fxaVlrMin.value != "") {
		     params += "&fxaVlrMin=" + fxaVlrMin.value;
//		     fxaVlrMin.style.border = '';
		     fxaVlrMin.style.color = '';
		  }
		  else {
//		     fxaVlrMin.style.border = '2px solid #FF0000'; //NÃO FUNCIONA NO IE!
	       fxaVlrMin.style.color = 'red';
		     erros = true;
		  }
    }
	  
 	  // faixa de valor máximo
    if(fxaVlrMax != null) {
		  if(fxaVlrMax.value != "") {
		     params += "&fxaVlrMax=" + fxaVlrMax.value;
//		     fxaVlrMax.style.border = '';
		     fxaVlrMax.style.color = '';
		  }
		  else {
//		     fxaVlrMax.style.border = '2px solid #FF0000'; //NÃO FUNCIONA NO IE!
	       fxaVlrMax.style.color = 'red';
		     erros = true;
		  }
    }
    
    if(fxaVlrMax != null && fxaVlrMin) {
       if(parseInt(fxaVlrMax.value) < parseInt(fxaVlrMin.value)) {
          	fxaVlrMin.style.color = 'red';
          	fxaVlrMax.style.color = 'red';
		   erros = true;
       }
    }
    
 	  // valor do imóvel
    if(vlrImovel != null) {
    	var valor = vlrImovel.value;
        valor = replaceAll(".", "", valor); // tira ponto decimal
        valor = replaceAll(",", ".", valor); // troca , por .
        valor = tirarEspacos(valor);
       	
	    if(valor != "" && !isNaN(valor)) { //valor do imóvel não informado ou não válido
		     params += "&vlrImovel=" + valor;
		     vlrImovel.style.border = '';
		  }
		  else {
		     vlrImovel.style.border = '2px solid #FF0000'; //NÃO FUNCIONA NO IE!
		     erros = true;
		  }
    }

	  // faixa de área
    if(fxaArea != null) {
		  if(fxaArea.value != "") {
		     params += "&fxaArea=" + fxaArea.value;
//		     fxaArea.style.border = '';
		     fxaArea.style.color = '';
		  }
		  else {
//		     fxaArea.style.border = '2px solid #FF0000'; //NÃO FUNCIONA NO IE!
         fxaArea.style.color = 'red';
		     erros = true;
		  }
	  }

	// quartos
	var quarto1 = false;
	var quarto2 = false;
	var quarto3 = false;
	var quarto4 = false;
	var quarto5 = false;
    if(umQuarto != null && umQuarto.checked) {
        quarto1 = true;
    }
    if(doisQuartos != null && doisQuartos.checked) {
        quarto2 = true;
    }
    if(tresQuartos != null && tresQuartos.checked) {
        quarto3 = true;
    }
    if(quatroQuartos != null && quatroQuartos.checked) {
        quarto4 = true;
    }
    if(maisQuartos != null &&  maisQuartos.checked) {
        quarto5 = true;
    }
    
    // se não for informado quarto nenhum, assumir todos - Valmir 14/05
//    if(quarto1 == false && quarto2 == false && quarto3 == false && quarto4 == false && quarto5 == false) {
//    	quarto1 = quarto2 = quarto3 = quarto4 = quarto5 = true;
//    }
    
    if(quarto1 == true || quarto2 == true || quarto3 == true || quarto4 == true || quarto5 == true) {
	  params += "&quartos=";
	  if(quarto1 == true) { 
	  	params += "1;";
	  }
	  if(quarto2 == true) { 
	  	params += "2;";
	  }
	  if(quarto3 == true) { 
	  	params += "3;";
	  }
	  if(quarto4 == true) { 
	  	params += "4;";
	  }
	  if(quarto5 == true) { 
	  	params += "5;";
	  }
	  if(document.getElementById('quartos') != null) {// existe caracteristicas quartos
	    if(quarto1 == true || quarto2 == true || quarto3 == true || quarto4 == true || quarto5 == true) {
					document.getElementById('quartos').style.color = '';	    	
	    }
	    else {
				document.getElementById('quartos').style.color = 'red';	    	
		     	erros = true;
	    }
	  }
    }
    
    // vagas na garagem
	var vaga1 = false;
	var vaga2 = false;
	var vaga3 = false;
	var vaga4 = false;
	    if(umaVaga != null && umaVaga.checked) {
	    	vaga1 = true;
	    }
	    if(duasVagas != null && duasVagas.checked) {
	    	vaga2 = true;
	    }
	    if(tresVagas != null && tresVagas.checked) {
	    	vaga3 = true;
	    }
	    if(maisVagas != null && maisVagas.checked) {
	    	vaga4 = true;
	    }
	    
	    if(vaga1 == true || vaga2 == true || vaga3 == true || vaga4 == true) {
		    params += "&vagasGaragem=";
		    if(vaga1 == true) {
		       params += "1;"
		    }
		    if(vaga2 == true) {
		       params += "2;"
		    }
		    if(vaga3 == true) {
		       params += "3;"
		    }
		    if(vaga4 == true) {
		       params += "4;"
		    }
	    }
     
	  if(mobiliado != null && mobiliado.checked) {
	     params += "&mobiliado=true";
	  }
	  if(cobertura != null && cobertura.checked) {
	     params += "&cobertura=true";
	  }
	  if(condFechado != null && condFechado.checked) {
	     params += "&condFechado=true";
	  }
	  if(textoCaptcha != null) {
         params += "&textoCaptchaDigitado=" + textoCaptcha.value;
	  }

	  if(opcoesNegocio != null) {
	  		if(opcoesNegocio.value == 3 && periodoInicial != null) {
            	params += "&periodoInicial=" + periodoInicial.value;
	  		}
		    if(opcoesNegocio.value == 3 && periodoFinal != null) {
		        params += "&periodoFinal=" + periodoFinal.value;
			}
	  }

	  
	  if(opcoesNegocio != null && periodoInicial != null && periodoFinal != null) { 
          if(opcoesNegocio.value != 3 || (opcoesNegocio.value == 3 && periodoInicial.value != ""))		  
	        periodoInicial.style.color = '';
	      else {
	        periodoInicial.style.color = 'red';
	        erros = true;
	      }
          if(opcoesNegocio.value != 3 || (opcoesNegocio.value == 3 && periodoFinal.value != ""))		  
	        periodoFinal.style.color = '';
	      else {
	        periodoFinal.style.color = 'red';
	        erros = true;
	      }
	  }
	  
	  if(erros)   
	     params += "&erro";
	  return params;
}

function montar_parametros_envio() {
	var nome      		= document.getElementById("nomeContato");
	var email      		= document.getElementById("emailContato");
	var dddTelefone		= document.getElementById("telefone_ddd");
	var telefone		= document.getElementById("telefone");
	var dddCelular		= document.getElementById("celular_ddd");
	var celular 		= document.getElementById("celular");
	var observacao		= document.getElementById("observacao");
	var autorizo_fone	= document.getElementById("autorizo_telefone");
	var recebe_oferta	= document.getElementById("recebe_oferta");
	
	var params = "";
	var erros = false;
 	  // valor do imóvel
    if(nome != null) {
   	  if(tirarEspacos(nome.value) != "") { //nome do contato não informado
		     params += "&nome=" + nome.value;
		     nome.style.border = '';
		  }
		  else {
		     nome.style.border = '2px solid #FF0000';
		     erros = true;
		  }
    }
 	  // valor do imóvel
    if(email != null) {
	    if(checkMail(email.value)) { // email do contato não informado ou não válido
		     params += "&email=" + email.value;
		     email.style.border = '';
		  }
		  else {
		     email.style.border = '2px solid #FF0000';
		     erros = true;
		  }
    }
	
	  if(dddTelefone != null)
	     params += "&telefone_ddd=" + dddTelefone.value;
	  if(telefone != null)
	     params += "&telefone=" + telefone.value;
	  if(dddCelular != null)
	     params += "&celular_ddd=" + dddCelular.value;
	  if(celular != null)
	     params += "&celular=" + celular.value;
	  if(observacao != null)
	     params += "&observacao=" + observacao.value;
	  if(autorizo_fone != null)
	     params += "&autorizo_fone=" + autorizo_fone.checked;
	  if(recebe_oferta != null)
	     params += "&recebe_oferta=" + recebe_oferta.checked;
	     
	  if(erros)   
	     params += "&erro";
	     
	  return params;
}

function mostra_mapa_rmc() {
   lbMapaRmc.show(false);
  var pagina_ga = document.getElementById('pagina_ga').innerHTML;
  var arr = pagina_ga.split('/');
	var nPag = '/' + arr[1];
	    nPag = nPag + '/' + arr[2].split('<')[0];
			nPag = nPag.substr(0,nPag.length);
    	nPag = nPag + '/mapa-regiao-metropolitana/';
	 registro_ga(nPag); // registro no google
}

function mostra_mapa_curitiba() {
   lbMapa.show();
   
   var mapaObject	= document.getElementById('mapaObject');   
   var mapaEmbed 	= document.getElementById('mapaEmbed');
   
   mapaObject.style.visibility = '';
   mapaEmbed.style.visibility = '';
   
   // separar apenas o nome da página, virá algo como <h1> vendas/busca/ </h1>
    var pagina_ga = document.getElementById('pagina_ga').innerHTML;
    var arr = pagina_ga.split('/');
	var nPag = '/' + arr[1];
	    nPag = nPag + '/' + arr[2].split('<')[0];
			nPag = nPag.substr(0,nPag.length);
    	nPag = nPag + '/mapa-bairros/';
	 registro_ga(nPag); // registro no google
}


// mapa de Curitiba - ao clicar sobre um bairro, executa essa  função
function selecionaRegiao(id) {
	
	var nomeRegiao  = "";
	var campoRegiao = document.getElementById('cmbRegiaoBairro');
    
    switch(id) {
      case 1 : nomeRegiao = "A.R. Bairro Novo";       break;
      case 2 : nomeRegiao = "A.R. Boa Vista";         break;
      case 3 : nomeRegiao = "A.R. Boqueirão";         break;
      case 4 : nomeRegiao = "A.R. Cajurú";            break;
      case 5 : nomeRegiao = "A.R. Matriz";            break;
      case 6 : nomeRegiao = "A.R. Pinheirinho";       break;
      case 7 : nomeRegiao = "A.R. Portão";            break;
      case 8 : nomeRegiao = "A.R. Santa Felicidade";  break;
    }
    
    for (var i=0; i < campoRegiao.length; i++) {
    	if (campoRegiao.options[i].value == id) {
    		campoRegiao.selectedIndex = i;
    	}
    }
    
    lbMapa.close();
   	troca_regiao_bairro(document.getElementById("cmbRegiaoBairro"));
}

function trocar_localidade(tipo,destino) {
	var ajax = new Ajax();
	ajax.load('POST', SITE+'ajax/count-click-localidade.php',"localidade="+tipo,null,null,"redirect_localidade('"+tipo+"','"+destino+"')");
}

function redirect_localidade(tipo,destino) {
	if (tipo == 1) {
		if (destino == "venda")
			window.location.href = SITE+"imoveis-a-venda";
		else
			window.location.href = SITE+"imoveis-para-alugar";
	} else {
		if (destino == "venda")
			window.location.href = SITE+"vendas-regiao-metropolitana-curitiba";
		else
			window.location.href = SITE+"aluguel-regiao-metropolitana-curitiba";
	}
}
