function calcPercent() {
  var i = document.ratio.ratio.value;
  var j = 100/i;

  formatCellValue(document.ratio.percent, j);
}


function calcAll() {
  DocalcOil();
}

function calcRatio() {
  var i = document.ratio.percent.value;
  var j = 100/i;
  formatCellValue(document.ratio.ratio, j);
}


// Common routines used by all calculators
var g_gas, g_gasm, g_oilqty, g_oilqtym;

function galToLiter() {
  g_gas = document.gasoil.gas.value ; //get gallons
  g_gasm = (g_gas * 3.785411784) ; //gas converted to liters
  DocalcOil();
  document.gasoil.gas.focus();
}

function literToGal() {
  g_gasm = document.gasoil.gasm.value ; //get liters
  g_gas = (g_gasm * 0.26417205235814844) ; //gas converted to gallons

  DocalcOil();
  selectField(document.gasoil.gasm);
}


function calcOil() {
  DocalcOil();
  selectField(document.gasoil.gomr);
}

function DocalcOil()
{
  var gast = g_gas; //get gallons
  var gomrt = document.gasoil.gomr.value; //get mixture ratio
  var gaso = (gast * 128); //convert gas to ounces
  var oilo = (( gaso) / gomrt); //divide by ratio
  g_oilqty = oilo; //required oil

  var gastm = g_gasm; //get liters
  var gomrtm =document.gasoil.gomr.value; //get mixture ratio
  var gasom = (gastm * 1000); //convert petrol to ml
  var oilom = (( gasom) / gomrtm); //divide by ratio
  g_oilqtym = oilom; //required oil


  formatAll();
  selectField(document.gasoil.gomr);
}


function formatAll() {
  formatCellValue(document.gasoil.oilqty, g_oilqty);
  formatCellValue(document.gasoil.oilqtym, g_oilqtym);
  formatCellValue(document.gasoil.gas, g_gas);
  formatCellValue(document.gasoil.gasm, g_gasm);
  return false;
}


