<!-- Author: Brian Mackenzie -->
<!-- Date: 11th March 2004 -->
<!-- Version: 1.0 -->
<!-- Function:  Calculate vo2 max from a race result  -->
<!-- Required by: vo2race.htm -->
<!-- Copyright Brian Mackenzie 2004 -->

function vo2maxcalculate()
{
  var units = document.vo2max.units.options[document.vo2max.units.selectedIndex].value;
  var hrs = document.vo2max.hrs.value*1;
  var mins = document.vo2max.mins.value*1;
  var secs = document.vo2max.secs.value*1;
  var dist = document.vo2max.dist.value*1;

  if (units == 'miles')
    {
      dist = dist * 1.609;
    }

  //convert time to mins and 100ths of mins
  th = hrs*60;
  tm = mins * 1;
  ts = secs /60;
  time = th+tm+ts;

  //calculate velocity im metres per min
  d=eval(dist*1000/time);

  //calculate % max
  p=0.8+(0.1894393*Math.exp(-0.012778*time))+(0.2989558*Math.exp(-0.1932605*time));

  //calculate vo2
  v=-4.60+(0.182258*d)+(0.000104*d*d);

  //calculate vo2 max
  vo2=v/p;
  document.vo2max.vo2.value = nt2dp(vo2,2);
}
 
function vo2clear()
{
  document.vo2max.vo2.value = "";
  document.vo2max.hrs.value= "";
  document.vo2max.secs.value= "";
  document.vo2max.mins.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);
}