var radius,topHeight,middleHeight,radAngle,angle,RAD=180/Math.PI;function Window_onload(){Calculate();SetNumeric();if(document.getElementById("sldr").type=="range")document.getElementById("sldr").style.display="block"}function sldr_onchange(b){document.getElementById("txtAngle").value=b.value;Calculate()}
function Calculate(){radius=parseFloat(document.getElementById("txtRadius").value);if(isNaN(radius))alert("Please Enter Radius");else{angle=parseFloat(document.getElementById("txtAngle").value);if(isNaN(angle))alert("Please Enter Angle");else if(angle>179)alert("Please Enter Angle Under 180");else{radAngle=angle/RAD;middleHeight=radius*Math.cos(radAngle/2);topHeight=radius-middleHeight;CalcCircle()}}}
function CalcFromTable(){middleHeight=parseFloat(document.getElementById("txtMiddle").value);topHeight=parseFloat(document.getElementById("txtTop").value);if(isNaN(middleHeight)||isNaN(topHeight))alert("Please Enter Height");else{radius=topHeight+middleHeight;document.getElementById("txtRadius").value=Math.round(radius);angle=(90-Math.atan(middleHeight/Math.sqrt(radius*radius-middleHeight*middleHeight))*RAD)*2;radAngle=angle/RAD;document.getElementById("txtAngle").value=RoundTo(angle,1);CalcCircle()}}
function CalcCircle(){var b=Math.round(radius*2*Math.PI),a=Math.PI*radius*radius,d=a/(360/angle),e=Math.round(radAngle*radius),c=b-e,f=a-d,h=Math.round(Math.sin(radAngle/2)*radius*2),i=d-radius*radius*Math.sin(radAngle)/2;d=d-i;a*=1.0E-6;d*=1.0E-6;i*=1.0E-6;f*=1.0E-6;var j=1.33333*Math.PI*Math.pow(radius,3),g=Math.sqrt(Math.pow(radius,2)-Math.pow(h/2,2)),k=0.33333*Math.PI*Math.pow(h/2,2)*g;g=radius-g;g=Math.PI/6*(3*Math.pow(h/2,2)+Math.pow(g,2))*g;var l=j-k-g;j*=1.0E-6;l*=1.0E-6;k*=1.0E-6;g*=1.0E-6;
document.getElementById("spnLowerArea").innerHTML=RoundTo(f,3);document.getElementById("spnMidArea").innerHTML=RoundTo(d,3);document.getElementById("spnTopArea").innerHTML=RoundTo(i,3);document.getElementById("spnTotalArea").innerHTML=RoundTo(a,3);document.getElementById("spnSphereLower").innerHTML=RoundTo(l,2);document.getElementById("spnSphereMid").innerHTML=RoundTo(k,2);document.getElementById("spnSphereTop").innerHTML=RoundTo(g,2);document.getElementById("spnSphereTotal").innerHTML=RoundTo(j,
2);document.getElementById("spnAroundLower").innerHTML="Around Blue "+c;document.getElementById("spnTotalCirc").innerHTML="Total Circ "+b;document.getElementById("spnAroundBow").innerHTML="Around "+e;document.getElementById("spnChord").innerHTML="Across "+h;DrawCircle();c=document.getElementById("cnvsSection");b=c.height;a=c.width;f=radius*2/b;e=topHeight/f;f=middleHeight/f;h=c.height/2;c=c.getContext("2d");c.clearRect(0,0,a,b);c.fillStyle="#87ceeb";c.fillRect(0,h,a,b);c.fillStyle="#7cfc00";c.fillRect(0,
h-f,a,f);c.fillStyle="#f00";c.fillRect(0,0,a,e);document.getElementById("txtTop").style.top=95+e/2-10+"px";document.getElementById("txtTop").value=Math.round(topHeight);document.getElementById("txtMiddle").style.top=95+e+f/2-10+"px";document.getElementById("txtMiddle").value=Math.round(middleHeight)}
function DrawCircle(){var b=document.getElementById("cnvsCircle"),a=b.getContext("2d");a.clearRect(0,0,b.width,b.height);a.beginPath();a.fillStyle="#87ceeb";a.strokeStyle="#000";a.save();a.shadowOffsetY=6;a.shadowBlur=6;a.shadowColor="#c0c0c0";a.arc(170,170,169,0,360/RAD,false);a.fill();a.restore();a.beginPath();a.fillStyle="#f00";b=angle/2;var d=170-Math.sin(b/RAD)*169,e=170-Math.cos(b/RAD)*169,c=340-d;a.arc(171,170,169,(270-b)/RAD,(270+b)/RAD,false);a.fill();a.beginPath();a.fillStyle="#7cfc00";
a.moveTo(170,170);a.lineTo(d,e);a.lineTo(c,e);a.lineTo(170,170);a.fill();a.fillStyle="#000";a.font="12px Arial";a.textBaseline="top";a.fillText("Radius",224,177);a.fillText("Angle",116,177)}var animTimer;function AnimStart(b){animTimer=setInterval("Anim("+b+")",40)}function AnimStop(){clearInterval(animTimer)}
function Anim(b){b=parseFloat(document.getElementById("txtAngle").value)+b;if(b>1&&b<179){document.getElementById("txtAngle").value=b;document.getElementById("sldr").value=b;Calculate()}else AnimStop()};