<!-- Author: Brian Mackenzie -->
<!-- Date: 11th March 2004 -->
<!-- Version: 1.0 -->
<!-- Function:  Calculate maximum heart rate  -->
<!-- Required by: maxhr.htm -->
<!-- Copyright Brian Mackenzie 2004 -->


function vcalc()
{
var sp = document.mhr.sport.options[document.mhr.sport.selectedIndex].value;
var age = document.mhr.age.value;
var sexp = document.mhr.exper.options[document.mhr.exper.selectedIndex].value;

age=age*1;
beats = 217 - (0.85 * age);

if (sp=='3')beats=beats-3;
if (sp=='4')beats=beats-5;
if(sexp=='1')
 {
  if(age>=55)beats=beats+4;

  if ((age>49) && (age<55)) {beats=beats+2};

  if (age<=30)beats=beats-3;
 }

 document.mhr.bpm.value = nt2dp(beats,0);
 document.mhr.bpm2.value = nt2dp(206.3 - (0.711*age),0);
 document.mhr.bpm3.value = nt2dp(217 - (0.85*age),0);
 document.mhr.bpm4.value = nt2dp(206.9 - (0.67*age),0);
 document.mhr.bpm5.value = nt2dp(202 - (0.55*age),0);
 document.mhr.bpm6.value = nt2dp(216 - (1.09*age),0);
}

function vclear()
{
  document.mhr.bpm.value = "";
  document.mhr.bpm2.value = "";
  document.mhr.bpm3.value = "";
  document.mhr.bpm4.value = "";
  document.mhr.bpm5.value = "";
  document.mhr.bpm6.value = "";
}

function calculate()
{
  var conv = document.stride.conv.value;
  var con = document.stride.con.options[document.stride.con.selectedIndex].value;

  if (con=='MHR')
    {
      r1=(conv-37)/0.64;
      document.stride.ans2.value=nt2dp(r1,2);
      document.stride.ans3.value="VO2 max";
    }
  else
    {
      r1=(conv*0.64)+37;
      document.stride.ans3.value="MHR";
      document.stride.ans2.value=nt2dp(r1,0);
    }
}

function valclear()
{
  document.stride.ans2.value = "";
  document.stride.ans3.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);
}