/* * * * * * * * * *    CONVERT SCRIPT 1   * * * * * * * * * *\
*                                                             *
*    Converts between U.S./Imperial and SI (Metric) units.    *
*                                                             *
*        --  Written by Bo Johansson  1998-11-10  --          *
*        --      Area measures added  1999-02-21  --          *
*        --  Pressure measures added  2000-05-17  --          *
*        --        Opera 4 bug fixes  2000-10-14  --          *
*        --   Other ressure measures  2002-03-21  --          *
*        --  Pressure measures moved                          *
*              to script convert2.js  2002-05-23  --          *
*        --  Common functions moved                           *
*                 to file convert.js  2002-06-14  --          *
*        --  Astronomic length                                *
*                     measures added  2002-09-14  --          *
*                                                             *
*   --   http://w1.545.telia.com/~u54504162/index_e.htm   --  *
\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

function VOL_MEASURES()
{
  this.mCubic_meter = 1000
  this.mHectoliter = 100
  this.mDekaliter = 10
  this.mLiter = 1
  this.mDeciliter = 0.1
  this.mCentiliter = 0.01
  this.mMilliliter = 0.001
  this.mCubic_millimeter = 0.000001
  
  this.mcTable_spoon=0.015
  this.mcTea_spoon=0.005

  this.uscCubic_inch = 0.016387064
  this.uscAcre_foot = 43560 * 1728 * this.uscCubic_inch
  this.uscCubic_yard = 27 * 1728 * this.uscCubic_inch
  this.uscCubic_foot = 1728 * this.uscCubic_inch
  
  this.uslGallon = 231 * this.uscCubic_inch
  this.uslBarrel = 42 * this.uslGallon
  this.uslQuart =  this.uslGallon / 4
  this.uslPint =  this.uslGallon / 8
  this.uslGill =  this.uslGallon / 32
  this.uslFluid_ounce = this.uslGallon / 128
  this.uslFluid_dram =  this.uslGallon / 1024
  this.uslMinim = this.uslFluid_ounce / 61440
  
  this.usdBarrel = 7056 * this.uscCubic_inch
  this.usdBushel = 2150.42 * this.uscCubic_inch
  this.usdPeck = this.usdBushel / 4
  this.usdQuart = this.usdBushel / 32
  this.usdPint = this.usdBushel / 64
  
  this.uscCup = 8 * this.uslFluid_ounce
  this.uscTable_spoon = this.uslFluid_ounce / 2
  this.uscTea_spoon = this.uslFluid_ounce / 6
  
  this.briGallon = 4.54609
  this.briBarrel = 36 * this.briGallon
  this.briBushel = 8  * this.briGallon
  this.briPint = this.briGallon / 8
  this.briFluid_ounce = this.briGallon / 160
}


function WEIGHT_MEASURES()
{
  this.mTon = 1000
  this.mKilogram = 1
  this.mGram = 0.001
  this.mMilligram = 0.000001

  this.avdpPound = 0.45359237
  this.briTon = 2240 * this.avdpPound
  this.usTon = 2000 * this.avdpPound
  this.briCWT = 112 * this.avdpPound
  this.usCWT = 100 * this.avdpPound
  this.briStone = 14 * this.avdpPound     // *** Added 2000-05-17
  this.avdpOunce = this.avdpPound / 16
  this.avdpDram= this.avdpPound / 256
  this.avdpGrain = this.avdpPound / 7000

  this.troyPound = 5760 * this.avdpGrain
  this.troyOunce = 480 * this.avdpGrain
  this.troyDWT = 24 * this.avdpGrain
  this.troyGrain = this.avdpGrain
}


function LENGTH_MEASURES()
{
  this.mKilometer = 1000
  this.mMeter = 1
  this.mDecimeter = 0.1
  this.mCentimeter = 0.01
  this.mMillimeter = 0.001

  this.engFoot = 0.3048
  this.engMile = 5280 * this.engFoot
  this.engFurlong = 660 * this.engFoot
  this.engYard = 3 * this.engFoot
  this.engInch = this.engFoot / 12
  this.engMil = this.engFoot / 12000
  
  this.nautMile = 1852
  this.nautFathom = 6 * this.engFoot
  
  this.astrua = 149597870000                    // *** Added 2002-09-14
  this.astrly = 299792458 * 3600 * 24 * 365.25  // *** Added 2002-09-14
  this.astrpc = 30856780000000000               // *** Added 2002-09-14
}


function AREA_MEASURES()              //******* function added 1999-02-21
{
  this.mSquare_kilometer = (1000 * 1000)
  this.mHectare = (100 * 100)
  this.mAre = 100
  this.mSquare_meter = 1
  this.mSquare_decimeter = (0.1 * 0.1)
  this.mSquare_centimeter = (0.01 * 0.01)
  this.mSquare_millimeter = (0.001 * 0.001)

  this.engSquare_foot = (0.3048 * 0.3048)
  this.engSquare_yard = (3 * 3 * this.engSquare_foot)
  this.usSquare_rod = (16.5 *16.5 * this.engSquare_foot)
  this.engAcre = 160 * this.usSquare_rod
  this.engSquare_mile = (5280 *5280 * this.engSquare_foot)
  this.engSquare_inch = (this.engSquare_foot / (12 * 12))
}


var vol_data = new VOL_MEASURES();

var weight_data = new WEIGHT_MEASURES();

var length_data = new LENGTH_MEASURES();

var area_data = new AREA_MEASURES();



function computeTempC(obj)
{
  var tempC = parseFloat(obj.tempCelsius.value)

  if( (tempC >= 0) && (obj.tempCelsius.value.indexOf("-") != -1) )
  {
    tempC = -tempC;    // *** Hack for Opera 4.0  2000-10-14
  }

  if(!(tempC < -273.15) )
  {
    var tempK = tempC + 273.15

    var tempF = 32 + (tempC * 9 / 5)

    obj.tempKelvin.value = tempK

    obj.tempFahr.value = tempF
  }

  else
  {                                  // **** BJ 2000-10-14
    obj.tempKelvin.value = "ERROR"

    obj.tempFahr.value = "ERROR"
  }

}  // * * * * * * * END function computeTempC() * * * * * * * * *


function computeTempK(obj)
{
  var tempK = parseFloat(obj.tempKelvin.value)

  if( (tempK >= 0) && (obj.tempKelvin.value.indexOf("-") != -1) )
  {
    tempK = -tempK;    // *** Hack for Opera 4.0  2000-10-14
  }

  if(!(tempK < 0) )
  {
    var tempC = tempK - 273.15

    var tempF = 32 + (tempC * 9 / 5)

    obj.tempCelsius.value = tempC

    obj.tempFahr.value = tempF
  }
  else
  {                                  // **** BJ 2000-10-14
    obj.tempCelsius.value = "ERROR"

    obj.tempFahr.value = "ERROR"
  }

}  // * * * * * * * END function computeTempK() * * * * * * * * *


function computeTempF(obj)
{
  var tempF = parseFloat(obj.tempFahr.value)

  if( (tempF >= 0) && (obj.tempFahr.value.indexOf("-") != -1) )
  {
    tempF = -tempF;    // *** Hack for Opera 4.0  2000-10-14
  }

  if(!(tempF < -459.666666) )
  {
    var tempC = (tempF - 32) * 5 / 9

    var tempK = tempC + 273.15

    obj.tempCelsius.value = tempC

    obj.tempKelvin.value = tempK
  }

  else
  {                                  // **** BJ 2000-10-14
    obj.tempCelsius.value = "ERROR"

    obj.tempKelvin.value = "ERROR"
  }

}  // * * * * * * * END function computeTempF() * * * * * * * * *



function resetAll(form)    // *** Hack for Opera 4.0  2000-10-14
{
  resetValues(form,vol_data);
  resetValues(form,weight_data);
  resetValues(form,length_data);
  resetValues(form,area_data);

  form.tempCelsius.value = ""
  form.tempKelvin.value = ""
  form.tempFahr.value = ""

}  // * * * * * * * END function resetAll() * * * * * * * * *

//* * * * * * * *   CONVERT SCRIPT 1 - END -  * * * * * * * * *


