﻿   
    
 /****************************************************************************
 ** NOME: CheckSelected                                                    **
 ** AUTOR: Filipe Peixinho (Maio 2006)                                     **
 ** DESCRIÇÃO: Liga ou desliga todos os checkboxes com o nome "nomeFilhos" **
 **            ao clicar no checkbox "nomePai"                             **
 ****************************************************************************/
function CheckSelected( nomeFilhos )
{ 
  var frm=theForm;
  var existem = false;
  for(i=0;i< frm.length;i++)
  {
    e=frm.elements[i];

    if ( (e.type=='checkbox' || e.type=='radio') && e.name.indexOf(nomeFilhos) != -1 && e.checked)
    {
      existem = true;
    }
  }
  return existem;
}
/****************************************************************************
 ** NOME: CheckAll                                                         **
 ** AUTOR: Filipe Peixinho (Maio 2006)                                     **
 ** DESCRIÇÃO: Liga ou desliga todos os checkboxes com o nome "nomeFilhos" **
 **            ao clicar no checkbox "nomePai"                             **
 ****************************************************************************/
function CheckAll( nomePai, nomeFilhos )
{
  var frm=theForm;
  var actVar = nomePai.checked ;
  
  for(i=0;i< frm.length;i++)
  {
    e=frm.elements[i];
    if ( e.type=='checkbox' && e.name.indexOf(nomeFilhos) != -1 )
      e.checked= actVar ;
  }
}

/****************************************************************************
 ** NOME: UnCheck                                                          **
 ** AUTOR: Filipe Peixinho (Maio 2006)                                     **
 ** DESCRIÇÃO: Desliga a chekbox que selecciona todos (nomePai) quando se  **
 **            clica numa checkbox filha                                   **
 ****************************************************************************/
function UnCheck(nomePai)
{
  var frm=theForm;

  for(i=0;i< frm.length;i++)
  {
    e=frm.elements[i];
    if ( e.type=='checkbox' && e.name.indexOf(nomePai) != -1 )
    {
      e.checked= false ;
      break;
    }
  }
}

/****************************************************************************
 ** NOME: highlightbg                                                      **
 ** AUTOR: Filipe Peixinho (Maio 2006)                                     **
 ** DESCRIÇÃO: Muda o background do objecto "o" para a cor "cor"           **
 ****************************************************************************/
 function MudaBackground(o,cor)
 { 
     o.style.backgroundColor=cor;
     return;
 } 

/****************************************************************************
 ** NOME: closeSpan                                                        **
 ** AUTOR: Filipe Peixinho (Maio 2006)                                     **
 ** DESCRIÇÃO: Fecha um span                                               **
 ****************************************************************************/
function closeSpan(tabID)
{
	o=document.getElementById(tabID);	
	o.style.display="none";
	return false;
}

/****************************************************************************
 ** NOME: openSpan                                                         **
 ** AUTOR: Filipe Peixinho (Maio 2006)                                     **
 ** DESCRIÇÃO: Abre um span                                                **
 ****************************************************************************/
function openSpan(tabID)
{
	var o=document.getElementById(tabID);
	o.style.display="block";
	return false;
}
function switchSpan(tabID)
{
    var o = document.getElementById(tabID);
    
    if ((o.style.display == 'none') || (o.style.display == ''))
    {
        openSpan(tabID); 
    }
    else
    {
        closeSpan(tabID);
    }
}

/****************************************************************************
 ** NOME: MudaEstadoMenu                                                   **
 ** AUTOR: Filipe Peixinho (Maio 2006)                                     **
 ** DESCRIÇÃO: Gere o icon nos menus que indica se o menu está aberto ou   **
 **            fechado.                                                    **
 ****************************************************************************/
function MudaEstadoMenu(menuid,Topo)
{
    o = document.getElementById(menuid);
    
    if ((o.style.display == 'none') || (o.style.display == ''))
    {        
        o.style.display = 'block';
        Topo.style.backgroundImage="url('imagens/menos_menu.gif')";
        SetMenuCookie(menuid,1);
    }
    else
    {
        o.style.display = 'none';
        Topo.style.backgroundImage="url('imagens/mais_menu.gif')";
        SetMenuCookie(menuid,0);
    }
}

/****************************************************************************
 ** NOME: SetMenuCookie                                                    **
 ** AUTOR: Filipe Peixinho (Maio 2006)                                     **
 ** DESCRIÇÃO: Grava num cookie o estado do menu (aberto ou fechado)       **
 ****************************************************************************/
function SetMenuCookie(menuid,status)
{
    date = new Date();
    document.cookie = menuid + "=" + (status==1 ? "block" : "none") + "; expires=Fri, 31 Dec 2100 23:59:59 GMT;";
}

/****************************************************************************
 ** NOME: GetMenuCookie                                                    **
 ** AUTOR: Filipe Peixinho (Maio 2006)                                     **
 ** DESCRIÇÃO: Lê o estado do menu que foi previamente gravado num cookie  **
 **            usando a função SetMenuCookie                               **
 ****************************************************************************/
function GetMenuCookie(menuid)
{
    var aCookie = document.cookie.split("; ");
    for (var i=0; i < aCookie.length; i++)
    {
        var aValores = aCookie[i].split("=");
        if (menuid == aValores[0]) 
            return unescape(aValores[1]);
    }
    return null;
}