// ------------------------------------------
// Cyberlight Turbo Beam size and output calculator
// Copyright High End Systems 1999
// Ver 1.0 MWW 11-9-99
// ------------------------------------------


function validate(a)
{
var c
	if(a.value.length == 0) {
		c = 0.0
	} else {
		c=a.value
		if (c.indexOf("m") != -1) c=c.substring(0,c.length-2)
		if (c.indexOf("ft") != -1) c=c.substring(0,c.length-3)
	}
return c
}


function lightingcalculator(form)
{	
  var Units 			// Metric or English Units
  var Throw 			// Throw Distance
  var MinImage 			// Min Image Diameter
  var MaxImageWide 		// Image Diameter Max w Wide Angle Lens
  var MinOut 			// Output at Min
  var LightUnits 		// Temp variable for light units
  var MaxImage 			// Image Diameter Max
  var MaxOutWide 		// Output at Max w Wide Angle Lens
  var MaxOut 			// Output at Max
  var RequiredImage  		// Required Image Size at Mid Zoom
  var LensSystem  		// Normal or Narrow Angle Lens
  var LensMin			// Temp variable for lens at Min Zoom
  var LensMax			// temp variable for lens at Max Zoom
  var NarOutputNar		// Temp variable for output with narrow angle lens, narrow
  var NarOutputWide		// Temp variable for output with narrow angle lens, wide

	Throw=validate(form.Throw) 
	RequiredImage=validate(form.RequiredImage)

	Units = form.Units.options[form.Units.selectedIndex].value
	LensSystem = form.LensSystem.options[form.LensSystem.selectedIndex].value

	if (Units == "m") {
		LightUnits = "lux"
	} else { 
		LightUnits = "fc"
	}

	if (LensSystem == "Normal") {
		LensMin = 1
		LensMax = 1
		NarOutputNar = 1
		NarOutputWide = 1
	} else {
		LensMin = 0.654
		LensMax = 0.568
		NarOutputNar = 1.11
		NarOutputWide = 2.46
	}

	if (Throw != 0 && RequiredImage != 0 ) {
		RequiredImage = 0
	}

	if (Throw ==0 && RequiredImage ==0) {
		Throw = 1 
	}

	MinImage = RequiredImage/1.45

	if (Throw == 0) {
		Throw = 57.3 * MinImage / 11.6 / LensMin
	}

	if (MinImage == 0) {
		MinImage = 11.6 * Throw / 57.3 * LensMin
	}

	RequiredImage = MinImage*1.45
	MaxImageWide = 0.4733 * Throw * LensMax
	MaxImage = 0.389 * Throw * LensMax

	if (Throw != 0){
		MinOut = 907000 / Throw / Throw * NarOutputNar
		MaxOutWide = 178000 / Throw / Throw * NarOutputWide
		MaxOut = 252000 / Throw / Throw * NarOutputWide
	}

	Throw = Math.round(10 * Throw) / 10
	MinImage = Math.round(10 * MinImage) / 10
	RequiredImage = Math.round(10 * RequiredImage) / 10
	MaxImageWide = Math.round(10 * MaxImageWide) / 10
	MaxImage = Math.round(10 * MaxImage) / 10  
	MinOut = Math.round(MinOut)
	MaxOutWide = Math.round(MaxOutWide)
	MaxOut = Math.round(MaxOut)

	form.Throw.value = "" + Throw + " " + Units
	form.RequiredImage.value = "" + RequiredImage + " " + Units 
	form.MinImage.value = "" + MinImage + " " + Units
	form.MaxImageWide.value = "" + MaxImageWide + " " + Units
	form.MinOut.value = "" + MinOut + " " + LightUnits
	form.MaxImage.value = "" + MaxImage + " " + Units
	form.MaxOutWide.value = "" + MaxOutWide + " " + LightUnits
	form.MaxOut.value = "" + MaxOut + " " + LightUnits

}

function clearcalculator(form)
{	
	form.Throw.value = ""
	form.MinImage.value = ""
	form.MaxImageWide.value = ""
	form.MinOut.value = ""
	form.MaxImage.value = ""
	form.MaxOutWide.value = ""
	form.MaxOut.value = ""
	form.RequiredImage.value = ""
}


