function calculateSavings(form) {

  if (!document.getElementById) return false;
  if (!document.createElement) return false;
  if (!document.createTextNode) return false;
  if (!document.appendChild) return false;
  if (!document.removeChild) return false;

  // form fields
  var fuelPrice   = parseFloat(form.fuelPrice.value);
  var annualMiles = parseFloat(form.annualMiles.value);
  var currentMPG  = parseFloat(form.currentMPG.value);
  var partNumber  = form.partNumber.value;

  // unit price indexed by part number from the form
  var prices = new Array();
  prices['38564']  =   4.50;
  prices['38564C'] =  100.80;
  prices['38565']  =   7.80;
  prices['38565C'] =  79.20;
  prices['38566']  =  25.00;
  prices['38566C'] = 135.00;
  var unitPrice = prices[partNumber];

  // number of gallons of fuel treated indexed by the part number
  var gallonsTreated = new Array();
  gallonsTreated['38564']  =   30;
  gallonsTreated['38564C'] =  720;
  gallonsTreated['38565']  =   60;
  gallonsTreated['38565C'] =  720;
  gallonsTreated['38566']  =  250;
  gallonsTreated['38566C'] = 1500;
  var numGallonsTreated = gallonsTreated[partNumber];

  // here we perform our magic
  var mpgImprovementFactor = 0.07;
  var unitCostPerFuelGallon = unitPrice / numGallonsTreated;
  var newMPG = currentMPG + (currentMPG * mpgImprovementFactor);
  var newPricePerGallon = fuelPrice + unitCostPerFuelGallon;
  var additiveCostPerMile = newPricePerGallon / newMPG;
  var fuelCostPerMile = fuelPrice / currentMPG;
  var additiveAnnualFuelCost = additiveCostPerMile * annualMiles;
  var currentAnnualFuelCost = annualMiles * fuelCostPerMile;
  var netFuelCostSavings = Math.round((currentAnnualFuelCost - additiveAnnualFuelCost) * 100) / 100;
  netFuelCostSavings = netFuelCostSavings.toFixed(2);

  /*First, find the tag with id="result". This div is not displayed when the
  page first loads. Then remove all of its content (This is so we can recalculate
  the result without previous results mucking up the display).Then, build a paragraph
  with text holding the result of the calculation. Finally, attach the new
  paragraph to the "result" div and make it visible (really only necessary the first
  time it runs).*/
  var resultDiv = document.getElementById('result');
  while (resultDiv.firstChild) {
    resultDiv.removeChild(resultDiv.firstChild);
  }
  var para = document.createElement('p');
  var txt = 'Your Estimated Annual Savings: $' + netFuelCostSavings;  var para_text = document.createTextNode(txt);
  para.appendChild(para_text);
  resultDiv.appendChild(para);
  resultDiv.style.display = 'block';
}

