if(top!=self)top.location=self.document.location;function Window_onload(){for(var d=document.getElementsByName("rbgGaps"),c=0;c<d.length;c++)d[c].onclick=EvenGap_onchange;d=document.getElementsByName("rbgType");for(c=0;c<d.length;c++)d[c].onclick=Type_onchange;Calculate()}
function CheckInput(){var d=parseInt(document.getElementById("ddWidthInches").value)*32+parseInt(document.getElementById("ddWidthFrac").value),c=parseInt(document.getElementById("ddTails").value),e=parseInt(document.getElementById("ddTailWidthInches").value)*32+parseInt(document.getElementById("ddTailWidthFrac").value);parseInt(document.getElementById("ddTailThickFrac").value);if(document.getElementById("rbEvenSpacing").checked){if(gap=document.getElementById("rbEvenGapsTails").checked?(d-e)/(c*2-
1):(d-e-c*e)/(c-1),gap<6)return alert("Will not fit"),false}else if(document.getElementById("rb4t2c").checked&&(gap=document.getElementById("rbEvenGapsTails").checked?(d-e)/11:(d-e-e*6)/5,gap<6))return alert("Will not fit 2 in centre"),false;return true}function Type_onchange(){document.getElementById("rbEvenSpacing").checked?document.getElementById("divTails").style.display="block":document.getElementById("divTails").style.display="none";Calculate()}
function EvenGap_onchange(){document.getElementById("rbSetTailWidth").checked?document.getElementById("divGapType").style.display="block":document.getElementById("divGapType").style.display="none";Calculate()}
function Calculate(){if(CheckInput()){var d=document.getElementById("cnvsDovetail");if(d.getContext){var c=3,e=(parseFloat(document.getElementById("ddWidthInches").value)*32+parseFloat(document.getElementById("ddWidthFrac").value))*c,h=parseFloat(document.getElementById("ddTailThickFrac").value)*c,f=parseFloat(document.getElementById("ddSocketThickFrac").value)*c,i=(parseFloat(document.getElementById("ddTailWidthInches").value)*32+parseInt(document.getElementById("ddTailWidthFrac").value))*c,s=document.getElementById("rb4t2c").checked,
c=document.getElementById("cbColor").checked,a=parseFloat(document.getElementById("ddPitch").value),b;b=s?6:parseFloat(document.getElementById("ddTails").value);var o=256+h+f*2,p=o/2,n=h/2,t=p-n,j=p+n,u=t-f,k=j+f,l=0,q=a>0?f/a:0,m=0;a>0?document.getElementById("rbEvenGapsTails").checked?b>1?(l=i=(e-h)/(b*2-1),m=n):l=m=i=e/3:b>1?(m=n,l=(e-h-b*i)/(b-1)):(m=e/2-i/2,l=(e-i)/2):m=l=i=e/(b*2+1);var g=0,a=d.getContext("2d");d.setAttribute("height",o);d.setAttribute("width",e);a.font="22px Verdana";a.fillStyle=
"#000";var d="X",n=m/2,g=a.measureText(d).width,r=g/2;p-=r;a.fillText(d,n-r,p+12);a.fillStyle=c?"#778899":"#fff";a.strokeStyle=c?"#fff":"#000";a.fillRect(0,0,e,128);a.fillRect(0,o-128,e,128);o=s?4:b;for(b=0;b<o;b++){g=m;a.beginPath();a.moveTo(g+q,u);a.lineTo(g,t);a.lineTo(g,j);a.lineTo(g+q,k-0.5);a.lineTo(g+(i-q),k-0.5);a.lineTo(g+i,j);a.lineTo(g+i,t);a.lineTo(g+(i-q),u+0.5);a.lineTo(g+q,u+0.5);c?a.fill():a.stroke();if(b<o-1)a.save(),a.fillStyle="#000",a.fillText(d,g+i+l/2-r,p+12),a.restore();g=i+
l;if(s&&(b==0||b==2))g+=i+l;m+=g}a.fillStyle="#000";a.fillText(d,e-n-r,p+12);i=128;a.beginPath();c||(a.moveTo(0,i),a.lineTo(e,i));i+=f;a.moveTo(0,i);a.lineTo(e,i);i+=h;a.moveTo(0,i);a.lineTo(e,i);c||(i+=f,a.moveTo(0,i),a.lineTo(e,i));a.stroke();a.font="bold 14px  Verdana";a.fillStyle="#fff";d="Print - Fold Over Wood";g=a.measureText(d).width;a.fillText(d,e/2-g/2,16);d="Cut Through Paper Template";g=a.measureText(d).width;a.fillText(d,e/2-g/2,36);if(document.getElementById("cbRuler").checked){a.strokeStyle=
c?"#fff":"#000";a.fillStyle=c?"#fff":"#000";a.font="18px Arial";a.textBaseline="top";a.lineWidth=0.5;c=6;h=16*c;f=0;a.beginPath();for(b=h;b<e;b+=h)a.moveTo(b,k),a.lineTo(b,k+28),f+=1,g=a.measureText(f).width/2,a.fillText(f,b-g,k+30);a.stroke();h=16*c;f=8*c;a.font="10px Arial";d="1/2";g=a.measureText(d).width/2;a.beginPath();for(b=f;b<e;b+=h)a.moveTo(b,k),a.lineTo(b,k+22),a.fillText(d,b-g,k+24);a.stroke();h=8*c;f=4*c;a.beginPath();for(b=f;b<e;b+=h)a.moveTo(b,k),a.lineTo(b,k+16);a.stroke();h=c;a.beginPath();
f=0;for(b=h;b<e;b+=h)f+=1,f%4!=0&&(a.moveTo(b,k),a.lineTo(b,k+8));a.stroke();j+=1;f=0;h=16*c;a.fillStyle="#000";a.strokeStyle="#000";a.font="18px Arial";a.beginPath();for(b=h;b<e;b+=h)a.moveTo(b,j),a.lineTo(b,j+28),f+=1,g=a.measureText(f).width/2,a.fillText(f,b-g,j+30);a.stroke();h=16*c;f=8*c;a.font="10px Arial";d="1/2";g=a.measureText(d).width/2;a.beginPath();for(b=f;b<e;b+=h)a.moveTo(b,j),a.lineTo(b,j+22),a.fillText(d,b-g,j+24);a.stroke();h=8*c;f=4*c;a.beginPath();for(b=f;b<e;b+=h)a.moveTo(b,j),
a.lineTo(b,j+16);a.stroke();h=c;a.beginPath();f=0;for(b=h;b<e;b+=h)f+=1,f%4!=0&&(a.moveTo(b,j),a.lineTo(b,j+8));a.stroke()}}}}
function PitchChanged(d){d.value=="0"?(document.getElementById("rbEvenGapsTails").checked=true,document.getElementById("rbEvenSpacing").checked=true,document.getElementById("spn4t2c").style.display="none",document.getElementById("spnSetTailWidth").style.display="none",document.getElementById("divTails").style.display="block",document.getElementById("divGapType").style.display="none"):(document.getElementById("spn4t2c").style.display="block",document.getElementById("spnSetTailWidth").style.display=
"block",document.getElementById("divGapType").style.display="block");Calculate()};
