window.onload = function(){
 Event.observe('thema0','click',radio_handler0);
 Event.observe('thema1','click',radio_handler1);
 Event.observe('thema2','click',radio_handler2);
 Event.observe('thema3','click',radio_handler3);
 Event.observe('thema4','click',radio_handler4);
 Event.observe('thema5','click',radio_handler5);
 Event.observe('thema6','click',radio_handler6);

 Event.observe('thema0','mouseover',backcolor0);
 Event.observe('thema1','mouseover',backcolor1);
 Event.observe('thema2','mouseover',backcolor2);
 Event.observe('thema3','mouseover',backcolor3);
 Event.observe('thema4','mouseover',backcolor4);
 Event.observe('thema5','mouseover',backcolor5);
 Event.observe('thema6','mouseover',backcolor6);

 Event.observe('thema0','mouseout',backcolorl0);
 Event.observe('thema1','mouseout',backcolorl1);
 Event.observe('thema2','mouseout',backcolorl2);
 Event.observe('thema3','mouseout',backcolorl3);
 Event.observe('thema4','mouseout',backcolorl4);
 Event.observe('thema5','mouseout',backcolorl5);
 Event.observe('thema6','mouseout',backcolorl6);

 Event.observe($("bheight"),"keyup",bmical,false);
 Event.observe($("bweight"),"keyup",bmical,false);
//Check Button Reset
reset();
}

function backcolor0(){$('tbl0').style.backgroundColor = "bisque";$('ckno0').style.backgroundColor = "lightcyan";}
function backcolor1(){$('tbl1').style.backgroundColor = "bisque";$('ckno1').style.backgroundColor = "lightcyan";}
function backcolor2(){$('tbl2').style.backgroundColor = "bisque";$('ckno2').style.backgroundColor = "lightcyan";}
function backcolor3(){$('tbl3').style.backgroundColor = "bisque";$('ckno3').style.backgroundColor = "lightcyan";}
function backcolor4(){$('tbl4').style.backgroundColor = "bisque";$('ckno4').style.backgroundColor = "lightcyan";}
function backcolor5(){$('tbl5').style.backgroundColor = "bisque";$('ckno5').style.backgroundColor = "lightcyan";}
function backcolor6(){$('tbl6').style.backgroundColor = "bisque";$('ckno6').style.backgroundColor = "lightcyan";}

function backcolorl0(){$('tbl0').style.backgroundColor = "transparent";$('ckno0').style.backgroundColor = "#ffffcc";}
function backcolorl1(){$('tbl1').style.backgroundColor = "transparent";$('ckno1').style.backgroundColor = "#ffffcc";}
function backcolorl2(){$('tbl2').style.backgroundColor = "transparent";$('ckno2').style.backgroundColor = "#ffffcc";}
function backcolorl3(){$('tbl3').style.backgroundColor = "transparent";$('ckno3').style.backgroundColor = "#ffffcc";}
function backcolorl4(){$('tbl4').style.backgroundColor = "transparent";$('ckno4').style.backgroundColor = "#ffffcc";}
function backcolorl5(){$('tbl5').style.backgroundColor = "transparent";$('ckno5').style.backgroundColor = "#ffffcc";}
function backcolorl6(){$('tbl6').style.backgroundColor = "transparent";$('ckno6').style.backgroundColor = "#ffffcc";}


function bmical(){
	var bmi = ($("bweight").value / ($("bheight").value / 100)) / ($("bheight").value / 100);
	$("bmi").innerHTML = "　" + bmi.toFixed(1) + "　";

//document.getElementByname("q12").value);
	if (bmi > 18.5){
		document.thema2.q12[0].checked = true;
	}else{
		document.thema2.q12[1].checked = true;
	}
}

function radio_handler0(){

// var flag1,flag2,flag3,flag4,flag5;
//   value1,value2,value3,value4,value5 グローバル変数とする。
// var num1=document.thema1.q01.length;			//要素数を求める。今回は３に固定のため不要  

 var obj=document.thema0;
	obj.q01[0].checked ? value1=obj.q01[0].value : value1=obj.q01[1].value;
	obj.q02[0].checked ? value2=obj.q02[0].value : value2=obj.q02[1].value;
	obj.q03[0].checked ? value3=obj.q03[0].value : value3=obj.q03[1].value;
	obj.q04[0].checked ? value4=obj.q04[0].value : value4=obj.q04[1].value;
	obj.q05[0].checked ? value5=obj.q05[0].value : value5=obj.q05[1].value;
	total0 = parseInt(value1) + parseInt(value2) + parseInt(value3) + parseInt(value4) + parseInt(value5);
	$("ckno0").innerHTML = total0+"/5";
	displaytotal();
}
/*
	for (i=0;i<2;i++) {
		flag1=document.thema0.q01[i].checked;
		if (flag1){ value1=document.thema0.q01[i].value;}
	}
	for (i=0;i<2;i++) {
		flag2=document.thema0.q02[i].checked;
		if (flag2){ value2=document.thema0.q02[i].value;}
	}
	for (i=0;i<2;i++) {
		flag3=document.thema0.q03[i].checked;
		if (flag3){ value3=document.thema0.q03[i].value;}
	}
	for (i=0;i<2;i++) {
		flag4=document.thema0.q04[i].checked;
		if (flag4){ value4=document.thema0.q04[i].value;}
	}
	for (i=0;i<2;i++) {
		flag5=document.thema0.q05[i].checked;
		if (flag5){ value5=document.thema0.q05[i].value;}
	}

//var ck1total = parseInt(value1) + parseInt(value2) + parseInt(value3) + parseInt(value4) + parseInt(value5) + parseInt(value6) + parseInt(value7) + parseInt(value8) + parseInt(value9) + parseInt(value10);



//document.getElementById("ckno3").innerHTML = document.getElementsByName("q03").item;
//document.getElementById("ckno4").innerHTML = document.getElementsByName("q04")[1].checked;
//$("ckno5").innerHTML = document.getElementsByName("q05")[1].checked;
//$("ckno6").innerHTML = document.getElementsByName("q06")[1].checked;
*/

function radio_handler1(){
 var obj=document.thema1;
	obj.q06[0].checked ? value6=obj.q06[0].value : value6=obj.q06[1].value;
	obj.q07[0].checked ? value7=obj.q07[0].value : value7=obj.q07[1].value;
	obj.q08[0].checked ? value8=obj.q08[0].value : value8=obj.q08[1].value;
	obj.q09[0].checked ? value9=obj.q09[0].value : value9=obj.q09[1].value;
	obj.q10[0].checked ? value10=obj.q10[0].value : value10=obj.q10[1].value;
	total1 = parseInt(value6) + parseInt(value7) + parseInt(value8) + parseInt(value9) + parseInt(value10);
	$("ckno1").innerHTML = total1+"/5";
	displaytotal();

}

function radio_handler2(){
 var obj=document.thema2;
	obj.q11[0].checked ? value11=obj.q11[0].value : value11=obj.q11[1].value;
	obj.q12[0].checked ? value12=obj.q12[0].value : value12=obj.q12[1].value;
	total2 = parseInt(value11) + parseInt(value12);

	$("ckno2").innerHTML = total2 + "/2";

displaytotal();
}



function radio_handler3(){

 var obj=document.thema3;
	obj.q13[0].checked ? value13=obj.q13[0].value : value13=obj.q13[1].value;
	obj.q14[0].checked ? value14=obj.q14[0].value : value14=obj.q14[1].value;
	obj.q15[0].checked ? value15=obj.q15[0].value : value15=obj.q15[1].value;
	total3 = parseInt(value13) + parseInt(value14) + parseInt(value15);
	$("ckno3").innerHTML = total3+"/3";
	displaytotal();
}


function radio_handler4(){
 var obj=document.thema4;
	obj.q16[0].checked ? value16=obj.q16[0].value : value16=obj.q16[1].value;
	obj.q17[0].checked ? value17=obj.q17[0].value : value17=obj.q17[1].value;
	total4 = parseInt(value16) + parseInt(value17);
	$("ckno4").innerHTML = total4+"/2";
	displaytotal();
}


function radio_handler5(){
 var flag18,flag19,flag20;
	document.thema5.q18[0].checked ? value18=document.thema5.q18[0].value : value18=document.thema5.q18[1].value;
	document.thema5.q19[0].checked ? value19=document.thema5.q19[0].value : value19=document.thema5.q19[1].value;
	document.thema5.q20[0].checked ? value20=document.thema5.q20[0].value : value20=document.thema5.q20[1].value;
	total5 = parseInt(value18) + parseInt(value19) + parseInt(value20);
	$("ckno5").innerHTML = total5+"/3";
	displaytotal();
}

function radio_handler6(){
	document.thema6.q21[0].checked ? value21=document.thema6.q21[0].value : value21=document.thema6.q21[1].value;
	document.thema6.q22[0].checked ? value22=document.thema6.q22[0].value : value22=document.thema6.q22[1].value;
	document.thema6.q23[0].checked ? value23=document.thema6.q23[0].value : value23=document.thema6.q23[1].value;
	document.thema6.q24[0].checked ? value24=document.thema6.q24[0].value : value24=document.thema6.q24[1].value;
	document.thema6.q25[0].checked ? value25=document.thema6.q25[0].value : value25=document.thema6.q25[1].value;
	total6 = parseInt(value21) + parseInt(value22) + parseInt(value23) + parseInt(value24) + parseInt(value25);
	$("ckno6").innerHTML = total6+"/5";
	displaytotal();
}

function displaytotal(){
 var total = 0; 

	(typeof(total0) == "number") ? total += total0 : total0 = 0;		//問診
	(typeof(total1) == "number") ? total += total1 : total1 = 0;		//運動機能
	(typeof(total2) == "number") ? total += total2 : total2 = 0;		//栄養
	(typeof(total3) == "number") ? total += total3 : total3 = 0;		//口腔機能
	(typeof(total4) == "number") ? total += total4 : total4 = 0;		//閉じこもり
	(typeof(total5) == "number") ? total += total5 : total5 = 0;		//認知症

//特定高齢者判定
		if (total < 10 || total1 < 3 || total2 < 2 || total3 < 2){
			$("lebel").innerHTML = "一般高齢者";
			$("lebel").style.color = "green";
		}
		if (total >= 10 || total1 >=3 || total2 == 2 || total3 >= 2){
			$("lebel").innerHTML = "特定高齢者候補者";
			$("lebel").style.color = "brown";
		}
//
	(typeof(total6) == "number") ? total += total6 : total6 = 0;		//うつ予防

	$("totalpoint").style.color = "green";
	$("totalpoint").innerHTML = total+"/25";
//$("dbg").innerHTML = typeof(total0) + typeof(total1) + typeof(total2) + typeof(total3) + typeof(total4) + typeof(total5) + typeof(total6);

	return total;	
}

function reset(){
	document.thema0.q01[0].checked = true;
	document.thema0.q02[0].checked = true;
	document.thema0.q03[0].checked = true;
	document.thema0.q04[0].checked = true;
	document.thema0.q05[0].checked = true;
	document.thema1.q06[0].checked = true;
	document.thema1.q07[0].checked = true;
	document.thema1.q08[0].checked = true;
	document.thema1.q09[1].checked = true;
	document.thema1.q10[1].checked = true;
	document.thema2.q11[1].checked = true;
	document.thema2.q12[0].checked = true;
	document.thema3.q13[1].checked = true;
	document.thema3.q14[1].checked = true;
	document.thema3.q15[1].checked = true;
	document.thema4.q16[0].checked = true;
	document.thema4.q17[1].checked = true;
	document.thema5.q18[1].checked = true;
	document.thema5.q19[0].checked = true;
	document.thema5.q20[1].checked = true;
	document.thema6.q21[1].checked = true;
	document.thema6.q22[1].checked = true;
	document.thema6.q23[1].checked = true;
	document.thema6.q24[1].checked = true;
	document.thema6.q25[1].checked = true;
}
