/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  *
  * Title : 		Form Validation Example
  * Author : 		Vito Tardia
  * URL : 			http://www.vtardia.com
  *
  * Description :	Includes functions from HackerJournal magazine
  *					(http://www.hackerjournal.it)
  *				- 	filled
  *				- 	canSubmit
  *
  * Created : 	27/03/2006
  * Modified : 	27/11/2006
  *
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/

	var theForm;

	//Attach an "onLoad" event to the current window
	window.onload = init;
	
	//Initialization function
	function init() {
		//Attaching the onSubmit event to the sendMail form
		theForm = document.getElementById('sendMail');
		theForm.onsubmit = function () {
			return canSubmit(this);
		}
		
		//Setting focus to the user field
		theForm.customerName.focus();
	}

	function filled(field) {
		if (field.value == "" || field.value == null) {
			return false;
		} else {
			return true;
		}
	}
	
	function canSubmit(form) {
		if (!filled(form.username)) {
			alert("Please enter your name.");
			form.customerName.focus();
			return false;
		}
		
		if (!filled(form.email)) {
			alert("Please enter your email address.");
			form.email.focus();
			return false;
		}

		return true;
	}
