var current="txtTopAngle",offColor="#fff",onColor="#7cfc00";function Window_onload(){document.getElementById(current).style.backgroundColor=onColor;Calculate();SetNumeric();if(document.getElementById("sldr").type=="range")document.getElementById("sldr").style.visibility="visible"}function sldr_onchange(b){current!="txtTopAngle"&&SetCurrent(document.getElementById("txtTopAngle"));document.getElementById("txtTopAngle").value=b.value;Calculate()}
function SetCurrent(b){document.getElementById(current).style.backgroundColor=offColor;current=b.id;b.style.backgroundColor=onColor;current=="txtTopAngle"?document.getElementById("btnCalculate").value="Calculate from Angle":document.getElementById("btnCalculate").value="Calculate from Base"}
function Calculate(){var b=180/Math.PI,f=parseFloat(document.getElementById("txtSideLengths").value);if(isNaN(f))alert("Please enter valid Sides");else{var c,d;if(current=="txtTopAngle"){c=parseFloat(document.getElementById("txtTopAngle").value);if(isNaN(c)||c<1||c>179){alert("Please enter Top Angle larger than 0 and smaller than 180");return}d=Math.sin(c/b/2)*f*2;document.getElementById("txtBase").value=RoundTo(d,1)}else{d=parseFloat(document.getElementById("txtBase").value);c=f*2;if(isNaN(d)||d>=
c){d=f;document.getElementById("txtBase").value=Math.round(d);alert("Please enter Base ( Max "+c+" )");return}c=Math.asin(d/2/f)*b;c*=2;document.getElementById("txtTopAngle").value=RoundTo(c,2)}c=(180-c)/2;var h=Math.tan(c/b)*(d/2),e=h*(d/2)/1E6;document.getElementById("spnRes").innerHTML="Base Angles "+RoundTo(c,2)+"&deg;<br />Height "+RoundTo(h,1)+"<br>Triangle Area "+RoundTo(e,2)+" m&sup2;";var a=600/(f*2),e=h*a;d=d*a/2;var g=document.getElementById("cnvsTriangle"),a=g.getContext("2d");g.setAttribute("height",
e+6);a.strokeStyle="#808080";a.beginPath();a.moveTo(300,0);a.lineTo(300-d,e-1);a.lineTo(300+d,e-1);a.closePath();a.save();a.fillStyle="#87ceeb";a.strokeStyle="#808080";a.shadowOffsetY=6;a.shadowBlur=6;a.shadowColor="#c0c0c0";a.fill();a.restore();a.stroke();a.beginPath();a.moveTo(300,0);a.lineTo(300,e-1);a.stroke();a.font="14px Arial";a.fillStyle="#000";var g=RoundTo(c,1),i=14/Math.tan(c/b);i>60&&(i=60);d<36&&(d=36);a.fillText(g,300-d+i,e-2);a.fillText(g,300+d-i-a.measureText(g).width,e-2);a.fillText(RoundTo(h,
1),302,e/2);a.fillText(RoundTo(f,1),300-e/2/Math.tan(c/b),e/2+14)}}var animTimer;function AnimStart(b){SetCurrent(document.getElementById("txtTopAngle"));animTimer=setInterval("Anim("+b+")",40)}function AnimStop(){clearInterval(animTimer)}function Anim(b){b=parseFloat(document.getElementById("txtTopAngle").value)+b;b>1&&b<179?(document.getElementById("txtTopAngle").value=b,document.getElementById("sldr").value=b,Calculate()):AnimStop()};
