function validate_email(field,alerttxt)
{
	with (field)
	{
	apos=value.indexOf("@");
	dotpos=value.lastIndexOf(".");
	if (apos<1||dotpos-apos<2)
	  {alert(alerttxt);return false;}
	else {return true;}
	}
}

function strRight(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

function isDate(sDate) {

   var re = /^\d{1,2}\/\d{1,2}\/\d{4}$/

   if (re.test(sDate)) {

      var dArr = sDate.split("/");
      var currdate=new Date();

      dArr[0] = strRight("0" + dArr[0],2);
      dArr[1] = strRight("0" + dArr[1],2);
      //alert ("dArr[2] = " + dArr[2]);
      //alert ("dArr[1] = " + dArr[1]);


	  var Yr = currdate.getYear();
	  if(Yr<1900){Yr+=1900;}

      if (dArr[2] > Yr) return false;
      if (dArr[2] == Yr) {
      	   	if (dArr[1] -1 > currdate.getMonth()) return false;
      }

      //* swap mm & dd as the next bit wants it in mm/dd/yyyy
	  var d = new Date(dArr[1] + "/" + dArr[0]+ "/" + dArr[2]);

      return d.getMonth() + 1 == dArr[1] && d.getDate() == dArr[0] && d.getFullYear() == dArr[2];
   }
   else {
      return false;
   }
}

function IsNumeric(strString)
   //  check for valid numeric strings
   {
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }

function validate_location(theForm) {

	if ( theForm.location.value == "" ) {
		alert("You must select a Location");
		theForm.location.focus();
		return (false);
	}

}


function validate(theForm) {

    if(eval(theForm.compcatg))
    {
		if (theForm.compcatg.value == "") {
	  		alert ( "You must select a Company Catgeory" );
			theForm.compcatg.focus();
	  		return false;
		}
	}
	if ( theForm.company.value == "" ) {
		alert("You must fill in your Company Name / Government Dept");
		theForm.company.focus();
		 return (false);
	}

	var tt_choice = false;
	for (counter = 0; counter < theForm.teamtype.length; counter++) {
		if (theForm.teamtype[counter].checked) {
			tt_choice = true; }
	}



	if ( theForm.address.value == "" ) {
		alert("You must fill in the Address");
		theForm.address.focus();
		 return (false);
	}
	if ( theForm.suburb.value == "" ) {
		alert("You must fill in the Suburb");
		theForm.suburb.focus();
		return (false);
	}

	if ( theForm.pcode.value == "" ) {
		alert("You must fill in your PCode");
		theForm.pcode.focus();
		return (false);
	}

	if ( theForm.contact.value == "" ) {
		alert("You must fill in the Teams Contact Name");
		theForm.contact.focus();
		 return (false);
	}

	if ( theForm.wkphone.value == "" ) {
		if ( theForm.mobile.value == "" ) {
			alert("You must fill in a Work Phone or Mobile Number");
			theForm.wkphone.focus();
		    return (false);
		}
	}

	if ( theForm.email.value == "" ) {
		alert("You must fill in your email address");
		theForm.email.focus();
		return (false);
	}

	if (validate_email(theForm.email,"Please enter a valid email")==false) {
  		{theForm.email.focus();
  		return false;}
	}

	var catg_choice = false;
	for (counter = 0; counter < theForm.catg.length; counter++) {
		if (theForm.catg[counter].checked) {
			catg_choice = true; }
	}

	if (!catg_choice)
	{
		alert("You must select a Race Category");
		return (false);
	}




	if (!tt_choice)
	{
		alert("You must select a Team Type");
		return (false);
	}


	if ( theForm.teamname.value == "" ) {
		alert("You must fill in your Team Name");
		theForm.teamname.focus();
		 return (false);
	}
	
	if ( theForm.firstname1.value == "" ) {
		alert("You must fill in details for at least the first Entrant");
		theForm.firstname1.focus();
		return (false);
	}
	if ( theForm.surname1.value == "" ) {
		alert("You must fill in details for at least the first Entrant");
		theForm.surname1.focus();
		return (false);
	}

    if ( ( theForm.gender1[0].checked == false )
    && ( theForm.gender1[1].checked == false ) )
    {
        alert ( "You must select a gender for the first Entrant" );
        return (false);
    }

   if (theForm.age1.value.length == 0)
      {
      alert("Please enter an Age");
	  theForm.age1.focus();
	  return (false);
      }
   else if (!IsNumeric(theForm.age1.value))
      {
      alert("Please enter a numeric value for the Age");
	  theForm.age1.focus();
	  return (false);
      }

   if (theForm.age1.value < 1 || theForm.age1.value > 99)
      {
      alert("Please enter an Age between 1 and 99");
	  theForm.age1.focus();
	  return (false);
      }

	var dist_choice = false;
	for (counter = 0; counter < theForm.dist1.length; counter++) {
		if (theForm.dist1[counter].checked) {
			dist_choice = true; }
	}

	if (!dist_choice)
	{
        alert ( "You must select a Distance value for the first Entrant" );
        return (false);
    }

	if ( theForm.email1.value == "" ) {
		alert("You must fill in your email address");
		theForm.email1.focus();
		return (false);
	}

	if (validate_email(theForm.email1,"Please enter a valid email")==false) {
  		{theForm.email1.focus();
  		return false;}
	}


    if(eval(theForm.surname2)) {
		if ( theForm.surname2.value != "" || theForm.firstname2.value != "" ) {
			if ( theForm.surname2.value == "" ) {
				alert("Please enter a Surname for the second Entrant");
				theForm.surname2.focus();
				return (false);
			}
			if ( theForm.firstname2.value == "" ) {
				alert("Please enter a First Name for the second Entrant");
				theForm.firstname2.focus();
				return (false);
			}

		    if ( ( theForm.gender2[0].checked == false )
		    && ( theForm.gender2[1].checked == false ) )
		    {
		        alert ( "You must select a gender for the second Entrant" );
		        return (false);
		    }

		   if (theForm.age2.value.length == 0)
		      {
		      alert("Please enter an Age for the second Entrant");
			  theForm.age2.focus();
			  return (false);
		      }
		   else if (!IsNumeric(theForm.age2.value) )
		      {
		      alert("Please enter a numeric value for the Age of the second Entrant");
			  theForm.age2.focus();
			  return (false);
		      }

		   if (theForm.age2.value < 1 || theForm.age2.value > 99)
		      {
		      alert("Please enter an Age between 1 and 99");
			  theForm.age2.focus();
			  return (false);
		      }

			var dist_choice = false;
			for (counter = 0; counter < theForm.dist2.length; counter++) {
				if (theForm.dist2[counter].checked) {
					dist_choice = true; }
			}

			if (!dist_choice)
			    {
		        alert ( "You must select a Distance value for the second Entrant" );
		        return (false);
		    }
		    
			if ( theForm.email2.value == "" ) {
				alert("You must fill in your email address");
				theForm.email2.focus();
				return (false);
			}
		
			if (validate_email(theForm.email2,"Please enter a valid email")==false) {
		  		{theForm.email2.focus();
		  		return false;}
			}

		}
	}

    if(eval(theForm.surname3)) {
		if ( theForm.surname3.value != "" || theForm.firstname3.value != "" ) {
			if ( theForm.surname3.value == "" ) {
				alert("Please enter a Surname for the third Entrant");
				theForm.surname3.focus();
				return (false);
			}
			if ( theForm.firstname3.value == "" ) {
				alert("Please enter a First Name for the third Entrant");
				theForm.firstname3.focus();
				return (false);
			}

		    if ( ( theForm.gender3[0].checked == false )
		    && ( theForm.gender3[1].checked == false ) )
		    {
		        alert ( "You must select a gender for the third Entrant" );
		        return (false);
		    }

		   if (theForm.age3.value.length == 0)
		      {
		      alert("Please enter an Age for the third Entrant");
			  theForm.age3.focus();
			  return (false);
		      }
		   else if (!IsNumeric(theForm.age3.value) )
		      {
		      alert("Please enter a numeric value for the Age of the third Entrant");
			  theForm.age3.focus();
			  return (false);
		      }

		   if (theForm.age3.value < 1 || theForm.age3.value > 99)
		      {
		      alert("Please enter an Age between 1 and 99");
			  theForm.age3.focus();
			  return (false);
		      }

			var dist_choice = false;
			for (counter = 0; counter < theForm.dist3.length; counter++) {
				if (theForm.dist3[counter].checked) {
					dist_choice = true; }
			}

			if (!dist_choice)
		    {
		        alert ( "You must select a Distance value for the second Entrant" );
		        return (false);
		    }
			if ( theForm.email3.value == "" ) {
				alert("You must fill in your email address");
				theForm.email3.focus();
				return (false);
			}
		
			if (validate_email(theForm.email3,"Please enter a valid email")==false) {
		  		{theForm.email3.focus();
		  		return false;}
			}

		}
	}

    if(eval(theForm.surname4)) {
		if ( theForm.surname4.value != "" || theForm.firstname4.value != "" ) {
			if ( theForm.surname4.value == "" ) {
				alert("Please enter a Surname for the fourth Entrant");
				theForm.surname4.focus();
				return (false);
			}
			if ( theForm.firstname4.value == "" ) {
				alert("Please enter a First Name for the fourth Entrant");
				theForm.firstname4.focus();
				return (false);
			}

		    if ( ( theForm.gender4[0].checked == false )
		    && ( theForm.gender4[1].checked == false ) )
		    {
		        alert ( "You must select a gender for the fourth Entrant" );
		        return (false);
		    }

		   if (theForm.age4.value.length == 0)
		      {
		      alert("Please enter an Age for the fourth Entrant");
			  theForm.age4.focus();
			  return (false);
		      }
		   else if (!IsNumeric(theForm.age4.value))
		      {
		      alert("Please enter a numeric value for the Age of the fourth Entrant");
			  theForm.age4.focus();
			  return (false);
		      }

		   if (theForm.age4.value < 1 || theForm.age4.value > 99)
		      {
		      alert("Please enter an Age between 1 and 99");
			  theForm.age4.focus();
			  return (false);
		      }

			var dist_choice = false;
			for (counter = 0; counter < theForm.dist4.length; counter++) {
				if (theForm.dist4[counter].checked) {
					dist_choice = true; }
			}

			if (!dist_choice)
		    {
		        alert ( "You must select a Distance value for the second Entrant" );
		        return (false);
		    }
			if ( theForm.email3.value == "" ) {
				alert("You must fill in your email address");
				theForm.email3.focus();
				return (false);
			}
		
			if (validate_email(theForm.email3,"Please enter a valid email")==false) {
		  		{theForm.email3.focus();
		  		return false;}
			}

		}
	}

    if(eval(theForm.surname5)) {
		if ( theForm.surname5.value != "" || theForm.firstname5.value != "" ) {
			if ( theForm.surname5.value == "" ) {
				alert("Please enter a Surname for the fifth Entrant");
				theForm.surname5.focus();
				return (false);
			}
			if ( theForm.firstname5.value == "" ) {
				alert("Please enter a First Name for the fifth Entrant");
				theForm.firstname5.focus();
				return (false);
			}

		    if ( ( theForm.gender5[0].checked == false )
		    && ( theForm.gender5[1].checked == false ) )
		    {
		        alert ( "You must select a gender for the fifth Entrant" );
		        return (false);
		    }

		   if (theForm.age5.value.length == 0)
		      {
		      alert("Please enter an Age for the fifth Entrant");
			  theForm.age5.focus();
			  return (false);
		      }
		   else if (!IsNumeric(theForm.age5.value) )
		      {
		      alert("Please enter a numeric value for the Age of the fifth Entrant");
			  theForm.age5.focus();
			  return (false);
		      }

		   if (theForm.age5.value < 1 || theForm.age5.value > 99)
		      {
		      alert("Please enter an Age between 1 and 99");
			  theForm.age5.focus();
			  return (false);
		      }

			var dist_choice = false;
			for (counter = 0; counter < theForm.dist5.length; counter++) {
				if (theForm.dist5[counter].checked) {
					dist_choice = true; }
			}

			if (!dist_choice)
		    {
		        alert ( "You must select a Distance value for the fifth Entrant" );
		        return (false);
		    }
		    
			if ( theForm.email2.value == "" ) {
				alert("You must fill in your email address");
				theForm.email2.focus();
				return (false);
			}
		
			if (validate_email(theForm.email2,"Please enter a valid email")==false) {
		  		{theForm.email2.focus();
		  		return false;}
			}

		}
	}

    if(eval(theForm.surname6)) {
		if ( theForm.surname6.value != "" || theForm.firstname6.value != "" ) {
			if ( theForm.surname6.value == "" ) {
				alert("Please enter a Surname for the sixth Entrant");
				theForm.surname6.focus();
				return (false);
			}
			if ( theForm.firstname6.value == "" ) {
				alert("Please enter a First Name for the sixth Entrant");
				theForm.firstname6.focus();
				return (false);
			}

		    if ( ( theForm.gender6[0].checked == false )
		    && ( theForm.gender6[1].checked == false ) )
		    {
		        alert ( "You must select a gender for the sixth Entrant" );
		        return (false);
		    }

		   if (theForm.age6.value.length == 0)
		      {
		      alert("Please enter an Age for the sixth Entrant");
			  theForm.age6.focus();
			  return (false);
		      }
		   else if (!IsNumeric(theForm.age6.value) )
		      {
		      alert("Please enter a numeric value for the Age of the sixth Entrant");
			  theForm.age6.focus();
			  return (false);
		      }

		   if (theForm.age6.value < 1 || theForm.age6.value > 99)
		      {
		      alert("Please enter an Age between 1 and 99");
			  theForm.age6.focus();
			  return (false);
		      }

			var dist_choice = false;
			for (counter = 0; counter < theForm.dist6.length; counter++) {
				if (theForm.dist6[counter].checked) {
					dist_choice = true; }
			}

			if (!dist_choice)
		    {
		        alert ( "You must select a Distance value for the sixth Entrant" );
		        return (false);
		    }

			if ( theForm.email6.value == "" ) {
				alert("You must fill in your email address");
				theForm.email6.focus();
				return (false);
			}
		
			if (validate_email(theForm.email6,"Please enter a valid email")==false) {
		  		{theForm.email6.focus();
		  		return false;}
			}

		}
	}
    if(eval(theForm.surname7)) {
		if ( theForm.surname7.value != "" || theForm.firstname7.value != "" ) {
			if ( theForm.surname7.value == "" ) {
				alert("Please enter a Surname for the seventh Entrant");
				theForm.surname7.focus();
				return (false);
			}
			if ( theForm.firstname7.value == "" ) {
				alert("Please enter a First Name for the seventh Entrant");
				theForm.firstname7.focus();
				return (false);
			}

		    if ( ( theForm.gender7[0].checked == false )
		    && ( theForm.gender7[1].checked == false ) )
		    {
		        alert ( "You must select a gender for the seventh Entrant" );
		        return (false);
		    }

		   if (theForm.age7.value.length == 0)
		      {
		      alert("Please enter an Age for the seventh Entrant");
			  theForm.age7.focus();
			  return (false);
		      }
		   else if (!IsNumeric(theForm.age7.value))
		      {
		      alert("Please enter a numeric value for the Age of the seventh Entrant");
			  theForm.age7.focus();
			  return (false);
		      }

		   if (theForm.age7.value < 1 || theForm.age7.value > 99)
		      {
		      alert("Please enter an Age between 1 and 99");
			  theForm.age7.focus();
			  return (false);
		      }

			var dist_choice = false;
			for (counter = 0; counter < theForm.dist7.length; counter++) {
				if (theForm.dist7[counter].checked) {
					dist_choice = true; }
			}

			if (!dist_choice)
		    {
		        alert ( "You must select a Distance value for the seventh Entrant" );
		        return (false);
		    }

			if ( theForm.email7.value == "" ) {
				alert("You must fill in your email address");
				theForm.email7.focus();
				return (false);
			}
		
			if (validate_email(theForm.email7,"Please enter a valid email")==false) {
		  		{theForm.email7.focus();
		  		return false;}
			}
		    
		}
	}

	if (!theForm.Agree1.checked ) {
			 alert("You must agree to this declaration.");
			 theForm.Agree1.focus();
			 return (false);
		}

return true;
}








