
function custRound(x,places) {
  return (Math.round(x*Math.pow(10,places)))/Math.pow(10,places)
}



function calculateBmiBmr() {
  var frm = document.frmBmiBmr
  var weight = eval(frm.txtWeight.value)
  var height = eval(frm.txtHeight.value)
  var age = eval(frm.txtAge.value)
if(frm.cmbWeight.selectedIndex==0)
  weight/=2.2046226

if(frm.cmbHeight.selectedIndex==0)
  height*=0.0254
else
  height/=100

var BMI =  weight/(height * height)

frm.txtBmi.value=custRound(BMI,1);

var BMR = 0

if(frm.cmbGender.selectedIndex==0)
    BMR = 655.0955 + (9.5634 * weight) + (184.96 * height) - (4.6756 * age)
else
    BMR = 66.473 + (13.7516 * weight) + (500.33 * height) - (6.775 * age)

  frm.txtBmr.value=custRound(BMR,0);

if(BMI < 16)
  frm.txtClassifcation.value='Underweight - Severe thinness'
else if (BMI < 17)
  frm.txtClassifcation.value='Underweight - Moderate thinness'
else if (BMI < 18.5)
  frm.txtClassifcation.value='Underweight - Mild thinness'
else if (BMI < 25)
  frm.txtClassifcation.value='Normal range'
else if (BMI < 30)
  frm.txtClassifcation.value='Overweight - Pre-obese'
else if (BMI < 35)
  frm.txtClassifcation.value='Overweight - Obese class I'
else if (BMI < 40)
  frm.txtClassifcation.value='Overweight - Obese class II'
else if (BMI >= 40)
  frm.txtClassifcation.value='Overweight - Obese class III'
else
  frm.txtClassifcation.value='Error'

}


function clearBmiBmr(){
	var frm = document.frmBmiBmr;
	frm.txtWeight.value='';
	frm.txtHeight.value='';
	frm.txtAge.value='';
	frm.txtBmi.value='';
	frm.txtBmr.value='';
	frm.txtClassifcation.value='';
}