<!--
var failMessage = "";

function submitForm()
{
	document.join.submit();
	return;
}

function validateorder()
{
	var jcardsecuritycode = document.join.cardsecuritycode.value;
	if (jcardsecuritycode=="")
	{
		alert("Please input your card sercurity code and re-submit the order");
		document.join.cardsecuritycode.focus();
		return;
	}

	var jdob = document.join.dob.value;
	if (jdob=="")
	{
		alert("Please input your date of birth and re-submit the order");
		document.join.dob.focus();
		return;
	}

	var jjob = document.join.jobname.value;
	if (jjob=="")
	{
		alert( "Please input your job details and re-submit the order ");
		document.join.jobname.focus();
		return;
	}

	var jtitle = document.join.title.value;
	if (jtitle=="")
	{
		alert( "Please input your title and re-submit the order ");
		document.join.title.focus();
		return;
	}

	var jsurname = document.join.surname.value;
	if (jsurname=="")
	{
		alert( "Please input your surname and re-submit the order ");
		document.join.surname.focus();
		return;
	}

	var jfname = document.join.fname.value;
	if (jfname=="")
	{
		alert( "Please input your first name and re-submit the order ");
		document.join.fname.focus();
		return;
	}

	var jstreet1 = document.join.street1.value;
	if (jstreet1=="")
	{
		alert( "Please input your street and re-submit the order ");
		document.join.street1.focus();
		return;
	}

	var jdistrict = document.join.district.value;
	if (jdistrict=="")
	{
		alert( "Please input your district and re-submit the order ");
		document.join.district.focus();
		return;
	}

	var jtown = document.join.town.value;
	if (jtown=="")
	{
		alert( "Please input your town and re-submit the order ");
		document.join.town.focus();
		return;
	}

	var jcounty = document.join.county.value;
	if (jcounty=="")
	{
		alert( "Please input your county and re-submit the order ");
		document.join.county.focus();
		return;
	}

	var jpostcode = document.join.postcode.value;
	if (jpostcode=="")
	{
		alert( "Please input your postcode and re-submit the order ");
		document.join.postcode.focus();
		return;
	}

	var jphone = document.join.phone.value;
	if (jphone=="")
	{
		alert( "Please input your phone and re-submit the order ");
		document.join.phone.focus();
		return;
	}

	var jagree = document.join.agree_to_CoM[0].checked;
	if (jagree!=true)
	{
		alert( "Sorry, but to apply, you must agree to the Conditions of Membership ");
		document.join.agree_to_CoM[0].focus();
		return;
	}

	if(document.join.email.value!="")
	{
		if(!emailCheck(document.join.email.value))
		{
			alert("Your email address: " + document.join.email.value + "\ndoes not appear to be correct.\nReason: " + failMessage + "\n\nTo prevent spam our email server is configured to remove email from invalid accounts.\nWe will not receive your application if the email address is not valid.");
			document.join.email.focus();
			return;
		}
	}

	if(document.join.email.value=="")
	{
		if(confirm("No email address\nEnter it now?"))
		{
			var newEmail = prompt("Enter email address:",'email');
			document.join.email.value = newEmail;
			if(!emailCheck(document.join.email.value))
			{
				alert("Your email address: " + document.join.email.value + "\ndoes not appear to be correct.\nReason: " + failMessage + "\n\nTo prevent spam our email server is configured to remove email from invalid accounts.\nWe will not receive your application if the email address is not valid.");
				document.join.email.focus();
				return;
			}
		}
		else
		{
			alert("As you have not entered an email address\nyour application can not be confirmed by email.");
		}
	}


	var joffer = document.join.free_offer_yes.checked;
	var jpayingfor1 = document.join.paying_for1.checked;
	var jpayingfor2 = document.join.paying_for2.checked;
	if ((jpayingfor1=="") && (jpayingfor2==""))
	{
		alert( "Please tell us which register you would like to enroll on, and re-submit the order ");
		document.join.paying_for1.focus();
		return;
	}
	if ((jpayingfor2=="") && (joffer!=""))
	{
		alert( "I'm sorry, the free offer is only for the Top People's Register ");
		document.join.free_offer_yes.focus();
		return;
	}

	var jcard = document.join.card.value;
	if (jcard=="")
	{
		alert( "Please input your credit-card details and re-submit the order ");
		document.join.card.focus();
		return;
	}

	var jcnum = document.join.cnum.value;
	if (jcnum=="")
	{
		alert( "Please input your credit-card number and re-submit the order ");
		document.join.cnum.focus();
		return;
	}

	validatecard();
}


function validatecard()
{

	if(validatecardfunc()==true)
	{
		//alert ("Credit card validated! Please press 'OK' to continue.");
		submitForm();
	}
	else
	{
		alert ("Credit card not valid! Please double check account number entered, validity date and name!");
	}
}

function validatecardfunc()
{
	validcard=false;
	ret=stripNonNumbers (document.join.cnum.value);
	thing=document.join.card.selectedIndex;
	result=document.join.card.options[thing].text;

	if (result=="Mastercard")
	{
		if (ret.length==16)
		validcard=true;
		if ((ret.substring (0,2)>="51") &&
		   (ret.substring (0,2)<="55"))
			validcard=true;
		else
			validcard=false;
	}

	if (result=="Visa")
	{
		if (((ret.length == 16) || (ret.length == 13)) && (ret.substring (0,1)=="4"))
		{
			validcard=true;
		}
		else
		{
			validcard=false;
		}
	}

	if (result=="Switch")
	{
		validcard=true;
	}

	if (result=="Delta")
	{
		validcard=true;
	}

	if (result=="Solo")
	{
		validcard=true;
	}

	if (result=="JCB")
	{
		validcard=true;
	}

	return (validcard);
}

function stripNonNumbers (InString)
{
	OutString="";
	for (Count=0;Count<InString.length;Count++)
	{
		TempChar=InString.substring (Count,Count+1);
		Strip=false;
 		CharString="0123456789";
		for (Countx=0;Countx<CharString.length;Countx++)
		{
			StripThis=CharString.substring (Countx,Countx+1)
			if (TempChar==StripThis)
			{
				Strip=true;
				break;
			}
		}
		if (Strip)
		OutString=OutString+TempChar;
	}
	return (OutString);
}


function emailCheck(emailStr)
{
	var checkTLD=1;
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	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)
	{
		failMessage = "Email address seems incorrect (check @ and .'s)";
		return false;
	}

	var user=matchArray[1];
	var domain=matchArray[2];

	for (i=0; i<user.length; i++)
	{
		if (user.charCodeAt(i)>127)
		{
			failMessage = "Ths username contains invalid characters.";
			return false;
		}
	}
	for (i=0; i<domain.length; i++)
	{
		if (domain.charCodeAt(i)>127)
		{
			failMessage = "Ths domain name contains invalid characters.";
			return false;
		}
	}

	if (user.match(userPat)==null)
	{
		failMessage = "The username doesn't seem to be valid.";
		return false;
	}

	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null)
	{
		for (var i=1;i<=4;i++)
		{
			if (IPArray[i]>255)
			{
				failMessage = "Destination IP address is invalid!";
				return false;
   			}
		}
		return true;
	}

	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++)
	{
		if (domArr[i].search(atomPat)==-1)
		{
			failMessage = "The domain name does not seem to be valid.";
			return false;
		}
	}

	if (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1)
	{
		failMessage = "The address must end in a 3 letter domain (eg:'com') or two letter country (eg:'uk').";
		return false;
	}

	if (len<2)
	{
		failMessage = "This address is missing a hostname!";
		return false;
	}

	return true;
}
//-->

