function calcBMR(){var doc=document.bmr;if(doc.height1.value==""||isNaN(doc.height1.value)||doc.height1.value<=0)
{alert("That is not a valid number for height.  Enter a number greater than 0, please.");doc.height1.value="";doc.height1.focus();return;}
if(doc.height2.value==""||isNaN(doc.height2.value)||doc.height2.value<0)
{alert("That is not a valid number for height.  Enter a number greater than 0, please.");doc.height2.value="";doc.height2.focus();return;}
if(doc.weight.value==""||isNaN(doc.weight.value)||doc.weight.value<=0)
{alert("That is not a valid number for weight.  Enter a number greater than 0, please.");doc.weight.value="";doc.weight.focus();return;}
weight=doc.weight.value
var uom=doc.weightuom.options[doc.weightuom.selectedIndex].value;if((uom=='kg'&&weight<44)||(uom=='lbs'&&weight<100))
{alert("Weight is too low to calculate BMR.  Weight must be 100lbs (45kg) and over.");doc.weight.value="";doc.weight.focus();return;}
if(doc.age.value==""||isNaN(doc.age.value)||doc.age.value<=0)
{alert("That is not a valid number for age.  Enter a number greater than 0, please");doc.age.value="";doc.age.focus();return;}
if(uom==0)
{weight=convertlbstokg(weight)}
height1uom=doc.height1uom.selectedIndex
height2uom=doc.height2uom.selectedIndex
if(height1uom==0&&height2uom==0)
{feet=parseInt(doc.height1.value);inches=parseInt(doc.height2.value);htInCm=calculateHeight(feet,inches);}
else if(height1uom==1&&height2uom==1)
{metres=parseInt(doc.height1.value);cm=parseInt(doc.height2.value);convertedCm=convertMetresToCm(metres);htInCm=convertedCm+cm;}
else{alert("The units of measure need to be the same.  Make both measure of units for your height either feet and inches OR metres and centimetres.");return;}
age=doc.age.value;if(doc.gender[0].checked==true)
{bmrate=calculateBMRF(weight,htInCm,age);}
else if(doc.gender[1].checked==true)
{bmrate=calculateBMRM(weight,htInCm,age);}
doc.result.value=Math.round(bmrate);}
function calculateBMRF(weight,htInCm,age){return(9.5634*weight)+(1.8496*htInCm)-(4.6756*age)+655.0955}
function calculateBMRM(weight,htInCm,age){return(13.7516*weight)+(5.0033*htInCm)-(6.7550*age)+66.4730}
function convertlbstokg(pounds){weight=pounds*.45359237
return weight}
function convertMetresToCm(metres){return metres*100}
function convertFeetToInches(feet){inches=feet*12;return inches}
function convertInchesToCm(totalInches){totalInches=totalInches*2.54
return totalInches}
function calculateHeight(feet,inches){convertedInches=convertFeetToInches(feet);totalInches=convertedInches+inches;return convertInchesToCm(totalInches);}
function clearForm(){document.forms['bmr'].reset();}
function calc_hr()
{var frm_element=document.getElementById('form1');val=220-frm_element.age.value;var val1=0;var val2=0;if(frm_element.level[0].checked){val1=val*.4;val2=val*.5;}
if(frm_element.level[1].checked){val1=val*.5;val2=val*.6;}
if(frm_element.level[2].checked){val1=val*.6;val2=val*.8;}
if(frm_element.level[3].checked){val1=val*.7;val2=val*.9;}
frm_element.target1.value=Math.round(val1);frm_element.target2.value=Math.round(val2);}
function cal_bmi()
{var weight=eval(document.getElementById('weight').value);var height_m=eval(document.getElementById('height_m').value);var height_cm=eval(document.getElementById('height_cm').value);var h_m=(1*height_cm)/100;var total_h=h_m+height_m;var res=weight/(total_h*total_h);var bmi=res.toPrecision(3);var result="An adult who is "+weight+" Kgs and "+height_m+" Meters and "+height_cm+" Centimeter tall has a body mass index of "+bmi+" \n\n Warning! An adult with a body mass index over 30 is considered to be obese.\n\n Remember, that for adults, a body mass index: \n\n 1) over 30 is considered obese.\n\n 2) between 25 and 29.9 is considered overweight. \n\n 3) between 18.5 and 24.9 is considered a healthy bmi. \n\n 4) under 18.5 is consider underweight.";alert(result);}


