//A utility function that returns true is a string contains only white space characters

function isblank(s) {
  var c;
  for(var i = 0; i < s.length; i++) {
      c = s.charAt(i);
      if ((c!=" ") && (c!="\n") && (c!="")) { return false;
      }
  }
  return true;
}

// This is the function that performs form verification.  It is invoked
// from the onsubmit event handler.  The handler should return whatever
// value this function returns.

function verify(f) {
   var msg;
   var empty_fields = "";
   var errors = "";
   var e;

// Loop through forms elements looking for text and textarea errors

   for(var i = 0; i < f.length; i++) {
       e = f.elements[i];
       if (((e.type == "text") || (e.type == "textarea")) && !e.optional) {
          // Check if the field is empty
          if ((e.value==null) || (e.value=="") || isblank(e.value)) {
              empty_fields += "\n          " + e.name;
              continue;
          }
       }
    }

   if (!empty_fields) { return true;
   }

   // Report errors
   msg =  "____________________________________________________________ _ \n\n";
   msg += "The forms was not submitted because of the following error(s). \n";
   msg += "Please correct the error(s) and re-submit. \n";
   msg += "____________________________________________________________ _ \n\n";

   if (empty_fields) {
      msg += "- The following required field(s) are empty:";
      msg += empty_fields + "\n";
   alert(msg);
   return false;
   }
}
