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