function Form_onsubmit(){var a=parseInt(document.getElementById("txtWidth").value),c=parseInt(document.getElementById("txtLength").value);if(a>c){alert("Width cannot be greater than Length");document.getElementById("txtWidth").focus();return false}if(parseInt(document.getElementById("txtPlateWidth").value)>0){a=parseInt(document.getElementById("_txtAngle").value);c=parseInt(document.getElementById("txtPlateWidth").value)*Math.sin(a/(180/Math.PI));a=parseInt(document.getElementById("txtRafterDepth").value);
if(a/c<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}c=parseInt(document.getElementById("txtHipDepth").value);a=parseInt(document.getElementById("txtRafterDepth").value);if(c<a){alert("Hip Depth must be equal to or greater than Rafter Depth\n\r\n\rHip Depth re-set to "+a);document.getElementById("txtHipDepth").value=a}return true}
function ShowBirdsCalc(){document.getElementById("_txtBirdsmouthAngle").value=document.getElementById("_txtAngle").value;document.getElementById("divBirdsmouth").style.left="260px"}function HideBirdsCalc(){document.getElementById("divBirdsmouth").style.left="-10000px"}
function CalcSeat(){var a=parseFloat(document.getElementById("txtPlumbCut").value);if(isNaN(a)){document.getElementById("txtPlumbCut").select();alert("Please enter a valid number for Plumb Cut")}else{var c=GetRangle();if(c!=null){c=a/Math.tan(c);document.getElementById("spnSeatCut").innerHTML=Math.round(c)+" mm";document.getElementById("txtSeatCut").value=Math.round(c);document.getElementById("spnPlumbCut").innerHTML=Math.round(a)+" mm";document.getElementById("txtPlateWidth").value=document.getElementById("txtSeatCut").value}}}
function CalcPlumb(){var a=parseFloat(document.getElementById("txtSeatCut").value);if(isNaN(a)){document.getElementById("txtSeatCut").select();alert("Please enter a valid number for Seat Cut")}else{var c=GetRangle();if(c!=null){a=Math.tan(c)*a;document.getElementById("spnPlumbCut").innerHTML=Math.round(a)+" mm";document.getElementById("txtPlumbCut").value=Math.round(a);a=a/Math.tan(c);document.getElementById("spnSeatCut").innerHTML=Math.round(a)+" mm";document.getElementById("txtPlateWidth").value=
document.getElementById("txtSeatCut").value}}}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)}
function Window_onload(){DrawRoof();DrawRafter();DrawHip();DrawTemplate();DrawHipDetail();SetInput()}var RAD=Math.PI/180,lineWidth=6,fontSize=12;
function DrawRoof(){var a=document.getElementById("cnvsRoof");if(a.getContext){var c=a.width-30,e=roofData.split(","),l=parseFloat(e[0]),f=parseFloat(e[1]);if(!(f>l)){var r=parseFloat(e[2]),k=parseFloat(e[3]),d=parseFloat(e[4]),m=parseFloat(e[5]),i=parseFloat(e[6]),n=parseFloat(e[7]),p=parseFloat(e[8]),h=parseFloat(e[9]),s=parseFloat(e[10]),t=parseFloat(e[11]),w=parseFloat(e[12]),q=parseFloat(e[13]),v=parseFloat(e[14]),u=parseFloat(e[15]);parseFloat(e[16]);var x=parseFloat(e[17]),A=parseFloat(e[18]),
y=parseFloat(e[19]),E=parseFloat(e[20]),C=parseFloat(e[21]),D=l+u*2,F=f+u*2;f=c*(F/D);a.setAttribute("height",f);var z=c/D;e=0;var b=a.getContext("2d");b.beginPath();b.fillStyle="#f8f8ff";b.strokeStyle="#000";b.fillRect(0,0,c,f);b.strokeRect(0,0,c,f-1);if(u>0){e=u*z;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*z;b.lineWidth=lineWidth;b.font=
fontSize+"px Verdana";b.textBaseline="top";if(q>50){b.strokeStyle="#f00";v=v;var g=c-a+o,j=f-a+o;for(b.fillStyle="#000";g<c&&v>50;){b.beginPath();b.moveTo(g,f);b.lineTo(g,j);b.lineTo(c,j);b.stroke();b.fillText(Math.round(v),g+lineWidth/2,j-lineWidth/2-fontSize);v-=q;g+=o;j=f-(c-g)}}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;v=w-2;g+=t>0?t*z:o;for(j=0;j<v;j++){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;j=i*RAD;y*=Math.cos(j);y*=z;var B=0;if(E>0){B=E*z*Math.cos(j);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 "+d,a/2+lineWidth,G-fontSize);d="Rafters "+m+" long x "+h+" deep x "+p+" thick";h=b.measureText(d).width;b.fillText(d,c/2-h/2,a-lineWidth/2-g*4);d=t==0?"Adjusted Rafter Spacing "+s:"Rafter Spacing "+s+" (2 ends = "+t+")";s=a-lineWidth/2;h=b.measureText(d).width;b.fillText(d,
c/2-h/2,s-g*3);d="Creeper Shortening "+q;h=b.measureText(d).width;b.fillText(d,c/2-h/2,s-g*2);d="Ridge "+k+" long x "+n+" thick";h=b.measureText(d).width;b.fillText(d,c/2-h/2,s-g);d="Roof area "+x+" m\u00b2";h=b.measureText(d).width;b.fillText(d,c-a/2-h/2,2);d="Rafter "+m;b.fillText(d,c-a+lineWidth,G);if(u>0){d="Roof Length "+D;b.fillText(d,4,a+g*2);d="Roof Width "+F;b.fillText(d,4,a+g*3);d="Overhang (level) "+u;b.fillText(d,40,2)}d="Wall Length "+l;h=b.measureText(d).width;b.fillText(d,c/2-h/2,0);
d="Angle "+i+"\u00b0";h=b.measureText(d).width;b.fillText(d,c/2-h/2,g);d="Overall Rise From Wall "+r;h=b.measureText(d).width;b.fillText(d,c/2-h/2,g*2);b.fillText("Sheathing",40,f-g*2);b.fillText(A+"\u00b0",40,f-g);C>0&&b.fillText("End Jacks "+C,44,s-g);if(document.getElementById("pnlRunning")!=null){b=document.getElementById("cnvsRun");b.setAttribute("height",f);i=document.getElementById("lblRunLength").innerHTML.split(", ");q=0;l=document.getElementById("lblRunWidth").innerHTML.split(", ");r=0;
x=document.getElementById("lblRunRidge").innerHTML.split(", ");A=0;k=document.getElementById("lblRunHip").innerHTML.split(", ");m=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(u>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="11px Verdana";b.fillStyle="#000";b.textBaseline="top";b.beginPath();b.strokeStyle="#f00";g=e+i[0]*z;for(j=
f-g;g<a-10;){b.moveTo(g,f);b.lineTo(g,j);b.lineTo(0,j);d=l[r++];b.fillText(d,2,j+2);b.save();d=i[q++];h=b.measureText(d).width;b.translate(g-2,f-6-h);b.rotate(90*RAD);b.fillText(d,0,0);b.restore();g+=o;j-=o}b.stroke();b.beginPath();b.strokeStyle=n==p?"#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=l[r++];b.fillText(d,2,a+2);g=a;b.moveTo(a,0);b.lineTo(a,f);b.save();d=i[q++];h=b.measureText(d).width;b.translate(a-2,f-6-h);b.rotate(90*
RAD);b.fillText(d,0,0);b.restore();if(w>1){g+=t>0?t*z:o;for(j=0;j<v;j++){b.moveTo(g,f);b.lineTo(g,0);b.save();d=i[q++];h=b.measureText(d).width;b.translate(g-2,f-6-h);b.rotate(90*RAD);b.fillText(d,0,0);b.restore();b.save();d=x[++A];h=b.measureText(d).width;b.translate(g-2,a-h-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=i[q++];h=b.measureText(d).width;b.translate(c-a,f-6-h);b.rotate(90*RAD);b.fillText(d,0,0);b.restore();b.save();d=x[++A];h=b.measureText(d).width;
b.translate(c-a-2,a-h-4);b.rotate(90*RAD);b.fillText(d,0,0);b.restore()}b.stroke();b.beginPath();b.strokeStyle="#f00";g=c-a+o;for(j=a+o;g<c-e&&q<i.length;){b.moveTo(g,f);b.lineTo(g,j);b.lineTo(c,j);b.save();d=i[q++];h=b.measureText(d).width;b.translate(g-2,f-6-h);b.rotate(90*RAD);b.fillText(d,0,0);b.restore();g+=o;j+=o}g=c-a+o;j=a+o;for(n=0;n<k.length;n++){b.save();b.translate(g-4,j-10);b.rotate(-40*RAD);b.fillText(k[m++],0,0);b.restore();g+=o;j+=o}g=a-o;for(j=a-o;g>e+2;){b.moveTo(g,0);b.lineTo(g,
j);b.lineTo(0,j);b.fillText(l[r++],2,j+2);g-=o;j=g}g=c-a+o;for(j=a-o;g<c-e-2;){b.moveTo(g,0);b.lineTo(g,j);b.lineTo(c,j);g+=o;j-=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]),l=parseFloat(c[1]),f=parseFloat(c[2]),r=parseFloat(c[3]),k=c[4]=="1",d=parseFloat(c[5]),m=c[6];c=a.width;var i=a.height-20,n=i/Math.tan(f*RAD),p=k?n:0;a=a.getContext("2d");a.font="13px Verdana";a.textBaseline="top";a.fillStyle="#7cfc00";a.strokeStyle="#000";a.beginPath();a.moveTo(p,0);a.lineTo(c,0);a.lineTo(c-n,i);var h,s;k=false;if(d>0){var t=e/i;s=d/t;h=170-n;var w=s*
Math.sin((90-f)*RAD),q=h+w/Math.tan(f*RAD),v=i-w,u=q+s*Math.cos((90-f)*RAD);s=d*Math.tan((90-f)*RAD);a.lineTo(u,i);a.lineTo(q,v);a.lineTo(170,0);a.lineTo(h,i);a.lineTo(0,i);if(e/t/w<2.9)k=true}else a.lineTo(0,i);a.lineTo(p,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(m,172,2);a.fillText(Math.round(s),170-n-20,i-20);a.fillText(Math.round(Math.sqrt(Math.pow(s,2)+Math.pow(d,2))),h,i)}l="Setback "+l;d=a.measureText(l).width;
a.fillText(l,c-d-2,i+4);l="Plumb cut "+f+"\u00b0";d=a.measureText(l).width;a.fillText(l,c-d-10,2);a.fillText("Rafter Len "+r,2,2);a.fillText("Rafter depth "+e,c*0.6,i/2-12);if(k){a.fillStyle="#f00";a.fillText("Birdsmouth is Deep !",h+40,i)}}}
function DrawHip(){var a=document.getElementById("cnvsHip");if(a.getContext){var c=hipData.split(","),e=parseFloat(c[0]),l=parseFloat(c[1]),f=parseFloat(c[2]),r=c[3],k=c[4]=="1",d=parseFloat(c[5]),m=c[6],i=parseFloat(c[7]);c=90-f;var n=a.width,p=a.height-20,h=p/Math.tan(f*RAD),s=k?h:0;a=a.getContext("2d");a.font="13px Verdana";a.textBaseline="top";a.fillStyle="#ffa500";a.strokeStyle="#000";a.beginPath();a.moveTo(s,0);a.lineTo(n,0);a.lineTo(n-h,p);var t,w,q;k=false;if(i>0||d>0){d=Math.sqrt(d*d+d*d);
var v=e/p;t=130-h;var u=d/v*Math.sin(c*RAD);if(i>0)u+=i/Math.cos(c*RAD)/v;var x=t+u/Math.tan(f*RAD),A=p-u,y=x+u/Math.tan(c*RAD);q=d*Math.sin(c*RAD);q+=i*Math.cos(c*RAD);w=q/Math.cos(c*RAD);q=q/Math.sin(c*RAD);a.lineTo(y,p);a.lineTo(x,A);a.lineTo(130,0);a.lineTo(t,p);a.lineTo(0,p);if(e/v/u<2.9)k=true}else a.lineTo(0,p);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(i>0||d>0){a.fillText(m,132,2);a.fillText(Math.round(w),
130-h-20,p-20);a.fillText(Math.round(Math.sqrt(Math.pow(w,2)+Math.pow(q,2))),t,p)}l="Setback "+l;d=a.measureText(l).width;a.fillText(l,n-d-2,p+4);l="Plumb cut "+f+"\u00b0";d=a.measureText(l).width;a.fillText(l,n-d-10,2);a.fillText("Hip Len "+r,2,2);a.fillText("Hip Depth "+e,n*0.6,p/2-12);a.fillText("Hip Angle "+c.toFixed(1)+"\u00b0",n*0.6,p/2+8);if(k){a.fillStyle="#f00";a.fillText("Birdsmouth is Deep !",t+40,p)}}}
function DrawTemplate(){var a=document.getElementById("cnvsTemplate");if(a.getContext){var c=templateData.split(","),e=parseFloat(c[0]),l=parseFloat(c[1]),f=parseFloat(c[2]),r=parseFloat(c[3]),k=parseFloat(c[4]),d=parseFloat(c[5]),m=parseFloat(c[6]),i=parseFloat(c[7]);c=parseFloat(c[8]);a.setAttribute("height",400/Math.tan(i*RAD)+14+4);a=a.getContext("2d");a.font="14px Verdana";a.textBaseline="top";var n=new Image;n.src=document.getElementById("imgAngles").src;a.drawImage(n,0,0);a.beginPath();a.moveTo(0,
0);a.lineTo(400,e);a.fillText("Hip plumb "+l+"\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,k);a.fillText("Hip side cut "+d+"\u00b0",416,k-14);a.moveTo(0,0);a.lineTo(400,m);a.fillText("Creeper side "+i+"\u00b0",416,m);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,k-12,14,12);a.fillStyle="#f00";
a.fillRect(400,m+2,14,12)}}
function DrawHipDetail(){var a=document.getElementById("cnvsHipDetail");if(a.getContext){var c=hipDetailData.split(","),e=parseFloat(c[0]),l=parseFloat(c[1]),f=parseFloat(c[2]);c=parseFloat(c[3]);var r=a.width-2,k=f*(100/c)+100;a.setAttribute("height",k+18);var d=(k-100)/Math.tan(e*RAD);a=a.getContext("2d");a.beginPath();var m=new Image;m.src=document.getElementById("bgImage1").src;m=a.createPattern(m,"repeat");a.fillStyle=m;a.moveTo(75,1);a.lineTo(1,25);a.lineTo(75,50);a.lineTo(75+d,k);a.lineTo(r,
k);m=0;for(var i=(k-50)/20,n=0;n<21;n++){a.lineTo(r-m,k-n*i);m=m>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,k-25);a.lineTo(75+d,k);a.lineTo(75,50);a.lineTo(1,25);m=new Image;m.src=document.getElementById("bgImage2").src;m=a.createPattern(m,"repeat");a.fillStyle=m;a.fill();a.stroke();a.font="24px Arial";a.textBaseline="top";a.fillStyle="#000";e=e+"\u00b0";a.fillText(e,85,50);d=a.measureText(f).width;
a.fillText(f,r-d-40,k/2);d=a.measureText(c).width;a.fillText(c,r-25-d-10,11);e="Hip Plumb + Side Cuts";a.fillText(e,r/3,52);e=l+"\u00b0";d=a.measureText(e).width;a.translate(d/2,6);a.rotate(20*RAD);a.fillText(e,50-d,29)}}function CommonTemplate(){var a=document.getElementById("txtRafterThick").value,c=rafterData.split(",");window.open("Templates/rafter.aspx?rw="+a+"&rd="+c[0]+"&pa="+c[2]+"&m=1")}
function CreeperTemplate(){var a=document.getElementById("txtRafterThick").value,c=rafterData.split(","),e=templateData.split(",");window.open("Templates/creeper.aspx?rw="+a+"&rd="+c[0]+"&pa="+c[2]+"&sa="+e[7]+"&m=1")}function HipTemplate(){var a=document.getElementById("txtHipThick").value,c=hipData.split(","),e=templateData.split(",");window.open("Templates/hip.aspx?rw="+a+"&rd="+c[0]+"&pa="+c[2]+"&sa="+e[5]+"&m=1")};