<!-- Author: Brian Mackenzie -->
<!-- Date: 11th March 2004 -->
<!-- Version: 1.0 -->

<!-- Function:  Calculate the results from the Yuhasz Skinfold Test -->

<!-- Required by: fatyuhasz.htm -->

<!-- Copyright Brian Mackenzie 2004 -->


function fatcalculate()

{
  var age = document.fat.age.options[document.fat.age.selectedIndex].value;
  var fold = eval(document.fat.fold.value);
  var gender = document.fat.gender.options[document.fat.gender.selectedIndex].value;
  var wtunits = document.fat.wtunits.options[document.fat.wtunits.selectedIndex].value;
  var wt = document.fat.wt.value;

    if (wtunits == "kilos")
    {
        wt *= 2.205;
    }

    if (gender == "male")
    {
        if (age == '16')
        {
            tfat = (fold*0.097)+3.64;
        }
        if (age == '30')
        {
            tfat = (fold*0.1066)+4.975;
        }
    }
    	     
    if (gender == "female")
    {
        if (age == '16')
        {
            tfat = (fold*0.217)-4.47;
        }
        if (age == '30')
        {
            tfat = (fold*0.224)-2.8;
        }
    }

   document.fat.bodyfat.value = nt2dp(tfat,2);
	 
  // determine weight of fat and lean body mass

  wf = wt *tfat / 100;
  wl = wt - wf;	 
  document.fat.wfat.value = nt2dp(wf,2);
  document.fat.wlean.value = nt2dp(wl,2);
  document.fat.wfatkg.value = nt2dp(wf / 2.205,2);
  document.fat.wleankg.value = nt2dp(wl /2.205,2);
}

function vclear()

{
  document.fat.bodyfat.value = "";
  document.fat.wfat.value = "";
  document.fat.wlean.value = "";
  document.fat.wfatkg.value = "";
  document.fat.wleankg.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);
}