var lar;
var alt;
var cor1;
var tmp_expira;
var ctrl_tempo;
cor1 = '';

// Função Menu
function callAllLoaders() {
    var i, loaderFunc;
    for (i = 0; i < _4.length; i++) {
        loaderFunc = _4[i];
        if (loaderFunc != callAllLoaders) {
            loaderFunc();
        }
    }
} 

function menuSelec(obj) {
    document.getElementById(obj).style.background = '#222222 no-repeat right url(/imagens/seta_escolha.gif)';
    document.getElementById(obj).style.color = '#ff9900';
}

function menuNormal(obj) {
    document.getElementById(obj).style.background = 'transparent';
    document.getElementById(obj).style.color = '#ffffff';    
}

function troca() 
{
    if (cor1 == '') {
        cor1 = document.getElementById(lblbasedados).style.color;
    }    
    if (document.getElementById(lblbasedados).style.color == cor1) {
        document.getElementById(lblbasedados).style.color = 'White';
        document.getElementById(lblbasedados).style.backgroundColor = cor1;
    }
    else {
        document.getElementById(lblbasedados).style.color = cor1;
        document.getElementById(lblbasedados).style.backgroundColor = 'White';
    }
    setTimeout('troca()',800)  	      
}  

function divfundo()
{
    if ( ( (document.getElementById(div_modal).style.display != "none") && 
           (document.getElementById(div_modal).style.display != "")    
         )         || 
         ( (document.getElementById("div_pesquisa").style.display != "none") && 
           (document.getElementById("div_pesquisa").style.display != "")
         )         ||
         ( (div_janela_especifica) && 
           (document.getElementById(div_janela_especifica).style.display != "none") && 
           (document.getElementById(div_janela_especifica).style.display != "")
         )         ||
         ( (document.getElementById("div_tempo").style.display != "none") && 
           (document.getElementById("div_tempo").style.display != "")
         )         
       ) 
    {
        document.getElementById("div_fundo").style.display = 'block';
        if (document.getElementById(div_menu) != null)
            document.getElementById(div_menu).style.zIndex = '2';
    } 
    else 
    {
        document.getElementById("div_fundo").style.display = 'none';      
        if (document.getElementById(div_menu) != null)
            document.getElementById(div_menu).style.zIndex = '298';
    }
}

function atualiza() 
{
    if (document.documentElement && document.documentElement.clientWidth)
    { 
        lar = document.documentElement.clientWidth; 
        alt = document.documentElement.clientHeight;
    }
    else if(window.innerWidth)
    { 
        lar = window.innerWidth; 
        alt = window.innerHeight; 
    }
    else if(document.body.clientWidth)
    { 
        lar = document.body.clientWidth; 
        alt = document.body.clientHeight; 
    }      
       
    width = document.getElementById(div_modal).style.width.replace("px","").replace("%","");        
    height = document.getElementById(div_modal).style.height.replace("px","").replace("%","");                
    document.getElementById(div_modal).style.left = ((lar-width)/2)+'px';        
    document.getElementById(div_modal).style.top = ((alt-height)/2)+'px';                
    
    width = document.getElementById("div_tempo").style.width.replace("px","").replace("%","");        
    height = document.getElementById("div_tempo").style.height.replace("px","").replace("%","");                
    document.getElementById("div_tempo").style.left = ((lar-width)/2)+'px';        
    document.getElementById("div_tempo").style.top = ((alt-height)/2)+'px';    
    
    width = document.getElementById("div_pesquisa").style.width.replace("px","").replace("%","");                
    height = document.getElementById("div_pesquisa").style.height.replace("px","").replace("%","");                        
    document.getElementById("div_pesquisa").style.left = ((lar-width)/2)+'px';
    document.getElementById("div_pesquisa").style.top = ((alt-height)/2)+'px';
           
    if (div_janela_especifica) 
    {                             
        width = document.getElementById(div_janela_especifica).style.width.replace("px","").replace("%","");
        height = document.getElementById(div_janela_especifica).style.height.replace("px","").replace("%","");
        document.getElementById(div_janela_especifica).style.left = ((lar-width)/2)+'px';
        document.getElementById(div_janela_especifica).style.top = ((alt-height)/2)+'px';
        if (document.getElementById(divjanelaespecifica).value == "1") {
            if (document.getElementById(divpesquisa).value == "1") {                
                document.getElementById(div_janela_especifica).style.zIndex = '298'; /*Z-INDEX do div_fundo menos 1*/                
            } else {                
                document.getElementById(div_janela_especifica).style.zIndex = '300'; /*Z-INDEX do div_fundo mais 1*/
            }
                          
            document.getElementById(div_janela_especifica).style.display = 'block';
        } else 
            document.getElementById(div_janela_especifica).style.display = 'none';                  
    }

    document.getElementById('div_fundo').style.width = lar+'px';
    document.getElementById('div_fundo').style.height = alt+'px';
    
    verificaMsgUsuario();   
    
    if (document.getElementById(divpesquisa).value == "1") {
        document.getElementById("div_pesquisa").style.display = 'block';
    } else {
        document.getElementById("div_pesquisa").style.display = 'none';
    }
        
    if (document.getElementById(MsgModalControl).value == "1") {        
        document.getElementById(div_modal).style.display = 'block';      
    } else {
        document.getElementById(div_modal).style.display = 'none';
    }   
           
    divfundo();   
    
    // Limpa input hidden para não ir para o menu anterior - Claudio 20/05/2010
    var MeuForm = document.forms['aspnetForm'];
    if (!MeuForm) {
        MeuForm = document.aspnetForm;
    }
    MeuForm.__EVENTTARGET.value = '';
    MeuForm.__EVENTARGUMENT.value = '';
    
    window.onresize = atualiza;  
}
 
function fecharPesquisa()
{
    document.getElementById(divpesquisa).value = "0";
    atualiza();
} 
          
function concluirPesquisa(linhaPesquisa)
{
    fecharPesquisa();
    __doPostBack("frmPesquisa", "acao=concluirConsulta;" + linhaPesquisa);
}

function IniciaTempoExpira() {    
    // Codigo para calcular tempo restante
    // Só roda 1 vez na inicialização    
    if (document.getElementById(show_expira).value != "0") {
        dt1 = new Date();
        tmp_expira = (dt1.getTime()/1000) + Number(document.getElementById(t_expira).value);
        tempo_func();       
    }
}

function tempo_func () {
    dt2 = new Date();
    str = "Sua sessão irá expirar em ";
    tmp_rest = Math.round(tmp_expira-(dt2.getTime()/1000));
    // Maior que 5 minutos (Tempo deve ser menor q a metade da sessão)
    if (tmp_rest > 300) {
        document.getElementById("div_tempo").style.display = 'none';
        document.getElementById("div_fundo").style.zIndex = '299'; /*Z-INDEX padrão do div_fundo*/       
        setTimeout("tempo_func()",10000);
        ctrl_tempo = 1;
    } else if (tmp_rest > 0) {
        if (tmp_rest > 60) {
            document.getElementById("m_expira").value = str + Math.ceil(tmp_rest/60) + " min";            
            tmp = 10000;
        } else {
            document.getElementById("m_expira").value = str + Math.ceil(tmp_rest) + " seg";                
            tmp = 1000;
        }
        document.getElementById("div_tempo").style.display = 'block'; 
        document.getElementById("div_fundo").style.zIndex = '301'; /*Z-INDEX padrão do div_fundo mais 2*/
        setTimeout("tempo_func()",tmp);
        ctrl_tempo = 1;        
    // Expirado (teoricamente pois pode ter sido aberta outra janela)
    } else {    
        document.getElementById("m_expira").value = "Sua sessão pode ter expirado";
        document.getElementById("div_tempo").style.display = 'block';
        document.getElementById("div_fundo").style.zIndex = '301'; /*Z-INDEX padrão do div_fundo mais 2*/        
        ctrl_tempo = 0;        
    }
    divfundo();    
}