$(document).ready(function(){	
	//Add a new input field that sets the payment method type to free as default
	$('<input type="radio" value="10" id="free" name="PaymentMethodType" selected="true" style="display:none;" /><input type="radio" value="1" id="creditCard" name="PaymentMethodType" selected="true"  style="display:none;" />').appendTo("table.webform");

	function hideFields(){   
		//change the payment method type to free
		$("input#free").attr("checked",true);
		$("input#creditCard").attr("checked",false);
		//Hide credit card fields
		$("input#CardName").parent().parent().hide("slow");
		$("input#CardNumber").parent().parent().hide("slow");
		$("select#CardExpiryMonth").parent().parent().hide("slow");
		$("input#CardCCV").parent().parent().hide("slow");
		$("select#CardType").parent().parent().hide("slow");
		$("input#Amount").parent().parent().hide("slow");
		//Hide voucher
		$("input#CAT_Custom_110724").parent().parent().hide("slow");		
	};
	
	function showVoucher(){    
			hideFields();
		 //show the ticket number fields
			$("input#CAT_Custom_110724").parent().parent().show("slow");
	};
	
	function showCreditCard(){    
		hideFields();
		//change the payment method type to credit card
		$("input#free").attr("checked",false);
		$("input#creditCard").attr("checked",true);
		 //show the hidden fields
		 	$("input#CardName").parent().parent().show("slow");
			$("input#CardNumber").parent().parent().show("slow");
			$("select#CardExpiryMonth").parent().parent().show("slow");
			$("input#CardCCV").parent().parent().show("slow");
			$("select#CardType").parent().parent().show("slow");
			$("input#Amount").parent().parent().show("slow");
			$("input#CAT_Custom_107539").parent().parent().show("slow");	
	};
	
	//Run the hide function so the cc fields are hidden initailly
	hideFields();
	
	//Detect changes in the "attendee type" radio buttons
	 $("input#CAT_Custom_110721_0").click(function(){ showCreditCard() });
	 $("input#CAT_Custom_110721_1").click(function(){ showVoucher() });
	 
	 
});
