function updateVisibleOptions(){
  if($("#_monthly").val() === "0"){
    $("#annual-donations").show();
    $("#monthly-donations").hide();
    $("#lifetime").hide();
    $("#annual-donations ." + $("#monthly-donations input:checked").attr("class")).attr("checked", "checked"); 
  } else if($("#_monthly").val() === "1") {
    $("#annual-donations").hide();
    $("#monthly-donations").show();
    $("#lifetime").hide();
    $("#monthly-donations ." + $("#annual-donations input:checked").attr("class")).attr("checked", "checked"); 
  } else {
    $("#annual-donations").hide();
    $("#monthly-donations").hide();
    $("#lifetime").show();
  }
}

$(document).ready(function() {
  $(".options-header").hide();
  updateVisibleOptions();
  $("#_monthly").change(function(){
    updateVisibleOptions();
    
  })
  
  $('form.supporter-signup-form').submit(function(){
    var haserror = false;
    var errormessage = '';
    
    if(!$('#email').val().isValidEmail())
		{
			haserror=true;
			errormessage = 'Please enter a valid email address';					
		}


		if(!(
			$('#name').val().length>0 &&
			$('#address').val().length>0 &&
			$('#telephone').val().length>0
		))
		{
			haserror = true;
			errormessage = 'Please complete each field';
		}

		// If we have an error alter the message and return false
		if(haserror === true)
		{
			$("#errorholder").html(errormessage);
			$("#errorholder").show();
			return false;
		}
		else
		{
			$('#donate_submit_button').attr("disabled", "disabled");
			return true;
		}
  });
});