function Convert1(myform){
  with (myform) {
    var LocalValFrom  = parseFloat(elements['ValFrom'].value);
    if (elements['What'].value == "Temperature") {
       var LocalTypeFrom = elements['TypeFrom'].options[elements['TypeFrom'].selectedIndex].value;
       var LocalTypeTo   = elements['TypeTo'].options[elements['TypeTo'].selectedIndex].value;
       TempSI       = ToSI(LocalValFrom, LocalTypeFrom);
       elements['ValTo'].value = DecPlaces(FromSI(TempSI, LocalTypeTo), 6);
       }
    else {
       var LocalTypeFrom = parseFloat(elements['TypeFrom'].options[elements['TypeFrom'].selectedIndex].value);
       var LocalTypeTo   = parseFloat(elements['TypeTo'].options[elements['TypeTo'].selectedIndex].value);
       elements['ValTo'].value = DecPlaces(LocalValFrom * LocalTypeFrom / LocalTypeTo, 6);
       }
  }
}

function Convert2(myform){
  with (myform) {
    var LocalValTo    = parseFloat(elements['ValTo'].value);
    if (elements['What'].value == "Temperature") {
       var LocalTypeFrom = elements['TypeFrom'].options[elements['TypeFrom'].selectedIndex].value;
       var LocalTypeTo   = elements['TypeTo'].options[elements['TypeTo'].selectedIndex].value;
       TempSI       = ToSI(LocalValTo, LocalTypeTo);
       elements['ValFrom'].value = DecPlaces(FromSI(TempSI, LocalTypeFrom), 6);
       }
    else {
       var LocalTypeFrom = parseFloat(elements['TypeFrom'].options[elements['TypeFrom'].selectedIndex].value);
       var LocalTypeTo   = parseFloat(elements['TypeTo'].options[elements['TypeTo'].selectedIndex].value);
       elements['ValFrom'].value = DecPlaces(LocalValTo / LocalTypeFrom * LocalTypeTo, 6);
       }
  }
}

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

function ToSI(Temperature, Measure)
{
  if      (Measure == "Celsius")     return Temperature + 273.15;
  else if (Measure == "Fahrenheit")  return 5/9 * (Temperature + 459.67);
  else if (Measure == "Kelvin")      return Temperature;
  else if (Measure == "Raumure")    return 5/4 * Temperature + 273.15;
  else if (Measure == "Rankine")     return 5/9 * Temperature;
}

function FromSI(Temperature, Measure)
{
  if      (Measure == "Celsius")    return Temperature - 273.15;
  else if (Measure == "Fahrenheit") return 9/5 * Temperature - 459.67;
  else if (Measure == "Kelvin")     return Temperature;
  else if (Measure == "Raumure")   return 4/5 * (Temperature - 273.15);
  else if (Measure == "Rankine")    return 9/5 * Temperature;
}
