/*
Webcam Calculator v1.0JavaScript and DHTMLcopyright (c) Adrian R. Ashford, 22nd November 2007.*/
function round_fifth(num){ return Math.floor(num / 5 + 0.5) * 5;}

function round_10(num){ return Math.floor((num + 0.05) * 10) / 10;}function round_100(num){ return Math.floor((num + 0.005) * 100) / 100;}function round_1000(num){ return Math.floor((num + 0.0005) * 1000) / 1000;}function neximage_calc(){with (Math){var aperture = parseFloat(document.scope.aperture.value);
if(isNaN(aperture)){ alert("Please enter a valid figure for the telescope's aperture.");
 return;}
document.scope.aperture.value = aperture;

var inch_or_mm = document.scope.metric.value;
aperture = aperture * inch_or_mm;
var focal_ratio = parseFloat(document.scope.focalratio.value);
if(isNaN(focal_ratio)){ alert("Please enter a valid figure for the telescope's focal ratio.");
 return;}
document.scope.focalratio.value = focal_ratio;

var barlow_factor = parseFloat(document.scope.barlowlens.value);
var focal_reducer = parseFloat(document.scope.focalreducer.value);
var focal_length = aperture * focal_ratio * barlow_factor * focal_reducer;var focal_ratio = round_10(focal_length / aperture);
var field_width = atan(1.8452 / focal_length) * 180 / PI * 2;
var field_height = atan(1.3832 / focal_length) * 180 / PI * 2;
var arcsec_per_pixel = 0.0056 / focal_length * 180 / PI * 3600;
var scope_resolution = 115.824 / aperture;
var amplification = 2 * arcsec_per_pixel / scope_resolution;

if (barlow_factor != 1 && focal_reducer != 1)
{
 alert("Are you sure that you wish to use a focal reducer and a Barlow lens together?");
}var scope_info = "Focal Length:  " + round_fifth(focal_length) + "mm   ";

if (focal_reducer != 1.0)
{
 scope_info += "(You are using a " + focal_reducer + " x focal reducer)   ";
}

if (barlow_factor != 1.0)
{
 scope_info += "(You are using a " + barlow_factor + " x Barlow lens)";
}

scope_info += "\nWidth of Field: ";

if (field_width < 1)
{
 scope_info += round_10(field_width * 60) + "'   ";
}
else
{
 scope_info += round_100(field_width) + "\u00B0   ";
}

if (field_width >= 3.5 && field_width < 7){ scope_info += "(Orion's Belt could easily fit into the field of view)";}

if (field_width >= 2.8 && field_width < 3.5){ scope_info += "(Orion's Belt would fit snuggly into the field of view)";}

if (field_width >= 1.5 && field_width < 2.8){ scope_info += "(The Pleiades would easily fit into the field of view)";}

if (field_width >= 1.0 && field_width < 1.5){ scope_info += "(The Pleiades could fit snuggly into the field of view)";}
if (field_width >= 0.6 && field_width < 1.0){ scope_info += "(The full Moon would easily fit into the field of view)";}if (field_width >= 0.50 && field_width < 0.6){ scope_info += "(The full Moon could just fit within the field of view)";}if (field_width >= 0.35 && field_width < 0.5){ scope_info += "(The full Moon would not quite fit into the field of view)";}if (field_width >= 0.25 && field_width < 0.35){ scope_info += "(About half of the full Moon's disc would fit into the field of view)";}if (field_width >= 0.125 && field_width < 0.25){ scope_info += "(Less than half of the full Moon's disc would fit into the field of view)";}

if (field_width >= 0.0625 && field_width < 0.125){ scope_info += "(Less than a quarter of the full Moon's disc would fit into the field of view)";}

if (field_width < 0.0625){ scope_info += "(Large lunar craters, Jupiter or Saturn will dominate the field of view)";}

scope_info += "\nHeight of Field: ";

if (field_height < 1)
{
 scope_info += round_10(field_height * 60) + "'";
}
else
{
 scope_info += round_100(field_height) + "\u00B0";
}

scope_info += "\nCCD Chip Resolution: " + round_10(arcsec_per_pixel) + " arcseconds/pixel";

scope_info += "   (Telescope Resolving Power: " + round_10(scope_resolution) + " arcseconds)";

if (amplification > 1 && barlow_factor == 1 && focal_reducer == 1)
{
 scope_info += "\n(Note: for optimum results on the Moon and planets, try amplifying\n the focal length by using at least a " + round_10(amplification) + " x Barlow lens)";
}
document.scope.result.value = scope_info;}}