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_ReturnError(val, opt, test) {
   var p,q,num,min,max,errors='';
   if ((val=val.value)!="") {
     if (test.indexOf('isEmail')!=-1) {
       p=val.indexOf('@');
       q=val.lastIndexOf('.');
       if (p<1 || q<3 || q==(val.length-1) || q<=(p+1))
         errors=' doit contenir une adresse e-mail.\n';
     } else if (test!='R') {
       if (isNaN(val))
         errors=' doit contenir un nombre.\n';
       if (test.indexOf('inRange') != -1) {
         p=opt.indexOf(':');
         min=opt.substring(0,p);
         max=opt.substring(p+1);
         if (val<min || max<val)
           errors=' doit contenir un nombre compris entre '+min+' et '+max+'.\n';
       }
     }
   } else if (test.charAt(0) == 'R')
     errors = ' doit être rempli.\n';
   return errors;
}


function MM_validateForm() { //v4.0
  var i,x,val,nm,test,tmp,str='',errors='',errors2='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) {
    test=args[i+2];
    tmp = args[i];
    if (tmp.indexOf('||') != -1) {
      while ((x=tmp.indexOf('||')) != -1) {
        val=MM_findObj(tmp.substring(0,x));
    	tmp=tmp.substring(x+2);
    	if (val) {
    	  errors2 = MM_ReturnError(val, args[i+1], test);
    	  str += ' ' + val.name + ' ou';
    	}
    	if (errors2 == '')
    	  break;
      }
      if (errors2 != '') {
        val=MM_findObj(tmp);
        if (val){
    	  errors2 = MM_ReturnError(val, args[i+1], test);
    	  str += ' ' + val.name;
    	}
      }
      if (errors2 != '')
        errors += ' - au moins un des champs' + str + errors2;
    } else {
      val=MM_findObj(args[i]);
      if (val) {
        nm = val.name;
        if ((errors2=MM_ReturnError(val, args[i+1], test))!='')
          errors += ' - le champ ' + nm + errors2;
      }
    }
  }
  if (errors)
    alert('Ce formulaire est incomplet:\n'+errors);
  document.MM_returnValue = (errors == '');
}
