﻿  // current Date
  var toDay, thisYear, thisMonth, thisDate, thisHour, thisMin;
  var days = new Array("Lundi","Mardi","Mercredi","Jeudi","Vendredi","Samedi","Dimanche");
  var months = new Array("Janvier","Février","Mars","Avril","Mai","Juin","Juillet","Aût","Septembre","Octobre","Novembre","Décembre");
  //var days = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
  //var months = new Array("January","February","March","April","May","June","July","August","September","October","November","December");

  toDay = new Date(); 
  thisMonth = format0X(toDay.getMonth() + 1);
  thisDate = format0X(toDay.getDate());
  thisYear = toDay.getFullYear();
  //thisYear = toDay.getYear();
  //if (thisYear < 2000) thisYear += 1900;
  thisHour = format0X(toDay.getHours());
  thisMin = format0X(toDay.getMinutes());
  // setValues("" + thisDate+thisMonth+thisYear+thisHour+thisMin,"amblDatetime_", 12, "");

  // date of last update
  var lastUpdate = document.lastModified;
  var dateObj = new Date(document.lastModified);
  var lday = days[dateObj.getDay() + 1];
  var lmonth = months[dateObj.getMonth() + 1];
  var ldate = dateObj.getDate();
  var lyear = dateObj.getFullYear();
  
 function getRandom() {
  var toDay = new Date(); 
  return ""+format0X(toDay.getHours())+format0X(toDay.getMinutes())+format0X(toDay.getSeconds());
 }

  function format0X(numVal) { return (numVal<10)?("0" + numVal):numVal; }

  function getCurrDate() {
    var toDay = new Date(); // current Date
    thisMonth = format0X(toDay.getMonth() + 1);
    thisDate = format0X(toDay.getDate());
    thisYear = toDay.getFullYear();
    thisHour = format0X(toDay.getHours());
    thisMin = format0X(toDay.getMinutes());
   }

// check date for format "DD/MM/YYYY"
// returns date or -1 if the date isn't valid
function checkDate(strDate) {
  var i,j,lenStr,month,day,year,ch,oddYear;
  strDate = replaceSTR(strDate," ","");
  if (strDate=="") return "";
  lenStr=strDate.length;
  
  if ((lenStr>10) || (lenStr<5)) return -1;
  month=0;
  day=0;
  year=0; 
  oddYear=false;
  i=0;
  j=0;
  while (i < lenStr) {
     ch=strDate.charAt(i);
     if ((ch=='.') || (ch=='/')) { 
        day=strToInt(strDate.substring(j,i));
        j=++i;
        break;
      }
     i++;
   }
  if ((day>31) || (day<1))  return -1; 

  while (i < lenStr) {
     ch=strDate.charAt(i);
     if ((ch=='.') || (ch=='/')) { 
        month=strToInt(strDate.substring(j,i));
        break;
      }
     i++;
   }
  if ((month>12) || (month<1))  return -1; 

  year=strToInt(strDate.substring(++i));
  if (year<0)  return -1; 
  if (year<100) 
   if (year>90) year+=1900;
     else year+=2000; 

  if (((year % 4)==0) && (((year % 100)!=0) || ((year % 400)==0))   ) oddYear=true;

  if ( ((month==4) || (month==6) || (month==9) || (month==11)) && (day>30)) return -1;
  if (month==2) 
    if (oddYear) { if (day>29) return -1; }
     else if (day>28) return -1;
  if (month<10) month="0"+month;
  if (day<10) day="0"+day;
  return day+"/"+month+"/"+year;
}

// check date field for validity. Empty strings are right. 
function checkFieldDate(strField) { 
   var fieldObj = eval("document." + strField);
   var strDate = checkDate(fieldObj.value);
   if (strDate==-1) {
      alert("  Format de la date incorrect! Suivez le modèle  'JJ/MM/AA[AA]' !  ");
	  fieldObj.focus();
      return false;
     }
   fieldObj.value = strDate; 
   return true;
 }

// check date field for validity. Empty strings are not right. 
function checkFieldDateMandatory(strField) { 
   var fieldObj = eval("document." + strField);
   var strDate = checkDate(fieldObj.value);
   if ((strDate==-1) || (strDate=="")) {
	  if (strDate=="") alert("  La date est obligatoire!  ");
	   else alert("  Format de la date incorrect! Suivez le modèle  'JJ/MM/AA[AA]' !  ");
	  fieldObj.focus();
      return false;
     }
   fieldObj.value = strDate; 
   return true;
 }

// check date field for validity. Empty strings are not right. 
function checkFieldDateMandatory1(strField) { 
   var fieldObj = eval("document." + strField);
   var strDate = checkDateMMDD(fieldObj.value);
   if ((strDate==-1) || (strDate=="")) {
	  if (strDate=="") alert("  La date est obligatoire!  ");
	   else alert("  Format de la date incorrect! Suivez le modèle 'JJ/MM/AA[AA]' !  ");
	  fieldObj.focus();
      return false;
     }
   fieldObj.value = strDate; 
   return true;
 }

// check date field for validity. Empty strings are not right. 
function checkFieldDateMandat(strField) { 
   var fieldObj = eval("document." + strField);
   var strDate = checkDate(fieldObj.value);
   if ((strDate==-1) || (strDate=="")) return false;
   fieldObj.value = strDate; 
   return true;
 }

// check date for format "MM/DD/YYYY"
// returns date or -1 if the date isn't valid
function checkDateMMDD(strDate) {
  var i,j,lenStr,month,day,year,ch,oddYear;
  strDate = replaceSTR(strDate," ","");
  if (strDate=="") return "";
  lenStr=strDate.length;
  
  if ((lenStr>10) || (lenStr<5)) return -1;
  month=0;
  day=0;
  year=0; 
  oddYear=false;
  i=0;
  j=0;
  while (i < lenStr) {
     ch=strDate.charAt(i);
     if ((ch=='.') || (ch=='/')) { 
        month=strToInt(strDate.substring(j,i));
        j=++i;
        break;
      }
     i++;
   }
  if ((month>12) || (month<1))  return -1; 

  while (i < lenStr) {
     ch=strDate.charAt(i);
     if ((ch=='.') || (ch=='/')) { 
        day=strToInt(strDate.substring(j,i));
        break;
      }
     i++;
   }
  if ((day>31) || (day<1))  return -1; 

  year=strToInt(strDate.substring(++i));
  if (year<0)  return -1; 
  if (year<100) 
   if (year>90) year+=1900;
     else year+=2000; 

  if (((year % 4)==0) && (((year % 100)!=0) || ((year % 400)==0))   ) oddYear=true;

  if ( ((month==4) || (month==6) || (month==9) || (month==11)) && (day>30)) return -1;
  if (month==2) 
    if (oddYear) { if (day>29) return -1; }
     else if (day>28) return -1;
  if (month<10) month="0"+month;
  if (day<10) day="0"+day;
  return month+"/"+day+"/"+year;
}

function my_parseInt(str) {
 var chrTemp, strl = str.length;
 var found = false;
 for (var i=0; i<strl; i++) {
  chrTemp = str.charAt(i);
  if ((chrTemp>'0') && (chrTemp<='9')) {
     found = true;
     break;
   }
 }

 if (found) return parseInt(str.substring(i));
  else return 0;
}

function checkDatesLess(strDate1, strDate2) {
 var y1 = my_parseInt(strDate1.substring(6)); 
 var y2 = my_parseInt(strDate2.substring(6)); 
 var m1 = my_parseInt(strDate1.substring(3,5)); 
 var m2 = my_parseInt(strDate2.substring(3,5)); 
 var d1 = my_parseInt(strDate1.substring(0,2)); 
 var d2 = my_parseInt(strDate2.substring(0,2)); 
 if (y1<y2) return 1;
  else if (y1>y2) return -1;
  else if (m1<m2) return 1;
  else if (m1>m2) return -1;
  else if (d1<d2) return 1;
  else if (d1>d2) return -1;
   return 0;
}

// it returns the differ between two dates in number of days
function datesDiffer(strDate1, strDate2) { 
   var lngTemp=((Date.parse(strDate1)-Date.parse(strDate2))/(24*60*60*1000))
   if (lngTemp<1) {
      alert("  'from' date must be litle than 'to' date !  ");
      return -1;
    }
   return lngTemp;
 }
   
  function getLastDay(m, y) {
	 dayS = 31;
     if ((m==4) || (m==6) || (m==9) || (m==11)) dayS = 30;
     if (m==2)
      if (((y % 4)==0) && (((y % 100)!=0) || ((y % 400)==0))) dayS = 29;
	   else dayS = 28;
	}

 function convertDate(strDate) {
  var d = strDate;
  return d.substring(3,5) + "/" + d.substring(0,2) + "/" + d.substring(6,10);
 }   
 function convertDateDDMMYYY(strDate) {
  var d = strDate;
  return d.substring(0,2) + "/" + d.substring(2,4) + "/" + d.substring(4,8);
 }   