
// Validation and submission functions
function validate_and_submit_activity()
{// begin validate_and_submit_activity
	errorMsg = "";

	// make sure they can't click the button again
	document.activity_form.submit_button.disabled = true
	
	// check to make sure a radio button has been selected
	areaSelected = -1;

	for(count = 0; count < document.activity_form.lf_area_type.length; count++)
	{
		if(document.activity_form.lf_area_type[count].checked)
		{
			areaSelected = 1;
			count = document.activity_form.lf_area_type.length;
		}
	}
	
	if(areaSelected == -1)
		errorMsg += "Please select an area for the activity!\n";
	if(Trim(document.activity_form.grade_level.value) == "")
		errorMsg += "Please enter a grade level!\n";
	if(Trim(document.activity_form.people_needed.value) == "")
		errorMsg += "Please enter the number of people needed!\n";
	if(Trim(document.activity_form.time_needed.value) == "")
		errorMsg += "Please enter the time needed!\n";
	if(Trim(document.activity_form.lf_materials_for_activity.value) == "")
		errorMsg += "Please enter any materials needed for the activity or n/a if none!\n";
	if(Trim(document.activity_form.lf_description_of_activity.value) == "")
		errorMsg += "Please enter a description of the activity!\n";
	if(Trim(document.activity_form.name.value) == "")
		errorMsg += "Please enter your name!\n";
//	if(Trim(document.activity_form.address.value) == "")
//		errorMsg += "Please enter your address!\n";
	if(Trim(document.activity_form.city.value) == "")
		errorMsg += "Please enter your city!\n";
	if(Trim(document.activity_form.state.value) == "")
		errorMsg += "Please select your state!\n";
	if(Trim(document.activity_form.zip.value) == "")
		errorMsg += "Please enter your zip code!\n";
	if(Trim(document.activity_form.from.value) == "")
		errorMsg += "Please enter your email!\n";
//	if(Trim(document.activity_form.school_name.value) == "")
//		errorMsg += "Please enter your child's school name!\n";
//	if(Trim(document.activity_form.school_address.value) == "")
//		errorMsg += "Please enter your child's school address!\n";
//	if(Trim(document.activity_form.school_city.value) == "")
//		errorMsg += "Please enter your child's school city!\n";
//	if(Trim(document.activity_form.school_zip.value) == "")
//		errorMsg += "Please enter your child's school zip!\n";

	if(errorMsg != "")
	{
		alert(errorMsg);

		// there was an error so reactiviate the button
		document.activity_form.submit_button.disabled = false
	}
	else
	{
		//  Catch items that don't have to be entered.
		if(Trim(document.activity_form.address.value) == "")
			document.activity_form.address.value = "None";
		if(Trim(document.activity_form.school_name.value) == "")
			document.activity_form.school_name.value = "None";
		if(Trim(document.activity_form.school_address.value) == "")
			document.activity_form.school_address.value = "None";
		if(Trim(document.activity_form.school_city.value) == "")
			document.activity_form.school_city.value = "None";
		if(Trim(document.activity_form.school_zip.value) == "")
			document.activity_form.school_zip.value = "None";
		
		//  Set thank you page
		
		//  Send document
		document.activity_form.submit();
	}
}// end validate_and_submit_activity

function validate_and_submit_funds()
{// begin validate_and_submit_funds
	// make sure they can't click the button again
	document.funds_form.submit_button.disabled = true
	
	errorMsg = "";
	
	if(Trim(document.funds_form.name.value) == "")
		errorMsg += "Please enter your name!\n";
	if(Trim(document.funds_form.organization.value) == "")
		errorMsg += "Please enter your organization's name!\n";
	if(Trim(document.funds_form.address.value) == "")
		errorMsg += "Please enter your address!\n";
	if(Trim(document.funds_form.city.value) == "")
		errorMsg += "Please enter your city!\n";
	if(Trim(document.funds_form.state.value) == "")
		errorMsg += "Please select your state!\n";
	if(Trim(document.funds_form.zip.value) == "")
		errorMsg += "Please enter your zip code!\n";
	if(Trim(document.funds_form.phone.value) == "")
		errorMsg += "Please enter your telephone number!\n";
//	if(Trim(document.funds_form.fax.value) == "")
//		errorMsg += "Please enter your fax number!\n";
	if(Trim(document.funds_form.from.value) == "")
		errorMsg += "Please enter your email!\n";

	if(errorMsg != "")
	{
		alert(errorMsg);

		// there was an error so reactiviate the button
		document.funds_form.submit_button.disabled = false
	}
	else
	{
		//  Catch items that don't have to be entered.
		if(Trim(document.funds_form.fax.value) == "")
			document.funds_form.fax.value = "None";
		
		//  Set thank you page
		
		//  Send document
		document.funds_form.submit();
	}
}// end validate_and_submit_funds

/*
==================================================================
LTrim(string) : Returns a copy of a string without leading spaces.
==================================================================
*/
function LTrim(str)
/*
   PURPOSE: Remove leading blanks from our string.
   IN: str - the string we want to LTrim
*/
{
   var whitespace = new String(" \t\n\r");
   var s = new String(str);
   if (whitespace.indexOf(s.charAt(0)) != -1) {
      // We have a string with leading blank(s)...
      var j=0, i = s.length;
      // Iterate from the far left of string until we
      // don't have any more whitespace...
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;
      // Get the substring from the first non-whitespace
      // character to the end of the string...
      s = s.substring(j, i);
   }
   return s;
}
/*
==================================================================
RTrim(string) : Returns a copy of a string without trailing spaces.
==================================================================
*/
function RTrim(str)
/*
   PURPOSE: Remove trailing blanks from our string.
   IN: str - the string we want to RTrim
*/
{
   // We don't want to trip JUST spaces, but also tabs,
   // line feeds, etc.  Add anything else you want to
   // "trim" here in Whitespace
   var whitespace = new String(" \t\n\r");
   var s = new String(str);
   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
      // We have a string with trailing blank(s)...
      var i = s.length - 1;       // Get length of string
      // Iterate from the far right of string until we
      // don't have any more whitespace...
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i--;
      // Get the substring from the front of the string to
      // where the last non-whitespace character is...
      s = s.substring(0, i+1);
   }
   return s;
}
/*
=============================================================
Trim(string) : Returns a copy of a string without leading or trailing spaces
=============================================================
*/
function Trim(str)
/*
   PURPOSE: Remove trailing and leading blanks from our string.
   IN: str - the string we want to Trim
   RETVAL: A Trimmed string!
*/
{
   return RTrim(LTrim(str));
}
