//<!--
var vTipoPesquisa = 'galeria';
var vNegocioPadrao = 'V';
var vUfPadrao = 'DF';
var vCidadePadrao = 0;
var vTipoPadrao = 0;
var vQuartoPadrao = 0;
var vRegiaoPadrao = 0;
var vBairroPadrao = '';
var vPalavraPadrao = '';
var vPrecoPadrao = '';
var vPrecoInicialPadrao = 0;
var vPrecoFinalPadrao = 0;
var vOrdemPadrao = 'A';
var vPlantaPadrao = true;
var vProntoPadrao = true;
var vFinanciamentoPadrao = false;
var vCulturaPadrao = 'pt-BR';
var vBuscaFrame = false;
var vSalao = false;

var varInputCodigo = document.getElementById('inputCodigo');
var varCbxUf = document.getElementById('cbxUf');
var varCbxNegocio = document.getElementById('cbxNegocio');
var varCbxCidade = document.getElementById('cbxCidade');
var varDivRegiao = document.getElementById('divRegiao');
var varCbxRegiao = document.getElementById('cbxRegiao');
var varCbxBairro = document.getElementById('cbxBairro');
var varCbxTipo = document.getElementById('cbxTipo');
var varCbxQuarto = document.getElementById('cbxQuarto');
var varDivPlanta = document.getElementById('divPlanta');
var varDivPronto = document.getElementById('divPronto');
var varDivFinanciamento = document.getElementById('divFinanciamento');
var varCbxPlanta = document.getElementById('cbxPlanta');
var varCbxPronto = document.getElementById('cbxPronto');
var varCbxFinanciamento = document.getElementById('cbxFinanciamento');
var varInputPreco = document.getElementById('inputPreco');
//var varCbxPreco = document.getElementById('cbxPreco');
var varInputPalavra = document.getElementById('inputPalavra');
var varCbxOrdem = document.getElementById('cbxOrdem');
//var varLabelResultado = document.getElementById('labelResultado');

var arrayNegocio = [
	 ['A', 'ALUGUEL', 'FOR RENT', 'ALQUILER']
	,['V', 'VENDA', 'FOR SALE', 'REVENTA']
	,['L', 'LANCAMENTO', 'RELEASE', 'LIBERAR']
	,['T', 'TEMPORADA', 'SEASON', 'TEMPORADA']
	,['R', 'RURAL', 'FARM', 'RURAL']
	,['M', 'LANC/VENDA','RELEASE/SALE','LIB/REVENTA']
];

/*
var arrayPrecoVenda = [
      [0, '--Todos--']
    , [100000, 'ate 100.000']
    , [150000, '100.000 a 150.000']
    , [200000, '150.000 a 200.000']
    , [250000, '200.000 a 250.000']
    , [300000, '250.000 a 300.000']
    , [350000, '300.000 a 350.000']
    , [400000, '350.000 a 400.000']
    , [600000, '400.000 a 600.000']
    , [800000, '600.000 a 800.000']
    , [1000000, '800.000 a 1 milhao']
    , [3000000, '1 milhao a 3 milhoes']
    , [9999999, 'acima de 3 milhoes']
];

var arrayPrecoAluguel = [
      [0, '--Todos--']
    , [300, 'ate 300']
    , [400, '300 a 400']
    , [500, '400 a 500']
    , [600, '500 a 600']
    , [700, '600 a 700']
    , [800, '700 a 800']
    , [900, '800 a 900']
    , [1000, '900 a 1.000']
    , [1250, '1.000 a 1.250']
    , [1500, '1.250 a 1.500']
    , [2000, '1.500 a 2.000']
    , [5000, '2.000 a 5.000']
    , [8000, '5.000 a 8.000']
    , [12000, '8.000 a 12.000']
    , [15000, '12.000 a 15.000']
    , [30000, '15.000 a 30.000']
    , [99999, 'acima de 30.000']
]
*/

function showText(ob, txt){
	if (ob.value == "") {
		ob.value = txt;
		}
	}

function fecharFloater() {
    var divFloater = document.getElementById("divFloater");
    if (divFloater != null)
        divFloater.style.display = "none";
}

function clearText(ob, txt){
	if (ob.value == txt) {
		ob.value = "";
	}
}

function limpaLista( ObjLst ) {
   for (i = ObjLst.length; i >= 0; i--) {
	  ObjLst[i] = null;
   }
}

function limpaCombo(combo) {
	while(combo.options.length>0)
	    combo.options[0]=null
}

function carregarArray( Uf, Negocio ) {
	var arrayTmp;
	var nomeVar = 'array' + Uf + '_' + Negocio;

	eval( 'arrayTmp = (' + nomeVar + ') ? ' + nomeVar + ' : null;' );
	return arrayTmp;
}

function inicializarUf(){
	if ( varCbxUf ) {
		limpaLista( varCbxUf );
		for ( i = 0; i < arrayUFs.length; i++ ) {
			varCbxUf.options[i] = new Option( arrayUFs[i][1], arrayUFs[i][0] );
			if ( varCbxUf.options[i].value == vUfPadrao ) {
				varCbxUf.selectedIndex = (i);
			} 
		}
	}

	inicializarNegocio( vUfPadrao );
	if ( varCbxNegocio )
		inicializarCidade( vUfPadrao, varCbxNegocio.value );
	else
		inicializarCidade( vUfPadrao, vNegocioPadrao );

    if (varInputPalavra)
        varInputPalavra.value = vPalavraPadrao;
	if ( varInputPreco )
        varInputPreco.value = vPrecoPadrao;
    //if (varCbxPreco)
    //    varCbxPreco.value = vPrecoFinalPadrao;

	inicializarOrdem(vOrdemPadrao);
	definirOrdem(varCbxOrdem);
	
    //exibirResultado();
}

function definirOrdem(combo) {
    if (combo) {
        for (i = 0; i < combo.options.length; i++) {
            if (combo.options[i].value == vOrdemPadrao) {
                combo.selectedIndex = i;
                break;
            }
        }
    }
}

function inicializarUfRural(){
    limpaLista( varCbxUf );	
	for ( i = 0; i < arrayUFs.length; i++ ) {
		varCbxUf.options[i] = new Option( arrayUFs[i][1], arrayUFs[i][0] );
		if ( varCbxUf.options[i].value == vUfPadrao ) {
			varCbxUf.selectedIndex = (i);
		} 
	}
	inicializarTipoRural();
	inicializarOrdem(vOrdemPadrao);
	//exibirResultado();
}

function inicializarNegocio( Uf ) {
	var existe;
	var c = 0;
	var nomeVar = false;
	var indexCultura;
	
	if ( varCbxNegocio ) {
		limpaLista( varCbxNegocio );
		for ( i = 0; i < arrayNegocio.length; i++ ){
			nomeVar = 'array' + Uf + '_' + arrayNegocio[i][0];
			eval( 'existe = (window.' + nomeVar + ') ? true : false;' );
			if (existe) {
			    if (vCulturaPadrao == "en-US")
			        indexCultura = 2;
			    else if (vCulturaPadrao == "es-MX")
			        indexCultura = 3;
			    else
			        indexCultura = 1;
				varCbxNegocio.options[c] = new Option( arrayNegocio[i][indexCultura], arrayNegocio[i][0] );
				if ( varCbxNegocio.options[c].value == vNegocioPadrao ) 
					varCbxNegocio.selectedIndex = (c);
				c++;
			}
		}
	}
	//inicializarPreco(vNegocioPadrao);
}

function inicializarCidade( Uf, Negocio ){
	var arrayTmp = carregarArray( Uf, Negocio );
	var lCidadePadrao = vCidadePadrao;
	if ( vUfPadrao != Uf ) {
		lCidadePadrao = arrayTmp[0];
	}

	if ( varCbxCidade ) {
		limpaLista( varCbxCidade ); 
		var entrou = false;
		for ( i = 1; i < arrayTmp.length; i++ ) {
		    if (arrayTmp[i][1] == 'BRASILIA')
		        varCbxCidade.options[i - 1] = new Option("BRASILIA / PLANO PILOTO", arrayTmp[i][0]);
		    else
		        varCbxCidade.options[i - 1] = new Option(arrayTmp[i][1], arrayTmp[i][0]);

		    if ( varCbxCidade.options[i-1].value == lCidadePadrao ) {
			    varCbxCidade.selectedIndex = (i - 1);
				entrou = true;
			}

        }
        if (!entrou) {
            for (i = 0; i < arrayTmp.length; i++) {
                // BRASILIA & GOIANIA
                if ((Uf == "DF" && varCbxCidade.options[i].value == 1) || (Uf == "GO" && varCbxCidade.options[i].value == 5)) {
                    varCbxCidade.selectedIndex = i;
                    break;
                }
            }
        }
		inicializarRegiao( Uf, Negocio, varCbxCidade.selectedIndex );
	}
	else {
		var indexCidade = 0;
		for ( i = 1; i < arrayTmp.length; i++ ) {
			if ( arrayTmp[i][0] == lCidadePadrao ) {
				indexCidade = (i-1);
				break;
			}
		}
		inicializarRegiao( Uf, Negocio, indexCidade );
	}
}

function inicializarRegiao( Uf, Negocio, indexCidade ){
	var arrayTmp = carregarArray( Uf, Negocio );
	var lRegiaoPadrao = vRegiaoPadrao;
	if ( vUfPadrao != Uf ) {
		lRegiaoPadrao = arrayTmp[0];
	}
	var arrayRegiao = arrayTmp[indexCidade+1];

	if ( varCbxRegiao ) {
		limpaLista( varCbxRegiao ); 
		for ( i = 3; i < arrayRegiao.length; i++ ) {
			varCbxRegiao.options[i-3] = new Option( arrayRegiao[i][1] , arrayRegiao[i][0] );
			if ( varCbxRegiao.options[i-3].value == lRegiaoPadrao ) 
				varCbxRegiao.selectedIndex = (i-3);
		}
    	if ( varDivRegiao != null ) {
    	    if ( varCbxRegiao.options.length > 2 )
    	        varDivRegiao.style.display = 'block';
    	    else
    	        varDivRegiao.style.display = 'none';
   	    }
		inicializarBairro( Uf, Negocio, indexCidade, varCbxRegiao.selectedIndex );
	}
	else {
		var indexRegiao = 0;
		for ( i = 3; i < arrayRegiao.length; i++ ) {
			if ( arrayRegiao[i][0] == lRegiaoPadrao ) {
				indexRegiao = (i-1);
				break;
			}
		}
		inicializarBairro( Uf, Negocio, indexCidade, indexRegiao );
	}
}

function inicializarBairro(Uf, Negocio, indexCidade, indexRegiao) {
    var bairroTitulo;
	var arrayTmp = carregarArray( Uf, Negocio );
	var lBairroPadrao = vBairroPadrao;
	if ( vUfPadrao != Uf ) {
		lBairroPadrao = arrayTmp[0];
	}
	var arrayRegiao = arrayTmp[indexCidade + 1][indexRegiao + 3];

	if ( varCbxBairro ) {
		limpaLista( varCbxBairro );
		for (i = 2; i < arrayRegiao.length; i++) {
		    bairroTitulo = arrayRegiao[i][1];
		    if (bairroTitulo == "TODOS" || bairroTitulo == "BAIRRO(TODOS)") {
		        if (vCulturaPadrao == "en-US")
		            bairroTitulo = "NEIGHBORHOOD(ALL)";
		        else if (vCulturaPadrao == "es-MX")
		            bairroTitulo = "VECINDARIO(TODOS)";
		    }
			varCbxBairro.options[i-2] = new Option( bairroTitulo, arrayRegiao[i][0] );
			if ( varCbxBairro.options[i-2].value == lBairroPadrao ) 
				varCbxBairro.selectedIndex = (i-2);
		}
		inicializarOutros( Uf, Negocio, indexCidade, indexRegiao, varCbxBairro.selectedIndex );
	}
	else {
		var indexBairro = 0;
		for ( i = 2; i < arrayBairro.length; i++ ) {
			if ( arrayBairro[i][0] == lBairroPadrao ) {
				indexBairro = (i-1);
				break;
			}
		}
		inicializarOutros( Uf, Negocio, indexCidade, indexRegiao, indexBairro );
	}
}

function inicializarOutros( Uf, Negocio, indexCidade, indexRegiao, indexBairro ) {

    var arrayTmp = carregarArray( Uf, Negocio );
    var arrayBairro = arrayTmp[indexCidade+1][indexRegiao + 3][indexBairro + 2];

    inicializarTipo( Negocio, arrayBairro );

    var arrayQuarto = arrayBairro[ 3 ].split( "-" );
    var c = 1;
    if ( varCbxQuarto ) {
        limpaLista(varCbxQuarto);
        if (vCulturaPadrao == "en-US")
            varCbxQuarto.options[0] = new Option('ALL', '0');
	    else if (vCulturaPadrao == "es-MX")
	        varCbxQuarto.options[0] = new Option( 'TODOS', '0' );
	    else
	        varCbxQuarto.options[0] = new Option( 'TODOS', '0' );
	    for ( i = 0; i < arrayQuarto.length; i++ ) {
		    if ( arrayQuarto[i] > 0 && arrayQuarto[i] < 4 ) {
			    varCbxQuarto.options[c] = new Option( arrayQuarto[i], arrayQuarto[i] );
			    if ( varCbxQuarto.options[c].value == vQuartoPadrao ) 
				    varCbxQuarto.selectedIndex = (c);
			    c++;
		    }
		    else if (arrayQuarto[i] >= 4) {
		        if (vCulturaPadrao == "en-US")
		            varCbxQuarto.options[c] = new Option('4 or +', '4');
		        else if (vCulturaPadrao == "es-MX")
		            varCbxQuarto.options[c] = new Option('4 ou +', '4');
		        else
		            varCbxQuarto.options[c] = new Option('4 ou +', '4');
			    if ( varCbxQuarto.options[c].value == vQuartoPadrao ) 
				    varCbxQuarto.selectedIndex = (c);
			    c++;
		    }
	    }
	}
}

function inicializarTipo( Negocio, arrayBairro ) {
	var arrayTipo = arrayBairro[ 2 ].split( "-" );
	
	limpaLista( varCbxTipo );

	for ( i = 0; i < arrayTipo.length; i++ ) {

		var lId = arrayTipos[ arrayTipo[ i ] ][ 0 ];
		var lDesc;
		if (vCulturaPadrao == "en-US")
		    lDesc = arrayTipos[arrayTipo[i]][2];
		else if (vCulturaPadrao == "es-MX")
		    lDesc = arrayTipos[arrayTipo[i]][3];
		else
		    lDesc = arrayTipos[arrayTipo[i]][1];
		var lPlanta = arrayTipos[ arrayTipo[ i ] ][ 4 ];

		if ( Negocio != "V" )
			lPlanta = false;

        varCbxTipo.options[i] = new Option(lDesc, lId);
		if ( varCbxTipo.options[i].value == vTipoPadrao ) {
		    varCbxTipo.selectedIndex = (i);
		    var arrTipo = arrayTipos[arrayTipo[i]];
		    if (arrTipo[2]) {
		        varDivPlanta.style.visibility = "visible";
		        varDivPronto.style.visibility = "visible";
		    } else {
		        varDivPlanta.style.visibility = "hidden";
		        varDivPronto.style.visibility = "hidden";
		    }
		}
		if (varDivFinanciamento) {
		    if (Negocio != "A" && Negocio != "T")
		        varDivFinanciamento.style.visibility = "visible";
		    else
		        varDivFinanciamento.style.visibility = "hidden";
		}
		
		verificarNegocio();
		if (varDivPlanta != null)
            varCbxPlanta.checked = vPlantaPadrao;
		if (varDivPronto != null)
	        varCbxPronto.checked = vProntoPadrao;
	    if (varCbxFinanciamento != null)
	        varCbxFinanciamento.checked = vFinanciamentoPadrao;
    }
}

function inicializarTipoRural() {
	limpaLista( varCbxTipo );
    var arrayTipo = arrayUFs[ varCbxUf.selectedIndex ][2].split( "-" );
	for ( i = 0; i < arrayTipo.length; i++ ) {

		var lId = arrayTipos[ arrayTipo[ i ] ][ 0 ];
		var lDesc = arrayTipos[ arrayTipo[ i ] ][ 1 ];
		
		varCbxTipo.options[i] = new Option( lDesc, lId );
		if ( lId == vTipoPadrao )
		    varCbxTipo.selectedIndex = (i);
    }
}

function inicializarAba() {
    varCbxOrdemAba = document.getElementById('cbxOrdemAba');
    if (varCbxOrdemAba != null) {
        limpaCombo(varCbxOrdemAba);
        if (varCbxOrdem != null) {
            var i = 0;
            for (i; i < varCbxOrdem.options.length; i++) {
                varCbxOrdemAba.options[i] = new Option(varCbxOrdem.options[i].text, varCbxOrdem.options[i].value);
            }
        }
        definirOrdem(varCbxOrdemAba);
    }
}

/*
function inicializarPreco(negocio) {
    if (varCbxPreco) {
        limpaCombo(varCbxPreco);
        var i = 0;
        var arrayPreco = (negocio == "A") ? arrayPrecoAluguel : arrayPrecoVenda;
        for (i = 0; i < arrayPreco.length; i++) 
            varCbxPreco.options[i] = new Option(arrayPreco[i][1], arrayPreco[i][0]);
    }
}
*/

function inicializarOrdem(Ordem) {
    limpaCombo(varCbxOrdem);
    if (vCulturaPadrao == "en-US") {
        varCbxOrdem.options[0] = new Option(unescape('Address'), 'E');
        varCbxOrdem.options[1] = new Option(unescape('Update'), 'A');
        varCbxOrdem.options[2] = new Option('Photo', 'F');
        if (Ordem != "L")
            varCbxOrdem.options[3] = new Option(unescape('Price'), "P");
    }
    else if (vCulturaPadrao == "es-MX") {
        varCbxOrdem.options[0] = new Option(unescape('Direccion'), 'E');
        varCbxOrdem.options[1] = new Option(unescape('Actualizacion'), 'A');
        varCbxOrdem.options[2] = new Option('Foto', 'F');
        if (Ordem != "L")
            varCbxOrdem.options[3] = new Option(unescape('Precio'), "P");
    }
    else {
        varCbxOrdem.options[0] = new Option(unescape('Endere%E7o'), 'E');
        varCbxOrdem.options[1] = new Option(unescape('Atualiza%E7%E3o'), 'A');
        varCbxOrdem.options[2] = new Option('Foto', 'F');
        if (Ordem != "L")
            varCbxOrdem.options[3] = new Option(unescape('Pre%E7o'), "P");
        varCbxOrdem.options[4] = new Option(unescape('Bairro'), "B");
        varCbxOrdem.options[5] = new Option(unescape('%C1rea'), "M");
        varCbxOrdem.options[6] = new Option(unescape('Anunciante'), "I");

    }
}

function pegarPaginaAtual() {
	var dir = location.href.substring( 0, location.href.lastIndexOf( '/' ) + 1 );
	var url = location.href.substring( dir.length, location.href.length + 1 );
	if ( url.indexOf( '?' ) >= 0 )
		return url.substring( 0, url.indexOf( '?' ) )
	else
		return url;
}

function verificarNegocio() {
    if (varCbxNegocio) {
        if (varCbxNegocio.value == 'A' || varCbxNegocio.value == 'T') {
            varCbxPronto.checked = false;
            varCbxPlanta.checked = false;
            varCbxFinanciamento.checked = false;
            varDivPronto.style.visibility = "hidden";
            varDivPlanta.style.visibility = "hidden";
            if (varDivFinanciamento)
                varDivFinanciamento.style.visibility = "hidden";
        }
    }
}

function mudarNegocio( Negocio ) {
    VNegocioPadrao = Negocio;
	inicializarCidade( varCbxUf.value, Negocio );
	inicializarOrdem(vOrdemPadrao);
	varCbxOrdem.value = vOrdemPadrao;
	//inicializarPreco(VNegocioPadrao);
}

function mudarUf(Uf) {
    var url;
    
    if (location.pathname == "/busca_mobile") {
        url = 'busca_mobile.aspx';
        url += '?n=' + vNegocioPadrao + '&uf=' + Uf.toUpperCase();
    }

    else if (vBuscaFrame) {
        url = 'busca_mg.aspx';
        url += '?n=' + vNegocioPadrao + '&uf=' + Uf.toLowerCase();
    }
    else {
        url = '/' + Uf.toLowerCase();
    }

    if (location.pathname != "/busca_salao")
        location.href = url;
    else {
        mudarUfSalao(Uf);
    }
	
    return;
}

function mudarUfRural( Uf ){
	vUfPadrao = Uf;
    inicializarTipoRural();
}

function mudarUfSalao( Uf ){
    vUfPadrao = Uf;
    inicializarNegocio(Uf);
    inicializarCidade( vUfPadrao, 'M' );
}

function mudarCidade( indexCidade ) {
    var lNegocio = vNegocioPadrao;
	if ( varCbxNegocio )
		lNegocio = varCbxNegocio.value;
	var lUf = vUfPadrao;	
	if ( varCbxUf )
		lUf = varCbxUf.value;
    var indexCidade = varCbxCidade.selectedIndex;
    vCidadePadrao = varCbxCidade.value;
   /* if (vCidadePadrao == 5) {
        location.href = 'http://www.wimoveis.com.br/goias';
        return;
    }*/
    inicializarRegiao(lUf, lNegocio, indexCidade);

}

function mudarRegiao( indexRegiao ) {
    var lNegocio = vNegocioPadrao;
	if ( varCbxNegocio )
		lNegocio = varCbxNegocio.value;
	var lUf = vUfPadrao;	
	if ( varCbxUf )
		lUf = varCbxUf.value;
    var indexCidade = varCbxCidade.selectedIndex;
    vRegiaoPadrao = varCbxRegiao.value;
    inicializarBairro( lUf, lNegocio, indexCidade, indexRegiao );
}

function mudarBairro( indexBairro ) {
    var lNegocio = vNegocioPadrao;
	if ( varCbxNegocio )
		lNegocio = varCbxNegocio.value;
	var lUf = vUfPadrao;	
	if ( varCbxUf )
		lUf = varCbxUf.value;
    var indexCidade = varCbxCidade.selectedIndex;
    var indexRegiao = varCbxRegiao.selectedIndex;
    vBairroPadrao = varCbxBairro.value;
    inicializarOutros( lUf, lNegocio, indexCidade, indexRegiao, indexBairro );
}

function mudarTipo( indexTipo ) {
	if ( varDivPlanta != null && varDivPronto != null ) {


		var Negocio = vNegocioPadrao;
		if ( varCbxNegocio )
			Negocio = varCbxNegocio.value;

		if ( Negocio == 'V' ) {
		    var Uf = varCbxUf.value;
			var arrayUf = carregarArray( Uf, Negocio );

			var indexCidade = 0;
			var indexRegiao = 0;
			if ( varCbxCidade ) {
				indexCidade = varCbxCidade.selectedIndex;
			} else {
				for ( i = 1; i < arrayUf.length; i++ ) {
					if ( arrayUf[i][0] == vCidadePadrao ) {
						indexCidade = (i-1);
						break;
					}
				}
			}
			var arrayCidade = arrayUf[indexCidade + 1];
			if ( varCbxRegiao ) {
				indexRegiao = varCbxRegiao.selectedIndex;
			} else {
				for ( i = 3; i < arrayCidade.length; i++ ) {
					if ( arrayCidade[i][0] == vRegiaoPadrao ) {
						indexRegiao = (i-3);
						break;
					}
				}
			}
			var arrayRegiao = arrayCidade[indexRegiao + 3];
			if ( varCbxRegiao ) {
				indexBairro = varCbxBairro.selectedIndex;
			} else {
				for ( i = 3; i < arrayRegiao.length; i++ ) {
					if ( arrayRegiao[i][0] == vBairroPadrao ) {
						indexBairro = (i-3);
						break;
					}
				}
			}
			var arrayBairro = arrayRegiao[indexBairro + 2];
			var arrayTipo = arrayBairro[ 2 ].split( "-" );
			
			var arrTipo = arrayTipos[ arrayTipo[ indexTipo ] ];
			if ( arrTipo[ 2 ] ) {
				varDivPlanta.style.visibility = "visible";
				varDivPronto.style.visibility = "visible";
			} else {
				varDivPlanta.style.visibility = "hidden";
				varDivPronto.style.visibility = "hidden";
            }
            verificarNegocio();
		}
	}
}

/*
function exibirResultado() {
    var resultado = "";
    if (varCbxUf)
        resultado = varCbxUf.value;
    var negocio = "R";
    if (varCbxNegocio != null)
        negocio = varCbxNegocio.value;
    if (negocio == "R" || negocio == "r") 
        resultado = resultado + " - Rural";
    else if (negocio == "V" || negocio == "v")
        resultado = resultado + " - Revenda";
    else if (negocio == "A" || negocio == "a")
        resultado = resultado + " - Aluguel";
    else if (negocio == "L" || negocio == "l")
        resultado = resultado + " - Lançamento";
    else if (negocio == "T" || negocio == "t")
        resultado = resultado + " - Temporada";
    if (varCbxCidade != null)
        resultado = resultado + " - " + varCbxCidade.options[varCbxCidade.selectedIndex].text;
    //if (varCbxRegiao != null)
    //    resultado = resultado + " - " + varCbxRegiao.options[varCbxRegiao.selectedIndex].text;
    if (varCbxBairro != null)
        resultado = resultado + " - " + varCbxBairro.options[varCbxBairro.selectedIndex].text;
    if (varCbxTipo)
        resultado = resultado + " - " + varCbxTipo.options[varCbxTipo.selectedIndex].text;
    if (varCbxQuarto != null)
        resultado = resultado + " - " + varCbxQuarto.options[varCbxQuarto.selectedIndex].text;
    varLabelResultado = document.getElementById('labelResultado');
    if (varLabelResultado)
        varLabelResultado.innerHTML = resultado;

}
*/

function pesquisa_codigo()
 {
    var url = "";
    if (varInputCodigo != null && varInputCodigo.value != '') 
    {
        url += "/imovel_codigo.aspx";
        url += "?cod=" + escape(varInputCodigo.value);
        window.open(url);
    }
}

function oc(a)
{
    var o = {};
    for(var i=0;i<a.length;i++)
        o[a[i]] = "";
    return o;
}

String.prototype.renlacc = function () {
    var torem = this;
    torem = torem.split('');
    toremout = new Array();
    toremlen = torem.length;
    var sec = 'ÀÁÂÃÄÅàáâãäåÒÓÔÕÕÖØòóôõöøÈÉÊËèéêëðÇçÐÌÍÎÏìíîïÙÚÛÜùúûüÑñŠšŸÿýŽž';
    var rep = ['A', 'A', 'A', 'A', 'A', 'A', 'a', 'a', 'a', 'a', 'a', 'a', 'O', 'O', 'O', 'O', 'O', 'O', 'O', 'o', 'o', 'o', 'o', 'o', 'o', 'E', 'E', 'E', 'E', 'e', 'e', 'e', 'e', 'e', 'C', 'c', 'D', 'I', 'I', 'I', 'I', 'i', 'i', 'i', 'i', 'U', 'U', 'U', 'U', 'u', 'u', 'u', 'u', 'N', 'n', 'S', 's', 'Y', 'y', 'y', 'Z', 'z'];
    for (var y = 0; y < toremlen; y++) {
        if (sec.indexOf(torem[y]) != -1) { toremout[y] = rep[sec.indexOf(torem[y])]; } else toremout[y] = torem[y];
        if (torem[y] == ' ')
            toremout[y] = '-';
        if (torem[y].charCodeAt(0) == 47)
            toremout[y] = '-';
    }
    toascout = toremout.join('');
    return toascout;
} 

function remacc(text) {
    var c = '';
    var textout = new Array();
    text = text.replace(/\r/g, '');
    text = text.split('\n');
    var linecnt = text.length;
    for (var x = 0; x < linecnt; x++) {
        textout[x] = text[x].renlacc();
    }
    textout = textout.join('\n');
    return escape(textout);
}

function gerarPermalink(texto) {
    textor = remacc(texto.toLowerCase());
  /*  texto = texto.toLowerCase();
    var textor = "";
    for (var i = 0; i < texto.length; i++) {
        if (texto.charAt(i) in oc(['ã', 'á', 'à', 'â', 'ä']))
            textor += 'a';
        else if (texto.charAt(i) in oc(['é', 'è', 'ê', 'ë']))
            textor += 'e';
        else if (texto.charAt(i) in oc(['í', 'ì', 'ï']))
            textor += 'i';
        else if (texto.charAt(i) in oc(['õ', 'ó', 'ò', 'ö']))
            textor += 'o';
        else if (texto.charAt(i) in oc(['ú', 'ù', 'ü']))
            textor += 'u';
        else if (texto.charAt(i) == 'ç')
            textor += 'c';
        else if (texto.charAt(i) == ' ')
            textor += String.fromCharCode(45);
        else {
            var code = texto.charCodeAt(i);
            if ((code >= 97 && code <= 122) || (code >= 65 && code <= 90) || (code >= 48 && code <= 57) || (code == 46))
                textor += String.fromCharCode(code);
        }
    }*/
    return escape(textor);
} 

function gerarUrl() {
    var url = "";
    var negocio = "r";
    var negocioQuery = "";
    if (varCbxNegocio != null)
        negocio = varCbxNegocio.value.toLowerCase();
    if (varCbxUf)
        url += "/" + gerarPermalink(varCbxUf.value);
    if (varCbxCidade) {
        if (varCbxCidade.options[varCbxCidade.selectedIndex].text == 'BRASILIA / PLANO PILOTO')
            url += "/" + gerarPermalink('BRASILIA');
        else
            url += "/" + gerarPermalink(varCbxCidade.options[varCbxCidade.selectedIndex].text);
    }
    else if (negocio == "r")
        url += "/rural"
    if (varCbxTipo)
        url += "/" + gerarPermalink(varCbxTipo.options[varCbxTipo.selectedIndex].text);
    if (negocio == "r")
        url += "/rural";
    else if (negocio == "a")
        url += "/aluguel";
    else if (negocio == "l")
        url += "/lancamento";
    else if (negocio == "t")
        url += "/temporada";
    else
        url += "/venda/";

    var urlQuery = '';
    if (varCbxBairro != null) {
        if (varCbxBairro.selectedIndex == 0)
            urlQuery += "&bairro=todos";
        else
            urlQuery += "&bairro=" + gerarPermalink(varCbxBairro.options[varCbxBairro.selectedIndex].text);
    }
    if (vTipoPesquisa == "lista" || vTipoPesquisa == "Listagem")
        urlQuery += "&busca=lista";
    else if (vTipoPesquisa == "galeria" || vTipoPesquisa == "Galeria")
        urlQuery += "&busca=galeria";
    else if (vTipoPesquisa == "mapa" || vTipoPesquisa == "Mapa")
        urlQuery += "&busca=mapa";

    if (varCbxQuarto != null) {
        if (varCbxQuarto.selectedIndex == 0)
            urlQuery += "&quarto=todos";
        else
            urlQuery += "&quarto=" + gerarPermalink(varCbxQuarto.options[varCbxQuarto.selectedIndex].value);
    }

    if (varInputPalavra != null && varInputPalavra.value != "")
        urlQuery += "&palavra=" + escape(varInputPalavra.value);

    var varOrdemAba = document.getElementById('cbxOrdemAba');
    if (varOrdemAba && varOrdemAba.value != pegarQueryString('o'))
        urlQuery += '&o=' + escape(varOrdemAba.value);
    else
        urlQuery += '&o=' + escape(varCbxOrdem.value);
    if (varInputPreco && varInputPreco.value != "")
        urlQuery += '&v=' + escape(varInputPreco.value);
    if (varCbxPlanta && varCbxPlanta.checked && (negocioQuery != 'A' && negocioQuery != 'T'))
        urlQuery += '&planta=1';
    if (varCbxPronto && varCbxPronto.checked && (negocioQuery != 'A' && negocioQuery != 'T'))
        urlQuery += '&pronto=1';
    if (varCbxFinanciamento && varCbxFinanciamento.checked && (negocioQuery != 'A' && negocioQuery != 'T'))
        urlQuery += '&afn=1';
    
    //marcelo 28/10/2011
    if (location.pathname == "/busca_mobile")
        urlQuery += "&mobile=1";
    
    if (urlQuery != '')
        url += '?' + urlQuery.substr(1, urlQuery.length);

    return url;
    /*
    if (vSalao){
        url += "busca_salao.aspx";
    }
    else if (negocio == "R" || negocio == "r") {
        if (vTipoPesquisa == "lista" || vTipoPesquisa == "Listagem")
            url += "rural.aspx";
        else if (vTipoPesquisa == "galeria" || vTipoPesquisa == "Galeria")
            url += "rural_galeria.aspx";
        else if (vTipoPesquisa == "mapa" || vTipoPesquisa == "Mapa")
            url += "rural_mapa.aspx";
    }
    else if (negocio == "V" || negocio == "v") {
        if (vTipoPesquisa == "lista" || vTipoPesquisa == "Listagem")
            url += "venda.aspx";
        else if (vTipoPesquisa == "galeria" || vTipoPesquisa == "Galeria")
            url += "venda_galeria.aspx";
        else if (vTipoPesquisa == "mapa" || vTipoPesquisa == "Mapa")
            url += "venda_mapa.aspx";
    }
    else if (negocio == "A" || negocio == "a") {
        if (vTipoPesquisa == "lista" || vTipoPesquisa == "Listagem")
            url += "aluguel.aspx";
        else if (vTipoPesquisa == "galeria" || vTipoPesquisa == "Galeria")
            url += "aluguel_galeria.aspx";
        else if (vTipoPesquisa == "mapa" || vTipoPesquisa == "Mapa")
            url += "aluguel_mapa.aspx";
    }
    else if (negocio == "L" || negocio == "l") {
        url += "lancamento.aspx";
    }
    else if (negocio == "T" || negocio == "t") {
        if (vTipoPesquisa == "lista" || vTipoPesquisa == "Listagem")
            url += "temporada.aspx";
        else if (vTipoPesquisa == "galeria" || vTipoPesquisa == "Galeria")
            url += "temporada_galeria.aspx";
        else if (vTipoPesquisa == "mapa" || vTipoPesquisa == "Mapa")
            url += "temporada_mapa.aspx";
    }
    
    if (varCbxUf) {
        url += "?uf=" + escape(varCbxUf.value);
    }
    if (vSalao){
        var usr = pegarQueryString("usr");
        if(usr != null)
            url += "&usr=" + usr;
        }
    if (varCbxNegocio != null){
        url += "&n=" + escape(varCbxNegocio.value);
        negocioQuery = escape(varCbxNegocio.value);
    }
    else{
        url += "&n=R";
        negocioQuery = "R";
    }
    if (varCbxCidade != null)
        url += "&c=" + escape(varCbxCidade.value);
    if (varCbxRegiao != null)
        url += "&r=" + escape(varCbxRegiao.value);
    if (varCbxBairro != null)
        url += "&b=" + escape(varCbxBairro.value);
    if (varCbxTipo)
        url += "&t=" + escape(varCbxTipo.value);
    if (varCbxQuarto != null)
        url += "&q=" + escape(varCbxQuarto.value);
    if (varInputPalavra != null)
        url += "&p=" + escape(varInputPalavra.value);
    var varOrdemAba = document.getElementById('cbxOrdemAba');
    if (varOrdemAba != null && varOrdemAba.value != pegarQueryString("o"))
        url += "&o=" + escape(varOrdemAba.value);
    else
        url += "&o=" + escape(varCbxOrdem.value);
    if (varInputPreco != null)
        url += "&v=" + escape(varInputPreco.value);
    if (varCbxPlanta != null && varCbxPlanta.checked && (negocioQuery != 'A' && negocioQuery != 'T'))
        url += "&planta=1";
    if (varCbxPronto != null && varCbxPronto.checked && (negocioQuery != 'A' && negocioQuery != 'T'))
        url += "&pronto=1";
    if (varCbxFinanciamento != null && varCbxFinanciamento.checked && (negocioQuery != 'A' && negocioQuery != 'T'))
        url += "&afn=1";
    url += "#busca";
    return url;
    */
}

function gerarURLAntiga() {

    var url = "";

    if (vSalao) {
        url += "busca_salao.aspx";
    }

    else if (location.pathname == "/busca_mobile") {
        if (varCbxNegocio.value == "L")
            url += "lancamento_mobile.aspx";
        else
            url += "venda_mobile.aspx";
    }

    else if (negocio == "R" || negocio == "r") {
        if (vTipoPesquisa == "lista" || vTipoPesquisa == "Listagem")
            url += "rural.aspx";
        else if (vTipoPesquisa == "galeria" || vTipoPesquisa == "Galeria")
            url += "rural_galeria.aspx";
        else if (vTipoPesquisa == "mapa" || vTipoPesquisa == "Mapa")
            url += "rural_mapa.aspx";
    }
    else if (negocio == "V" || negocio == "v") {
        if (vTipoPesquisa == "lista" || vTipoPesquisa == "Listagem")
            url += "venda.aspx";
        else if (vTipoPesquisa == "galeria" || vTipoPesquisa == "Galeria")
            url += "venda_galeria.aspx";
        else if (vTipoPesquisa == "mapa" || vTipoPesquisa == "Mapa")
            url += "venda_mapa.aspx";
    }
    else if (negocio == "A" || negocio == "a") {
        if (vTipoPesquisa == "lista" || vTipoPesquisa == "Listagem")
            url += "aluguel.aspx";
        else if (vTipoPesquisa == "galeria" || vTipoPesquisa == "Galeria")
            url += "aluguel_galeria.aspx";
        else if (vTipoPesquisa == "mapa" || vTipoPesquisa == "Mapa")
            url += "aluguel_mapa.aspx";
    }
    else if (negocio == "L" || negocio == "l") {
        url += "lancamento.aspx";
    }
    else if (negocio == "T" || negocio == "t") {
        if (vTipoPesquisa == "lista" || vTipoPesquisa == "Listagem")
            url += "temporada.aspx";
        else if (vTipoPesquisa == "galeria" || vTipoPesquisa == "Galeria")
            url += "temporada_galeria.aspx";
        else if (vTipoPesquisa == "mapa" || vTipoPesquisa == "Mapa")
            url += "temporada_mapa.aspx";
    }

    if (varCbxUf) {
        url += "?uf=" + escape(varCbxUf.value);
    }
    if (vSalao) {
        var usr = pegarQueryString("usr");
        if (usr != null)
            url += "&usr=" + usr;
    }
    if (varCbxNegocio != null) {
        url += "&n=" + escape(varCbxNegocio.value);
        negocioQuery = escape(varCbxNegocio.value);
    }
    else {
        url += "&n=R";
        negocioQuery = "R";
    }
    if (varCbxCidade != null)
        url += "&c=" + escape(varCbxCidade.value);
    if (varCbxRegiao != null)
        url += "&r=" + escape(varCbxRegiao.value);
    if (varCbxBairro != null)
        url += "&b=" + escape(varCbxBairro.value);
    if (varCbxTipo)
        url += "&t=" + escape(varCbxTipo.value);
    if (varCbxQuarto != null)
        url += "&q=" + escape(varCbxQuarto.value);
    if (varInputPalavra != null)
        url += "&p=" + escape(varInputPalavra.value);
    var varOrdemAba = document.getElementById('cbxOrdemAba');
    if (varOrdemAba != null && varOrdemAba.value != pegarQueryString("o"))
        url += "&o=" + escape(varOrdemAba.value);
    else
        url += "&o=" + escape(varCbxOrdem.value);
    if (varInputPreco != null)
        url += "&v=" + escape(varInputPreco.value);
    if (varCbxPlanta != null && varCbxPlanta.checked && (negocioQuery != 'A' && negocioQuery != 'T'))
        url += "&planta=1";
    if (varCbxPronto != null && varCbxPronto.checked && (negocioQuery != 'A' && negocioQuery != 'T'))
        url += "&pronto=1";
    if (varCbxFinanciamento != null && varCbxFinanciamento.checked && (negocioQuery != 'A' && negocioQuery != 'T'))
        url += "&afn=1";
    url += "#busca";

    return url;
}

function pegarQueryString(variavel)
{
	qs=new Array();
	var str = location.search.split("&");
	if(str != ""){
		for(i=0;i<str.length;i++){
			var nvar = str[i].split("=")
			qs[nvar[0]]=unescape(nvar[1])
		}
    }
	return qs[variavel];
}

function pressionarEnter(evento) {
    if (evento != null)
    {
        if (evento.keyCode == 13 || evento.which == 13) {
            pesquisar();
            return false;
        }
    }
}

function pesquisar() {

    if (location.pathname == "/busca_mobile")
        location.href = gerarURLAntiga();
    else
        location.href = gerarUrl();
}

function pesquisarAntigo() {
    location.href = gerarURLAntiga();

    if (location.pathname == "/busca_salao") {
        gravarPretensao();
    }
}

function gravarPretensao() {

    var email = pegarQueryString("nom_email");

    if (email != null && email != "") {

        var uf = escape(varCbxUf.value),
        cidade = escape(varCbxCidade.value),
        bairro = escape(varCbxBairro.value),
        tipo = escape(varCbxTipo.value),
        quartos = escape(varCbxQuarto.value);

        Wimoveis2011.WebControl.Visitante.gravarPesquisa(uf, cidade, bairro, tipo, quartos, email, callback_teste);
    }
}

function callback_teste(res){
}

function pesquisarBlank() {
    window.open(gerarUrl());
}

///////////////////////////////////////////////////////////////////////////////////

var PrecoExibido = false;
var M2Exibido = false;
var BairroExibido = false;

function ativarItens(nomeCtrl, nomeLink, nomeTag) {
    var ulCtrl = document.getElementById(nomeCtrl);
    var linkCtrl = document.getElementById(nomeLink);
    for (var i = 0; i < ulCtrl.childNodes.length; i++) {
        if (ulCtrl.childNodes[i].tagName && ulCtrl.childNodes[i].tagName == nomeTag) 
            ulCtrl.childNodes[i].style.display = "";  //(nomeTag == "TR") ? "block" : "inline";
    }

    if (vCulturaPadrao == 'en-US')
        linkCtrl.innerHTML = 'Close (-)';
    else
        linkCtrl.innerHTML = 'Fechar (-)';
}

function desativarItens(nomeCtrl, nomeLink, nomeTag) {
    var ulCtrl = document.getElementById(nomeCtrl);
    var linkCtrl = document.getElementById(nomeLink);
    var c = 0;
    for (var i = 0; i < ulCtrl.childNodes.length - 2; i++) {
        if (ulCtrl.childNodes[i].tagName && ulCtrl.childNodes[i].tagName == nomeTag) {
            if (c > ((nomeTag == "TR") ? 9 : 8)) 
                ulCtrl.childNodes[i].style.display = "none";
            c++;
        }
    }

    if (vCulturaPadrao == 'en-US')
        linkCtrl.innerHTML = 'Show all (-)';
    else
        linkCtrl.innerHTML = 'Mostrar Todos (+)';
}

function exibirPreco() {
    if (!PrecoExibido) {
        ativarItens("ulPreco", "liPrecoLink","LI");
        PrecoExibido = true;
    }
    else {
        desativarItens("ulPreco", "liPrecoLink", "LI");
        PrecoExibido = false;
    }
}

function exibirM2() {
    if (!M2Exibido) {
        ativarItens("ulM2", "liM2Link","LI");
        M2Exibido = true;
    }
    else {
        desativarItens("ulM2", "liM2Link","LI");
        M2Exibido = false;
    }
}

function exibirBairro() {
    if (!BairroExibido) {
        ativarItens("ulBairro", "liBairroLink","TR");
        BairroExibido = true;
    }
    else {
        desativarItens("ulBairro", "liBairroLink","TR");
        BairroExibido = false;
    }
}

function incluirParam(oldUrl, param, valor) {
    var url = '';
    var str = oldUrl;
    if (str.indexOf("#") >= 0)
        str = str.substr(0, str.indexOf("#"));

    if (pegarQueryString('pg') != 0)
        str = str.replace('&pg=' + pegarQueryString('pg'), '');
    if (str.indexOf('&' + param + '=') >= 0) {
        url = str.substr(0, str.indexOf('&' + param + '='));
        str = str.substr(str.indexOf('&' + param + '=') + 1);
        url += '&' + param + '=' + valor;
        if (str.indexOf('&') > 0)
            url += str.substr(str.indexOf('&'));
    }
    else
        url = str + ((str.indexOf('?') >= 0) ? '&' : '?') + param + '=' + valor;
    return url;
}

function filtrarQuarto(valor) {
    //var url = incluirParam(location.href, "qi", valor);
    var url = "/" + incluirParam(urlReal, "qi", valor);
    if (valor == 4)
        valor = 100;
    location.href = incluirParam(url, "qf", valor);
    //location.href = incluirParam(location.href, "q", valor);
}

function filtrarBairro(valor) {
    //location.href = incluirParam(location.href, "b", valor);
    location.href = "/" + incluirParam(urlReal, "b", valor);
}

function pegarValorInicial(valorFinal) {
    var valorInicial = 0;
    if (varCbxNegocio != null && varCbxNegocio.value == 'A') {
        switch (valorFinal) {
            case 0: valorInicial = 0; break;
            case 700: valorInicial = 1; break;
            case 850: valorInicial = 701; break;
            case 950: valorInicial = 851; break;
            case 1200: valorInicial = 951; break;
            case 1450: valorInicial = 1201; break;
            case 2000: valorInicial = 1451; break;
            case 4000: valorInicial = 2001; break;
            case 8000: valorInicial = 4001; break;
            case 12000: valorInicial = 8001; break;
            case 99999: valorInicial = 12001; break;
        }
    }
    else {
        switch (valorFinal) {
            case 0: valorInicial = 0; break;
            case 150000: valorInicial = 1; break;
            case 250000: valorInicial = 150001; break;
            case 350000: valorInicial = 250001; break;
            case 450000: valorInicial = 350001; break;
            case 600000: valorInicial = 450001; break;
            case 800000: valorInicial = 600001; break;
            case 1200000: valorInicial = 800001; break;
            case 2000000: valorInicial = 1200001; break;
            case 3000000: valorInicial = 2000001; break;
            case 9999999: valorInicial = 3000001; break;
        }
    }
    return valorInicial;
}

function pegarAreaInicial(areaFinal) {
    var areaInicial = 0;
    switch (areaFinal) {
        case 0: areaInicial = 0; break;
        case 30: areaInicial = 1; break;
        case 60: areaInicial = 31; break;
        case 90: areaInicial = 61; break;
        case 120: areaInicial = 91; break;
        case 150: areaInicial = 121; break;
        case 180: areaInicial = 151; break;
        case 209: areaInicial = 181; break;
        case 240: areaInicial = 210; break;
        case 270: areaInicial = 241; break;
        case 300: areaInicial = 271; break;
        case 999: areaInicial = 301; break;
    }
    return areaInicial;
}

function filtrarPreco(valor) {
    var valorInicial = pegarValorInicial(valor);
    //var url = incluirParam(location.href, "vi", valorInicial);
    var url = "/" + incluirParam(urlReal, "vi", valorInicial);
    location.href = incluirParam(url, "vf", valor) + "#busca";
}

function filtrarArea(area) {
    var areaInicial = pegarAreaInicial(area);
    //var url = incluirParam(location.href, "ai", areaInicial);
    var url = "/" + incluirParam(urlReal, "ai", areaInicial);
    location.href = incluirParam(url, "af", area) + "#busca";
}

function filtrarSuite(suite) {
    //var url = incluirParam(location.href, "si", suite);
    var url = "/" + incluirParam(urlReal, "si", suite);
    if (suite == 4)
        suite = 100;
    location.href = incluirParam(url, "sf", suite) + "#busca";
}

function filtrarVaga(suite) {
    //var url = incluirParam(location.href, "gi", suite);
    var url = "/" + incluirParam(urlReal, "gi", suite);
    if (suite == 4)
        suite = 100;
    location.href = incluirParam(url, "gf", suite) + "#busca";
}

//-->

//Marcelo 22/11/2010
function setCbx() {

    var url = document.location.href;

    var name = new Array();
    name[0] = 'CIDADE';
    name[1] = 'BAIRRO';

    var cbxName = new Array();
    cbxName[0] = 'cbxCidade';
    cbxName[1] = 'cbxBairro';

    var n = new Array();
    n[0] = 'c';
    n[1] = 'b';

    var counter;
    var indice;
    for (counter = 0; counter < name.length; counter++) {
        var vi = url.indexOf('&' + name[counter] + '=');
        var vf = url.indexOf('&', vi + 1);
        var str = url.slice(vi + 8, vf);
        str = str.replace('%20', ' ');

        var cbx = document.getElementById(cbxName[counter]);


        indice = trocaOpcao(str, cbx);

        if (indice != undefined) {
            vi = url.indexOf('&' + n[counter] + '=');
            vf = url.indexOf('&', vi + 1);
            str = url.slice(vi, vf);
            url = url.replace(str, '&' + n[counter] + '=' + indice[0]);

            if (n[counter] == 'c')
                mudarCidade(indice[1]);
            if (n[counter] == 'b')
                mudarBairro(indice[1]);
        }
    }

    if (indice != undefined) {
        if (url.indexOf('retorno') == -1){
            url = url + '&retorno=true';
            abrirPopUp();
            document.location.href = url;
        }
    }
}

function trocaOpcao(valor, objSel) {

    if (valor == 'TODOS') {
        var indice_value = new Array();
        indice_value[0] = objSel.value;
        indice_value[1] = 0;

        return indice_value;
    }

    for (i = 0; i < objSel.length; i++) {
        qtd = valor.length;
        if (objSel.options[i].text.substring(0, qtd).toUpperCase() == valor.toUpperCase()) {
            objSel.selectedIndex = i;

            var indice_value = new Array();
            indice_value[0] = objSel.value;
            indice_value[1] = i;

            return indice_value;
        }
    }
}

//Marcelo 23/11/2010
function abrirPopUp() {
    /*
    var frameVisitante = document.createElement('iframe');
    frameVisitante.id = 'frameVisitante';
    frameVisitante.style.width = 0 + 'px';
    frameVisitante.style.height = 0 + 'px';
    frameVisitante.src = gerarURL(document.location.href);
    frameVisitante.frameBorder = 0;
    document.getElementById('divIFrame').appendChild(frameVisitante);
    */

    if (pegarQueryString('ID_USUARIO') != 0) {
        window.open(gerarURL(document.URL), '1', 'toolbar=no,location=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=600,height=320');
    }
}

function gerarURL(url) {
    var strReplace = 'busca_salao.aspx';
    var novaURL = 'http://fazendomais/wimoveis/frmcadastro.aspx?';

    var vi = url.indexOf(strReplace);
    var vf = url.indexOf('&ID_USUARIO');
    var str = url.slice(0/*vi + strReplace.length+1*/, vf + 1);

    url = url.replace(str, '');
    //url = url.replace('busca_salao.aspx', novaURL);
    url = novaURL + url;
    return url = url.replace('&retorno=true', '');
}

//Marcelo 24/11/2010
function redirecionaListaEmpresa() {

    var c = (pegarQueryString('c') != undefined ? pegarQueryString('c') : 0);
    var q = (pegarQueryString('q') != undefined ? pegarQueryString('q') : 0);
    var t = (pegarQueryString('t') != undefined ? pegarQueryString('t') : 0);
    var b = (pegarQueryString('b') != undefined ? pegarQueryString('b') : 0);

    var url = "http://cyber.salaowimoveis.com.br/empresa_salao.aspx?" + "c=" + c + "&q=" + q + "&b=" + b + "&t=" +t;
    window.open(url, '2', 'toolbar=no,location=no,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width=800,height=600');
}

function OnEnter(evt) {
    var key_code = evt.keyCode ? evt.keyCode :
                       evt.charCode ? evt.charCode :
                       evt.which ? evt.which : void 0;


    if (key_code == 13) {
        pesquisa_codigo();
    }
}

function deleteQueryString(elementoInicial, elementoFinal, elementoNome) {

    var url = document.location.href;
    if (elementoInicial != 'bairro') {
        var vi = (url.indexOf('&' + elementoInicial) != -1 ? url.indexOf('&' + elementoInicial) : url.indexOf('?' + elementoInicial));
        var vf = url.indexOf(elementoFinal);

        if (vi != -1 && vf != -1) {
            if ((url.indexOf('&', vf)) == -1) {
                var str = url.slice(vi, url.length);
            }
            else
                var str = url.slice(vi, (url.indexOf('&', vf)));

            var novaURL = document.location.href.replace(str, '');

            if (novaURL.indexOf('?') == -1)
                novaURL = novaURL.replace('&', '?');

            if (elementoInicial != 'qi')
                document.getElementById(elementoNome).setAttribute('href', novaURL);

            else {
                vi = novaURL.indexOf('&q=');

                if (vi != -1) {

                    var indexQuarto = url.indexOf("&q=");

                    if (indexQuarto != -1)
                        novaURL = novaURL.replace(novaURL.slice(indexQuarto, indexQuarto + 4), '&q=0');

                    str = novaURL.slice(vi, (url.indexOf('&', vi + 1)));
                }

                if (novaURL.indexOf('?') == -1)
                    novaURL = novaURL.replace('&', '?');

                document.getElementById(elementoNome).setAttribute('href', novaURL);
            }
        }
    }

    else {
        var vi = url.indexOf('&bairro=');
        var i = '&';

        if (vi == -1) {
            vi = url.indexOf('?bairro=');
            i = '?';
        }
        
        var index = (url.indexOf('&', vi + 1) != -1 ? url.indexOf('&', vi + 1) : url.length);
        var str = url.slice(vi, index);
        var novaURL = document.location.href.replace(str, i+ 'bairro=todos');
        
        if (novaURL.indexOf('?') == -1)
            novaURL = novaURL.replace('&', '?');
        
        document.getElementById(elementoNome).setAttribute('href', novaURL);
    }
}

function formatarFiltro() {
    
    var tags       = ["bairro="       ,"vi="          ,"ai="        ,"qi="       ,"si="      ,"gi="     ];
    var liListagem = ["liBairro" ,"liFaixaPreco" ,"liAreaUtil" ,"liQuartos" ,"liSuites" ,"liVagas" ];
    
    var url = document.location.href;

    if (pegarIndice(url, tags[0]) == -1 || pegarQueryString('?bairro') == "todos" || pegarQueryString('&bairro') == "todos")
        ocultarElemento(liListagem[0]);
    else
        if (document.getElementById('pInfo') != -1 && document.getElementById('pInfo') != null)
            document.getElementById('pInfo').style.display = 'none';

    for (var counter = 1; counter < tags.length; counter++)
        if (pegarIndice(url, tags[counter]) == -1)
            ocultarElemento(liListagem[counter]);
        else
            if (document.getElementById('pInfo') != -1 && document.getElementById('pInfo') != null)
                document.getElementById('pInfo').style.display = 'none';
}

//function ocultarElemento(idGaleria,idListagem) {
function ocultarElemento(id) {
    //if (document.getElementById(idGaleria) != null)
    document.getElementById(id).style.display = 'none';
    //else if (document.getElementById(idListagem) != null)
        //document.getElementById(idListagem).style.display = 'none';
}

function pegarIndice(url,str) {
    if (url.indexOf('?' + str) != -1)
        return url.indexOf('?' + str);
    else
        return url.indexOf('&' + str);
}

function definirInfo() {
    if (document.getElementById('spanLocalPesquisa') != null) {
        var cidade = pegarItemCbx('cbxCidade', false);
        var uf = pegarItemCbx('cbxUf', true);
        var negocio = pegarItemCbx('cbxNegocio', false);
        var tipo = pegarItemCbx('cbxTipo', false);
        var str = cidade + ' / ' + uf + ' / ' + negocio + ' / ' + tipo;


        document.getElementById('spanLocalPesquisa').innerHTML = str;
    }
}

function pegarItemCbx(cbxNome, value) {

    if (document.getElementById(cbxNome) != null) {
        var indice = document.getElementById(cbxNome).options.selectedIndex;
        var str;
        if (value == true)
            str = document.getElementById(cbxNome).options[indice].value;
        else
            str = document.getElementById(cbxNome).options[indice].innerHTML;

        return str;
    }

    return "";
}
