// JavaScript Document

// origineel Brian Chandler 2001
// http://www.imaginatorium.org/stuff/angle.htm


function set35mm(form) {
// if f set .... calculate else clear
form.w.value = 36;
form.h.value = 24;
};

function set16mm(form) {
// if f set .... calculate else clear
form.w.value = 22.2;
form.h.value = 14.8;
};

function set13mm(form) {
// if f set .... calculate else clear
form.w.value = 28.1;
form.h.value = 18.7;
};

function cropfactor (rnum) {
	var rlength = 1; // The number of decimal places to round to
	if (rnum > 8191 && rnum < 10485) {
		rnum = rnum-5000;
		var newnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength);
		newnumber = newnumber+5000;
	} else {
		var newnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength);
	}
	return newnumber;
}

function arcdeg(x, f) {	// find arctan(x/2f) in degrees (string)
var deg = Math.atan(x/(2*f)) * 360 / Math.PI;
return " " + String(Math.floor(deg)) + String.fromCharCode(176) + " " + String(Math.round((deg*60)%60)) + "'";
}

function angle(form) {
form.c.value = '';

// ****** NO CHECKS YET!!!!!!!!!!!!!

var f, w, h, d;
f = Number(form.f.value);
w = Number(form.w.value);
h = Number(form.h.value);
d = Math.round(Math.sqrt(w*w + h*h) * 100)/100;
c = cropfactor(36/w);

form.d.value = d;
if(!form.c.value) form.c.value = c;

form.wdeg.value = arcdeg(w, f);
form.hdeg.value = arcdeg(h, f);
form.ddeg.value = arcdeg(d, f);
form.fdist.value = c * f;

} // end function

	// regel van 600 voor foto zonder sterrensporen
	function calc_exp_time(form) {
		
		var cropf, focalr, expt, maxt;
		
		form.expt.value = '';
		cropf = Number(form.cropf.value);
		focalr = Number(form.focalr.value);
		
		maxt = Math.round(600 / (cropf * focalr));
				
		form.expt.value = maxt;
	}
