function oiloz()
// Copyright(c) 2000, Blue Heron's Nest - all rights reserved
{
        Oz=document.ozform.gals.value *
               (128 / document.ozform.ratio.value)
        document.ozform.ozoil.value=Math.round(Oz * 10)/ 10
}

function oiloz2()
// Copyright(c) 2000, Blue Heron's Nest - all rights reserved
{
 if (document.zzform.gunits(0).checked==true)
  {
                      Oz=document.zzform.gas.value *
               (128 / document.zzform.mxrat.value)
        document.zzform.ozoil2.value=Math.round(Oz * 10)/ 10
                     Ioz=document.zzform.gas.value *
               (133.233 / document.zzform.mxrat.value)
        document.zzform.iozoil.value=Math.round(Ioz * 10)/ 10
                      Ml=document.zzform.gas.value *
               (3785.4 / document.zzform.mxrat.value)
        document.zzform.mloil.value=Math.round(Ml)
  }
  else
     {
      if (document.zzform.gunits(1).checked==true)
        {
                      Oz=document.zzform.gas.value *
               (153.722 / document.zzform.mxrat.value)
        document.zzform.ozoil2.value=Math.round(Oz * 10)/ 10
                      Ioz=document.zzform.gas.value *
               (160 / document.zzform.mxrat.value)
        document.zzform.iozoil.value=Math.round(Ioz * 10)/ 10
                      Ml=document.zzform.gas.value *
               (4546 / document.zzform.mxrat.value)
        document.zzform.mloil.value=Math.round(Ml)           
         }
       else
           {
            if (document.zzform.gunits(2).checked==true)
               {
                          Oz=document.zzform.gas.value *
                   (33.81402 / document.zzform.mxrat.value)
            document.zzform.ozoil2.value=Math.round(Oz * 10)/ 10
                     Ioz=document.zzform.gas.value *
               (35.195 / document.zzform.mxrat.value)
        document.zzform.iozoil.value=Math.round(Ioz * 10)/ 10
                          Ml=document.zzform.gas.value *
                   (1000 / document.zzform.mxrat.value)
            document.zzform.mloil.value=Math.round(Ml)
                }
            }
      }    
}

function stripBad(string) {
    for (var i=0, output='', valid="eE-0123456789."; i<string.length; i++)
       if (valid.indexOf(string.charAt(i)) != -1)
          output += string.charAt(i)
    return output;
}
function resetanswer() {
  document.ozform.ozoil.value = "";
}


function gasgal()
// Copyright(c) 2000, Blue Heron's Nest - all rights reserved
{
        Gal=document.galform.gals.value * 
               document.galform.ratioa.value *
               ((1 / document.galform.ratiob.value) - (1 / document.galform.ratioa.value))
               document.galform.galgas.value=Math.round(Gal * 10)/ 10
}
function oiladd()
// Copyright(c) 2000, Blue Heron's Nest - all rights reserved
{
        oznow=document.addozform.gala.value * 128
             iratiob= 1 / document.addozform.ratiob.value
             iratioa= 1 / document.addozform.ratioa.value
             dratio= iratiob - iratioa  
             Ozadd=oznow * dratio
             document.addozform.ozoil.value=Math.round(Ozadd * 10)/ 10
}
function displ()
// Copyright(c) 2000, Blue Heron's Nest - all rights reserved
{
        Answ=document.myform2.xvar.value * 
             document.myform2.yvar.value *
             (document.myform2.zvar.value / 12) * 62.5
        Bnsw=document.myform2.xvar.value * 
             document.myform2.yvar.value *
             (document.myform2.zvar.value / 12) * 64
        document.myform2.fans.value=Math.round(Answ)
        document.myform2.sans.value=Math.round(Bnsw)
}
function draft()
// Copyright(c) 2000, Blue Heron's Nest - all rights reserved
{
        Answ=(document.myform3.zvar.value / 
             (document.myform3.xvar.value *
              document.myform3.yvar.value * 62.5)) * 12
        Bnsw=(document.myform3.zvar.value / 
             (document.myform3.xvar.value *
              document.myform3.yvar.value * 64)) * 12     
        document.myform3.fans.value=Math.round(Answ * 10) / 10
        document.myform3.sans.value=Math.round(Bnsw * 10) / 10
}
function hullspd()
// Copyright(c) 2000, Blue Heron's Nest - all rights reserved
{
        Answ= 1.34 * Math.sqrt(document.myform4.yvar.value)
        Bnsw= 1.1508 * Answ
        Cnsw= 1.852  * Answ  
        document.myform4.fans.value=Math.round(Answ * 10) / 10
        document.myform4.sans.value=Math.round(Bnsw * 10) / 10
        document.myform4.tans.value=Math.round(Cnsw * 10) / 10
}
function transit()
// Copyright(c) 2000, Blue Heron's Nest - all rights reserved
{
  if (document.ttform.dunits(0).checked==true && document.ttform.sunits(0).checked==true)
 {
  tothrs = document.ttform.dist.value / document.ttform.speed.value
  totdays = Math.floor (tothrs / document.ttform.hruway.value)
  pthrs = Math.floor ((tothrs  - (totdays * document.ttform.hruway.value))) 
  ptmins = Math.round (60 * ((tothrs - (totdays * document.ttform.hruway.value)) - pthrs))
  document.ttform.thours.value = Math.round (tothrs * 10) / 10
  document.ttform.tdays.value = totdays
  document.ttform.phrs.value = pthrs
  document.ttform.pmins.value=ptmins
  }
   else
   {
     if (document.ttform.dunits(1).checked==true &&          document.ttform.sunits(1).checked==true)
   {
       tothrs = document.ttform.dist.value / document.ttform.speed.value
       totdays = Math.floor (tothrs / document.ttform.hruway.value)
       pthrs = Math.floor ((tothrs  - (totdays * document.ttform.hruway.value)))
       ptmins = Math.round (60 * ((tothrs - (totdays * document.ttform.hruway.value)) - pthrs))
       document.ttform.thours.value = Math.round (tothrs * 10) / 10
       document.ttform.tdays.value = totdays
       document.ttform.phrs.value = pthrs
       document.ttform.pmins.value=ptmins
    }
   else
   {
     if (document.ttform.dunits(0).checked==true &&          document.ttform.sunits(1).checked==true)
   {
       smph = document.ttform.speed.value * 1.1508
       tothrs = document.ttform.dist.value / smph
       totdays = Math.floor (tothrs / document.ttform.hruway.value)
       pthrs = Math.floor ((tothrs  - (totdays * document.ttform.hruway.value)))
       ptmins = Math.round (60 * ((tothrs - (totdays * document.ttform.hruway.value)) - pthrs))
       document.ttform.thours.value = Math.round (tothrs * 10) / 10
       document.ttform.tdays.value = totdays
       document.ttform.phrs.value = pthrs
       document.ttform.pmins.value=ptmins 
    }
        else
       {
        if (document.ttform.dunits(1).checked==true &&                      document.ttform.sunits(0).checked==true)
       {
          dmiles = document.ttform.dist.value * 1.15078
       tothrs = dmiles / document.ttform.speed.value
       totdays = Math.floor (tothrs / document.ttform.hruway.value)
       pthrs = Math.floor ((tothrs  - (totdays * document.ttform.hruway.value)))
       ptmins = Math.round (60 * ((tothrs - (totdays * document.ttform.hruway.value)) - pthrs))
       document.ttform.thours.value = Math.round (tothrs * 10) / 10
       document.ttform.tdays.value = totdays
       document.ttform.phrs.value = pthrs
       document.ttform.pmins.value=ptmins
       }
      }
    }
  }
}
function range()
// Copyright(c) 2000, Blue Heron's Nest - all rights reserved
{
// convert liters to gallons
  if (document.rrform.dunits(1).checked==true)
   {
     vgal = .26417 * document.rrform.tank.value
    }
    else
      {
        vgal = document.rrform.tank.value
       }
// convert liters/hr to gallons/hr
  if (document.rrform.funits(1).checked==true)
   {
     vgph = .26417 * document.rrform.usage.value
    }
    else
      {
        vgph = document.rrform.usage.value
       }
// convert SM/liter to SM/gallon
  if (document.rrform.funits(3).checked==true)
   {
     vsmg = 3.7854 * document.rrform.usage.value
    }
    else
      {
        vsmg = document.rrform.usage.value
       }
// convert NM/liter to NM/gallon
  if (document.rrform.funits(5).checked==true)
   {
     vnmg = 3.7854 * document.rrform.usage.value
    }
    else
      {
        vnmg = document.rrform.usage.value
       }
// ......mph and sm/unit consumption
  if  ((document.rrform.funits(2).checked==true || 
        document.rrform.funits(3).checked==true) &&
        document.rrform.sunits(0).checked==true)
      {
        vrsm = vgal * vsmg
        vrnm = .86898 * vrsm
        vrhr = vrsm / document.rrform.speed.value
       }
      else
       {
// ......knots and nm/unit consumption
        if  ((document.rrform.funits(4).checked==true ||               document.rrform.funits(5).checked==true) &&
              document.rrform.sunits(1).checked==true)
      {
        vrnm = vgal * vnmg
        vrsm = 1.15078 * vrnm
        vrhr = vrnm / document.rrform.speed.value
       }
      else
       { 
// ......mph and gph consumption
          if  ((document.rrform.funits(0).checked==true ||                 document.rrform.funits(1).checked==true) &&
                document.rrform.sunits(0).checked==true)
      {
        vrhr = vgal / vgph
        vrsm = vrhr * document.rrform.speed.value
        vrnm = .86898 * vrsm
       }
      else
       {
// ......knots and sm/unit consumption
          if  ((document.rrform.funits(2).checked==true ||                 document.rrform.funits(3).checked==true) &&
                document.rrform.sunits(1).checked==true)
      {
        vrsm = vgal * vsmg
        vrnm = .86898 * vrsm
        vrhr = vrnm / document.rrform.speed.value
       }
      else
       {
// ......mph and nm/unit consumption
           if  ((document.rrform.funits(4).checked==true ||                  document.rrform.funits(5).checked==true) &&
                 document.rrform.sunits(0).checked==true)
      {
        vrnm = vgal * vnmg
        vrsm = 1.15078 * vrnm
        vrhr = vrnm / (document.rrform.speed.value * .868976)
       }
      else
       {
// ......knots and gph consumption
           if  ((document.rrform.funits(0).checked==true ||                  document.rrform.funits(1).checked==true) &&
                 document.rrform.sunits(1).checked==true)
      {
        vrhr = vgal / vgph
        vrnm =  vrhr * document.rrform.speed.value
        vrsm = vrnm * 1.15078
       }
     }
    }
   }
  }
 }
            document.rrform.rsm.value =  Math.round (vrsm * 10) / 10
            document.rrform.rnm.value =  Math.round (vrnm * 10) / 10
            document.rrform.rhr.value  =   Math.round (vrhr * 10) / 10
                       vtcost = vgal * document.rrform.cpu.value
            document.rrform.tcost.value = Math.round (vtcost * 100) / 100 
            document.rrform.csm.value = Math.round ((vtcost / vrsm) * 100) / 100
            document.rrform.cnm.value = Math.round ((vtcost / vrnm) * 100) / 100
            document.rrform.chr.value = Math.round ((vtcost / vrhr) * 100) / 100
}            
function format(nval)
{
      var ftmp = Math.round(nval * 10);
      ftmp = ftmp / 10;
      return ftmp;
} 
