function isDate(dateStr) {
// retourne vrai si dateStr est une date valide (jj/mm/aaaa ou jj-mm-aaaa), faux sinon.
// le nombre de jours du mois est testé en fonction du numéro du mois.
  var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
  var matchArray = dateStr.match(datePat); // is the format ok?

  if (matchArray == null) {
    return false;
    }

  day = matchArray[1]; // date => variables
  month = matchArray[3];
  year = matchArray[5];

  if (day < 1 || day > 31) { // teste le jour
    return false;
    }

  if (month < 1 || month > 12) { // teste le mois
    return false;
    }

  if ((month==4 || month==6 || month==9 || month==11) && day==31) {
    return false;
    }

  if (month == 2) { // teste le 29 février
    var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
    if (day > 29 || (day==29 && !isleap)) {
      return false;
      }
    }

  return true; // la date est valide
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}
 
function MM_changeProp(objName,x,theProp,theValue) { //v3.0
  var obj = MM_findObj(objName);
  if (obj && (theProp.indexOf("style.")==-1 || obj.style)) eval("obj."+theProp+"='"+theValue+"'");
}

function YB_validateForm() { //v4.0 en francais pour formmail3b.asp
  var i,p,q,nm,test,num,min,max,errors='',args=YB_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]); 
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) { errors+='- '+nm.substring(0, nm.length-3)+' doit être une adresse e-mail.\n'; }
      } else if (test!='R') {
        if (isNaN(val)) { errors+='- '+nm.substring(0, nm.length-3)+' doit être un nombre.\n'; }
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (val<min || max<val) { errors+='- '+nm.substring(0, nm.length-3)+' doit être un nombre entre '+min+' et '+max+'.\n'; }
    } } } else if (test.charAt(0) == 'R') { errors += '- '+nm.substring(0, nm.length-3)+' est obligatoire.\n'; } }
  } if (errors) alert('L(es) erreur(s) suivante(s) est(sont) survenue(s) :\n'+errors);
  document.MM_returnValue = (errors == '');
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function YB_LitTitle(objName) {
  var obj = MM_findObj(objName);
  return(eval("obj.title"));
}

//function YB_validateFormTitle() {
//  var i,p,q,nm,test,num,min,max,errors='',args=YB_validateFormTitle.arguments;
//  for (i=0; i<(args.length-2); i+=3) {
//    test=args[i+2];
//    val=MM_findObj(args[i]);
//    MM_changeProp(val.name,'','style.backgroundColor','#f8c751','INPUT/TEXT');
//    if (val) {
//      nm=val.name;
//      if ((val=val.value)!="") {
//        if (test.indexOf('isEmail')!=-1) {
//          p=val.indexOf('@');
//          if (p<1 || p==(val.length-1)) {
//            errors+='- '+YB_LitTitle(nm)+' doit être une adresse e-mail.\n';
//            MM_changeProp(nm,'','style.backgroundColor','#ffff00','INPUT/TEXT');
//          }
//        };
//        if (test.indexOf('isDate')!=-1) {
//          if (!isDate(val)) {
//            errors+='- '+YB_LitTitle(nm)+' doit être une date valide.\n';
//            MM_changeProp(nm,'','style.backgroundColor','#ffff00','INPUT/TEXT');
//          }
//        }
//        else
//          if (test!='R') {
//            if (isNaN(val)) {
//              errors+='- '+YB_LitTitle(nm)+' doit être un nombre.\n';
//              MM_changeProp(nm,'','style.backgroundColor','#ffff00','INPUT/TEXT');
//            }
//            if (test.indexOf('inRange') != -1) {
//              p=test.indexOf(':');
//              min=test.substring(8,p);
//              max=test.substring(p+1);
//              if (val<min || max<val) {
//                errors+='- '+YB_LitTitle(nm)+' doit être un nombre entre '+min+' et '+max+'.\n';
//                MM_changeProp(nm,'','style.backgroundColor','#ffff00','INPUT/TEXT');
//              }
//            }
//          }
//      }
//      else
//        if (test.charAt(0) == 'R') {
//          errors += '- '+YB_LitTitle(nm)+' est obligatoire.\n';
//          MM_changeProp(nm,'','style.backgroundColor','#ffff00','INPUT/TEXT');
//        }
//    }
//  }
//  if (errors) alert('L(es) erreur(s) suivante(s) est(sont) survenue(s) :\n'+errors);
//    document.MM_returnValue = (errors == '');
//}

function YB_validateFormTitle() {
  var i,p,q,nm,test,num,min,max,errors='',args=YB_validateFormTitle.arguments;
  for (i=0; i<(args.length-2); i+=3) {
    test=args[i+2];
    val=MM_findObj(args[i]);
    MM_changeProp(val.name,'','style.backgroundColor','#f8c751','INPUT/TEXT');
    if (val) {
      nm=val.name;
      if ((val=val.value)!="") {
        if ((test.indexOf('isEmail')!=-1) || (test.indexOf('isDate')!=-1)) {
          if (test.indexOf('isEmail')!=-1) {
            p=val.indexOf('@');
            if (p<1 || p==(val.length-1)) {
              errors+='- '+YB_LitTitle(nm)+' doit être une adresse e-mail.\n';
              MM_changeProp(nm,'','style.backgroundColor','#ffff00','INPUT/TEXT');
            }
          }
          if (test.indexOf('isDate')!=-1) {
            if (!isDate(val)) {
              errors+='- '+YB_LitTitle(nm)+' doit être une date valide.\n';
              MM_changeProp(nm,'','style.backgroundColor','#ffff00','INPUT/TEXT');
            }
          }
        }
        else if (test!='R') {
          if (isNaN(val)) {
            errors+='- '+YB_LitTitle(nm)+' doit être un nombre.\n';
            MM_changeProp(nm,'','style.backgroundColor','#ffff00','INPUT/TEXT');
          }
          if (test.indexOf('inRange') != -1) {
            p=test.indexOf(':');
            min=test.substring(8,p);
            max=test.substring(p+1);
            if (val<min || max<val) {
              errors+='- '+YB_LitTitle(nm)+' doit être un nombre entre '+min+' et '+max+'.\n';
              MM_changeProp(nm,'','style.backgroundColor','#ffff00','INPUT/TEXT');
            }
          }
        }
      }
      else if (test.charAt(0) == 'R') {
          errors += '- '+YB_LitTitle(nm)+' est obligatoire.\n';
          MM_changeProp(nm,'','style.backgroundColor','#ffff00','INPUT/TEXT');
      }
    }
  }
  if (errors) alert('L(es) erreur(s) suivante(s) est(sont) survenue(s) :\n'+errors);
  document.MM_returnValue = (errors == '');
}
