

function calcBMI(){

// Get Variables and validate to make sure they're numbers, 
// setting them to a value of 1 if they're not.

if(isNaN(document.getElementById("bmi_weight").value) || (document.getElementById("bmi_weight").value == 0)){
	alert("Results will be inaccurate.  Weight is not a valid number.");
	return;
}
if(isNaN(document.getElementById("bmi_height").value) || (document.getElementById("bmi_height").value==0)){
alert("Results will be inaccurate.  Height is not a valid number.");
	return;	
}
var weight = Number(document.getElementById("bmi_weight").value);
var height = Number(document.getElementById("bmi_height").value);

var height_meter=height/100;

// set multipliers based on whether metric or English units were selected

//var wmult = (document.wcbubba.units.value == "pounds") ? 2.204 : 1;

// Turns inches/centimeters into meters

//var hmult = (document.wcbubba.hunits.value == "inches") ? .0254 : .01;

// Do the calculation (weight in kg divided by the height in meters 
// times itself). The multiplication by 10 and then division by ten
// work in conjunction with Math.round() to round the value to one
// decimal place of precision.
var BMI=(weight/(height_meter*height_meter));
BMI = BMI.toFixed(2);
//var BMI = Math.round(((weight / wmult)/((height * hmult)*(height * hmult))) *10)/10;

// get the analysis - note this is for general purpose, there is a separate scale for
// Southeast Asian people and there may be more variants on the way

var result = "";
if(BMI < 18) result = "severely underweight";
else if((BMI >=18)&&(BMI<=24)) result = "healthy";
else if((BMI >=24)&&(BMI<=29)) result = "overweight";
else if((BMI >=29)&&(BMI<=34)) result = "obesity (Grade 1)";
else if((BMI >=34)&&(BMI<=40)) result = "Obesity (Grade 2)";
else if((BMI >=40)) result = "Extremely obese - Obesity (Grade 3)";


document.getElementById('results').innerHTML = "Your Body Mass Index (BMI) is: " + BMI + ". This would be considered " + result + ".";

}
