<!--------------------------------------------------------------------------------
// Copyright 		2000-2001, A. Aten. All rights reserved.
// Name			bbConversion
// Description		Contains all routines needed to fill the Omzettingen form,
//			and calculate the conversion between different units.
// Referenced by		omzettingen.htm
// References		<None>
// Version			1.05
// History
//	Date		Author	Reason
//	---------------	-------	--------------------------------------------------
//	14-Feb-2001	A. Aten	Created
//	30-apr-2003	A. Aten	Changed refernce to form
//--------------------------------------------------------------------------------
  var MeasureArray = new Array;
  var UnitArray = new Array;
  var FactorArray = new Array;
  var OffsetArray = new Array;
  var BaseArray = new Array;

  MeasureArray[0] = "Alcohol";
  BaseArray[0] = 1;
  UnitArray[0] = new Array("gew. %", "vol. %");
  FactorArray[0] = new Array(1.25, 1);
  OffsetArray[0] = new Array(0, 0);

  MeasureArray[1] = "Energie";
  BaseArray[1] = 3;
  UnitArray[1] = new Array("Btu", "cal", "erg", "J", "kcal", "kgm");
  FactorArray[1] = new Array(1055.06, 4.1868, 0.0000001, 1, 4186.8, 9.80665);
  OffsetArray[1] = new Array(0, 0, 0, 0, 0, 0);

  MeasureArray[2] = "Gewicht";
  BaseArray[2] = 0;
  UnitArray[2] = new Array("g", "kg", "mg", "lb UK", "lb US", "ons", "oz UK", "oz US", "pond");
  FactorArray[2] = new Array(1, 1000, 0.001, 453.59, 454, 100, 28.349523, 29.573730, 500);
  OffsetArray[2] = new Array(0, 0, 0, 0, 0, 0, 0, 0, 0);

  MeasureArray[3] = "Hardheid";
  BaseArray[3] = 0;
  UnitArray[3] = new Array("mmol/l", "°D", "°F", "°UK", "°US");
  FactorArray[3] = new Array(1, 0.1783, 0.1, 0.145, 0.01);
  OffsetArray[3] = new Array(0, 0, 0, 0, 0);

  MeasureArray[4] = "Kleur";
  BaseArray[4] = 1;
  UnitArray[4] = new Array("A.S.B.C.", "EBC", "Lovibond");
  FactorArray[4] = new Array(2.65, 1, 2.65);
  OffsetArray[4] = new Array(-1.2, 0, -1.2);

  MeasureArray[5] = "Suiker schalen";
  BaseArray[5] = 2;
  UnitArray[5] = new Array("°Plato", "°Oechsle", "SG (kg/l)", "SG (gr/l)", "Suiker (gr/l)");
  FactorArray[5] = new Array(0.004545, 0.001, 1, 0.001, 0.0003779);
  OffsetArray[5] = new Array(0.9945, 1, 0, 0, 1.0007484);

  MeasureArray[6] = "Temperatuur";
  BaseArray[6] = 0;
  UnitArray[6] = new Array("°C", "°F", "°K");
  FactorArray[6] = new Array(1, 0.5556, 1);
  OffsetArray[6] = new Array(0, -17.7778, -273.15);

  MeasureArray[7] = "Volume";
  BaseArray[7] = 1;
  UnitArray[7] = new Array("hl", "l", "dl", "ml", "fl. oz UK", "fl. oz US", "gallon UK", "gallon US", "pint UK", "pint US", "kop", "el (eetlepel)", "tl (theelepel)");
  FactorArray[7] = new Array(100, 1, 0.1, 0.001, 0.028412, 0.0295735, 4.545960, 3.7854118, 0.55686852, 0.47317648, 0.25, 0.02, 0.005);
  OffsetArray[7] = new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);

function PopulateMeasures() {

    var i;
    var CurrentForm = document.forms['aspnetForm'];
    if (!CurrentForm) {
        CurrentForm = document.aspnetForm;
    }
    
    for (i=0; i < MeasureArray.length; i++) {
        eval("CurrentForm.measure.options[" + i + "]=" + "new Option('" + MeasureArray[i] + "')");
    }
}

function PopulateUnits() {

    var CurrentForm = document.forms['aspnetForm'];
    if (!CurrentForm) {
        CurrentForm = document.aspnetForm;
    }

  while (UnitArray[CurrentForm.measure.selectedIndex].length < CurrentForm.fromunits.options.length) {
    CurrentForm.fromunits.options[(CurrentForm.fromunits.options.length - 1)] = null;
    CurrentForm.tounits.options[(CurrentForm.fromunits.options.length - 1)] = null;
  }
  for (var i=0; i < UnitArray[CurrentForm.measure.selectedIndex].length; i++) {
    eval("CurrentForm.fromunits.options[i]=" + "new Option('" + UnitArray[CurrentForm.measure.selectedIndex][i] + "')");
    eval("CurrentForm.tounits.options[i]=" + "new Option('" + UnitArray[CurrentForm.measure.selectedIndex][i] + "')");
  }
}

function Convert(SelForm) {

  var newValue;
  var BaseIndex;
    var CurrentForm = document.forms['aspnetForm'];
    if (!CurrentForm) {
        CurrentForm = document.aspnetForm;
    }
  var CurrentMeasure = CurrentForm.measure.selectedIndex;
  var FromIndex = CurrentForm.fromunits.selectedIndex;
  var ToIndex = CurrentForm.tounits.selectedIndex;
	
  if (CurrentForm.fromvalue.value == "" || FromIndex == -1 || CurrentForm.tounits.selectedIndex == -1) {
    CurrentForm.tovalue.value = "";
  }
  else {
    if (FromIndex == ToIndex) {
      CurrentForm.tovalue.value = CurrentForm.fromvalue.value;
    } else {
      newValue = CurrentForm.fromvalue.value;
      BaseIndex = BaseArray[CurrentMeasure];
			
      if (FromIndex != BaseIndex) {
        newValue = newValue * FactorArray[CurrentMeasure][FromIndex] + OffsetArray[CurrentMeasure][FromIndex];
      }
      if (ToIndex != BaseIndex) {
        newValue = (newValue  - OffsetArray[CurrentMeasure][ToIndex]) / FactorArray[CurrentMeasure][ToIndex];
      }
      CurrentForm.tovalue.value = newValue;
    }
  }
}

//-->