﻿function KeyDownHandlerTwo(btn, e)
			{
				//alert("here" + btn);
		
				// process only the Enter key
				var ex = e;
				if (ex==null) {
					ex = window.event;
				}
				if (ex.keyCode == 13)
				{
					var theBtn = document.getElementById(btn);
					// cancel the default submit 
					//ex.returnValue=false;
					//ex.cancel = true;
					// submit the form by programmatically clicking the specified button
					//alert("The btn is " + theBtn.id);
					//alert(theBtn.id);
					theBtn.click();
					//document.getElementById(btn).createEvent("click");
					
					return false;
				}else {
				    return true;
				}
			}
			
			function checkRegister()
			{
				var result=true;
				if (document.getElementById("txtGuestForename").value=="")
				{
					alert("You need to enter your name");
					result=false;
				}
				if (document.getElementById("txtGuestEmail").value=="")
				{
					alert("You need to enter a email address");
					result=false;
				}				
				if (result)
				{
					result=validEmail(document.getElementById("txtGuestEmail").value);
				}
				
				return result;
			}
			
			function validEmail(emailAddr)	//---------validEmail()------------checks email validity---------------
			{
				var error = false;
				var email=emailAddr;
				invalidChars ="/:,; ";
				if  (email == "")//email not entered
				{
					errorString = "Please enter a valid email address";error = true;
				}
			
				for(i=0; i<invalidChars.length; i++)//checks for the invalid characters
				{
					badChar = invalidChars.charAt(i)
					if(email.indexOf(badChar,0)>-1)
					{
						if(badChar == ' ')
						{
							errorString = "Error: Email must not contain spaces.\n Please correct.";error = true;
						}
						else
						{
							errorString = "Error: Email must not contain the character: ' " + badChar + " '.\n Please correct.";error = true;
	   					}
	   				}
				}

				atPos = email.indexOf("@",1);//checks position
				if(atPos == -1)
				{
					errorString = "Email Error: Missplaced ' @ ' symblol.\n Please correct.";error =  true;
				}
				if(email.indexOf("@",atPos+1) !=-1)//checks pos
				{
					errorString = "Email Error: Missplaced ' @ ' symblol.\n Please correct.";error =  true;
				}
				periodPos=email.indexOf(".",atPos)//checks point for .provider
				if(periodPos ==-1)
				{
					errorString = "Email Error: Missplaced ' . ' symblol.\n Please correct.";error = true;
				}
				if(periodPos + 3 > email.length)//checks length of provider atleast 3 as standard
				{
					errorString = "Email Error: Error with right hand side of address.\n Please correct.";error = true;
				}
				if (error)
				{
					alert(errorString);
					return false;
				}
				for(i=0; i<email.length; i++)
				{	
					//checks for 'www' in email address
					if(email.charAt(i) == 'w' && email.charAt(i+1) == 'w' && email.charAt(i+2) == 'w' && wwwCheck == true)
					{
						if(confirm("Caution: WWW is for surfing the web, it is not usually part of an email address.\nClick OK to confirm or cancel to correct address.") == false)
						{
							return false;
						}
					}else
					{
						wwwCheck = false;
					}
				}
				
				return true;
			}
