function Beamcalc(){
var pheight = document.beamcalc.pheight.value;
var cheight = document.beamcalc.cheight.value;
var hdist = document.beamcalc.hdist.value;
var aimheight = document.beamcalc.aimheight.value;
var lenssize;
for (var i = 0; i < 7; i++)
{
if (document.beamcalc.lenssize[i].checked)
{
var lenssize = document.beamcalc.lenssize[i].value;
}
}
var throwdist = Math.sqrt((Math.pow(hdist, 2))+(Math.pow((pheight - aimheight),2)));
if (lenssize == 3)
{var lenswidth = 14.02;}
else if (lenssize == 2.5)
{var lenswidth = 18.29;}
else if (lenssize == 4)
{var lenswidth = 8.74;}
else if (lenssize == 5.5)
{var lenswidth = 6.15;}
else if (lenssize == 6)
{var lenswidth = 5.13;}
else if (lenssize == 8)
{var lenswidth = 3.61;}
else if (lenssize == 10)
{var lenswidth = 3.25;}
var lensratio = (lenswidth / 9.1);
var imgdiam = (throwdist * lensratio);
var imgr = (imgdiam / 2);
var shortline = Math.sqrt((Math.pow((pheight - cheight),2))+(Math.pow(hdist, 2)));
var sinsigma = (hdist / throwdist);
var sintheta = Math.sqrt(1-(Math.pow(sinsigma, 2)));
var singamma = (hdist / shortline);
var sindelta = Math.sin((Math.PI)-((Math.asin(sintheta))+(Math.asin(singamma))));
var y2 = (((cheight - aimheight)/sindelta)*singamma);
var x2 = Math.sqrt((Math.pow(imgr , 2))-(Math.pow(y2 , 2)));
var longline = Math.sqrt((Math.pow(throwdist , 2))+(Math.pow(y2 , 2)));
var x1 = (shortline / longline) * x2;
var topwidth = (x1 * 2);
var bigshortline = Math.sqrt((Math.pow(pheight , 2))+(Math.pow(hdist , 2)));
var extrathrow = (aimheight * sintheta);
var bigr = ((extrathrow + throwdist)* lensratio)/2;
var y3 = Math.sqrt((Math.pow(aimheight , 2))-(Math.pow(extrathrow , 2)));
var x3 = Math.sqrt((Math.pow(bigr , 2))-(Math.pow(y3 , 2)));
var y2ratio = (y2 / imgr);
var y3ratio = (y3 / bigr);
var longthrow = (extrathrow + throwdist);
var bottomwidth = (2 * x3);
var beamratio = (y2ratio + y3ratio)/2;
document.beamcalc.throwdist.value = throwdist.toFixed(2);
document.beamcalc.imgdiam.value = imgdiam.toFixed(2);
document.beamcalc.imgr.value = imgr.toFixed(2);
document.beamcalc.topwidth.value = topwidth.toFixed(2);
document.beamcalc.bottomwidth.value = bottomwidth.toFixed(2);
document.beamcalc.beamratio.value = beamratio.toFixed(3);
}
