// KON shopping cart
// Last updated ?????
// 
// Global variables
var sub_total; 
var normal_sub_total;
var shipping_total;
var packing_charge;
var packing_charge_default = 7;   // Packing charge amount for normal orders 
var dendrobiumQty;
//var phalaenopsisQty;
var budded_special_qty;
var giftpackage_qty;
var ind_special_qty;
var itemName = new Array();
var itemDescr = new Array();
var image = new Array();
var itemCost = new Array();
var itemQty = new Array();
var extCost = new Array();
var catNum = new Array();
var newitemQty = new Array();    // Array to calculate quantity
var shippingType = new Array();  // Array to store shipping type
var shippingValue = new Array(); // Array to store shipping amount for individual item
var qtyShipCost = new Array();   // Array to store shipping amount for a specified quantity
var itemQty = new Array();
itemCounter = 0;
var counter = 0;
var cookData = "";
var expdate = new Date()
expdate.setTime (expdate.getTime() + (1 * 24 * 60 * 60 * 1000))

// Parse cookie and extract the ordered items from the string.  
// Calls calculate() to do math 
// Calls writeCart() to display the shopping cart
// The following delimiters are used @, {, ^, ', *, ~, }, ?, % 

 if (getCookieData('Scart')) {
  substr0 = getCookieData('Scart')
  cLen = substr0.length
  offset0 = substr0.indexOf('@')
  counter = substr0.substring(0,offset0)
  if (counter == 0) {
   killCookie('Scart')
   history.go(0)
  }
  j = 0;
  //document.write(counter + '<br>')
  for (i=1; i<=counter; i++) {
   offsetq = eval('offset' + j + '');
   substrq = eval('substr' + j + '');
   eval('ind' + i + ' = offsetq + 1');
   eval('substr' + i + ' = substrq.substring(ind' + i + ',cLen)');
   eval('offset' + i + ' = substr' + i + '.indexOf("?")');
   eval('item' + i + ' = substr' + i + '.substring(0,offset' + i + ')');
   eval('Delimiter_name2qty_' + i + ' = item' + i + '.indexOf("{")');
   eval('Delimiter_qty2image_' + i + ' = item' + i + '.indexOf("*")');
   eval('Delimiter_image2price_' + i + ' = item' + i + '.indexOf("~")');
   eval('Delimiter_price2catno_' + i + ' = item' + i + '.indexOf("}")');
   eval('Delimiter_catno2shiptype_' + i + ' = item' + i + '.indexOf("^")');   
   eval('Delimiter_shiptype2shipvalue_' + i + ' = item' + i + '.indexOf("%")');
   //
   eval('item_name' + i + ' = item' + i + '.substring(0,Delimiter_name2qty_' + i + ')');
   eval('item_quantity' + i + ' = item' + i + '.substring((Delimiter_name2qty_'+i+'+1),Delimiter_qty2image_' + i + ')');
   eval('item_image' + i + ' = item' + i + '.substring((Delimiter_qty2image_' + i + ' + 1),Delimiter_image2price_' + i + ')');
   eval('item_price' + i + ' = item' + i + '.substring((Delimiter_image2price_' + i + ' + 2),Delimiter_price2catno_' + i + ')'); 
   eval('item_number' + i + ' = item' + i + '.substring((Delimiter_price2catno_' + i + ' + 1),Delimiter_catno2shiptype_' + i + ')'); 
   eval('item_shiptype' + i + ' = item' + i + '.substring((Delimiter_catno2shiptype_' + i + ' + 1),Delimiter_shiptype2shipvalue_' + i + ')'); 
   eval('item_shipvalue' + i + ' = item' + i + '.substring((Delimiter_shiptype2shipvalue_' + i + ' + 2),offset' + i + ')'); 
   //
   eval('orderDetail(i,item_name' + i + ',item_quantity' + i + ',item_image' + i + ',item_price' + i + ',item_number' + i + ',item_shiptype' + i + ',item_shipvalue' + i + ')');
   j++
  }
  calculate();
  calculateQty();
 }

// function: orderDetail()
// -----------------------
// Writes values into corresponding arrays
function orderDetail(j,name,qt,pic_name,cost,number,type,value) {
 //document.write(seq +' - '+ name +' - '+ qt +' - '+ descr +' - '+ cost +' - '+ number +' - '+ type +' - '+ value + '<br><br>');
 itemName[j] = name
 itemQty[j] = qt
 image[j] = pic_name
 itemCost[j] = cost
 catNum[j] = number
 shippingType[j] = type
 shippingValue[j] = value 
 //document.write(itemName[j] + ' ')
 //document.write(itemQty[j])
 //document.write('<br>')
}


// function: calculateQty()
// ---------------------
// *** List the quantity of items in the persons cart ***
function calculateQty() {
  for (y = 1; y <= counter; y++) {
	for (p=1; p <= itemQty[y]; p++) itemCounter++;
  }
  document.close();
//  document.write(itemCounter + '<br>');
}


// ****Debugging function to display cookie contents.****
function showMe() {
 //display = getCookieData("Scart");
 document.write(getCookieData("Scart"));
 //alert(display)
}



// Parse cookie and extract the ordered items from the string.  
// Calls calculate() to do math 
// Calls writeCart() to display the shopping cart
// The following delimiters are used @, {, ^, ', *, ~, }, ?, % 
function loadCart() {
 if (getCookieData('Scart')) {
  writeCart();
 }
}

function writeItemCounter() {
 if (getCookieData('Scart')) {
  if (itemCounter == 1) {
    document.write('<center><font color=#0000CC size=-2" face="Arial,Verdana, Helvetica"><b>' + itemCounter + '</b><\/font><font color=#990033 size=-2" face="Arial,Verdana, Helvetica"><b> item in your cart</b><\/font><\/center>')
  } else {
    document.write('<center><font color=#0000CC size=-2" face="Arial,Verdana, Helvetica"><b>' + itemCounter + '</b><\/font><font color=#990033 size=-2" face="Arial,Verdana, Helvetica"><b> items in your cart</b><\/font><\/center>')
  }
 } else {
 document.write('<center><font color=#990033 size=-2" face="Arial,Verdana, Helvetica"><b>Cart Is Empty</b><\/font><\/center>');
 }
 document.close();
}


// function: calculate()
// ---------------------
// Calculate Item subtotal, shipping subtotal, and overall Sub-total
function calculate() {
  var sub_total_temp = 0;
  var normal_sub_total_temp = 0;
  var ind_special_counter = 0;
  var startvalue = 0;
  var six_dollar_counter = 0;
  var twelve_dollar_counter = 0;
  var twenty_dollar_counter = 0;
  dendrobiumQty = 0;
  phalaenopsisQty = 0;
  budded_special_qty = 0;
  giftpackage_qty = 0;
  ind_special_qty = 0;
  
  //document.write(counter + "    ");
  // Counter 1
  for (y = 1; y <= counter; y++) {
  	// dendrobium and phalaenopsis adjustments
	//if (shippingType[y] == "dendrobium") {
    //    for (p=1; p <= itemQty[y]; p++) dendrobiumQty++;
	//}
	if (shippingType[y] == "budded" || shippingType[y] == "budded45") {
        for (r=1; r <= itemQty[y]; r++) budded_special_qty++;
        //document.write(budded_special_qty);
 	    //document.write("   ");			
	}	
	if (shippingType[y] == "giftpackage") {
        for (s=1; s <= itemQty[y]; s++) giftpackage_qty++;
	}	
	// BULK ORDERING RESTORE
	//if (itemCost[y] == "4.5") {
    //    itemCost[y]="6";
	//}
	//if (itemCost[y] == "5") {
    //    itemCost[y]="6";
	//}
	//if (itemCost[y] == "10.5") {
    //    itemCost[y]="12";
	//}
	//if (itemCost[y] == "9") {
    //    itemCost[y]="12";
	//}
	//if (itemCost[y] == "17.5") {
    //    itemCost[y]="20";
	//}
	//if (itemCost[y] == "15") {
    //    itemCost[y]="20";
	//}
	//
  }
  
  // Counter 2
  //for (k = 1; k <= counter; k++) {
  	// BULK ORDERING COUNTER
	//if (itemCost[k] == "6") {
    //    for (p=1; p <= itemQty[k]; p++) six_dollar_counter++;
	//}
	//if (itemCost[k] == "12") {
    //    for (p=1; p <= itemQty[k]; p++) twelve_dollar_counter++;
	//}
	//if (itemCost[k] == "20") {
    //    for (p=1; p <= itemQty[k]; p++) twenty_dollar_counter++;
	//}
  //}
   
  // Counter 3
  for (z = 1; z <= counter; z++) {
    // BULK ORDERING DISCOUNT
	//if (itemCost[z] == "20" && twenty_dollar_counter > 5 && twenty_dollar_counter < 12) {
	//if (itemCost[z] == "20" && twenty_dollar_counter > 5) {
        //itemCost[z] = 17.50;
		//shippingValue[z] = 17.50;
	//}
	//if (itemCost[z] == "20" && twenty_dollar_counter > 11) {
    //    itemCost[z] = 15;
	//	shippingValue[z] = 15;
	//}
	//if (itemCost[z] == "12" && twelve_dollar_counter > 5 && twelve_dollar_counter < 12) {
	//if (itemCost[z] == "12" && twelve_dollar_counter > 5) {
        //itemCost[z] = 10.50;
		//shippingValue[z] = 10.50;
	//}
	//if (itemCost[z] == "12" && twelve_dollar_counter > 11) {
    //    itemCost[z] = 9;
	//	shippingValue[z] = 9;
	//}
	//if (itemCost[z] == "6" && six_dollar_counter > 5 && six_dollar_counter < 12) {
	//if (itemCost[z] == "6" && six_dollar_counter > 5) {
        //itemCost[z] = 5;
		//shippingValue[z] = 5;
	//}
	//if (itemCost[z] == "6" && six_dollar_counter > 11) {
    //    itemCost[z] = 4.50;
	//	shippingValue[z] = 4.50;
	//}
  

	// phalaenopsis adjustments
	//if (shippingType[z] == "phalaenopsis" && phalaenopsisQty > 9) {
    //    itemCost[z] = 12;
	//	shippingValue[z] = 12;
	//}
	//if (shippingType[z] == "phalaenopsis" && phalaenopsisQty < 10) {
    //    itemCost[z] = 18;
	//	shippingValue[z] = 18;
	//}
	// if there are 3 or more budded specials, then change price such that 3 add up to $102
	if (shippingType[z] == "budded" && budded_special_qty > 2) {
        itemCost[z] = 34;
	}
	if (shippingType[z] == "budded45" && budded_special_qty > 2) {
		itemCost[z] = 34;
	}
	if (shippingType[z] == "budded" && budded_special_qty < 3) {
		itemCost[z] = 38;
	}
	if (shippingType[z] == "budded45" && budded_special_qty < 3) {
		itemCost[z] = 45;
	}
	// for different quantities of packages, need to change the shipping cost
	if (shippingType[z] == "giftpackage" && giftpackage_qty < 2) {
        //if (itemCost[z] == 104) {
    	shippingValue[z] = 39;
		//}
		//if (itemCost[z] == 97.5) {
    	//    shippingValue[z] = 32.50;
		//}
		//if (itemCost[z] == 84) {
    	//    shippingValue[z] = 26.50;
		//}
	}

	if (shippingType[z] == "giftpackage" && giftpackage_qty == 2) {
		shippingValue[z] = 24;
	}
	if (shippingType[z] == "giftpackage" && giftpackage_qty > 2) {
        shippingValue[z] = 18;
	}
	// for the independent plants (2003 winter specials) shipping is $7.5, $10, and $12
	// for the first plant and $5 for each additional
	//if (shippingType[z] == "ind_special1" || shippingType[z] == "ind_special2" || shippingType[z] == "ind_special3") {
	//	ind_special_counter++;
	//	if (z == 1) {
	//			if (shippingType[z] == "ind_special1") {
	//				shippingValue[z] = eval((12 + 5*(itemQty[z]-1))/itemQty[z]);
	//			}
	//			if (shippingType[z] == "ind_special2") {
	//				shippingValue[z] = eval((7.5 + 5*(itemQty[z]-1))/itemQty[z]);
	//			}
	//			if (shippingType[z] == "ind_special3") {
	//				shippingValue[z] = eval((10 + 5*(itemQty[z]-1))/itemQty[z]);
	//			}
	//	}
    //  if (z > 1) {
	//		shippingValue[z] = 5;
	//		//document.write(shippingValue[z]);
	//	}
	//}
    //document.write(itemCost[z] + ' &nbsp;&nbsp;&nbsp;' + shippingValue[z] + '<br>');
    extCost[z]=eval(itemCost[z]*itemQty[z]);
    qtyShipCost[z]=eval(shippingValue[z]*itemQty[z]);
   	if (shippingType[z] == "phalaenopsis") {
        eval('normal_sub_total_temp += parseFloat(extCost[' + z + ']);');
	}
	if (shippingType[z] == "dendrobium") {
        eval('normal_sub_total_temp += parseFloat(extCost[' + z + ']);');
	}
	if (shippingType[z] == "normal") {
        eval('normal_sub_total_temp += parseFloat(extCost[' + z + ']);');
	}
    //document.write(extCost[z] + ' &nbsp;&nbsp;&nbsp;' + shippingType[z] + ' &nbsp;&nbsp;&nbsp;' + qtyShipCost[z] + '<br>');
    eval('sub_total_temp += parseFloat(extCost[' + z + ']);');
  }
  // DIAGNOSTIC
  //document.write("Phalaenopsis = " + phalaenopsisQty + "plants");	
  //
  normal_sub_total = fix(normal_sub_total_temp);
  sub_total = fix(sub_total_temp);
  //
  // Variable used to calculate final shipping: shipping_total
  var shipping_total_temp = 0;
  // Temp values used for calculations
  var special_shipping_temp = 0;
  var package_shipping_temp = 0;
  var normal_shipping_temp = 0;
  var wholesale_shipping_temp = 0;
  // Values that when multiplied by corresponding percentage provide 'temp' values
  var special_shipping_value = 0;
  var package_shipping_value = 0;
  var normal_shipping_value = 0;
  var wholesale_shipping_value = 0;
  // Calculate subtotal for different types of shipping
  for (v=1; v <= counter; v++) {
    if (shippingType[v] == "special") eval('special_shipping_value += parseFloat(qtyShipCost[' + v + ']);');
    // Note: package shipping value should have the exact shipping cost in the load function
    if (shippingType[v] == "package" || shippingType[v] == "giftpackage" || shippingType[v] == "ind_special1" || shippingType[v] == "ind_special2" || shippingType[v] == "ind_special3") {
		eval('package_shipping_value += parseFloat(qtyShipCost[' + v + ']);');
	}
    if (shippingType[v] == "normal") eval('normal_shipping_value += parseFloat(qtyShipCost[' + v + ']);');
    //if (shippingType[v] == "phalaenopsis") eval('normal_shipping_value += parseFloat(qtyShipCost[' + v + ']);');
    if (shippingType[v] == "dendrobium") eval('normal_shipping_value += parseFloat(qtyShipCost[' + v + ']);');
    if (shippingType[v] == "scriptum") eval('package_shipping_value += parseFloat(qtyShipCost[' + v + ']);');
    if (shippingType[v] == "wholesale") eval('wholesale_shipping_value += parseFloat(qtyShipCost[' + v + ']);');
  }
  //document.write(special_shipping_value + ' - ' +package_shipping_value  + ' - ' + normal_shipping_value  + ' - ' + wholesale_shipping_value + '<br>');
  //
  // Special shipping
  if (special_shipping_value >0 && special_shipping_value <= 50) {
    special_shipping_temp = 10;
  } else {
    special_shipping_temp = special_shipping_value * 0.15;
  }
  //
  // Package shipping
  package_shipping_temp = package_shipping_value;
  //
  // Normal shipping
  if (normal_shipping_value > 0 && normal_shipping_value < 25) {
    normal_shipping_temp = 5;  // Code to allow for minimum shipping cost
  } 
  if (normal_shipping_value >= 25) {
    normal_shipping_temp = normal_shipping_value * 0.20;
  }
  //
  // Wholesale shipping
  if (wholesale_shipping_value >0 && wholesale_shipping_value <= 50) {
    wholesale_shipping_temp = 10;
  } else {
    wholesale_shipping_temp = wholesale_shipping_value * 0.20;
  }
  //
  // Calculate total shipping
  shipping_total_temp = special_shipping_temp + package_shipping_temp + normal_shipping_temp + wholesale_shipping_temp;
  shipping_total = fix_dec(shipping_total_temp,1);
  //
  // Packing charge of $6 only applies to items markes as "normal" shipping
  packing_charge = fix_dec(0,1);  
  if (normal_shipping_temp > 0) {
    packing_charge = fix_dec(packing_charge_default,1);
  }
}
  
// function: writeCart()
// ---------------------
// Function to write the shopping cart details
// into the table on the shopping cart page.
function writeCart() {
  var ordFrm = '<br><form name="shopCart" action="https://ssl.maui.net/order-bin/order_all.pl?orchids " method="post">'
  // Continue shopping button
  ordFrm += '<table width="700" border=0 cellspacing="0" cellpadding="0" align=center ><tr><td align=left>'
  ordFrm += '<a href="javascript:history.go(-1)"><img border=0 src="pictures/continueshopping.gif"></a>' 
  ordFrm += '</td></tr></table>'
  // Space
  ordFrm += '<table width="640" border=0 cellspacing="0" cellpadding="0" align=center ><tr height=5><td></td></tr></table>'
  // Not budded or blooming statement
  ordFrm += '<table width="640" border=1 cellspacing="0" cellpadding="2" bordercolor=#000099 align=center bgcolor=#FFEEFF>'
  ordFrm += '<tr><td align=middle ><font color=#CC0000><b>Unless stated, the plants you order are NOT BUDDED OR BLOOMING.&nbsp; '
  ordFrm += '<br><font size=-1>Some exceptions include "gift baskets" & "budded or blooming specials".'
  ordFrm += '<br>Please call in your order to check "budded or blooming" availability for a specific orchid plant. </font></b></font></td></tr></table>'
  // Space
  ordFrm += '<table width="640" border=0 cellspacing="0" cellpadding="0" align=center ><tr height=5><td></td></tr></table>'
  ordFrm += '<table width="640" border=0 cellspacing="0" cellpadding="0" align=center >'
  // Generate shopping cart titles
  ordFrm += '<tr><td><font size="-1" face="Arial, Helvetica"><b>Your Shopping Cart</b></font></td></tr>'
  ordFrm += '</table>'
  ordFrm += '<table width="640" border=1 cellspacing="0" cellpadding="3" bgcolor="#FFEEFF" bordercolor="#000099" align=center>'
  ordFrm += '<tr bgcolor=#CCCCFF>'
  ordFrm += '<td align="center"><b><font face="Arial" size="-1">Item</font></b></td>'              
  // ****Removed description and replaced with image
  //ordFrm += '<td align="center"><b><font face="Arial" size="-1">Description</font></b></td>'
  ordFrm += '<td align="center"><b><font face="Arial" size="-1">Image</font></b></td>'
  ordFrm += '<td align="center"><b><font face="Arial" size="-1">Item Price</font></b></td>'
  ordFrm += '<td align="center"><b><font face="Arial" size="-1">Quantity</font></b></td>'
  ordFrm += '<td align="center"><b><font face="Arial" size="-1">Quantity Price</font></b></td>'
  ordFrm += '<td align="center"><b><font face="Arial" size="-1">Click to<br>Remove</font></b></td>'
  ordFrm += '</tr>'
  // Generate shopping cart items
  for (i = 1; i <= counter; i++) {
    ordFrm += '<tr>'
    ordFrm += '<td width=140><font face="Arial" size="-1">' + itemName[i] + '</font>'
    ordFrm += '<input type="hidden" name=product_' + catNum[i] + i + ' value="' + itemQty[i] + '" >'
    // Previous code to attach shipping to each item
    //     ordFrm += '<input type="hidden" name=itemnumber' + i + ' value="' + itemCost[i] + '.00|' + itemCost[i] + '|' + itemName[i] + '">'
    // Alternate code to allow for multiple shipping types.  It places the total shipping cost in only the last item in the cart.
	if (i == 1) {
      ordFrm += '<input type="hidden" name=' + catNum[i] + i + ' value="' + itemCost[i] + '|' + shipping_total/itemQty[i] + '|' + itemName[i] + '">'
    } else {
      ordFrm += '<input type="hidden" name=' + catNum[i] + i + ' value="' + itemCost[i] + '|' + '0' + '|' + itemName[i] + '">'
    }
    ordFrm += '</td>'
	// ****Removed description and replaced with image
    //ordFrm += '<td align="center"><font face="Verdana, Arial" size="-2">' + itemDescr[i] + '</font></td>'
	ordFrm += '<td align="center"><font face="Verdana, Arial" size="-2">' 
 	if (image[i] != "") {
		ordFrm += '<a href="pictures/' + image[i] + 'a.jpg" target="_blank"><img src="pictures/' + image[i] + 'b.jpg"></a>'
	} else {
		ordFrm += '&nbsp;'
	}
	ordFrm += '</font></td>'
    ordFrm += '<td align="center"><font face="Arial" size="-1">$' + itemCost[i] + '</font></td>'
    ordFrm += '<td width=80 align="center">&nbsp;<input type="text" name="q'+i+'" size="2" value="'+itemQty[i]+'" size="3">&nbsp;&nbsp;'
    ordFrm += '<a href="javascript:updateItem()"><img src="pictures/update2.gif" border=0 alt=update></a></td>'
    ordFrm += '<td width=55 align="center"><font face="Arial" size="-1">$' + fix(extCost[i]) + '</font></td>'
    ordFrm += '<td width=82 align=center><a href="javascript:deleteItem('+i+')"><img src="pictures/delete.gif" border=0 align="bottom" alt=update></a></td></tr>'
  }
  ordFrm += '</table>'
  // Packing charge
  if (packing_charge > 0) {
    ordFrm += '<input type="hidden" name=product_packingcharge value="1" >'
    ordFrm += '<input type="hidden" name=packingcharge value="' + packing_charge + '|0|Packing Charge">'
  }
  // Sub-Total 
  ordFrm += '<table width="640" border=0 cellspacing="0" cellpadding="0" align=center >'
  ordFrm += '<tr><td align="right">'
  ordFrm += '<b><font face="Arial" size="-1">Subtotal: &nbsp;$ '
  ordFrm += sub_total
  ordFrm += '</font></b>' 
  ordFrm += '</td>'
  ordFrm += '<td width="103" align="right">'
  ordFrm += '&nbsp;'
  ordFrm += '</td></tr>'
  ordFrm += '</table>'
  // Shipping
  ordFrm += '<table width="640" border=0 cellspacing="0" cellpadding="0" align=center >'
  ordFrm += '<tr><td align="right">'
  ordFrm += '<b><font face="Arial" size="-1">Shipping total: &nbsp;$ '
  ordFrm += shipping_total
  ordFrm += '</font></b>' 
  ordFrm += '</td><td width="103" align="right">'
  ordFrm += '&nbsp;'
  ordFrm += '</td></tr>'  
  ordFrm += '<tr><td align="right">'
  ordFrm += '<b><font face="Arial" size="-1">Packing Charge: &nbsp;$ '
  ordFrm += packing_charge
  ordFrm += '</font></b>' 
  ordFrm += '</td>'
  ordFrm += '<td width="103" align="right">'
  ordFrm += '&nbsp;'
  ordFrm += '</td></tr>'
  ordFrm += '</table>'
  ordFrm += '<br>'
  // Begin Button Functions
  ordFrm += '<table width="640" border=0 cellspacing="0" cellpadding="0" align=center>'
  ordFrm += '<tr valign="middle">'
  // Empty Cart Button
  ordFrm += '<td width="250" height="35" align="left">'
  ordFrm += '<a href="javascript:killCart()"><img src="pictures/emptycart.gif" border=0 alt=update></a>' 
  ordFrm += '</td>'
  // Text asking if anything has changed
  ordFrm += '<td width="280" height="35" align="right">'
  ordFrm += '<font face="Arial, Helvetica, sans-serif" color="#990033" size="-1"><b>Change anything? &nbsp;Click&nbsp;</b></font>'  
  ordFrm += '</td>'
  // Update quantity values in cookie
  ordFrm += '<td align="left">'
  ordFrm += '<a href="javascript:updateItem()"><img src="pictures/update2.gif" border=0 alt=update></a>'
  ordFrm += '</td>'  
  // Text, more of it
  ordFrm += '<td width="200" height="35" align="right">'
  ordFrm += '<font face="Arial, Helvetica, sans-serif" color="#990033" size="-1"><b> before Checking Out!</b></font>'  
  ordFrm += '</td></tr>'
  ordFrm += '<tr valign="middle">'
  ordFrm += '<td width="640" valign="middle" align="right" colspan="4">'
  // ordFrm += '<input type=hidden value=special name=shipper>'
  ordFrm += '<input type=hidden value=exact name=shipper>'
  // Checkout button
  ordFrm += '<input type=image name=submit border=0 src="pictures/checkout_off1.gif" align="bottom">'
  ordFrm += '</td>'
  ordFrm += '</tr>'
  ordFrm += '</table><br>'
  // Regular shipping cost explanation
  ordFrm += '<table width="500" border="1" cellspacing="0" cellpadding="5" align="center" bordercolor="#0000CC">'
  ordFrm += '<tr bgcolor="#FFEEFF"><td height="52"><div align="center"><b><font face="Trebuchet MS, Tahoma, Arial, sans-serif" color=#0000CC>'
  ordFrm += 'For regular catalog orders, Shipping is 20% per item (with a <br>minimum of $5.00) along with a '
  ordFrm += 'Packing Charge of $' 
  ordFrm += packing_charge_default
  ordFrm += '.00.</b></font></div></td></tr></table>'
  ordFrm += '</form>'
  document.write(ordFrm);
  document.close();
}


// ** Delete Function removes the selected item from the cart. **
function deleteItem(num) {
 itemName[num] = "item"
 rewriteCookie()
}

// ** UpdateItem: Function to update quantity of items, shipping, and sub-total. **
function updateItem() {
 deleteValue = 0
 dataUpdate = ""
 for (i=1; i<=counter; i++) {
 	newitemQty[i]=eval("document.shopCart.q"+i+".value");
    a = eval("newitemQty[i]")
	if (newitemQty[i] == 0) {
      itemName[i] = "item"
      deleteValue = deleteValue + 1
    }
    for (var j = 0; j < a.length; j++) {
      var oneChar = a.substring(j, j + 1)
      if (oneChar < "0" || oneChar > "9") {
//       alert("Please make sure entries are numbers only.")  
       newitemQty[i] = itemQty[i]
      }
    }
	// Wholesale price adjustments based on quantity
	if (shippingType[i] == "wholesale") {
	  if (newitemQty[i] < 25) {
        newitemQty[i] = 25;
        alert("Wholesale orders and Gift Certificates are a minimum of $25.00");
        increaseCost(i);
      }
      if (newitemQty[i] >= 50 && itemQty[i] < 50) {
        reduceCost(i);
      }
      if (newitemQty[i] < 50 && itemQty[i] >= 50) {
        if (itemCost[i] != 1) alert("Wholesale orders less than 50 have a higher price.");
        increaseCost(i);
      }
	}
	// End wholesale price adjustments
	//
    if (itemName[i] != "item") {
      dataUpdate += itemName[i] + '{' + newitemQty[i] + '*' + image[i] + '~$' + itemCost[i] + '}' + catNum[i] + '^' + shippingType[i] + '%$'+ shippingValue[i] + '?'
    }
 }
 counter = counter - 1 - deleteValue
 cookData = dataUpdate
 setCookieData("Scart", cookData, expdate.toGMTString())
 onLoad=window.setTimeout("location.href='scart.html'",000)
}

// Wholesale increase cost function
function increaseCost(num) {
  if (itemCost[num] == 11.5) {
	itemCost[num] = 14;
    shippingValue[num] = 14;
  }
  if (itemCost[num] == 9.75) {
    itemCost[num] = 11;
    shippingValue[num] = 11;
  }
}

// Wholesale reduce cost function
function reduceCost(num) {
  if (itemCost[num] == 14) {
	itemCost[num] = 11.5;
    shippingValue[num] = 11.5;
  }
  if (itemCost[num] == 11) {
    itemCost[num] = 9.75;
    shippingValue[num] = 9.75;
  }
}

// **Function to rewrite the cookie when the user **
// **deletes a line item from the shopping cart. **

function rewriteCookie() {
 dataUpdate = ""
 for (i=1; i<=counter; i++) {
   if (itemName[i] != "item") {
    dataUpdate += itemName[i] + '{' + itemQty[i] + '*' + image[i] + '~$' + itemCost[i] + '}' + catNum[i] + '^' + shippingType[i] + '%$'+ shippingValue[i] + '?'
   }
 }
 counter = counter - 2
 cookData = dataUpdate
 setCookieData("Scart", cookData, expdate.toGMTString())
 onLoad=window.setTimeout("location.href='scart.html'",000)
}

// ****End shopping cart detail section.****

// ****Start of code section to display subtotal.****

function update() {
// if (getCookieData("Scart")) {
//  var sub_total = 0;
//  var ship_total = 0;
//  for (i=1; i<itemName.length; i++) {
//    eval('sub_total += parseFloat(extCost[' + i + ']);');
//    eval('ship_total += parseFloat(extCost[' + i + ']);');
//  }
//  fix(sub_total);
  //document.shopCart.subtotal.value= fix(sub_total);
// }
}

function fix(num) {
 var decplaces = 2
  var str = "" + Math.round (eval(num) * Math.pow(10,decplaces))
  while (str.length <= decplaces) {
   str = "0" + str
  }
  var decpoint = str.length - decplaces
  return str.substring(0,decpoint) + "." + str.substring(decpoint,str.length);
 return str;
}

function fix_dec(num,decplaces) {
 //var decplaces = 0
 //I want this function rounds down
  var str = "" + Math.round (eval(num) * Math.pow(10,decplaces))
  if (str > (eval(num) * Math.pow(10,decplaces)) ) str = "" + Math.abs (eval(str)-1);
  while (str.length <= decplaces) {
   str = "0" + str
  }
  var decpoint = str.length - decplaces
  str = str.substring(0,decpoint) + "." + str.substring(decpoint,str.length);
  for (i=2; i>decplaces; i--) {
   str = str + "0"
  //return str.substring(0,decpoint) + "." + str.substring(decpoint,str.length);
  }
 return str;
}

// **Function to clear the shopping cart.**

function killCart() {
 killCookie("Scart")
 history.go(-1)
}


// ****Function to reset the form elements everytime the page loads.  Remove the
// ****onLoad() event handler from the catalog body tags to eliminate this feature.
function clearQtys() {
 document.form1.reset()
}


// **Read cookie data.**
function getCookieData(name) {
	var label = name + "="
	var labelLen = label.length
	var cLen = document.cookie.length
	var i = 0
	while (i < cLen) {
		var j = i + labelLen
		if (document.cookie.substring(i,j) == label) {
			var cEnd = document.cookie.indexOf(";",j)
			if (cEnd == -1) {
				cEnd = document.cookie.length
			}
			return unescape(document.cookie.substring(j,cEnd))
		}
		i++
	}
	return ""
}



// **Write cookie data**
function setCookieData(name,value,expires) {
        counter ++
	document.cookie = name + "=" + counter + "@" + value + "; expires=" + expires
}




// **Kill cookie function. When the order is submitted**
// **the cookie is killed via an event handler call.**

function killCookie(name) {
 if (getCookieData(name)) {
 document.cookie = name + "=" + "; expires = Thu, 01-Jan-70 00:00:01 GMT";
 cookData = ""
 counter = 0
// history.go(0)
 }
}
// ****End shared cookie functions****

