var ps;

function rows(doc) {
ps = new params 
(
doc,    // Name(LEAVE ALONE), label, desc
new param("Sensor","CCD Size-H",	"SENSOR SIZE and FORMAT are essentially the same thing. For most video cameras the sensor is one of four standard sizes. Your operation manual should list the size of sensor your camera has. If your sensor has a non-standard size, you can manually enter the height of the sensor, the software will calculate the width based on the Standard Width to Height ratio of 4:3"),

new param("FOV","FOV-H",	"The Field Of View is further defined in this calculator as the Horizontal image width the lens sees. Be aware that the Vertical FOV is usually less than horizontal for standard TV type (ie., RS-170/NTSC) type cameras. The ratio of FOV width/height is called Aspect Ratio. For standard cameras, its 4:3, the same aspect as our television set. Non standard video cameras such as megapixel can have other aspect ratios such as 1:1 which is a square sensor format."),

new param("Mag","MAG",	"Ratio of Sensor Size to Object Size. As long as the object is bigger than the sensor, the magnification will be less than one."),

new param("WD","Working Distance",		"Working distance is the approximate distance from the lens to the subject. The accuracy of the calculation will vary with lens type and manufacturer. This measurement is a useful guide, but allowances must be made for individual lenses. Typically, the error will not exceed about half the physical length of the lens, and is usually only a problem when working close to a subject."),

new param("Standoff","Flange Distance",	"FLANGE DISTANCE or Standoff is the distance from the camera mount to the object.  The flange is where the lens meets the camera when it they are together. This measurement will be accurate to +/- 50 mm depending on the lens. This error is only significant for close working distances (less than one or two feet). If the principle point separation is known for a given lens, it can be added to make the calculation exact. This number is exact for C mount lenses only."),

new param("Ext","Ext. Tube",	"For close working distances or magnifications approaching 1 and larger, the lens must be extended from the flange using an extension tube. Most lenses have the ability to adjust focus, which is essentially a variable extension tube with limited range. This measure is an indication of a good starting place for an extension tube length in high magnification cases. Usually, the lens focus adjustment can be used for fine tuning."),

new param("FL","Focal Length",		"The Focal Length of a lens determines image size, and the angle that the camera will see.  For typical C mount applications, the range is approximately 3 mm to 75 mm. Longer focal lengths are available, but uncommon. The shorter a focal length is, typically the higher the geometric distortion. Lens are available in specific, fixed focal lengths, some adjustment may be necessary in order to find a lens that works with your application. Zoom and Variable Focal Length lenses are available which can be set to the exact focal length called for, however this comes at an increased cost, and frequently increased geometric distortion and / or aberration.  See our section on lenses for more information."),

new param("DOF","Depth of Field",	"Depth-of-field tells you how much of your object will be in focus. Depth of field is a function of the f# of the lens, the higher the f#, the larger the Depth of Field.  It should be noted that as the f# increases in a system, the resolution decreases. There comes a point where increasing the depth of field will diminish the resolution.  This condition is uncommon in most video applications, but can be a serious limitation in high resolution applications.  Depth of Field relies on the user to select a circle-of-confusion, basically the diameter that represents the smallest resolvable object, which is inputted as RES in this program."),

new param("FStop","F/#",	"The F/# or F-stop is commonly indicated by the notation f#, and is mathematically the ration between the focal length of a lens and the diameter of the lens, and indicates the light gathering ability of a lens. It is very uncommon for an f# to be lower than .95, or greater than 32. A common way to notate the f# of a lens is to show it like this: f/8, where 8 is the f#.  As the f# gets larger, resolution decreases, and dept of field increases, as it gets smaller aberrations tend to increase, as does image brightness.. Most lenses have optimal correction around f# 8. when looking at a lens the notation 1:XX/YY indicates that the lowest f# is XX, and the focal length is YY.   F#, being a ratio of like terms, has no units."),

new param("Res","Resolution",	"RESOLUTION is the smallest feature that can be detected by a camera / lens system. Typically, use .020 mm for a 1/3\\\" and 1/2\\\" sensor. Use .030mm for 2/3\\\" sensor and .040 for a 1\\\" sensor.  These resolutions are based on the assumed Circle Of Confusion. There is a theoretical limit to the resolving power of an optical system using visible light, generally accepted as 0.002 mm."),
-1);
}

var forms;

function setup() {
with(this.document.form){
forms = new formulas 
(
new formula(function f(){return this.b.v/this.a.v;},
	function err(){return  (this.a.v == "0"); },
	"FOV cannot equal 0",
	Mag, 	FOV, Sensor),		// Mag = Sensor/FOV
new formula(function f(){return this.b.v/this.a.v;},
	function err(){return  (this.a.v == "0"); },
	"Mag cannot equal 0",
	FOV, 	Mag, Sensor),		//  FOV = Sensor/Mag
new formula(function f(){return ((1/this.a.v)+1)*this.b.v;},
	function err(){return  (this.a.v == 0); },
	"Mag cannot equal 0",
	WD, 	Mag, FL),	// WD = (1+1/Mag)*FL
new formula(function f(){return this.a.v/((1/this.b.v)+1);},
	function err(){return  (this.b.v == 0); },
	"Mag cannot equal 0",
	FL, 	WD, Mag),	// FL = WD/(1/Mag+1)
new formula(function f(){return this.a.v/(this.b.v-this.a.v);},
	function err(){return  (this.a.v == this.b.v); },
	"FL cannot equal WD",
	Mag, 	FL, WD),	// Mag = FL / (WD-FL)
new formula(function f(){return 1.0*this.a.v+1.0*this.b.v;},
	function err(){return  (false); },
	"",
	Standoff, FL, WD),	// Standoff = FL + WD

new formula(function f(){return 1.0*this.a.v-1.0*this.b.v;},
	function err(){return  (false); },
	"",
	FL, 	Standoff, WD),	// FL = Standoff - WD
new formula(function f(){return 1.0*this.a.v-1.0*this.b.v;},
	function err(){return  (false); },
	"",
	WD, 	Standoff, FL),	// WD = Standoff - FL
new formula(function f(){return this.a.v*this.b.v;},
	function err(){return  (false); },
	"",
	Ext, 	FL, Mag), 	// Ext=FL*Mag
new formula(function f(){return this.a.v/this.b.v;},
	function err(){return  (this.b.v == 0); },
	"Mag cannot equal 0",
	FL, 	Ext, Mag),
new formula(function f(){return this.a.v/this.b.v;},
	function err(){return  (this.b.v == 0); },
	"FL cannot equal 0",
	Mag, 	Ext, FL),

new formula(function f(){return 2*this.a.v*this.b.v*(1+this.c.v)
	/(this.c.v*this.c.v);},
	function err(){return  (this.c.v == 0); },
	"Mag cannot equal 0",
	DOF, 	FStop, Res, Mag),
new formula(function f(){return this.a.v*
	(this.c.v*this.c.v)/(2*this.b.v*(1+this.c.v));},
	function err(){return  (this.c.v == -1); },
	"Mag cannot equal -1",
	FStop, 	DOF, Res, Mag),
new formula(function f(){return this.a.v*
	(this.c.v*this.c.v)/(2*this.b.v*(1+this.c.v));},
	function err(){return  (this.c.v == -1); },
	"Mag cannot equal -1",
	Res, 	DOF, FStop, Mag),
new formula(function f(){return this.b.v*this.a.v;},
	function err(){return  (false); },
	"",
	Sensor, 	Mag, FOV),		//  Sensor = FOV*Mag
//new formula(function f(){return this.a.v*
//	(this.c.v*this.c.v)/(2*this.b.v*(1+this.c.v));},
//	Res, 	DOF, FStop, Mag),
// M = (-FR+-sqrt(FR(FR+D)))    / D
-1);
}}



function calculate() {
	if(ps.validate()) 
		forms.calc();
}

