$(document).ready(function() {

	$("input[name='type']").click(function () {
		if($("input[name='type']:checked").val() == "P") {
			$("#vocaltraining").removeAttr("disabled");
			$("span.passiveparticipants").show();
		} else {
			$("span.passiveparticipants").hide();
			$("#vocaltraining").attr("checked","checked");
			$("#vocaltraining").attr("disabled","disabled");			
		}
	});
	$("input[name='course']").click(function () { updatePrice();});
	$("input[name='type']").click(function () { updatePrice();});
	$("input[name='lodging']").click(function () { updatePrice();});
	$("input[name='singleroom']").click(function () { updatePrice();});
	$("input[name='vocaltraining']").click(function () { updatePrice();});
	
});

function updatePrice() {
	var course_id 		= $("input[name='course']:checked").val();
	var type 			= $("input[name='type']:checked").val();
	var lodging 		= $("input[name='lodging']:checked").val();
	var singleroom 		= new Boolean($('input[name="singleroom"]').attr("checked"));
	var vocaltraining 	= new Boolean($('input[name="vocaltraining"]').attr("checked"));
	
	var url = "getPrice.do?";
	$.getJSON(url,{course_id: course_id, type: type, lodging: lodging, singleroom: singleroom, vocaltraining: vocaltraining}, function(json) {
		$("table#applicationPrice td.fee").html(json.fee + "&euro;");
		$("table#applicationPrice td.totalfee").html(json.fee + "&euro;");
		$("table#applicationPrice td.applicationfee").html(json.application_fee + "&euro;");
		$("table#applicationPrice td.totalapplicationfee").html(json.application_fee + "&euro;");
		$("table#applicationPrice td.coaching").html(json.coaching + "&euro;");
		$("table#applicationPrice td.totalcoaching").html(json.coaching + "&euro;");	
		$("table#applicationPrice td.total").html(((json.fee)+(json.application_fee)+(json.coaching)) + "&euro;");		
		
		$("table#extrasPrice td.courseDays").html(json.days);
		$("table#extrasPrice td.lodging").html(json.lodging + "&euro;");
		$("table#extrasPrice td.totallodging").html(json.days*json.lodging + "&euro;");
		$("table#extrasPrice td.singleroom").html(json.singleroom + "&euro;");
		$("table#extrasPrice td.totalsingleroom").html(json.days*json.singleroom + "&euro;");	
		$("table#extrasPrice td.total").html(((json.days*json.lodging)+(json.days*json.singleroom)) + "&euro;");
	});	
}