function Screening(rootDivId, toggleBtnId, numQuest)
{
	this.numQuest = numQuest;
	this.rootDiv = $("#" + rootDivId).hide();
	this.toggleBtn = $("#" + toggleBtnId);
	this.init();
}

Screening.prototype = {
	init: function()
	{
		$(":radio[name=answer_" + this.numQuest + "]").bind("click", function(e)
			{
				if ($(e.target).parents(".vrag_suboptions").length)
				{
					e.preventDefault();
					e.target.checked = false;
					alert(Webtext.get("vrag_tablehint"));
				}
				else
					this.rootDiv.find(":radio:checked").each(function(){this.checked = false});
			}.bind(this)
		);
		this.toggleBtn.bind("click", function(e){this.rootDiv.slideToggle("normal")}.bind(this));
		var _self = this;
		this.rootDiv.find(":radio").each(function(index)
			{
				$(this).bind("click", function(e){_self.calcResult()});
			}
		);
	},
	calcResult: function()
	{
		var checked = this.rootDiv.find(":radio:checked");
		if (this.rootDiv.find(".vrag_item").length != checked.length) return false;
		// bilde Summe aus allen Fragen
		var sum = 0;
		checked.each(function()
			{
				sum += parseInt($(this).val());
			}
		);
		
		if (this.numQuest == 12)
		{
			if (sum <= 1)				$("#vraglabel_12_7_1").get(0).checked = true;
			if (sum >= 2 && sum <= 3)	$("#vraglabel_12_7_2").get(0).checked = true;
			if (sum == 4)				$("#vraglabel_12_7_3").get(0).checked = true;
			if (sum >= 5)				$("#vraglabel_12_7_4").get(0).checked = true;
		}
	}
};

$(function()
	{
		new Screening("vrag_cats", "vrag_cats_btn", 12);
	}
);
