// --- Form Validation ---
function message(obj,msg)
	{alert(msg);obj.focus();mt=false}
	
function checker(obj,msg)
	{if(obj.value=="" && mt==true)message(obj,msg)}
	
function radio(obj,msg)
	{
	y=0;for(i=0;i<obj.length;i++){if(obj[i].checked)y=1}
	if(y==0 && mt==true)message(obj[0],msg)
	}
	
function check_child(fm,num)
	{
	if(eval("fm.child"+num).value!="")
		{
		radio(eval("fm.gender"+num),"You must enter the child's gender")
		checker(eval("fm.dob"+num),"You must enter the child's date of birth")
		radio(eval("fm.place"+num),"You must enter the type of place required")
		checker(eval("fm.start"+num),"You must enter the child's proposed start date")
		}
	}
	
function email(obj)
	{
	var emailStr=obj.value;var emailPat=/^(.+)@(.+)$/
	var specialChars="\\(\\)!£$%^&*()+='#~?<>@,;:\\\\\\\"\\.\\[\\]";var validChars="\[^\\s" + specialChars + "\]";var quotedUser="(\"[^\"]*\")";var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	var atom=validChars + '+';var word="(" + atom + "|" + quotedUser + ")";var userPat=new RegExp("^" + word + "(\\." + word + ")*$");var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");var matchArray=emailStr.match(emailPat)
	if ((matchArray==null) && mt==true){message(obj,"Email address seems incorrect (check @ and .'s)")}
	if (mt==true){var user=matchArray [1];var domain=matchArray [2];if (user.match(userPat)==null)message(obj,"The username doesn't seem to be valid.")}
	if (mt==true){var IPArray=domain.match(ipDomainPat);if (IPArray!=null){for (var j=1;j<=4;j++){if (IPArray[j]>255)message(obj,"Destination IP address is invalid!")}}}
	if (mt==true){var domainArray=domain.match(domainPat);if (domainArray==null)message(obj,"The domain name doesn't seem to be valid.")}
	if (mt==true){var atomPat=new RegExp(atom,"g");var domArr=domain.match(atomPat);var len=domArr.length;if(domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>4)message(obj,"The address must end in a two,three or four letter domain")}
	if ((len<2) && mt==true)message(obj,"This address is missing a hostname!");
	}
	
function contact(fm)
	{
	mt=true;
	checker(fm.fname,'You must enter your name')
	checker(fm.sname,'You must enter your name')
	checker(fm.address1,'You must enter the first line of your address')
	checker(fm.address1,'You must enter the second line of your address')
	email(fm.sender_email)
	checker(fm.tel,'You must enter a telephone number')
	check_child(fm,1)
	check_child(fm,2)
	checker(fm.captcha,'Please verify the letters displayed on the screen')
	return mt
	}