<!-- Author: Brian Mackenzie -->
<!-- Date: 11th May 2008 -->
<!-- Version: 1.0 -->
<!-- Function:  Calculate training window for 400m  -->

function speedcalculate()
{
  var pb = document.speed.pb.value;
  var distance = document.speed.distance.value;
  var ef1 = document.speed.effort1.value;
  var ef2 = document.speed.effort2.value;

  val1=(100/ef1)*pb;
  val2=(100/ef2)*pb;
  
  time1=val1*(distance/100);
  time2=val2*(distance/100);
  
  time1m=Math.floor(time1/60);
  time1s=time1-(time1m*60);
  
  time2m=Math.floor(time2/60);
  time2s=time2-(time2m*60);
  
  document.speed.time1m.value = nt2dp(time1m,0);
  document.speed.time1s.value = nt2dp(time1s,1);
  document.speed.time2m.value = nt2dp(time2m,0);
  document.speed.time2s.value = nt2dp(time2s,1);
}

function valclear()
{
  document.speed.time1m.value = "";
  document.speed.time1s.value = "";
  document.speed.time2m.value = "";
  document.speed.time2s.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);
}