/* BMIを計算 */     
function calcBMI(){
	/* 身長 */
	var height = document.formBMI.height.value;
	if(height == '0' || height === ''){
		/* エラー */
		document.formBMI.height.value = '入力してください。';
		return;
	}
	/* 体重 */
	var weight = document.formBMI.weight.value;
	if(weight == '0' || weight === ''){
		/* エラー */
		document.formBMI.weight.value = '入力してください。';
		return;
	}
	
	/* BMI */
	var bmi = (weight / height / height);
	bmi = (bmi * 100);
	bmi = Math.round(bmi);
	bmi = (bmi / 100);
	
	/* 表示 */
	bestWeight(height);
	document.formBMI.bmi.value=bmi;
	if(bmi < 18.5){
		document.formBMI.judge.value = 'やせすぎ';
	}else if(18.5 <= bmi && bmi < 25){
	 	document.formBMI.judge.value = '標準';
	}else if(25 <= bmi && bmi < 30){
		document.formBMI.judge.value = '肥満1度';
	}else if(30 <= bmi && bmi < 35){
		document.formBMI.judge.value = '肥満2度';
	}else if(35 <= bmi && bmi < 40){
		document.formBMI.judge.value = '肥満3度';	
	}else if(40 <= 40){
		document.formBMI.judge.value = '肥満4度';
	}
}
/* クリア */
function clearBMI(){
	document.formBMI.weight.value = '0';
	document.formBMI.height.value = '0';
	document.formBMI.bmi.value = '0';
	document.formBMI.judge.value = '';
	document.formBMI.weight_low.value = '0';
	document.formBMI.weight_high.value = '0';
	document.formBMI.weight_mid.value = '0';
}
/* 標準体重 */
function bestWeight(height){
	var low = 18.5;
	var high = 24.99;

	/* 計算 */
	var w_low = (low * height * height);
	var w_hi  = (high * height * height);
	
	/* 小数点第2位で四捨五入 */
	w_low = (w_low * 100);
	w_low = Math.round(w_low);
	w_low = (w_low / 100);
	
	w_hi  = (w_hi  * 100);
	w_hi  = Math.round(w_hi);
	w_hi  = (w_hi  / 100);
	
	/* 表示 */
	document.formBMI.weight_low.value = w_low;
	document.formBMI.weight_high.value = w_hi;
}
/* インプットBOXにフォーカスが移ったら内容をクリア */
function clearTXT(index){
	if(index == 1){
		var h = document.formBMI.height.value;
		if(h == '0' || h == '入力してください。'){
			document.formBMI.height.value = '';
		}
		
	}else if(index == 2){
		var w = document.formBMI.weight.value;
		if(w == '0' || w == '入力してください。'){
			document.formBMI.weight.value = '';
		}
	}
}

	