// JavaScript Document

function valForm()
	{

	 var MEMBER_NAME = document.getElementById("MEMBER_NAME").value;
	 var MEMBER_EMAIL = document.getElementById("MEMBER_EMAIL").value;	 
	 var MEMBER_OPTIN = document.getElementById("MEMBER_OPTIN").value;	 
	 var MEMBER_SPAM_VAL = document.getElementById("MEMBER_SPAM_VAL").value;	 

	 if(MEMBER_NAME == "")
	  {
	   alert("Please enter your name");
	   document.getElementById("MEMBER_NAME").focus();
	   document.getElementById("Submit").disabled = false;
	   return false;
	  }

	  if(MEMBER_EMAIL == "")
	  {
	   alert("Please supply your email address");
	   document.getElementById("MEMBER_EMAIL").focus();
	   document.getElementById("Submit").disabled = false;
	   return false;
	  }	
	  if(MEMBER_EMAIL.indexOf (".",0) == -1)
	  {
	   alert("The Email field must contain the \".\" character.\nPlease try again.");
	   document.getElementById("MEMBER_EMAIL").focus();
	   document.getElementById("Submit").disabled = false;
	   return false;
	  }
 
	  if(MEMBER_EMAIL.indexOf ("@",0) == -1)
	  {
	   alert("The Email field must contain the \"@\" character.\nPlease try again.");
	   document.getElementById("MEMBER_EMAIL").focus();
	   document.getElementById("Submit").disabled = false;
	   return false;
	  }
	  //check for these characters at the beginning or end of the email address
	  if(MEMBER_EMAIL.charAt(0) == "-" || MEMBER_EMAIL.charAt(0) == "_" || MEMBER_EMAIL.charAt(0) == "." || MEMBER_EMAIL.charAt(0) == "@" || MEMBER_EMAIL.charAt(MEMBER_EMAIL.length-1) == "-" || MEMBER_EMAIL.charAt(MEMBER_EMAIL.length-1) == "_" || MEMBER_EMAIL.charAt(MEMBER_EMAIL.length-1) == "." || MEMBER_EMAIL.charAt(MEMBER_EMAIL.length-1) == "@")
	  {
	    alert("This does not appear to be a valid email address");
		document.getElementById("MEMBER_EMAIL").focus();
		document.getElementById("Submit").disabled = false;
		return false;
	  }
	  
      for(var i = 0; i < MEMBER_EMAIL.length; i++)
      {
         if(!((MEMBER_EMAIL.charAt(i) >= "a" && MEMBER_EMAIL.charAt(i) <= "z") || (MEMBER_EMAIL.charAt(i) >= "A" && MEMBER_EMAIL.charAt(i) <= "Z") || (MEMBER_EMAIL.charAt(i) >= "0" && MEMBER_EMAIL.charAt(i) <= "9")|| MEMBER_EMAIL.charAt(i) == "." || MEMBER_EMAIL.charAt(i) == "-" || MEMBER_EMAIL.charAt(i) == "_" || MEMBER_EMAIL.charAt(i) == "@"))
         {
       	   alert("This does not appear to be a valid email address");
           document.getElementById("MEMBER_EMAIL").focus();
		   document.getElementById("Submit").disabled = false;
		   return false;
         }
      }
	  	
	 if(!document.getElementById("MEMBER_OPTIN").checked)
	  {
		
		var MEMBER_OPTIN=window.confirm("You will NOT receive email correspondence.\nIf this is not what you intended, please press cancel\nand put a tick next to \"Receive stuff\".")
		if (MEMBER_OPTIN)
		{
			//alert("Opting out");
		}
		else
		{
			//alert("Now change to optin");
			document.getElementById("MEMBER_OPTIN").focus();
			document.getElementById("Submit").disabled = false;
			return false;
		}
	  }

	 if(MEMBER_SPAM_VAL == "")
	  {
	   alert("Please type the word shown in the spam filter box. This allows us ensure that you are human.\nIf you cannot read the image, please refresh the page to change the image and try again.");
	   document.getElementById("MEMBER_SPAM_VAL").focus();
	   document.getElementById("Submit").disabled = false;
	   return false;
	  }
	  
	  return true;
}