$(function() {
	$("fieldset.optionlist input:checkbox").live("click", function(e) {

		var params = "[" + $.map($("fieldset.optionlist input:checkbox"), function(checkbox, index) {
			return '{"Key":' + $(checkbox).val() + ',"Value":' + ((checkbox.checked) ? 1 : 0)  + '}';
		}).join() + "]";
		var url = "/zorgverleners/services/serviceresults.svc/GetAttributeCount?attributesValues=" + params;
		//var url = "/frontend_20/assets/data/counters/counters.txt?params=" + params;

		$.getJSON(url, function(data) {
			$(data.d).each(function(index, obj) {
				var checkbox = $("input[value='" + obj.Key + "']");
				checkbox.next("label").find("span").text(" (" + obj.Value + ")");
				if (obj.Value == 0) {
					checkbox.filter(":checkbox, :radio").attr("disabled", "disabled").parents("div:first").addClass("disabled");
				} else {
					checkbox.filter(":checkbox, :radio").removeAttr("disabled").parents("div:first").removeClass("disabled");
				}
			});
			$("p.amount span").text(data.d[0].Value);
		});

	});

});
