var inType="p",dangle=18.4,rise=400,run=1200,pitch=4,hyp=1265,presc=0,RAD=Math.PI/180;function Setup(){SetNumeric();document.getElementById("spnPitch").value="4";CalcAll()}
function ChangeIn(c){inType=c;document.getElementById("spnPitch").style.display="none";document.getElementById("spnAngle").style.display="none";document.getElementById("spnRise").style.display="none";document.getElementById("btnPitch").setAttribute("class","BtnOff");document.getElementById("btnAngle").setAttribute("class","BtnOff");document.getElementById("btnRise").setAttribute("class","BtnOff");switch(c){case "p":document.getElementById("spnPitch").style.display="block";document.getElementById("_txtIn").value=
RoundTo(pitch,2);document.getElementById("btnPitch").setAttribute("class","BtnOn");break;case "a":document.getElementById("spnAngle").style.display="block";document.getElementById("_txtIn").value=RoundTo(dangle,2);document.getElementById("btnAngle").setAttribute("class","BtnOn");break;case "r":document.getElementById("spnRise").style.display="block",document.getElementById("_txtIn").value=Math.round(rise),document.getElementById("btnRise").setAttribute("class","BtnOn")}DrawIt()}
function CalcAll(){run=parseFloat(document.getElementById("txtRun").value);presc=run<100?1:0;var c=parseFloat(document.getElementById("_txtIn").value),b;switch(inType){case "p":pitch=c;b=Math.atan(pitch/12);rise=Math.tan(b)*run;dangle=b/RAD;break;case "a":dangle=c;b=dangle*RAD;pitch=Math.tan(b)*12;rise=Math.tan(b)*run;break;case "r":rise=c,b=Math.atan(rise/run),dangle=b/RAD,pitch=Math.tan(b)*12}hyp=run/Math.cos(b);document.getElementById("spnRiseRes").innerHTML=RoundTo(rise,presc);document.getElementById("spnPitchRes").innerHTML=
RoundTo(pitch,1);document.getElementById("spnAngleRes").innerHTML=RoundTo(dangle,1);document.getElementById("spnHyp").innerHTML=RoundTo(hyp,presc);DrawIt()}function CheckIn(c){var b=parseFloat(c.value);if(inType=="p")if(b>200)c.value="200";else if(b<0.2)c.value="0.2";if(inType=="a")if(b>89.9)c.value="89.9";else if(b<1)c.value="1"}function RoundTo(c,b){b=Math.pow(10,b);return d=Math.round(c*b)/b}
function DrawIt(){var c=document.getElementById("cnvsRiseRun");if(c.getContext){var b,e;run>rise?(b=900,e=b*(rise/run)):(e=900,b=e/rise,b*=run);c.setAttribute("width",b+100);c.setAttribute("height",e+40);var a=c.getContext("2d");a.fillStyle="#fff";a.fillRect(0,0,c.width,c.height);a.lineJoin="round";a.fillStyle="#dcdcdc";a.strokeStyle="#808080";a.lineWidth=1;a.beginPath();a.moveTo(0.5,0.5);a.lineTo(0.5,e-0.5);a.lineTo(b-0.5,e-0.5);a.closePath();a.save();a.shadowOffsetY=10;a.shadowOffsetX=10;a.shadowBlur=
10;a.shadowColor="#c0c0c0";a.fill();a.restore();a.stroke();a.fillStyle="#080";a.font="18px Verdana";a.textBaseline="top";var c=RoundTo(run,presc)+" Run",f=a.measureText(c).width;a.fillText(c,b/2-f/2,e+10);a.fillStyle="#000";a.fillText(RoundTo(hyp,presc)+" Slope",b/2,e/2-18);a.fillStyle=inType=="a"?"#f00":"#000";a.font=inType=="a"?"bold 24px 'comic sans ms'":"18px Verdana";c=RoundTo(dangle,1)+"\u00b0";a.fillText(c,b+10+1,e-16);a.fillStyle=inType=="p"?"#f00":"#000";a.font=inType=="p"?"bold 24px 'comic sans ms'":
"18px Verdana";c=RoundTo(pitch,1)+" in 12";a.fillText(c,b+10,e+10);a.fillStyle=inType=="r"?"#f00":"#000";a.font=inType=="r"?"bold 24px 'comic sans ms'":"18px Verdana";a.fillText(RoundTo(rise,presc)+" Rise",5,e/2)}};
