var property = new Array();
var unit = new Array();
var factor = new Array();

property[0] = "Kraft";
unit[0] = new Array("Newton (N)", "Dekanewton (daN)", "Kilonewton (kN)","Dyne (dy)", "Kilogramm Kraft (kgf)", "Kilopond (kp)", "Kip (=1.000 lbf)", "Ounce Kraft (ozf)", "Pound Kraft (lbf)", "Poundal", "Joule/cm", "Tonne Kraft (long/UK)", "Tonne Kraft (Short/US)");
factor[0] = new Array(1, 10, 1000, .00001, 9.806650, 9.806650, 4448.2216, .2780139, 4.4482216, .138255, 100, 9964.0164182, 8896.4432305);
 
property[1] = "Druck";
unit[1] = new Array("Bar","Pounds/square inch (psi)","Millibar", "Pascal (Pa) N/m2 ", "Zentimeter Wassersäule (4°C)","Atmosphäre (normal)", "Atmosphäre (techinisch)", "Zentimeter Quecksiber(cmHg)",  "Dezibar", "Kilogramm Kraft/Quadratzentimeter", "Kilogramm Kraft/Quadratmeter", "Kip/square inch", "Millimeter Quecksilber(mmHg)", "Kilopascal (kPa)", "Megapascal (Mpa)", "Poundal/sq.foot", "Pound-force/sq.foot", "Torr (mmHg,0°C)");
factor[1] = new Array(100000, 6894.757, 100, 1, 98.0638, 101325, 98066.5, 1333.22, 10000, 98066.5, 9.80665, 6894757, 133.3224, 1000, 1000000, 47.88026, 47.88026, 133.322);
 
property[2] = "Beschleunigung";
unit[2] = new Array("G (g)", "Meter/Sekunde^2 (m/s^2)", "Foot/sq.sec (ft/s^2)", "Galileo (gal)", "Inch/sq.sec (in/s^2)");
factor[2] = new Array(9.806650, 1, .3048, .01, 2.54E-02);
 
property[3] = "Drehmoment";
unit[3] = new Array("Newton-Meter (N m)", "Dyne-centimeter(dy cm)", "Kilogramm-meter (kgf m)", "lbf-inch (lbf in)", "lbf-foot (lbf ft)");
factor[3] = new Array(1, .0000001, 9.806650, .1129848, 1.355818);
 
property[4] = "Weg";
unit[4] = new Array("Zoll (in)","Millimeter (mm)", "Meter (m)", "Mil", "Angström (A')", "Astronomical unit (AU)", "Caliber (cal)", "Zentimeter (cm)", "Kilometer (km)", "Ell", "Em", "Fathom", "Furlong", "Fermi (fm)", "Foot (ft)", "League (int'l)", "League (UK)", "Light year (LY)", "Meter (m)", "Mikrometer (mu-m)", "Nanometer (nm)", "Mile (int'l nautical)", "Mile (UK nautical)", "Mile (US nautical)", "Mile (US statute)", "Parsec", "Pica (printer)", "Picometer (pm)", "Point (pt)", "Rod", "Yard (yd)");
factor[4] = new Array(.0254, .001, 1, .0000254, 1E-10, 1.49598E11, .000254, .01, 1000, 1.143, 4.2323E-03, 1.8288, 201.168, 1E-15, .3048, 5556, 5556, 9.46055E+15, 1, .000001, 1E-9, 1852, 1853.184, 1852, 1609.344, 3.08374E+16, 4.217518E-03, 1E-12, .0003514598, 5.0292, .9144);
 
property[5] = "Temperatur";
unit[5] = new Array("Grad Celsius (°C)", "Grad Fahrenheit (°F)", "Kelvin (K)", "Grad Rankine (°R)");
factor[5] = new Array(1,  0.555555555555, 1, 0.555555555555);
tempIncrement = new Array(0, -32, -273.15, -491.67);
 
property[6] = "Elektrizität";
unit[6] = new Array("Coulomb (Cb)", "Abcoulomb", "Amperestunde (A hr)", "Faraday (F)", "Statcoulomb", "Millifaraday (mF)", "Microfaraday (mu-F)", "Picofaraday (pF)");
factor[6] = new Array(1, 10, 3600, 96521.8999999997, .000000000333564, 96.5219, 9.65219E-02, 9.65219E-05);
 
property[7] = "Leistung";
unit[7] = new Array("Watt (W)", "Kilowatt (kW)", "Megawatt (MW)", "Milliwatt (mW)", "BTU (SI)/h", "BTU (thermo)/s", "BTU (thermo)/minute", "BTU (thermo)/h", "Kalorie (thermo)/s", "Kalorie (thermo)/min", "Erg/s", "Foot-pound force/h", "Foot-pound force/min", "Foot-pound force/s", "Pferdestärke(550 ft lbf/s)", "Pferdestärke (elektrisch)", "Pferdestärke (boiler)", "Pferdestärke (metrisch)", "Pferdestärke (UK)", "Kilokalorie (thermo)/min", "Kilokalorie (thermo)/s");
factor[7] = new Array(1, 1000, 1000000, .001, .2930667, 1054.35, 17.5725, .2928751, 4.184, 6.973333E-02, .0000001, .0003766161, .02259697, 1.355818, 745.7, 746, 9809.5, 735.499, 745.7, 69.7333, 4184);

property[8] = "Energie";
unit[8] = new Array("Joule (J)","Kalorie (SI) (cal)", "Kalorie (mean)(cal)", "Kalorie (thermo)", "BTU (mean)", "BTU (thermochemical)", "Electron volt (eV)", "Erg (erg)", "Foot-pound force", "Foot-poundal", "Horsepower-hour", "Kilokalorie (SI)(kcal)", "Kilokalorie (mean)(kcal)", "Kilowattstunde (kW hr)", "Tonnen TNT", "Volt-coulomb (V Cb)", "Wattstunde (W hr)", "Wattsekunde (W s)");
factor[8] = new Array(1, 4.1868, 4.19002, 4.184, 1055.87, 1054.35, 1.6021E-19, .0000001, 1.355818, 4.214011E-02, 2684077.3, 4186.8, 4190.02, 3600000, 4.2E9, 1, 3600, 1);
 
property[9] = "Geschwindigkeit";
unit[9] = new Array("Meter/Sekunde (m/s)", "Kilometer/Stunde (km/h)", "Knoten (int'l)", "Mile (US)/hour (mph)", "Mile (nautical)/hour", "Mile (US)/minute", "Mile (US)/second", "Lichtgeschwindigkeit (c)", "Mach (STP)(a)", "Foot/minute (ft/min)", "Foot/second (ft/s)");
factor[9] = new Array(1, .2777778, .5144444, .44707, .514444, 26.8224, 1609.344, 299792458, 340.0068750, 5.08E-03, .3048);
 
property[10] = "Masse";
unit[10] = new Array("Kilogramm (kg)", "Gramm (g)", "Milligramm (mg)", "Mikrogramm (mu-g)", "Carat (metric)(ct)", "Hundredweight (long)", "Hundredweight (short)", "Pound mass (lbm)", "Pound mass (troy)", "Ounce mass (ozm)", "Ounce mass (troy)", "Slug", "Ton (assay)", "Ton (long)", "Ton (short)", "Ton (metric)", "Tonne");
factor[10] = new Array(1, .001, .000001, .000000001, .0002, 50.80235, 45.35924, .4535924, .3732417, .02834952, .03110348, 14.5939, .02916667, 1016.047, 907.1847, 1000, 1000);
 
property[11] = "Masse Fluss";
unit[11] = new Array("Kilogram/Sekunde (kgr/s)", "Pound mass/Sekunde (lbm/s)", "Pound mass/min (lbm/min)");
factor[11] = new Array(1, .4535924, .007559873);
 
property[12] = "Dichte & Masse capazität";
unit[12] = new Array("Kilogramm/Kubikmeter", "Grain/galon", "Gramm/Kubikzentimeter (g/cm^3)", "Pound mass/cubic foot", "Pound mass/cubic-inch", "Ounces/gallon (UK,liq)", "Ounces/gallon (US,liq)", "Ounces (mass)/inch", "Pound mass/gal (UK,liq)", "Pound mass/gal (US,liq)", "Slug/cubic foot", "Tons (long,mass)/cub.yard");
factor[12] = new Array(1, .01711806, 1000, 16.01846, 27679.91, 6.236027, 7.489152, 1729.994, 99.77644, 119.8264, 515.379, 1328.939);
 
property[13] = "Licht";
unit[13] = new Array("Lumen/Quadratmeter (Lu/m^2)", "Lumen/Quadratzentimeter", "Lumen/sq.foot", "Foot-candle (ft-cdl)", "Foot-lambert", "Candela/Quadratmeter", "Candela/Quadratzentimeter", "Lux (lux)", "Phot");
factor[13] = new Array(1, 10000, 10.76391, 10.76391, 10.76391, 3.14159250538575, 31415.9250538576, 1, 10000);
 
property[14] = "Fläche";
unit[14] = new Array("Quadratmeter (m^2)", "Acre (acre)", "Are", "Barn (barn)", "Hektar", "Rood", "Quadratzentimeter", "Quadratkilometer", "Circular mil", "Square foot (ft^2)", "Square inch (in^2)", "Square mile (mi^2)", "Square yard (yd^2)");
factor[14] = new Array(1, 4046.856, 100, 1E-28, 10000, 1011.71413184285, .0001, 1000000, 5.067075E-10, 9.290304E-02, 6.4516E-04, 2589988, .8361274);
 
property[15] = "Zeit";
unit[15] = new Array("Sekunde (s)", "Tag (mean solar)", "Tag (sidereal)", "Stunde (mean solar)", "Stunde (sidereal)", "Minute (mean solar)", "Minute (sidereal)", "Monat (mean calendar)", "Sekunde (sidereal)", "Jahr (Kalender)", "Jahr (tropisch)", "Jahr (sidereal)");
factor[15] = new Array(1, 8.640E4, 86164.09, 3600, 3590.17, 60, 60, 2628000, .9972696, 31536000, 31556930, 31558150);
 
property[16] = "Kraft / Länge";
unit[16] = new Array("Newton/Meter (N/m)", "Pound force/inch (lbf/in)", "Pound force/foot (lbf/ft)");
factor[16] = new Array(1, 175.1268, 14.5939);
 
property[17] = "Viscosität";
unit[17] = new Array("Newton-Sekunde/Meter", "Centipoise", "Centistoke", "Sq.foot/second", "Poise", "Poundal-second/sq.foot", "Pound mass/foot-second", "Pound force-second/sq.foot", "Rhe", "Slug/foot-second", "Stoke");
factor[17] = new Array(1, .001, .000001, 9.290304E-02, .1, 1.488164, 1.488164, 47.88026, 10, 47.88026, .0001);
 
property[18] = "Volumen";
unit[18] = new Array("Kubikmeter (m^3)", "Kubikzentimeter (cm^3)", "Kubikmillimeter (mm^3)", "Acre-foot", "Barrel (oil)", "Board foot", "Bushel (US)", "Cup", "Fluid ounce (US)", "Cubic foot", "Gallon (UK)", "Gallon (US,dry)", "Gallon (US,liq)", "Gill (UK)", "Gill (US)", "Cubic inch (in^3)", "Liter (new)", "Liter (old)", "Ounce (UK,fluid)", "Ounce (US,fluid)", "Peck (US)", "Pint (US,dry)", "Pint (US,liq)", "Quart (US,dry)", "Quart (US,liq)", "Stere", "Tablespoon", "Teaspoon", "Ton (register)", "Cubic yard");
factor[18] = new Array(1, .000001, .000000001, 1233.482, .1589873, .002359737, .03523907, .0002365882, .00002957353, .02831685, .004546087, .004404884, .003785412, .0001420652, .0001182941, .00001638706, .001, .001000028, .00002841305, .00002957353, 8.8097680E-03, .0005506105, 4.7317650E-04, .001101221, 9.46353E-04, 1, .00001478676, .000004928922, 2.831685, .7645549);
 
property[19] = "Volumen Fluss";
unit[19] = new Array("Kubikmeter/second (m^3/s)", "Cubic foot/second", "Cubic foot/minute", "Cubic inches/minute", "Gallons (US,liq)/minute)");
factor[19] = new Array(1, .02831685, .0004719474, 2.731177E-7, 6.309020E-05);
 
property[20] = "Währung";
unit[20] = new Array("Euro (Euroland)", "DEM (Deutschland)", "FRF (Frankreich)", "NLG (Niederlande)", "BEF (Belgien)", "ESP (Spanien)", "IEP (Irland)", "ITL (Italien)", "LUF (Luxemburg)", "ATS (Österreich)", "PTE (Portugal)", "FIM (Finnland)", "GRD (Griechenland)");
factor[20] = new Array(1, 1/1.95583, 1/6.55957, 1/2.20371, 1/40.3399, 1/166.386, 1/0.787564, 1/1936.27, 1/40.3399, 1/13.7603, 1/200.482, 1/5.9457300, 1/340.75);

// *** Functions *************************************************************

function UpdateUnitMenu(propMenu, unitMenus){
	var i;
	i = propMenu.selectedIndex;
	FillMenuWithArray(unitMenus, unit[i]);
	CalculateUnit(document.form_A, document.form_B);
}

function SetMenu(){
	document.form_A.unit_menu.selectedIndex=1;
	document.form_A.unit_menu.selectedIndex=0;
	document.form_B.unit_menu.selectedIndex=2;
	document.form_B.unit_menu.selectedIndex=1;
//	nur so habe ich Netscape7 begebracht die Einheiten zu aktualisieren!
}
function SwitchMenu(){
	var IndexA=document.form_A.unit_menu.selectedIndex;
	var IndexB=document.form_B.unit_menu.selectedIndex;
	document.form_A.unit_menu.selectedIndex=IndexA;//wegen Netscape notwendig
	document.form_A.unit_menu.selectedIndex=IndexB;
	document.form_B.unit_menu.selectedIndex=IndexB;//wegen Netscape notwendig
	document.form_B.unit_menu.selectedIndex=IndexA;
	CalculateUnit(document.form_A, document.form_B);
}

function DefaultValue(){
	FillMenuWithArray(document.property_form.the_menu, property);

	if (document.property_form.the_menu.selectedIndex == 0){
		if (document.images){
			FillMenuWithArray(document.form_A.unit_menu, unit[0]);
			FillMenuWithArray(document.form_B.unit_menu, unit[0]);
		} else {
			alert("Browser unterstützt diese Anwendung nicht");
		}
	}

	document.form_A.unit_input.value = 1;
	CalculateUnit(document.form_A, document.form_B);
}

function CalculateUnit(sourceForm, targetForm){
//alert(sourceForm.unit_input.value.indexOf('.') + "ee" + sourceForm.unit_input.value.length);
	if (sourceForm.unit_input.value == "-" || sourceForm.unit_input.value.indexOf('.') + 1 == sourceForm.unit_input.value.length || sourceForm.unit_input.value.indexOf(',') +1 == sourceForm.unit_input.value.length ){
	} else {
		var sourceValue = UpdatePoint(sourceForm.unit_input.value);
		sourceForm.unit_input.value = sourceValue;
		if ( !isNaN(sourceValue) || sourceValue == 0){
			Convert(sourceForm, targetForm);
		} 
	} 
}

function FillMenuWithArray(myMenu, myArray){
	var inc;
	myMenu.length = myArray.length;
	for(inc = 0; inc < myArray.length; inc++){
		myMenu.options[inc].text = myArray[inc];
	}
}

function Convert(sourceForm, targetForm){
	var propIndex;
	var sourceIndex;
	var sourceFactor;
	var targetIndex;
	var targetFactor;
	var result;

	propIndex = document.property_form.the_menu.selectedIndex;
	sourceIndex = sourceForm.unit_menu.selectedIndex;
	sourceFactor = factor[propIndex][sourceIndex];
	targetIndex = targetForm.unit_menu.selectedIndex;
	targetFactor = factor[propIndex][targetIndex];
	result = (sourceForm.unit_input.value).split(',').join('.');
	if (property[propIndex] == "Temperatur"){
		result = parseFloat(result) + tempIncrement[sourceIndex];
	}
	result = result * sourceFactor;
	result = result / targetFactor;
	if (property[propIndex] == "Temperatur"){
		result = parseFloat(result) - tempIncrement[targetIndex];
	}
// ************O U T P U T **************************
	targetForm.unit_input.value = OutputResult(result);
// ************O U T P U T **************************
}

function UpdatePoint(input){
	var PointInput = input.split(',').join('.');
	return parseFloat(PointInput);
}

function OutputResult(input) {
	var OutputString;

	switch (document.form_C.Rundungstyp.value)
	{
	case "Sig":
		OutputString=parseFloat(SignificantPlaces(input));
		break    
	case "Dez":
		OutputString=parseFloat(DecimalPlaces(input));
		break
	case "SigDez":
		OutputString=parseFloat(SignificantDecimalPlaces(input));
		break
	case "KeineRundung":
		OutputString=parseFloat(input);
		break
	default:
		OutputString=parseFloat(SignificantDecimalPlaces(input));
	}
	return parseFloat(OutputString);
}

function ResetForm(){
	document.form_A.unit_input.value = 1;
	document.form_C.kommastellen.value = 3;
	document.form_C.Rundungstyp.selectedIndex = 2;
	DefaultValue()
}

