/* 
This regular expression works on standard email addresses: name.surname@site.com
var regex = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/; 

This regular expression works on standard email addresses and addresses like bob.o'connor@bobssite.com
var regex = /^[a-zA-Z0-9._-]+([a-zA-Z'])+[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;

*/

	function checkEmail(theEmail) {
		var regex = /^[a-zA-Z0-9._-]+([a-zA-Z'])+[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
		
		if (!regex.test(theEmail)) {
			return false;
		} else {
			return true;
		}
	}

	// trim() function to strip whitespace
	String.prototype.trim = function() 
	{
	  return( this.replace(/^\s*([\s\S]*\S+)\s*$|^\s*$/,'$1') ); 
	}

	function validate() {
		var f = document.register;
		
		// Check the user has typed in their name
		if (f.nameofagency.value.trim().length == 0) {
			alert("Please enter Name of agency.");
			f.nameofagency.focus();
			return false;
		}
		
		// Check the user has typed in their name
		if (f.agentnumber.value.trim().length == 0) {
			alert("Please enter Agent Number.");
			f.agentnumber.focus();
			return false;
		}
		
		// Check the user has typed in their name
		if (f.contactname.value.trim().length == 0) {
			alert("Please enter Contact name.");
			f.contactname.focus();
			return false;
		}
		
		// Check the user has typed in their name
		if (f.telephone.value.trim().length == 0) {
			alert("Please enter Telephone number.");
			f.telephone.focus();
			return false;
		}
		
		// Check the user has typed in their Postcode
		if (f.postcode.value.trim().length == 0) {
			alert("Please enter your postcode.");
			f.postcode.focus();
			return false;
		}
		
		// Check for a valid email address
		if (f.email.value.trim().length == 0) {
			alert("Please enter your email address.");
			f.email.focus();
			return false;
		}
		
		if (!checkEmail(f.email.value)) {
			alert("Please enter a valid email address.");
			f.email.focus();
			return false;
		}
		
		if (f.url.value.trim().length > 0){
			return false;
			//It is a spam, reject this post here
		}
		
		return true;
	}
	