function fctDecFormat(pwNb,nbDec){
 return (Math.round(parseInt(pwNb * Math.pow(10,((nbDec - 0) + 1)),10) / 10) / Math.pow(10,nbDec));
}

function fctDateFormat(pDay, pMonth, pYear){
 var lDay = pDay.toString(), lMonth = (pMonth + 1).toString(), lYear = pYear.toString();
 if (lDay.length == 1) lDay = "0" + lDay;
 if (lMonth.length == 1) lMonth = "0" + lMonth;
 return lDay + "/" + lMonth + "/" + lYear;
}

function fstrDateCheckFormat(TDate,pintDateInf){
 var ErrMsg, lstrRes2, ThisYear;
 var TDayIn, TMonthIn, TYearIn, TestDate;
 var LenTDayIn, LenTMonthIn, LenTYearIn;
 var Mindice, Yindice;
 var ldatCurrent;
 var lintDateInf=pintDateInf;
 ErrMsg = "";
 lstrRes2 = "";
 Mindice = 0;
 Yindice = 0;
 if (TDate.length < 3) {
    ErrMsg = "Date Invalide, Format: Jour Séparateur Mois (Séparateur Année)";
    return [ErrMsg,lstrRes2];
 }
 TDayIn = TDate.substring(0, 2);
 if (isNaN(parseInt(TDayIn))) {
    ErrMsg = "Date Invalide, Format: Jour Séparateur Mois (Séparateur Année)";
    return [ErrMsg,lstrRes2];
 }
 if ((TDayIn.charAt(0) == "0") || (TDayIn.charAt(0) == " ")) {
    Mindice = 1;
    TDayIn = TDayIn.charAt(1);
 }
 TDayIn = (parseInt(TDayIn,10)).toString();
 LenTDayIn = TDayIn.length;
 if (LenTDayIn == 1)  {
    TDayIn = "0" + TDayIn;
 }
 Mindice = Mindice + LenTDayIn + 2;
 if (!(isNaN(parseInt(TDate.charAt(Mindice - 2),10)))) {
    ErrMsg = "Date Invalide, Format: Jour Séparateur Mois (Séparateur Année)";
    return [ErrMsg,lstrRes2];
 }
 TMonthIn = TDate.substring(Mindice - 1, Mindice + 1);
 if (isNaN(parseInt(TMonthIn,10))) {
    ErrMsg = "Date Invalide, Format: Jour Séparateur Mois (Séparateur Année)";
    return [ErrMsg,lstrRes2];
 }
 if ((TMonthIn.charAt(0) == "0") || (TMonthIn.charAt(0) == " ")) {
    Yindice = 1;
    TMonthIn = TMonthIn.charAt(1);
 }
 TMonthIn = (parseInt(TMonthIn,10)).toString();
 LenTMonthIn = TMonthIn.length;
 if (LenTMonthIn == 1)  {
    TMonthIn = "0" + TMonthIn;
 }
 Yindice = Yindice + Mindice + LenTMonthIn + 1;
 if (!(isNaN(parseInt(TDate.charAt(Yindice - 2),10)))) {
    ErrMsg = "Date Invalide, Format: Jour Séparateur Mois (Séparateur Année)";
    return [ErrMsg,lstrRes2];
 }
 TYearIn = TDate.substring(Yindice - 1, Yindice + 3);
 if (TYearIn.length != 0) {
    if (isNaN(parseInt(TYearIn,10))) {
        ErrMsg = "Date Invalide, Format: Jour Séparateur Mois (Séparateur Année)";
        return [ErrMsg,lstrRes2];
    }
 }
 if (TYearIn.length == 0) {
    TYearIn = "";
 }
 else {
    TYearIn = fctTrimLeft(TYearIn);
 }
 LenTYearIn = TYearIn.length;
 ldatCurrent = new Date();
 ThisYear = ldatCurrent.getFullYear();
 if (LenTYearIn == 0) {
    TYearIn = ThisYear.toString();
 }
 if ((LenTYearIn == 1) || (LenTYearIn == 2) || (LenTYearIn == 3)) {
    var lstrYear = ThisYear.toString().substring(0, (4 - LenTYearIn)) + TYearIn;
    var lstrAddedPart = ThisYear.toString().substring(0, (4 - LenTYearIn));
    if (lintDateInf == 1) {
       if (parseInt(lstrYear,10) <= parseInt(ThisYear,10)) {
          TYearIn = ThisYear.toString().substring(0, (4 - LenTYearIn)) + TYearIn;
       }
       else {
          TYearIn = (parseInt(lstrAddedPart,10) - 1).toString() + TYearIn;
       }
    }
    else {
       if (parseInt(lstrYear,10) >= parseInt(ThisYear,10)) {
          TYearIn = ThisYear.toString().substring(0, (4 - LenTYearIn)) + TYearIn;
       }
       else {
          TYearIn = (parseInt(lstrAddedPart,10) + 1).toString() + TYearIn;
       }
    }
 }
 lstrRes2 = TDayIn + "/" + TMonthIn + "/" + TYearIn;
 TestDate = new Date(TYearIn,(TMonthIn - 1), TDayIn);
 if ((((TestDate.getDate()) - TDayIn) != 0) || (((TestDate.getMonth()) - TMonthIn) != -1) || (((TestDate.getFullYear()) - TYearIn) != 0)) {
    ErrMsg = "Date Invalide, Format: Jour Séparateur Mois (Séparateur Année)";
    return [ErrMsg,lstrRes2];
 }
 return [ErrMsg,lstrRes2];
}

function fctcompdate(pDate1,pDate2)
{
    var lYear1 = pDate1.substring(6, 10);
    var lMonth1 = pDate1.substring(3, 5);
    var lDay1 = pDate1.substring(0, 2);
    var lYear2 = pDate2.substring(6, 10);
    var lMonth2 = pDate2.substring(3, 5);
    var lDay2 = pDate2.substring(0, 2);
    
    var date1=lYear1+lMonth1+lDay1;
    var date2=lYear2+lMonth2+lDay2;
    
    if(parseInt(date1,10) < parseInt(date2,10)) return 1;
    else if(parseInt(date1,10) > parseInt(date2,10)) return -1;
    else if(parseInt(date1,10) == parseInt(date2,10)) return 0;
    
    return 0;
}

function fctcompheure(pheure1,pheure2)
{
    
    var lheure1  = pheure1.substring(0, 2);
    var lMinute1 = pheure2.substring(3, 5);
    var lheure2  = pheure2.substring(0, 2);
    var lMinute2 = pheure2.substring(3, 5);
    
    var heure1=lheure1+lMinute1;
    var heure2=lheure2+lMinute2;
    
    if(parseInt(heure1,10) < parseInt(heure2,10)) return 1;
    else if(parseInt(heure1,10) > parseInt(heure2,10)) return -1;
    else if(parseInt(heure1,10) == parseInt(heure2,10)) return 0;
    
    return 0;
    
}   


//function fctDateDiff : Retourne la différence (un nombre relatif) entre deux date (Unité de la différence : voir pstrRetNbOf)
//pstrDate1, pstrDate2 : Dates format ("dd/mm/yyyy")
//pstrRetNbOf : Unité désirée de la différence valeurs ("L" : Milli-secondes) ("S": Secondes) ("M": Minutes) ("H": Heures) (Autre ou absent: Jours)
//Remarque : Si Date1 > Date2 retour val < 0 (On peut utiliser Math.abs(Resultat) : Valeur absolue si vous voulez ignorer le sens de la difference)
function fctDateDiff(pstrDate1,pstrDate2,pstrRetNbOf) {
    //Date.parse(pstrDate2) déconne
    var lDate1 = new Date(parseInt(pstrDate1.substring(6, 10),10),parseInt(pstrDate1.substring(3, 5),10)-1,parseInt(pstrDate1.substring(0, 2),10));
    var lDate2 = new Date(parseInt(pstrDate2.substring(6, 10),10),parseInt(pstrDate2.substring(3, 5),10)-1,parseInt(pstrDate2.substring(0, 2),10));
    var lTime1 = lDate1.getTime();
    var lTime2 = lDate2.getTime();

    var lnbSecMilli = 1000;
    var lnbMinMilli = (lnbSecMilli * 60);
    var lnbHrMilli = (lnbMinMilli * 60);
    var lnbDyMilli = (lnbHrMilli * 24);
    var lnbTimeDiff;
    var lnbRes;

    if (!pstrRetNbOf) {
        pstrRetNbOf = "D";
    }
    pstrRetNbOf = pstrRetNbOf.toUpperCase();

    lnbTimeDiff = (lTime2 - lTime1);
    switch(pstrRetNbOf) {
        case "L":
            lnbRes = lnbTimeDiff;
            break;
        case "S":
            lnbRes = Math.round(lnbTimeDiff / lnbSecMilli);
            break;
        case "M":
            lnbRes = Math.round(lnbTimeDiff / lnbMinMilli);
            break;
        case "H":
            lnbRes = Math.round(lnbTimeDiff / lnbHrMilli);
            break;
        default :
            lnbRes = Math.round(lnbTimeDiff / lnbDyMilli);
    }
    return lnbRes;
}

function fstrHourCheckFormat(THour){
 var ErrMsg, lstrRes2;
 var THourIn, TMinIn;
 var LenTHourIn, LenTMinIn;
 var Mindice;
 ErrMsg = "";
 lstrRes2 = "";
 Mindice = 0;

 if (THour.length < 2) {
    ErrMsg = "Heure Invalide, Format: Heure Séparateur Minute";
    return [ErrMsg,lstrRes2];
 }
 
 THourIn = THour.substring(0, 2);
 if (isNaN(parseInt(THourIn,10))) {
    ErrMsg = "Heure Invalide, Format: Heure Séparateur Minute";
    return [ErrMsg,lstrRes2];
 }
 if ((THourIn.charAt(0) == " ")||(THourIn.charAt(0) == "0")) {
    Mindice = 1;
    THourIn = THourIn.charAt(1);
 }
 
 if (THourIn > 23) {
   ErrMsg = "Heure Invalide, Format: Heure < 24";
   return [ErrMsg,lstrRes2];
   }
 THourIn = (parseInt(THourIn,10)).toString(); 
 LenTHourIn = THourIn.length;
 if (LenTHourIn == 1)  {
    THourIn = "0" + THourIn;
    }
 Mindice = Mindice + LenTHourIn + 2;
 if (!(isNaN(parseInt(THour.charAt(Mindice - 2),10)))) {
    ErrMsg = "Heure Invalide, Format: Heure Séparateur Minute";
    return [ErrMsg,lstrRes2];
 }
 TMinIn = THour.substring(Mindice - 1, Mindice + 1);
 if (isNaN(parseInt(TMinIn,10))) {
    ErrMsg = "Heure Invalide, Format: Heure Séparateur Minute";
    return [ErrMsg,lstrRes2];
 }
 if (TMinIn.charAt(0) == " ") {
    Yindice = 1;
    TMinIn = TMinIn.charAt(1);
 }
 TMinIn = (parseInt(TMinIn,10)).toString();
 LenTMinIn = TMinIn.length;
 if (LenTMinIn == 1)  {
    TMinIn = "0" + TMinIn;
 }
 if (TMinIn > 59) {
    ErrMsg = "Minute Invalide, Format: Minute < 60";
    return [ErrMsg,lstrRes2];
 }

 lstrRes2 = THourIn + ":" + TMinIn;
 return [ErrMsg,lstrRes2];
}



/* fonction permettant de récupérer le dernier jour du mois month */
function fctLastDayInMonth(month,year) {    
    var dd = new Date(year, month, 0);
    return dd.getDate();
}