<!-- Author: Brian Mackenzie -->
<!-- Date: 11th March 2004 -->
<!-- Version: 1.0 -->
<!-- Function:  Calculate times for 5k training  -->
<!-- Required by: tp5k.htm -->
<!-- Copyright Brian Mackenzie 2004 -->

function timecalculate()
{
  var secs = document.time.secs.value;
  var mins = document.time.mins.value;

  t5 = (mins*1) + (secs/60);

  //10k time
  t10k = t5 * 2.1;
  m10 = Math.floor(t10k);
  s10 = (t10k - m10) * 60;

  //3k time
  t3k = t5 * 0.58;
  m3 = Math.floor(t3k);
  s3 = (t3k - m3) * 60;

  //1.5k time
  t15k = t5 * 0.27;
  m15 = Math.floor(t15k);
  s15 = (t15k - m15) * 60;

  //800m time
  t800 = t5 * 0.13;
  m800 = Math.floor(t800);
  s800 = (t800 - m800) * 60;

  //400m time
  t400 = t5 * 0.06;
  m400 = Math.floor(t400);
  s400 = (t400 - m400) * 60;

  document.time.m10.value = m10;
  document.time.s10.value = nt2dp(s10,0);
  document.time.m3.value = m3;
  document.time.s3.value = nt2dp(s3,0);
  document.time.m400.value = m400;
  document.time.s400.value = nt2dp(s400,0);
  document.time.m15.value = m15;
  document.time.s15.value = nt2dp(s15,0);
  document.time.m800.value = m800;
  document.time.s800.value = nt2dp(s800,0);
}

function valclear()
{
  document.time.m10.value = "";
  document.time.s10.value = "";
  document.time.m3.value = "";
  document.time.s3.value = "";
  document.time.m400.value = "";
  document.time.s400.value = "";
  document.time.m15.value = "";
  document.time.s15.value = "";
  document.time.m800.value = "";
  document.time.s800.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);
}