var clsOut, 
    clsOver;

function initPage(classOut, classOver)
/*
  Objectif : Initialiser les menus afin d'en assurer la fonctionnalité.

  PARAMÈTRES : classOut : classe de style à appliquer aux objets TR lorsqu'ils sont hors sélection.
               classOver : classe de style à appliquer aux objets TR lorsqu'ils sont sélectionnés.
               cellSpace : espacement entre les lignes des tableaux des menus (valeur par défaut : 2).
*/
{
  clsOut = classOut;
  clsOver = classOver;
  initTRs();
}

function aTraiter(obj, filtre)
{
  if(obj.id == null)
	obj.id = "";
  if(filtre == null)
    filtre = "";
  retour = obj != null;
  if(filtre != null)
  	retour = retour && obj.id.substr(0, filtre.length) == filtre;
  return retour;
}

function traiterCollection(coll, filtre, fct)
{
  var i = 0, n = coll.length;
  for (; i < n; ++i)
    if (aTraiter(coll[i], filtre))
      fct(coll[i]);
}

function initTRs()
{
    traiterCollection(document.getElementsByTagName("TR"), "a_", initElem);
    traiterCollection(document.getElementsByTagName("TR"), "tr_", initTR);
}

function initImg(p)
{
  if (p.title && p.title != "")
    p.m_Remp = p.title;
  p.title = "";
}

function initTR(p)
{
	p.onmouseover = p.onmouseout = changerElem;
	p.m_Selected = false;
}

function initElem(p)
{
  initTR(p);
  p.onclick = chargerDoc;
  var i = p.title.indexOf(";");
  p.m_Cible = p.title.substr(0, i);
  p.m_EstTexte = p.title.substr(i + 1, 1) == "1";
  p.m_Lien = p.title.substr(i + 3, p.title.length - i - 3);
  p.title = p.m_Lien;
  p.className = clsOut;
  var imgs = p.getElementsByTagName("IMG");
  var i = 0, n = imgs.length, puce = false, fleche = false, stop = false;
  while (!stop && i < n)
  {
    puce = imgs[i].id.substr(0, 5) == "puce_";
    if (puce)
    {
      p.m_Puce = imgs[i].id;
      initImg(imgs[i]);
    }
    fleche = imgs[i].id.substr(0, 7) == "fleche_";
    if (fleche)
      imgs[i].style.visibility = "hidden";
    i++;
  }
  p.title = "";
}

function changerElem()
{
  if (this.m_Selected)
  {
    this.className = clsOut;
  }
  else
  {
    this.className = clsOver;
  }
  this.m_Selected = !this.m_Selected;
  changerPuce(this);
}

function changerPuce(tr)
{
  var img = document.getElementById(tr.m_Puce);
  if (img)
  {
    var temp = img.src;
    img.src = img.m_Remp;
    img.m_Remp = temp;
  }
}

function chargerDoc()
{
  
  if (this.m_EstTexte)
  { 

    switch (this.m_Cible)
    {
    case "_self" :
      location.href = location.pathname + "?txt=" + this.m_Lien;
      break;
    case "_blank" :
      if (!window['fen_' + this.id])
        window['fen_' + this.id] = f_open_window_max(this.m_Lien, null);
        //window['fen_' + this.id].moveTo(0,0);                                                           
    	//window['fen_' + this.id].resizeTo(screen.availWidth,screen.availHeight);
      else
        try
        { 
          window['fen_' + this.id].focus();
        }
        catch(err)
        {
          window['fen_' + this.id] = f_open_window_max(this.m_Lien, null);
        } 
      break;
    case "_top" :
      location.href = "AfficherTxt.php?txt=" + this.m_Lien;
      break;
    }
  }
  else
  {
    switch (this.m_Cible)
    {
    case "_self" :
      location.href = location.pathname + "?doc=" + this.m_Lien;
      break;
    case "_blank" :
      if (!window['fen_' + this.id])
        window['fen_' + this.id] =f_open_window_max(this.m_Lien, null);
      else
        try
        {
          window['fen_' + this.id].focus();
        }
        catch(err)
        {
          window['fen_' + this.id] = f_open_window_max(this.m_Lien, null);
        }
      break;
    case "_top" :
      location.href = this.m_Lien;
      break;
    }
  }
}
function f_open_window_max( aURL, aWinName )
{
   var wOpen;
   var sOptions;

   sOptions = 'status=yes,menubar=yes,scrollbars=yes,resizable=yes,toolbar=yes';
   sOptions = sOptions + ',width=' + (screen.availWidth - 10).toString();
   sOptions = sOptions + ',height=' + (screen.availHeight - 122).toString();
   sOptions = sOptions + ',screenX=0,screenY=0,left=0,top=0';

   wOpen = window.open( '', aWinName, sOptions );
   wOpen.location = aURL;
   wOpen.focus();
   wOpen.moveTo( 0, 0 );
   wOpen.resizeTo( screen.availWidth, screen.availHeight );
   return wOpen;
}