/*
  Copyright 1999-2001 Digital Pathways International, Inc. All Rights Reserved
  This source code is the property of Digital Pathways International, Inc.
  and may not be modified, copied, distributed, transmitted, displayed,
  reproduced, published, licensed, used to create derivative works,
  transferred, or sold in any form without written permission from
  Digital Pathways International, Inc., PO Box 591171 San Francisco, CA 94159-1171
*/

function format(v)
{
  var xv = v.toString();
  if (xv.indexOf('.') == -1)  xv = xv + ".00"; else xv = xv + "00";
  xv = "$ "+ xv.slice(0,xv.indexOf('.')+3);
  while (xv.length < 10) { xv = " "+ xv; }
  return (xv);
}

function calc()
{
  document.calculator.perhour.value = " ";
  document.calculator.perplane.value = " ";
  document.calculator.perpilot.value = " ";
  document.calculator.total.value = " ";
  if (document.calculator.planecount.value > 0)
  {
    var xtotal = 0;
    var additional = document.calculator.planecount.value;
    if (additional >= 100)
      {
        xtotal = ((additional-99) * 4);  // 100+
        xtotal += (70 * 5);              // 30..99
        xtotal += (20 * 8);              // 10..29
        xtotal += (8 * 16);              // 2..9
        xtotal += 20;
      }
    else
   { if (additional >= 30)
      {
        xtotal = ((additional-29) * 5);  // 30..99
        xtotal += (20 * 8);              // 10..29
        xtotal += (8 * 16);              // 2..9
        xtotal += 20;
      }
    else
     { if (additional >= 10)
       {
        xtotal = ((additional-9) * 8);   // 10..29
        xtotal += (8 * 16);              // 2..9
        xtotal += 20;
       }
       else
        { if (additional > 0)
          { xtotal = ((additional-1) * 16) + 20; }
        }
     }
    }
    document.calculator.total.value = format(xtotal);
    var perp = (xtotal / document.calculator.planecount.value);
    document.calculator.perplane.value = format(perp);

  if (document.calculator.pilotcount.value > 0)
    {
      var costper = (xtotal / document.calculator.pilotcount.value);
      document.calculator.perpilot.value = format(costper);
    }
  if (document.calculator.hours.value > 0)
    {
      var perh = (xtotal / (document.calculator.planecount.value * document.calculator.hours.value) );
      document.calculator.perhour.value = format(perh);
    }
  }
}