
function tableau() {
  this.length = tableau.arguments.length
  for (var i = 0; i < this.length; i++)
  this[i+1] = tableau.arguments[i]
}

var tablJour = new tableau("Dimanche","Lundi","Mardi","Mercredi","Jeudi","Vendredi","Samedi");
var tablMois = new tableau("Janvier","F&eacute;vrier","Mars","Avril","Mai","Juin","Juillet","Ao&ucirc;t","Septembre","Octobre","Novembre","D&eacute;cembre");
var DateJour = new Date();

function date() {
  document.write(tablJour[(DateJour.getDay()+1)]," ",DateJour.getDate()," ");
  document.write(tablMois[(DateJour.getMonth()+1)]," ");
  if (!document.all) {
    document.write((DateJour.getFullYear()));
  } else {
    document.write(DateJour.getFullYear());
  }
  document.write("&nbsp;&nbsp;");
}

function dateShort() {
  document.write(tablJour[(DateJour.getDay()+1)]," ",DateJour.getDate()," ");
  document.write(tablMois[(DateJour.getMonth()+1)]);
}

function time() {
  document.write(DateJour.getHours(),":",DateJour.getMinutes());
}

function TestTime(strTime)
{
// format testé 00:00:00
  re = /^(\d{1,2}):(\d{1,2}):?(\d{1,2})?$/;
  MyArray = re.exec(strTime);
  if (!MyArray) return false;
  iHou = MyArray[1];
  iMin = MyArray[2];
  if (MyArray.length > 3) {
    iSec = MyArray[3];
    if (iSec < 0 && iSec > 59) return false;
  }
  if (iHou < 0 || iHou > 23) return false;
  if (iMin < 0 && iMin > 59) return false;
  return true;
}

function checkDate(iDay, iMonth, iYear) {
  if (iMonth < 1 || iMonth > 12) return false;
  if (iMonth == 2 && iDay > 28) {
    if (iYear%4 != 0) return false;
    if (iDay > 29) return false;
  } else
  if ((iMonth == 4 || iMonth == 6 || iMonth == 9 || iMonth == 11) && iDay > 30) {
    return false;
  } else
  if (iDay > 31) return false;
  return true;
}

function TestDate(strDate)
{
 // format testé AAAA-MM-JJ HH:MM:SS
  re = /^(\d{4})-(\d{2})-(\d{2})\s?(\d{1,2}:\d{1,2}:\d{1,2})?$/;
  MyArray = re.exec(strDate);
  if (MyArray) {
    iDay = Number(MyArray[3]);
    iMonth = Number(MyArray[2]);
    iYear = Number(MyArray[1]);
    if (!checkDate(iDay, iMonth, iYear)) return false;
    if (MyArray[4]) if (!TestTime(MyArray[4])) return false;
    return true;
  }
// format testé JJ/MM/AAAA
  re1 = /^(\d{1,2})[- \/](\d{1,2})[- \/](\d{2}|\d{4})$/;
  MyArray = re1.exec(strDate);
  if (MyArray) {
    iDay = Number(MyArray[1]);
    iMonth = Number(MyArray[2]);
    iYear = Number(MyArray[3]);
    if (!checkDate(iDay, iMonth, iYear)) return false;
    return true;
  }
  return false;
}

function SetDateToSql(strDate) {
  if (!TestDate(strDate)) return false;
  sDate = strDate;
  re1 = /^(\d{1,2})[- \/](\d{1,2})[- \/](\d{2}|\d{4})$/;
  MyArray = re1.exec(strDate);
  if (MyArray) {
    iYear = Number(MyArray[3]);
    if (iYear < 100) iYear+=2000;
    iMonth = Number(MyArray[2]);
    sMonth = (iMonth < 10) ? "0"+iMonth : String(iMonth);
    iDay = Number(MyArray[1]);
    sDay = (iDay < 10) ? "0"+iDay : String(iDay);
    sDate = String(iYear)+"-"+sMonth+"-"+sDay;
  }
  return sDate;
}

function TestDateFR(strDate)
{ // format testé : date francaise JJ/MM/AAAA
  re1 = /^(\d{1,2})[- \/](\d{1,2})[- \/](\d{2}|\d{4})$/;
  MyArray = re1.exec(strDate);
  if (MyArray) {
    iDay = Number(MyArray[1]);
    iMonth = Number(MyArray[2]);
    iYear = Number(MyArray[3]);
    if (!checkDate(iDay, iMonth, iYear)) return false;
    return true;
  }
  return false;
}

function SetFRDateToSql(strDate) {
//Passe une date francaise 28/04/1977 en date 1977-04-28 - Modif Dam accepte JJMMAA(AA)
  //if (!TestDateFR(strDate)) return strDate;
  sDate = strDate;
  re1 = /^(\d{1,2})[- \/](\d{1,2})[- \/](\d{2}|\d{4})$/;
  MyArray = re1.exec(strDate);
  bFormatOK = false;
  if (MyArray) {
    iYear = Number(MyArray[3]);
    iMonth = Number(MyArray[2]);
    iDay = Number(MyArray[1]);
    bFormatOK = true;
  } else {
    re1 = /^(\d{2})(\d{2})(\d{2}|\d{4})$/;
    MyArray = re1.exec(strDate);
    if (MyArray) {
      iYear = Number(MyArray[3]);
      iMonth = Number(MyArray[2]);
      iDay = Number(MyArray[1]);
      bFormatOK = true;
    }
  }
  if (!bFormatOK) return strDate;
  if (!checkDate(iDay, iMonth, iYear)) return strDate;
  if (iYear < 100) iYear+=2000;
  sMonth = (iMonth < 10) ? "0"+iMonth : String(iMonth);
  sDay = (iDay < 10) ? "0"+iDay : String(iDay);
  sDate = String(iYear)+"-"+sMonth+"-"+sDay;
  return sDate;
}

function SetSqlDateToFrDat(strDate) {
//Passe une date sql courte 1977-04-28 en date francaise courte 28/04/1977
  if (!TestDate(strDate)) return strDate;
  sDate = strDate;
  re1 = /^(\d{4})[- \/](\d{1,2})[- \/](\d{2}|\d{1,2})$/;
  MyArray = re1.exec(strDate);
  if (MyArray) {
    iYear = Number(MyArray[1]);
    if (iYear < 100) iYear+=2000;
    iMonth = Number(MyArray[2]);
    sMonth = (iMonth < 10) ? "0"+iMonth : String(iMonth);
    iDay = Number(MyArray[3]);
    sDay = (iDay < 10) ? "0"+iDay : String(iDay);
    sDate = sDay+"/"+sMonth+"/"+String(iYear);
  }
  return sDate;
}

function SetFullSqlDateToFrDat(strDate) {
//Passe une date sql longue 1977-04-28 00:00:00 en date francaise courte 28/04/1977
  if (!TestDate(strDate)) return strDate;
  sDate = strDate;
  adat = (strDate.split(" "))[0];
  strDate=adat;
  re1 = /^(\d{4})[- \/](\d{1,2})[- \/](\d{2}|\d{1,2})$/;
  MyArray = re1.exec(strDate);
  if (MyArray) {
    iYear = Number(MyArray[1]);
    if (iYear < 100) iYear+=2000;
    iMonth = Number(MyArray[2]);
    sMonth = (iMonth < 10) ? "0"+iMonth : String(iMonth);
    iDay = Number(MyArray[3]);
    sDay = (iDay < 10) ? "0"+iDay : String(iDay);
    sDate = sDay+"/"+sMonth+"/"+String(iYear);
  }
  return sDate;
}

function SetFullSqlDateToFullFrDat(strDate) {
//Passe une date sql longue 1977-04-28 00:00:00 en date francaise  28/04/1977 00:00:00
  if (!TestDate(strDate)) return strDate;
  sDate = strDate;
  adat = (strDate.split(" "))[0];
    aheure = (strDate.split(" "))[1];
  strDate=adat;
  re1 = /^(\d{4})[- \/](\d{1,2})[- \/](\d{2}|\d{1,2})$/;
  MyArray = re1.exec(strDate);
  if (MyArray) {
    iYear = Number(MyArray[1]);
    if (iYear < 100) iYear+=2000;
    iMonth = Number(MyArray[2]);
    sMonth = (iMonth < 10) ? "0"+iMonth : String(iMonth);
    iDay = Number(MyArray[3]);
    sDay = (iDay < 10) ? "0"+iDay : String(iDay);
    sDate = sDay+"/"+sMonth+"/"+String(iYear)+" "+aheure;
  }
  return sDate;
}

function GetSqlDat(strDate){
//date sql -> Date sql sans l'heure
  adat = (strDate.split(" "))[0];
  return adat;
}

function GetSqlHeure(strDate){
//date sql (2000-28-04 09:12:25) -> heure (09:12:25)
  adat = (strDate.split(" "))[1];
  return adat;
}

function GetTime(strDate){
//date -> heure
  adat = (strDate.split(" "))[1];
  return adat;
}

function GetCurDate() {
//Date courante
  d = new Date();
  iYear = Number(d.getYear()); if (iYear < 100) iYear+=2000;
  iMonth = Number(d.getMonth())+1; sMonth = (iMonth < 10) ? "0"+iMonth : String(iMonth);
  iDay = Number(d.getDate());  sDay = (iDay < 10) ? "0"+iDay : String(iDay);
  iHour = Number(d.getHours());  sHour = (iHour < 10) ? "0"+iHour : String(iHour);
  iMn = Number(d.getMinutes());  sMn = (iMn < 10) ? "0"+iMn : String(iMn);
  iSec = Number(d.getSeconds());  sSec = (iSec < 10) ? "0"+iSec : String(iSec);
  df = String(iYear)+"-"+sMonth+"-"+sDay+" "+sHour+":"+sMn+":"+sSec;
  return df;
}

function AddTimeToDate(addTime) {
//addTime est une valeur en semaines
  dat = new Date();
  dateInMs = dat.getTime();
  dateInMs += (addTime*7*24*3600*1000) ;
  d = new Date(dateInMs)
  iYear = Number(d.getYear()); if (iYear < 100) iYear+=2000;
  iMonth = Number(d.getMonth())+1; sMonth = (iMonth < 10) ? "0"+iMonth : String(iMonth);
  iDay = Number(d.getDate());  sDay = (iDay < 10) ? "0"+iDay : String(iDay);
  iHour = Number(d.getHours());  sHour = (iHour < 10) ? "0"+iHour : String(iHour);
  iMn = Number(d.getMinutes());  sMn = (iMn < 10) ? "0"+iMn : String(iMn);
  iSec = Number(d.getSeconds());  sSec = (iSec < 10) ? "0"+iSec : String(iSec);
  df = String(iYear)+"-"+sMonth+"-"+sDay+" "+sHour+":"+sMn+":"+sSec;
  return df;
}
//function quicksearch2(){
   //document.quicksearch.lettre.value = 'rechercherArticles';
   //document.quicksearch.submit();
//}

function quicksearch2(){
   var chaine = document.kwForm2.chaine.value;
   if(chaine.length < 2) {
      alert("Vous devez saisir au moins deux caractères");
      return;
   }
   for(i=0; i<chaine.length; i++) {
        var c = chaine.charAt(i);
        if(!estUneLettre(c)) {
           alert("Vous ne devez saisir que des caractères de type lettre");
           return;
        }
   }
   document.kwForm2.mode.value = "fullText";
   document.kwForm2.submit();
}

function googleSearch() {
   var chaine = document.kwForm2.q.value;
   if(chaine.length == 0) {
      alert("Vous devez saisir au moins un caractère");
      return;
   }
   document.kwForm2.submit();
      
}

function googleSearch2() {
   var chaine = document.kwForm3.q.value;
   if(chaine.length == 0) {
      alert("Vous devez saisir au moins un caractère");
      return;
   }
   document.kwForm3.submit();
      
}

function estUneLettre(c) {
     return ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z')
                || c == 'é' || c == 'è' || c == 'ê' || c == 'ë' || c == 'à' || c == 'ô' || c == 'ù' || c == 'ç' || c == 'û' || c == 'î'
                || c == 'É' || c == 'È' || c == 'Ê' || c == 'Ë' || c == 'À' || c == 'Ô' || c == 'Ù' || c == 'Ç' || c == 'Û' || c == 'Î';
}
