function emailvalidation(entered, alertbox)
{
with (entered)
{
apos=value.indexOf("@");
dotpos=value.lastIndexOf(".");
lastpos=value.length-1;
if (apos<1 || dotpos-apos<2 || lastpos-dotpos>3 || lastpos-dotpos<2)
{if (alertbox) {alert(alertbox);} return false;}
else {return true;}
}
}

function valuevalidation(entered, min, max, alertbox, datatype)
{
with (entered)
{
checkvalue=parseFloat(value);
if (datatype)
{smalldatatype=datatype.toLowerCase();
if (smalldatatype.charAt(0)=="i") {checkvalue=parseInt(value)};
}
if ((parseFloat(min)==min && checkvalue<min) || (parseFloat(max)==max && checkvalue>max) || value!=checkvalue)
{if (alertbox!="") {alert(alertbox);} return false;}
else {return true;}
}
}

function emptyvalidation(entered, alertbox)
{
with (entered)
{
if (value==null || value=="")
{if (alertbox!="") {alert(alertbox);} return false;}
else {return true;}
}
}

function digitvalidation(entered, min, max, alertbox, datatype)
{
// Digit Validation by Henrik Petersen / NetKontoret
// Explained at www.echoecho.com/jsforms.htm
// Please do not remove this line and the two lines above.
with (entered)
{
checkvalue=parseFloat(value);
if (datatype)
{smalldatatype=datatype.toLowerCase();
if (smalldatatype.charAt(0)=="i") 
{checkvalue=parseInt(value); if (value.indexOf(".")!=-1) {checkvalue=checkvalue+1}};
}
if ((parseFloat(min)==min && value.length<min) || (parseFloat(max)==max && value.length>max) || value!=checkvalue)
{if (alertbox!="") {alert(alertbox);} return false;}
else {return true;}
}
}


function formvalidation(thisform)
{
with (thisform)
{
if (emptyvalidation(first,"You cannot leave the FIRST NAME field blank")==false) {first.focus(); return false;};
if (emptyvalidation(last,"You cannot leave the LAST NAME field blank")==false) {last.focus(); return false;};
if (emptyvalidation(address1,"You cannot leave the ADDRESS 1 field blank")==false) {address1.focus(); return false;};
if (emptyvalidation(town,"You cannot leave the TOWN field blank")==false) {town.focus(); return false;};
if (emptyvalidation(postcode,"You cannot leave the POSTCODE field blank")==false) {postcode.focus(); return false;};
if (emailvalidation(email,"You must enter a valid email address")==false) {email.focus(); return false;};
if (emptyvalidation(phone,"You cannot leave the PHONE NUMBER field blank")==false) {phone.focus(); return false;};
}
}

function formvalidationrelay(thisform)
{
with (thisform)
{
if (emptyvalidation(team,"You cannot leave the TEAM NAME field blank")==false) {team.focus(); return false;};
if (emptyvalidation(first,"You cannot leave the FIRST NAME field blank")==false) {first.focus(); return false;};
if (emptyvalidation(last,"You cannot leave the LAST NAME field blank")==false) {last.focus(); return false;};
if (emptyvalidation(address1,"You cannot leave the ADDRESS 1 field blank")==false) {address1.focus(); return false;};
if (emptyvalidation(town,"You cannot leave the TOWN field blank")==false) {town.focus(); return false;};
if (emptyvalidation(postcode,"You cannot leave the POSTCODE field blank")==false) {postcode.focus(); return false;};
if (emailvalidation(email,"You must enter a valid email address")==false) {email.focus(); return false;};
if (emptyvalidation(phone,"You cannot leave the PHONE NUMBER field blank")==false) {phone.focus(); return false;};
if (emptyvalidation(swimmer,"You cannot leave the SWIMMER NAME field blank")==false) {swimmer.focus(); return false;};
if (digitvalidation(mins,2,"You must enter 2 digit number in the mins field","You must enter 2 digit number in the mins field")==false) {mins.focus(); return false;};
if (digitvalidation(secs,2,"You must enter 2 digit number in the secs field","You must enter 2 digit number in the secs field")==false) {secs.focus(); return false;};
if (emptyvalidation(cyclist,"You cannot leave the CYCLIST NAME field blank")==false) {cyclist.focus(); return false;};
if (emptyvalidation(runner,"You cannot leave the RUNNER NAME field blank")==false) {runner.focus(); return false;};
}
}