<!-- function used to validate elements on a form. It will test every element on the page nad make sure it contains data -->
<!-- it does not validate radio buttons yet -->
<!-- sytax used for this function is as follows-->
<!--   <form onSubmit="return verify(this,radiobuttonelement) OPTIONS" (where options are as follows -->
<!-- this.ELEMENTNAME.numeric = true; (for numeric only element) -->
<!-- this.ELEMENTNAME.optional = true; (if you do not want to validate that element -->
<!-- if there are minimum and maximum values for numeric elements you can set their min and max as follows -->
<!-- this.ELEMENTNAME.min = VALUE;  &  this.ELEMENTNAME.max = VALUE;
<!-- if you have drop down boxes on your page it will validate that something OTHER THAN the first item is checked -->
<!-- so make sure the first item in a drop down box is CHOOSE or something on that nature -->
<!-- if you have any questions contact Anne-Marie Keithley -->

function isblank(s)
{
  for (var i = 0; i < s.length; i++)
  {
    var c = s.charAt(i);
    if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
  }
    return true;
}
  
function verify(f,r1, r2,r3,r4)
{
  var msg;
  var empty_fields = "";
  var drp_fields = "";
  var rd_fields = "";
  var errors = "";
  var drperrors = "";

// Added to handle radio buttons1 since JavaScript can't handle type = radio
	if (r1 != null)	 {
		var count = 0;
		for (var i = 0; i < r1.length; i++) {
			if (r1[i].checked == true) {
				count = count + 1;
			}
		}
		if (count == 0) {
	 		rd_fields = "\n	" + r1[0].name;
	 	}
	}

// Added to handle radio buttons2 since JavaScript can't handle type = radio
	if (r2 != null)	 {
		var count = 0;
		for (var i = 0; i < r2.length; i++) {
			if (r2[i].checked == true) {
				count = count + 1;
			}
		}
		if (count == 0) {
	 		rd_fields += "\n	" + r2[0].name;
	 	}
	}

// Added to handle radio buttons3 since JavaScript can't handle type = radio
	if (r3 != null)	 {
		var count = 0;
		for (var i = 0; i < r3.length; i++) {
			if (r3[i].checked == true) {
				count = count + 1;
			}
		}
		if (count == 0) {
	 		rd_fields += "\n	" + r3[0].name;
	 	}
	}

// Added to handle radio buttons4 since JavaScript can't handle type = radio
	if (r4 != null)	 {
		var count = 0;
		for (var i = 0; i < r4.length; i++) {
			if (r4[i].checked == true) {
				count = count + 1;
			}
		}
		if (count == 0) {
	 		rd_fields += "\n	" + r4[0].name;
	 	}
	}

   
// Loop through elements on form.
  for (var i = 0; i < f.length; i++)
  {
    var e = f.elements[i];
  
  
// If drop-down box, test to see if something other than the first option is picked. Write error if not.
    if ((e.type == "select-one") && !e.optional)
    {
      if (e.selectedIndex == 0)
      {
        drp_fields += "\n	" + e.name;
      }
    }
    
// If text or textarea, test to see if blank.  Write error if blank.
    if (((e.type == "text") || (e.type == "textarea")) && !e.optional)
    {
      if ((e.value == null) || (e.value == "") || isblank(e.value))
      {
        empty_fields += "\n	" + e.name;
        continue;
      }

// Now check for fields that are supposed to be numeric.
// Must set min and max value on form to test for these values.
      if (e.numeric || (e.min != null) || (e.max != null))
      {
        var v = parseFloat(e.value);
        if (isNaN(v) || ((e.min != null) && (v < e.min)) || ((e.max != null) && (v > e.max)))
        {
          errors += "- The field " + e.name + " must be a number";
          if (e.min != null)
            errors += " that is greater than " + e.min;
          if (e.max != null && e.min != null)
            errors += " and less than " + e.max;
          else if (e.max != null)
            errors += " that is less than " + e.max;
          errors += ".\n";
        }
      }
    }

// Now check for fields that are optional but required numeric.
			if ((e.numeric) && (e.optional) && !((e.value == null) || (e.value == "") || isblank(e.value))) {
				var v = parseFloat(e.value);
			  if (isNaN(v)) {
		  	  errors += "- The field " + e.name + " must be a number.\n";
				}
			}

  }


    
  if (!empty_fields && !errors && !drp_fields && !rd_fields) return true;
  
  msg =  "_______________________________________________________\n\n"
  msg += "The form was not submitted because of the following error(s).\n";
  msg += "Please correct these error(s) and re-submit.\n";
  msg += "_______________________________________________________\n\n"
  

  if (empty_fields)
  {
    msg += "- The following required field(s) are empty:"
            + empty_fields + "\n";
  }  

  if (drp_fields)
  {
    msg += "\n- The following required drop-down box(es) must have a selection:"
            + drp_fields + "\n";
//    if (errors) msg += "\n"; 
  }  

  if (rd_fields)
  {
    msg += "\n- The following required radio-button(s) must have a selection:"
            + rd_fields + "\n";
    if (errors) msg += "\n"; 
  }  

  msg += errors;
  alert(msg);
  return false;
}