/* Functions for validating the online gift form */

function validate(f) {
	//check for an amount
	if (f.AMOUNT.value == "") {
		alert("Please enter a gift amount in US dollars.");
		f.AMOUNT.focus();
		return false;
	}
	
	//strip any commas

	var testString = f.AMOUNT.value;

	//remove the commas
	if (testString.match(/,/)) {
		var tempArray = testString.split(",");
		testString = "";
		for (i = 0; i < tempArray.length; i++) {
			testString += tempArray[i];
		}
		f.AMOUNT.value = testString;
	}

	//check for a name
	if (f.NAME.value == "") {
		alert("Please enter your name and class year.");
		f.NAME.focus();
		return false;
	}
	
	//check for an address
	if (f.ADDRESS.value == "") {
		alert("Please enter your street address.");
		f.ADDRESS.focus();
		return false;
	}

	//check for a city
	if (f.CITY.value == "") {
		alert("Please enter your city.");
		f.CITY.focus();
		return false;
	}
	
	//check for a state
	if (f.STATE.value == 0) {
		alert("Please select your state.");
		f.STATE.focus();
		return false;
	}

	
	//check for a zip code
	if (f.ZIP.value == "") {
		alert("Please enter your zip code.");
		f.ZIP.focus();
		return false;
	}

	//email address
	  var checkString = f.EMAIL.value;
	  
	  if (checkString == "" || !checkString.match(/\S+@\S+/)) {
		  f.EMAIL.focus();
		  alert("Please enter a valid email address. Example: username@domain.xxx.");
		  return false;
	  }    
	return true;
}

