/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  *
  * Title : 		Basic Form Validation
  * Author : 		Miles Pearson
  * 
  * Description :	Checks that all needed fields have content before submitting to server
  *
  * Created : 		13/03/2007
  * Modified : 	13/03/2007
  *
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/

	var mailmasterForm;

	//Attach an "onLoad" event to the current window
	window.onload = init;
	
	//Initialization function
	function init() {
		//Attaching the onSubmit event to the mailmaster form
		mailmasterForm = document.getElementById('mailmaster');
		mailmasterForm.onsubmit = function () {
			return canSubmit(this);
		}
		
		//Setting focus to the user field
		mailmasterForm.fname.focus();
	}

	function filled(field) {
		if (field.value == "" || field.value == null) {
			return false;
		} else {
			return true;
		}
	}
	
	function canSubmit(form) {
		if (!filled(form.first)) {
			alert("Please enter your first name.");
			form.first.focus();
			return false;
		}
		
		if (!filled(form.last)) {
			alert("Please enter your last name.");
			form.last.focus();
			return false;
		}
		
		if (!filled(form.email)) {
			alert("Please enter your primary email address.");
			form.email.focus();
			return false;
		}
		
		

		return true;
	}