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(a){document.getElementById("txtAngle").value=a.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 a=Math.round(radius*2*Math.PI),b=Math.PI*radius*radius,h=b/(360/angle),c=Math.round(radAngle*radius),f=a-c,g=b-h,d=Math.round(Math.sin(radAngle/2)*radius*2),i=h-radius*radius*Math.sin(radAngle)/2;h=h-i;b*=1.0E-6;h*=1.0E-6;i*=1.0E-6;g*=1.0E-6;var j=1.33333*Math.PI*Math.pow(radius,3),e=Math.sqrt(Math.pow(radius,2)-Math.pow(d/2,2)),k=0.33333*Math.PI*Math.pow(d/2,2)*e;e=radius-e;e=Math.PI/6*(3*Math.pow(d/2,2)+Math.pow(e,2))*e;var l=j-k-e;j*=1.0E-6;l*=1.0E-6;k*=1.0E-6;e*=1.0E-6;
document.getElementById("spnLowerArea").innerHTML=RoundTo(g,3);document.getElementById("spnMidArea").innerHTML=RoundTo(h,3);document.getElementById("spnTopArea").innerHTML=RoundTo(i,3);document.getElementById("spnTotalArea").innerHTML=RoundTo(b,3);document.getElementById("spnSphereLower").innerHTML=RoundTo(l,2);document.getElementById("spnSphereMid").innerHTML=RoundTo(k,2);document.getElementById("spnSphereTop").innerHTML=RoundTo(e,2);document.getElementById("spnSphereTotal").innerHTML=RoundTo(j,
2);document.getElementById("spnAroundLower").innerHTML="Arc Blue "+f;document.getElementById("spnTotalCirc").innerHTML="Total Circ "+a;document.getElementById("spnAroundBow").innerHTML="Arc Red "+c;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";
c=angle/2;f=170-Math.sin(c/RAD)*169;b=170-Math.cos(c/RAD)*169;g=340-f;a.arc(170,170,169,(270-c)/RAD,(270+c)/RAD,false);a.fill();a.beginPath();a.fillStyle="#7cfc00";a.moveTo(170,170);a.lineTo(f,b);a.lineTo(g,b);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);d="Chord "+d;c=a.measureText(d).width;a.fillText(d,170-c/2,b-angle*0.04);b=document.getElementById("cnvsSection");d=b.height;c=b.width;a=radius*2/d;
f=topHeight/a;g=middleHeight/a;i=b.height/2;a=b.getContext("2d");a.clearRect(0,0,c,d);a.fillStyle="#87ceeb";a.fillRect(0,i,c,d);a.fillStyle="#7cfc00";a.fillRect(0,i-g,c,g);a.fillStyle="#f00";a.fillRect(0,0,c,f);document.getElementById("txtTop").style.top=1+f/2-10+"px";document.getElementById("txtTop").value=Math.round(topHeight);document.getElementById("txtMiddle").style.top=1+f+g/2-10+"px";document.getElementById("txtMiddle").value=Math.round(middleHeight)}var animTimer;
function AnimStart(a){animTimer=setInterval("Anim("+a+")",40)}function AnimStop(){clearInterval(animTimer)}function Anim(a){a=parseFloat(document.getElementById("txtAngle").value)+a;if(a>1&&a<179){document.getElementById("txtAngle").value=a;document.getElementById("sldr").value=a;Calculate()}else AnimStop()};
