﻿// JScript source code
/** Initialize all of our objects now. */
window.historyStorage.init();
window.dhtmlHistory.create();
dhtmlHistory.initialize();            
dhtmlHistory.addListener(historyChange);// subscribe to DHTML history change

//var interval = window.setInterval('initialize()', 2000);
var interval = 2000;
var TimeOutLoadPage = 0;
CheckLoadedMasterPage();

// funcao recursiva que aguarda o html da masterPage ser carregado para que os objetos existam
function CheckLoadedMasterPage()
{
    if ( document.getElementById('hiddenUltimoObjeto') == null && TimeOutLoadPage < 10000 )
    {
        TimeOutLoadPage = TimeOutLoadPage + 300;
        window.setTimeout('CheckLoadedMasterPage()', 300);
    }
    else
        initialize();
}

function initialize() 
{
    // initialize the DHTML History
    clearInterval(interval);

    if (dhtmlHistory.isFirstLoad()) 
    {
        var hashValue = window.location.hash;
        if (hashValue == null || hashValue == undefined || hashValue == "" || (hashValue.length == 1 && hashValue.charAt(0) == "#"))
            hashValue = null;
        else if (hashValue.length > 1 && hashValue.charAt(0) == "#")
            hashValue = hashValue.substring(1);

        if(hashValue != null)
        {
            var nav = GetNavegador();    
            
            if (EnumNavegador.IE6 == nav)
            {
               var temp =  new String(window.location);
               var req = temp.split('#');
               hashValue = req[1];
            }

            var Menu = QueryString('menuId');
            if(Menu != '')
            {
                //verifica se tem cookie
                if (document.cookie.indexOf('pref_menu') != -1)
                    MontaMenu(Menu,false,true);
                else
                    MontaMenu(Menu);                    
            }

            if (hashValue.indexOf('pchave') >= 0)
            {
                if(document.all)
                    hashValue = UrlDecode(hashValue); 

                if(EnumNavegador.SAFARI == nav)
                {
                    var newPchave = QueryStringInUrl(hashValue,'pchave');
                    hashValue = hashValue.replace('pchave','_p');
                    hashValue = hashValue + '&pchave=' + newPchave;
                }

                ParseUrl(hashValue);

                OcultarDivsGerenciar();
                ExibirDivMenu('PainelCarregando');
                EnviarPedido(hashValue, TratarDados, '', 'GET', false);
            }
        }
        else
        {
            if (document.getElementById('ctl00_hiddenTipoPagina') != null)
            {
                if (document.getElementById('ctl00_hiddenTipoPagina').value == 'home')
                    MontaMenu(EnumMenu.Home);
                else if (document.getElementById('ctl00_hiddenTipoPagina').value == 'cookie_hom')
                    MontaMenu(EnumMenu.Home,false,true);
                else if (document.getElementById('ctl00_hiddenTipoPagina').value == 'cookie_pub')
                    MontaMenu(EnumMenu.Publicidade,false,true);
                else if (document.getElementById('ctl00_hiddenTipoPagina').value == 'cookie_edi')
                    MontaMenu(EnumMenu.Editorial,false,true);
                else if (document.getElementById('ctl00_hiddenTipoPagina').value == 'cookie_cen')
                    MontaMenu(EnumMenu.Cenas,false,true);
                else if (document.getElementById('ctl00_hiddenTipoPagina').value == 'cookie_cds')
                    MontaMenu(EnumMenu.Cd,false,true);
                else if (document.getElementById('ctl00_hiddenTipoPagina').value == 'cookie_dam')
                    MontaMenu(EnumMenu.Dam,false,true);
                else if (document.getElementById('ctl00_hiddenTipoPagina').value == 'cddwn')
                {
                    MontaMenu(EnumMenu.Cd);
                    OcultarDivsGerenciar();
                    document.getElementById('ConteudoDaPagina').style.display = 'block';
                    document.getElementById('PainelBottom').style.display = 'none';
                    document.getElementById('pesquisa').style.border = 'none';
                }
                else
                {
                    MontaMenu(EnumMenu.Home);
                    OcultarDivsGerenciar();
                    document.getElementById('ConteudoDaPagina').style.display = 'block';
                    document.getElementById('PainelBottom').style.display = 'none';
                    document.getElementById('pesquisa').style.border = 'none';
                }
            }        
        }
    }
}

function InitializeTimer()
{
    // Set the length of the timer, in seconds
    //    secs = 1;
    //    StopTheClock();
    //    StartTheTimer();

    //    intervalo = window.setInterval("RequisitaThumbsVisiveis()", 500);
}

function IniciaLoop()
{
    //    intervalo = window.setInterval("RequisitaThumbsVisiveis()", 500);
}

