function mudaCampos(formulario,acao){
	var action;
	action = acao == '0'?true:false;
	for (i = 0; i < formulario.length; i++)
	{
		formulario.elements[i].disabled = action;	
	}
}

function FormataCpfCgc(campo,tammax,teclapres,frmName) {
	if (frmName == undefined) frmName = "form";
	nmCampo = eval("document."+frmName+"."+campo);
	if (nmCampo) {
		vr = limpaCampo(nmCampo.value);
		if (vr.length <= 11) {
			FormataCpf(campo,tammax,teclapres,frmName)
		} else {
			FormataCgc(campo,tammax,teclapres,frmName)
		}
	}
}

function FormataCpf(campo,tammax,teclapres,frmName) {
	if (frmName == undefined) frmName = "form";
	nmCampo = eval("document."+frmName+"."+campo);
	if (nmCampo) {
		var tecla = teclapres.keyCode;
		vr = limpaCampo(nmCampo.value);
		tam = vr.length + 1;

		if (tam > 3) {
			vr = vr.substr(0, 3) + '.' + vr.substr(3);
			if (tam > 6)
				vr = vr.substr(0, 7) + '.' + vr.substr(7);
				if (tam > 9)
					vr = vr.substr(0, 11) + '-' + vr.substr(11);
		}
  	nmCampo.value = vr;
	}
}

function FormataCgc(campo,tammax,teclapres,frmName) {
	if (frmName == undefined) frmName = "form";
	nmCampo = eval("document."+frmName+"."+campo);
	if (nmCampo) {
		var tecla = teclapres.keyCode;
		vr = limpaCampo(nmCampo.value);
		tam = vr.length + 1;

		if (tam > 2) {
			vr = vr.substr(0, 2) + '.' + vr.substr(2);
			if (tam > 5)
				vr = vr.substr(0, 6) + '.' + vr.substr(6);
				if (tam > 8)
					vr = vr.substr(0, 10) + '/' + vr.substr(10);
					if (tam > 12)
						vr = vr.substr(0, 15) + '-' + vr.substr(15);
		}
  	nmCampo.value = vr;
	}
}
function limpaCampo(valor) {
// Retira os simbolos de um campo, retornando apenas os seus digitos
	var numeros = "0123456789";
	var cont = 0;
	while (cont < valor.length)
	  {
	  	if (numeros.indexOf(valor.charAt(cont)) < 0)
				valor = valor.substr(0, cont) + valor.substr(cont + 1);
			else
				cont++;
	  }
	return valor;
}

function validaNumeros(campo, event){
  var BACKSPACE= 8;
  var key;
  var tecla;
	
  CheckTAB=9;
  if (navigator.appName.indexOf("Netscape")!= -1) 
	tecla= event.which;
  else
	tecla= event.keyCode;
	 
  key = String.fromCharCode( tecla);
	
  if (tecla == 13) return false;
	 
  if (tecla == BACKSPACE) return true;
  
  if (tecla == CheckTAB) return true;
  
   if (tecla == 0) return true;
	
  return (numerico(key));
} // fim da funcao validaTecla 

function numerico(caractere)
{
  var strValidos = "0123456789,";
  if (strValidos.indexOf(caractere) == -1) return false;
  return true;
}

function validaNumeros2(campo, event){
  var BACKSPACE= 8;
  var key;
  var tecla;
	
  CheckTAB=9;
  if (navigator.appName.indexOf("Netscape")!= -1) 
	tecla= event.which;
  else
	tecla= event.keyCode;
	 
  key = String.fromCharCode( tecla);
	
  if (tecla == 13) return false;
	 
  if (tecla == BACKSPACE) return true;
  
  if (tecla == CheckTAB) return true;
  
   if (tecla == 0) return true;
	
  return (numerico2(key));
} // fim da funcao validaTecla 

function numerico2(caractere)
{
  var strValidos = "0123456789";
  if (strValidos.indexOf(caractere) == -1) return false;
  return true;
}

//da receita federal
function validaCPF(obj, str){
var numero;
var digito = new Array(10); // array para os dígitos do CPF.
var aux = 0; // índice para a string num.
var posicao
var i
var soma
var dv
var dvInformado;

if(obj != null)
{
str = obj.value;
}

//numero = _extraiNumero(str);

// Retira os dígitos formatadores de CPF '.' e '-', caso existam.
if (str.length > 0){
while ((str.indexOf('.') != -1) || (str.indexOf('-') != -1))
{
if (str.indexOf('.') != -1)
{
aux = str.indexOf('.');
str = str.substr(0, aux) + str.substr(aux+1, str.length-1);
}
if (str.indexOf('-') != -1)
{
aux = str.indexOf('-');
str = str.substr(0, aux) + str.substr(aux+1, str.length-1);
}
} //while
} //if

//verifica CPFs manjados
switch (str) {
case '0':
case '00':
case '000':
case '0000':
case '00000':
case '000000':
case '0000000':
case '00000000':
case '000000000':
case '0000000000':
case '00000000000':
case '11111111111':
case '22222222222':
case '33333333333':
case '44444444444':
case '55555555555':
case '66666666666':
case '77777777777':
case '88888888888':
case '99999999999':
return false;
}

// Início da validação do CPF.
/* Retira do número informado os dois últimos dígitos */
dvInformado = str.substr(9,2);
/* Desmembra o número do CPF no array digito */
for (i=0; i<=8; i++)
{
digito[i] = str.substr(i,1);
}
/* Calcula o valor do 10o. digito de verificação */
posicao = 10;
soma = 0;
for (i=0; i<=8; i++)
{
soma = soma + digito[i] * posicao;
posicao--;
}
digito[9] = soma % 11;
if (digito[9] < 2)
{
digito[9] = 0;
}
else
{
digito[9] = 11 - digito[9];
}
/* Calcula o valor do 11o. digito de verificação */
posicao = 11;
soma = 0;
for (i=0; i<=9; i++)
{
soma = soma + digito[i] * posicao;
posicao--;
}
digito[10] = soma % 11;
if (digito[10] < 2)
{
digito[10] = 0;
}
else
{
digito[10] = 11 - digito[10];
}
dv = digito[9] * 10 + digito[10];
/* Verifica se o DV calculado é igual ao informado */
if(dv != dvInformado)
{
return false;
}
else
{
return true;
}
}

function valida_cnpj(cnpj){
      var numeros, digitos, soma, i, resultado, pos, tamanho, digitos_iguais;
      digitos_iguais = 1;
//adicionado para tirar os digitos		
if (cnpj.length > 0){
while ((cnpj.indexOf('.') != -1) || (cnpj.indexOf('-') != -1) || (cnpj.indexOf('/') != -1))
{
if (cnpj.indexOf('.') != -1)
{
aux = cnpj.indexOf('.');
cnpj = cnpj.substr(0, aux) + cnpj.substr(aux+1, cnpj.length-1);
}
if (cnpj.indexOf('-') != -1)
{
aux = cnpj.indexOf('-');
cnpj = cnpj.substr(0, aux) + cnpj.substr(aux+1, cnpj.length-1);
}
if (cnpj.indexOf('/') != -1)
{
aux = cnpj.indexOf('/');
cnpj = cnpj.substr(0, aux) + cnpj.substr(aux+1, cnpj.length-1);
}
} //while
} //if
		
		
      if (cnpj.length < 14 && cnpj.length < 15)
            return false;
      for (i = 0; i < cnpj.length - 1; i++)
            if (cnpj.charAt(i) != cnpj.charAt(i + 1)){
                  digitos_iguais = 0;
                  break;
             }
      if (!digitos_iguais){
            tamanho = cnpj.length - 2
            numeros = cnpj.substring(0,tamanho);
            digitos = cnpj.substring(tamanho);
            soma = 0;
            pos = tamanho - 7;
            for (i = tamanho; i >= 1; i--)
                  {
                  soma += numeros.charAt(tamanho - i) * pos--;
                  if (pos < 2)
                        pos = 9;
                  }
            resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
            if (resultado != digitos.charAt(0))
                  return false;
            tamanho = tamanho + 1;
            numeros = cnpj.substring(0,tamanho);
            soma = 0;
            pos = tamanho - 7;
            for (i = tamanho; i >= 1; i--)
                  {
                  soma += numeros.charAt(tamanho - i) * pos--;
                  if (pos < 2)
                        pos = 9;
                  }
            resultado = soma % 11 < 2 ? 0 : 11 - soma % 11;
            if (resultado != digitos.charAt(1))
                  return false;
            return true;
            }
      else
            return false;
} 

function validaEmailBO(email) {
		if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email.val()))) {
			return false;
		}
		return true;
}

function enterloga(oEvent,funcao){
  var oEvent = (oEvent)? oEvent : event;
  var oTarget =(oEvent.target)? oEvent.target : oEvent.srcElement;
  if(oEvent.keyCode==13){
    //oEvent.keyCode = 9;
	 eval(funcao+";");
  }else if(oTarget.type=="text" && oEvent.keyCode==13){
    //return false;
    //oEvent.keyCode = 9;
	 eval(funcao+";");
  }else if (oTarget.type=="radio" && oEvent.keyCode==13){
    //oEvent.keyCode = 9;
	 eval(funcao+";");
  }
}

function ajaxHtml(local,servidor,param){
	$.ajax({
							 type: "POST",
							 url: servidor,
							 dataType: "html",
							 data: param,
							 success: function(msg){
								 if(msg){									 
									 $("#carreg").css("display","none");
									 $('#'+local).html(msg);
									
									 									
								 }else{									 
									 alert("Sem resposta do servidor!");
									 
								 }
							 },
			 error: function(){	
			 			 alert("Erro no servidor de envio, favor contactar o suporte!");			 				
						 
						
						 
			 },
							 beforeSend: function(){
									
									
								}
	});	
}

function ajaxXml(destino,servidor,param,form,frase,antes,erro){
	if(form){
		form_string = $("#"+form).serialize();
		eval("form = document."+form+";");
	}else{
		form_string = "";
	}
	$.ajax({
							 type: "POST",
							 url: servidor,
							 dataType: "xml",
							 data: param+"&"+form_string,
							 success: function(msg){
								  var retorno = msg.getElementsByTagName('retorno')[0];
								 if(retorno.getElementsByTagName('msg')[0].firstChild.nodeValue == '1'){	
									 if(frase == 1){	 
										alert(retorno.getElementsByTagName('alerta')[0].firstChild.nodeValue);				 				
										eval(destino);
										
									 }else{
										eval(destino);
									 }									 
									 if(form){
									 	mudaCampos(form,1);
									 }
									 fechar();
			
								 }else{									 
									 alert(retorno.getElementsByTagName('alerta')[0].firstChild.nodeValue);
									 eval(erro);						 							 
									 if(form){
									 	mudaCampos(form,1);
									 }
									 
								 }
							 },
			 error: function(){	
			 			 alert("Erro no servidor de envio, favor contactar o suporte!");			 				         eval(erro);	
						 if(form){
						 	mudaCampos(form,1);
						 }
						 
			 },
			 beforeSend: function(){
				if(form){
					mudaCampos(form,0);
				}
				eval(antes);									
			}
	});	
}

function formataValorMonetario(campooriginal,decimais){
		  if(campooriginal.value){
		    var posicaoPontoDecimal;
		    var campo = '';
		    var resultado = '';
		    var pos,sep,dec;
		
		    //Retira possiveis separadores de milhar
		    for (pos=0; pos < campooriginal.value.length; pos ++)
		    {
			  if (campooriginal.value.charAt(pos)!='.')
				campo = campo + campooriginal.value.charAt(pos);
		    }     
		
		    //Formata valor monetário com decimais
		    posicaoPontoDecimal = campo.indexOf(',');
		    if (posicaoPontoDecimal != -1)
		    {
			  sep = 0;
			  for (pos=posicaoPontoDecimal-1;pos >= 0;pos--)
			  {
				sep ++;
				if (sep > 3)
				{
				   //resultado = '.' + resultado;
				   sep = 1;
				}
		
				resultado = campo.charAt(pos) + resultado;   
			  }
		
			  // Trata parte decimal
			  if (parseInt(decimais) > 0 )
			  {
				 resultado = resultado + ',';
			  
				 pos=posicaoPontoDecimal+1;
				 for (dec = 1;dec <= parseInt(decimais); dec++)
				 {
				   if (pos < campo.length)
				   {
					  resultado = resultado + campo.charAt(pos);
					  pos++;
				   }
				   else
					  resultado = resultado + '0';   
				 }
		
			  } // trata decimais
		   }
		   // Trata valor monetário sem decimais
		   else
		   {
			  sep = 0;
			  for (pos=campo.length-1;pos >= 0;pos--)
			  {
				sep ++;
				if (sep > 3)
				{
				  // resultado = '.' + resultado;
				   sep = 1;
				}
				resultado = campo.charAt(pos) + resultado;   
			  }
			  // Trata parte decimal
			  if (parseInt(decimais) > 0 )
			  {
				 resultado = resultado + ',';
				 for (dec = 1;dec <= parseInt(decimais); dec++)
				 {
					  resultado = resultado + '0';   
				 }
			  } // trata decimais
		   }
		   campooriginal.value = resultado;
		}
}

function Maiusculas(id){
	$("#"+id).val($("#"+id).val().toUpperCase());
	
}

function tamanhoPagina() {
			var xScroll, yScroll;
			if (window.innerHeight && window.scrollMaxY) {	
				xScroll = window.innerWidth + window.scrollMaxX;
				yScroll = window.innerHeight + window.scrollMaxY;
			} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
				xScroll = document.body.scrollWidth;
				yScroll = document.body.scrollHeight;
			} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
				xScroll = document.body.offsetWidth;
				yScroll = document.body.offsetHeight;
			}
			var windowWidth, windowHeight;
			if (self.innerHeight) {	// all except Explorer
				if(document.documentElement.clientWidth){
					windowWidth = document.documentElement.clientWidth; 
				} else {
					windowWidth = self.innerWidth;
				}
				windowHeight = self.innerHeight;
			} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
				windowWidth = document.documentElement.clientWidth;
				windowHeight = document.documentElement.clientHeight;
			} else if (document.body) { // other Explorers
				windowWidth = document.body.clientWidth;
				windowHeight = document.body.clientHeight;
			}	
			// for small pages with total height less then height of the viewport
			if(yScroll < windowHeight){
				pageHeight = windowHeight;
			} else { 
				pageHeight = yScroll;
			}
			// for small pages with total width less then width of the viewport
			if(xScroll < windowWidth){	
				pageWidth = xScroll;		
			} else {
				pageWidth = windowWidth;
			}
			arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
			return arrayPageSize;
};
		
function scrollPagina() {
			var xScroll, yScroll;
			if (self.pageYOffset) {
				yScroll = self.pageYOffset;
				xScroll = self.pageXOffset;
			} else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
				yScroll = document.documentElement.scrollTop;
				xScroll = document.documentElement.scrollLeft;
			} else if (document.body) {// all other Explorers
				yScroll = document.body.scrollTop;
				xScroll = document.body.scrollLeft;	
			}
			arrayPageScroll = new Array(xScroll,yScroll);
			return arrayPageScroll;
};

function listarCidades(opcao,local){
	if(opcao>0){
	campo_select = document.getElementById("cidade");
	$.ajax({
					 type: "POST",
					 url: local+"index.php/ajax/consultarCidade",
					 dataType: "html",
					 data: "opcao="+opcao,
					 success: function(msg){
						 if(msg){
							document.getElementById("bairro").length = 0;								
							document.getElementById("bairro").options[0] = new Option("Escolha uma cidade","0");
							campo_select.options.length = 0;
							results = msg.split(",");	 
							for( i = 0; i < results.length; i++ ){ 
							  string = results[i].split( "|" );
							  campo_select.options[i] = new Option( string[0], string[1] );	
							}
							mudaCampos(document.frmBusca,0);
							carregarTipoDeImoveis2(local);		 									 
				
						 }else{
							alert("Erro na aplicação, favor tentar em alguns minutos!");
							document.getElementById("bairro").length = 0;								
							document.getElementById("bairro").options[0] = new Option("Escolha uma cidade","0");
							campo_select.options.length = 0;
							document.getElementById("cidade").options[0] = new Option("Escolha uma cidade","0");
							mudaCampos(document.frmBusca,1);			 												
										 
						 }
					 },
					 beforeSend: function(){												
						document.getElementById("cidade").length = 0;
						document.getElementById("cidade").options[0] = new Option("carregando...","0");
						document.getElementById("bairro").length = 0;
						document.getElementById("bairro").options[0] = new Option("carregando...","0");
						mudaCampos(document.frmBusca,0);													
										
					 }
	});
  }
}


function listarCidades2(opcao,local){
	if(opcao>0){
	campo_select = document.getElementById("cidade");
	$.ajax({
					 type: "POST",
					 url: local+"index.php/ajax/consultarCidade",
					 dataType: "html",
					 data: "opcao="+opcao,
					 success: function(msg){
						 if(msg){
							document.getElementById("bairro").length = 0;								
							document.getElementById("bairro").options[0] = new Option("Escolha uma cidade","0");
							campo_select.options.length = 0;
							results = msg.split(",");	 
							for( i = 0; i < results.length; i++ ){ 
							  string = results[i].split( "|" );
							  campo_select.options[i] = new Option( string[0], string[1] );	
							}
							mudaCampos(document.frmBusca,0);
							carregarTipoDeImoveis(local);		 									 
				
						 }else{
							alert("Erro na aplicação, favor tentar em alguns minutos!");
							document.getElementById("bairro").length = 0;								
							document.getElementById("bairro").options[0] = new Option("Escolha uma cidade","0");
							campo_select.options.length = 0;
							document.getElementById("cidade").options[0] = new Option("Escolha uma cidade","0");
							mudaCampos(document.frmBusca,1);			 												
										 
						 }
					 },
					 beforeSend: function(){												
						document.getElementById("cidade").length = 0;
						document.getElementById("cidade").options[0] = new Option("carregando...","0");
						document.getElementById("bairro").length = 0;
						document.getElementById("bairro").options[0] = new Option("carregando...","0");
						mudaCampos(document.frmBusca,0);													
										
					 }
	});
  }
}



function carregarTipoDeImoveis(local){
  opcao  = document.getElementById('opcoes2').value;
  campo_select = document.getElementById("tipo2");
  
  $.ajax({
		 type: "POST",
		 url:  local+"index.php/ajax/consultarTipo",
		 dataType: "html",
		 data: "opcao="+opcao,
		 success: function(msg){
			 if(msg){																	
				campo_select.options.length = 0;
				results = msg.split(",");	 
				for( i = 0; i < results.length; i++ ){ 
				  string = results[i].split( "|" );
				  campo_select.options[i] = new Option( string[0], string[1] );
				}
				mudaCampos(document.frmBusca2,1); 	 	 									 
	
			 }else{
				alert("Erro na aplicação, favor tentar em alguns minutos!");																		
				campo_select.options.length = 0;
				document.getElementById("tipo2").options[0] = new Option("Escolha uma opção","0");
				mudaCampos(document.frmBusca2,1);			 												
							 
			 }
		 },
		 beforeSend: function(){
			campo_select.options.length = 0;												
			document.getElementById("tipo2").options[0] = new Option("Carregando...","0");							
			mudaCampos(document.frmBusca2,0);													
							
		 }
	});			
	
}

function carregarTipoDeImoveis2(local){
  opcao  = document.getElementById('opcoes').value;
  campo_select = document.getElementById("tipo");
  
  $.ajax({
		 type: "POST",
		 url:  local+"index.php/ajax/consultarTipo",
		 dataType: "html",
		 data: "opcao="+opcao,
		 success: function(msg){
			 if(msg){																	
				campo_select.options.length = 0;
				results = msg.split(",");	 
				for( i = 0; i < results.length; i++ ){ 
				  string = results[i].split( "|" );
				  campo_select.options[i] = new Option( string[0], string[1] );
				}
				mudaCampos(document.frmBusca,1); 	 	 									 
	
			 }else{
				alert("Erro na aplicação, favor tentar em alguns minutos!");																		
				campo_select.options.length = 0;
				document.getElementById("tipo").options[0] = new Option("Escolha uma opção","0");
				mudaCampos(document.frmBusca,1);			 												
							 
			 }
		 },
		 beforeSend: function(){
			campo_select.options.length = 0;												
			document.getElementById("tipo").options[0] = new Option("Carregando...","0");							
			mudaCampos(document.frmBusca,0);													
							
		 }
	});			
	
}



function carregarBairros(local){
  opcao  = document.getElementById('opcoes').value;
  cidade = document.getElementById('cidade').value;
  if(opcao>0 && opcao<3 && cidade){
  	campo_select = document.getElementById("bairro");		
	$.ajax({
					type: "POST",
					url:  local+"index.php/ajax/consultarBairros",
					dataType: "html",
					 data: "opcao="+opcao+"&cidade="+cidade,
					 success: function(msg){
						 if(msg){																	
							campo_select.options.length = 0;
							results = msg.split(",");	 
							for( i = 0; i < results.length; i++ ){ 
							  string = results[i].split( "|" );
							  campo_select.options[i] = new Option( string[0], string[1] );
							  if(i==0){
							  	campo_select.options[i].selected = true;
							  }
							}
							mudaCampos(document.frmBusca,1); 	 	 									 
				
						 }else{
							alert("Erro na aplicação, favor tentar em alguns minutos!");																		
							campo_select.options.length = 0;
							campo_select.options[0] = new Option("Escolha uma cidade","0");
							mudaCampos(document.frmBusca,1);			 												
										 
						 }
					 },
					 beforeSend: function(){
						campo_select.options.length = 0;												
						campo_select.options[0] = new Option("Carregando...","0");							
						mudaCampos(document.frmBusca,0);													
										
					 }
			});	
	}		
}

function buscaRapida(){
	 op = document.frmBusca.opcoes.value;
	 vali = document.frmBusca.valorini.value;
	 valf = document.frmBusca.valorfim.value;
	 tipo = document.frmBusca.tipo.value;
	 codigo = document.frmBusca.codigo.value;
	 cidade = document.frmBusca.cidade.value;
	 bairro = document.frmBusca.bairro.value;
	 if(codigo && op>0){
		 $("#frmBusca").submit();
	 }else {
		 if((op == 0)) {
			alert("É necessário escolher uma pretensão!");
			document.frmBusca.opcoes.focus();
			return false;
		 }else if(tipo == 0){
			alert("É necessário escolher um tipo de imovel!");
			document.frmBusca.tipo.focus();
			return false;
		 }else if(cidade == 0){
			alert("É necessário escolher uma cidade!");
			document.frmBusca.cidade.focus();
			return false;
		 }else {
			$("#frmBusca").submit();		
		 }
	 }
}

function buscaRapida2(local){
	 op = document.frmBusca.opcoes.value;
	 vali = document.frmBusca.valorini.value;
	 valf = document.frmBusca.valorfim.value;
	 tipo = document.frmBusca.tipo.value;
	 tipoNom = $("#tipo option").filter(":selected").text();
	 codigo = document.frmBusca.codigo.value;
	 cidade = document.frmBusca.cidade.value;
	 bairro = document.frmBusca.bairro.value;
	 if(codigo && op>0){
		 if(op==1) op="aluguel"; else op="venda";
		 document.frmBusca.action = local+"index.php/imoveis/buscaRapida/"+op+"/"+codigo+"/imoveis+"+op+"+codigo+"+codigo+".html";
		 $("#frmBusca").submit();
	 }else {
		 if((op == 0)) {
			alert("É necessário escolher uma pretensão!");
			document.frmBusca.opcoes.focus();
			return false;
		 }else if(tipo == 0){
			alert("É necessário escolher um tipo de imovel!");
			document.frmBusca.tipo.focus();
			return false;
		 }else if(cidade == 0){
			alert("É necessário escolher uma cidade!");
			document.frmBusca.cidade.focus();
			return false;
		 }else {
			if(op==1) op="aluguel"; else op="venda";
			if(vali) vali = vali.replace(",","."); else vali=0;
			if(valf) valf = valf.replace(",","."); else valf=0;
			if(valf>0 && vali>0){
				valores="/"+vali+" a "+valf+"/";
				valstr = "+"+vali+"+a+"+valf;
			}else if(valf>0){
				valores="/ate "+valf+"/";
				valstr = "+ate+"+valf;
			}else if(vali>0){
				valores="/a partir "+vali+"/";
				valstr = "+a+partir+"+vali;
			}else {
				valores="/0/";
				valstr = "";
			}
			if($("#bairro option").filter(":selected").text().indexOf("TODOS")!=-1){
				 pagina="/imoveis+"+tipoNom+"+"+op+"+"+cidade+valstr+".html";
				 document.frmBusca.action = local+"index.php/imoveis/buscaRapida/"+op+"/"+cidade+valores+tipo+"/"+tipoNom+pagina;
				 $("#frmBusca").submit();
			}else {
				var bairro="";	
				var arr = new Array;
				$("#bairro option").filter(":selected").each(function (){
					if(this.selected){
						if(this.value!=0) arr.push(this.value);
					}
				});
				for(i=0;i<arr.length;i++){
					if(i==(arr.length-1))
						bairro+=arr[i];
					else 
						bairro+=arr[i]+"-";
				}
				 pagina="/imoveis+"+tipoNom+"+"+op+"+"+cidade+valstr+"+"+bairro+".html";
				 document.frmBusca.action = local+"index.php/imoveis/buscaRapida/"+op+"/"+cidade+valores+tipo+"/"+tipoNom+"/"+bairro+pagina;
				 $("#frmBusca").submit();
			}			
		 }
	 }
}


function buscaRapida2_rapida(local){
	 op = document.frmBusca2.opcoes2.value;
	 vali =0;
	 valf =0;
	 tipo = document.frmBusca2.tipo2.value;
	 tipoNom = $("#tipo2 option").filter(":selected").text();
	 codigo = "";
	 cidade = "0";
	 bairro = "";
	 if(codigo && op>0){
	    if(op==1) op="aluguel"; else op="venda";
		 
		 document.frmBusca2.action = local+"index.php/imoveis/buscaRapida/"+op+"/"+codigo+"/imoveis+"+op+"+codigo+"+codigo+".html";
		 $("#frmBusca").submit();
	    }else {
			 if((op == 0)) {
				alert("É necessário escolher uma pretensão!");
				document.frmBusca.opcoes.focus();
				return false;
			 }else if(tipo == 0){
				alert("É necessário escolher um tipo de imovel!");
				document.frmBusca.tipo.focus();
				return false;
			 }else {
				if(op==1) op="aluguel"; else op="venda";
				   
					valores="/0/";
					valstr = "";
						
				  pagina="/imoveis+"+tipoNom+"+"+op+"+"+cidade+valstr+".html";
				 document.frmBusca2.action = local+"index.php/imoveis/buscaRapida/"+op+"/"+cidade+valores+tipo+"/"+tipoNom+pagina;
				 //alert(document.frmBusca2.action);
				 $("#frmBusca2").submit();
					
		 }
	 }
}


function validaLogin() {
  bot = document.getElementById("botao").value;
  login = document.getElementById("login").value;
  senha = document.getElementById("senha_usu").value;
  nSenha = fncReplace(senha,"'","");
  document.getElementById("senha_usu").value = nSenha;
  
  if(login.length == 14){
	  document.getElementById("botao").value = 1;
	  bot = document.getElementById("botao").value;
  }else if(login.length == 18){
  	  document.getElementById("botao").value = 2;
	  bot = document.getElementById("botao").value;
  }else {
  	 bot = 0;
  }
  
  if(login == "") {
     alert("É necessário preencher o campo Login do usuário");
	 return document.getElementById("login").focus();
  }else if(senha == "") {
     alert("É necessário preencher o campo Senha do usuário");
	 return document.getElementById("senha_usu").focus();
  }else if((bot == 1) && (login.length != 14)) {
     alert("CPF inválido");
	  return document.getElementById("login").focus();
  }else if((bot == 2) && (login.length != 18)) {
     alert("CNPJ inválido");
	  return document.getElementById("login").focus();
  }else if(!bot){
  	alert("Campo login inválido!");
	return document.getElementById("login").focus();
  }else {
  
     document.formLogin.submit();
  }
} 

function fncReplace(str,find,repla)
{
    var newStr = ""
    
    for(i=0;i<=str.length-1;i++)
    {
 strValue = str.substring(i,i+1)

 if (strValue == find)
     newStr += repla
 else
     newStr += str.substring(i,i+1)
    }
    return newStr
}

function validarVoto(local) {
   val = $("#valor").val();
   
	if(!val) {
	   alert("Você deve escolher uma opção antes de votar");
	}else {
		form = document.frmVoto;
		//form_string = $("#frmVoto").serialize();		   
			$.ajax({
			 type: "POST",
			 url: local+"index.php/ajax/votoenquete",
			 dataType: "html",
			 data: "enquete_pergunta="+$('#enquete_pergunta').val()+"&enquete_resposta="+val+"&comando="+$('#comando').val()+"",
			 success: function(msg){
				 if(msg){		 
					 $("#local").html(msg);
														
				 }else{
					 alert("Erro na ação, Favor tentar em alguns minutos!");						 
					 
				 }
			 },
			 beforeSend: function(){
					$("#local").html('<div style="width:100%; height:57px; clear:both;"></div><div style="float:left; margin-top:10px; margin-left:58px;"><img src="'+local+'application/images/load.gif"></div></div><div style="width:100%; height:30px; text-align:center; font-family:Arial, Helvetica, sans-serif; font-size:10px;color: #a52828; font-weight: bold;">Votando...</div>');
					
				}
		});	
	}
}

function voltar(origem){
	window.location = origem;
}

function retira_acentos(palavra) {  
   com_acento = 'áàãâäéèêëíìîïóòõôöúùûüçÁÀÃÂÄÉÈÊËÍÌÎÏÓÒÕÖÔÚÙÛÜÇ';  
   sem_acento = 'aaaaaeeeeiiiiooooouuuucAAAAAEEEEIIIIOOOOOUUUUC';  
   nova='';  
   for(i=0;i<palavra.length;i++) {  
      if (com_acento.search(palavra.substr(i,1))>=0) {  
        nova+=sem_acento.substr(com_acento.search(palavra.substr(i,1)),1);  
	  }else {  
		nova+=palavra.substr(i,1);  
	  }  
   }  
  return nova;  
}  
//busca avancada
function carDiv(id,barra,local,url,parametros){
	$('body').append('<div id="mask" style="position:absolute;left:0;top:0;z-index:9000;background-color:#FFFFFF;display:none;"></div>');
	scrollP  = scrollPagina();
	tamanhoP = tamanhoPagina();
	var winH = tamanhoP[3];
	var winW = tamanhoP[2];
	var maskHeight = tamanhoP[1];
	var maskWidth  = tamanhoP[0];
	$('#mask').css({'width':maskWidth,'height':maskHeight});
	$('#mask').css({ opacity:0.5,background:"#000000" });
	$('#mask').css("z-index","900");
	$("#mask").fadeIn("fast");
	$("#"+id).css("z-index","1000");
	if(barra ==1){
		$("#"+id).css("top", (parseInt(scrollP[1] + (tamanhoP[3] / 10) - $("#"+id).width())));
	}else {
		$("#"+id).css("top", (parseInt(scrollP[1] + (tamanhoP[3] / 10))));
	}
	//$("#"+id).draggable({ handle: "#"+barra });
	$("#"+id).fadeIn("fast");
	
	//$("#"+id).css("display","block");
	$('#mask').click(function () {
		fechar(id);	
		$("#"+id).css("display","none");
	});	
	$("#"+id).html("<img src='"+local+"application/images/loading.gif' /><label style='font-family:Arial, Helvetica, sans-serif;color:#FF0000;font-size:12px;font-weight:bold'>Carregando...</label>");
	ajaxHtml(id,url,parametros);
	
}

function fechar(id){
	$("#"+id).css("display","none");
	$("#mask").remove();
}

function Validar_lig(idi){
        nome =$("#txt_lig_nom").val();
		tel  =$("#txt_lig_tel").val();
		ass  =$("#txt_lig_ass").val();
		msn  =$("#txt_lig_msn").val();
	 
	if(!nome) {
		   if(idi == 1) {
		      alert("É necessário preencher o campo Nome");
		   }
		   if(idi == 2) {
		      alert("It is necessary to fill the field Name");
		   }
		   return $("#txt_lig_nom").focus();
		}
		if(!tel) {
		   if(idi == 1) {
			  alert("É necessário preencher o campo Telefone");
		   }
		   if(idi == 2) {
		      alert("It is necessary to fill field Phone");
		   }
		   return $("#txt_lig_tel").focus();
		}
	  if(!ass) {
		   if(idi == 1) {
			  alert("É necessário preencher o campo Assunto");
		   }
		   if(idi == 2) {
		      alert("It is necessary to fill field Assunto");
		   }
		   return $("#txt_lig_ass").focus();
		}
		 if(!msn) {
		   if(idi == 1) {
			  alert("É necessário preencher o campo Mensagem");
		   }
		   if(idi == 2) {
		      alert("It is necessary to fill field Message");
		   }
		   return $("#txt_lig_msn").focus();
		}
		
		else {
		   document.ligamos.submit();
		}
	
		
}

function EnvioForm(){
        nome =$("#txtNome").val();
		tel  =$("#txtFones").val();
		email  =$("#txtEmail").val();
		
	  if(!nome) {
		   alert("É necessário preencher o campo Nome!");
		   return $("#txtNome").focus();
		}
	  if(!tel) {
			  alert("É necessário preencher o campo Telefone!");
		      return $("#txtFones").focus();
	  }
	  if(!email){
			  alert("É necessário preencher o campo E-Mail!");
		      return $("#txtEmail").focus();
	  }
	  if(email&&!ValidaEmail()){
			alert("Email incorreto");
			return $("#txtEmail").focus();
	  }else{
		   document.frmCadImo.submit();
	  }
	
		
}

function ValidaEmail()
{
  email  =$("#txtEmail").val();
  if ((email.length != 0) && ((email.indexOf("@") < 1) || (email.indexOf('.') < 7)))
  {
      return false;
  }
  return true;
}

 function mask_Tel_Form(){
		$("#txtFones").unmask();
		$("#txtFones").mask("(99)9999-9999");
		

	}



	 function mask_lig(){
		$("#txt_lig_tel").unmask();
		$("#txt_lig_tel").mask("(99)9999-9999");
		

	}

