// Ver.1.19990616 Y.Nakahara


// Ver.1.19990617 Y.Nakahara


// Ver.1.19990618 Y.Nakahara


// Ver.1.19990626 Y.Nakahara


// Ver.1.20000711 Y.Nakahara(全面改訂)





var timeIndex			= "";


var speed				= 0;


var exerciseDivision	= "";


var weight				= 0;


var time				= "";


var result				= "";





/*


	メイン


*/


function calculateMain(form){





	//	フォーム値解析処理


	if(analyzeFormValue(form) == false){


		return;


	}





	//	エネルギーの計算


	calculateEnergy();





	//	結果表示


	form.txtResult.value = result;


}





/*


	フォーム値解析処理


*/


function analyzeFormValue(form){





	//	フォーム値の獲得


    exerciseDivision	= form.hiddenWork_or_Run.value;


    speed				= form.textSpeed.value;


	weight				= form.textWeight.value;


    timeIndex			= form.selectTime.selectedIndex;


    time				= form.selectTime[timeIndex].value ;





	//	速度入力チェック


	if(speed == ""){


		alert("速度を入力してください");


		form.textSpeed.focus();


		return false;


	}


	else if(checkNumeric(speed) == false){


		alert("速度の値に問題があります");


		form.textSpeed.focus();


		form.textSpeed.select();


		return false;


	}


	else if(exerciseDivision == "1"){


		if(speed < 50 || speed > 100){


			alert("「速度」に入力できるのは50-100の範囲の数値です");


			form.textSpeed.focus();


			form.textSpeed.select();


			return false;


		}


	}


	else if(exerciseDivision == "2"){


		if(speed < 140){


			alert("「速度」に入力できるのは140以上の数値です");


			form.textSpeed.focus();


			form.textSpeed.select();


			return false;


		}


	}





	//	体重(kg)の入力チェック


	if(weight == ""){


		alert("体重(kg)を入力してください");


		form.textWeight.focus();


		return false;


	}


	else if(checkNumeric(weight) == false){


		alert("体重(kg)の値に問題があります");


		form.textWeight.focus();


		form.textWeight.select();


		return false;


	}


	return true;


}





/*


	リセット


*/


function resetform( form )


{


	form.hiddenWork_or_Run.value = "1" ;


}





/*


	数値チェック


*/


function checkNumeric(numeric){


	numericTable = "1234567890.";


	countDot = 0;


	moji = "";


	for(i=0;i<numeric.length;i++){


		moji = numeric.substring(i,i+1);


		if(moji == "."){


			countDot++;


			if(2 <= countDot){


				return false;


			}


		}


		if(numericTable.indexOf(moji)==-1){


			return false;


		}


	}


	return true;


}





/*


	エネルギー値を求める


*/


function calculateEnergy(form){


    var coefficient  = "" ;


    var temp1 = "" ;


    var temp2 = "" ;





    if(exerciseDivision == "1"){


        coefficient = 0.1;


    }


    else {


        coefficient = 0.2;


    }





    temp1 = coefficient * speed + 3.5;


    temp2 = temp1 / 3.5;


    result = temp2 * weight * time;


    result = Math.ceil( result );


}





// -->


