var rise,run,angle,topAngle,hyp,find,RAD=Math.PI/180;function SetInputs(a,b,c){document.getElementById("spnInputLabel1").innerHTML=b;document.getElementById("spnInputLabel2").innerHTML=c;document.getElementById("btnRise").setAttribute("class","BtnOff");document.getElementById("btnRun").setAttribute("class","BtnOff");document.getElementById("btnAngle").setAttribute("class","BtnOff");a.setAttribute("class","BtnOn");find=a.id;Calculate()}
function Calculate(){var a=parseFloat(document.getElementById("_txtInput2").value);if(find!="btnAngle")if(a<1||a>89){alert("Angles 1 to 89 only");document.getElementById("_txtInput2").select();return}var b=parseFloat(document.getElementById("_txtInput1").value),c;switch(find){case "btnRise":run=b;angle=a;rise=RoundTo(Math.tan(angle*RAD)*run,1);c="Rise = "+rise;break;case "btnRun":rise=b;angle=a;run=RoundTo(rise/Math.tan(angle*RAD),1);c="Run = "+run;break;case "btnAngle":rise=b;run=a;angle=RoundTo(Math.atan(rise/
run)/RAD,1);c="Angle = "+angle;break}hyp=RoundTo(Math.sqrt(rise*rise+run*run),1);document.getElementById("spnResult").innerHTML=c;topAngle=RoundTo(90-angle,1);DrawTriangle()}
function DrawTriangle(){var a=document.getElementById("cnvsRiseRun");if(a.getContext){var b,c;if(run>rise){b=310;c=b*(rise/run)}else{c=310;b=c/rise;b=run*b}a.setAttribute("width",b+(angle>60?90:0));a.setAttribute("height",c+40);a=a.getContext("2d");a.lineJoin="round";a.fillStyle="#dcdcdc";a.strokeStyle="#c0c0c0";a.lineWidth=2;a.beginPath();a.moveTo(1,1);a.lineTo(1,c-1);a.lineTo(b-1,c-1);a.closePath();a.stroke();a.save();a.shadowOffsetY=4;a.shadowOffsetX=4;a.shadowBlur=4;a.shadowColor="#c0c0c0";a.fill();
a.restore();a.fillStyle="#000";a.font="16px Verdana";a.textBaseline="top";a.fillText(hyp,b/2,c/2-18);a.fillText(topAngle+"\u00b0",2,2);var d=run+" Run",e=a.measureText(d).width;a.fillStyle=find=="btnRun"?"Red":"#000";a.fillText(d,e>b?0:b/2-e/2,c+10);d=angle+"\u00b0";a.fillStyle=find=="btnAngle"?"Red":"#000";e=a.measureText(d).width;a.fillText(d,b-e-2,c-14);a.fillStyle=find=="btnRise"?"Red":"#000";a.fillText(rise+" Rise",2,c/2)}}function Setup(){SetInput();find="btnRise";Calculate()};
