/********************************************

The Catalyst Schools
jQuery Donate Form

Version: 1.0
Author: Poccuo (http://www.poccuo.com)        	

*******************************************/

$(document).ready(function(){
	
	//THIS WILL BE RUDENDENT
	$("#donation_form").validate();
	
	$(".hide_temporarily").hide();

	function checkValues() {
	
		if ($("#recurringDonation").attr("checked")) {
       	$("#recurringDonation_options").fadeIn("slow");
   	} else {
       	$("#recurringDonation_options").hide();
       	$("#recurringDonation_options input").val('');
       }

       if ($("#gift").attr("checked")) {
       	$("#gift_options").fadeIn("slow");
       	$("#gift_to").addClass("required");
   	} else {
       	$("#gift_options").hide();
       	$("#gift_options input").val('');
       	$("#gift_options textarea").val('');
       	$("#gift_to").removeClass("required");
       }

       if ($("#inMemoryOf").attr("checked")) {
       	$("#inMemoryOf_options").fadeIn("slow");
       	$("#memory_name").addClass("required");
   	} else {
       	$("#inMemoryOf_options").hide();
       	$("#inMemoryOf_options input").val('');
			$("#inMemoryOf_options textarea").val('');
       	$("#memory_name").removeClass("required");
       }

	}

	$("#recurringDonation").click(checkValues);
	$("#gift").click(checkValues);
	$("#inMemoryOf").click(checkValues);

	//If they click in the custom amount text box select the radio button
	$('#x_amount_custom').click(function() {
		$('#x_amount_custom_select').attr('checked', true);
	});

	//If they click the radio button select the custom amount text box, if they click another empty it
	$('[name=x_amount]').click(function() {
		if($('#x_amount_custom_select').is(':checked'))  {
			$('#x_amount_custom_select').parent('li').find.('#x_amount_custom').focus();
	   	} else {
			$('#x_amount_custom').val('');
		}
	});

	checkValues();
		
});


