// check create account form
function checkform(form) {
	// check email addresses first
	var email = form.email.value;
	var email_confirm = form.email_confirm.value;
	if ((email.indexOf("@") == -1) || (email.indexOf(".") == -1) || (email.length < 7) || (email.length > 255)) {
		alert("You must specify a valid e-mail address.");
		form.email.focus();
		form.email.select();
		return false;
	}

	if (email != email_confirm) {
		alert("You must confirm your e-mail address.");
		form.email_confirm.focus();
		form.email_confirm.select();
		return false;
	}

//-----------------------------------------------------------------------------
	// check the passwords
	var illegalChars = /\W/;

	var password = form.password.value;
	var password_confirm = form.password_confirm.value;
	if ((password.length < 6) || (password.length > 30)) {
		alert("Password must be between 6 and 30 characters.");
		form.password.focus();
		form.password.select();
		return false;
	}
	else if (illegalChars.test(password)) {
		alert("Password can only contain letters, numbers and underscores.");
		form.password.focus();
		form.password.select();
		return false;
	}

	if (password != password_confirm) {
		alert("You must confirm your password.");
		form.password_confirm.focus();
		form.password_confirm.select();
		return false;
	}


//-----------------------------------------------------------------------------
	// check title/name details
	var illegalChars = /[^a-zA-Z0-9 \-]/;

	var title = form.title.value;
	if (title) {
		if (title.length > 30) {
			alert("The Title can not be longer than 30 characters.");
			form.title.focus();
			form.title.select();
				return false;
		}
		else if (illegalChars.test(title)) {
			alert("Your Title can only contain letters, numbers, spaces and hyphens (-).");
			form.title.focus();
			form.title.select();
				return false;
		}
	}

	var first_name = form.first_name.value;
	if ((first_name.length < 1) || (first_name.length > 255)) {
		alert("You must enter a First Name.");
		form.first_name.focus();
		form.first_name.select();
		return false;
	}
	else if (illegalChars.test(first_name)) {
		alert("Your First Name can only contain letters, numbers, spaces and hyphens (-).");
		form.first_name.focus();
		form.first_name.select();
		return false;
	}

	var surname = form.surname.value;
	if ((surname.length < 1) || (surname.length > 255)) {
		alert("You must enter a Surname.");
		form.surname.focus();
		form.surname.select();
		return false;
	}
	else if (illegalChars.test(surname)) {
		alert("Your Surname can only contain letters, numbers, spaces and hyphens (-).");
		form.surname.focus();
		form.surname.select();
		return false;
	}

//-----------------------------------------------------------------------------
	// check telephone/mobiles
	var illegalChars = /[^0-9 \(\)\+\.]/;

	var telephone = form.telephone.value;
	var mobile = form.mobile.value;
	if ((telephone.length < 1) || (telephone.length > 30)) {
		alert("You must enter a Telephone.");
		form.telephone.focus();
		form.telephone.select();
		return false;
	}
	else if (illegalChars.test(telephone)) {
		alert("Your Telephone can only contain numbers.");
		form.telephone.focus();
		form.telephone.select();
		return false;
	}

	if (mobile) {
		if ((mobile.length < 1) || (mobile.length > 30)) {
			alert("You must enter a Mobile.");
			form.mobile.focus();
			form.mobile.select();
				return false;
		}
		else if (illegalChars.test(mobile)) {
			alert("Your Mobile can only contain numbers.");
			form.mobile.focus();
			form.mobile.select();
				return false;
		}
	}

//-----------------------------------------------------------------------------
	// check the address details
	var illegalChars = /[^a-zA-Z0-9 \-]/;
	var address1 = form.address1.value;
	var address2 = form.address2.value;
	var city = form.city.value;
	var county = form.county.value;
	var post_code = form.post_code.value;

	if ((address1.length < 1) || (address1.length > 255)) {
		alert("You must enter the first line of your address.");
		form.address1.focus();
		form.address1.select();
		return false;
	}
	if (address2) {
		if (address2.length > 255) {
			alert("The second line of the address must not be longer than 255 characters.");
			form.address2.focus();
			form.address2.select();
				return false;
		}
	}
	if ((city.length < 1) || (city.length > 255)) {
		alert("You must enter your Town/City.");
		form.city.focus();
		form.city.select();
		return false;
	}
	if (county) {
		if (county.length > 255) {
			alert("The county must not be longer than 255 characters.");
			form.county.focus();
			form.county.select();
				return false;
		}
	}
	if ((post_code.length < 1) || (post_code.length > 30)) {
		alert("You must enter your Post Code.");
		form.post_code.focus();
		form.post_code.select();
		return false;
	}
	if ((illegalChars.test(address1)) || (illegalChars.test(address2)) || (illegalChars.test(city)) || (illegalChars.test(county)) || (illegalChars.test(post_code))) {
		alert("Your address can only contain letters, numbers, spaces and hyphens (-).");
		form.address1.focus();
		form.address1.select();
		return false;
	}
}

