//Check that an email address is valid
function ValidateEmail(str) {
   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}

//Check for whitespace string
function isblank (str) {
  for (var i=0; i<str.length; i++) {
    var c = str.charAt(i);
	if ((c != ' ') && (c != '\n') & (c != ''))
	  return false;
  }
  return (true);
}

//Function validates form data
function ValidateForm (f)
{
    var msg;
	var empty = "";
	var email = "";
	var i, e;

	
	//Loop through form fields.
	for (i=0; i<f.length; i++) {

	  e = f.elements[i];
	  
		  
	  if (((e.type == "text") || (e.type == "textarea")) && e.required) {
	    //Check to see if the field is empty
		if ((e.value == null)  || (e.value == "") || isblank(e.value)) {
		  empty += "\n                 " + e.id;
		  continue;
		}
		if (e.email && !ValidateEmail(e.value))
		   email += "\n                " + e.id;
	  }
	}
	
	//If there are no empty fields and all email address are valid
	if (!empty && !email)
	  return (true);
	  
	msg = "______________________________________________________________\n\n";
	msg += "The form was not submitted because of the following error(s).\n"
	msg += "Please correct the following problems and resubmit.\n";
	msg += "______________________________________________________________\n\n";
	
	if (empty) {
	  msg += "- The following required fields are empty:" + empty + "\n";
	}
	
	if (email) {
	   msg += "- The following email addresses are invalid:" + email + "\n";
	}

        alert (msg);
	
	return (false);
}