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.display="block"}function sldr_onchange(c){current!="txtTopAngle"&&SetCurrent(document.getElementById("txtTopAngle"));document.getElementById("txtTopAngle").value=c.value;Calculate()}
function SetCurrent(c){document.getElementById(current).style.backgroundColor=offColor;current=c.id;c.style.backgroundColor=onColor;if(current=="txtTopAngle")document.getElementById("btnCalculate").value="Calculate from Angle";else document.getElementById("btnCalculate").value="Calculate from Base"}
function Calculate(){var c=180/Math.PI,f=parseFloat(document.getElementById("txtSideLengths").value);if(isNaN(f))alert("Please enter valid Sides");else{var b,d;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}d=Math.sin(b/c/2)*f*2;document.getElementById("txtBase").value=RoundTo(d,1)}else{d=parseFloat(document.getElementById("txtBase").value);b=f*2;if(isNaN(d)||d>=
b){d=f;document.getElementById("txtBase").value=Math.round(d);alert("Please enter Base ( Max "+b+" )");return}b=d/2/f;b=Math.asin(b)*c;b=b*2;document.getElementById("txtTopAngle").value=RoundTo(b,2)}b=(180-b)/2;var h=Math.tan(b/c)*(d/2),e=h*(d/2)/1E6;document.getElementById("spnRes").innerHTML="Base Angles "+RoundTo(b,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.beginPath();a.save();a.fillStyle="#87ceeb";a.strokeStyle="#000";a.shadowOffsetY=6;a.shadowBlur=6;a.shadowColor="#c0c0c0";a.moveTo(300,0);a.lineTo(300-d,e-1);a.lineTo(300+d,e-1);a.closePath();a.fill();a.restore();a.moveTo(300,0);a.lineTo(300,e-1);a.stroke();a.font="14px Arial";a.fillStyle="#000";g=RoundTo(b,1);var i=14/Math.tan(b/c);if(i>60)i=60;if(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(b/c),e/2+14)}}var animTimer;function AnimStart(c){SetCurrent(document.getElementById("txtTopAngle"));animTimer=setInterval("Anim("+c+")",40)}function AnimStop(){clearInterval(animTimer)}function Anim(c){c=parseFloat(document.getElementById("txtTopAngle").value)+c;if(c>1&&c<179){document.getElementById("txtTopAngle").value=c;document.getElementById("sldr").value=c;Calculate()}else AnimStop()};