$(document).ready(function() {
	// Hide our address details, billing details and referral other fields initially
	$('.billing_details, .delivery_details, #referral_other').hide();
	// Show correct form fieldsets initially
	showCorrectFieldsets();

	// Show correct form fieldsets when the registration type or delivery address checkbox changes
	$('input[name=registration_type],input[name=same_delivery_address]').click(function() {
		showCorrectFieldsets();
	});
	
	// Show correct fieldsets when the referral field changes
	$('select[name=referral_id]').change(function() {
		showCorrectFieldsets();											  
	});
});
function showCorrectFieldsets() {
	// Check whether to show/hide our billing details
	if($('input[name=registration_type]:checked').val()=='free') { 
		// Free registration so hide billing and delivery addresses
		$('.billing_details, .delivery_details').slideUp('fast');
	} else {
		// Subscription so show billing details
		$('.billing_details').slideDown('fast');
		// Check whether we need to show delivery details aswell
		if($('input[name=same_delivery_address]:checked').val()=='1') { 
			// Same address so hide billing details
			$('.delivery_details').slideUp('fast');			
		} else {
			// Different address so show billing details
			$('.delivery_details').slideDown('fast');
		}
	}
	// Check whether to show the referrals other field
	if($('select[name=referral_id]').val()=='other') {
		$('#referral_other').slideDown('fast');
	} else {
		$('#referral_other').slideUp('fast');
	}
}