// Functions to check forms input

function ValidDate(y, m, d){ // m = 0..11
        with (new Date(y, m, d))
        return ((getMonth()==m) && (getDate()==d))
        }

function CheckDate(DateString){
        if (DateString.search(/^\d{2}\/\d{2}\/\d{4}$/)!=0) { return false; } // bad format
        var T = DateString.split('/')
        if (!ValidDate(T[2], T[1]-1, T[0])) { return false; } // bad value
        return T
        }

function CheckTime(TimeString) {
         // ^ begin of line, $ end of line
         return /^([01]?[0-9]|[2][0-3])(:[0-5][0-9])(:[0-5][0-9])?$/.test(TimeString)
         }

function CheckThisDate(param,errmsg){
        if (!CheckDate(param)){
              alert (errmsg + " : " + param)
                }
        }

function CheckThisTime(param,errmsg){
        if (!CheckTime(param)){
              alert (errmsg + " : " + param)
                }
        }

// 15/10/2005 : allows to verify email format
function AntCheckEmail (EmailString){
         emailSaisi= EmailString;
         emailValeur = new String (emailSaisi);
         emailArobas= emailValeur.indexOf("@");
         emailPoint= emailValeur.indexOf(".");
         if ((emailArobas == -1) || (emailPoint == -1)){
            return false;
            }
         else{
              return true;
              }
         }

// 04/02/2008 : check sur les caractères et leur longueur
// type peut prendre
// int : que des entiers
// alpha : que des lettres
// alphanum: entiers et lettres
// len : la longueur de la chaine.
function AntChecktextfield (type,len,param,errmsg,errreason){
         // 1 test sur la longueur
         txt= new String(param);

         if (txt.length != len){
             alert (errmsg + " : " + param);
             }

         if (type == 'int'){
             if (!isInteger(param)){
                  alert (errmsg + " : " + param);
                  }
             }

         }

function isInteger (s)
   {
      var i;

      if (isEmpty(s))
      if (isInteger.arguments.length == 1) return 0;
      else return (isInteger.arguments[1] == true);

      for (i = 0; i < s.length; i++)
      {
         var c = s.charAt(i);

         if (!isDigit(c)) return false;
      }

      return true;
   }

function isEmpty(s)
   {
      return ((s == null) || (s.length == 0))
   }

function isDigit (c)
   {
      return ((c >= "0") && (c <= "9"))
   }

