// simple validation form for main contact page
// 29.05.2004 Rees Kenyon

// Focus on first field of form onload
function formFocus(){
submitForm.comments.focus();
}

function checkInput(formContent) {

	// check name
	if (formContent.name.value == "")
	{
		alert("Please enter your full Name please.");
		formContent.name.focus();
		return(false);
	}
	
	// check address line 1
	if (formContent.add1.value == "")
	{
		alert("Please enter your full Address please.");
		formContent.add1.focus();
		return(false);
	}

	// check city
	if (formContent.city.value == "")
	{
		alert("Please enter your Town or City please.");
		formContent.city.focus();
		return(false);
	}
	
	// check postcode
	if (formContent.postcode.value == "")
	{
		alert("Please enter your Postal or Zip Code please.");
		formContent.postcode.focus();
		return(false);
	}

	// check email address
	if (formContent.submit_by.value == "")
	{
		alert("Please enter your main Email address please.");
		formContent.submit_by.focus();
		return(false);
	}

	// check telephone number
	if (formContent.telno.value == "")
	{
		alert("Please enter your Telephone Number please.");
		formContent.telno.focus();
		return(false);
	}

	// check email address format
	if (!emailFormat(document.submitForm.submit_by))
	{
		alert("Your e-mail address does not appear to be the correct format. Please check your e-mail and try again.");
		formContent.submit_by.focus();
		return(false);
	}
}

function emailFormat(formInput)
{
	var atPosition, dotPosition, lastPosition;
	with (formInput)
	{
		aPosition = value.indexOf("@");
		dotPosition = value.lastIndexOf(".");
		lastPosition = value.length-1;
		if (aPosition < 1 || dotPosition - aPosition < 2 || lastPosition - dotPosition > 3 || lastPosition - dotPosition < 2)
		{
			return(false);
		}
		return(true);
	}
}