// see: http://members.aol.com/paypalsip/sing1.html

var aqty = new Array ();  // amount qty breakpoint
var aamt = new Array ();  // amount to charge
var an   = 0;             // number of discount brkpts

var hqty = new Array ();  // handling qty breakpoints
var hamt = new Array ();  // amount charged
var hn   = 0;             // number of handling brkpts

var qqty = new Array ();  // quantity discount breakpoints
var qamt = new Array ();  // amount of discount
var qd   = 0;             // number of qty breakpoints

var sqty = new Array ();  // shipping qty breakpoints
var samt = new Array ();  // amount charged
var sn   = 0;             // number of shipping brkpts
var stxt = "";            // shipping type text

var taxp = 0.0;             // tax percent for this order

function ClearAll () {
  sn = 0;  // reset shipping indicator
}

function Dollar (val) {  // force to valid dollar amount
var str,pos,rnd=0;
  if (val < 1) rnd = 1;
  str = escape (val*1.0 + 0.005001 + rnd);  // float, round, escape
  pos = str.indexOf (".");
  if (pos > 0) str = str.substring (rnd, pos + 3);
  return str;
}

function Process (obj1) {      // process the form, but no submit
  var i,j,obj,bqty,bamt,btxt,tdis,thnd,tshp,ttax,val,pos,bshp;
  bshp = obj1.shipdest.value*1.0; // set the base shipping cost based on destination
  if (!obj1.quantity) {
    alert ("HTML must have quantity field!");
    return false;
  }
  if (!obj1.basedes) {
    alert ("HTML must have basedes field!");
    return false;
  }
  if (!obj1.baseamt) {
    alert ("HTML must have baseamt field!");
    return false;
  }
  btxt = obj1.basedes.value;          // reload desc
  bamt = obj1.baseamt.value*1.0;      //  and amount
  bqty = obj1.quantity.value;         // selected quantity
  if (isNaN(bqty) || bqty == "" || bqty < 1) {
    // alert ("You have not entered a Quantity. Assuming you would like one.");
    bqty = 1;
    obj1.quantity.value = "1";
  }
  
  tshp = 0;                           // shipping charges (only for products)
  bqty = bqty*1.0;                    // float that sucker
  tshp = bqty*bshp;

  ttax = 0;
  if (taxp > 0 &&              // have a percent recorded?
      obj1.tax) {              // check for override
    ttax = taxp/100.0;         // yep - calculate it.
    obj1.tax.value = Dollar (ttax * bqty * bamt);
  }

  obj1.shipping.value = Dollar (tshp);
  obj1.amount.value = Dollar (bamt);  // plug amount
  obj1.item_name.value = btxt;        // and descriptiuon
}


function SetSH (q1, s1) {      // set shipping breakpoints
var i;
  sn = 0;                      // count of breakpoints
  for (i=0; i<arguments.length; i=i+2) {
    sqty[sn] = arguments[i];   // price breakpoint
    samt[sn] = arguments[i+1]; // shipping charge
    sn = sn + 1;               // number of bkpts
  }
}

function SetTX (obj1) {  // Set tax percent for this order
var pos;
  pos  = obj1.selectedIndex;           // which item selected
  if(pos==1){
    taxp = 8.24;  // float it
  }
  else{
    taxp=0.0;
  }
}
