
	String.prototype.trim = function() {
		return this.replace(/^\s+|\s+$/g,"");
	}

	function $(id) { return document.getElementById(id); }

	/* form field validation */
	function validate() {
	
		///^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/
	
		var firstname	= $('firstname').value.trim();
		var lastname	= $('lastname').value.trim();
		var email		= $('email').value.trim();
		var confirmemail= $('confirmemail').value.trim();
		var captcha		= $('captcha').value.trim();
		var agree		= $('agree').checked;

		// check for empty fields
		if(firstname == "") {
			alert("Please specify your first name in the space provided");
			$('firstname').focus();
			return false;
		}	
		if(lastname == "") {
			alert("Please specify your last name in the space provided");
			$('lastname').focus();
			return false;
		}	
		if(email == "") {
			alert("Please specify your email address in the space provided");
			$('email').focus();
			return false;
		}	
		if(confirmemail == "") {
			alert("Please confirm your email address in the space provided");
			$('confirmemail').focus();
			return false;
		}	
		if(captcha == "") {
			alert("Please enter the security code in the space provided");
			$('captcha').focus();
			return false;
		}	
		
		// validate field contents
		if(email.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/)==-1) {
			alert("You have specified an invalid email address");
			$('email').focus();
			return false;
		}
		if(confirmemail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/)==-1) {
			alert("You have specified an invalid email address");
			$('confirmemail').focus();
			return false;
		}
		
		// ensure matching email addresses
		if(email!=confirmemail) {
			alert("The email addresses you specified do not match!");
			return false;
		}
		
		if(!agree) {
			alert("Please indicate that you agree to allow us to send you electronic newsletters and information");
			return false;
		}
		
		return true;
}
