<!-- Author: Brian Mackenzie -->
<!-- Date: 11th March 2004 -->
<!-- Version: 1.0 -->
<!-- Function:  Calculate event times using Frank Horwills 4 and 5 second Rule  -->
<!-- Required by: frankhorwill.htm -->
<!-- Copyright Brian Mackenzie 2004 -->


function speedcalculate()

{
  var tmins = document.time.tmins.value;
  var tsecs = document.time.tsecs.value;
  var gender = document.time.gender.options[document.time.gender.selectedIndex].value;
  var distance = document.time.distance.options[document.time.distance.selectedIndex].value;

  //convert time to seconds
  ttime = tmins*60 + tsecs*1;

  //default Male athlete
  ts=4;

  if (gender == "Female")
    {
      ts = 5;
    }
  if  (distance == "Marathon")
    {
      t400 = (ttime/105.5)-(ts*7);
    }

  if  (distance == "Half Marathon")
    {
      t400 = (ttime/52.75)-(ts*6);
    }

  if  (distance == "10k")
    {
      t400 = (ttime/25)-(ts*5);
    }

  if  (distance == "5k")
    {
      t400 = (ttime/12.5)-(ts*4);
    }

  if  (distance == "3k")
    {
      t400 = (ttime/7.5)-(ts*3);
    }

  if  (distance == "1500m")
    {
      t400 = (ttime/3.75)-(ts*2);
    }

  if  (distance == "800m")
    {
      t400 = (ttime/2)-(ts*1);
    }
  if  (distance == "400m")
    {
      t400 = ttime;
    }

  t400s = t400 *1;
  t800s = (t400 + ts) * 2;
  t1500s = (t400+(ts*2)) * 3.75;
  t3000s = (t400 + (ts*3)) * 7.5;
  t5000s = (t400 + (ts*4)) * 12.5;
  t10s = (t400 + (ts*5)) * 25;
  thms = (t400 + (ts*6)) * 52.75;
  tms = (t400 + (ts*7)) * 105.5;
  tm = t400s/60;
  t400m = Math.round(tm);

  if (t400m > tm)
    {
      t400m = t400m - 1;
    }

  t400s = t400s - (60 * t400m);
  tm = t800s/60;
  t800m = Math.round(tm);

  if (t800m > tm)
    {
      t800m = t800m - 1;
    }

  t800s = t800s - (60 * t800m);
  tm = t1500s/60;
  t1500m = Math.round(tm);

  if (t1500m > tm)
    {
      t1500m = t1500m - 1;
    }

  t1500s = t1500s - (60 * t1500m);
  tm = t3000s/60;
  t3000m = Math.round(tm);

  if (t3000m > tm)
    {
      t3000m = t3000m - 1;
    }

  t3000s = t3000s - (60 * t3000m);
  tm = t5000s/60;
  t5000m = Math.round(tm);

  if (t5000m > tm)
    {
      t5000m = t5000m - 1;
    }

  t5000s = t5000s - (60 * t5000m);
  tm = t10s/60;
  t10m = Math.round(tm);

  if (t10m > tm)
    {
      t10m = t10m - 1;
    }

  t10s = t10s - (60 * t10m);
  tm = thms/60;
  thmm = Math.round(tm);

  if (thmm > tm)
    {
      thmm = thmm - 1;
    }

  thms = thms - (60 * thmm);
  tm = tms/60;
  tmm = Math.round(tm);

  if (tmm > tm)
    {
      tmm = tmm - 1;
    }

  tms = tms - (60 * tmm);

  document.time.t400s.value = nt2dp(t400s,0);
  document.time.t400m.value = t400m;
  document.time.t800s.value = nt2dp(t800s,0);
  document.time.t800m.value = t800m;
  document.time.t1500s.value = nt2dp(t1500s,0);
  document.time.t1500m.value = t1500m;
  document.time.t3000s.value = nt2dp(t3000s,0);
  document.time.t3000m.value = t3000m;
  document.time.t5000s.value = nt2dp(t5000s,0);
  document.time.t5000m.value = t5000m;
  document.time.t10s.value = nt2dp(t10s,0);
  document.time.t10m.value = t10m;
  document.time.thms.value = nt2dp(thms,0);
  document.time.thmm.value = thmm;
  document.time.tms.value = nt2dp(tms,0);
  document.time.tmm.value = tmm;

}

function valclear()
{
  document.time.t400s.value = "";
  document.time.t400m.value = "";
  document.time.t800s.value = "";
  document.time.t800m.value = "";
  document.time.t1500s.value = "";
  document.time.t1500m.value = "";
  document.time.t3000s.value = "";
  document.time.t3000m.value = "";
  document.time.t5000s.value = "";
  document.time.t5000m.value = "";
  document.time.t10s.value = "";
  document.time.t10m.value = "";
  document.time.thms.value = "";
  document.time.thmm.value = "";
  document.time.tms.value = "";
  document.time.tmm.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);
}