/* 
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 of Intermediary
		if (f.intermediary.value.trim().length == 0) {
			alert("Please enter Name of Intermediary.");
			f.intermediary.focus();
			return false;
		}
		
		// Check the user has typed in their first line of their Address
		if (f.address1.value.trim().length == 0) {
			alert("Please enter the first line of your Address.");
			f.address1.focus();
			return false;
		}
		
		// Check the user has typed in their second line of their Address
		if (f.address2.value.trim().length == 0) {
			alert("Please enter the second line of your Address.");
			f.address2.focus();
			return false;
		}
		
		// Check the user has typed in their Town
		if (f.town.value.trim().length == 0) {
			alert("Please enter your Town.");
			f.town.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 the user has typed in their Phone Number
		if (f.phonenumber.value.trim().length == 0) {
			alert("Please enter your Phone number.");
			f.phonenumber.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;
		}
		
		// Check the user has typed in their Contact Name
		if (f.contactname.value.trim().length == 0) {
			alert("Please enter your Contact name.");
			f.contactname.focus();
			return false;
		}
		
		// Check the user has typed in their Company Registration Number
		if (f.regnum.value.trim().length == 0) {
			alert("Please enter your Company Registration Number.");
			f.regnum.focus();
			return false;
		}
		
		// Check the user has typed in their FSA Status
		if (f.fsastatus.value.trim().length == 0) {
			alert("Please enter your FSA Status.");
			f.fsastatus.focus();
			return false;
		}
		
		// Check the user has typed in their FSA Number
		if (f.fsanumber.value.trim().length == 0) {
			alert("Please enter your FSA Number.");
			f.fsanumber.focus();
			return false;
		}
		
		// Check the user has typed in their Software House or other Computer system used
		if (f.softwarehouse.value.trim().length == 0) {
			alert("Please enter your Software House or other Computer system used.");
			f.softwarehouse.focus();
			return false;
		}
				
		// Check the user has typed in their Main classes of business to be transacted with this agency
		if (f.mainclasses.value.trim().length == 0) {
			alert("Please enter your Main classes of business to be transacted with this agency.");
			f.mainclasses.focus();
			return false;
		}
		
		if (f.url.value.trim().length > 0){
			return false;
			//It is a spam, reject this post here
		}
		
		return true;
	}
	