function fieldFocus(fieldname) {
    document.booking[fieldname].focus();
}


function submitForm() {
	if (checkForm('Please note all fields marked * are mandatory') && checkForIllegalChars("Some of your fields appear to contain illegal characters.\nPlease retype without using %, ?, {, }, (, ), <, >, ;, :, \\, /, \", [ or ]")) {
		document.booking.fieldschecked.value=true;
		document.booking.submit();
	}
}

function checkForm(errorAlert) {
	for (i=0;i<11;i++)
	{
		sbox = document.forms[0].elements[i];
		sname = sbox.name;
		svalue = sbox.value;
		stype = sbox.type;
		
//		alert(sname+' '+svalue+' '+stype);

		if(sname != 'specReq')
		{
			if (!sbox.value)
			{
				alert(errorAlert);
				sbox.focus()
				return false;
			}
		}
	}
	if(!emailCheck(document.booking.email.value)) {
		 document.booking.email.focus();
		 alert("Please supply a valid email address.");
		 return false;
	}
	if(!telephoneValidation(document.booking.telNo, 'Please supply a valid telephone number \r\n  including std code', "I")) 
	{
		document.booking.telNo.focus();
		return false;
	}
	 return true
}

function emailCheck(strAddr) {
  emailOK = true;
  atPos = strAddr.indexOf("@");
  if(atPos == -1 || strAddr.indexOf(".", atPos) == -1 || strAddr.length < 7 ) emailOK = false;
  return emailOK;
}

function telephoneValidation(entered, alertbox, datatype)
{
	with (entered)
	{
		if(value.length > 0)
		{
			if (!parseFloat(value))
			{
				//the first digit wasn't numeric
				alert("Please enter only numbers in this field:\r\n\t-Telephone");
				return false;
			}
			else
			{
				//the first digit was numeric, so check the rest
				for (var i=0; i<value.length; i++) 
				{
					if ((value.charAt(i) != "0") && (!parseFloat(value.charAt(i))))
					{
						alert("Please enter only numbers in this field.\r\n\t-Telephone");
						return false;
					}
					else if (value.length < 9 || value.length > 20)
					{
						alert(alertbox);
						return false;
					}
				}
			}
		}
		else 
		{
			alert ('entered = '+entered);
			alert (alertbox);
			return false;
		}
	}
	return true;
} 

function checkForIllegalChars(errorAlert) {
	illegalChars = /[\%\?\{\}\(\)\<\>\;\:\\\/\"\[\]]/;
	for(i=0;i<11;i++)
	{
		sbox = document.forms[0].elements[i];
		sname = sbox.name;
		svalue = sbox.value;
		if (illegalChars.test(svalue)) {
			alert(errorAlert)
			sbox.focus()
			return false;
		}
	}
	return true;
}
