<!-- Author: Brian Mackenzie -->
<!-- Date: 11th March 2004 -->
<!-- Version: 1.0 -->
<!-- Function:  Calculate ideal weight  -->
<!-- Required by: idealw.htm -->
<!-- Copyright Brian Mackenzie 2004 -->


function bmicalculate()
{
  var weight = document.bmi.weight.value;
  var height = document.bmi.height.value;
  
  w1 = weight / (height * height);

  w2="Low";
  if (w1<18.5) w2="Underweight";
  if (w1>=18.5) w2="Ideal Weight";
  if (w1>=25) w2="Pre Obese";
  if (w1>=30) w2="Obese";
  if (w1>=40) w2="Very Obese";
  
  document.bmi.bmi.value = nt2dp(w1,2);
  document.bmi.result.value = w2;
}

function bmiclear(a)
{
  document.bmi.bmi.value = "";
  document.bmi.result.value = "";
  document.bmi.bmib.value = "";
  document.bmi.resultb.value = "";
}

function bmibc()
{
  var f = document.bmi.hft.value*1;
  var i = document.bmi.hin.value*1;
  var s = document.bmi.wst.value*1;
  var l = document.bmi.wlbs.value*1;
  h=((f*12)+i)/39.36;
  w=((s*14)+l)*0.45;
  w1 = w/(h*h);

  w2="Low";
  if (w1>=20) w2="Normal";
  if (w1>25) w2="Pre Obese";
  if (w1>30) w2="Obese";
  if (w1>35) w2="Grossly Obese";
  
  document.bmi.bmib.value = nt2dp(w1,2);
  document.bmi.resultb.value = w2;
}

function weight1calculate()
{
  var heightunits = document.weight1.heightunits.options[document.weight1.heightunits.selectedIndex].value;
  var height = document.weight1.height.value;

  if (heightunits == "inches")
    {
        height *= 2.54;
    }

  var sex = document.weight1.sex.options[document.weight1.sex.selectedIndex].value;

  a = height / 100;
  a = a * a;

  if (sex == "Male")
    {
      w1 = a * 20.1;
      w2 = a * 25.0;
      w3 = w1 / 0.4536;
      w4 = w2 / 0.4536;
    }
  else
    {
       w1 = a * 18.7;
       w2 = a * 23.8;
       w3 = w1 / 0.4536;
       w4 = w2 / 0.4536;
    }
       
  document.weight1.w1.value = nt2dp(w1,1);
  document.weight1.w2.value = nt2dp(w2,1);
  document.weight1.w3.value = nt2dp(w3,1);
  document.weight1.w4.value = nt2dp(w4,1);
}

function valclear()
{
document.weight1.w1.value = "";
document.weight1.w2.value = "";
document.weight1.w3.value = "";
document.weight1.w4.value = "";
}

function nt2dp(num,dp)
{
<!-- rounds num to dp decimal places -->
  num=num*1+(0.55/Math.pow(10,dp));
  if (dp>0) dp=dp+1;
  b=Math.floor(num).toString().length+dp;
  return num.toString().substr(0,b);
}