// JavaScript Document

// masque champs date
function masque(obj) {
var ch;
var ch_gauche, ch_droite;

ch = obj.value;
ch.toString(); 

if ( ( (ch.slice(2,3)) != ("/") ) && (ch.length >= 3) ){
  ch_gauche = ch.slice(0,2);
  ch_droite = ch.slice(2);
  obj.value = ch_gauche + "/" + ch_droite;
}
if ( ( (ch.slice(5,6)) != ("/") ) && (ch.length >= 6) ){
  ch_gauche = ch.slice(0,5);
  ch_droite = ch.slice(5);
  obj.value = ch_gauche + "/" + ch_droite;
}
  return;
}

/*
=============================================
LTrim(string) : Enleve les espaces à gauche
==============================================
*/
function LTrim(str)
/*
   PURPOSE: Remove leading blanks from our string.
   IN: str - the string we want to LTrim
*/
{
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(0)) != -1) {
      // We have a string with leading blank(s)...

      var j=0, i = s.length;

      // Iterate from the far left of string until we
      // don't have any more whitespace...
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;

      // Get the substring from the first non-whitespace
      // character to the end of the string...
      s = s.substring(j, i);
   }
   return s;
}

/*
=============================================
RTrim(string) :  Enleve les espaces à droite
==============================================
*/
function RTrim(str)
/*
   PURPOSE: Remove trailing blanks from our string.
   IN: str - the string we want to RTrim

*/
{
   // We don't want to trip JUST spaces, but also tabs,
   // line feeds, etc.  Add anything else you want to
   // "trim" here in Whitespace
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
      // We have a string with trailing blank(s)...

      var i = s.length - 1;       // Get length of string

      // Iterate from the far right of string until we
      // don't have any more whitespace...
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i--;


      // Get the substring from the front of the string to
      // where the last non-whitespace character is...
      s = s.substring(0, i+1);
   }

   return s;
}

/*
========================================
Trim(string) : Enleve tous les espaces
=========================================
*/
function Trim(str)
/*
   PURPOSE: Remove trailing and leading blanks from our string.
   IN: str - the string we want to Trim

   RETVAL: A Trimmed string!
*/
{
   return RTrim(LTrim(str));
}


function checkdate(da) {
  // Cette fonction permet de vérifier la validité d'une date au format jj/mm/aa ou jj/mm/aaaa
  d=da.value;
  
  if (d == "") // si la variable est vide on retourne faux
    return true;
  
  e = new RegExp("^[0-9]{1,2}\/[0-9]{1,2}\/([0-9]{2}|[0-9]{4})$");
  
  if (!e.test(d)) // On teste l'expression régulière pour valider la forme de la date
    return false; // Si pas bon, retourne faux

  // On sépare la date en 3 variables pour vérification, parseInt() converti du texte en entier
  j = parseInt(d.split("/")[0], 10); // jour
  m = parseInt(d.split("/")[1], 10); // mois
  a = parseInt(d.split("/")[2], 10); // année
  
  // Si l'année n'est composée que de 2 chiffres on complète automatiquement
  if (a < 1000) {
    if (a < 89)  a+=2000; // Si a < 89 alors on ajoute 2000 sinon on ajoute 1900
    else a+=1900;
  }

  // Définition du dernier jour de février
  // Année bissextile si annnée divisible par 4 et que ce n'est pas un siècle, ou bien si divisible par 400
  if (a%4 == 0 && a%100 !=0 || a%400 == 0) fev = 29;
  else fev = 28;

  // Nombre de jours pour chaque mois
  nbJours = new Array(31,fev,31,30,31,30,31,31,30,31,30,31);

  // Enfin, retourne vrai si le jour est bien entre 1 et le bon nombre de jours, idem pour les mois, sinon retourn faux
  return ( m >= 1 && m <=12 && j >= 1 && j <= nbJours[m-1] );
}

//fonction champ obligatoire
function oblig(obj) {
if (Trim(obj.value) < 1) {
return false;
}
}


// fonction de clignotement de texte

function clignotement(elem){ 
    if (document.getElementById(elem).color =="#728194") 
       document.getElementById(elem).color="#FF0000"; 
    else 
       document.getElementById(elem).color="#728194"; 
	   
}

//  End -->