$(function(){
	$("#check_start").click(function(){
		var idx = 1;
		var score = 0;
		$(".selectable").each(function(){
			var checked = $(this).attr("checked");
			if (checked) {
				if (idx==1||idx==2||idx==3||idx==5||idx==21) {
					score = score + 8;
				} else {
					score = score + 3;
				}
			}
			idx++;
		});
		var text_image = "selfcheck_bg.jpg";
		var text_score = "あなたの糖尿病危険度は"+score+"%です。";
		var text_comment = "";
		if (score>=51) {
			text_comment = "糖尿病の可能性大！！ 生活改善が必要です。<br />今すぐ専門医への受診をおすすめします。<br />糖尿病は重症になる前に、早い段階で改善することが大切です。";
			text_image = "selfcheck_bg04.jpg";
		} else if (score>=20) {
			text_comment = "もしかしたら、糖尿病かも！？<br />自覚症状がないからと放置していませんか？<br />できるだけ早く空腹時血糖値やヘモグロビンA1cなどの検査の受診をおすすめします。";
			text_image = "selfcheck_bg03.jpg";
		} else if (score>=11) {
			text_comment = "糖尿病予備群の可能性大！！<br />食べすぎや肥満に注意し、定期的な検査を受けて、<br />糖尿病にならないように気をつけましょう。<br />";
			text_image = "selfcheck_bg02.jpg";
		} else {
			text_comment = "今のところ糖尿病の心配はないようです。<br />でも、油断は禁物！<br />今後もバランスの良い食事や適度な運動を心がけましょう";
			text_image = "selfcheck_bg01.jpg";
		}
		$("#answer_text").css("background-image", "url(../img/diabetic/"+text_image+")"); 
		$(".answer_text_score").html(text_score);
		$(".answer_text_comment").html(text_comment);
		return false;
	});
	$("#check_clear").click(function(){
		$(".selectable").each(function(){
			$(this).attr("checked", false);
		
		});

		text_comment = "上記の設問で該当する箇所をチェックし、「糖尿病危険度をチェックする」ボタンを押してください。<br />この場所に計測結果が表示されます。";		

		text_score = "あなたの糖尿病危険度を計測します。";

		$(".answer_text_comment").html(text_comment);
		$(".answer_text_score").html(text_score);
		$("#answer_text").css("background-image", "url(../img/diabetic/selfcheck_bg.jpg)"); 
		return false;
	});

});
