var propriedade = new Array();
var unidade = new Array();
var fator = new Array();

propriedade[0] = "Aceleraçao";
unidade[0] = new Array("m/seg2", "pé/seg2", "g", "Galileo", "pol/seg2");
fator[0] = new Array(1, .3048, 9.806650, .01, 2.54E-02);

propriedade[1] = "Área";
unidade[1] = new Array("m2", "Acre", "Are", "Barn", "Hectare", "Rood", "cm2", "km2", "Milha Circular", "Pé2", "Pol2", "Milha2", "Jarda2");
fator[1] = new Array(1, 4046.856, 100, 1E-28, 10000, 1011.71413184285, .0001, 1000000, 5.067075E-10, 9.290304E-02, 6.4516E-04, 2589988, .8361274);

propriedade[2] = "Torque";
unidade[2] = new Array("N.m", "dy.cm", "kgf.m", "lbf.pol", "lbf.pé");
fator[2] = new Array(1, .0000001, 9.806650, .1129848, 1.355818);

propriedade[3] = "Carga elétrica";
unidade[3] = new Array("Coulomb", "Abcoulomb", "A.hr", "Faraday", "Statcoulomb", "Millifaraday", "Microfaraday", "Picofaraday");
fator[3] = new Array(1, 10, 3600, 96521.8999999997, .000000000333564, 96.5219, 9.65219E-02, 9.65219E-05);

propriedade[4] = "Energia";
unidade[4] = new Array("Joule", "BTU(meio)", "BTU(termoquimico)", "Caloria", "Caloria (meio)(cal)", "Caloria (termo)", "Eletro volt (eV)", "Erg", "Pé-libra força", "Pé-poundal", "Horsepower-hora", "Kilocaloria", "Kilocaloria(meio)(kcal)", "Kilowatt-hora", "Ton de TNT", "Volt-coulomb", "Watt-hora", "Watt-segundo");
fator[4] = new Array(1, 1055.87, 1054.35, 4.1868, 4.19002, 4.184, 1.6021E-19, .0000001, 1.355818, 4.214011E-02, 2684077.3, 4186.8, 4190.02, 3600000, 4.2E9, 1, 3600, 1);

propriedade[5] = "Força";
unidade[5] = new Array("Newton", "Dyna", "Kgf", "Kilolibra força (kpf)", "Kip (k)", "Onça força (ozf)", "Libra força (lbf)", "Poundal");
fator[5] = new Array(1, .00001, 9.806650, 9.806650, 4448.222, .2780139, .4535924, .138255);

propriedade[6] = "Força / comprimento";
unidade[6] = new Array("Newton/metro", "Libra força/pol (lbf/pol)", "Libra força/pé (lbf/pé)");
fator[6] = new Array(1, 175.1268, 14.5939);

propriedade[7] = "Comprimento";
unidade[7] = new Array("Metro", "Angstrom", "Unidade Astronomica (AU)", "Caliber (cal)", "Cm", "Km", "Ell", "Em", "Fathom", "Furlong", "Fermi (fm)", "Pé (pé)", "Polegada(pol)", "Légua (int'l)", "Légua (UK)", "Ano Luz (AL)", "Micrometro (mu-m)", "Mil", "Milimetro (mm)", "Nanometro (nm)", "Milha (int'l nautica)", "Milha (UK nautica)", "Milha (US nautica)", "Milha (US statute)", "Parsec", "Pica (printer)", "Picometro (pm)", "Ponto (pt)", "Rod", "Jarda");
fator[7] = new Array(1, 1E-10, 1.49598E11, .000254, .01, 1000, 1.143, 4.2323E-03, 1.8288, 201.168, 1E-15, .3048, .0254, 5556, 5556, 9.46055E+15, .000001, .0000254, .001, 1E-9, 1852, 1853.184, 1852, 1609.344, 3.08374E+16, 4.217518E-03, 1E-12, .0003514598, 5.0292, .9144);

propriedade[8] = "Iluminaçao";
unidade[8] = new Array("Lumen/m2", "Lumen/cm2", "Lumen/pé2", "Pé-vela (pé-cdl)", "Pé-lambert", "Candela/m2", "Candela/cm2", "Lux (lux)", "Phot");
fator[8] = new Array(1, 10000, 10.76391, 10.76391, 10.76391, 3.14159250538575, 31415.9250538576, 1, 10000);

propriedade[9] = "Massa";
unidade[9] = new Array("Kilograma(kg)", "Grama(g)", "Miligrama (mgr)", "Micrograma (mu-gr)", "Carat (metrico)(ct)", "Hundredweight (long)", "Hundredweight (short)", "Libra massa (lbm)", "Libra massa (troy)", "Onça massa (ozm)", "Onça massa (troy)", "Slug", "Ton (assay)", "Ton (long)", "Ton (short)", "Ton (metrica)", "Tonelada");
fator[9] = new Array(1, .001, 1e-6, .000000001, .0002, 50.80235, 45.35924, .4535924, .3732417, .02834952, .03110348, 14.5939, .02916667, 1016.047, 907.1847, 1000, 1000);

propriedade[10] = "Fluxo (massa)";
unidade[10] = new Array("kg/s", "Libra/seg(lbm/seg)", "Libra/min (lbm/min)");
fator[10] = new Array(1, .4535924, .007559873);

propriedade[11] = "Densidade e capacidade";
unidade[11] = new Array("Kg/m3", "Grao/galao", "g/cm3 (gr/cc)", "Libra massa/pé3", "Libra massa/pol3", "Onças/galao (UK,liq)", "Onças/galao (US,liq)", "Onças (massa)/pol", "Libra/gal(UK,liq)", "Libra/gal (US,liq)", "Slug/pé3", "Tons(long,massa)/jarda3");
fator[11] = new Array(1, .01711806, 1000, 16.01846, 27679.91, 6.236027, 7.489152, 1729.994, 99.77644, 119.8264, 515.379, 1328.939);

propriedade[12] = "Potencia";
unidade[12] = new Array("Watt (W)", "Kilowatt (kW)", "Megawatt (MW)", "Miliwatt (mW)", "BTU (SI)/hora", "BTU (termo)/segundo", "BTU (termo)/minuto", "BTU (termo)/hora", "Caloria(termo)/s", "Caloria(termo)/min", "Erg/segundo", "Pé-libra força/h", "Pé-libra força/min", "Pé-libra força/seg", "HP(550ft.lbf/s)", "HP(eletrico)", "HP(caldeira)", "HP(metrico)", "HP(UK)", "Kcal(termo)/min", "Kcal(termo)/s");
fator[12] = 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);

propriedade[13] = "Pressao e Tensao";
unidade[13] = new Array("Newton/m2", "Atm(normal)", "Atm(tecnica)", "Bar", "cmHg", "Centimetro de Água (4'C)", "Decibar", "Kgf/cm3", "Kgf/m2", "Kip/pol2", "Milibar", "Torr(mmHg)", "Pascal(Pa)", "kPa", "Mpa", "Libraal/pé2", "Libra-força/pé2", "psi", "Torr (mmHg,0'C)");
fator[13] = new Array(1, 101325, 98066.5, 100000, 1333.22, 98.0638, 10000, 98066.5, 9.80665, 6894757, 100, 133.3224, 1, 1000, 1000000, 47.88026, 47.88026, 6894.757, 133.322);

propriedade[14] = "Temperatura";
unidade[14] = new Array("Celsius", "Fahrenheit", "Kelvin", "Rankine");
fator[14] = new Array(1,  0.555555555555, 1, 0.555555555555);
tempIncrement = new Array(0, -32, -273.15, -491.67);

propriedade[15] = "Tempo";
unidade[15] = new Array("Segundo", "Dia", "Dia(sideral)", "Horas (médio solar)", "Horas (sidereal)", "Minutos (médio solar)", "Minutos (sidereal)", "Mes (Médio calendario)", "Segundos (sidereal)", "Anos (calendario)", "Anos (tropical)", "Anos (sidereal)");
fator[15] = new Array(1, 8.640E4, 86164.09, 3600, 3590.17, 60, 60, 2628000, .9972696, 31536000, 31556930, 31558150);

propriedade[16] = "Velocidade";
unidade[16] = new Array("m/s", "pé/min", "pé/s", "Km/h", "No (int'l)", "Milha/h", "Milha/h(nautica)", "Milha/min", "Milha/s", "vel. luz (c)", "Mach (STP)(a)");
fator[16] = new Array(1, 5.08E-03, .3048, .2777778, .5144444, .44707, .514444, 26.8224, 1609.344, 299792458, 340.0068750);

propriedade[17] = "Viscosidade";
unidade[17] = new Array("N.s/m", "Centipoise", "Centistoke", "pé2/segundo", "Poise", "Libraal-segundo/pé2", "Libramassa/pé-seg", "Libra força-seg/pé2", "Rhe", "Slug/pé-segundo", "Stoke");
fator[17] = new Array(1, .001, .000001, 9.290304E-02, .1, 1.488164, 1.488164, 47.88026, 10, 47.88026, .0001);

propriedade[18] = "Volume & Capacidade";
unidade[18] = new Array("m3", "cm3", "mm3", "Acre-pé", "Barril(óleo)", "Board pé", "Bushel (US)", "Copo", "Onça fluída (US)", "Pé3", "Galao (UK)", "Galao (US,seco)", "Galao (US,liq)", "Gill (UK)", "Gill (US)", "Polegada cúbica (pol3)", "Litro", "ml", "Onça (UK,fluida)", "Onça (US,fluida)", "Peck (US)", "Pint (US,seco)", "Pint (US,liq)", "Quarto (US,seco)", "Quarto (US,liq)", "Stere", "Colher de sopa", "Colher de chá", "Ton (registro)", "Jarda cúbic");
fator[18] = new Array(1, .000001, .000000001, 1233.482, .1589873, .002359737, .03523907, .0002365882, .00002957353, .02831685, .004546087, .004404884, .003785412, .0001420652, .0001182941, .00001638706, .001, .0000010, .00002841305, .00002957353, 8.8097680E-03, .0005506105, 4.7317650E-04, .001101221, 9.46353E-04, 1, .00001478676, .000004928922, 2.831685, .7645549);

propriedade[19] = "Fluxo (volume)";
unidade[19] = new Array("m3/s", "pés3/s", "pés3/min", "pol3/min", "Galoes (US,liq)/minuto)");
fator[19] = new Array(1, .02831685, .0004719474, 2.731177E-7, 6.309020E-05);



function UpdateUnitMenu(propMenu, unitMenu)
   {
	var i;
	i = propMenu.selectedIndex;
	FillMenuWithArray(unitMenu, unidade[i]);	
   }

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

function CalculateUnit(sourceForm, targetForm, sourceFormS, targetFormS)
 {
	var sourceValue = sourceForm.unit_input.value;
	
	sourceValue = parseFloat(sourceValue);
	if ( !isNaN(sourceValue) || sourceValue == 0)
	  {
		sourceForm.unit_input.value = sourceValue;
		ConvertFromTo(sourceForm, targetForm, sourceFormS, targetFormS);
	  } 
	
 }

function ConvertFromTo(sourceForm, targetForm, sourceFormS, targetFormS)
 {
	var propIndex;
	var sourceIndex;
	var sourcefator;
	var targetIndex;
	var targetfator;
	var result;

	propIndex = document.propriedade_form.the_menu.selectedIndex;
	sourceIndex = sourceFormS.unit_menu.selectedIndex;
	sourcefator = fator[propIndex][sourceIndex];
	targetIndex = targetFormS.unit_menu.selectedIndex;
	targetfator = fator[propIndex][targetIndex];
	result = sourceForm.unit_input.value;

	if (propriedade[propIndex] == "Temperatura")
	{
		result = parseFloat(result) + tempIncrement[sourceIndex];
	}

	result = result * sourcefator;
	result = result / targetfator;

	if (propriedade[propIndex] == "Temperatura")
	{
		result = parseFloat(result) - tempIncrement[targetIndex];
	}

	targetForm.unit_input.value = result;
 }

function Limpar()
   {
	document.Entrada.unit_input.value = "";
	document.Saida.unit_input.value = "";
   }