
function chkInput() {
	for (var i = 0; i < 3; i++) {
		if (isNaN(document.forms[0].elements[i].value) || document.forms[0].elements[i].value < 0 || document.forms[0].elements[i].value == "") {
			alert("Please enter a number greater than 0 in each of the data entry fields.");
			return false;
		}
	}
	if (! document.forms[0].rdoGender[0].checked && !document.forms[0].rdoGender[1].checked) {
		alert("Please select a gender.");
		return false;
	}
	return true;
}

function calculateBMR() {
	var intHeight;
	var intWeight;
	var intAge;
	var BMR = 0;
	var AMR = 0;

	intHeight = (document.forms[0].txtFeet.value * 12) + (document.forms[0].txtInches.value*1);
	intWeight = document.forms[0].txtWeight.value;
	intAge = document.forms[0].txtAge.value;
	//alert ("height: " + intHeight + " weight: " + intWeight + " age: " + intAge);

	//calculate basic rate according to gender
	if (document.forms[0].rdoGender[0].checked) {
		BMR = Math.round(655 + ( 4.35 * intWeight) + ( 4.7 * intHeight) - ( 4.7 * intAge));
	}
	else {
		BMR = Math.round(66 + ( 6.23 * intWeight)  + ( 12.7 * intHeight)  - ( 6.8 *  intAge));
	}
	document.forms[0].txtResults.value = "Your BMR is " + BMR + ".";

	//use Harris Benedict equation to account for activity level
	if (document.forms[0].rdoActive[0].checked) {
		AMR = Math.round(BMR * 1.2);
	}
	if (document.forms[0].rdoActive[1].checked) {
		AMR = Math.round(BMR * 1.375);
	}
	if (document.forms[0].rdoActive[2].checked) {
		AMR = Math.round(BMR * 1.55);
	}
	if (document.forms[0].rdoActive[3].checked) {
		AMR = Math.round(BMR * 1.725);
	}
	if (document.forms[0].rdoActive[4].checked) {
		AMR = Math.round(BMR * 1.9);
	}
	if (AMR>0) document.forms[0].txtResult2.value = "You use " + AMR + " calories per day."
}
