$(function() {
	$('#choose_insurance_line').hide()
	$('#AppointmentApplicationStateId').change(function() {
		$('#choose_insurance_line').load('/appointment_applications/choose_insurance/'+$(this).val(), function(e) {
			$('.checkbox.disabled input').attr('disabled', 'disabled')
			if($('.checkbox input:checked').size() > 0) {
				$(this).show()
				$('.submit, .checkbox').show()
				$('.no_lines_found').hide()
			} else {
				$(this).hide()
				$('.submit, .checkbox').hide()
				$('.no_lines_found').show()
			}
			
		});
	});
	
	$('.appointment_application .input.checkbox input').click(function() {
		if(this.checked) {
			$(this).parent().next('.details').slideDown()
		} else {
			$(this).parent().next('.details').slideUp()
		}
	});
	
	$('.check_toggle dd input').click(function() {
		dl = $(this).parents('dl')
		if(dl.children('dd').children('div').children('input:checked').length > 0) {
			dl.next('.details').slideDown()
		} else {
			dl.next('.details').slideUp()
		}
	});
	
});

