// -------------------------------------------------------------------------
//  Générateur de page
//  PREFIXE : pger1
// -------------------------------------------------------------------------

// -------------------------------------------------------------------------
//  Inversion image +/-, affiche/masque detail rubrique
// -------------------------------------------------------------------------
//  [IN] pstrRowID  : ID de la ligne a afficher/masquer
//  [IN] pstrSwapID : ID image +/-
//  [IN] pstrExpandSaveID : ID de mémorisation attribut affichage/masquage
// -------------------------------------------------------------------------

function shr_pger0_SwapDsp(pstrRowID, pstrSwapID, pstrExpandSaveID)
{
 var lobjRow;
 var lstrExpandState;

 // Objet ligne
 lobjRow = shr_tool0_GetElementByID(pstrRowID);

 // Objet ligne non defini !
 if (lobjRow)
   {
    // Affichage/Masquage ligne
    if (lobjRow.className == 'cssFDisplayNone')
      {
       lstrExpandState = 'O';
       lobjRow.className = 'cssFDisplayBlock';
      }
    else
      {
       lstrExpandState = 'N';
       lobjRow.className = 'cssFDisplayNone';
      }

    // Changement d'image +/-
    if (lobjRow.className == 'cssFDisplayNone')
      { shr_pger0_SetSwapPicture(pstrSwapID, '+'); }
    else
      { shr_pger0_SetSwapPicture(pstrSwapID, '-'); }

    // Redimensionnement de la barre laterale gauche
    shr_balg0_SetLeftBarHeight();

    // Memoriser l'etat
    if (pstrExpandSaveID != '')
      { shr_rqst0_SendData(shr_pger0_gstrURLPagerHandler,'pstrHandler=Expand&pstrExpandSaveID=' + pstrExpandSaveID + '&pstrExpandState=' + lstrExpandState); }
   }
 }


// -------------------------------------------------------------------------
//  Inversion image +/-, affiche/masque detail rubrique
// -------------------------------------------------------------------------
//  [IN] pstrSwapID  : Identifiant image +/-
//  [IN] pstrSens  : + ou -
// -------------------------------------------------------------------------

function shr_pger0_SetSwapPicture(pstrSwapID, pstrSens)
{
 var lobjSwap = shr_tool0_GetElementByID(pstrSwapID);
 var lstrSrcImage='';

 if (lobjSwap == null)
   { return; }

 if (pstrSens == '+')
   {
    lstrSrcImage = lobjSwap.getAttribute('_strPlus');

    // Image specifique ou standard
    if (lstrSrcImage == null)
      { lobjSwap.src = tool0_gstrImageExtandPlus; }
    else
      { lobjSwap.src = lstrSrcImage; }
   }
 else
   {
    lstrSrcImage = lobjSwap.getAttribute('_strMinus');

    // Image specifique ou standard
    if (lstrSrcImage == null)
      { lobjSwap.src = tool0_gstrImageExtandMinus; }
    else
      { lobjSwap.src = lstrSrcImage; }
   }
}


// -------------------------------------------------------------------------
//  Applique une nouvelle couleur de fond aux cellules d'une ligne
// -------------------------------------------------------------------------
//  [IN] pobjRow : Objet ligne (tr)
// -------------------------------------------------------------------------

function shr_pger0_SetBgColor(pobjRow)
{
 if (pobjRow == null)
   { return; }

 // Cellules row
 var lobjCells = pobjRow.cells;

 // Applique la nouvelle couleur
 for (var lintI=0 ; lintI<lobjCells.length ; lintI++)
    {
     var lstrInnerHTML = lobjCells[lintI].innerHTML;

     // Pas de changement de couleur si la cellule contient
     // une image jpg (donc sans gestion de la transparence)
     if (lstrInnerHTML.search(/<img.*src=".*\.jpg".*>/i) == -1)
       { lobjCells[lintI].style.backgroundColor = shr_pger0_gstrColorHighlight; }
    }
}


// -------------------------------------------------------------------------
//  Restore la couleur initiale des cellules d'une ligne
// -------------------------------------------------------------------------
//  [IN] pobjRow : Objet ligne (tr)
// -------------------------------------------------------------------------

function shr_pger0_ResBgColor(pobjRow)
{
 if (pobjRow == null)
   { return; }

 // Cellules row
 var lobjCells = pobjRow.cells;

 // Restore la couleur initiale
 for (var lintI=0 ; lintI<lobjCells.length ; lintI++)
    { lobjCells[lintI].style.backgroundColor = ''; }
}


// -------------------------------------------------------------------------
//  Mémoriser l'état de l'attribut Expand
// -------------------------------------------------------------------------

function shr_pger0_SaveStateAll()
{
 var lstrState = '';
 var lobjRow;

 // Pas de memorisation a effectuer
 if (typeof shr_pger0_gstrExpandKey == 'undefined')
   { return; }

 // Liste des pagers pour lesquels la memorisation doit etre effectuee
 var ltstrExpandKey = shr_pger0_gstrExpandKey.split(',');

 // Pour chaque identifiant pager
 for (var lintI=0,lintIMax=ltstrExpandKey.length ; lintI<lintIMax ; lintI++)
    {
     if (lstrState != '')
       { lstrState += '; '; }

     lstrState += ltstrExpandKey[lintI] + '%';

     // L'etat de l'attribut expand est determine par le nom de la classe
     // cssFDisplayNone = Etat masqué
     // cssFDisplayBlock = Etat affiché
     for (var lintJ=0 ; ; lintJ++)
        {
         // Plus de ligne
         if (shr_tool0_GetElementByID('SHR_PGER0_TBODY'+ltstrExpandKey[lintI]+lintJ) == null)
           { break; }

         lobjRow = shr_tool0_GetElementByID('SHR_PGER0_ROW'+ltstrExpandKey[lintI]+lintJ);

         // Creation d'une liste des etats de l'attribut expand
         if (  (lobjRow == null)
             ||(lobjRow.className == 'cssFDisplayNone') )
           { lstrState += 'N'; }
         else
           { lstrState += 'O'; }
        }
    }

 // Memoriser dans un cookie
 shr_tool0_gclsCookies.SetCookie('shr_pger0_ExpandState',lstrState,0);
 shr_tool0_gclsCookies.SetCookie('shr_pger0_ExpandCheck',document.URL,0);
}


// -------------------------------------------------------------------------
//  Restaurer l'état de l'attribut Expand
// -------------------------------------------------------------------------

function shr_pger0_Init()
{
 var ltstrExpandKey;
 var lstrAllState;
 var ltstrAllState;
 var lstrState;
 var ltstrState;
 var lstrExpandCheck;
 var lobjRow;

 // Pas de memorisation a restaurer
 if (typeof shr_pger0_gstrExpandKey == 'undefined')
   { return; }

 lstrExpandCheck = shr_tool0_gclsCookies.GetCookie('shr_pger0_ExpandCheck');

 // URL differentes
 if (  (lstrExpandCheck == null)
     ||(lstrExpandCheck != document.URL) )
   { return; }

 // Liste des pagers pour lesquels la restauration doit etre effectuee
 ltstrExpandKey = shr_pger0_gstrExpandKey.split(',');

 lstrAllState = shr_tool0_gclsCookies.GetCookie('shr_pger0_ExpandState');

 // Aucune memorisation presente
 if (lstrAllState == null)
   { return; }

 ltstrAllState = lstrAllState.split('; ');

 // Pour chaque identifiant pager
 for (var lintI=0,lintIMax=ltstrExpandKey.length ; lintI<lintIMax ; lintI++)
    {
     lstrState = '';

     // Extrait memorisation pour le pager courant
     for (var lintJ=0,lintJMax=ltstrAllState.length ; lintJ<lintJMax ; lintJ++)
        {
         ltstrState = ltstrAllState[lintJ].split('%');

         if (ltstrState[0] == ltstrExpandKey[lintI])
           { lstrState = ltstrState[1]; }
        }

     if (lstrState == '')
       { continue; }

     // Pour chaque ligne de tableau
     for (var lintJ=0,lintJMax=lstrState.length ; lintJ<lintJMax ; lintJ++)
        {
         lobjRow = shr_tool0_GetElementByID('SHR_PGER0_ROW'+ltstrExpandKey[lintI]+lintJ);

         // Restaurer l'etat de l'attribut expand
         if (lstrState.substring(lintJ,lintJ+1) == 'O')
           {
            // Affichage portion de ligne
            if (lobjRow != null)
               { lobjRow.className = 'cssFDisplayBlock'; }

            // Changement d'image
            shr_pger0_SetSwapPicture('SHR_PGER0_SWAP'+ltstrExpandKey[lintI]+lintJ, '-');
           }
         else
           {
            // Masque portion de ligne
            if (lobjRow != null)
               { lobjRow.className = 'cssFDisplayNone'; }

            // Changement d'image
            shr_pger0_SetSwapPicture('SHR_PGER0_SWAP'+ltstrExpandKey[lintI]+lintJ, '+');
           }
        }
    }

 // Redimensionnement de la barre laterale gauche
 shr_balg0_SetLeftBarHeight();
}


// -------------------------------------------------------------------------
//  Modifier globalement l'attribut expand des ligne
// -------------------------------------------------------------------------
//  [IN] pstrExpandKey : Identifiant pager
// -------------------------------------------------------------------------

function shr_pger0_ExpandAll(pstrExpandKey)
{
 var lobjTBody;
 var lobjRow;

 // Action initiale suivant etat de l'attribut expand de la premiere ligne
 if (typeof shr_pger0_gblnExpandAll == 'undefined')
   {
    lobjRow = shr_tool0_GetElementByID('SHR_PGER0_ROW'+pstrExpandKey+'0');

    // Affichage/Masquage ligne
    if (  (lobjRow == null)
        ||(lobjRow.className == 'cssFDisplayNone') )
      { shr_pger0_gblnExpandAll = false; }
    else
      { shr_pger0_gblnExpandAll = true; }
   }

 shr_pger0_gblnExpandAll = !shr_pger0_gblnExpandAll;

 // Pour chaque ligne de tableau
 for (var lintI=0 ; ; lintI++)
    {
     // Plus de ligne
     if (shr_tool0_GetElementByID('SHR_PGER0_TBODY'+pstrExpandKey+lintI) == null)
       { break; }

     // Image +/-
     if (shr_pger0_gblnExpandAll)
       { shr_pger0_SetSwapPicture('SHR_PGER0_SWAP'+pstrExpandKey+lintI, '-'); }
     else
       { shr_pger0_SetSwapPicture('SHR_PGER0_SWAP'+pstrExpandKey+lintI, '+'); }

     // Portion de ligne a afficher/masquer
     lobjRow = shr_tool0_GetElementByID('SHR_PGER0_ROW'+pstrExpandKey+lintI);

     if (lobjRow != null)
       {
        if (shr_pger0_gblnExpandAll)
          { lobjRow.className = 'cssFDisplayBlock'; }
        else
          { lobjRow.className = 'cssFDisplayNone'; }
       }
    }

 // Redimensionnement de la barre laterale gauche
 shr_balg0_SetLeftBarHeight();
}
