﻿/* Parte das notícias */

function MudarFundo(href) {
    //var div = document.getElementById(href.id + "div");
    //div.style.backgroundColor = "#B22222";
    //href.style.color = "black";
}

function MudarFundoBack(href) {
    //var div = document.getElementById(href.id + "div");
    //div.style.backgroundColor = "white";
    //href.style.color = "#B22222";
}

// initial position 
var dn_startpos = 190;
// end position
var dn_endpos = 0;
// Speed of scroller higher number = slower scroller 
var dn_speed = 30;
// ID of the news box
var dn_newsID = 'ctl00_ContentPlaceHolderConteudo_NoticiasDestaqueControl_news';
// class to add when JS is available
var dn_classAdd = 'hasJS';
// ID of the generated paragraph
var dn_paraID = 'DOMnewsstopper';
var dn_interval = 0;

/* Initialise scroller when window loads */
window.onload = function() {
    // check for DOM
    if (!document.getElementById || !document.createTextNode) { return; }
    if( document.getElementById(dn_newsID) == null ){ return; }
    var n1 = document.getElementById(dn_newsID).getElementsByTagName('li').length;
    dn_endpos = -n1 * 170;
    initDOMnews();
    dn_interval = setInterval('scrollDOMnews()', dn_speed);
    // add more functions as needed
    dn_interval_calend = setInterval('RodarCalendario()', dn_speed_calendario);
}
/* stop scroller when window is closed */
window.onunload = function() {
    clearInterval(dn_interval);
    clearInterval(dn_interval_calend);
}

/*
This is the functional bit, do not press any buttons or flick any switches
without knowing what you are doing!
*/

var dn_scrollpos = dn_startpos;
/* Initialise scroller */
function initDOMnews() {
    var n = document.getElementById(dn_newsID);
    
    if (!n) { return; }    
   
    n.onmouseover = function() {
        clearInterval(dn_interval);
    }
    n.onmouseout = function() {
        dn_interval = setInterval('scrollDOMnews()', dn_speed);
    }
}

function stopDOMnews() {
    alert("stop");
    clearInterval(dn_interval);
    var n = document.getElementById(dn_newsID);
    n.className = '';
    n.parentNode.removeChild(n.nextSibling);
    return false;
}
function scrollDOMnews() {
    var n = document.getElementById(dn_newsID).getElementsByTagName('ul')[0];
    n.style.top = dn_scrollpos + 'px';
    if (dn_scrollpos == dn_endpos) { dn_scrollpos = dn_startpos; }
    dn_scrollpos--;
}

/* Parte Calendário da HomePage */

var nomeControloPai = "ctl00_ContentPlaceHolderConteudo_Calend_";
var dn_speed_calendario = 3500;
var indice_inicial = 1;
var dn_interval_calend = 0;
var maxDias = 0;

function CalcularDiasMaximos(){
    if( maxDias != 0 )
        return maxDias;
    var flag = true;
    var i=1;
    do
    {
        var d = document.getElementById(nomeControloPai + "CalendarioDiaSpan" + i );
        if( d == null ){
            maxDias = i-1;
            flag = false;            
        }
        ++i;
    }while( flag );    
    return maxDias;
}

function MudarFundoCalendario(href, idx) {    
    // desactivar o rodar automatico
    clearInterval(dn_interval_calend);
    // desactivar o antigo
    var indice_anterior = indice_inicial - 1;
    if (indice_inicial == 1) {
        indice_anterior = CalcularDiasMaximos();
    }   
    MostrarTodosDias(); 
    var n = document.getElementById(nomeControloPai + "CalendarioDiaDetalheDiv" + indice_anterior);
    var d = document.getElementById(nomeControloPai + "CalendarioDiaSpan" + indice_anterior );    
    if( d != null ){
         d.style.backgroundColor = "#231E1E";
         d.style.color = "#AF0002";
    }
    if( n != null ){        
        n.style.display = "none";    
        n.style.visibility = "hidden";        
    }
    //
    href.style.backgroundColor = "white";
    href.style.color = "#AF0002";
    var n1 = document.getElementById( nomeControloPai + "CalendarioDiaDetalheDiv" + idx);
    n1.style.display = "block";
    n1.style.visibility = "visible";    
}

function MudarFundoCalendarioBack(href) {
    /*href.style.backgroundColor = "#231E1E";
    href.style.color = "#AF0002";*/
    EsconderDetalheDia();
    // reactivar o rodar automatico
    dn_interval_calend = setInterval('RodarCalendario()', dn_speed_calendario);
}

function RodarCalendario() {
    EsconderDetalheDia();
    var n = document.getElementById(nomeControloPai + "CalendarioDiaDetalheDiv" + indice_inicial);
    var d = document.getElementById(nomeControloPai + "CalendarioDiaSpan" + indice_inicial);
    if( d != null )
    { 
        d.style.backgroundColor = "white";
        d.style.color = "#AF0002";
    }
    if( n != null ){
        n.style.display = "block";
        n.style.visibility = "visible";
    }
    
    // apaga background color do anterior
    if (indice_inicial == 1) {
        var d_old = document.getElementById(nomeControloPai + "CalendarioDiaSpan" + CalcularDiasMaximos() );
        if(d_old != null){
         d_old.style.backgroundColor = "#231E1E";
         d_old.style.color = "#AF0002";
        }
    }
    else {
        var d_old = document.getElementById(nomeControloPai + "CalendarioDiaSpan" + (indice_inicial - 1));
        if(d_old != null){
         d_old.style.backgroundColor = "#231E1E";
         d_old.style.color = "#AF0002";
         }
    }
    // avançar para o proximo
    indice_inicial = indice_inicial + 1;
    if (indice_inicial == CalcularDiasMaximos() + 1)
        indice_inicial = 1;
}

function MostrarTodosDias()
{
    var d1 = document.getElementById(nomeControloPai + "CalendarioDiaSpan1");
    if( d1 != null )
    {
        d1.style.backgroundColor = "#231E1E";
        d1.style.color = "#AF0002";
    }
    var d2 = document.getElementById(nomeControloPai + "CalendarioDiaSpan2");
    if( d2 != null )
    {
        d2.style.backgroundColor = "#231E1E";
        d2.style.color = "#AF0002";
    }
    var d3 = document.getElementById(nomeControloPai + "CalendarioDiaSpan3");
    if( d3 != null )
    {
        d3.style.backgroundColor = "#231E1E";
        d3.style.color = "#AF0002";
    }
    var d4 = document.getElementById(nomeControloPai + "CalendarioDiaSpan4");
    if( d4 != null )
    {
        d4.style.backgroundColor = "#231E1E";
        d4.style.color = "#AF0002";
    }
    var d5 = document.getElementById(nomeControloPai + "CalendarioDiaSpan5");
    if( d5 != null )
    {
        d5.style.backgroundColor = "#231E1E";
        d5.style.color = "#AF0002";
    }
    var d6 = document.getElementById(nomeControloPai + "CalendarioDiaSpan6");
    if( d6 != null )
    {
        d6.style.backgroundColor = "#231E1E";
        d6.style.color = "#AF0002";
    }
    var d7 = document.getElementById(nomeControloPai + "CalendarioDiaSpan7");
    if( d7 != null )
    {
        d7.style.backgroundColor = "#231E1E";
        d7.style.color = "#AF0002";
    }
}

function EsconderDetalheDia() 
{
    MostrarTodosDias();
    var n1 = document.getElementById(nomeControloPai + "CalendarioDiaDetalheDiv1");
    if( n1 != null )
    {
    n1.style.display = "none";
    n1.style.visibility = "hidden";
    }    
    var n2 = document.getElementById(nomeControloPai + "CalendarioDiaDetalheDiv2");
    if( n2 != null )
    {
    n2.style.display = "none";
    n2.style.visibility = "hidden";
    }    
    var n3 = document.getElementById(nomeControloPai + "CalendarioDiaDetalheDiv3");
    if( n3 != null )
    {
    n3.style.display = "none";
    n3.style.visibility = "hidden"; 
    }    
    var n4 = document.getElementById(nomeControloPai + "CalendarioDiaDetalheDiv4");
    if( n4 != null )
    {
    n4.style.display = "none";
    n4.style.visibility = "hidden";
    }       
    var n5 = document.getElementById(nomeControloPai + "CalendarioDiaDetalheDiv5");
    if( n5 != null )
    {
    n5.style.display = "none";
    n5.style.visibility = "hidden";
    }
    
    var n6 = document.getElementById(nomeControloPai + "CalendarioDiaDetalheDiv6");
    if( n6 != null )
    {
    n6.style.display = "none";
    n6.style.visibility = "hidden";
    }
    
    var n7 = document.getElementById(nomeControloPai + "CalendarioDiaDetalheDiv7");
    if( n7 != null )
    {
    n7.style.display = "none";
    n7.style.visibility = "hidden";
    }       
}