<!--
// Global variables
theProducts   = new Array ();
theDisplay    = new Array ();
theQty        = new Array ();
thePrice      = new Array ();
theName       = new Array ();
theCatNo      = new Array ();
deliveryCharges = new Array ("0","-1","");
taxCharges = new Array ("0","-1","");

totalItemsInArray = 0;

function GetTaxAndDelivery (form)
{
	form.taxRate.value=(taxCharges[document.forms[0].taxRate.selectedIndex]);
	form.delivery.value=(deliveryCharges[document.forms[0].delivery.selectedIndex]);
}
function Monify(value)
{
  var str = "" + Math.round(value*100);
  var len = str.length;
  return (str=="0")?"0.00":(str.substring(0,len-2)+"."+str.substring(len-2,len));
}

function InsertInArray (i, qty, price, name, catNo)
{
   if (qty > 0)
   {
      theQty[i]       = qty;
      thePrice[i]     = price;
      theName[i]      = name;
      theCatNo[i]     = catNo;
      theProducts[i]  = "|Forstflwr9@aol.com,"+theQty[i]+","+thePrice[i]+","+theName[i]+","+theCatNo[i];
      theDisplay[i]   = theName[i]+" - "+theQty[i]+" x "+thePrice[i]+"\r\n";
   }
   else
   {
      theCatNo[i]     = catNo;
      theProducts[i]  = "";
   }
}

function CheckTheProduct (qty, price, name, catNo)
{
   price = Monify (price);
   var i = 0;
   while (i < totalItemsInArray)
   {
      // Two items with the same or no catalog number are allowed, if they have different names
      if (theCatNo[i] == catNo && theName[i] == name)
      {
         InsertInArray (i, qty, price, name, catNo);
         return;
      }
      i++;
   }

   // If adding a new item, its qty must be more than 0
   if (qty > 0)
   {
      InsertInArray (i, qty, price, name, catNo);
      totalItemsInArray++;
   }
}

function PrepareProductsList (form)
{
   var products = "";
   var display  = "";
   var i = 0;
   var sub = 0;
   while (i < totalItemsInArray)
   {
      // CONSTRUCT THE PRODUCTS LIST
      if (theProducts[i])
      {
         products += theProducts[i];
         display  += theDisplay[i];
         sub += theQty[i]*thePrice[i];
      }
      i++;
     }
   products += "|";
   form.orderproducts.value    = products;
   form.displayProducts.value = display;
   form.total.value    = Monify(sub);

   // Get the delivery charge. The value is converted from string to intger.
   // Get the tax charge. The value is converted from string to intger
   // Calculate the tax + delivery charge; If tax rate is negative ignore it
   // Do not add the tax or delivery if the sub total is 0
   var delivery = parseFloat (deliveryCharges[form.delivery.selectedIndex]);

   if (delivery < 0) { delivery = 0; }
   var tax = parseFloat (taxCharges[form.taxRate.selectedIndex]);
   if (tax < 0) { tax = 0; }
   if (sub > 0) { form.subTotal.value    = Monify(sub + sub * tax/100 + delivery); }
   else { form.subTotal.value    = "0.00"; }
}

function D_M_Table(form, form_element, price, name, catNo)
{
   var qty = Math.abs(form_element.value);
   CheckTheProduct (qty, price, name, catNo);
   PrepareProductsList (form);
//   form.submit();
}

function ClearAndReset (form)
{
   totalItemsInArray = 0;
}

//-->


