<!-- Author: Brian Mackenzie -->
<!-- Date: 15th August 2007 -->
<!-- Version: 1.0 -->

function fatcalculate()
{

var age = document.fat.age.options[document.fat.age.selectedIndex].value;
var sa = document.fat.sitea.value;
var sb = document.fat.siteb.value;
var sc = document.fat.sitec.value;
var gender = document.fat.gender.options[document.fat.gender.selectedIndex].value;

  if (gender == "male")
    {
      if (age == '18')
        {
            a=-0.008356+1.4579703*sa-(sa*sa*-1.38E-05);
			b=0.05+0.5153731*sb-(sb*sb*7.029E-06);
			c=0.0046667+2.1375328*sc;
			wf=a+b-c-10.2;
        }

      if (age == '27')
        {
            a=0.0322044+0.411777*sa-(sa*sa*4.391E-06);
			b=0.054149789+0.351389907*sb-(sb*sb*6.275E-06);
			c=-0.035750057+1.184314710*sc-(sc*sc*-0.000035952);
			wf=a+b-c-15;
        }
	}

    if (gender == "female")
    {
        if (age == '18')
        {
            a=-0.03+0.527362205*sa-(sa*sa*-0.000007750);
			b=0.0268+0.8181496061*sb-(sb*sb*0.00000775);
			c=-0.016530612+1.698176121*sc-(sc*sc*-0.000015816);
			wf=a+b-c-19.6;
        }

      if (age == '27')
        {
            a=0.05875+0.466141732*sa-(sa*sa*0.000007750);
			b=-0.0248+0.487755906*sb-(sb*sb*-0.00000775);
			c=-0.0222222+0.570516185*sc-(sc*sc*-0.000013778);
			wf=a+b-c-19.6;
        }
     }
 
  document.fat.bodyfat.value = nt2dp(wf,1);

}

function vclear()
{
  document.fat.bodyfat.value = "";
}

function vcleare()
{
  document.fat.bodyfat.value = "";
  document.fat.sitea.value = "";
  document.fat.siteb.value = "";
  document.fat.sitec.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);
}