<!--- hide script from old browsers
/**
 *  The following validation functions are provided by validate.js:
 *
 *  validateEmailText(control, label);
 *     This function is written to validate an email address entered into a text box.
 *       control = A reference to the text box, normally something like form.textBoxName
 *       label = The text box label text, in quotes, like "Your Email"
 *
 *  validateText(control, label);
 *     This function checks to see if something is entered into a text box.
 *       control = A reference to the text box, normally something like form.textBoxName
 *       label = The text box label text, in quotes, like "Your Name"
 *
 *  validateRadio(control, label);
 *     This function checks to see if anything was checked from a set of radio buttons.
 *       control = A reference to the radio button, normally something like form.radioName
 *       label = The select label text, in quotes, like "Your Shipping Preference"
 *
 *  validateSelect(control, label);
 *     This function verifies that something other than the first option, with a value of
 *       "" or "-1", is selected.  It is assumed that you provide an option like
 *       "-- Please Select --" with a value of "" or "-1" for a set of vadidated options.
 *       control = A reference to the select element, normally something like form.selectName
 *       label = The select label text, in quotes, like "Your State"
 *
 *  validateStateCombo(select, textbox, label);
 *     This function is designed to facilitate having both a seleect and text box for entry
 *       of data (primarily used for Java CountryStates).
 *
 *  The intended use of these functions is to:
 *
 *    1)  Import this file using a script tag in the page header, like
 *  <script language="JavaScript" src="/common/validate.js"></script>
 *
 *    2)  Add an onSubmit event to your form tag, which calls a JavaScript
 *        form validation function that you will write, like
 *  <form name="subscribe" action="http://www.pcusa.org/form2mail/" onSubmit="return submitValidation(this);" method="post">
 *
 *    3)  Write a JavaScript submitValidation function in your page's
 *        header to validate the specific elements of your form.  Your
 *        page's requirements will almost certainly be different than
 *        the following example.  The concept behind this function is
 *        that you start with an empty error message, then you have a
 *        series of lines where any element validation errors are added
 *        to your error message.  Finally, you check to see if your error
 *        message is still empty. If it's not empty, you display the
 *        error message and return a logical false to block the form
 *        submit, or else you return a logical true value, which
 *        allows the form to submit.
 *
 ***********
<SCRIPT LANGUAGE="JavaScript">
<!--- hide script from old browsers

 function submitValidation(form) {
  var errTxt = "";
  errTxt += validateText(form.fname, "Your First Name");
  errTxt += validateText(form.lname, "Your Last Name");
  errTxt += validateText(form.address1, "Your Street Address");
  errTxt += validateText(form.city, "Your City");
  errTxt += validateSelect(form.state, "A State");
  errTxt += validateText(form.zip, "Your Zip Code");
  if (form.notifyByEmail.checked) {
    errTxt += validateEmailText(form.email, "Your Email Address");
  }
  if (errTxt.length != 0) {
    alert("The following must be corrected before your form can be processed:\n\n"+errTxt);
    return false;
  }
  return true;
}

// end hiding from old browsers -->
</SCRIPT>
 ***********
 *
 */ 

emailTest = "^([0-9,a-z,A-Z]+)([.,_,-]([0-9,a-z,A-Z]+))*[@]([0-9,a-z,A-Z]+)([.,_,-]([0-9,a-z,A-Z]+))*[.]([0-9,a-z,A-Z]){2,6}$";

function validateEmailText(control, label) {
  if (control.value == "" || control.value.search(emailTest) == -1) {
    return ("  * "+label+" must contain a valid email address.\n");
  }
  return "";
}
function validateEmailTextWithFocus(control, label) {
  var error = validateEmailText(control, label);
  if (error.length != 0) {
    control.focus();
  }
  return error;
}

function validateText(control, label) {
  if (control.value == "") {
    return ("  * "+label+" must be filled in.\n");
  }
  return "";
}
function validateTextWithFocus(control, label) {
  var error = validateText(control, label);
  if (error.length != 0) {
    control.focus();
  }
  return error;
}

function validateRadio(control, label) {
  var i = 0;
  var max = control.length;
//  Index through each radio button element until you find one that's checked or reach max.
  while (i < max && (! control[i].checked)) { i++; }
  if (i == max || control[i].value == "") {
    return ("  * "+label+" must be selected.\n");
  }
  return "";
}
function validateRadioWithFocus(control, label) {
//  Note: Radio buttons have no focus method; this method is provided for reliabile untutored use
  return validateRadio(control, label);
}

function validateSelect(control, label) {
  if (control.selectedIndex == 0) {
    var val = control.options[0].value;
    if (val == "" || val == "-1") {
      return ("  * "+label+" must be selected.\n");
    }
  }
  return "";
}
function validateSelectWithFocus(control, label) {
  var error = validateSelect(control, label);
  if (error.length != 0) {
      control.focus();
  }
  return error;
}

function validateStateCombo(select, textbox, label) {
  if (select.selectedIndex == 0) {
    var selVal = select.options[0].value;
    if (textbox.value == "" && (selVal == "" || selVal == "-1")) {
      return ("  * You must either select or enter "+label+".\n");
    }
  }
  return "";
}
function validateStateComboWithFocus(select, textbox, label) {
  var error = validateStateCombo(select, textbox, label);
  if (error.length != 0) {
      select.focus();
  }
  return error;
}
// end hiding from old browsers -->