function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function isValidEmail(str) {
   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0); 
}

function validateForm(){
	theForm = document.frmBudgetSuggestion;
	
	//check all fields are entered
	if (trim(theForm.comments.value) == ''){
		alert('Budget suggestion is required.');
		return false;
	}
		
	//check email has @
	if((trim(theForm.email.value) != '') && (!(isValidEmail(theForm.email.value)))){
		alert('Email must be valid.');
		return false;
	}

	//comments must be less then 8000 characters
	if (theForm.comments.value.length > 8000){
		alert('Budget suggestion must be less then 8000 characters. Character count ' + theForm.comments.value.length);
		return false;
	}

	return true;
}