// JavaScript validation routines
// Web Techniques

var validated=true;  // global

// call this from onchange
function valid(fld,errm) // varying number of arguments
  {
  var i;
  validated=true;
// scan regular expressions
  for (i=2;i<valid.arguments.length;i++) 
    {
    var rx;
    rx=new RegExp(valid.arguments[i]);
    if (rx.exec(fld.value)!=null ) 
       return true;  // ok
    }
// no matches...
  alert(errm);
  fld.focus();   // put focus back
  validated=false;  // tell onsubmit if necessary
  return false;
  }

// This scans all the onchanged routines
function onsubmit(frm)
  {
  // force validation of all fields
  var l;
  var i;
  validated=true;
  for (i=0;i<frm.elements.length && validated;i++)
    if (frm.elements[i].onchange!=null)
      frm.elements[i].onchange();  // fake change
  return validated;
  }