/*  JAVACRIPT	FOR LEAGUE HTML : CALLED BY */ 

function submitvalid()
{
	      
		//Code below is  used for testing purposes: to get count of elements. 
	         //window.alert("No of elements is: " + document.form1.length);
		//Returns  19
		
		// Code below is used to identify the various elements
		/*
		    for(i=0;i<=18;i++)
		    {
			  window.alert("Value of  box" + [i] + " is: " + form1.elements[i].value);
		    }
		*/
		   
	
	
		  // window.alert("Value of  name box is: " + form1.name.value);
  
	   
	   //TEST FOR EMPTY FIELDS. NOT ALL OF THEM NEED TO BE FILLED IN
	   //NAME  AND SURNAME NEED TO BE FILLED IN
		   for(i=3;i<=4;i++)
		   {
		   	
		   	
		   	if(form1.name.value=="")
		   	{
		   		form1.name.focus();
		   		window.alert("Please fill in the 'name' box!.");
		   		return false;
		   		
		   		 
		        }
		        
		        if(form1.surname.value=="")
			{
				form1.surname.focus();
				window.alert("Please fill in the 'surname' box!.");
				return false;

					   		 
		        }
		        
		        
		        //ALSO TEST FOR TYPE OF INPUT: TEXT OR NUMBERS ONLY
		        if(alpha_test(form1.name.value)!=true)
			{
				window.alert("The 'name' box must only contain letters!");
				form1.name.value= "";
				form1.name.focus();
				return false;
 		   	}
 		   	if(alpha_test(form1.surname.value)!=true)
			{
				window.alert("The 'surname' box must only contain letters!");
				form1.surname.value= "";
				form1.surname.focus();
				return false;
 		   	}
		    
		   	
		   	
		   }

		   
		  
		   
	   
		   // AT LEAST ONE OF THESE MUST BE FILLED IN; HOME TEL NO,WORK TEL NO,MOBILE NO, OR EMAIL ADDRESS
		   if(form1.elements[8].value=="" && form1.elements[9].value=="" && form1.elements[10].value=="" && form1.elements[11].value=="")
		   {
			window.alert("You must give either a telephone number or an email address as contact!");
			form1.elements[8].focus();
			return false;
			
			
			 
		   }
		   
		   
		   // AT LEAST ONE OF THESE MUST BE FILLED IN; ADDRESS LINE1 OR ADDRESS LINE2 OR ADDRESS LINE3
		   if(form1.elements[12].value=="" && form1.elements[13].value=="" && form1.elements[14].value=="" )
		   {
			window.alert("You must fill in at least one of the address lines!");
			form1.elements[12].focus();
			return false;
		   }
		   
		   
		   // AREA, CITY AND POSTCODES MUST BE FILLED IN. CITY IS FILLED IN BT DEFAULT.
		   for(i=15;i<=17;i++)
		  {
		   		   	
		   		   	
			if(form1.area.value=="")
			{
				form1.area.focus();
				window.alert("Please fill in the 'area' box!.");
				return false;


			}
		   	
		   	
		   	
		   	if(form1.city.value=="")
			{
				form1.city.focus();
				window.alert("Please fill in the 'city' box!.");
				return false;
			
			
			}
			
			if(form1.postcode.value=="")
			{
				form1.postcode.focus();
				window.alert("Please fill in the 'postcode' box!.");
				return false;

						
			}
		   		   	
		   }
		   
             // TEST THAT RELEVANT FIELDS CONTAIN NUMBERS ONLY
              // LTA BOX MUST  ONLY CONTAIN NUMBERS  IF IT IS FILLED IN
		   if(alpha_test(form1.elements[6].value)==true)
		   {
			window.alert("The 'LTA' box must contain numbers only!");
			form1.elements[6].value= "";
			form1.elements[6].focus();
			return false;
		   }
		   
		   
	         // HOME TEL, WORK TEL AND MOBILE TEL  BOXES  MUST CONTAIN NUMBERS ONLY IF FILLED IN
		    
		   for(i=8;i<=10;i++)
		   {
			   if(alpha_test(form1.htel.value)==true)
			   {
				window.alert("The 'home telephone' box must contain numbers only!");
				form1.htel.value= "";
				form1.htel.focus();
				return false;
			   }
			   
			   if(alpha_test(form1.wtel.value)==true)
			   {
				window.alert("The 'work telephone' box must contain numbers only!");
				form1.wtel.value= "";
				form1.wtel.focus();
				return false;
			   }
			   
			   if(alpha_test(form1.mtel.value)==true)
			   {
				window.alert("The 'mobile telephone' box must contain numbers only!");
				form1.mtel.value= "";
				form1.mtel.focus();
				return false;
			   }
		   }
	   
		  
		 
		 
		
		
	    //TEST FOR VALIDITY OF EMAIL ADDRESS
		  if( form1.email.value!="")
		  {
			  if(email_test(form1.email.value)==false)
			  {
				//window.alert("Please correct your 'email' address");
				form1.email.focus();
				return false;

			  }
		   }
     		
		  
		 /*
		   window.alert("Your details will now be forwarded!");
		   return true;
		 */
		   
		   
	      //LTA NUMBER NEEDS TO BE FILLED IN UNDER SOME CIRCUMSTANCES
		   if(form1.elements[3].value=="" && form1.rating.options[12].selected==false)
		   {
			window.alert("The 'LTA' box must be filled in if you have a rating!");
			form1.elements[3].focus();
			return false;
		   }


		   if(form1.rating.options[12].selected==true)
		   {

			form1.elements[6].value ="";
			window.alert("To join this League, you will need to apply for an LTA rating! Details available from http://www.lta.org.uk");
		   }
		  confirm_submit(); 
		   
		   
 }
        	
 
 			
 		
 			

 
 function alpha_test(text)
 {
 	var myRegExp=/[a-z]/i;
 	return (myRegExp.test(text));
 }
 

function confirm_submit()
{
	return (confirm("Your details will now be forwarded."));
	
}



function confirm_reset()
{
	window.alert("Are you sure you want to cancel all entries?");
	
	form1.name.value="";
	form1.surname.value="";
	form1.memshipno.value="";
	
	for(i=8;i<16;i++)
	{
		form1.elements[i].value="";
	}
	
	form1.postcode.value="";
}


function email_test(email_address)
{
	if(email_address.length<5)
	{
		window.alert("Please correct your email address. It appears to be too short!");
		//window.alert("It appears to be too short!");
		return false;
	}
	
	at_check=email_address.indexOf("@");
	dot_check=email_address.indexOf(".");
	
	//if(at_check== -1 || dot_check== -1 || at_check>dot_check) 
	if(at_check== -1 || dot_check== -1)
	{
		window.alert("Please correct your email address. It is missing a dot or an @ sign!");
		//window.alert("It is missing a dot or an @ sign!");
		return false;
	}
	
	// Is there at least one character before @?
	if(at_check==0)
	{
		window.alert("Please correct your email address. It cannot start with an @ sign!");
		//window.alert("It cannot start with an @ sign!");
		return false;
	}
	
	//Is there at least one character between @ and .  or between  . and @?
	if((dot_check - at_check) ==1 || (dot_check - at_check) == -1 )
	{
		//window.alert("Position of dot is: " + dot_check);
		//window.alert("Position of @ is: " + at_check);
		//window.alert("Position of dot - position of @ is: " + (dot_check-at_check));
		
		window.alert("Please correct your email address. The @ sign cannot have a dot immediately after it or before it!");
		//window.alert("The @ sign cannot have a dot immediately after it!");
		return false;
	}
	
	//Is there at least one character after .?
	if((email_address.length - dot_check)==0)
	{
		window.alert("Please correct your email address. The address cannot end with a dot!");
		//window.alert("The address cannot end with a dot!");
		return false;
	}
	
	// Otherwise, it's a valid address, so return true
	return true;
}





  function test_array()
{
	var check_array1=new Array(102,101,100,101,114,101,114);
	//var user_pass=prompt("This page is accessible to League members only. Please enter the current password:", "");
	
	var showing=parent.main.location.href
	if(showing.indexOf("reslts.htm")>-1)
	{
		window.alert("You are already on Results page!");
	}
	

	else
	{
		var user_pass=prompt("This page is accessible to League members only. Please enter the current password:", "");
		for(var counter=0;counter<check_array1.length;counter++)
		{

			if(user_pass.charCodeAt(counter)!=check_array1[counter])
			{
				alert("Sorry,password is not correct!");
				return false;
			}

		}
	}
   

	parent.main.location="reslts.htm";
	
	return false;
}
 
 
 
    
function test_arrayn()
{
	var check_array1=new Array(102,101,100,101,114,101,114);
	var showing=parent.main.location.href
	if(showing.indexOf("postns.htm")>-1)
	{
		window.alert("You are already on Positions page!");
	}
	
	

	else
	{
		var user_pass=prompt("This page is accessible to League members only. Please enter the current password:", "");
		for(var counter=0;counter<check_array1.length;counter++)
		{

			if(user_pass.charCodeAt(counter)!=check_array1[counter])
			{
				alert("Sorry,password is not correct!");
				return false;

			}

		}
	}
	

	
	parent.main.location="postns.htm";
	return false;
	
}

     
