// These functions check to see if all the required elements of an 
// HTML form have been filled out, and create a popup error message 
// if they haven't. To use them, copy them over to your HTML file
// and hook up the function to the onSubmit event handler of the
// appropriate form as shown below.
//
// <form action="sendit.php3" method="post" onSubmit="return checkrequired(this);">
//
// Make sure all the required fields in your form have a name that
// begins with "required_" - otherwise, the function will skip over 
// them.

function convertSpaces(str) {
  var out = "", flag = 0;
  for (i = 0; i < str.length; i++) {
    if (str.charAt(i) != "_") {
      out += str.charAt(i);
      flag = 0;
    } else {
      if (flag == 0) {
        out += " ";
        flag = 1;
      }
    }
  }
  return out;
}

function checkrequired(which) {
  var pass=true;
  if (document.images) {
    for (i=0; i < which.length; i++) {
      var tempobj=which.elements[i];
      if (tempobj.name.substring(0,9)=="required_") {
        if (((tempobj.type=="text"||tempobj.type=="textarea")&&
          tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&
          tempobj.selectedIndex==0)) {
          pass=false;
          break;
        }
      }
    }
  }
  if (!pass) {
    shortFieldName = tempobj.name.substring(9,tempobj.name.length).toUpperCase();
    alert("The "+convertSpaces(shortFieldName)+" field is required. Please enter the "
		+convertSpaces(shortFieldName.toLowerCase())+" and try again.");
    return false;
  } else {
    return true;
  }
}
