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(".sorag_suboptions").length && !e.target.id.match(/soraglabel_13_3.*/))
				{
					e.preventDefault();
					e.target.checked = false;
					alert(Webtext.get("sorag_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(".sorag_item").length != checked.length) return false;
		// bilde Summe aus allen Fragen
		var sum = 0;
		checked.each(function()
			{
				sum += parseInt($(this).val());
			}
		);
		
		if (this.numQuest == 13)
		{
			if (sum <= 2)	$("#soraglabel_13_4_1").get(0).checked = true;
			if (sum == 3)	$("#soraglabel_13_4_2").get(0).checked = true;
			if (sum >= 4)	$("#soraglabel_13_4_3").get(0).checked = true;
		}
		if (this.numQuest == 14)
		{
			if (sum <= 1)				$("#soraglabel_14_7_1").get(0).checked = true;
			if (sum >= 2 && sum <= 3)	$("#soraglabel_14_7_2").get(0).checked = true;
			if (sum == 4)				$("#soraglabel_14_7_3").get(0).checked = true;
			if (sum >= 5)				$("#soraglabel_14_7_4").get(0).checked = true;
		}
	}
};

$(function()
	{
		new Screening("sorag_screening_scale", "sorag_screening_btn", 13);
		new Screening("sorag_cats", "sorag_cats_btn", 14);
	}
);
