function setSatisfactionBlock()
{
	for (var star=0; star<5; ++star)
	{
		$("#star_999_"+ star).click(function() { var split = $(this).attr("id").split("_"); setStars(999,split[2]); $("#satisfaction").animate({ height:0 },500,function() {}); }).hover(
			function() { var split = $(this).attr("id").split("_"); showStars(999,split[2]); },
			function() { var split = $(this).attr("id").split("_"); checkStars(999); }
		);
	}
}

function setFeedbackBlocks()
{
	$("#feedbackbtn").click(function() { toggleFeedbackDiv(); })/*.hover(
		function() { if ($("#feedback").width()<50) $("#feedback").width(40); },
		function() { if ($("#feedback").width()<50) $("#feedback").width(30); }
	)*/;
	if ($("#feedbackcontent").height()<$("#feedbackbtn").height()-12) $("#feedbackcontent").height($("#feedbackbtn").height()-12);
	$("#feedbackcancelbtn").click(function() { clearAndCloseFeedbackDiv(); });

	for (var block=0; block<nrOfBlocks; ++block)
	{
		for (var star=0; star<5; ++star)
		{
			$("#star_"+ block +"_"+ star).click(function() { var split = $(this).attr("id").split("_"); setStars(split[1],split[2]); }).hover(
				function() { var split = $(this).attr("id").split("_"); showStars(split[1],split[2]); },
				function() { var split = $(this).attr("id").split("_"); checkStars(split[1]); }
			);
		}
	}

	$("#feedbacksubmitbtn").click(function()
	{
		var allVals = new Array(nrOfBlocks);
		for (var block=0; block<nrOfBlocks; ++block)
		{
			var questionid = "";
			if ($("#text_" + block).length > 0)
			{
				questionid = $("#text_" + block).parent("p").attr("id");
				allVals[block] = questionid+":"+$("#text_" + block).val();
			}
			else
			{
				var tmpVal = -1;
				$(".star_" + block).each(function(i)
				{
					if (i==0) questionid = $(this).parent("p").attr("id");
					if ($(this).hasClass("active")) tmpVal = $(this).attr("id");
				});
				if (tmpVal!=null && tmpVal!=undefined && tmpVal.length>0) tmpVal = tmpVal.substring(tmpVal.length-1, tmpVal.length);
				allVals[block] = questionid+":"+(parseInt(tmpVal)+1);
			}
		}

		var url = encodeURIComponent(location.href);

		var info = "url="+url+"&nrOfAnswers="+nrOfBlocks+"&sw="+screen.width+"&sh="+screen.height+"&w="+$(window).width()+"&h="+$(window).height();
		$.each(allVals,function(index, val) { info += "&answer"+index+"="+val.replace(/\n/gi,"%0A"); });

		$.ajax({url:"ajax/feedback/saveAnswer.jsp",data:info,dataType:"script"});

		clearAndCloseFeedbackDiv("close");
	});

	$(".star_999").click(function()
	{
		var tmpVal = $(this).attr("id");
		if (tmpVal!=null && tmpVal!=undefined && tmpVal.length>0) tmpVal = tmpVal.substring(tmpVal.length-1, tmpVal.length);
		tmpVal = (parseInt(tmpVal)+1);

		var url = encodeURIComponent(location.href);

		var info = "url="+url+"&nrOfAnswers=1&sw="+screen.width+"&sh="+screen.height+"&w="+$(window).width()+"&h="+$(window).height()+"&answer0="+tmpVal+"&satisfaction=1";

		$.ajax({url:"ajax/feedback/saveAnswer.jsp",data:info,dataType:"script"});
	});
}

function clearAndCloseFeedbackDiv(action)
{
	toggleFeedbackDiv(action);
	$(".star").removeClass("active").attr("src","images/feedback/star-off.png");
	$(".feedbacktext").val("");
}

function toggleFeedbackDiv(action)
{
	if ($("#feedback").width()<50)
	{
		if (action!=null && action=="close") $("#feedback").animate({ width:434 },1250,function() { $(this).hide(); });
		else $("#feedback").animate({ width:434 },1250,function() {});
	}
	else
	{
		if (action!=null && action=="close") $("#feedback").animate({ width:30 },1000,function() { $(this).hide(); });
		else $("#feedback").animate({ width:30 },1000,function() {});
	}
}

function setStars(block,star)
{
	$(".star_"+block).removeClass("active");
	$("#star_"+block+"_"+star).addClass("active");
}

function showStars(block,star)
{
	if (star==null || star==undefined) $(".star_"+block).attr("src","images/feedback/star-off.png");
	else if (star==4) $(".star_"+block).attr("src","images/feedback/star-on.png");
	else
	{
		for (var i=0; i<=star; ++i) $("#star_"+block+"_"+i).attr("src","images/feedback/star-on.png");
		for (var i=star+1; i<5; ++i) $("#star_"+block+"_"+i).attr("src","images/feedback/star-off.png");
	}
}

function checkStars(block)
{
	var clearAll = true;
	for (var i=0; i<5; ++i)
	{
		if ($("#star_"+block+"_"+i).hasClass("active"))
		{
			showStars(block,i);
			clearAll = false;
			break;
		}
	}
	if (clearAll) showStars(block,null);
}
