function ClearForm(form){
    form.weight.value = "";
    form.height.value = "";
    form.bmi.value = "";
    form.my_comment.value = "";
    form.idweight.value = "";
    form.obesity.value = "";
    form.age.value = "";
    form.cal.value = "";
    form.exe.value = "";
    form.idweight2.value = "";
    form.obesity2.value = "";
}
function bmi(weight, height) {
          bmindx=weight/eval(height*height);
          return bmindx;
}
function idweight(height) {
          idw=22*eval(height*height);
          return idw;
}
function checkform(form) {
       if (form.weight.value==null||form.weight.value.length==0 ||
			 form.height.value==null||form.height.value.length==0){
            alert("\身長、体重は必ず入力して下さい");
            return false;
       }
       else if (parseFloat(form.height.value) <= 0||
                parseFloat(form.height.value) >=500||
                parseFloat(form.weight.value) <= 0||
                parseFloat(form.weight.value) >=500){
                alert("\n入力が間違っています　数字を確認して下さい");
                ClearForm(form);
                return false;
       }
       return true;
}
function computeform(form) {
       if (checkform(form)) {
       yourbmi=Math.round(bmi(form.weight.value, form.height.value/100));
       form.bmi.value=yourbmi;
	youridweight=idweight(form.height.value/100);
	form.idweight.value=Math.round(youridweight);
	form.obesity.value=Math.round((form.weight.value/youridweight - 1) *100);
	youridweight2=(form.height.value - 100) * 0.9;
	form.idweight2.value=Math.round(youridweight2);
	form.obesity2.value=Math.round((form.weight.value/youridweight2 -1)*100);

	if (form.age.value <= 30) {
		nutidx = 6;
	} else if (form.age.value > 30 && form.age.value <= 40 ) {
		nutidx = 5;
	} else if (form.age.value > 40 && form.age.value <= 50 ) {
		nutidx = 4;
	} else if (form.age.value > 50 && form.age.value <= 60 ) {
		nutidx = 3;
	} else if (form.age.value > 60 && form.age.value <= 70 ) {
		nutidx = 2;
	} else if (form.age.value > 70 && form.age.value <= 80 ) {
		nutidx = 1;
	} else if (form.age.value >= 80 ) {
		nutidx = 0;
	}
	if(form.exe.value && form.sex.value) {
		if (form.sex.value == "M") {
			nutidx *= 1.5;
		}
	 	nutidx += parseFloat(form.exe.value);
 		nutidx += 20;
		form.cal.value = Math.round(nutidx * youridweight);
	} else {
		form.cal.value = "???";
	}
       if (yourbmi >40) {
          form.my_comment.value="深刻な肥満状態です。医者や専門家に相談してみましょう。";
       } else if (yourbmi >30 && yourbmi <=40) {
          form.my_comment.value="ひどい肥満状態です。病気になる前にダイエットするべきです。";
       } else if (yourbmi >27 && yourbmi <=30) {
          form.my_comment.value="太りすぎです。減量する必要があります。";
       } else if (yourbmi >23 && yourbmi <=27) {
          form.my_comment.value="やや太り気味です。ダイエットを考えて下さい。";
       } else if (yourbmi >=21 && yourbmi <=23) {
          form.my_comment.value="ベストコンディション！";
       } else if (yourbmi >=18 && yourbmi <21) {
          form.my_comment.value="やせ気味です。あまり体に良いことではありません";
       } else if (yourbmi >=16 && yourbmi <18) {
          form.my_comment.value="痩せすぎです。これ以上痩せないように気をつけてください。";
       } else if (yourbmi <16) {
          form.my_comment.value="栄養失調。病気にならないうちに食生活を変えるべきです。";
       }
       }
       return;
}
