// This function performs form validation by // looping through the elements of the form// looking for any in the 'required' or // 'numeric' class.  // This function is passed a reference to // the form (document._NotesFormName)function validateFields(theForm)  {         var msg;  var empty_fields = "";  var numeric_fields="";  // The next three variables are used when  // checking radio buttons and checkboxes.  possibleError = new Object();  var noError ="";      var x=0;  // Loop through the elements of the form,   // looking for all text and textarea elements   // in the "required" class. Then, check for   // fields that are empty and make a list of them.      // Put together an error message for fields that  // fail validation.  for(var i = 0; i < theForm.length; i++) {    var e = theForm.elements[i];      if (e.className.indexOf("required") != -1 ) {      // Check for the type of field and then      // edit accordingly.       if ((e.type == "text" || e.type=="password" || e.type == "textarea") &&     	           (e.value == null || e.value == "" ))  {        empty_fields += "\n          " + e.title;        continue;        }      if (e.type == "select-multiple" &&        e.selectedIndex == -1) {           empty_fields += "\n          " + e.title;        continue;        }      // The first option in the select-one      // list is "Select One" and should      // produce an error.      if (e.type == "select-one" &&      e.selectedIndex == 0)  {        empty_fields += "\n          " + e.title;        continue;                 }      // Process each checkbox and radio button.      // If checked, add to the no error list, otherwise      // add to the possible error list.      if (e.type == "radio" || e.type == "checkbox") {        if (e.checked == false)          possibleError[x++] = e.title;                else          noError += e.title;        }    } //End of check for required fields        // Check for numeric fields.    if (e.className.indexOf("numeric") != -1 &&    (e.type == "text" || e.type == "textarea"))  {      if ( !isNumber (e.value)) {        numeric_fields += "\n          " + e.title;                }            } // end checking for numerics  } // End looping through form elements    // Loop through the possible errors in   // radio button and checkboxes and   // find out which are actual errors.  for (count in possibleError) {    if (noError.indexOf (possibleError[count]) ==-1) {      empty_fields += "\n          " +       possibleError[count];      noError += possibleError[count];      }        }  // If there were any errors display  // the error message, otherwise give the  // user the option of submitting the form.  if (!empty_fields && !numeric_fields)  {		return true; }  else {    msg  = "__________________________________\n\n"    msg += " The form was not submitted because of\n"    msg += " the following errors.  Please correct\n";        msg += " these error(s) and re-submit.\n";    msg += "__________________________________\n\n"    if (empty_fields) {      msg += " These required fields are empty:\n";      msg += empty_fields + "\n\n";         }    if (numeric_fields) {      msg += " The following numeric fields have\n";      msg += " character data:\n"      msg += numeric_fields + "\n";      }    alert(msg);	        }}//Check if a string is a number. //Numbers have 0-9, "-", and "."function isNumber (inputNum) {  decimalPoint=false;  for (var i = 0; i< inputNum.length; i++) {        var oneChar = inputNum.charAt(i);      if (i==0 && oneChar == "-") {        continue      }      if (oneChar == "." && !decimalPoint) {        decimalPoint = true;        continue        }             if (oneChar < "0" || oneChar > "9") {        return false      }    } //end of looping through inputNum    return true}
