<!--
  //USAGE: <form ... onSubmit="return checkRequired(this, required)">

  function isBlank(inString)
  {
    var inChar;
  
    for (var i = 0; i <= inString.length; i++)
	{
      inChar = inString.charAt(i);
	  if ((inChar !=' ') && (inChar != '\n') && (inChar != '\t'))
	  {
	    return false;
	  }
	  return true;  
    }
  }

  function checkRequired(thisForm, requiredArray)
  {
    var missingFields = "";
	var otherErrors  = "";
	var message = "";
	var thisElement;
	
	var emailRE = /^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
	var zIPRE   = /^[0-9]{5}(-[0-9]{4})*$/;
	var bSNRE   = /^[0-9]{6,}$/;
	
	requiredArray.sort();
	
    for(var i = 0; i < thisForm.length; i++)
	{
	  thisElement = thisForm.elements[i];
	  if (((thisElement.type == "text")||(thisElement.type == "textarea")) && inArray(thisElement.name, requiredArray))
	  {
	    if ((thisElement.value == null)||(thisElement.value == "")||(isBlank(thisElement.value)))
		{
	      missingFields += "     " + thisElement.name + "\n";
        }
		else
		{
		  if (thisElement.name == "Email Address")
		  {
		    if (!emailRE.test(thisElement.value))
			{
			  otherErrors += "\"" + thisElement.value + "\" is not a properly formatted email address.\n";
			}
		  }
		  else if (thisElement.name == "ZIP")
		  {
		    if (!zIPRE.test(thisElement.value))
			{
			  otherErrors += "\"" + thisElement.value + "\" is not a properly formatted ZIP code.\n";
			}
		  }
		  else if (thisElement.name == "Serial Number")
		  {
		    if (!bSNRE.test(thisElement.value))
			{
			  otherErrors += "\"" + thisElement.value + "\" is not a properly formatted Base Serial Number.\n";
			}
		  } 
		}
	  }
	  else
	  {
	    if ((thisElement.type == "select-one") && inArray(thisElement.name, requiredArray))
		{
		  if (thisElement.selectedIndex == 0)
		  {
	        missingFields += "     " + thisElement.name + "\n";
          }
		}
	  }
	} 
	
	if (missingFields || otherErrors)
	{
	  if (missingFields)
	  {
	    message += "The following required field(s) were left blank in your submission:\n\n" + missingFields;
	  }
	  if (otherErrors)
	  {
	    if (message)
		{
			message += "\n";
		}
		
		message += otherErrors;
	  }
	  
	  message += "\nPlease fix the input errors, and resubmit the form.\n";
    }
	
	if (message)
	{
	  alert(message);
	  return false;
	}
	else
	{
	  return true;
	}
  }

  function inArray(thisValue, thisArray)
  {
    var found = false;
	var low  = 0;
	var high = thisArray.length-1;
	var mid;
	
	while(!found && (low <= high))
	{
	  mid = Math.floor((low + high)/2);
	 // alert(low + "\n" + mid + "\n" + high + "\n" +thisArray[mid]);
	  if (thisValue == thisArray[mid])
	  {
	    found = true;
	  }
	  else
	  {
	    if (thisValue < thisArray[mid])
		{
		  high = mid - 1;
		}
		else
		{
		  low = mid + 1;
		}
	  } 
	}
	return found;
  }
//-->