function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
//   var inputString = inputField.value+'';
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function


function CheckForm( thisform, fields )
{
	var correct = true;
	var err_msg = " ";
	var last, curr_value;

	for( i=0; i<fields.length; i++ )
	{
		last = true;
		elem = document.getElementById(fields[i]);
		if(elem)
		{
			if (!trim(elem.value) && fields[i] != 'Comment')
			{
				last = false;
			}
			if( last == true )
			{
				curr_value = trim( elem.value );
				switch( fields[i] )
				{
					case "IDNumber1" :
	//					alert(isNaN(curr_value));
						if( curr_value.length != 3 || isNaN(curr_value) )
						{
							last = false;
						}
						break;
					case "IDNumber2" :
						if( curr_value.length != 2 || isNaN(curr_value) )
						{
							last = false;
						}
						break;
					case "IDNumber3" :
						if( curr_value.length != 4 || isNaN(curr_value) )
						{
							last = false;
						}
						break;
					case "Zip" :
						if( curr_value.length != 5 || isNaN(curr_value) )
						{
							last = false;
						}
						break;
					case "DOB2" :
						if( curr_value > 31 || curr_value < 1 || isNaN(curr_value) )
						{
							last = false;
						}
						break;
					case "DOB1" :
						if( curr_value > 12 || curr_value < 1 || isNaN(curr_value) )
						{
							last = false;
						}
						break;
					case "DOB3" :
						if( curr_value > 1999 || curr_value < 1930 || isNaN(curr_value) )
						{
							last = false;
						}
						break;
					case "Weight" :
						if( curr_value < 1 || curr_value > 400 || isNaN(curr_value) )
						{
							last = false;
						}
						break;
					case "Height1" :
						if( curr_value < 4 || curr_value > 7 || isNaN(curr_value) )
						{
							last = false;
						}
						break;
					case "Height2" :
						if( curr_value < 0 || curr_value > 11 || isNaN(curr_value) )
						{
							last = false;
						}
						break;
					case "ReturnZip" :
						if( curr_value.length != 5 || isNaN(curr_value) )
						{
							last = false;
						}
						break;
				
						
						case "Phonenumber" :
						if( curr_value.length>30 )
						{
							last = false;
						}
						break;
						
						case "Comment" :
						if( curr_value.length>500 )
						{
							last = false;
						}
						break;
				}
			}
		}
		if( last != false )
		{
			elem.className = "inputf";
		}
		else
		{
			elem.className = "inputferr";
			err_msg = err_msg + "Please enter the "+ fields[i] +" correctly.\n";
			correct = false;
		}
	}
	
	if (!correct)
	{
		alert("Error:\n"+err_msg);
	}
	return correct;
}

