function round(number,X) {
	X = (!X ? 2 : X);
	return Math.round(number*Math.pow(10,X))/Math.pow(10,X);
}

function UpdateTemperature(input) {
	var Degre=input.value*1;
	var Type=input.name;
	
	if (Type == "Celcius") {
		C=Degre;
		F=round(((9/5)*C)+32);
		K=round((Degre+273.15));
		R=round(K*1.8);
	} else if (Type == "Fahrenheit") {
		F=Degre;
		C=round((F-32)*(5/9));
		K=round(C+273.15);
		R=round(K*1.8);
	} else if (Type == "Kelvin") {
		K=Degre;
		C=round(K-273.15);
		F=round(((9/5)*C)+32);
		R=round(K*1.8);
	} else if (Type == "Rankine") {
		R=Degre;
		K=round(R/1.8);
		C=round(K-273.15);
		F=round(((9/5)*C)+32);
	}
	if (Type != "Celcius") { document.Temperatures.Celcius.value=C; }
	if (Type != "Fahrenheit") { document.Temperatures.Fahrenheit.value=F; }
	if (Type != "Kelvin") { document.Temperatures.Kelvin.value=K; }
	if (Type != "Rankine") { document.Temperatures.Rankine.value=R; }
}

function UpdatePression(input) {
	var Press=input.value*1;
	var Type=input.name;

	if (Type == "kPa")			{ kgcm2=Press*0.01019716; } 
	else if (Type == "mb")		{ kgcm2=Press*0.001019716; } 
	else if (Type == "poHg")	{ kgcm2=Press*0.03453145; } 
	else if (Type == "cmHg")	{ kgcm2=Press*0.01359506; } 
	else if (Type == "mH2O")	{ kgcm2=Press*0.09999724; } 
	else if (Type == "poH2O")	{ kgcm2=Press*0.00253993; } 
	else if (Type == "atm")		{ kgcm2=Press*1.033228; }
	else if (Type == "kgcm2")	{ kgcm2=Press; }

	kPa=round(kgcm2*98.0665);
	mb=round(kgcm2*980.665);
	poHg=round(kgcm2*28.95911);
	cmHg=round(kgcm2*73.55613);
	mH2O=round(kgcm2*10.00028);
	poH2O=round(kgcm2*393.7117);
	atm=round(kgcm2*0.9678411);
	kgcm2=round(kgcm2);

	if (Type != "kPa")	{ document.Pressions.kPa.value=kPa; }
	if (Type != "mb")	{ document.Pressions.mb.value=mb; }
	if (Type != "poHg") { document.Pressions.poHg.value=poHg; }
	if (Type != "cmHg") { document.Pressions.cmHg.value=cmHg; }
	if (Type != "mH2O") { document.Pressions.mH2O.value=mH2O; }
	if (Type != "poH2O"){ document.Pressions.poH2O.value=poH2O; }
	if (Type != "atm")	{ document.Pressions.atm.value=atm; }
	if (Type != "kgcm2"){ document.Pressions.kgcm2.value=kgcm2; }

}

function UpdateVitesse(input) {
	var Vit=input.value*1;
	var Type=input.name;

	if (Type == "kmh")		{ ms = Vit*0.2777778;} 
	else if (Type == "mph") { ms = Vit*0.44704;}
	else if (Type == "kt")	{ ms = Vit*0.5144444;}
	else if (Type == "ms")  { ms = Vit;}

	kmh = round(ms*3.6);
	mph = round(ms*2.236936);
	kt  = round(ms*1.943845);
	ms  = round(ms);

	if (Type != "kmh") { document.Vitesses.kmh.value=kmh; }
	if (Type != "mph") { document.Vitesses.mph.value=mph; }
	if (Type != "kt") { document.Vitesses.kt.value=kt; }
	if (Type != "ms") { document.Vitesses.ms.value=ms; }
}

function UpdateDistance(input) {
	var Dist=input.value*1;
	var Type=input.name;
	
	if (Type == "km")	   { A = Dist * 10000000000000; }
	else if (Type == "m")  { A = Dist * 10000000000; }
	else if (Type == "cm") { A = Dist * 100000000; }
	else if (Type == "um") { A = Dist * 10000; }
	else if (Type == "mi") { A = Dist * 16090000000000; }
	else if (Type == "yd") { A = Dist * 9144000000; }
	else if (Type == "pi") { A = Dist * 3048000000; }
	else if (Type == "po") { A = Dist * 254000000; }
	else if (Type == "mn") { A = Dist * 18520000000000; }
	else if (Type == "au") { A = Dist * 1.496e+21; }
	else if (Type == "al") { A = Dist * 9.461e+25; }
	else if (Type == "ps") { A = Dist * 3.086e+26; }
	else if (Type == "A")  { A = Dist * 1; }
	else if (Type == "mm") { A = Dist * 10000000; }
	else if (Type == "pt") { A = Dist * 3528000; }
	else if (Type == "pica") { A = Dist * 42330000; }

	km = round(A*1e-13);
	m = round(A*1e-10);
	cm = round(A*1e-8);
	um = round(A*0.0001);
	mi = round(A*6.213712e-14);
	yd = round(A*1.093613e-10);
	pi = round(A*3.28084e-10);
	po = round(A*3.937008e-9);
	mn = round(A*5.399568e-14);
	au = round(A*6.684587e-22);
	al = round(A*1.057023e-26);
	ps = round(A*3.240779e-27);
	A = round(A*1);
	mm = round(A*1e-7);
	pt = round(A*2.834646e-7);
	pica = round(A*2.362205e-8);

	if (Type != "km") { document.Distances.km.value=km; }
	if (Type != "m")  { document.Distances.m.value=m; }
	if (Type != "cm") { document.Distances.cm.value=cm; }
	if (Type != "um") { document.Distances.um.value=um; }
	if (Type != "mi") { document.Distances.mi.value=mi; }
	if (Type != "yd") { document.Distances.yd.value=yd; }
	if (Type != "pi") { document.Distances.pi.value=pi; }
	if (Type != "po") { document.Distances.po.value=po; }
	if (Type != "mn") { document.Distances.mn.value=mn; }
	if (Type != "au") { document.Distances.au.value=au; }
	if (Type != "al") { document.Distances.al.value=al; }
	if (Type != "ps") { document.Distances.ps.value=ps; }
	if (Type != "A")  { document.Distances.A.value=A; }
	if (Type != "mm") { document.Distances.mm.value=mm; }
	if (Type != "pt") { document.Distances.pt.value=pt; }
	if (Type != "pica") { document.Distances.pica.value=pica; }
}

function UpdatePoids(input) {
	var Poids=input.value*1;
	var Type=input.name;

	if (Type == "T")	   { mg = Poids * 1000000000; }
	else if (Type == "kg") { mg = Poids * 1000000; }
	else if (Type == "g")  { mg = Poids * 1000; }
	else if (Type == "mg") { mg = Poids * 1; }
	else if (Type == "N")  { mg = Poids * 101971.6; }
	else if (Type == "lbs"){ mg = Poids * 453592.4; }
	else if (Type == "oz") { mg = Poids * 28349.52; }

	T   = round ( mg * 1e-9 );
	kg  = round ( mg * 0.000001);
	g   = round ( mg * 0.001);
	mg  = round ( mg * 1);
	N   = round ( mg * 0.000009806652);
	lbs = round ( mg * 0.000002204623);
	oz  = round ( mg * 0.00003527396);

	if (Type != "T") { document.Poids.T.value=T; }
	if (Type != "kg") { document.Poids.kg.value=kg; }
	if (Type != "g") { document.Poids.g.value=g; }
	if (Type != "mg") { document.Poids.mg.value=mg; }
	if (Type != "N") { document.Poids.N.value=N; }
	if (Type != "lbs") { document.Poids.lbs.value=lbs; }
	if (Type != "oz") { document.Poids.oz.value=oz; }
}

function UpdateVolumes(input) {
	var Vol=input.value*1;
	var Type=input.name;


	if (Type == "m3")		{ ml = Vol * 1000000;}
	else if (Type == "hl")	{ ml = Vol * 100000;}
	else if (Type == "l")	{ ml = Vol * 1000;}
	else if (Type == "ml")	{ ml = Vol * 1;}
	else if (Type == "gal")	{ ml = Vol * 3785.412;}
	else if (Type == "pt")	{ ml = Vol * 473.1765;}
	else if (Type == "oz")	{ ml = Vol * 29.57353;}
	else if (Type == "cm3")	{ ml = Vol * 1;}
	else if (Type == "mm3")	{ ml = Vol * 0.001;}
	else if (Type == "pi3")	{ ml = Vol * 28316.85;}
	else if (Type == "po3")	{ ml = Vol * 16.38706;}
	else if (Type == "tasse"){ ml = Vol * 236.5882;}
	else if (Type == "galimp")	{ ml = Vol * 4546.099;}
	else if (Type == "ptimp")	{ ml = Vol * 568.2624;}
	else if (Type == "ozimp")	{ ml = Vol * 28.41312;}

	m3 = round (ml*0.000001);
	hl = round (ml*0.00001);
	l  = round (ml*0.001);
	ml = round (ml*1);
	gal= round (ml*0.0002641721);
	pt = round (ml*0.002113376);
	oz = round (ml*0.03381402);
	cm3= round (ml*1);
	mm3= round (ml*1000);
	pi3= round (ml*0.00003531467);
	po3= round (ml*0.06102374);
	tasse=round(ml*0.004226753);
	galimp= round (ml*0.0002199688);
	ptimp = round (ml*0.00175975);
	ozimp = round (ml*0.03519501);


	if (Type != "m3") { document.Volumes.m3.value=m3; }
	if (Type != "hl") { document.Volumes.hl.value=hl; }
	if (Type != "l") { document.Volumes.l.value=l; }
	if (Type != "ml") { document.Volumes.ml.value=ml; }
	if (Type != "gal") { document.Volumes.gal.value=gal; }
	if (Type != "pt") { document.Volumes.pt.value=pt; }
	if (Type != "oz") { document.Volumes.oz.value=oz; }
	if (Type != "cm3") { document.Volumes.cm3.value=cm3; }
	if (Type != "mm3") { document.Volumes.mm3.value=mm3; }
	if (Type != "pi3") { document.Volumes.pi3.value=pi3; }
	if (Type != "po3") { document.Volumes.po3.value=po3; }
	if (Type != "tasse") { document.Volumes.tasse.value=tasse; }
	if (Type != "galimp") { document.Volumes.galimp.value=galimp; }
	if (Type != "ptimp") { document.Volumes.ptimp.value=ptimp; }
	if (Type != "ozimp") { document.Volumes.ozimp.value=ozimp; }

}

function UpdateAires(input) {
	var Air=input.value*1;
	var Type=input.name;

	if (Type == "km2")		{ mm2 = Air * 1000000000000; }
	else if (Type == "ha")	{ mm2 = Air * 10000000000; }
	else if (Type == "m2")	{ mm2 = Air * 1000000; }
	else if (Type == "mm2")	{ mm2 = Air * 1; }
	else if (Type == "mi2")	{ mm2 = Air * 2590000000000; }
	else if (Type == "ac")	{ mm2 = Air * 4047000000; }
	else if (Type == "v2")	{ mm2 = Air * 836100; }
	else if (Type == "po2")	{ mm2 = Air * 645.2; }
	else if (Type == "pi2")	{ mm2 = Air * 92900; }
	else if (Type == "cm2")	{ mm2 = Air * 100; }

	km2 = round(mm2*1e-12);
	ha  = round(mm2*1e-10);
	m2  = round(mm2*0.000001);
	mm2 = round(mm2*1);
	mi2 = round(mm2*3.861022e-13);
	ac  = round(mm2*2.471054e-10);
	v2  = round(mm2*0.00000119599);
	po2 = round(mm2*0.001550003);
	pi2 = round(mm2*0.00001076391);
	cm2 = round(mm2*0.01);

	if (Type != "km2") { document.Aires.km2.value=km2; }
	if (Type != "ha") { document.Aires.ha.value=ha; }
	if (Type != "m2") { document.Aires.m2.value=m2; }
	if (Type != "mm2") { document.Aires.mm2.value=mm2; }
	if (Type != "mi2") { document.Aires.mi2.value=mi2; }
	if (Type != "ac") { document.Aires.ac.value=ac; }
	if (Type != "v2") { document.Aires.v2.value=v2; }
	if (Type != "po2") { document.Aires.po2.value=po2; }
	if (Type != "pi2") { document.Aires.pi2.value=pi2; }
	if (Type != "cm2") { document.Aires.cm2.value=cm2; }
}

function UpdateEolien(input) {
	var Type=input.name;

	var Temp1 = document.TempRess.Temp1.value;
	var Vents = document.TempRess.Vents.value;
	var Eolien = document.TempRess.Eolien.value;

	Eolien = round(13.12 + 0.6215 * Temp1 - 11.37 * Math.pow(Vents,0.16) + 0.3965 * Temp1 * Math.pow(Vents,0.16));
	if (Eolien > Temp1) Eolien=Temp1;
	
	if (Type != "Temp1") { document.TempRess.Temp1.value=Temp1; }
	if (Type != "Vents") { document.TempRess.Vents.value=Vents; }
	if (Type != "Eolien") { document.TempRess.Eolien.value=Eolien; }
}

function UpdateHumidex(input) {
	var Type=input.name;

	var Temp2 = document.TempRess.Temp2.value*1;
	var HumRel = document.TempRess.HumRel.value*1;
	var Humidex = document.TempRess.Humidex.value;

	
	var t=7.5*Temp2/(237.7+Temp2);

  	var e = 6.112* Math.pow(10, t) *HumRel/100;
	var h = 5/9*(e-10);
	Humidex = round(Temp2+h);
	if (Humidex < Temp2) Humidex=Temp2;

	if (Type != "Temp2") { document.TempRess.Temp2.value=Temp2; }
	if (Type != "HumRel") { document.TempRess.HumRel.value=HumRel; }
	if (Type != "Humidex") { document.TempRess.Humidex.value=Humidex; }
}

function UpdateHumidex2(input) {
	var Type=input.name;

	var Temp3 = document.TempRess.Temp3.value*1;
	var Rosee = document.TempRess.Rosee.value*1;
	var Humidex2 = document.TempRess.Humidex2.value;
	
	var Td=Rosee+273.15;
	var e=6.11*Math.exp(5417.7530*((1/273.16)-(1/Td)));
	
	var h=5/9*(e-10);

	Humidex2 = round(Temp3+h);
	if (Humidex2 < Temp3) Humidex2=Temp3;

	if (Type != "Temp3") { document.TempRess.Temp3.value=Temp3; }
	if (Type != "Rosee") { document.TempRess.Rosee.value=Rosee; }
	if (Type != "Humidex2") { document.TempRess.Humidex2.value=Humidex2; }
}

