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;if(current=="txtTopAngle")document.getElementById("btnCalculate").value="Calculate from Angle";else 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=c/2/f;b=Math.asin(b)*d;b=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=300/(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(150,0);a.lineTo(150-c,e-1);a.lineTo(150+c,e-1);a.closePath();a.fill();a.restore();a.moveTo(150,0);a.lineTo(150,e-1);a.stroke();a.font="12px Arial";a.fillStyle="#000";var i=RoundTo(b,1),h=12/Math.tan(b/d);if(h>50)h=50;if(c<32)c=32;a.fillText(i,150-c+h,e-2);a.fillText(i,150+c-h-a.measureText(i).width,e-2);a.fillText(RoundTo(g,1),152,e/2);a.fillText(RoundTo(f,
1),150-e/2/Math.tan(b/d),e/2+12)}}var animTimer,isAnim=false;function AnimStart(d){if(isAnim)AnimStop();else{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;if(d>1&&d<179){document.getElementById("txtTopAngle").value=d;Calculate()}else AnimStop()};