function RoundTo(number,X)
{
X = (!X ? 2 : X);
return Math.round(number*Math.pow(10,X))/Math.pow(10,X);
}
function Calculate()
{
var err = '';
var f1 = document.calcform;
var f2 = document.outform;
if (!f1 || !f2)
err = 'Forms not found';
else
{
var bulletweight = parseFloat(f1.bulletweight.value);
var bulletvelocity = parseFloat(f1.bulletvelocity.value);
var powderweight = parseFloat(f1.powderweight.value);
var gunweight = parseFloat(f1.gunweight.value);
err += (bulletweight == '') ? 'You must supply the bulletweight.\n' : '';
err += (bulletvelocity == '') ? 'You must supply the bulletvelocity.\n' : '';
err += (powderweight == '') ? 'You must supply the powderweight.\n' : '';
err += (gunweight == '') ? 'You must supply the gunweight.\n' : '';
if (!err)
{
var bulletmass = bulletweight/7000/32.17;
var powdermass = powderweight/7000/32.17;
var powdermomentum = powdermass*4000.0;
var momentum = (bulletmass*bulletvelocity)+powdermomentum;
var muzzleenergy = (bulletmass/2.0)*Math.pow(bulletvelocity,2.0);
var gunmass = gunweight/32.17;
var recoilvelocity = (gunmass == 0) ? 0 : momentum/gunmass;
var recoilenergy = (gunmass/2.0)*Math.pow(recoilvelocity,2.0);
f2.muzzleenergy.value = RoundTo(muzzleenergy,2);
f2.recoilvelocity.value = RoundTo(recoilvelocity,2);
f2.recoilenergy.value = RoundTo(recoilenergy,2);
}
}
if (err) alert(err);
}







