var APP_URL = "http://www.infodivio.com/clients/ffc/";
var LIB_URL = APP_URL + "library/";
var IMG_URL = APP_URL + "images/";
var RES_URL = APP_URL + "ressources/";

// Crée un objet http, utilisé pour générer dynamiquement du code (AJAX)
function getHTTPObject()
{
   var xmlhttp;
   /*@cc_on
   @if (@_jscript_version >= 5)
   try
   {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
   }
   catch (e)
   {
      try
      {
         xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch (E)
      {
         xmlhttp = false;
      }
   }
   @else
      xmlhttp = false;
   @end @*/
   if (!xmlhttp && typeof XMLHttpRequest != 'undefined')
   {
      try
      {
         xmlhttp = new XMLHttpRequest();
      }
      catch (e)
      {
         xmlhttp = false;
      }
   }
   return xmlhttp;
}


/**
 * Fait un submit du formulaire avec les valeurs passer en argument
 * @param string asMode mode
 * @param string asValue valeur du mode
 */

function submit(asMode, asValue, asNomForm)
{
   if (asNomForm == null)
   {
      asNomForm = "principal";
   }
   if (asMode && asValue)
   {
      document.forms[asNomForm].elements[asMode].value = asValue;
   }
   document.forms[asNomForm].submit();
}
   

/**
 * Contrôle le nombre de caractères dans le textarea
 * @param string asFieldName nom du textarea
 * @param number anMaxLength longueur maximum du textarea
 */
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.principal.elements['nb' + asFieldName + 'Car'])
   {
      document.principal.elements['nb' + asFieldName + 'Car'].value = anMaxLength - document.principal.elements[asFieldName].value.length;
   }
}

/**
 * Inialise les évènements onclick, onmouseover et onmouseout de la checklist
 * @param string asIdCheckList nom de l'indentifiant de la checklist
 */
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";
            }
            loDivCheckBox.onmouseover = function()
            {
               if (this.className == "")
               {
                  this.className = "checklistHover";
               }
            }
            loDivCheckBox.onmouseout = function()
            {
               if (this.className == "checklistHover")
               {
                  this.className = "";
               }
            }
            loDivCheckBox.onclick = function()
            {
               if (document.getElementById(this.id+"Cb"))
               {
                  var loCheckBox = document.getElementById(this.id+"Cb");
                  if (loCheckBox.checked)
                  {
                     this.className = "checklistChecked";
                  }
                  else
                  {
                     this.className = "checklistHover";
                  }
               }
            }
         }
      }
   }
}

/**
 * Retourne false si au moins une case du checklist est cochée
 * @param string asIdCheckList nom de l'indentifiant de la checklist
 */
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;
   }
}

/**
 * Retourne false si au moins une case est cochée d'une liste de checkbox ou de radiobutton
 * @param array aaCheckBoxList tableau contenant la liste des checkbox
 */
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;
}

/**
 * Ouvre un page en popup
 * @param string asPage - l'URL de la page à ouvrir
 * @param int anWidth - la largeur en pixels du popup
 * @param int anHeight - la hauteur en pixels du popup
 * @param int anPosX - la position en pixels du popup par rapport au bord gauche de l'écran
 * @param int anPosY - la position en pixels du popup par rapport au bord supérieur de l'écran
 * @param string asName - le nom (javascript) du popup
 */
function openWindow(asPage, anWidth, anHeight, anPosX, anPosY, asName)
{
   if (!anWidth)
   {
      anWidth = screen.width / 2;
   }
   if (!anHeight)
   {
      anHeight = screen.height / 2;
   }
   if (!anPosX)
   {
      anPosX = (screen.width - anWidth) / 2;
   }
   if (!anPosY)
   {
      anPosY = (screen.height - anHeight) / 2;
   }
   if (!asName)
   {
      asName = 'window1';
   }
   window1 = window.open(asPage,asName,"toolbar=no,location=no,dependent=yes,directories=no,status=yes,menubar=no,resizable=yes,scrollbars=yes,left="+anPosX+",screenX="+anPosX+",top="+anPosY+",screenY="+anPosY+",width="+anWidth+",height="+anHeight);
}

/**
 * Retaille la popup
 * @param int anWidth - la largeur en pixels du popup
 * @param int anHeight - la hauteur en pixels du popup
 */
function resize(anWidth, anHeight)
{
   window.resizeTo(anWidth,anHeight);
}