// JavaScript Document
function sauceAmounts() {
H = (document.order.sauce1amount.value + ' ' + document.order.sauce1.value + ', ');
I = (document.order.sauce2amount.value + ' ' + document.order.sauce2.value + ', ');
J = (document.order.sauce3amount.value + ' ' + document.order.sauce3.value + ', ');
K = (document.order.sauce4amount.value + ' ' + document.order.sauce4.value + ', ');
L = (document.order.sauce5amount.value + ' ' + document.order.sauce5.value + ', ');
M = (document.order.sauce6amount.value + ' ' + document.order.sauce6.value);

if (parseFloat(document.order.sauce1amount.value) == 0)
	{
	H = ('');
	}
	
if (parseFloat(document.order.sauce2amount.value) == 0)
	{
	I = ('');
	}
	
if (parseFloat(document.order.sauce3amount.value) == 0)
	{
	J = ('');
	}

if (parseFloat(document.order.sauce4amount.value) == 0)
	{
	K = ('');
	}

if (parseFloat(document.order.sauce5amount.value) == 0)
	{
	L = ('');
	}
	
if (parseFloat(document.order.sauce6amount.value) == 0)
	{
	M = ('');
	}

totalSauce = (H + I + J + K + L + M);
document.order.os0.value = totalSauce;
}

function total() {
A = parseFloat(document.order.sauce1amount.value);
B = parseFloat(document.order.sauce2amount.value);
C = parseFloat(document.order.sauce3amount.value);
D = parseFloat(document.order.sauce4amount.value);
E = parseFloat(document.order.sauce5amount.value);
F = parseFloat(document.order.sauce6amount.value);
result = (A + B + C + D + E + F);


document.order.qty.value = result;
}


 var ac = 0;    // table for qty/amt pairs
var aqty = new Array ();  // qty brkpt
var aamt = new Array ();  // amount to charge

var pc = 0;    // table for qty/percent pairs
var pqty = new Array ();  // qty brkpt
var pper = new Array ();  // percent to discount

function Dollar (val) {  // force to valid dollar amount
var str,pos,rnd=0;
  if (val < .995) rnd = 1;  // for old Netscape browsers
  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 ReadForm (obj1) { // quantity based discounts
 if (parseFloat(document.order.qty.value) < 2)
		{
		alert("Minimum order is 2 bottles");
		return false;
		}
		

var i,amt,des,qty;
  amt = obj1.baseamt.value*1.0; // base amount
  des = obj1.basedes.value;     // base description
  qty = obj1.qty.value;         // get user quantity
  if (isNaN (qty) || qty < 1) { // make sure it's good
    alert ('"' + qty + '"' + ' is not a valid number!');
    ac = 0;                     // always zap the table
    pc = 0;
    return false;               // th-th-that's all, folks.
  }
  qty = qty*1.0;                // force to numeric

  for (i=ac-1; i>=0; i=i-1) {   // run table backwards
    if (qty >= aqty[i]) {       // use this entry
      amt = aamt[i];            // this is the real amount
      break;                    // get out, we're done
    }
  }
  for (i=pc-1; i>=0; i=i-1) {   // run table backwards
    if (qty >= pqty[i]) {       // use this entry
      amt = amt - (amt/100.0 * pper[i]);
      break;                    // get out, we're done
    }
  }

  obj1.item_name.value = des + ", " + qty + " Bottles @" +
                         Dollar (amt) + " each";
  obj1.amount.value = Dollar (amt * qty);
  ac = 0;  // reset item discount
  pc = 0;
 
}

function SetAmt (q1, a1) {  // set up a quantity-based amount table
var i;
  ac = 0;
  for (i=0; i<arguments.length; i=i+2) {  // build the table
    aqty[ac] = arguments[i];   // get real args and store 
    aamt[ac] = arguments[i+1];
    ac = ac + 1;               // number of pairs in table
  }
}     



//-->
