//
//  -------------------------------------------------------------------- //
//                   HELIOP - SSII INFORMATIQUE                          //
//                 Copyright (c) 2006 heliop.com                         //
//                    <http://www.heliop.com/>                           //
//  -------------------------------------------------------------------- //
// jsChangeSelect.js - Javascript pour remplir un sélect (simple/multiple) en fonction d'un autre sélect simple
// Date: 12/01/2006
// Aut. Laurent Bourretere (l.bourretere@up-sale.com)
// Ver. 2.0 (18/09/2006)
// Modif: 18/09/2006 (v 2.0)
//        Ajout de la gestion d'un sélect Multiple

/*************************************************/
/* Changement d'un sélect par rapport à un autre */
/*************************************************/
function changeSelect (nomFormulaire,nomChamp1,nomChamp2,nomPremierLigne,tabIdSelect,tabNomSelect)
{
 var idChamp1 = eval("document."+nomFormulaire+"."+nomChamp1+".value");
 var tailleSelectEnCours = eval("document."+nomFormulaire+"."+nomChamp2+".options.length");
 for (i=0;i<tailleSelectEnCours;i++)
 {
  eval("document."+nomFormulaire+"."+nomChamp2+".options.length--");
 }
 decalage=0;
 if (nomPremierLigne.length>0)
 {
  eval("document."+nomFormulaire+"."+nomChamp2+".options[0]= new Option('- - - "+nomPremierLigne+" - - -','');");
  decalage=1;
 }
 if (tabIdSelect[idChamp1]!=undefined)
 {
  for (i=0;i<tabIdSelect[idChamp1].length;i++)
  {
   eval("document."+nomFormulaire+"."+nomChamp2+".options[i+decalage]= new Option('"+tabNomSelect[idChamp1][i]+"','"+tabIdSelect[idChamp1][i]+"')");
  }
 }
 tailleSelect(nomFormulaire,idChamp1,nomChamp2,tabIdSelect);
}

/******************************************************/
/* Chargement d'un sélect lors du retour sur une page */
/******************************************************/
function chargeSelectOnLoad (nomFormulaire,nomChamp1,idChamp1,nomChamp2,idChamp2,nomPremierLigne,tabIdSelect,tabNomSelect)
{
 typeSelect = eval("document."+nomFormulaire+"."+nomChamp2+".type");
 decalage=0;
 if (nomPremierLigne.length>0)
 {
  decalage=1;
  eval("document."+nomFormulaire+"."+nomChamp2+".options[0] = new Option('- - - "+nomPremierLigne+" - - -','');");
 }
 
// debugger;
 for (i=0;i<tabIdSelect[idChamp1].length;i++)
 {
  eval("document."+nomFormulaire+"."+nomChamp2+".options[i+decalage] = new Option('"+tabNomSelect[idChamp1][i]+"','"+tabIdSelect[idChamp1][i]+"')");
  if (typeSelect=="select-one")
  {
   if (tabIdSelect[idChamp1][i]==idChamp2)
   {
    eval("document."+nomFormulaire+"."+nomChamp2+".options.selectedIndex=i+decalage");
   }
  }
  else
  {
   var tabTmp = idChamp2.split(',');
   for (k=0;k<tabTmp.length;k++)
   {
    if (tabIdSelect[idChamp1][i]==tabTmp[k])
    {
     eval("document."+nomFormulaire+"."+nomChamp2+".options["+i+"].selected=true;");
    }
   }
  }
 }
 tailleSelect(nomFormulaire,idChamp1,nomChamp2,tabIdSelect);
}

/**********************************/
/* Gestion de la taille du sélect */
/**********************************/
function tailleSelect(nomFormulaire,idChamp1,nomChamp2,tabIdSelect)
{
 /* Taille d'un sélect Multiple */
 if (eval("document."+nomFormulaire+"."+nomChamp2+".type")=='select-multiple')
 {
  if (tabIdSelect[idChamp1].length<=20)
  {
   eval("document."+nomFormulaire+"."+nomChamp2+".size = "+tabIdSelect[idChamp1].length+";");
  }
  else
  {
   eval("document."+nomFormulaire+"."+nomChamp2+".size = 20;");
  }
 }
}
