var incs=0,aP=[],major,minor,_p1,p1,_major,_minor,_major2,_minor2,imgPencil,imgTack,imgTack2;function SetCalc(){imgPencil=new Image;imgPencil.src=document.getElementById("imgPencil").src;imgTack=new Image;imgTack.src=document.getElementById("imgTack").src;imgTack2=new Image;imgTack2.src=document.getElementById("imgTack2").src;CalcElipse();DrawElipse();if(document.getElementById("sldr").type=="range")document.getElementById("divSldr").style.display="block"}
function Calculate(){if(!anim){incs=0;CalcElipse();DrawElipse()}}function sldr_onchange(b){var a=parseInt(document.getElementById("ddOvalMajFeet").value)*384+parseInt(document.getElementById("ddOvalMajInches").value)*32+parseInt(document.getElementById("ddOvalMajFrac").value);if(!anim&&parseInt(b.value)<a){SetMinor(b.value);incs=0;CalcElipse();DrawElipse()}}
function CalcElipse(){major=parseInt(document.getElementById("ddOvalMajFeet").value)*384+parseInt(document.getElementById("ddOvalMajInches").value)*32+parseInt(document.getElementById("ddOvalMajFrac").value);minor=parseInt(document.getElementById("ddOvalMinFeet").value)*384+parseInt(document.getElementById("ddOvalMinInches").value)*32+parseInt(document.getElementById("ddOvalMinFrac").value);if(minor>=major){StopSize();alert("Minor axis length must be less than Major axis length")}else{var b=document.getElementById("cnvsOval"),
a=b.width;b.setAttribute("height",(a-60)/(major/minor)+66);b=major/(a-64);_major=major/b;_minor=minor/b;_major2=_major/2;_minor2=_minor/2;_cx=a/2;_cy=_minor/2+40;a=major/2;var c=minor/2;p1=Math.sqrt(a*a-c*c);_p1=p1/b;document.getElementById("spnP1").innerHTML=ConEng(p1,true);document.getElementById("spnCtoP1").innerHTML=ConEng(p1,true);b=Math.PI*a*c/147456;document.getElementById("spnMajor").innerHTML=ConEng(major,true);document.getElementById("spnMinor").innerHTML=ConEng(minor,true);document.getElementById("spnArea").innerHTML=
RoundTo(b,2);document.getElementById("sldr").setAttribute("max",major-1);document.getElementById("sldr").value=minor;a=-90*(Math.PI/180);b=Math.sin(a);a=Math.cos(a);for(c=0;c<361;c++){var d=c*(Math.PI/180),e=Math.sin(d);d=Math.cos(d);aP[c]=new Point(_cx+(_minor2*d*a-_major2*e*b),_cy+(_minor2*d*b+_major2*e*a))}}}
function DrawElipse(){var b=document.getElementById("cnvsOval"),a=b.getContext("2d");a.clearRect(0,0,b.width,b.height);a.lineWidth=2;if(document.getElementById("cbShowSet").checked){a.strokeStyle="#c0c0c0";a.beginPath();a.moveTo(_cx-_major2,_cy);a.lineTo(_cx+_major2,_cy);a.moveTo(_cx,_cy-_minor2);a.lineTo(_cx,_cy+_minor2);a.stroke();a.font="Bold 22px Arial";a.textBaseline="top";a.fillStyle="#f00";a.fillText("P1",_cx-_p1-10,_cy+6);a.fillText("P2",_cx+_p1-18,_cy+6);a.fillStyle="#00f";a.fillText("A",
10,_cy-10);a.fillText("B",_cx+_major2+4,_cy-10);a.fillText("C",_cx+2,_cy+6);a.fillText("D",_cx-8,_cy+_minor2+4);a.fillText("E",_cx-12,_cy-_minor2-34);a.strokeStyle="#080";a.beginPath();a.moveTo(_cx+24,_cy+12);a.lineTo(_cx+_p1-30,_cy+12);a.stroke();a.font="12px Arial";a.fillText(ConEng(p1,true),_cx+_p1/2-20,_cy+18);if(incs==0||incs==360)a.drawImage(imgTack2,_cx-20,_cy-_minor2-12)}if(document.getElementById("cbShowString").checked){a.beginPath();a.moveTo(_cx-_p1,_cy);a.lineTo(aP[incs].x,aP[incs].y);
a.lineTo(_cx+_p1,_cy);a.closePath();a.strokeStyle="#f00";a.stroke();a.drawImage(imgPencil,aP[incs].x-2,aP[incs].y-38);a.drawImage(imgTack2,_cx-_p1-14,_cy-16);a.drawImage(imgTack,_cx+_p1-12,_cy-16)}b=incs>0?incs+1:361;a.beginPath();a.moveTo(_cx,_cy-_minor2);for(var c=0;c<b;c++)a.lineTo(aP[c].x,aP[c].y);a.strokeStyle="#00f";a.stroke();incs++;if(incs>360){incs=0;anim=false;clearInterval(pTimer)}}var pTimer=null,anim=false;
function DoAnimation(){if(!anim){anim=true;pTimer=setInterval("DrawElipse()",10)}}function Point(b,a){this.x=b;this.y=a}var sizeTimer=null;function Minor(b){anim||(sizeTimer=setInterval("MinorAuto("+b+")",10))}function MinorAuto(b){b=parseInt(document.getElementById("ddOvalMinFeet").selectedIndex)*384+parseInt(document.getElementById("ddOvalMinInches").selectedIndex)*32+parseInt(document.getElementById("ddOvalMinFrac").selectedIndex*2)+b;if(b>32){SetMinor(b);CalcElipse();incs=0;DrawElipse()}}
function StopSize(){clearInterval(sizeTimer)}function SetMinor(b){document.getElementById("ddOvalMinFrac").selectedIndex=b%32/2;document.getElementById("ddOvalMinInches").selectedIndex=Math.floor(b/32)%12;document.getElementById("ddOvalMinFeet").selectedIndex=Math.floor(b/384)}function ShowSet(){if(!anim){incs=0;DrawElipse()}};
