

<!-- This function accepts gender inputs via radio buttons on this form, and five numeric inputs from the text boxes there. The inputs are used to calculate the daily caloric needs of someone meeting those parameters. -->
function CaloricNeedsCalc() {

var height_feet = document.CaloricNeedsForm.HeightFeet.value;
var height_inches = document.CaloricNeedsForm.HeightInches.value;

var weight_lbs = document.CaloricNeedsForm.WeightLbs.value;
var years_of_age = document.CaloricNeedsForm.YearsAge.value;
var activity_index = document.CaloricNeedsForm.ActivityLevel.value;
var gender = document.CaloricNeedsForm.Gender.value;
var MyElement = document.getElementById("ValidationBox");
var MyReport = document.getElementById("burnreport");


if((!(CheckValues(weight_lbs))) || (!(CheckValues(years_of_age)))) {
	MyElement.style.display='block';
        MyReport.style.display='none';
} else {
	var total_inches = parseInt(height_feet * 12) + parseInt(height_inches);
	var centimeters = total_inches * 2.54;
	var kilograms = weight_lbs/2.2;
        MyElement.style.display='none';
	if(document.CaloricNeedsForm.Gender.value=='Female') {  // Female calculation values
		var adjust_weight = 655 + (9.6 * kilograms);
		var adjust_height = 1.7 * centimeters;
		var adjust_age = 4.7 * years_of_age;
	} else {  // Male calculation values
		var adjust_weight = 66 + (13.7 * kilograms);
		var adjust_height = 5 * centimeters;
		var adjust_age = 6.8 * years_of_age;
		}


	document.CaloricNeedsForm2.Calories.value = Math.ceil((adjust_weight + adjust_height - adjust_age) * activity_index);
        document.CaloricNeedsForm2.CaloriesD1.value=document.CaloricNeedsForm2.Calories.value-(document.CaloricNeedsForm2.Calories.value*.10);
        document.CaloricNeedsForm2.CaloriesD15.value=document.CaloricNeedsForm2.Calories.value-(document.CaloricNeedsForm2.Calories.value*.20);
        document.CaloricNeedsForm2.CaloriesD2.value=document.CaloricNeedsForm2.Calories.value-(document.CaloricNeedsForm2.Calories.value*.30);

        MyReport.style.display='block';

	}
}

<!-- This function accepts a string value and determines if it is a zero-length or null string, then checks for positive integer values. It returns a value of true or false. -->
function CheckValues(this_string) {
	var is_number = true;
	var string_length = this_string.length;
	if(string_length == 0) {
		is_number = false;
	} else {
		for(count = 0; count < string_length; count++) {
			if((this_string.charAt(count) < "0") || (this_string.charAt(count) > "9")) {
				is_number = false;
				break;
			}	
		}
	}
	return is_number;
}

<!--  This function simply forces a page reload  -->
function StartOver() {
	location.reload()
}

