/*****************************/
/* switchDiv(dDiv,dispMode) */
/*****************************/
/* dDiv : the div to show/hide
 * dispMode:
 *   on  - show
 *   off - hide
 */

function switchDiv(dDiv,dispMode)
  {
    dispMode=="on"?document.getElementById(dDiv).style.visibility='visible':document.getElementById(dDiv).style.visibility='hidden'
  }

/*****************************/
/* getAgeFromDate(dd,mm,yy,currentDay,currentMonth,currentYear) */
/*****************************/
/* Donne l'age en année en fonction de la date passée en paramètre.
 * S'assurer que la date est correcte avant d'appeler cette fonction.
 */


function getAgeFromDate(dd,mm,yy,currentDay,currentMonth,currentYear) {
    /*
    days = new Date();
    gdate = days.getDate();
    gmonth = days.getMonth();
    gyear = days.getYear();
    alert(gdate +" " +gmonth+" "+gyear);
    suppression de la date courante du pc par une date recue en paramètre
    */
    gdate = currentDay;
    gmonth = currentMonth-1;
    gyear = currentYear;

    age = gyear - yy;

    if((mm == (gmonth + 1)) && (dd <= parseInt(gdate)))
      {
        age = age;
      }
    else
      {
        if(mm <= (gmonth))
          {
            age = age;
          }
        else
          {
            age = age - 1;
          }
      }
    return age;
  }

/**********************************************/
/* Change la class d'un element               */
/**********************************************/
function changeClass(Elem, myClass) {
	var elem;
	if(document.getElementById) {
		var elem = document.getElementById(Elem);
	} else if (document.all){
		var elem = document.all[Elem];
	}
	elem.className = myClass;
}

/**********************************************/
/* Fait un submit avec une valeur mid.CLE     */
/**********************************************/
function sendKey(theKey) {
	document.form_devis.CDOPTRN.value = " ";
	document.form_devis.CLE.value = theKey;
  document.form_devis.submit();
}



/**********************************************/
/* Mets le focus sur le premier champs        */
/* ex: initFocus("document.myForm.myField");  */
/**********************************************/
function initFocus(myFirstField)
  {
    eval(myFirstField+".focus();");
  }

/**************************************/
/* Tabulation automatique IE-Netscape */
/**************************************/
/* Usage:
 * <INPUT TYPE="text" size="2" MAXLENGTH="2" name="DANAIJJ" onKeyUp="return autoTab(this,DANAIMM, 2);">
 * <INPUT TYPE="text" size="2" MAXLENGTH="2" name="DANAIMM">
 */

 if (window.Event) /* Pour netscape 4 */
  {
    document.captureEvents(Event.KEYPRESS);
  }
function autoTab(obj,nextobj,mlength)
  {
    /*if (autoTab.arguments.length == 2)
      mlength=obj
      a terminer :-D */
    if(!mlength)
      {
        mlength = obj.size;
      }
    if(obj.value.length>=mlength)
      {
        obj.value = obj.value.substr(0,mlength);
	      nextobj.focus();
	    }
  }

/*******************************************/
/* Gestion des ROLL-OVER                   */
/*******************************************/

  function img_act(imgName)
    {
      imgOn = eval(imgName + "on.src");
      document[imgName].src = imgOn;
    }

  function img_inact(imgName)
    {
      imgOff = eval(imgName + "off.src");
      document [imgName].src = imgOff;
      }




/********************************************************************************************/
  function IsNumeroNational(string)
    {
      var temp;
      var module;
      var chiffre;
      temp=string;
      if (temp.length!=11) return(false);
      chiffre = temp.substring(0,9);
      module = temp.substring(9,11);
      if (chiffre % 97 == (97-module)) return(true);
    }
/********************************************************************************************/

 			function getQueryStringVal(lQuery)
			{
				var lDoc=String(document.location);
				var lSignet = "-1";
				var n1 = lDoc.indexOf("?");

				if (n1 > 0)
				{
				  var n2 = lDoc.indexOf("?" + lQuery + "=",n1);
				  if (n2 < n1)
				    n2 = lDoc.indexOf("&" + lQuery + "=",n1);
				  if (n2 >= n1)
				  {
				    n2 = n2 + ("?" + lQuery + "=").length;
				    var n3 = lDoc.indexOf("&",n2+1);
				    if (n3 > n2)
				      lSignet = lDoc.substring(n2, n3);
				    else
				      lSignet = lDoc.substring(n2);
				  }
				}
				return lSignet;
			}

/********************************************************************************************/

			function isEmailAdr(email) {
			  var result = false;
			  var theStr = new String(email);
			  var index = theStr.indexOf("@");
			  if (index > 0) {
			    var pindex = theStr.indexOf(".",index);
			    if ((pindex > index+1) && (theStr.length > pindex+1))
					result = true;
			  }
			  return result;
			}

/********************************************************************************************/

		   function remplace(expr,a,b) {
		      var i=0
		      while (i!=-1) {
		         i=expr.indexOf(a,i);
		         if (i>=0) {
		            expr=expr.substring(0,i)+b+expr.substring(i+a.length);
		            i+=b.length;
		         }
		      }
		      return expr
		   }

/********************************************************************************************/

			function couperMots(texte, lgMax) {
				var posit = 0;
				var lgMot = 0;
				var part1 = "";
				var part2 = "";
				while (posit<texte.length) {
					if (texte.substr(posit,1) == ' ' || texte.substr(posit,1) == '\n') {
						lgMot = 0;
					} else {
						lgMot = lgMot + 1;
						if (lgMot >= lgMax) {
							//ajout d'un blanc
							part1 = texte.substr(0, posit);
							part2 = texte.substr(posit, texte.length - posit);
							texte = part1 + " " + part2;
							lgMot = 0;
						} //end if
					} //end if
					posit = posit + 1;
				} //end while
				return texte;
			} //end function

/********************************************************************************************/

// ============================================================================
// nvl(number) : Returns 0 if value is null or value itself if not
//
// PURPOSE: Avoid null values in arithmetic operations
// IN: aNumberValue - the number to check
// RETVAL: number
// ============================================================================
function nvl(aNumberValue){
  if(aNumberValue == '' || aNumberValue == null){
    return 0;
  }else{
    return aNumberValue;
  }
}

// ===============================================================================================
// checkNumber(field) : check if field value is a number and focus the field with a warning if not
//
// PURPOSE: Check value of number fields
// IN: aField - the name of the field containing the number
// RETVAL: true/false
// ===============================================================================================
function checkNumber(aField,errMsg){
  if(isNaN(aField.value)){
    alert(errMsg);
    aField.value = '';
    aField.focus();
    return false;
  }
  return true;
}

// ----------------------------------
// isEmpty (s)
// ----------------------------------
// Retourne true si le champ s est vide.

function isEmpty(s) {
	return ((s == null) || (s.length == 0));
}


// ----------------------------------
// isInteger2 (s [,eok])
// ----------------------------------
// Retourne true si tous les caractères du champ s sont des chiffres.

function isInteger2 (s) {
  var i;


	if(isEmpty(s)) {
		if(isInteger2.arguments.length == 1) {
     	return (false);
		} else {
			return (isInteger2.arguments[1] == true);
		}
	}

  for (i = 0; i < s.length; i++) {
	  var c = s.charAt(i);
	  if((c < "0") || (c > "9")) return (false);
  }

  return (true);
}



// ----------------------------------
// addDecimal(myField)
// ----------------------------------
// Ajoute ",00" si nécessaire
// Remplace le "." par un "," si nécessaire
// IN:  Le champs à corriger (ex: document.monForm.monChamps)
// OUT: Rien. Le champs est corrigé
  function addDecimal(myField)
    {
      //On remplace "." par "," si besoin
      if(myField.value.indexOf('.') != -1){
        myField.value = myField.value.replace('.', ',');
      }

      //Si pas de "," et qu'il y a qque chose dans le champs, on ajoute ",00"
      if(myField.value.indexOf(',') == -1 && myField.value.length > 0){
        myField.value = myField.value + ',00';
      }
    }

// ----------------------------------
// isRadioChecked(myField,errMsg)
// ----------------------------------
// Vérifie si on a bien coché *un des radio* du champs
// IN:  Le radio à tester (ex: document.monForm.monRadio)
//      Le message d'erreur
// OUT: True si on a coché une case
//      False sinon + alert de "errMsg"
// IMPORTANT: les radio de longueur 1 (une seule case) posent problème avec ce genre de script (myField.length)!!!

    function isRadioChecked(myField,errMsg)
      {
        //On boucle sur le nombre de case
        for (i=0;i<myField.length;i++)
          {
            //On teste si la case en cours est cochée
            if (myField[i].checked==true)
              {
                //Si oui
                return true;
              }
          }
        //Si non
        if (errMsg.length>0)
          alert(errMsg);
        return false;
      }

// ----------------------------------
// unCheck(myField)
// ----------------------------------
// Décoche tous les champs d'un radio
// IN:  Le radio à décocher
// IMPORTANT: les radio de longueur 1 (une seule case) posent problème avec ce genre de script (myField.length)!!!

    function unCheck(myField)
      {
        //On boucle sur le nombre de case
        for (i=0;i<myField.length;i++)
          {
            //On décoche
            myField[i].checked=false;
          }
        return;
      }


// ----------------------------------
// isSelected(myField,errMsg)
// ----------------------------------
// Vérifie si on a bien choisi une option avec valeur != "" dans un <SELECT>
// IN:  Le select à tester (ex: document.monForm.monSelect)
//      Le message d'erreur
// OUT: True si on a choisi une option valable
//      False sinon + alert de "errMsg"

    function isSelected(myField,errMsg)
      {
        if (myField[myField.selectedIndex].value=="")
          {
            myField.focus();
            if (errMsg.length>0)
                alert(errMsg);
            return false;
          }
        return true;
      }

      /*****************************************/
      /* function checkTel(myField,errMsg,eOk) */
      /**************************************************************/
      /* Vérifie la validité d'un numéro de téléphone ==>           */
      /* Enlève tout les caractères tolérés sauf le '/'             */
      /* eOk = empty is ok?                                         */
      /**************************************************************/
      function checkTel(myField,errMsg,eOk)
        {
          theNum=myField.value;


          //On enlève les caractères autorisés mais inutiles
          theNum=compact(theNum,' ');
          theNum=compact(theNum,'.');
          theNum=compact(theNum,'-');
          theNum=compact(theNum,'(');
          theNum=compact(theNum,')');

          //On s'assure qu'il n'y a pas plus d'un slash. Si oui on le laisse, si non, on les vires
          if (charCount(theNum,'/')>1) theNum=compact(theNum,'/');

          //Une fois tout compacté, on vérifie la longueur du numéro et si c'est bien une chaine numérique uniquement ainsi que si c'est vide, si on doit retourner une erreur ou pas :-D
          lTheNum = theNum.length;

          if ((((lTheNum==9)||(lTheNum==10)||(lTheNum==11))&&(isNumeric(compact(theNum,'/'))))||((lTheNum == 0)&&(eOk==true)))
            {
              myField.value=theNum;
              return true;
            }
          else
            {
              myField.focus();
              myField.select();

              if (errMsg.length>0)
                alert(errMsg);

              return false;
            }
        }

/***************************************/
/* function compact(theString,theChar) */
/**************************************************************/
/* Enlève toutes les occurences de "theChar" dans "theString" */
/* Ex: compact("Hello world!",'o'); --> "Hell wrld!"          */
/* Case sensitive !!!                                         */
/**************************************************************/
function compact(theString,theChar)
  {
    var charPos;
    charPos = theString.indexOf(theChar);
    if (charPos !=-1)
      {
        return theString.substring(0,charPos) + compact(theString.substring(charPos+1),theChar);
      }
    else
      {
        return theString;
      }
  }



/*****************************************/
/* function charCount(strString,chrChar) */
/**************************************************************/
/* Compte le nombre d'occurence de chrChar dans strString     */
/* Ex: charCount("Hello world!",'o'); --> 2                   */
/* Case sensitive !!!                                         */
/**************************************************************/
function charCount(strString,chrChar)
  {
    var cpt=0;
    for (i=0;i<strString.length;i++)
    {
      if (strString.charAt(i)==chrChar) cpt++;
    }
    return cpt;
  }

/******************************/
/* function checkEmail(myField, errMsg) */
/********************************************************************/
/* Renvoi true si email est une adresse e-mail qui a l'air correcte */
/********************************************************************/
	function checkEmail(myField, errMsg) {
    //on vire les éventuels espaces
	  myField.value=compact(myField.value," ");

	  //et on check
    var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
    if (filter.test(myField.value))
      {
        return true;
      }
    else
      {
        myField.focus();
        myField.select();

        if (errMsg.length>0)
          alert(errMsg);

        return false;
      }
	}

/*****************************************/
/* function isNumeric(strString)         */
/**************************************************************/
/* Vérifie si strString est numérique                         */
/* strValidChars est la liste des charactères acceptés        */
/**************************************************************/
function isNumeric(strString)
   //  check for valid numeric strings
   {
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }

// ---------------------------------------------
// function checkField(myField,errMsg,isAmount)
// ---------------------------------------------
// Vérifie si un champs obligatoire est remplis. Affiche errMsg sinon. Ajoute ",00" si isAmout == true
// IN:  Le champs obligatoire (ex: document.monForm.monChamps)
//      Le message d'erreur
//      true s'il faut ajouter ",00"
// OUT: True si le champs est ok
//      False sinon + alert de "errMsg"

    function checkField(myField,errMsg,isAmount)
      {
        if (myField.value=="")
          {
            myField.focus();
            myField.select();
            if (errMsg.length>0)
              alert(errMsg);
            return false;
          }
        if (isAmount)
          {
            //on vire les blancs
            myField.value=compact(myField.value,' ');
            //on vérifie si on a pas de caractère non admis ex:a,z,e,r,t,*,-, ...
            if (!checkEuro(myField))
              {
                if (errMsg.length>0)
                  {
                    myField.focus();
                    myField.select();
                    alert(errMsg);
                  }
                return false;
              }
            //addDecimal(myField);
          }
        return true;
      }

      function checkEuro(ZoneName)
        {
        /* Un nombre bien formé ressemble à
         *  10.000,00
         *  10000,00
         *  10000
         * et pas à
         *  10000.00
         * Le résultat doit devenir de type
         * 10000,00
         * 10000,00
         * 10000
         */
         var putComma = 1; /* Si putComma = 1 alors on ajoute ",00" meme si l'utilisateur n'a rien entré */
         var Element = new Array(12)
            Element[0]  = "0";
            Element[1]  = "1";
            Element[2]  = "2";
            Element[3]  = "3";
            Element[4]  = "4";
            Element[5]  = "5";
            Element[6]  = "6";
            Element[7]  = "7";
            Element[8]  = "8";
            Element[9]  = "9";
            Element[10] = ",";
            Element[11] = ".";
          var StrOk     = "";
          var Car       = "";
          var tmp       = "";
          var Comma     = 0;
          var points    = 0;
          var temp      = 0;
          var CommaPos  = -1;
          var part1     = "";
          var part2     = "";

          for (var i=0; i<ZoneName.value.length; i++)
            {
              Car = ZoneName.value.substring(i,i+1);
              if (ZoneName.value.substring(i,i+1)==",") Comma  = Comma + 1;   /* determine the number of commas */
              if (ZoneName.value.substring(i,i+1)==".") points = points + 1;  /* determine the number of points */

              for (var counter=0; (counter<12); counter++)
                {
                  if (Car == Element[counter]) tmp = tmp + "Y";             /* Is the element a valid caracter of the array */
                }
              StrOk = StrOk + "Y";
            }
          if ((StrOk != tmp)||(Comma > 1))
            {
              //alert ("La zone n'est pas numérique ! \n" +
              //       "Veuillez vérifier s'il n'y a pas des blancs \n" +
              //       "ou plusieurs virgules dans la zone s.v.p.");
              ZoneName.focus();
              //return("error");
              return false;
            }

          /* S'il y a une virgule, on isole la partie entière dans part1 */
          /* et la partie fractionnaire dans part2 */
         if (Comma==1)
           {
             putComma = 1;
             CommaPos = Scan(ZoneName.value,',');
             part1 = ZoneName.value.substring(0, CommaPos);
             part2 = ZoneName.value.substring(CommaPos+1,ZoneName.value.length);

             if (part2.length > 2)
               {
                 //alert("Veuillez entrer un maximum de 2 décimales!");
                 //return("error");
                 return false;
               }
             else if (part2.length == 1)
               {
                 part2 = part2 + "0";
               }
             else if (part2.length == 0)
               {
                 part2 = part2 + "00";
               }
    	    }
    	    /* Si pas de virgule, part2 = "00" et on vérifie si le montant n'est pas trop grand */
    	    else if (Comma==0)
            {
              part2 = "00";
              /*if (ZoneName.value.length > ZoneLength-3)
                {
                  alert("Le montant introduit est incorrect (1)");
                  ZoneName.focus();
                  return("error");
                }
              */
              part1 = ZoneName.value;
            }
          else
            {
              //alert("Le montant introduit est incorrect (2)");
              ZoneName.focus();
              //return("error");
              return false;
            }

          /* On regarde si la partie entière contient des "." ou pas si oui on les enlèves */
          if (points==1)
          {
            /* un point, on regarde si c'est bien formatté */
            var pointPos = Scan(part1,'.');
            var sPart1 = part1.substring(0,pointPos);
            var sPart2 = part1.substring(pointPos+1,part1.length);

            if (sPart2.length == 3)
            {
              /* ex: 10.000 */
              part1=""+sPart1+sPart2;
            }
            else if ((sPart2.length == 2) && (Comma==0))
            {
              /* ex: 10000.50 */
              part1=sPart1;
              part2=sPart2;
            }
            else
            {
              //alert("Le montant introduit est incorrect (3)");
              ZoneName.focus();
              //return("error");
              return false;
            }

          }
          else if ((points > 1))
          {
            /* Plus d'un point le montant est incorrect ou trop grand */
            //alert("Le montant introduit est incorrect (4)");
            ZoneName.focus();
            //return("error");
            return false;
          }

         if (part2=="00" && putComma == 0) ZoneName.value=""+part1;
         else
          {
            if (part1=="")
              {
                part1="0";
              }
            ZoneName.value=""+part1+","+part2;
          }


         return true;
        }

function Scan(string,caracter)
  {
    /* Utilisé dans checkeuro !! */
    var temp;
    var i=0;
    var car="e";

    if (string=="") return(true);

    temp=string;
    j=string.length;

    for(i=0;i<j;i++)
      {
        car=temp.substring(i,i+1);
        if (car==caracter) return(i);
      }

    return(-1);
  }

/********************************************/
/* function isInteger(myField,errMsg[,eOk]) */
/********************************************/
/* Renvoie true:
 *  si la valeur du champs 'myField' est un nombre
 *  si le champs est vide ET que 'eOk' == true
 *  false sinon
 */

function isInteger(myField,errMsg) {

 s = myField.value; //récupère la valeur du champs
 s = trim(s);
 if(isEmpty(s)) {
  if(isInteger.arguments.length == 2) {
   alert(errMsg);
   myField.focus();
   return (false);
  } else {
   return (isInteger.arguments[2] == true);
  }
 }

 for (var i = 0; i < s.length; i++) {
  var c = s.charAt(i);
  if((c < "0") || (c > "9"))
    {
      myField.focus();
      alert(errMsg);
      return (false);
    }
 }

 return (true);
}

function isEmpty(s) {
 return ((s == null) || (s.length == 0));
}

// ----------------------------------
// function checkDate(myFields[,errMsg])
// ----------------------------------
// Vérifie si une date est valide
// IN:  Une *chaine* contenant le début du nom des champs contenant le jour, mois, année
//      exemple: DANAIJJ, DANAIMM, DANAIYY ==> "DANAI"
//      Le message d'erreur
// OUT: True si la date est ok
//      False sinon + alert de "errMsg" + mise à blanc des champs
    function WRONGcheckDate(myFields,errMsg)
      {
        myDay=eval(myFields+"JJ");
        myMonth=eval(myFields+"MM");
        myYear=eval(myFields+"AA");

        var testDate=new Date(myYear.value,myMonth.value,myDay.value); //on crée une date en via le constructeur javascript
        var testAnnee= testDate.getYear();
          if ((Math.abs(testAnnee)+"").length < 4) testAnnee = testAnnee + 1900; //on ajuste l'année qui n'est pas toujours à la bonne longueur à cause du bug de l'an 2000
        validDate = ((testDate.getDate() == myDay.value) && (testDate.getMonth() == myMonth.value) && (testAnnee == myYear.value)); //si la date générée est la meme que la date entrée, c'est une date valide!

        if (!validDate)
          {
            myDay.focus();
            if (errMsg.length>0)
              alert(errMsg);
            myDay.value="";
            myMonth.value="";
            myYear.value="";
            return false;
          }
        return true;
      }

    function checkDate(myFields,errMsg)
      {
        myDay=eval(myFields+"JJ");
        myMonth=eval(myFields+"MM");
        myYear=eval(myFields+"AA");

        //var errMsg="Veuillez entrer une date valide...";
        if(checkDate.arguments.length == 2) {
          errMsg=checkDate.arguments[1]
        } else {
          errMsg="";
        }

        //Test si pas de champs vide
        //!!!Attention au "defaults" de la fonction isDate...
        if ((myDay.value=="")||(myMonth.value=="")||(myYear.value==""))
          {
            if (errMsg.length>0)
              alert(errMsg);
            myDay.focus();
            return false;
          }

        //Test date
        if (!isDate(myDay.value,myMonth.value,myYear.value))
          {
            myDay.focus();
            if (errMsg.length>0)
              alert(errMsg);
            myDay.value="";
            myMonth.value="";
            myYear.value="";
            return false;
          }
        return true;
      }


/********************************************/
/* function isDate (day,month,year)         */
/********************************************/
/* Renvoie true:
 *  si la date est bonne :-D
 *  false sinon
 */
/*
function y2k(number) { return (number < 1000) ? number + 1900 : number; }
function isDate (day,month,year) {
  */
// checks if date passed is valid
// will accept dates in following format:
// isDate(dd,mm,ccyy), or
// isDate(dd,mm) - which defaults to the current year, or
// isDate(dd) - which defaults to the current month and year.
// Note, if passed the month must be between 1 and 12, and the
// year in ccyy format.
/*    var today = new Date();
    year = ((!year) ? y2k(today.getYear()):year);
    month = ((!month) ? today.getMonth():month-1);
    if (!day) return false
    var test = new Date(year,month,day);
    if ( (y2k(test.getYear()) == year) &&
         (month == test.getMonth()) &&
         (day == test.getDate()) )
        return true;
    else
        return false
}
*/
// ----------------------------------
// ***OLD*** isDate	(dd, mm, yyyy)
// ----------------------------------
// Retourne true si la date est valide.

function isDate(dd, mm, yyyy) {
	if (!isInteger2(dd) || !isInteger2(mm) || !isInteger2(yyyy)) {	return (false);	}

	if (dd < 1 || dd > 31) { return (false); }
	if (mm < 1 || mm > 12) { return (false); }
	if ((yyyy.toString()).length != 4) { return (false); }
	if ((mm==4 || mm==6 || mm==9 || mm==11) && dd==31) { return (false); }

	if (mm == 2) {
		var isleap = (yyyy % 4 == 0 && (yyyy % 100 != 0 || yyyy % 400 == 0));
		if (dd > 29 || (dd==29 && !isleap)) {
			return false;
		}
	}

	return (true);
}

// ----------------------------------
// getStandardDate(dd, mm, yyyy)
// ----------------------------------
// Retourne une date au format standard (yyyymmdd).

function getStandardDate(dd, mm, yyyy) {
	if (!isDate(dd, mm, yyyy)) {
		return (false);
	} else {
		if ((dd.toString()).length == 1) { dd = '0' + dd;	}
		if ((mm.toString()).length == 1) { mm = '0' + mm;	}

		return (yyyy.toString() + mm.toString() + dd.toString());
	}
}


// ----------------------------------
// getStandardHour(ss, mm, hh)
// ----------------------------------
// Retourne une heure au format standard (hhmmss).

function getStandardHour(ss, mm, hh) {
	if (!isSecond(ss) || !isMinute(mm) || !isHour(hh)) {
		return (false);
	} else {
		if ((ss.toString()).length == 1) { ss = '0' + ss;	}
		if ((mm.toString()).length == 1) { mm = '0' + mm;	}
		if ((hh.toString()).length == 1) { hh = '0' + hh;	}

		return (hh.toString() + mm.toString() + ss.toString());
	}
}

    // ----------------------------------
    // isSecond(ss)
    // ----------------------------------
    //
    function isSecond(ss) {
    	return (!((ss<0) || (ss>60)))
    }

    // ----------------------------------
    // isMinute(mm)
    // ----------------------------------
    //
    function isMinute(mm) {
    	return (!((mm<0) || (mm>60)))
    }

    // ----------------------------------
    // isHour(hh)
    // ----------------------------------
    //
    function isHour(hh) {
    	return (!((hh<0) || (hh>24)))
    }


// ----------------------------------
// compareDate(date1, date2, sign)
// ----------------------------------
// Comparaison de deux dates au format standard.
// Le champ sign détermine le type de comparaison, et peut avoir
// les valeurs suivantes: "<", "<=", ">", ">=", "=".

function compareDate(date1, date2, sign) {
	if (date1.length!=8) { return (false); }
	if (date2.length!=8) { return (false); }

	switch (sign) {
		case '<' :
			if (date1 >= date2) { return (false); }
			break;
		case '<=' :
			if (date1 > date2)  { return (false); }
			break;
		case '>' :
			if (date1 <= date2) { return (false); }
			break;
		case '>=' :
			if (date1 < date2)  { return (false); }
			break;
		case '=' :
			if (date1 != date2) { return (false); }
			break;
		default :
			return (false);
			break;
	}

	return (true);
}


// ----------------------------------
// getSystemDate()
// ----------------------------------
// Retourne la date système au format standard (yyyymmdd).

function getSystemDate() {
	return (getStandardDate(getCurrentDay(), getCurrentMonth(), getCurrentYear()));
}


// ----------------------------------
// getSystemTime()
// ----------------------------------
// Retourne l'heure système au format standard (hhmm).

function getSystemTime() {
	var hh = getCurrentHours();
	var mm = getCurrentMinutes();
	var ss = getCurrentSeconds();
	return (hh.toString() + mm.toString() + ss.toString());
}


// ----------------------------------
// getCurrentYear()
// ----------------------------------
// Retourne l'année courante.

function getCurrentYear() {
	var today = new Date();
	today = today.getYear();
	return (today < 1900 ? 1900 + today : today);
}


// ----------------------------------
// getCurrentMonth()
// ----------------------------------
// Retourne le mois de l'année courante (01-12).

function getCurrentMonth() {
	var today = new Date();
	today = today.getMonth() + 1;
	return (today < 10 ? '0' + today : today);
}


// ----------------------------------
// getCurrentDay()
// ----------------------------------
// Retourne le jour du mois courant (01-31).

function getCurrentDay() {
	var today = new Date();
	today = today.getDate()
	return (today < 10 ? '0' + today : today);
}


// ----------------------------------
// getCurrentHours()
// ----------------------------------
// Retourne l'heure du jour courant (00-23).

function getCurrentHours() {
	var today = new Date();
	today = today.getHours();
	return (today < 10 ? '0' + today : today);

}


// ----------------------------------
// getCurrentMinutes()
// ----------------------------------
// Retourne le nombre de minutes de l'heure courante (00-59).

function getCurrentMinutes() {
	var today = new Date();
	today = today.getMinutes();
	return (today < 10 ? '0' + today : today);
}


// ----------------------------------
// getCurrentSeconds()
// ----------------------------------
// Retourne le nombre de secondes de la minute courante (00-59).

function getCurrentSeconds() {
	var today = new Date();
	today = today.getSeconds();
	return (today < 10 ? '0' + today : today);
}