
var winPopUpCotacao = null;

/*
Função para abrir pop up de cotação rápida
*/
function cotacaoRapida(ativo, idioma)
{                
    var url = '../';

    if(idioma == 'P')
    {
        url = ''; 
    }
        
    url += '/cotacao-rapida/cotacaorapida.aspx?codigoAtivo=' + ativo + '&idioma=' + idioma;
    
    if(winPopUpCotacao != null && !winPopUpCotacao.closed)
    {
        winPopUpCotacao.location.href = url;
        winPopUpCotacao.focus();
    }
    else
    {
        winPopUpCotacao = window.open(url, 'CotacaoRapida', 'width=352px,height=300px,scrollbars=1');
        winPopUpCotacao.focus();
    }     
}

/*
Função para pesquisar cotação rápida ao pressionar o enter no campo de pesquisa 

function keyPressPesquisaCotacao(objeto, evt)
{
    if(evt.which || evt.keyCode)
    {
        if ((evt.which == 13) || (evt.keyCode == 13))
        {
            document.getElementById(objeto).click();
            return false;
        }
    }    
}
*/
        
// MOSTRAR ABAS DE GRAFICOS DA HOME

function mostra_aba(tab)
{
    var loop_max = (document.getElementById("numero_aba").value/1) + (1);
    for (var i = 1; i < loop_max; i++) 
    {
        var aba_href = "aba_href_"+i;
        var aba_id = "aba_"+i;
        if(i == tab)
        {
            href_class = "ativa";
            estado_aba = "block";
        }
        else
        {
            href_class = "";
            estado_aba = "none";
        }
        document.getElementById(aba_href).className =  href_class;
        document.getElementById(aba_id).style.display = estado_aba;
    }
    
    if (tab == 2) {
        document.getElementById("frameGraficoCommodities").src = "http://www2.bmf.com.br/pages/portal/bmfbovespa/graficoshome/GraficosBMFBovespa-2011" + idiomaShort + ".asp";
    } else if (tab == 3) {
        document.getElementById("frameGraficoCommoditiesFin").src = "http://www2.bmf.com.br/pages/portal/bmfbovespa/graficoshome/GraficosBMFBovespa-2011" + idiomaShort + ".asp?mercado=f";
    }
}

//TROCA SWFs POR IMAGENS QUANDO O SITE FOR ACESSADO POR DISPOSITIVOS APPLE
function alternarFlashImagem() {
    var IMAGEM_BANNER = '<div style="background-image: url(img/bannerHome.gif); background-repeat: no-repeat; background-position:center; height:100%; width:100%; margin:0; padding:0;"/>';
    var IMAGEM_BANNER_EN = '<div style="background-image: url(../img/bannerHomeEn.gif); background-repeat: no-repeat; background-position:center; height:100%; width:100%; margin:0; padding:0;"/>';
    var IMAGEM_BANNER_ES = '<div style="background-image: url(../img/bannerHome.gif); background-repeat: no-repeat; background-position:center; height:100%; width:100%; margin:0; padding:0;"/>';
    var IMAGEM_SUBBANNER = '<a href="http://www.bmfbovespa.com.br/como-investir-na-bolsa.aspx?idioma=pt-br" target="_top"><img src="img/subBannerHome.jpg" width="280" height="115"/></a>';
    if ((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i))) {
        if (idiomaShort == '_en') {
            document.getElementById("bannerprincipal").innerHTML = IMAGEM_BANNER_EN;
            $('.escondeApple').hide();
        }
        else if (idiomaShort == '_es') {
            document.getElementById("bannerprincipal").innerHTML = IMAGEM_BANNER_ES;
            $('.escondeApple').hide();
        }
        else {
            document.getElementById("bannerprincipal").innerHTML = IMAGEM_BANNER;
            document.getElementById("subBanner").innerHTML = IMAGEM_SUBBANNER;
            $('.escondeApple').hide();
            //CODIGO DO BANNER DO IPAD
            $('#floaterBanner').remove();
        }
    }
}
