function Form_onsubmit(){var a=parseInt(document.getElementById("ddWidthFeet").value),c=parseInt(document.getElementById("ddWidthInches").value),e=parseInt(document.getElementById("ddWidthFrac").value);a=a*384+c*32+e;c=parseInt(document.getElementById("ddLengthFeet").value);e=parseInt(document.getElementById("ddLengthInches").value);var t=parseInt(document.getElementById("ddLengthFrac").value);if(a>c*384+e*32+t){alert("Width cannot be greater than Length");return false}a=parseInt(document.getElementById("ddPlateWidthInches").value);
c=parseInt(document.getElementById("ddPlateWidthFrac").value);a=a*32+c;if(a>0){c=parseInt(document.getElementById("_txtAngle").value);a=a*Math.sin(c/(180/Math.PI));c=parseInt(document.getElementById("ddRafterDepthInches").value);e=parseInt(document.getElementById("ddRafterDepthFrac").value);if((c*32+e)/a<3)if(!confirm("Birds mouth depth will be greater than 1/3 rafter depth\n\rThis can significantly weaken rafter\n\r\n\rContinue?"))return false}a=parseInt(document.getElementById("ddRafterDepthInches").value)*
32+parseInt(document.getElementById("ddRafterDepthFrac").value);if(parseInt(document.getElementById("ddHipDepthInches").value)*32+parseInt(document.getElementById("ddHipDepthFrac").value)<a){alert("Hip Depth must be equal to or greater than Rafter Depth\n\r\n\rHip Depth re-set to "+ConEng(a));document.getElementById("ddHipDepthInches").selectedIndex=document.getElementById("ddRafterDepthInches").selectedIndex;document.getElementById("ddHipDepthFrac").selectedIndex=document.getElementById("ddRafterDepthFrac").selectedIndex}return true}
function Window_onload(){DrawRoof();DrawRafter();DrawHip();DrawTemplate();DrawHipDetail();SetInput()}function ChangePitch(){var a=document.getElementById("ddPitchIn12").value;if(a!=0){var c=180/Math.PI;a=Math.atan(a/12)*c;if(a>=2&&a<=50)document.getElementById("_txtAngle").value=a.toFixed(4)}}function ConvertDecimal(){var a=document.getElementById("txtConverter").value;document.getElementById("spnConverter").innerHTML=ConEng(a*32,true)}
function CompareOverhang(){var a=document.getElementById("ddOverhangFeet").value*384;a+=document.getElementById("ddOverhangInches").value*32;a+=document.getElementById("ddOverhangFrac").value;var c=document.getElementById("ddOverhangGableFeet").value*384;c+=document.getElementById("ddOverhangGableInches").value*32;c+=document.getElementById("ddOverhangGableFrac").value;if(a!=c){document.getElementById("ddOverhangGableFeet").style.backgroundColor="yellow";document.getElementById("ddOverhangGableInches").style.backgroundColor=
"yellow";document.getElementById("ddOverhangGableFrac").style.backgroundColor="yellow"}else{document.getElementById("ddOverhangGableFeet").style.backgroundColor="";document.getElementById("ddOverhangGableInches").style.backgroundColor="";document.getElementById("ddOverhangGableFrac").style.backgroundColor=""}}function ShowBirdsCalc(){document.getElementById("_txtBirdsmouthAngle").value=document.getElementById("_txtAngle").value;document.getElementById("divBirdsmouth").style.left="200px"}
function HideBirdsCalc(){document.getElementById("divBirdsmouth").style.left="-10000px"}function CalcBirdsSeat(){var a=parseInt(document.getElementById("ddBirdsPlumbInches").value),c=parseInt(document.getElementById("ddBirdsPlumbFrac").value);a=a*32+c;c=GetRangle();if(c!=null){a=a/Math.tan(c);document.getElementById("spnSeatCut").innerHTML=ConEng(a,false)}}
function CalcBirdsPlumb(){var a=parseInt(document.getElementById("ddBirdsFootInches").value),c=parseInt(document.getElementById("ddBirdsFootFrac").value);a=a*32+c;c=GetRangle();if(c!=null){a=Math.tan(c)*a;document.getElementById("spnPlumbCut").innerHTML=ConEng(a,false)}}
function GetRangle(){var a=parseFloat(document.getElementById("_txtBirdsmouthAngle").value);if(isNaN(a)){alert("Please enter a valid number for Angle");document.getElementById("_txtBirdsmouthAngle").select();return null}else if(a<1||a>45){alert("Angle must be larger than 1 and smaller than or equal to 45");document.getElementById("_txtBirdsmouthAngle").select();return null}else return a/(180/Math.PI)}var RAD=Math.PI/180,lineWidth=6,fontSize=12;
function DrawRoof(){var a=document.getElementById("cnvsRoof");if(a.getContext){var c=a.width-50,e=roofData.split(","),t=parseFloat(e[0]),f=parseFloat(e[1]),r=parseFloat(e[2]),m=parseFloat(e[3]),d=parseFloat(e[4]),h=parseFloat(e[5]),l=parseFloat(e[6]),j=parseFloat(e[7]),n=parseFloat(e[8]),i=parseFloat(e[9]),s=parseFloat(e[10]),p=parseFloat(e[11]),w=parseFloat(e[12]),q=parseFloat(e[13]),u=parseFloat(e[14]),v=parseFloat(e[15]);parseFloat(e[16]);var x=parseFloat(e[17]),z=parseFloat(e[18]),y=parseFloat(e[19]),
E=parseFloat(e[20]),C=parseFloat(e[21]),D=t+v*2,F=f+v*2;f=c*(F/D);a.setAttribute("height",f);var A=c/D;e=0;var b=a.getContext("2d");b.fillStyle="#f8f8ff";b.strokeStyle="#000";b.beginPath();b.fillRect(0,0,c,f);b.strokeRect(0,0,c,f-1);if(v>0){e=v*A;b.save();b.fillStyle="#f5f5dc";b.strokeStyle="#c0c0c0";b.shadowOffsetY=10;b.shadowBlur=10;b.shadowColor="#c0c0c0";b.fillRect(e,e,c-e*2,f-e*2);b.restore();b.strokeRect(e,e,c-e*2,f-e*2)}a=f/2;var G=f/4,o=s*A;b.lineWidth=lineWidth;b.font=fontSize-2+"px Verdana";
b.textBaseline="top";if(q>50){b.strokeStyle="#f00";u=u;var g=c-a+o,k=f-a+o;for(b.fillStyle="#000";g<c&&u>50;){b.beginPath();b.moveTo(g,f);b.lineTo(g,k);b.lineTo(c,k);b.stroke();b.fillText(ConEng(u,true),g,k-lineWidth/2-fontSize);u-=q;g+=o;k=f-(c-g)}}b.font=fontSize+"px Verdana";b.beginPath();b.strokeStyle="#ffa500";b.moveTo(0,0);b.lineTo(a,a);b.moveTo(0,f);b.lineTo(a,a);b.moveTo(c,0);b.lineTo(c-a,a);b.moveTo(c,f);b.lineTo(c-a,a);b.stroke();b.beginPath();b.strokeStyle=C==0?"#7cfc00":"#000";b.moveTo(0,
a);b.lineTo(a,a);b.moveTo(c-a,a);b.lineTo(c,a);b.stroke();b.strokeStyle="#7cfc00";b.beginPath();b.moveTo(a,0);b.lineTo(a,f);b.moveTo(c-a,0);b.lineTo(c-a,f);g=a;u=w-2;g+=p>0?p*A:o;for(k=0;k<u;k++){b.moveTo(g,f);b.lineTo(g,a);g+=o}b.stroke();b.beginPath();b.strokeStyle="#00f";b.moveTo(a-lineWidth/2,a);b.lineTo(c-a+lineWidth/2,a);b.stroke();if(y>180){g=f-1;k=l*RAD;y*=Math.cos(k);y*=A;var B=0;if(E>0){B=E*A*Math.cos(k);g-=B}b.strokeStyle="#00f";b.lineWidth=2;for(b.beginPath();g>a-lineWidth/2;){b.moveTo(B,
g);b.lineTo(c-B,g);B+=y;g-=y}b.stroke()}b.strokeStyle="#000";b.lineWidth=1;b.beginPath();b.moveTo(0,f);b.arc(0,f,120,0,315*RAD,true);b.moveTo(100,f-100);b.lineTo(0,f);b.stroke();b.fillStyle="#000";g=fontSize+4;b.fillText("Hip "+ConEng(d,true),a/2+lineWidth,G-fontSize);d="Rafters "+ConEng(h,true)+" long x "+ConEng(i,false)+" deep x "+ConEng(n,false)+" thick";i=b.measureText(d).width;b.fillText(d,c/2-i/2,a-lineWidth/2-g*4);d=p==0?"Adjusted Rafter Spacing "+ConEng(s,true):"Rafter Spacing "+ConEng(s,
true)+" (2 ends = "+ConEng(p,true)+")";s=a-lineWidth/2;i=b.measureText(d).width;b.fillText(d,c/2-i/2,s-g*3);d="Creeper Shortening "+ConEng(q,true);i=b.measureText(d).width;b.fillText(d,c/2-i/2,s-g*2);d="Ridge "+ConEng(m,true)+" long x "+ConEng(j,false)+" thick";i=b.measureText(d).width;b.fillText(d,c/2-i/2,s-g);d="Roof area "+x+" ft\u00b2";i=b.measureText(d).width;b.fillText(d,c-a/2-i/2,2);d="Rafter "+ConEng(h,true);b.fillText(d,c-a+lineWidth,G);if(v>0){d="Roof Length "+ConEng(D,true);b.fillText(d,
4,a+g*2);d="Roof Width "+ConEng(F,true);b.fillText(d,4,a+g*3);d="Overhang (level) "+ConEng(v,true);b.fillText(d,40,2)}d="Wall Length "+ConEng(t,true);i=b.measureText(d).width;b.fillText(d,c/2-i/2,0);d="Angle "+l+"\u00b0";i=b.measureText(d).width;b.fillText(d,c/2-i/2,g);d="Overall Rise From Wall "+ConEng(r,true);i=b.measureText(d).width;b.fillText(d,c/2-i/2,g*2);b.fillText("Sheathing",40,f-g*2);b.fillText(z+"\u00b0",40,f-g);C>0&&b.fillText("End Jacks "+ConEng(C,true),44,s-g);if(document.getElementById("pnlRunning")!=
null){b=document.getElementById("cnvsRun");b.setAttribute("height",f);l=document.getElementById("lblRunLength").innerHTML.split(", ");q=0;t=document.getElementById("lblRunWidth").innerHTML.split(", ");r=0;x=document.getElementById("lblRunRidge").innerHTML.split(", ");z=0;m=document.getElementById("lblRunHip").innerHTML.split(", ");h=0;b=b.getContext("2d");b.beginPath();b.fillStyle="#f8f8ff";b.strokeStyle="#000";b.fillRect(0,0,c,f);b.strokeRect(0,0,c,f-1);if(v>0){b.save();b.fillStyle="#f5f5dc";b.strokeStyle=
"#c0c0c0";b.fillRect(e,e,c-e*2,f-e*2);b.strokeRect(e,e,c-e*2,f-e*2)}b.lineWidth=1;b.font=10+o*0.06+"px Verdana";b.fillStyle="#000";b.textBaseline="top";b.beginPath();b.strokeStyle="#f00";g=e+(a-e)%o;for(k=f-g;g<a-10;){b.moveTo(g,f);b.lineTo(g,k);b.lineTo(0,k);d=t[r++];b.fillText(d,2,k+2);b.save();d=l[q++];i=b.measureText(d).width;b.translate(g-2,f-6-i);b.rotate(90*RAD);b.fillText(d,0,0);b.restore();g+=o;k-=o}b.stroke();b.beginPath();b.strokeStyle=j==n?"#080":"#000";b.moveTo(0,a);b.lineTo(a,a);b.moveTo(c-
a,a);b.lineTo(c,a);b.stroke();b.beginPath();b.strokeStyle="#080";d=t[r++];b.fillText(d,2,a+2);g=a;b.moveTo(a,0);b.lineTo(a,f);b.save();d=l[q++];i=b.measureText(d).width;b.translate(a-2,f-6-i);b.rotate(90*RAD);b.fillText(d,0,0);b.restore();if(w>1){g+=p>0?p*A:o;for(k=0;k<u;k++){b.moveTo(g,f);b.lineTo(g,0);b.save();d=l[q++];i=b.measureText(d).width;b.translate(g-2,f-6-i);b.rotate(90*RAD);b.fillText(d,0,0);b.restore();b.save();d=x[++z];i=b.measureText(d).width;b.translate(g-2,a-i-4);b.rotate(90*RAD);
b.fillText(d,0,0);b.restore();g+=o}b.moveTo(c-a,0);b.lineTo(c-a,f);b.save();d=l[q++];i=b.measureText(d).width;b.translate(c-a,f-6-i);b.rotate(90*RAD);b.fillText(d,0,0);b.restore();b.save();d=x[++z];i=b.measureText(d).width;b.translate(c-a-2,a-i-4);b.rotate(90*RAD);b.fillText(d,0,0);b.restore()}b.stroke();b.beginPath();b.strokeStyle="#f00";g=c-a+o;for(k=a+o;g<c-e&&q<l.length;){b.moveTo(g,f);b.lineTo(g,k);b.lineTo(c,k);b.save();d=l[q++];i=b.measureText(d).width;b.translate(g-2,f-6-i);b.rotate(90*RAD);
b.fillText(d,0,0);b.restore();g+=o;k+=o}g=c-a+o;k=a+o;for(j=0;j<m.length;j++){b.save();b.translate(g-4,k-10);b.rotate(-40*RAD);b.fillText(m[h++],0,0);b.restore();g+=o;k+=o}g=a-o;for(k=a-o;g>e+2;){b.moveTo(g,0);b.lineTo(g,k);b.lineTo(0,k);b.fillText(t[r++],2,k+2);g-=o;k=g}g=c-a+o;for(k=a-o;g<c-e-2;){b.moveTo(g,0);b.lineTo(g,k);b.lineTo(c,k);g+=o;k-=o}b.stroke();b.lineWidth=3;b.strokeStyle="#ffa500";b.beginPath();b.moveTo(0,0);b.lineTo(a,a);b.moveTo(0,f);b.lineTo(a,a);b.moveTo(c,0);b.lineTo(c-a,a);
b.moveTo(c,f);b.lineTo(c-a,a);b.stroke();b.strokeStyle="#00f";b.beginPath();b.moveTo(a,a);b.lineTo(c-a,a);b.stroke()}}}function LineSize(a){if(a==1&&lineWidth<40){lineWidth+=4;fontSize=(lineWidth+20)/2;DrawRoof()}else if(a==0&&lineWidth>3){lineWidth-=2;fontSize=(lineWidth+20)/2;DrawRoof()}}
function DrawRafter(){var a=document.getElementById("cnvsRafter");if(a.getContext){var c=rafterData.split(","),e=parseFloat(c[0]),t=parseFloat(c[1]),f=parseFloat(c[2]),r=parseFloat(c[3]),m=c[4]=="1",d=parseFloat(c[5]),h=c[6],l=90-f;c=a.width;var j=a.height-20,n=j/Math.tan(f*RAD),i=m?n:0;a=a.getContext("2d");a.font="13px Verdana";a.textBaseline="top";a.fillStyle="#7cfc00";a.strokeStyle="#000";a.beginPath();a.moveTo(i,0);a.lineTo(c,0);a.lineTo(c-n,j);var s,p,w;m=false;if(d>0){var q=e/j;p=d/q;s=170-
n;n=p*Math.sin(l*RAD);var u=s+n/Math.tan(f*RAD),v=j-n,x=u+p*Math.cos(l*RAD);p=d*Math.tan(l*RAD);w=e/Math.cos(l*RAD)-p;a.lineTo(x,j);a.lineTo(u,v);a.lineTo(170,0);a.lineTo(s,j);a.lineTo(0,j);if(e/q/n<2.9)m=true}else a.lineTo(0,j);a.lineTo(i,0);a.save();a.shadowOffsetY=10;a.shadowBlur=10;a.shadowColor="#c0c0c0";a.fill();a.restore();a.stroke();a.fillStyle="#000";if(d>0){a.fillText(ConEng(h,true),172,2);h=ConEng(p,false);l=a.measureText(h).width;a.fillText(h,s-l,j-20);a.fillText(ConEng(Math.sqrt(Math.pow(p,
2)+Math.pow(d,2)),false),s,j);h="HAP "+ConEng(w,false);l=a.measureText(h).width;a.fillText(h,s-l,j/2-13)}h="Setback "+ConEng(t,false);l=a.measureText(h).width;a.fillText(h,c-l-2,j+4);h="Plumb cut "+f+"\u00b0";l=a.measureText(h).width;a.fillText(h,c-l-10,2);a.fillText("Rafter "+ConEng(r,true),2,2);a.fillText("Rafter depth "+ConEng(e,false),c*0.6,j/2-12);if(m){a.fillStyle="#f00";a.font="15px Verdana bold";a.fillText("Birdsmouth is Deep !",s+20,j-20)}}}
function DrawHip(){var a=document.getElementById("cnvsHip");if(a.getContext){var c=hipData.split(","),e=parseFloat(c[0]),t=parseFloat(c[1]),f=parseFloat(c[2]),r=c[3],m=c[4]=="1",d=parseFloat(c[5]),h=c[6],l=parseFloat(c[7]);c=90-f;var j=a.width,n=a.height-20;a=a.getContext("2d");a.font="13px Verdana";a.textBaseline="top";a.fillStyle="#ffa500";a.strokeStyle="#000";a.beginPath();var i=n/Math.tan(f*RAD),s=m?i:0;a.moveTo(s,0);a.lineTo(j,0);a.lineTo(j-i,n);var p,w,q,u;m=false;if(l>0||d>0){d=Math.sqrt(d*
d+d*d);var v=e/n;p=140-i;i=d/v*Math.sin(c*RAD);if(l>0)i+=l/Math.cos(c*RAD)/v;var x=p+i/Math.tan(f*RAD),z=n-i,y=x+i/Math.tan(c*RAD);q=d*Math.sin(c*RAD);q+=l*Math.cos(c*RAD);w=q/Math.cos(c*RAD);q=q/Math.sin(c*RAD);u=e/Math.cos(c*RAD)-w;a.lineTo(y,n);a.lineTo(x,z);a.lineTo(140,0);a.lineTo(p,n);a.lineTo(0,n);if(e/v/i<2.9)m=true}else a.lineTo(0,n);a.lineTo(s,0);a.save();a.shadowOffsetY=10;a.shadowBlur=10;a.shadowColor="#c0c0c0";a.fill();a.restore();a.stroke();a.fillStyle="#000";if(l>0||d>0){a.fillText(ConEng(h,
true),142,2);d=ConEng(w,false);h=a.measureText(d).width;a.fillText(d,p-h,n-20);a.fillText(ConEng(Math.sqrt(Math.pow(w,2)+Math.pow(q,2)),false),p,n);d="HAP "+ConEng(u,false);h=a.measureText(d).width;a.fillText(d,p-h,n/2-13)}d="Setback "+ConEng(t,false);h=a.measureText(d).width;a.fillText(d,j-h-2,n+4);d="Plumb cut "+f+"\u00b0";h=a.measureText(d).width;a.fillText(d,j-h-10,2);a.fillText("Hip "+ConEng(r,true),2,2);a.fillText("Hip Depth "+ConEng(e,false),j*0.6,n/2-12);a.fillText("Hip Angle "+c.toFixed(1)+
"\u00b0",j*0.6,n/2+8);if(m){a.fillStyle="#f00";a.font="15px Verdana bold";a.fillText("Birdsmouth is Deep !",p+20,n-20)}}}
function DrawTemplate(){var a=document.getElementById("cnvsTemplate");if(a.getContext){var c=templateData.split(","),e=parseFloat(c[0]),t=parseFloat(c[1]),f=parseFloat(c[2]),r=parseFloat(c[3]),m=parseFloat(c[4]),d=parseFloat(c[5]),h=parseFloat(c[6]),l=parseFloat(c[7]);c=parseFloat(c[8]);a.setAttribute("height",400/Math.tan(l*RAD)+14+4);a=a.getContext("2d");a.font="14px Verdana";a.textBaseline="top";var j=new Image;j.src=document.getElementById("imgAngles").src;a.drawImage(j,0,0);a.beginPath();a.moveTo(0,
0);a.lineTo(400,e);a.fillText("Hip plumb "+t+"\u00b0",416,e-14);a.moveTo(0,0);a.lineTo(400,f);a.fillText("Rafter plumb "+r+"\u00b0",416,f+2);a.moveTo(0,0);a.lineTo(400,m);a.fillText("Hip side cut "+d+"\u00b0",416,m-14);a.moveTo(0,0);a.lineTo(400,h);a.fillText("Creeper side "+l+"\u00b0",416,h);a.stroke();a.fillText("Roof Angle "+c,160,2);a.fillStyle="#ffa500";a.fillRect(400,e-12,14,12);a.fillStyle="#7cfc00";a.fillRect(400,f+2,14,12);a.fillStyle="#ffa500";a.fillRect(400,m-12,14,12);a.fillStyle="#f00";
a.fillRect(400,h+2,14,12)}}
function DrawHipDetail(){var a=document.getElementById("cnvsHipDetail");if(a.getContext){var c=hipDetailData.split(","),e=parseFloat(c[0]),t=parseFloat(c[1]),f=parseFloat(c[2]);c=parseFloat(c[3]);var r=a.width-2,m=f*(100/c)+100;a.setAttribute("height",m+18);var d=(m-100)/Math.tan(e*RAD);a=a.getContext("2d");a.beginPath();var h=new Image;h.src=document.getElementById("bgImage1").src;h=a.createPattern(h,"repeat");a.fillStyle=h;a.moveTo(75,1);a.lineTo(1,25);a.lineTo(75,50);a.lineTo(75+d,m);a.lineTo(r,
m);h=0;for(var l=(m-50)/20,j=0;j<21;j++){a.lineTo(r-h,m-j*l);h=h>0?0:Math.random()*40+12}a.lineTo(r-100,1);a.lineTo(75,1);a.fill();a.stroke();a.beginPath();a.moveTo(75,50);a.lineTo(r,50);a.moveTo(1,25);a.lineTo(d,m-25);a.lineTo(75+d,m);a.lineTo(75,50);a.lineTo(1,25);h=new Image;h.src=document.getElementById("bgImage2").src;h=a.createPattern(h,"repeat");a.fillStyle=h;a.fill();a.stroke();a.font="24px Arial";a.textBaseline="top";a.fillStyle="#000";e=e+"\u00b0";a.fillText(e,85,50);e=ConEng(f,false);f=
a.measureText(e).width;a.fillText(e,r-f-40,m/2);e=ConEng(c,false);f=a.measureText(e).width;a.fillText(e,r-25-f-10,11);e="Hip Plumb + Side Cuts";a.fillText(e,r/3,52);e=t+"\u00b0";f=a.measureText(e).width;a.translate(f/2,6);a.rotate(20*RAD);a.fillText(e,50-f,29)}}
function CommonTemplate(){var a=parseInt(document.getElementById("ddRafterThickInches").value)*32+parseInt(document.getElementById("ddRafterThickFrac").value),c=rafterData.split(",");window.open("Templates/rafter.aspx?rw="+a+"&rd="+c[0]+"&pa="+c[2]+"&m=0")}
function CreeperTemplate(){var a=parseInt(document.getElementById("ddRafterThickInches").value)*32+parseInt(document.getElementById("ddRafterThickFrac").value),c=rafterData.split(","),e=templateData.split(",");window.open("Templates/creeper.aspx?rw="+a+"&rd="+c[0]+"&pa="+c[2]+"&sa="+e[7]+"&m=0")}
function HipTemplate(){var a=parseInt(document.getElementById("ddHipThickInches").value)*32+parseInt(document.getElementById("ddHipThickFrac").value),c=hipData.split(","),e=templateData.split(",");window.open("Templates/hip.aspx?rw="+a+"&rd="+c[0]+"&pa="+c[2]+"&sa="+e[5]+"&m=0")};