function isEmailAddr (s){ 
	var rv = false
	if ((s == null) || (s.length == 0)) 
       	rv = false;
 	 else {
		var reEmail =/([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		//reEmail = /.+\@.+\..+$/
		
		rv = reEmail.test(s)
    }
	if(rv){
		return rv
	}else{
		return false
	}
}

function validateRadio(theRadio){
	// set var radio_choice to false
	var radio_choice = false;

	if(theRadio){
		// Loop from zero to the one minus the number of radio button selections
		for (counter = 0; counter < theRadio.length; counter++){
			// If a radio button has been selected it will return true
			// (If not it will return false)
			if (theRadio[counter].checked){
				radio_choice = true; 
				strRadioValue = theRadio[counter].value;
			}
		}
		if(!radio_choice){
			return (false);
		}
			return (true);
	}else{
		return true	
	}
}

function validateSelect(selectbox){
	var iSelect = selectbox.options[selectbox.selectedIndex].value ;
	if(iSelect == 0){
		return false;
	}else{
		return true;
	}
}

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 validateCheckbox(checkbox){
	var isChecked = false;
	
	for (var i = 0; i < checkbox.length; i++) {
   		if (checkbox[i].checked) {
    		isChecked = true;
   		}
	}
	
	return isChecked;
}

var strRadioValue;
function validation(theForm){
	if (theForm.First_Name.value == ""){
    	alert("Please enter your First Name.");
    	theForm.First_Name.focus();
    	return (false);
  	}
	if (theForm.Surname.value == ""){
    	alert("Please enter your Surname.");
    	theForm.Surname.focus();
    	return (false);
  	}
  	if (!isEmailAddr(theForm.Email.value)){
    	alert("Please enter a complete email address in the form: yourname@yourdomain.com");
    	theForm.Email.focus();
    	return (false);
 	}
	if (!isEmailAddr(theForm.Email_Confirmed.value) || (theForm.Email.value != theForm.Email_Confirmed.value)){
    	alert("Please confirm your email address");
    	theForm.Email_Confirmed.focus();
    	return (false);
 	}
	
	strRadioValue="";
	if (!validateRadio(theForm.Occupation)){
		alert("Please select your main Occupation."); 
		theForm.Occupation[0].focus();
		return false;
	}
	if(strRadioValue == "Other" && theForm.Occupation_Other.value == ""){
    	alert("Please enter your main Occupation.");
    	theForm.Occupation_Other.focus();
    	return (false);
	}
	
	if (!validateCheckbox(theForm.Tight_Management_Farm)){
    	alert("Please select the Tight Management Farm/s that you would like to receive regular email updates on.");
    	theForm.Tight_Management_Farm[0].focus();
    	return (false);
 	}
	return (true);
}