
function MM_findObj (arg, doc) 
{ //v4.01
  var pos, i, val, frame;
    
  if (!doc) doc= document;                  // if no 'doc' supplied, 'doc' becomes the current document 
  pos= arg.indexOf("?");                    // 'pos' is the position of the question mark in the 'arg' string 
  if (pos>0 && parent.frames.length)   
    {
    // if there is a question mark AND there are frames
    frame= arg.substring(pos+1);            // 'frame' becomes the indicated frame
    doc= parent.frames[frame].document;     // 'doc' becomes the document within the indicated frame  
    arg= arg.substring(0,pos);              // remove question mark and the frame from 'arg'
    }
  val= doc[arg];                            // 'val' becomes the value of the parameter 'arg' within the document 'doc' 
  if (!val && doc.all)  val= doc.all[arg];  // 'val' becomes the value of the 'document.all[arg]'
  // if 'val' still unknown, find it from all available forms
  for (i=0; !val &&               i<doc.forms.length;  i++)  val= doc.forms[i][arg];
  // if 'val' still unknown, find it from all available layers
  for (i=0; !val && doc.layers && i<doc.layers.length; i++)  val= MM_findObj(arg,doc.layers[i].document);
  // if 'val' still unknown, find it with a call to getElementById(arg)
  if (!val && doc.getElementById)  val= doc.getElementById(arg); 
  return val;
}


function MM_validateForm() 
{ //v4.0
  var i,p,q,nm,test,num,min,max,warn,
      errors='',
      args=MM_validateForm.arguments;

  for (i=0; i<(args.length-2); i+=3) 
    { 
    warn= args[i+1];  
    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))
            if (warn.length>0)  errors+= '- '+warn+' kan niet goed zijn.\n';
            else                errors+= '- '+nm  +' kan niet goed zijn.\n';
          } 
        else if (test.indexOf('inRange') != -1) // a numeric field
          { 
          num = parseFloat(val);
          if (isNaN(num))  
              if (warn.length>0) errors+= '- '+warn+' moet een nummer zijn.\n';
              else               errors+= '- '+nm  +' moet een nummer zijn.\n';
          if (test.indexOf('inRange') != -1) 
            { 
            p= test.indexOf(':');
            min= test.substring(8,p); 
            max= test.substring(p+1);
            if (num<min || num>max)  
              if (warn.length>0) errors+= '- '+warn+' moet een nummer zijn tussen '+min+' en '+max+'\n';
              else               errors+= '- '+nm  +' moet een nummer zijn tussen '+min+' en '+max+'\n';
            } 
          } 
        } // if ((val=val.value)!="")
      else if (test.charAt(0) == 'R') 
        {
        if (warn.length>0) errors+= '- '+warn+' is verplicht.\n';
        else               errors+= '- '+nm  +' is verplicht.\n';
        } 
      } // if val
    } 
  if (errors) alert('Er waren de volgende fouten:\n'+errors);
  document.MM_returnValue = (errors == '');
}

