<!-- Author: Brian Mackenzie -->
<!-- Date: 11th March 2004 -->
<!-- Version: 1.0 -->

<!-- Function:  Calculate block settings   -->

<!-- Required by: blockset.htm -->

<!-- Copyright Brian Mackenzie 2004 -->


function calculate()

{
  var al = eval(document.stride.al.value);
  var bl = eval(document.stride.bl.value);
  var ull = eval(document.stride.ull.value);
  var lll = eval(document.stride.lll.value);
  var fl = eval(document.stride.fl.value);

  //default front pad angle to 60 degrees
  fa=60;

  //Bottom above shoulders V =
  v=ull*Math.sin(fa*Math.PI/180)+(lll*Math.cos(fa*Math.PI/180))+(fl*Math.sin(fa*Math.PI/180))-al;

  //calculate various angles
  y=ull*Math.sin(fa*Math.PI/180)+(lll*Math.cos(fa*Math.PI/180))+(fl*Math.sin(fa*Math.PI/180));
  x=Math.sqrt((fl*fl+lll*lll+ull*ull)-(2*Math.sqrt(fl*fl+lll*lll)*ull*Math.cos((120+(Math.atan(fl/lll)/Math.PI*180))*Math.PI/180)));
  z=Math.sqrt(bl*bl-v*v);
  w=Math.sqrt(x*x-y*y);
  c=Math.acos(y/x)/Math.PI*180;
  a=Math.acos((+(x*x)+ull*ull-(fl*fl+lll*lll))/(2*x*ull))*180/Math.PI;

  //calculate block distances
  fp=Math.sqrt(bl*bl-v*v)-(ull*Math.cos(fa*Math.PI/180))+(lll*Math.cos((90-fa)*Math.PI/180))-(fl*Math.cos(fa*Math.PI/180));
  rp=z+w;
  
  //calculate block angles
  fpa=fa;
  rpa=60+c-a;

  //calculat first foot strike distance from start line
  fl= ((ull+lll)/0.7071)-(0.7071*lll);

  document.stride.fp.value = nt2dp(fp,0);
  document.stride.rp.value = nt2dp(rp,0);
  document.stride.fpa.value = nt2dp(fpa,0);
  document.stride.rpa.value = nt2dp(rpa,0);
  document.stride.foot.value = nt2dp(fl,0);
}

function valclear()

{
  document.stride.fp.value = "";
  document.stride.rp.value = "";
  document.stride.fpa.value = "";
  document.stride.rpa.value = "";
  document.stride.foot.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);
}