function validateForm(f,a) {  // f is the form, a is comma-separated list of required fields
  var i,p,q,nm,errors='',args=a.split(',');
  for (i=0; i<(args.length); i+=1) { val=f[args[i]];
    if (val) { nm=val.name; var v=val.value;
      if (v.replace(/^\s*|\s*$/g,"")=="") { // trim spaces from the value
        errors += '- '+nm+' is required.\n';
      } } } if (errors) alert('The following error(s) occurred:\n'+errors);
  return (errors == '');
}

