/**
 * @FileFR » Gestion des fonctions du formulaire
 * @FileEN » Management of the functions of the form
 */

/**
 * @FunctionFR initForm » Fonction appelée au chargement de la page 
 * @FunctionEN initForm » Function called on the loading of the page
 */
function initForm() {
   addEventsTextbox();
   replaceChecks();
}

/**
 * @VarFR inputs Array » Tableau des composants HTML du formulaire
 * @VarEN inputs Array » Array of the HTML components of the form
 */
var inputs;

/**
 * @VarFR labels Array » Tableau des libellés HTML du formulaire
 * @VarEN labels Array » Array of the HTML labels of the form
 */
var labels;


/**
 * @FunctionFR addEventsTextbox » Ajoute aux textbox les évènements onkeyup
 * @FunctionEN addEventsTextbox » Add the textbox the onkeyup events
 */
function addEventsTextbox()
{
   inputs = document.getElementsByTagName('input');
   //cycle trough the input fields
   for (var i=0; i < inputs.length; i++)
   {
      //check if the input is a textbox
      if (inputs[i].getAttribute('type') == 'text' || inputs[i].getAttribute('type') == 'file')
      {
         if (inputs[i].onkeyup && !document.getElementById(inputs[i].id+'Id') && !document.getElementById(inputs[i].id+'Name'))
         {
            inputs[i].onblur = inputs[i].onkeyup;
            inputs[i].onblur += inputs[i].onchange;
         }
      }
   }
}

/**
 * @FunctionFR replaceChecks » Remplace les case à cocher et les boutons radio par des images
 * @FunctionEN replaceChecks » Replace the checkboxes and the radiobuttons by images
 */
function replaceChecks() {
   inputs = document.getElementsByTagName('input');
   labels = document.getElementsByTagName('label');
   for (i=0; i<labels.length; i++)
   {
      if (typeof labels[i].htmlFor != 'undefined')
      {
         elem = document.getElementById(labels[i].htmlFor);
         if (elem)
         {
            for (j=0; j<elem.length; j++)
            {
               elem.item(j).label = labels[i];
            }
            elem.label = labels[i];
         }
      }
   }
   
   //cycle trough the input fields
   for (var i=0; i < inputs.length; i++)
   {
      //check if the input is a checkbox
      if (inputs[i].getAttribute('type') == 'checkbox')
      {
         if (!document.getElementById(inputs[i].id+'Image'))
         {
            //create a new image
            var img = document.createElement('img');
         }
         else
         {
            var img = document.getElementById(inputs[i].id+'Image');
         }
         img.className = 'image';
         img.tabIndex = inputs[i].tabIndex;
         
         //check if the checkbox is checked
         if (inputs[i].getAttribute('accept') == 'on-off' && !inputs[i].checked)
         {
            img.src = IMG_URL + "form-html-checkbox-on-off.gif";
         }
         else
         {
            if (inputs[i].checked)
            {
               if (inputs[i].disabled)
               {
                  img.src = IMG_URL + "form-html-checkbox-on-disabled.gif";
               }
               else
               {
                  img.src = IMG_URL + "form-html-checkbox-on.gif";
               }
            }
            else
            {
               if (inputs[i].disabled)
               {
                  img.src = IMG_URL + "form-html-checkbox-off-disabled.gif";
               }
               else
               {
                  img.src = IMG_URL + "form-html-checkbox-off.gif";
               }
            }
         }
         if (!document.getElementById(inputs[i].id+'Image'))
         {
            //set image ID and onclick action
            img.id = inputs[i].id+'Image';
            //set image
            if (!inputs[i].disabled)
            {
               img.onclick = new Function('checkChange('+i+');');
               img.onkeyup = function(aoEvt)
               { 
                  var evt = (aoEvt) ? aoEvt : ((event) ? event : null);
                  var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
                  if ((evt.keyCode == 13))
                  {
                     for (var j=0; j < inputs.length; j++)
                     {
                        if (this.id == inputs[j].id+'Image')
                        {
                           var id = inputs[j].id.substr(0, (inputs[j].id.length - 2)); 
                           if (document.getElementById(id))
                           {
                              // Checkbox dans une checklist
                              document.getElementById(id).onmousedown();
                              document.getElementById(id).onmouseup();
                           }
                           checkChange(j);
                           break;
                        }
                     }
                  }
               }
            }
            //place image in front of the checkbox
            inputs[i].parentNode.insertBefore(img, inputs[i]);
            //hide the checkbox
            inputs[i].style.display='none';
            if (inputs[i].label)
            {
               inputs[i].label.onclick = new Function('checkImageChange('+i+');');
            }
         }
      }
      //check if the input is a radio
      if (inputs[i].getAttribute('type') == 'radio')
      {
         if (!document.getElementById(inputs[i].id+'Image'))
         {
            //create a new image
            var img = document.createElement('img');
         }
         else
         {
            var img = document.getElementById(inputs[i].id+'Image');
         }
         img.className = 'image';
         img.tabIndex = inputs[i].tabIndex;
         
         //check if the radio is checked
         if (inputs[i].checked)
         {
            if (inputs[i].disabled)
            {
               img.src = IMG_URL + "form-html-radiobutton-on-disabled.gif";
            }
            else
            {
               img.src = IMG_URL + "form-html-radiobutton-on.gif";
            }
         }
         else
         {
            if (inputs[i].disabled)
            {
               img.src = IMG_URL + "form-html-radiobutton-off-disabled.gif";
            }
            else
            {
               img.src = IMG_URL + "form-html-radiobutton-off.gif";
            }
         }
         if (!document.getElementById(inputs[i].id+'Image'))
         {
            //set image ID and onclick action
            img.id = inputs[i].id+'Image';
            //set image
            if (!inputs[i].disabled)
            {
               img.onclick = new Function('radioChange('+i+');');
               img.onkeyup = function(aoEvt)
               { 
                  var evt = (aoEvt) ? aoEvt : ((event) ? event : null);
                  var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
                  if ((evt.keyCode == 13))
                  {
                     for (var j=0; j < inputs.length; j++)
                     {
                        if (this.id == inputs[j].id+'Image')
                        {
                           radioChange(j);
                           break;
                        }
                     }
                  }
               }
            }
            //place image in front of the radio
            inputs[i].parentNode.insertBefore(img, inputs[i]);
            //hide the radio
            inputs[i].style.display='none';
            if (inputs[i].label)
            {
               inputs[i].label.onclick = new Function('radioImageChange('+i+');');
            }
         }
      }
   }
}

/**
 * @FunctionFR checkChange » Changement de l'état de la case à cocher et remplacement de l'image
 * @FunctionEN checkChange » Change of the checkbox status and the replacement image
 * @ParamFR anIndex Integer / » Indice de la case à cocher dans le formulaire 
 * @ParamEN anIndex Integer / » Index of the checkbox in the form
 */
function checkChange(anIndex)
{
   if(inputs[anIndex].checked)
   {
      document.getElementById(inputs[anIndex].id+'Image').src = IMG_URL + "form-html-checkbox-off.gif";
      inputs[anIndex].checked = '';
   }
   else
   {
      document.getElementById(inputs[anIndex].id+'Image').src = IMG_URL + "form-html-checkbox-on.gif";
      inputs[anIndex].checked = 'checked';
   }
   inputs[anIndex].onclick();
}

/**
 * @FunctionFR checkImageChange » Changement de l'image
 * @FunctionEN checkImageChange » Change of the image
 * @ParamFR anIndex Integer / » Indice de la case à cocher dans le formulaire 
 * @ParamEN anIndex Integer / » Index of the checkbox in the form
 */
function checkImageChange(anIndex)
{
   if (inputs[anIndex].checked)
   {
      document.getElementById(inputs[anIndex].id+'Image').src = IMG_URL + "form-html-checkbox-off.gif";
   }
   else
   {
      document.getElementById(inputs[anIndex].id+'Image').src = IMG_URL + "form-html-checkbox-on.gif";
   }
}

/**
 * @FunctionFR radioChange » Changement de l'état du bouton radio et remplacement de l'image
 * @FunctionEN radioChange » Change of the radiobutton status and the replacement image
 * @ParamFR anIndex Integer / » Indice du bouton radio dans le formulaire 
 * @ParamEN anIndex Integer / » Index of the radiobutton in the form
 */
function radioChange(anIndex)
{
   if (inputs[anIndex].checked)
   {
      document.getElementById(inputs[anIndex].id+'Image').src = IMG_URL + "form-html-radiobutton-off.gif";
      inputs[anIndex].checked = '';
   }
   else
   {
      document.getElementById(inputs[anIndex].id+'Image').src = IMG_URL + "form-html-radiobutton-on.gif";
      inputs[anIndex].checked = 'checked';
      radioChangeGroup(anIndex);
   }
   inputs[anIndex].onclick();
}

/**
 * @FunctionFR radioChangeGroup » Changement de l'état du bouton radio dans le groupe et remplacement de l'image
 * @FunctionEN radioChangeGroup » Change of the radiobutton status in the group and the replacement image
 * @ParamFR anIndex Integer / » Indice du bouton radio dans le formulaire 
 * @ParamEN anIndex Integer / » Index of the radiobutton in the form
 */
function radioChangeGroup(anIndex) {
   var radioGroup = document.forms["principal"].elements[inputs[anIndex].name];
   if (!radioGroup) return;
   for (var j=0; j<radioGroup.length; j++)
   {
      if (radioGroup[j].id != inputs[anIndex].id)
      {
         for (var k=0; k<inputs.length; k++)
         {
            if (inputs[k].id == radioGroup[j].id)
            {
               radioGroup[j].checked = '';
               document.getElementById(inputs[k].id+'Image').src = IMG_URL + "form-html-radiobutton-off.gif";
            }
         }
      }
   }
}

/**
 * @FunctionFR radioImageChange » Changement de l'image
 * @FunctionEN radioImageChange » Change of the image
 * @ParamFR anIndex Integer / » Indice du bouton radio dans le formulaire 
 * @ParamEN anIndex Integer / » Index of the radiobutton in the form
 */
function radioImageChange(anIndex)
{
   var image1 = document.getElementById(inputs[anIndex].id+'Image').src;
   var image2 = IMG_URL + "form-html-radiobutton-on.gif";
   var image3 = IMG_URL + "form-html-radiobutton-off.gif";
   
   if (inputs[anIndex].checked && document.getElementById(inputs[anIndex].id+'Image').src.indexOf(image2) > 0)
   {
      document.getElementById(inputs[anIndex].id+'Image').src = IMG_URL + "form-html-radiobutton-off.gif";
      setTimeout('radioImageChange(' + anIndex + ')', 10);
   }
   else if (inputs[anIndex].checked && document.getElementById(inputs[anIndex].id+'Image').src.indexOf(image3) > 0)
   {
      inputs[anIndex].checked = '';
      inputs[anIndex].onclick();
   }
   else
   {
      radioChangeGroup(anIndex);
      document.getElementById(inputs[anIndex].id+'Image').src = IMG_URL + "form-html-radiobutton-on.gif";
   }
}

/**
 * @FunctionFR submitForm » Envoi du formulaire avec les valeurs passer en argument
 * @FunctionEN submitForm » Submit of the form with the values passed in argument
 * @ParamFR asMode String / » Mode du formulaire 
 * @ParamEN asMode String / » Mode of the form
 * @ParamFR asValue String / » Valeur du mode du formulaire 
 * @ParamEN asValue String / » Value of the mode of the form
 * @ParamFR abOverlay Boolean / » Affichage ou non de l'animation de chargement
 * @ParamEN abOverlay Boolean / » Display or not of the animation of loading
 * @ParamFR asFormName String / » Nom du formulaire 
 * @ParamEN asFormName String / » Name of the form
 */
function submitForm(asMode, asValue, abOverlay, asFormName)
{
   if (asFormName == null)
   {
      asFormName = "principal";
   }
   if (asMode && asValue)
   {
      document.forms[asFormName].elements[asMode].value = asValue;
   }
   document.forms[asFormName].submit();
   if (abOverlay == null || abOverlay == true)
   {
      showOverlay();
   }
}

/**
 * @FunctionFR validateFormLogin » Valide le formulaire de connexion
 * @FunctionEN validateFormLogin » Validate the form of connection
 * @ParamFR aoEvt Object / » Evènement javascript
 * @ParamEN aoEvt Object / » Javascript event
 */
function validateFormLogin(aoEvt)
{
   var evt = (aoEvt) ? aoEvt : ((event) ? event : null);
   var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
   if ((evt.keyCode == 13))
   {
      submitForm('Connecter','Q29ubmV4aW9u');
   }
}

/**
 * @FunctionFR validateFormFilter » Valide le formulaire du filtre
 * @FunctionEN validateFormFilter » Validate the form of the filter
 * @ParamFR aoEvt Object / » Evènement javascript
 * @ParamEN aoEvt Object / » Javascript event
 */
function validateFormFilter(aoEvt)
{
   var evt = (aoEvt) ? aoEvt : ((event) ? event : null);
   var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
   if ((evt.keyCode == 13))
   {
      submitForm('Filtrer','RmlsdHJlcg==',true,'filter');
   }
}

/**
 * @FunctionFR largerTextarea » Agrandit la zone de texte
 * @FunctionEN largerTextarea » Enlarge the textarea
 * @ParamFR asId String / » Identifant HTML de la zone de texte
 * @ParamEN asId String / » HTML ID of the textarea
 */
function largerTextarea(asId)
{
   document.getElementById(asId).rows = parseInt(document.getElementById(asId).rows) + 2;
   if (document.getElementById(asId).style && document.getElementById(asId).style.height)
   {
      var height = document.getElementById(asId).style.height;
      heightValue = height.replace(/[^0-9]+/gi, "");
      heightUnit  = height.replace(heightValue, "");
      document.getElementById(asId).style.height = (parseInt(heightValue) + 30) + heightUnit;
   }
}

/**
 * @FunctionFR smallerTextarea » Réduit la zone de texte
 * @FunctionEN smallerTextarea » Reduce the textarea
 * @ParamFR asId String / » Identifant HTML de la zone de texte
 * @ParamEN asId String / » HTML ID of the textarea
 */
function smallerTextarea(asId)
{
   if (parseInt(document.getElementById(asId).rows) > 2)
   {
      document.getElementById(asId).rows = parseInt(document.getElementById(asId).rows) - 2;
   }
   if (document.getElementById(asId).style && document.getElementById(asId).style.height)
   {
      var height = document.getElementById(asId).style.height;
      heightValue = height.replace(/[^0-9]+/gi, "");
      heightUnit  = height.replace(heightValue, "");
      if (parseInt(heightValue) > 50)
      {
         document.getElementById(asId).style.height = (parseInt(heightValue) - 30) + heightUnit;
      }
   }
}

/**
 * @FunctionFR autoCompleteOff » Supprime l'autocomplétion du navigateur
 * @FunctionEN autoCompleteOff » Remove the autocompletion of the browser
 * @ParamFR asId String / » Identifant HTML du composant
 * @ParamEN asId String / » HTML ID of the component
 */
function autoCompleteOff(asId)
{
   document.getElementById(asId).setAttribute("autocomplete","off");
}

/**
 * @FunctionFR resetForm » Remet à zéro le formualaire
 * @FunctionEN resetForm » Reset the form
 * @ParamFR asFormName String / » Nom du formulaire 
 * @ParamEN asFormName String / » Name of the form
 */
function resetForm(asFormName)
{
   for ( i=0; i < document.forms[asFormName].elements.length; i++)
   {
      if (!(document.forms[asFormName].elements[i].readOnly  || document.forms[asFormName].elements[i].disabled))
      {
         if ((document.forms[asFormName].elements[i].type == 'text') || (document.forms[asFormName].elements[i].type == 'textarea') || (document.forms[asFormName].elements[i].type == 'password'))
         {
            document.forms[asFormName].elements[i].value = '';
         }
         if (document.forms[asFormName].elements[i].type == 'checkbox' || document.forms[asFormName].elements[i].type == 'radio')
         {
            document.forms[asFormName].elements[i].checked = false;
         }
         if (document.forms[asFormName].elements[i].type == 'select-one' && (document.forms[asFormName].elements[i].length != 0))
         {
            document.forms[asFormName].elements[i].options[0].selected = true;
         }
      }
   }
}

/**
 * @FunctionFR validCharacterMail » Rejette les mauvais caractères d'un email
 * @FunctionEN validCharacterMail » Reject the bad characters of an email
 * @ParamFR aoEvt Object / » Evènement javascript
 * @ParamEN aoEvt Object / » Javascript event
 */
function validCharacterMail(aoEvt)
{
   var keyCode  = aoEvt.which ? aoEvt.which : aoEvt.keyCode;
   if (keyCode != 8 && keyCode != 9 && keyCode != 13 && keyCode != 35  && keyCode != 36  && keyCode != 37 && keyCode != 39)
   {
      var authorized = "abcdefeghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-+.@";
      if (authorized.indexOf(String.fromCharCode(keyCode)) < 0)
      {
         return false;
      }
   }
}

/**
 * @FunctionFR validCharacterNumber » Rejette les mauvais caractères d'un nombre
 * @FunctionEN validCharacterNumber » Reject the bad characters of a number
 * @ParamFR aoEvt Object / » Evènement javascript
 * @ParamEN aoEvt Object / » Javascript event
 */
function validCharacterNumber(aoEvt) {
   var keyCode = aoEvt.which ? aoEvt.which : aoEvt.keyCode;
   if (keyCode != 8 && keyCode != 9 && keyCode != 13 && keyCode != 35  && keyCode != 36  && keyCode != 37 && keyCode != 39)
   {
      var authorized = '+-0123456789., ';
      if (authorized.indexOf(String.fromCharCode(keyCode)) < 0)
         return false;
   }
}

/**
 * @FunctionFR validCharacterPhone » Rejette les mauvais caractères d'un numéro de téléphone
 * @FunctionEN validCharacterPhone » Reject the bad characters of a phone number
 * @ParamFR aoEvt Object / » Evènement javascript
 * @ParamEN aoEvt Object / » Javascript event
 */
function validCharacterPhone(aoEvt) {
   var keyCode = aoEvt.which ? aoEvt.which : aoEvt.keyCode;
   if (keyCode != 8 && keyCode != 9 && keyCode != 13 && keyCode != 35  && keyCode != 36  && keyCode != 37 && keyCode != 39)
   {
      var authorized = '0123456789.-()+ ';
      if (authorized.indexOf(String.fromCharCode(keyCode)) < 0)
         return false;
   }
}

/**
 * @FunctionFR fillListMultiple » Rejette les mauvais caractères d'un numéro de téléphone
 * @FunctionEN fillListMultiple » Reject the bad characters of a phone number
 * @ParamFR aoListMultiple Object / » Composant HTML de la liste multiple
 * @ParamEN aoListMultiple Object / » HTML component of the multiple list
 * @ParamFR asValues String / » Chaînes de valeurs séparées par #+#
 * @ParamEN asValues String / » String of the values separed by #+#
 * @ParamFR anNbMaxValues Integer / » Nombre de valeurs maximum autorisées
 * @ParamEN anNbMaxValues Integer / » Number of maximum values authorised
 */
function fillListMultiple(aoListMultiple, asValues, anNbMaxValues)
{
   for (i = aoListMultiple.options.length-1 ; i >= 0 ; i--)
   {
      aoListMultiple.options[aoListMultiple.options.length - 1] = null;
   }
   laValues = asValues.split('#+#');
   for (i=0; i < laValues.length ; i++)
   {
      if (laValues[i] != "")
      {
         objOption = new Option(laValues[i],laValues[i]);
         aoListMultiple.options[aoListMultiple.options.length] = objOption;
      }
   }
   if (anNbMaxValues)
   {
      ctlListMutipleValues(aoListMultiple.name, anNbMaxValues);
   }
}

/**
 * @FunctionFR listMultipleSort » Permute des options de la liste multiple
 * @FunctionEN listMultipleSort » Permute options of the multiple list
 * @ParamFR aoListMultiple Object / » Composant HTML de la liste multiple
 * @ParamEN aoListMultiple Object / » HTML component of the multiple list
 * @ParamFR anStep Integer / » Pas de permutation
 * @ParamEN anStep Integer / » Step of permutation
 */
function listMultipleSort(aoListMultiple, anStep)
{
   if (anStep < 0)
   {
      for (i=0; i < aoListMultiple.options.length ; i++)
      {
         if (aoListMultiple.options[i].selected && aoListMultiple.options[i]!= "" && i > 0)
         {
            if (!aoListMultiple.options[i+anStep].selected && aoListMultiple.options[i+anStep]!= "")
            {
               listMultipleOptionPermutation(aoListMultiple, i, anStep)
            }
         }
      }
      listMultipleOptionHidden(aoListMultiple);
   }
   if (anStep > 0)
   {
      for (i=aoListMultiple.options.length-1; i >= 0 ; i--)
      {
         if (aoListMultiple.options[i].selected && aoListMultiple.options[i]!= "" && i < aoListMultiple.options.length-1)
         {
            if (!aoListMultiple.options[i+anStep].selected && aoListMultiple.options[i+anStep]!= "")
            {
               listMultipleOptionPermutation(aoListMultiple, i, anStep)
            }
         }
      }
      listMultipleOptionHidden(aoListMultiple);
   }
}

/**
 * @FunctionFR listMultipleOptionPermutation » Permute des options de la liste multiple
 * @FunctionEN listMultipleOptionPermutation » Permute options of the multiple list
 * @ParamFR aoListMultiple Object / » Composant HTML de la liste multiple
 * @ParamEN aoListMultiple Object / » HTML component of the multiple list
 * @ParamFR anIndex Integer / » Indice de l'option à permuter
 * @ParamEN anIndex Integer / » Index of the option to permute
 * @ParamFR anStep Integer / » Pas de permutation
 * @ParamEN anStep Integer / » Step of permutation
 */
function listMultipleOptionPermutation(aoListMultiple, anIndex, anStep)
{
   tmpopt = new Option(aoListMultiple.options[anIndex+anStep].text,aoListMultiple.options[anIndex+anStep].value);
   aoListMultiple.options[anIndex+anStep].text     = aoListMultiple.options[anIndex].text;
   aoListMultiple.options[anIndex+anStep].value    = aoListMultiple.options[anIndex].value;
   aoListMultiple.options[anIndex+anStep].selected = true;
   aoListMultiple.options[anIndex].text         = tmpopt.text;
   aoListMultiple.options[anIndex].value        = tmpopt.value;
   aoListMultiple.options[anIndex].selected     = false;
}

/**
 * @FunctionFR addListMultipleOption » Ajoute une nouvelle option
 * @FunctionEN addListMultipleOption » Add a new option
 * @ParamFR aoTextbox Object / » Composant HTML du champ de saisie
 * @ParamEN aoTextbox Object / » HTML component of the textbox
 * @ParamFR aoListMultiple Object / » Composant HTML de la liste multiple
 * @ParamEN aoListMultiple Object / » HTML component of the multiple list
 * @ParamFR anNbMaxValues Integer / » Nombre de valeurs maximum autorisées
 * @ParamEN anNbMaxValues Integer / » Number of maximum values authorised
 */
function addListMultipleOption(aoTextbox, aoListMultiple, anNbMaxValues)
{
   if (aoTextbox.value != "" && (!document.getElementById('nb' + aoListMultiple.name + 'Values') || (document.getElementById('nb' + aoListMultiple.name + 'Values') && document.getElementById('nb' + aoListMultiple.name + 'Values').innerHTML != '0')))
   {
      var lbExistOption = false;
      for (i=0; i < aoListMultiple.options.length ; i++)
      {
         if (aoListMultiple.options[i].text == aoTextbox.value)
         {
            lbExistOption = true;
         }
      }
      if (!lbExistOption)
      {
         for (i=0; i < aoListMultiple.options.length ; i++)
         {
            aoListMultiple.options[i].selected = false;
         }
         objOption = new Option(aoTextbox.value,aoTextbox.value);
         objOption.selected = true;
         aoListMultiple.options[aoListMultiple.options.length] = objOption;
         listMultipleOptionHidden(aoListMultiple);
      }
      if (anNbMaxValues)
      {
         ctlListMutipleValues(aoListMultiple.name, anNbMaxValues);
      }
   }
}

/**
 * @FunctionFR deleteListMultipleOptions » Supprime les options sélectionnées
 * @FunctionEN deleteListMultipleOptions » Delete the selected options
 * @ParamFR aoListMultiple Object / » Composant HTML de la liste multiple
 * @ParamEN aoListMultiple Object / » HTML component of the multiple list
 * @ParamFR anNbMaxValues Integer / » Nombre de valeurs maximum autorisées
 * @ParamEN anNbMaxValues Integer / » Number of maximum values authorised
 */
function deleteListMultipleOptions(aoListMultiple, anNbMaxValues)
{
   for (i=0; i < aoListMultiple.options.length ; i++)
   {
      if (aoListMultiple.options[i].selected && aoListMultiple.options[i]!= "" )
      {
         aoListMultiple.options[i]=null;
         i = i -1 ;
      }
   }
   listMultipleOptionHidden(aoListMultiple);
   if (anNbMaxValues)
   {
      ctlListMutipleValues(aoListMultiple.name, anNbMaxValues);
   }
}

/**
 * @FunctionFR ctlListMutipleValues » Affiche le nombre de valeurs autorisées restantes
 * @FunctionEN ctlListMutipleValues » Dispaly the number of authorised staying values 
 * @ParamFR asListMultipleName String / » Nom de la liste multiple
 * @ParamEN asListMultipleName String / » Name of the multiple list
 * @ParamFR anNbMaxValues Integer / » Nombre de valeurs maximum autorisées
 * @ParamEN anNbMaxValues Integer / » Number of maximum values authorised
 */
function ctlListMutipleValues(asListMultipleName, anMaxValues)
{
   var list = document.principal.elements[asListMultipleName].value;
   var nb   = document.principal.elements[asListMultipleName].options.length;
   if (document.getElementById('nb' + asListMultipleName + 'Values'))
   {
      document.getElementById('nb' + asListMultipleName + 'Values').innerHTML = anMaxValues - document.principal.elements[asListMultipleName].options.length;
   }
}

/**
 * @FunctionFR listMultipleOptionHidden » Met à jour le champ caché qui contient l'ensemble des options de la liste multiple
 * @FunctionEN listMultipleOptionHidden » Update the hidden field which contents the set of the options of the multiple list
 * @ParamFR aoListMultiple Object / » Composant HTML de la liste multiple
 * @ParamEN aoListMultiple Object / » HTML component of the multiple list
 **/
function listMultipleOptionHidden(aoListMultiple)
{
   lsValues = "";
   for (i=0; i < aoListMultiple.options.length ; i++)
   {
      if (i != 0)
      {
         lsValues += "#+#";
      }
      lsValues += aoListMultiple.options[i].value;
   }
   document.getElementById("hf" + aoListMultiple.id).value = lsValues;
}

/**
 * @FunctionFR countListMultipleOption » Compte le nombre d'options dans la liste multiple
 * @FunctionEN countListMultipleOption » Count the number of options in the multiple list
 * @ParamFR asListMultipleName String / » Nom de la liste multiple
 * @ParamEN asListMultipleName String / » Name of the multiple list
 * @ReturnFR Integer » Nombre d'options dans la liste multiple
 * @ReturnEN Integer » Number of options in the multiple list
 **/
function countListMultipleOption(asListMultipleName)
{
   return document.principal.elements[asListMultipleName+"List"].options.length;
}

/**
 * @FunctionFR countListMultipleOption » Contrôle le nombre de caractères dans la zone de texte
 * @FunctionEN countListMultipleOption » Control the number of characters in the textarea
 * @ParamFR asFieldName String / » Nom de la zone de texte
 * @ParamEN asFieldName String / » Name of the textarea
 * @ParamFR anMaxLength Integer / » Nombre de caractères maximum autorisés
 * @ParamEN anMaxLength Integer / » Number of maximum authorised characters
 **/
function ctlTextArea(asFieldName, anMaxLength)
{
   var txt = document.principal.elements[asFieldName].value;
   var nb  = document.principal.elements[asFieldName].value.length;
   if (nb > anMaxLength)
   {
      document.principal.elements[asFieldName].value = txt.substring(0, anMaxLength);
      nb = anMaxLength;
   }
   if (document.getElementById('nb' + asFieldName + 'Car'))
   {
      document.getElementById('nb' + asFieldName + 'Car').innerHTML = anMaxLength - document.principal.elements[asFieldName].value.length;
   }
}

/**
 * @FunctionFR checkListChecked » Inialise les évènements onclick, onmouseover et onmouseout de la liste multiple à cocher
 * @FunctionEN checkListChecked » Inialize the onclick, onmouseover and onmouseout events of the multiple list to check
 * @ParamFR asIdCheckList String / » Identifiant HTML de la liste multiple à cocher
 * @ParamEN asIdCheckList String / » HTML ID of the multiple list to check
 **/
function initCheckList(asIdCheckList)
{
   if (document.getElementById(asIdCheckList))
   {
      var laCheckList = document.getElementById(asIdCheckList).getElementsByTagName('input');
      for (var n = 0 ; n < laCheckList.length ; n++)
      {
         if (document.getElementById(laCheckList[n].id.substr(0, laCheckList[n].id.length-2)))
         {
            var loDivCheckBox = document.getElementById(laCheckList[n].id.substr(0, laCheckList[n].id.length-2));
            if (laCheckList[n].checked)
            {
               loDivCheckBox.className = "checklistChecked";
            }
            else
            {
               loDivCheckBox.className = "option";
            }
            loDivCheckBox.onmouseover = function()
            {
               if (this.className == "option")
               {
                  this.className = "option checklistHover";
               }
            }
            loDivCheckBox.onmouseout = function()
            {
               if (this.className == "option checklistHover")
               {
                  this.className = "option";
               }
            }
            loDivCheckBox.onmousedown = function()
            {
               if (document.getElementById(this.id+"Cb"))
               {
                  var loCheckBox = document.getElementById(this.id+"Cb");
                  if (loCheckBox.checked)
                  {
                     loCheckBox.checked = false;
                     this.className = "option checklistHover";
                     if (document.getElementById(loCheckBox.id+'Image'))
                     {
                        document.getElementById(loCheckBox.id+'Image').src = IMG_URL + "form-html-checkbox-off.gif";
                     }
                  }
                  else
                  {
                     loCheckBox.checked = true;
                     this.className = "option checklistChecked";
                     if (document.getElementById(loCheckBox.id+'Image'))
                     {
                        document.getElementById(loCheckBox.id+'Image').src = IMG_URL + "form-html-checkbox-on.gif";
                     }
                  }
               }
            }
            laCheckList[n].onclick = function()
            {
               if (this.checked)
               {
                  this.checked = false;
                  if (document.getElementById(this.id+'Image'))
                  {
                     document.getElementById(this.id+'Image').src = IMG_URL + "form-html-checkbox-off.gif";
                  }
               }
               else
               {
                  this.checked = true;
                  if (document.getElementById(this.id+'Image'))
                  {
                     document.getElementById(this.id+'Image').src = IMG_URL + "form-html-checkbox-on.gif";
                  }
               }
            }
         }
      }
   }
}

/**
 * @FunctionFR checkListChecked » Teste si aucun élément de la liste multiple n'est coché ou non
 * @FunctionEN checkListChecked » Test if no item of the multiple list is checked or not
 * @ParamFR asIdCheckList String / » Identifiant HTML de la liste multiple à cocher
 * @ParamEN asIdCheckList String / » HTML ID of the multiple list to check
 * @ReturnFR Boolean » Aucun élément n'est coché ou non
 * @ReturnEN Boolean » No item is checked or not
 **/
function checkListChecked(asIdCheckList)
{
   if (document.getElementById(asIdCheckList))
   {
      var laCheckList = document.getElementById(asIdCheckList).getElementsByTagName('input');
      for (var n = 0 ; n < laCheckList.length ; n++)
      {
         if (laCheckList[n].checked)
         {
            return false;
         }
      }
      return true;
   }
}

/**
 * @FunctionFR CbRbChecked » Teste si aucun élément n'est coché ou non
 * @FunctionEN CbRbChecked » Test if no item is checked or not
 * @ParamFR aaCheckList Array / » Tableau d'identifiant HTML de case à cocher ou de bouton radio
 * @ParamEN aaCheckList Array / » Array of HTML ID of checkboxes or radiobuttons
 * @ReturnFR Boolean » Aucun élément n'est coché ou non
 * @ReturnEN Boolean » No item is checked or not
 **/
function CbRbChecked(aaCheckList)
{
   for (var n = 0 ; n < aaCheckList.length ; n++)
   {
      if (document.getElementById(aaCheckList[n]))
      {
         if (document.getElementById(aaCheckList[n]).checked)
         {
            return false;
         }
      }
   }
   return true;
}

