﻿var paginaAtual;

function openPopUp() {
    window.open('EnviarPagina.aspx?url=' + document.location.href, 'popup', 'height = 600, width = 550,location = no,toolbar = no,scrollbars = auto, status=no, menubar=no');
}

function AtualizaImagemSite(site, legenda) {
    document.getElementById("ctl00_ctl00_ContentPlaceHolderConteudo_OrfaoContent_imgGrande").src = "/multimidia/images/" + site;
    document.getElementById("ctl00_ctl00_ContentPlaceHolderConteudo_OrfaoContent_imgGrande").alt = legenda;
    document.getElementById("ctl00_ctl00_ContentPlaceHolderConteudo_OrfaoContent_imgGrande").title = legenda;
    document.getElementById("legendaImagemGrande").innerHTML = legenda;
}

function CarregaPlanta(CaminhoHumanizada, CaminhoSimplificadaMedia, Legenda) {
    document.getElementById("ctl00_ctl00_ContentPlaceHolderConteudo_OrfaoContent_imgDadosPlantas_ImagemGrande").src = CaminhoSimplificadaMedia;
    document.getElementById("ctl00_ctl00_ContentPlaceHolderConteudo_OrfaoContent_imgDadosPlantas_ImagemGrande").alt = Legenda;
    document.getElementById("ctl00_ctl00_ContentPlaceHolderConteudo_OrfaoContent_imgDadosPlantas_ImagemGrande").title = Legenda;
    document.getElementById("ctl00_ctl00_ContentPlaceHolderConteudo_OrfaoContent_hlDownloadPlanta").href = CaminhoHumanizada;
    document.getElementById("dadosPlantaConteudo").innerHTML = Legenda;

}

function SelectImpressaoProdutosOnChange(dropdown, urlDomain, produtoId) {
    var myindex = dropdown.selectedIndex
    var SelValue = dropdown.options[myindex].value

    var baseURL;

    if (myindex == 1) {       
        var url = 'http://' + urlDomain + '/popup-impressao.aspx?id='+ produtoId + '&imagens=0';
        window.open(url, 'popWindow', 'width=680, height=700, menubar=auto, scrollbars=yes, resizable=no');
    }
    if (myindex == 2) {
        var url = 'http://' + urlDomain + '/popup-impressao.aspx?id=' + produtoId + '&imagens=1';
        window.open(url, 'popWindow', 'width=680, height=700, menubar=auto, scrollbars=yes, resizable=no');
    }

    return false;
}

function ConsultorOnline(nomeEmpreendimento) {
    var paramEmpreendimento = (nomeEmpreendimento.length == 0) ? "?origem=Gafisa%20-%20Home" : "?origem=" + nomeEmpreendimento;

    // Notificação do Omniture
    // trackView('Contato - Consultor on line - Tela inicial', '', 'Contato');
    window.open('http://www13.directtalk.com.br/clientes/custom/Gafisa/init.asp' + paramEmpreendimento, 'popup', 'height = 505, width = 450, resizable = no, toolbar = 0, location = 0, directories = 0 , status = 0 , menubar = 0');
    return;
}

function Simulador(infoProduto) {
    // Notificação Omniture agora no HTML
    var url = "/Simulador/CarregaSimulador.aspx?nomeEmpreendimento=" + infoProduto;
    //var url = "/swf/SimuladorFinanciamento.swf";
    
    window.open(url, 'popup', 'width = 550, height = 408, location = no,toolbar = no,scrollbars = auto, status=no, menubar=no');
}

function SimuladorConcluiu() {
    // Notificação do Omniture
    trackView('Institucional - Simule seu Financiamento - Resultado', 'event10', 'Institucional');
    return true;
}

function EscondeCarregando() {
    var carregando = document.getElementById('_divCarregando');    
    if (carregando != null) {
        carregando.style.display = "none";
    }
}

function EsconderBtnRecebeNovidades() {
    var carregando = document.getElementById('divbtnRecebeNovidades');
    if (carregando != null) {
        carregando.style.display = 'none';
    }
}



function EnvieEmail(nomeEmpreendimento) {

    // Notificação do Omniture
    trackView('Contato - Contato por Email - Formulario', '', 'Contato');

    if ($find('ctl00$ctl00$EnviePagina1$hdnNomeEmpreendimento')) $find('ctl00$ctl00$EnviePagina1$hdnNomeEmpreendimento').value = nomeEmpreendimento;
    if ($find('ctl00_ctl00_EnviePagina1_MPESiteEmail')) $find('ctl00_ctl00_EnviePagina1_MPESiteEmail').show();
    if ($find('ctl00_EnviePagina1_MPESiteEmail')) $find('ctl00_EnviePagina1_MPESiteEmail').show();
}

function EnvieEmailMeioProduto(nomeEmpreendimento) {

    // Notificação do Omniture
    trackView('Contato - Contato por Email - Formulario', '', 'Contato');

    if ($find('ctl00$ctl00$EnviaEmailMeioProduto1$hdnNomeEmpreendimento')) $find('ctl00$ctl00$EnviaEmailMeioProduto1$hdnNomeEmpreendimento').value = nomeEmpreendimento;
    if ($find('ctl00_ctl00_EnviaEmailMeioProduto1_MPESiteEmail')) $find('ctl00_ctl00_EnviaEmailMeioProduto1_MPESiteEmail').show();
    if ($find('ctl00_EnviaEmailMeioProduto1_MPESiteEmail')) $find('ctl00_EnviaEmailMeioProduto1_MPESiteEmail').show();
}
// Adiciona um empreendimento nos favoritos
function AdicionaFavorito(imgObject, codigo, textoObject, nomeEmpreendimento, txtDesmarcarFavorito, txtAdicionarFavorito) {

    // Encontro o controle do campo de texto preparado para abrir o empreendimento
    if (document.getElementById('ctl00_ctl00_ctrFavoritosContador_hfCodigoEmpreendimento') || document.getElementById('ctl00_ctrFavoritosContador_hfCodigoEmpreendimento')) {

        var oHfCodigoEmpreendimento;
        if (document.getElementById('ctl00_ctl00_ctrFavoritosContador_hfCodigoEmpreendimento')) oHfCodigoEmpreendimento = document.getElementById('ctl00_ctl00_ctrFavoritosContador_hfCodigoEmpreendimento');
        if (document.getElementById('ctl00_ctrFavoritosContador_hfCodigoEmpreendimento')) oHfCodigoEmpreendimento = document.getElementById('ctl00_ctrFavoritosContador_hfCodigoEmpreendimento');
                
        // Atribuo o código
        oHfCodigoEmpreendimento.value = codigo;
        
        // Encontro o controle que aciona o updatePanel
        if (document.getElementById('ctl00_ctl00_ctrFavoritosContador_btnFavoritos') || document.getElementById('ctl00_ctrFavoritosContador_btnFavoritos')) {
            var oBtnFavoritos;
            
            if (document.getElementById('ctl00_ctl00_ctrFavoritosContador_btnFavoritos')) oBtnFavoritos = 'ctl00_ctl00_ctrFavoritosContador_btnFavoritos';
            if (document.getElementById('ctl00_ctrFavoritosContador_btnFavoritos')) oBtnFavoritos = 'ctl00_ctrFavoritosContador_btnFavoritos';

            if (imgObject != null) {
                // Se passou um objeto de imagem, tento trocar a opção
                if (document.getElementById(imgObject)) {
                    var imageObject = document.getElementById(imgObject);
                    var imgHabilitada = '/images/ck_verde.gif';
                    var imgDesabilitada = '/images/ck_vermelho.gif';

                    var imgPathEnd = imageObject.src.substring(imageObject.src.length - 10);
                    imageObject.src = (imgPathEnd == imgHabilitada.substring(imgHabilitada.length - 10)) ? imgDesabilitada : imgHabilitada;
                }

            }

            if (textoObject != null) {

                if (document.getElementById(textoObject)) {

                    var linkObject = document.getElementById(textoObject);
                    var txtHabilitado = txtDesmarcarFavorito;
                    var txtDesabilitado = txtAdicionarFavorito;

                    var txtLinkChange = linkObject.innerHTML.substr(0, 7);
                    if (txtLinkChange == txtHabilitado.substring(0, 7)) {
                        linkObject.innerHTML = txtDesabilitado;
                    } else {
                        // Notificação do Omniture
                        trackView('Imoveis - ' + nomeEmpreendimento + ' - Adic a favoritos', '', 'Imoveis');
                        linkObject.innerHTML = txtHabilitado;

                    }
                    
                }
            }

            __doPostBack(oBtnFavoritos);
        }
    }
}

function IndiqueAmigo() {

    // Notificação do Omniture
    if (nomeEmpreendimento.length > 0) trackView('Imoveis - ' + nomeEmpreendimento + ' - Enviar para amigo - Formulario', '', 'Imoveis');
    else trackView('Institucional - Indique este site - Formulario', '', 'Institucional');
    
    if ($find('ctl00_ctl00_EnviePaginaAmigo1_MPEIndique')) $find('ctl00_ctl00_EnviePaginaAmigo1_MPEIndique').show();
    else if ($find('ctl00_EnviePaginaAmigo1_MPEIndique')) $find('ctl00_EnviePaginaAmigo1_MPEIndique').show();
}

function RSSInstrucoes() {
    if ($find('ctl00_ctl00_EnviePaginaAmigo1_MPEIndique')) $find('ctl00_ctl00_EnviePaginaAmigo1_MPEIndique').show();
    else if ($find('ctl00_EnviePaginaAmigo1_MPEIndique')) $find('ctl00_EnviePaginaAmigo1_MPEIndique').show();
}

function AgendeContato() {

    // Notificação do Omniture
    trackView('Contato - Agende seu Contato - Formulario', '', 'Contato');

    if ($find('ctl00_ctl00_Consultor1_MPESiteAgende')) 
        $find('ctl00_ctl00_Consultor1_MPESiteAgende').show();

    if ($find('ctl00_Consultor1_MPESiteAgende'))
        $find('ctl00_Consultor1_MPESiteAgende').show();
}

function ClickToCall(origem) {  
    var url;
    if (origem == "rj") {
        url = 'http://www.clickfone.com.br/gafisarj/';
    }
    else {
        url = 'http://www.clickfone.com.br/gafisasp/';
    }


    window.open(url, 'popup', 'height = 290, width = 450, menubar=no, scrollbars=auto, resizable=no');
   
}

//Função que recupera o server control ID passando como parametro o ID
function findObjWithClientId(Id) {
    var ctrls = document.all;

    for (var count = 0; count < ctrls.length; count++) {
        var index = ctrls[count].id.indexOf(Id);

        if (index != -1) {
            if ((ctrls[count].id.length - index) == Id.length) {
                return ctrls[count];
            }
        }
    }
    return null;
}

//Funcao que pega o HTML da pagina
function getHtml() {
    var conteudoDiv = document.getElementById('DivConteudoSite').innerHTML;
    findObjWithClientId("txtConteudoHtml").value = conteudoDiv;
}

// VisualizarMidia
function popUpVisualizarMidia(url, height, width) {
    height = height;
    width = width;
    window.open(url, 'popWindow', "height=" + height + ",width=" + width + ",menubar=no, scrollbars=auto, resizable=yes");
}

// Muda o tamanho das fontes nas telas que possuem tal função
function mudaTamanho(idAlvo, acao) {
    if (!document.getElementById) return
    var selecionados = null;
    tamanho = tamanhoInicial;
    var i;
    var j;
    var tagsAlvo;

    tamanho += acao;

    if (tamanho < 0) tamanho = 0;
    if (tamanho > 3) tamanho = 3;

    //zero todos as instruções de aumento e diminuição do tamanho da font
    document.getElementById("Amenos").style.display = "none";
    document.getElementById("Amais").style.display = "none";
    document.getElementById("spanOu").style.display = "none";

    switch (tamanho) {
        case 0:
            document.getElementById("Amenos").style.display = "none";
            document.getElementById("Amais").style.display = "inline";
        break;

        case 3:
            document.getElementById("Amais").style.display = "none";
            document.getElementById("Amenos").style.display = "inline";
        break;

        default:
            document.getElementById("Amenos").style.display = "inline";
            document.getElementById("Amais").style.display = "inline";
            document.getElementById("spanOu").style.display = "inline";
        break;
    }

    tamanhoInicial = tamanho;

    if (!(selecionados = document.getElementById(idAlvo))) selecionados = document.getElementsByTagName(idAlvo)[0];

    selecionados.style.fontSize = tamanhos[tamanho];

    for (i = 0; i < tagAlvo.length; i++) {
        tagsAlvo = selecionados.getElementsByTagName(tagAlvo[i]);
        for (j = 0; j < tagsAlvo.length; j++) tagsAlvo[j].style.fontSize = tamanhos[tamanho];
    }
}

// Efetua a geolocalização do usuário
function geolocate() {
    if (google != null &&
        google.loader != null &&
        google.loader.ClientLocation != null &&
        google.loader.ClientLocation.address != null &&
        google.loader.ClientLocation.address.country_code == "BR" &&
        google.loader.ClientLocation.address.region != null) {


        var possuiCidade = false;
        var arrCookies = document.cookie.split(';');

        // Procuro por um ID de cidadde
        for (var i = 0; i < arrCookies.length; ++i) {
            if (arrCookies[i].indexOf('cidadeid') > 0) possuiCidade = true;
        }

        // Se não achou chave de localização, move para SP
        if (!possuiCidade) {
            document.cookie = 'LOCALIZACAO_CIDADE=cidadeid=' + google.loader.ClientLocation.address.region + ';';
            document.location.reload();
        }
    }
}

// Gera um movie Flash
function flashMovieConsultor(url, id, width, height, flashVars) {

    alert('chegou aqui - ' + flashVars);

    AC_FL_RunContent(
        'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0',
        'width', width,
        'height', height,
        'src', '/swf/' + url,
        'quality', 'high',
        'pluginspage', 'http://www.adobe.com/go/getflashplayer',
        'align', 'middle',
        'play', 'true',
        'loop', 'true',
        'scale', 'noscale',
        'wmode', 'transparent',
        'devicefont', 'false',
        'id', id,
        'bgcolor', '#ffffff',
        'name', id,
        'menu', 'true',
        'allowFullScreen', 'true',
        'allowScriptAccess', 'sameDomain',
        'movie', '/swf/' + url,
        'flashvars', 'ida = ' + flashVars,
        'salign', 'lt'
        ); //end AC code
}

function flashMovie55anos(url, id, width, height, flashVars) {
    AC_FL_RunContent(
        'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0',
        'width', width,
        'height', height,
        'src', '/55anos/' + url,
        'quality', 'high',
        'pluginspage', 'http://www.adobe.com/go/getflashplayer',
        'align', 'middle',
        'play', 'true',
        'loop', 'true',
        'scale', 'noscale',
        'wmode', 'transparent',
        'devicefont', 'false',
        'id', id,
        'bgcolor', '#ffffff',
        'name', id,
        'menu', 'true',
        'allowFullScreen', 'true',
        'allowScriptAccess', 'sameDomain',
        'movie', '/55anos/' + url,
        'flashvars', flashVars,
        'salign', 'lt'
        ); //end AC code
}

// Gera um movie Flash
function flashMovie(url, id, width, height, flashVars) {
    AC_FL_RunContent(
        'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0',
        'width', width,
        'height', height,
        'src', '/swf/' + url,
        'quality', 'high',
        'pluginspage', 'http://www.adobe.com/go/getflashplayer',
        'align', 'middle',
        'play', 'true',
        'loop', 'true',
        'scale', 'noscale',
        'wmode', 'transparent',
        'devicefont', 'false',
        'id', id,
        'bgcolor', '#ffffff',
        'name', id,
        'menu', 'true',
        'allowFullScreen', 'true',
        'allowScriptAccess', 'sameDomain',
        'movie', '/swf/' + url,
        'flashvars', flashVars,
        'salign', 'lt'
        ); //end AC code
}

// Trata o fim das requisições AJAX
function EndRequestHandler(sender, args) {

    // Se não deu nenhum erro
    if (args.get_error() == undefined) {
        // Página de Envie um email
        var objSucessoEmail = document.getElementById("hfSucessoEnvioEmailMensagem");
        if (objSucessoEmail != null && objSucessoEmail.value == "sucesso") {
            trackView('Contato - Contato por Email - Confirmado', 'event2', 'Contato');
        }

        // Página de envie página para um amigo
        var objSucessoAmigo = document.getElementById("hfSucessoEnvioPaginaAmigo");
        if (objSucessoAmigo != null && objSucessoAmigo.value == "sucesso") {
            if (nomeEmpreendimento.length > 0) trackView('Imoveis - ' + nomeEmpreendimento + ' - Enviar para amigo - Enviado', 'event8', 'Imoveis');
            else trackView('Institucional - Indique este site - Confirmado', '', 'Institucional');
        }

        // Página de envie página agende um contato
        var objSucessoAgende = document.getElementById("hfSucessoEnvioAgendeContato");
        if (objSucessoAgende != null && objSucessoAgende.value == "sucesso") {
            trackView('Contato - Agende seu Contato - Confirmado', 'event3', 'Contato');
        }

        // Página de envie página receba novidades
        var objSucessoNews = document.getElementById("hfSucessoRecebaNews");
        if (objSucessoNews != null && objSucessoNews.value == "sucesso") {
            trackView('Institucional - Cadastre se - Confirmado', 'event4', 'Institucional');
        }

        // Página de produto - form de breves lançamentos
        var objSucessoBL = document.getElementById("hfSucessoBrevesLancamentos");
        if (objSucessoBL != null && objSucessoBL.value == "sucesso") {
            if (nomeEmpreendimento.length > 0) trackView('Imoveis - ' + nomeEmpreendimento + ' - Breve Lancamento - Enviado', '', 'Imoveis');
        }
    }
}

function abrir() {
    document.getElementById('oQueRss').style.display = 'block';
    document.getElementById('transp').style.display = 'block';
}
function fechar() {
    document.getElementById('oQueRss').style.display = "none";
    document.getElementById('transp').style.display = 'none';
}

function abrirFormBusca() {
    document.getElementById('buscaFormulario').style.display = 'block';
    document.getElementById('blockAll').style.display = 'block';
}
function fecharFormBusca() {
    document.getElementById('buscaFormulario').style.display = "none";
    document.getElementById('blockAll').style.display = 'none';
}

function abrirDivConsultorOnLine() {
    document.getElementById('divConsultorOnLine').style.display = 'block';
    document.getElementById('divTranspConsultorOnLine').style.display = 'block';
}
function fecharDivConsultorOnLine() {
    document.getElementById('divConsultorOnLine').style.display = "none";   
}

function hideBuscaDrops() {
    document.getElementById('divSelectsBusca').style.display = "none";
}

function showDivConsultor(secs) {   
    if (readCookieFechaChat('fechaChat') != 'true') {
        setTimeout(function () {
            document.getElementById('chat').style.display = 'block';
        }, '40000');
    }
}

function readCookieFechaChat(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
}

//criar outro aqui para iphone

function showDivIPhone(secs) {
    setTimeout(function() {
    document.getElementById('floterIphone').style.display = 'block';
    }, secs);
}

/*function abrirDivConsultorOnLine() {
    document.getElementById('divConsultorOnLine').style.display = 'block';
    document.getElementById('divTranspConsultorOnLine').style.display = 'block';
}*/

function fecharDivIPhone() {
    document.getElementById('floterIphone').style.display = "none";    
}

function showDivReservaFloater() {
    setTimeout(function() {
        document.getElementById('floaterReserva').style.display = 'block';
    }, '20000');
}

function fecharDivReservaFloater() {   
    document.getElementById('floaterReserva').style.display = "none";
}

function showBuscaDrops() {
    document.getElementById('divSelectsBusca').style.display = "block";
}

function abrirVideo() {
    var element = document.getElementById('divSelectsBusca');

    if (element != null) {
        document.getElementById('divSelectsBusca').style.display = "none";   
    }    
    document.getElementById('ctl00_pnVideoHome').style.display = 'block';    
}
function fecharVideo() {
    var element = document.getElementById('divSelectsBusca');

    if (element != null) {
        document.getElementById('divSelectsBusca').style.display = "block";
    }        
    document.getElementById('ctl00_pnVideoHome').style.display = 'none';
}

/*Trabalhe Conosco*/
function trabalhePop() {
    var url = "/trabalheConosco.htm";

    window.open(url, 'popup', 'width = 1024, height = 580, location = no,toolbar = no,scrollbars = auto, status=no, menubar=no');
}

/*Ocultar Combos p/ IE6*/
function ocultarCombos(ocultar) {
    var versao = navigator.appVersion;
    if (versao.substr(versao.indexOf(';', 0) + 2, 8) == "MSIE 6.0") {
        if (navigator.appName != 'Netscape') {
            for (i = 0; i <= document.getElementsByTagName('SELECT').length - 1; i++) {
                document.getElementsByTagName('SELECT')[+i].style.visibility = ocultar
            }
        }
    }
}