if(top!=self)top.location=self.document.location;
function CheckInput(){var d=parseInt(document.getElementById("txtWidth").value);if(isNaN(d)||d>500)return alert("Please Enter Valid Width\n\nMax = 500"),document.getElementById("txtWidth").focus(),false;var e=parseInt(document.getElementById("ddTails").value),f=parseInt(document.getElementById("ddTailWidth").value);parseInt(document.getElementById("ddTailThick").value);var h=0;if(document.getElementById("rbEvenSpacing").checked){if(h=document.getElementById("rbEvenGapsTails").checked?(d-f)/(e*2-1):
(d-f-e*f)/(e-1),h<4)return alert("Will not fit"),false}else if(document.getElementById("rb4t2c").checked&&(h=document.getElementById("rbEvenGapsTails").checked?(d-f)/11:(d-f-f*6)/5,h<4))return alert("Will not fit 2 in centre"),false;return true}function Window_onload(){for(var d=document.getElementsByName("rbgGaps"),e=0;e<d.length;e++)d[e].onclick=EvenGap_onchange;d=document.getElementsByName("rbgType");for(e=0;e<d.length;e++)d[e].onclick=Type_onchange;Calculate();SetNumeric()}
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 e=parseFloat(document.getElementById("txtWidth").value)*3.77952755905512,f=parseFloat(document.getElementById("ddTailThick").value)*3.77952755905512,h=parseFloat(document.getElementById("ddSocketThick").value)*3.77952755905512,c=parseFloat(document.getElementById("ddTailWidth").value)*3.77952755905512,s=document.getElementById("rb4t2c").checked,k=document.getElementById("cbColor").checked,a=parseFloat(document.getElementById("ddPitch").value),
b;b=s?6:parseFloat(document.getElementById("ddTails").value);var o=256+f+h*2,p=o/2,n=f/2,t=p-n,i=p+n,u=t-h,j=i+h,l=0,q=a>0?h/a:0,m=0;a>0?document.getElementById("rbEvenGapsTails").checked?b>1?(l=c=(e-f)/(b*2-1),m=n):l=m=c=e/3:b>1?(m=n,l=(e-f-b*c)/(b-1)):(m=e/2-c/2,l=(e-c)/2):m=l=c=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=
k?"#778899":"#fff";a.strokeStyle=k?"#fff":"#000";a.fillRect(0,0,e,128);a.fillRect(0,o-128,e,128);var o=s?4:b,v=o-1;for(b=0;b<o;b++){g=m;a.beginPath();a.moveTo(g+q,u);a.lineTo(g,t);a.lineTo(g,i);a.lineTo(g+q,j-0.5);a.lineTo(g+(c-q),j-0.5);a.lineTo(g+c,i);a.lineTo(g+c,t);a.lineTo(g+(c-q),u+0.5);a.lineTo(g+q,u+0.5);k?a.fill():a.stroke();if(b<v)a.save(),a.fillStyle="#000",a.fillText(d,g+c+l/2-r,p+12),a.restore();g=c+l;if(s&&(b==0||b==2))g+=c+l;m+=g}a.fillStyle="#000";a.fillText(d,e-n-r,p+12);c=128;a.beginPath();
k||(a.moveTo(0,c),a.lineTo(e,c));c+=h;a.moveTo(0,c);a.lineTo(e,c);c+=f;a.moveTo(0,c);a.lineTo(e,c);k||(c+=h,a.moveTo(0,c),a.lineTo(e,c));a.stroke();a.font="bold 18px  Verdana";a.fillStyle="#fff";d="Print - Fold Over Wood";g=a.measureText(d).width;a.fillText(d,e/2-g/2,20);d="Cut Through Paper Template";g=a.measureText(d).width;a.fillText(d,e/2-g/2,47);if(document.getElementById("cbRuler").checked){a.strokeStyle=k?"#fff":"#000";a.lineWidth=0.5;c=0;f=377.952755905512;h=30;a.font="18px Arial";a.textBaseline=
"top";a.fillStyle=k?"#f00":"#000";a.beginPath();for(b=f;b<e;b+=f)a.moveTo(b,j),a.lineTo(b,j+h),c+=100,g=a.measureText(c).width/2,a.fillText(c,b-g,j+30);a.stroke();f=37.7952755905512;a.beginPath();a.fillStyle=k?"#fff":"#000";h=24;c=0;a.font="12px Arial";for(b=f;b<e;b+=f)c+=10,c%100!=0&&(a.moveTo(b,j),a.lineTo(b,j+h),d=c%100,g=a.measureText(d).width/2,a.fillText(d,b-g,j+h));a.stroke();c=0;a.beginPath();f=3.77952755905512;h=12;for(b=0;b<e;b+=f)c++%10!=0&&(a.moveTo(b,j),a.lineTo(b,j+(c%5==1?h+5:h)));
a.stroke();i+=1;c=0;f=377.952755905512;a.font="18px Arial";a.fillStyle=k?"#f00":"#000";a.strokeStyle="#000";a.beginPath();for(b=f;b<e;b+=f)a.moveTo(b,i),a.lineTo(b,i+30),c+=100,g=a.measureText(c).width/2,a.fillText(c,b-g,i+30);a.stroke();f=37.7952755905512;a.beginPath();a.fillStyle="#000";h=24;c=0;a.font="12px Arial";for(b=f;b<e;b+=f)c+=10,c%100!=0&&(a.moveTo(b,i),a.lineTo(b,i+h),d=c%100,g=a.measureText(d).width/2,a.fillText(d,b-g,i+h));a.stroke();a.beginPath();f=3.77952755905512;h=12;for(b=c=0;b<
e;b+=f)c++%10!=0&&(a.moveTo(b,i),a.lineTo(b,i+(c%5==1?h+5:h)));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()};
