var blk1  = "https://www.paypal.com/cgi-bin/webscr?cmd=_cart";
var blk1a = "&add=1";
var blk1d = "&display=1";
var blk1u = "&upload=1";
var blk2  = "&business=";
var blk2a = "&quantity=";
var blk2q = 0;
var blk3  = "&item_name=";
var blk3n = "";
var bcode = "";
var blkcc = "";
var blkhn = "";  // item handling charges
var blksh = "";  // item shipping charges
var bmisc = "";  // stuff not supported anywhere else.
var op1n  = "";  // option name and value
var op1v  = "";
var op2n  = "";
var op2v  = "";
var blk4  = "&amount=";
var blk4a = "6.66";
var imgx  = "dummy.jpg";  // place for cart thumbnail image
var winpar = "width=710,height=500,scrollbars," +
             "location,resizable,status,menubar,toolbar";

var cmax  = 16;            // max items in cart
var cats  = 5;             // max number of categories allowed
var pcat  = 0;             // item product category
var ctot  = new Object (); // amt & qty totals by pcat

var stax  = 0;      // regional (state) tax percent
var ttxt  = "";     // tax text.
var ttax  = 0;
var hand;           // cart totals
var ship;
var tpkg;           // total packages
var qtyd;
var tqty = 0;       // the total quantity of items ordered
var cook;           // place for item cookie object
var tprc = 0;       // total price of items in cart
var tozs = 0;       // total ounces of order
var bozs = 0;       // subtotal for item
var gtot;           // order grand total
var insx = 0;       // insurance total

var dqty = new Array ();  // item discount qty breakpoint
var damt = new Array ();  // percent discount
var dn   = 0;             // number of discount brkpts

var aqty = new Array ();  // item quantity amt breakpoint
var aamt = new Array ();  // price at breakpoint
var an   = 0;             // number of amt brkpts

var iqty = 0;             // minimum item quantity to order
var xqty = 1000000;       // maximum item quantity to order

var zn   = 0;             // count of zip/zone pairs
var zzip = new Array ();  // zip code
var zone = new Array ();  // zone for that zip

var cdis = 0;             // percdnt coupon discount
var camt = 0;             // amount coupon discount
var gcamt = 0;			  // gift certificate amount
var coupval = "";         // coupon value user entered
var coupons = new Array ("coup1", "coup2");
var couponp = new Array (10,15);  // discount percent
var coupona = new Array (0,1);    // discount amount
var cval = "";            // recorded ocupon value
var ctxt = "";            // coupon text
var coup = -1;            // cart discount coupon not active
var csdsc = 0;            // indicate a one-time or per item discount (default is FALSE - user per item)

// stuff for shipping support...
var zip;        // shipping zip code
var wte;        // total weight of order
var zne = 0;    // shipping zone
var amt;        // priority shipping charge
var usps = -1;  // flag for USPS priority shipping
var uspp = -1;  // flag for USPS parcel post
var ups  = -1;  // flag for UPS ground, lower 48
var insu = -1;  // flag for insurance

var gwtot = 0;            // Gift wrapping total

// cart display options...
var on  = 1;       // on and off variables
var off = 0;
 

function AddDesc (strn) {  // add to current description
var c = "";
  if (blk3n.length > 0) c = ", ";
  blk3n = blk3n + c + strn;
}

function AddMisc (strn) {  // add extra stuff to PayPal params
var s = "&";
  if (strn.substring(0,1) == "&") s = "";
  bmisc = bmisc + s + escape (strn);
}

function AddOpt1 (val) {  // add to the value in op1v
var c = "";
  if (op1n.length == 0) op1n = "opt1";
  if (op1v.length > 0) c = ", ";
  op1v = op1v + c + val;
}

function AddOpt2 (val) {  // add to the value in op2v
var c = "";
  if (op2n.length == 0) op2n = "opt2";
  if (op2v.length > 0) c = ", ";
  op2v = op2v + c + val;
}

function AddPrcnt (strn) {    // add a percent to the price
  SetPrice (blk4a * (1.0 + strn/100.0));  // add the percent
}

function AddPrice (strn) {  // add to current price
  blk4a = Dollar (blk4a*1.0 + strn*1.0);
}

function AddWt (ozs) {  // set the weight of an item
  bozs = ozs*1.0 + bozs*1.0;
}

function CalcInsu (amt) {  // calculate insurance on an amount
//  it equals $2.20 + $1.00 per hundred
if (amt == 0) return 0;
if (amt <= 50) return 1.30;
return (2.20 + Math.floor (amt / 100.0));
}

function CallPay () { // call the PayPal shopping cart
var strn,cartwin;
  blkcc = "";                  // check default settings
  if (root.xx_cur.length > 0)  // record currency entry 
    blkcc = blkcc + "&currency_code=" + root.xx_cur;
  if (root.xx_lc.length > 0)   // record user entry
    blkcc = blkcc + "&lc=" + root.xx_lc;
  if (root.xx_can.length > 0)  // set cancel return path
    blkcc = blkcc + "&cancel_return=" + root.xx_can;
  if (root.xx_ret.length > 0)  // set return path 
    blkcc = blkcc + "&return=" + root.xx_ret;
  if (root.xx_sty.length > 0)  // set display style
    blkcc = blkcc + "&page_style=" + root.xx_sty;
//  if (root.cval.length > 0)    // set coupon value selected <--- Check this code
//    blkcc = blkcc + "&invoice=" + root.ctxt;
  strn = blk1 + blk1u + blk2 + root.xx_id + blkcc + bmisc + Xbuild ();
  ClearAll ();
  cartwin = window.open (strn, "paypal", winpar);
  cartwin.focus ();
  self.close ();
}

function CallView () { // call the local shopping cart view
var cartwin;

  //CheckInstantDiscount();			// Chcek for discount based on cart total
  //CheckInstantDiscountForItem();  // Check for additional discount based on quantity
  
  cartwin = window.open ("cart.htm", "local29", winpar);
  cartwin.focus ();
}

function GetPromoCookie(c_name)	// Get the promo cookie
{
  if (document.cookie.length>0)
  { 
    c_start=document.cookie.indexOf(c_name + "=")
    if (c_start!=-1)
    { 
      c_start=c_start + c_name.length+1 
      c_end=document.cookie.indexOf(";",c_start)
      if (c_end==-1) c_end=document.cookie.length
        return unescape(document.cookie.substring(c_start,c_end))
    } 
  }
  return ""
}

function SpecialCouponProcessing (acoupon) {
var j;
var promo_disc;				// Promo discount
var cart_total_with_promo;	// Cart total minus the current instant promo
var total_disc;				// Total discount to be deducted (gift certificate + promo discount)

	// Initialize variables
	promo_disc = 0;
	cart_total_with_promo = 0;
	total_disc = 0;
	
	// Check for free shipping coupon
	if (acoupon == "SHIP4FREE10") {
		// Clear shipping charges here
  		root.ship = 0;	// reset shipping amount
  		root.store ();

		// Because the free shipping code is 'special', we need to tell the user that it was accepted here
		alert("FREE SHIPPING coupon code accepted!");
		ctxt = "COUPON - Free Shipping";				// This will show up on PayPal's shopping cart
		return true;
	}
	
	// Check for UK shipping coupon
	if (acoupon == "UKSHIPPING") {
		// Clear shipping charges here
  		root.ship = 72.50;	// reset shipping amount
  		root.store ();

		// Because the free shipping code is 'special', we need to tell the user that it was accepted here
		alert("Special UK SHIPPING coupon code accepted!");
		ctxt = "COUPON - Special UK Shipping";				// This will show up on PayPal's shopping cart
		return true;
	}
	
	//
	// Check for Facebook 15% discount
	//
	if (acoupon == "FBT2T15") {
		return true;		// Coupon matches
	}
	
	//
	// Check for 10% discount
	//
	if (acoupon == "DISC10T2T") {
		return true;		// Coupon matches
	}
	//
	// Check for 15% discount
	//
	if (acoupon == "DISC15T2T") {
		return true;		// Coupon matches
	}
	//
	// Check for 20% discount
	//
	if (acoupon == "DISC20T2T") {
		return true;		// Coupon matches
	}
	//
	// Check for $10 Gift Certificate
	//
	//if ((acoupon == "T2T062450018") || 
	//	(acoupon == "T2T062770013") || 
	//	(acoupon == "T2T063040014") || 
	//	(acoupon == "T2T063340017")){
	//	if (tprc > 10) {	// Cart total > $10?
	//		return true;	// Y, accept the coupon code
	//	}
	//	else {
	//		alert('The total cost of items in your shopping cart must be at least $25 before you can use this coupon.');
	//		return false;
	//	}
	//}
	//
	// Check for island zest salad dressing winner gift certificates
	//
	if (acoupon == "T2TGC10001") {
	    // Check to see if item total is greater than the gift certificate amount
		// If it is less, do not allow the user to apply the gift certificate
		promo_disc = (tprc * (root.cdis/100.0));
		cart_total_with_promo = tprc - promo_disc;
			
		if (cart_total_with_promo >= 50) {	// Item total is at least $50
			// Set $50 gift certificate amount
  			//gcamt = Dollar(50 + promo_disc);
  			gcamt = 50 + promo_disc;
			return true;
		}
		else {				// Item total is less than $50	
			alert('The total cost of items in your shopping cart must be at least $50 before you can redeem this gift certificate.');
			return false;
		}
	}
	return false;
}

function ChkCoup () {  // check for a discount coupon
var i,j;
var cmsg;			  // Coupon message
  coup = -1;          // assume the worst
  csdsc = 0;		  // Assume that coupon discount is applied per item
  gcamt = 0;		  // Clear gift certificate amount
  ctxt = "";		  // Clear coupon text
  cmsg = "";		  // Clear coupon message
  coupons = root.xx_cval.split (",");
  couponp = root.xx_cdis.split (",");
  coupona = root.xx_camt.split (",");
  coupvalUC = coupval.toUpperCase();
  
  for (i=0; i<coupons.length; i++) {
    if (coupvalUC == coupons[i]) {

      coup = 1;              // user hit the coupon value
      cdis = couponp[i];     // remember the discount percent
      camt = coupona[i];     // discount amount 
      cval = coupvalUC;      // remember entered value
	  
	  // SpecialCouponProcessing can override the coupon value (e.g., for gift certificates)
	  if (SpecialCouponProcessing(coupvalUC)) {	
		
      	if (cdis > 0) {
        	cmsg = "Coupon code accepted! \n\n" + cdis + "% discount now in effect.";
       		ctxt = "COUPON - " + cval + " " + cdis + "% discount. ";
      	}
      	if (camt > 0) {
        	cmsg = "Coupon code accepted! \n\n" + "$" + camt + " discount now in effect.";
       		ctxt = "COUPON - " + cval + " $" + camt + " discount. ";
      	}
      	if (gcamt > 0) {
			camt = gcamt;
			cmsg = "$50 Gift Certificate accepted!";
       		ctxt = "$" + Dollar(camt) + " GIFT CERTIFICATE";
      	}
		
		// Alert user if there is a message
		if (cmsg != "") {
			alert(cmsg);
		}
  
      	root.cval = cval;      // remember entered value
      	root.coup = coup;
      	root.cdis = cdis;
      	root.camt = camt;
      	root.ctxt = ctxt;
      	root.xx_coup = off;    // suppress display for user to enter coupon code
      	root.store ();
      	document.location.reload ();  // show the latest info...
      	return;
      }
	}
  }
  alert ("'" + coupval + "' is not a valid coupon code.");
}

function GetProductTotal () {
var i;

  tprc = 0;
  for (i=1; i<cmax; i++) {  // print all entries
    cook = new Cookie (document, "paycart" + i);
    cook.load();
    if (cook.qty > 0) {
  	  tm = Dollar (cook.prc);
	  t1 = cook.qty*1.0;
	  t2 = cook.pcat;
	  tm = Dollar (t1*cook.prc);
	  tprc = tprc*1.0 + tm*1.0;
    }
  }

  return tprc;	// return product total
}

function CheckInstantDiscount () {  // check for a discount coupon
var total;

  ClearCoupon();		// Clear coupon code

  // Initialize variables
  coup = 1;
  cdis = 0;
  camt = 0;
  cval = "";
  total = 0;
  
  total = GetProductTotal();	// get the cart total
  
  //----------------------------------------------------------------------
  // Look for the promo cookie that is set in the special_offers page
  //----------------------------------------------------------------------
  //promocode = GetPromoCookie('t2tpromo');
  //if (promocode!=null && promocode!="") {
    // Found cookie -- Check to see if the value matches the sale
    //if (promocode == 'sale05162010') {
  	  // check the amount of discount that the customer qualifies
  	  //if (total > 25) {
      //  cdis = 20;				// customer qualifies for 20% discount
      //  cval = "MAYMADNESS20";	// set coupon code
  	  //}
    //}
  //}
  //----------------------------------------------------------------------
  
  //
  // check the amount of discount that the customer qualifies for instant discount
  //
  //if (total > 0) {			// if the cart total is > $0
  //  cdis = 20;				// customer qualifies for 20% discount
  //  cval = "BOSS20OFF";		// set coupon code
  //}
  //
  // Check the total cart amount to determine the instant discount that the person qualifies
  //
  //if ((total >= 20) && (total < 50)) {	// cart total >= $20 and < $50
  //  cdis = 15;							// customer qualifies for 10% discount
  //  cval = "HOLIDAY15";					// set coupon code
  //} else
  //if ((total >= 50) && (total < 75)) {	// cart total >= $50 and < $75
  //  cdis = 20;							// customer qualifies for 15% discount
  //  cval = "HOLIDAY20";					// set coupon code
  //} else
  //if (total >= 75) {					// cart total >= $75
  //  cdis = 25;							// customer qualifies for 20% discount
  //  cval = "HOLIDAY25";					// set coupon code
  //}
  
  if (cdis > 0) {
    ctxt = "COUPON-" + cdis + "%" + cval + ". "

    root.cval = cval;      // remember entered value
    root.coup = coup;
    root.cdis = cdis;
    root.camt = camt;
    root.ctxt = ctxt;
    //root.xx_coup = off;    // suppress display
    root.store ();
    //document.location.reload ();  // show the latest info...
    return;
  }
}

function GetItemQuantity (itemcd) {
var i;

  tqty = 0;
  for (i=1; i<cmax; i++) {  // print all entries
    cook = new Cookie (document, "paycart" + i);
    cook.load();
    if (cook.qty > 0) {
	  if (cook.cod == itemcd) {
	    t1 = cook.qty*1.0;
	    tqty = tqty*1.0 + t1*1.0;
	  }
    }
  }

  return tqty;	// return item total
}

function SetItemPrice (itemcd, newprice) {
var i;

  for (i=1; i<cmax; i++) {  // look at all entries
    cook = new Cookie (document, "paycart" + i);
    cook.load();
    if (cook.qty > 0) {
	  if (cook.cod == itemcd) {
  	    cook.prc = newprice;
		cook.store();
	  }
    }
  }
}

function CheckInstantDiscountForItem () {  // check for instant discount for item
var total;

  ClearCoupon();		// Clear coupon code

  // Initialize variables
  itemqty = 0;
  
  itemqty = GetItemQuantity("mix01");	// get the quantity total for item
  
  // check the amount of discount that the customer qualifies
  if ((itemqty >= 3) && (itemqty < 6)) {
    SetItemPrice("mix01", 6.23);	// customer qualifies for 3-5 bottle discount
  } else
  if ((itemqty >= 6) && (itemqty < 12)) {
    SetItemPrice("mix01", 6.20);	// customer qualifies for 6-11 bottle discount
  } else
  if (itemqty >= 12) {
    SetItemPrice("mix01", 6.15);	// customer qualifies for 12+ bottle discount
  }

  document.location.reload ();  // show the latest info...
  return;
}

function ChkFlg (temp) {     // check for special flag char
var pos;
  pos  = temp.indexOf ("@"); // is there a initial value?  
  if (pos >= 0) SetPrice (temp.substring (pos + 1));
  pos  = temp.indexOf ("+"); // is there a price adjustment?  
  if (pos >= 0) AddPrice (temp.substring (pos + 1));
  pos  = temp.indexOf ("%"); // is there a percent adjustment?  
  if (pos >= 0) AddPrcnt (temp.substring (pos + 1));
}

function ChkOpts () {  // check if user has selected everything
  if (tprc < root.xx_mamt || tqty < root.xx_mqty) {  // check minimums
    alert ("You have not yet met the minimum order requirements!");
    return false;
  }
  if (root.xx_chkbx == on && root.chkby == off) {  // agree checkbox
    alert ('You must agree to terms!');
    return false;
  } else
  if (root.xx_tax == on && ttxt.length == 0) {  // tax selection
    alert ('Please select a Tax Rate.');
    return false;
  } else
  if (root.xx_ship == on && root.sv0 == 0) {  // shipping selection
    alert ('Please select a Shipping Method.');
    return false;
  }
  return true;
}

function ClearAll () {  // wipe out the last entry
  blk2q = "";  // quantity
  blk3n = "";  // name
  blk4a = "0"; // price
  bcode = "";  // item number
  bmisc = "";  // extra data
  blkhn = "";  // item handling charges
  blksh = "";  // item shipping charges
  op1n  = "";  // clear options
  op1v  = "";
  op2n  = "";
  op2v  = "";
  imgx  = "dummy.jpg";
  bozs  = 0;
  dn    = 0;
  an    = 0;
  pcat  = 0;
  iqty  = 0;        // minimum item quantity
  xqty  = 1000000;  // max item quantity
}

function ClearCart () {     // zap all the cookies
var i;
  for (i=1; i<cmax; i++) {  // the data cookies
    ClearEntry (i);
  }
  
  ClearCoupon();			// clear coupon code also
  CalcCost();				// Recalculate shipping because the cart is now empty
}

function ClearEntry (i) {  // knock out a specific entry
  cook = new Cookie (document, "paycart" + i);
  cook.load();
  InitData ();
  
  // User deleted something so we have to recalculate the instant discount
  //CheckInstantDiscount();			// Check for discount based on cart total
  //CheckInstantDiscountForItem();  // Check for additional discount based on quantity
}

function ClearCoupon () {  // clear coupon code
  root.cval = 0;
  root.coup = 0;
  root.cdis = 0;
  root.camt = 0;
  root.ctxt = "";
  root.xx_coup = on;
  root.store ();
}

function Cookie(document, name, hours, path, domain, secure) {
  this.$document = document;  // required
  this.$name = name;          // required
  if (hours) this.$expiration = 
      new Date((new Date()).getTime() + hours * 3600000);
  else this.$expiration = null;
//  if (path)   this.$path   = path;   else this.$path   = null;
this.$path = "/";  // force, for now
  if (domain) this.$domain = domain; else this.$domain = null;
  if (secure) this.$secure = true;   else this.$secure = false;
}

function _Cookie_store() {  // store method of cookie object
var cookieval = "";  // clear actual cookie value
  for(var prop in this) {  // Ignore "$" properties, and methods
    if ((prop.charAt(0) == '$') || 
        ((typeof this[prop]) == 'function')) 
        continue;
    if (cookieval != "") cookieval += '&';
    cookieval += prop + ':' + escape(this[prop]);
  }

  var cookie = this.$name + '=' + cookieval;
  if (this.$expiration)
      cookie += '; expires=' + this.$expiration.toGMTString();
  if (this.$path) cookie += '; path=' + this.$path;
  if (this.$domain) cookie += '; domain=' + this.$domain;
  if (this.$secure) cookie += '; secure';
  if (root.xx_cdmp == on)           // cookie diagnostic dump
    alert(cookie.length + " chars - " + cookie);
  this.$document.cookie = cookie;  // store with magic property
}

function _Cookie_load() {  // cookie load function
var i;
var allcookies = this.$document.cookie;
  if (allcookies == "") return false;

  // Now extract just the named cookie from that list.
  var start = allcookies.indexOf(this.$name + '=');
  if (start == -1) return false;   // Cookie not defined for this page.
  start += this.$name.length + 1;  // Skip name and equals sign.
  var end = allcookies.indexOf(';', start);
  if (end == -1) end = allcookies.length;
  var cookieval = allcookies.substring(start, end);

  var a = cookieval.split('&');  // array of name/value pairs.
  for(i=0; i < a.length; i++)  // Break each pair into an array.
    a[i] = a[i].split(':');

  for(i=0; i<a.length; i++)
    this[a[i][0]] = unescape(a[i][1]);

  return true;     // We're done, so return the success code.
}

function _Cookie_remove() {  // the remove method
var cookie;
  cookie = this.$name + '=';
  if (this.$path) cookie += '; path=' + this.$path;
  if (this.$domain) cookie += '; domain=' + this.$domain;
  cookie += '; expires=Fri, 02-Jan-1970 00:00:00 GMT';

  this.$document.cookie = cookie;  // magic store
}

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 InitData () {  // zap a data cookie
  cook.pcat = 0;
  cook.qty  = 0;
  cook.cod  = "";
  cook.cus  = "";
  cook.ihnd = 0;
  cook.des  = "";
  cook.op1n = "";  // option name and value
  cook.op1v = "";
  cook.op2n = "";
  cook.op2v = "";
  cook.prc  = 0;
  cook.ozs  = 0;
  cook.imgx = "dummy.jpg";
  cook.store();    // stash it off
}

function InitRoot () {  // Build the base root cookie
var i;
  root.stax  = stax;     // stuff all base values
  root.ttxt  = ttxt;
  root.coup  = coup;
  root.cval  = cval;
  root.ctxt  = ctxt;
  root.cdis  = cdis;
  root.chkby = off;
  root.gwtot = gwtot;
  root.stxt0 = "";
  root.usps = usps;     // USPS flag
  root.uspp = uspp;     // USPS pp flag
  root.ups  = ups;      // UPS flag
  root.insu = insu;     // insurance flag
  root.zne  = zne;      // destination zone
  root.ship = 0;		// shipping amount for cart
  root.xx_can  = "";
  root.xx_cc   = off;
  root.xx_cdmp = off;
  root.xx_chkbx= off;
  root.xx_coup = on;	// default to allow coupon code
  root.xx_cper = 0;
  root.xx_cur  = "USD";
  root.xx_dadd = on;
  root.xx_img  = off;
  root.xx_lc   = "US";
  root.xx_mamt = 0;
  root.xx_mqty = 0;
  root.xx_pc   = off;
  root.xx_prt  = on;
  root.xx_ret  = "";
  root.xx_ship = off;
  root.xx_siz  = on;
  root.xx_sty  = "";
  root.xx_sum  = off;
  root.xx_tax  = off;
  root.xx_wt   = off;
  root.xx_wtent= "oz";
  root.xx_wtrup= 10;

  for (i=0; i<cats; i++) {
    root["hn" + i]   = 0;             // number of handling brkpts
    root["qd" + i]   = 0;             // number of qty discount
    root["sn" + i]   = 0;             // number of shipping brkpts
    root["av" + i]   = 0;             // number of bkpts
    root["sv" + i]   = 0;             // number of bkpts
    root["wv" + i]   = 0;             // number of bkpts
    root["ct" + 1]   = 0;             // cart amount bkpts
  }
  root.store();
}

function PrintCart () {  // print out entire cart, and get cart totals
var i,wt,p,tmp1,tmp2,s;
  tprc = 0;                 // total price of cart
  tozs = 0;                 // total ounces of order
  gtot = 0;                 // Grand total
  gtot_temp = 0;			// Grand total temporary variable
  ttax = 0;                 // total cart tax
  tqty = 0;                 // total qty of items
  insx = 0;                 // insurance amount

  for (i=0; i<cats; i++) {  // init pcat totals
    ctot["a" + i] = 0;      // amount in this cat
    ctot["q" + i] = 0;      // quantity in this cat
    ctot["h" + i] = 0;      // handling in this cat
    ctot["s" + i] = 0;      // shipping in this cat
    ctot["d" + i] = 0;      // discount in this cat
    ctot["w" + i] = 0;      // weight in this cat
  }
  for (i=1; i<cmax; i++) {  // print all entries
    cook = new Cookie (document, "paycart" + i);
    cook.load();
    if (cook.qty > 0) {
      PrintItem (i);
    }
  }

  tprc = Dollar (tprc)*1.0;             // round, float

  hand = 0;  // line display totals
  ship = 0;
  tpkg = 1;
  qtyd = 0;   

  for (p=0; p<cats; p++) {                 // run product categories
    sh  = 0;                               // local pcat tots
    ha  = 0;
    qt  = 0;

    var q = ctot["q" + p]*1.0;             // quantity this catagory
    var a = ctot["a" + p]*1.0;             // amount this category
    var w = ctot["w" + p]*1.0;
    if (root.xx_wtent == "gm")             // do we fix it?
      w = Math.ceil(w / root.xx_wtrup) * root.xx_wtrup;
    else
      w = Math.ceil(w / 16);
    ctot["w" + p] = w;                     // put back fixed version
  
    if (root["hn" + p] > 0) {
      tmp1 = root["hqty" + p].split(",");
      tmp2 = root["hamt" + p].split(",");
      for (i=root["hn" + p]-1; i>=0; i--) {  // run the table
        if (q >= tmp1[i]*1.0) {              // Check the quantity
          ha = tmp2[i]*1.0;                  // yep, set it
          break;                             // a-dios, mo-fo
        }
      }
    }
    ctot["h" + p] = ha;
    hand = hand + ha;

    if (root["sn" + p] > 0) {
      tmp1 = root["sqty" + p].split(",");
      tmp2 = root["samt" + p].split(",");
      for (i=root["sn" + p]-1; i>=0; i--) {  // run the table
        if (q >= tmp1[i]*1.0) {              // Check the price
          sh = tmp2[i]*1.0;                  // yep, set it
          break;
        }
      }
    }
    if ((sh == 0) && root["sv" + p] > 0) { // one or the other
      tmp1 = root["sval" + p].split(",");
      tmp2 = root["schg" + p].split(",");
      for (i=root["sv" + p]-1; i>=0; i--) {  // run the table (if one)
        if (a >= tmp1[i]*1.0) {  // Check the price
          sh = tmp2[i]*1.0;      // yep, set it
          break;
        }
      }
    }
    if ((sh == 0) && root["wv" + p] > 0) {  // only one shipping
      tmp1 = root["wval" + p].split(",");   // weight based shipping
      tmp2 = root["wchg" + p].split(",");
      for (i=root["wv" + p]-1; i>=0; i--) { // run the table (if one)
        if (w >= tmp1[i]*1.0) {     // Check the weight
          sh = tmp2[i]*1.0;         // yep, set it
          break;
        }
      }
    }
    ctot["s" + p] = sh;
    ship = ship + sh;
    if (root["qd" + p] > 0) {
      tmp1 = root["qqty" + p].split(",");  // qty based, %discount
      tmp2 = root["qamt" + p].split(",");
      for (i=root["qd" + p]-1; i>=0; i--) {
        if (q >= tmp1[i]*1.0) {
          qt = a * tmp2[i]/100.0;
          break;
        }
      }
    }
    if (coup > 0) {				 	// Check to see if there is a coupon
	  if (csdsc == 0) {			 	//   Apply a per item discount?
        qt = qt + a * cdis/100.0;  	//     Apply a per item percent discount
        qt = qt + q/tqty * camt;   	//     Apply a per item amount discount
	  }
    }
    ctot["d" + p] = qt;
    qtyd = qtyd + qt;
  }
  s = 0;  // for special stuff...
  wte = Math.floor ((tozs + 15.999) / 16.0);
  var twte = wte;
  if (usps > 0) {  // usps priority mail
    while (twte > pz2.length) {  // multiple packages?
      tpkg = tpkg + 1;
      twte = Math.floor ((tozs / tpkg + 15.999) / 16.0);
    }
    s = pzx[zne][twte] * tpkg;    // USPS charges to that zone

  } else
  if (uspp  > 0) {  // usps parcel post
    while (twte > pp2.length) {
      tpkg = tpkg + 1;
      twte = Math.floor ((tozs / tpkg + 15.999) / 16.0);
    }
    s = ppx[zne][twte] * tpkg; // UPS charges

  } else
  if (ups  > 0) {  // ups ground
    while (twte > uz2.length) {
      tpkg = tpkg + 1;
      twte = Math.floor ((tozs / tpkg + 15.999) / 16.0);
    }
    s = uzx[zne][twte] * tpkg; // UPS charges
  }
  ship = ship + s;  // only if wt shipping set
  if (insu > 0) insx = CalcInsu (tprc - qtyd);

  ttax = Dollar ((tprc + hand + gwtot*tqty - qtyd) * stax/100.0);
  gtot_temp = tprc + hand + ship + ttax*1.0 + insx - qtyd + gwtot*tqty;
  gtot = Dollar (gtot_temp);

  // Subtract single coupon amount
  if ((coup > 0) && (csdsc == 1)) {
	gtot = Dollar(gtot_temp - camt);		// Deduct single coupon amount from grand total
	qtyd = -camt;							// Notify shopping cart that a single discount was applied
  } 
}

function PrintItem (i) {  // make one entry in cart
var tm,t1,t2,wt;
  document.writeln ('<tr valign = "top"');
  document.writeln ('    align = "right">');
  document.writeln ('  <td>');
  document.writeln ('    <input type  = "checkbox" ');
  document.writeln ('           value = "BOX1"');
  document.writeln ('           onclick = "ClearEntry (', i, ');');
  document.writeln ('                      location.reload ();" />');
  document.writeln ('  </td>');
  document.writeln ('  <td align = "right">',
    cook.qty,'</td>');
  if (root.xx_pc == on) {
    document.writeln ('  <td align = "right">',
      cook.pcat,'</td>');
  }
  document.writeln ('  <td align = "left">',
    cook.cod,'</td>');
  document.writeln ('  <td align = "left">',
    cook.des);
  
  if (cook.ihnd > 0) {  // item-specific handling charges
    document.writeln (', HND=' + Dollar (cook.ihnd));
  }
  if (cook.ishp > 0) {  // item-specific shipping charges
    document.writeln (', SHP=' + Dollar (cook.ishp));
  }
  if (cook.op1n > 0 || cook.op1v > 0 || cook.op2n > 0 || cook.op2v > 0) {
    document.writeln (', ' +
      cook.op1n + ' ' + 
      cook.op1v + ' ' +
      cook.op2n + ' ' +
      cook.op2v,'</td>');
  }
  else {
    document.writeln ('</td>');
  }
  
  tm = Dollar (cook.prc);
  t1 = cook.qty*1.0;
  t2 = cook.pcat;
  document.writeln ('  <td>',
    tm,'</td>');
  tm = Dollar (t1*cook.prc);
  tprc = tprc*1.0 + tm*1.0;
  tqty = tqty + t1;
  ctot["a" + t2] = ctot["a" + t2] + tm*1.0;
  ctot["q" + t2] = ctot["q" + t2] + t1;
  document.writeln ('  <td>',
    tm,'</td>');

  wt = cook.ozs*1.0 * cook.qty;
  tozs = tozs + wt;
  if (root.xx_wt == on) {  // do we show weight?
    document.writeln ('  <td>',
      cook.ozs,'</td>');
    document.writeln ('    <td>',
      wt,'</td>');
  }
  if (root.xx_img == on) {  // display images?
    document.writeln ('  <td align = "center">',
      '<img src = "', 
      cook.imgx,
      '" border="0"');
    if (root.xx_siz == on) 
      document.writeln (' width="80" height="60"');
    document.writeln (' alt = "Image: Item" />',
      '</td>');
  }
  document.writeln ('</tr>');
}

function ReadForm (obj1) { //get form data for PayPal
var i,j,obj,temp,pos,val,nam3,nam4;
var qty  = 0;              // default value
var dis  = 0;              // quantity discount
  for (i=0; i<obj1.length; i++) {     // run whole form
    obj = obj1.elements[i];           // ref particular element
    nam3 = obj.name.substring (0, 3); // 3-char name (maybe)
    nam4 = obj.name.substring (3, 4); // where to store it
    if (obj.type == "select-one") {   // dropdowns
      pos = obj.selectedIndex;        // which option selected
      val = obj.options[pos].value;   // get selection
      ChkFlg (val);                   // check for flag char
      if (nam3 == "opt") {            // user says where to store
        Where (val, nam4);            // stash it
      } else {
        AddDesc (val);                // add to data
      }
    } else
    if (obj.type == "select-multiple") {     // one or more
      for (j=0; j<obj.options.length; j++) { // run all options
        if (obj.options[j].selected) {
          val = obj.options[j].value;
          ChkFlg (val);                   // flag chars?
          if (nam3 == "opt") {            // user says where to store
            Where (val, nam4);            // stash it
          } else {
            AddDesc (val);                // add to data
          }
        }
      }
    } else
    if (obj.type == "checkbox" ||    // boxes
        obj.type == "radio") {
      if (obj.checked) {             // was selected
        val = obj.value;
        ChkFlg (val);                // flag chars?
        if (nam3 == "opt") {         // user says where to store
          Where (val, nam4);         // stash it
        } else {
          AddDesc (val);             // add to data
        }
      }
    } else
    if (obj.type == "text") {  // user input fields
      val = obj.value;         // get input
      if (qty == 0) {          // this is 1st time
        qty = val;             // get user input
        if (qty == "" || qty < 1 || isNaN (qty)) {  // test
          alert ("Enter a valid integer quantity!");
          return false;
        }
      } else {
        if (nam3 == "opt") { // user says where to store
          Where (val, nam4); // stash it
        } else {
          AddDesc (val);     // add to data
        }
      }
    }
  }  // end of loop

  if (qty == 0) qty = 1;     // make sure we have something
  if (qty < iqty) {          // minimum items ordered?
    alert ("You must order at least " + iqty + " of this item!");
    return false;
  }
  if (qty > xqty) {          // maximum items that can be ordered
    alert ("You cannot order more than " + xqty + " of this item!");
    return false;
  }
  blk2q = qty;               // record for posterity

  for (i=an-1; i>=0; i--) {  // qty amount?
    if (qty >= aqty[i]) {    // qty brkpt
      SetPrice (aamt[i]);    // force it
      AddDesc ("AMT");
      break;                 // get out, now
    }
  }

  dis = 0;                   // any qty discounts?
  for (i=dn-1; i>=0; i--) {  // run backwards
    if (qty >= dqty[i]) {    // qty brkpt
      dis = damt[i];         // set qty amount
      break;                 // get out, now
    }
  }
  if (dis > 0) {             // there is an item discount, here
    AddPrcnt (-dis);         // apply the discount
    AddDesc ("Discount=" + dis + "%");  // mark it
  }
  
  CalcCost(); 				 // Reset shipping charges because something may have changed in the cart
    
  StoreCart ();
  if (root.xx_dadd == off) return false;  // hide cart display
  return true;
}

function SetAmtSH (pcat, a1, c1) {   // set cart amt shp brkpts
var i,sv;
var sval = new Array ();
var schg = new Array ();
  if (pcat >= cats) {          // check him out
    alert ("SetAmtSH cat arg too big!");
    return;
  }
  sv = 0;                      // count of breakpoints
  for (i=1; i<arguments.length; i=i+2) {
    sval[sv] = arguments[i];   // price breakpoint
    schg[sv] = arguments[i+1]; // discount amount
    sv = sv + 1;               // number of bkpts
  }
  root["sv" + pcat]   = sv;    // stash that bad boy off
  root["sval" + pcat] = sval;
  root["schg" + pcat] = schg;
  root.store();                // remember forever...
}

function SetCartHN (pcat, q1, c1) {  // set cart hand breakpoints
var i,hn;
var hamt = new Array ();
var hqty = new Array ();
  if (pcat >= cats) {          // check him out
    alert ("SetCartHN cat arg too big!");
    return;
  }
  hn = 0;                      // count of breakpoints
  for (i=1; i<arguments.length; i=i+2) {
    hqty[hn] = arguments[i];   // price breakpoint
    hamt[hn] = arguments[i+1]; // discount amount
    hn = hn + 1;               // number of bkpts
  }
  root["hn" + pcat] = hn;      // stash that bad boy off
  root["hqty" + pcat] = hqty;
  root["hamt" + pcat] = hamt;
  root.store();                // remember forever...
}

function SetCartDC (pcat, q1, c1) {  // set cart qty dis breakpoints
var i,qd;
var qqty = new Array ();
var qamt = new Array ();
  if (pcat >= cats) {          // check him out
    alert ("SetCartDC cat arg too big!");
    return;
  }
  qd = 0;                      // count of breakpoints
  for (i=1; i<arguments.length; i=i+2) {
    qqty[qd] = arguments[i];   // price breakpoint
    qamt[qd] = arguments[i+1]; // discount amount
    qd = qd + 1;               // number of bkpts
  }
  root["qd" + pcat] = qd;      // stash that bad boy off
  root["qqty" + pcat] = qqty;
  root["qamt" + pcat] = qamt;
  root.store();                // remember forever...
}

function SetCartSH (pcat, q1, c1) {  // set cart shp qty breakpoints
var i,sn;
var sqty = new Array ();
var samt = new Array ();
  if (pcat >= cats) {          // check him out
    alert ("SetCartSH cat arg too big!");
    return;
  }
  sn = 0;                      // count of breakpoints
  for (i=1; i<arguments.length; i=i+2) {
    sqty[sn] = arguments[i];   // price breakpoint
    samt[sn] = arguments[i+1]; // handling charge
    sn = sn + 1;               // number of bkpts
  }
  root["sn" + pcat] = sn;      // stash that bad boy off
  root["sqty" + pcat] = sqty;
  root["samt" + pcat] = samt;
  root.store();                // remember forever...
}

function SetCartTX (obj1) {    // set cart tax value
var i,pos;
  pos  = obj1.selectedIndex;   // which item selected
  stax = obj1.options[pos].value;
  ttxt = ' ' + obj1.options[pos].text;
  root.stax = stax;
  root.ttxt = ttxt;
  root.store();                // remember forever...
  document.location.reload ();  // show the latest info...
}

function SetCode (cd) { // set product code
  bcode = cd;
}

function SetDesc (strn) {  // set the desc field
  blk3n = strn;
}

function SetHN (amt) {  // set item-specific handling charges
  blkhn = amt;    // set local variable
  AddPrice (amt); // add in the price
}

function SetID (strn) {  // set the PayPal ID of this user
  blk2b = strn;
}

function SetImg (strn) {  // set the image for the cart
  imgx = strn;
}

function SetOpt1 (nam, val) {  // set the value of 1st option
  op1n = nam;
  op1v = val;
}

function SetOpt2 (nam, val) {  // set the value of 2nd option
  op2n = nam;
  op2v = val;
}

function SetPcat (val) {
  if (val >= cats) {
    alert ("Only " + cats + " product categories allowed!\n\n" +
           "Correct your HTML!");
    return;
  }
  pcat = val;
}

function SetPrice (strn) {  // set the current price
  blk4a = 0;
  AddPrice (strn);
}

function SetQA (q1, a1) {      // set qty amount breakpoints
var i;
  an = 0;                      // count of breakpoints
  for (i=0; i<arguments.length; i=i+2) {
    aqty[an] = arguments[i];   // quantity
    aamt[an] = arguments[i+1]; // amount
    an = an + 1;               // number of discount bkpts
  }
}

function SetQT (q) {           // set minimum item quantity
  iqty = q;
}

function SetQX (q) {           // set maximum item quantity
  xqty = q;
}
function SetQtyD (q1, d1) {    // set item qty discount breakpoints
var i;
  dn = 0;                      // count of breakpoints
  for (i=0; i<arguments.length; i=i+2) {
    dqty[dn] = arguments[i];   // quantity
    damt[dn] = arguments[i+1]; // percent
    dn = dn + 1;               // number of discount bkpts
  }
}

function SetSH (amt) {  // set item specific shipping amount
  blksh = amt;    // set local variable
  AddPrice (amt); // add in the price
}

function SetWgtSH (pcat, w1, c1) {   // ship by weight bkpts
var i,wv;
var wval = new Array ();
var wchg = new Array ();
  if (pcat >= cats) {          // check him out
    alert ("SetWgtSH cat arg too big!");
    return;
  }
  wv = 0;                      // count of breakpoints
  for (i=1; i<arguments.length; i=i+2) {
    wval[wv] = arguments[i];   // price breakpoint
    wchg[wv] = arguments[i+1]; // discount amount
    wv = wv + 1;               // number of bkpts
  }
  root["wv" + pcat]   = wv;    // stash that bad boy off
  root["wval" + pcat] = wval;
  root["wchg" + pcat] = wchg;
  root.store();                // remember forever...
}

function SetWt (ozs) {  // set the weight of an item
  bozs = ozs;
}

function SetZone (zi1, zn1) {  // record zip/zone info into table
var i;
  zn = 0;                      // count of breakpoints
  for (var i=0; i<arguments.length; i=i+2) {
    zzip[zn] = arguments[i];   // zip code index
    zone[zn] = arguments[i+1]; // zone
    zn = zn + 1;               // number of bkpts
  }
}

function StoreCart () {  // store data in local cart
var i;
  for (i=1; i<cmax; i++) {      //check for dup entry
    cook = new Cookie (document, "paycart" + i);  // run
    cook.load();                // get values
    if (cook.qty*1.0 > 0) {     // check it out - combine dups
      if (cook.cod == bcode &&  // check everything!!!
          cook.des == blk3n &&
//          cook.prc*1.0 == blk4a*1.0 &&	Ignore price differences
          cook.op1n == op1n &&
          cook.op1v == op1v &&
          cook.op2n == op2n &&
          cook.op2v == op2v) {
        cook.qty = cook.qty*1.0 + blk2q*1.0;  // combine
        cook.store();
        ClearAll ();
        return;                 // th-th-thats all, folks
      }
    }
  }
  for (i=1; i<cmax; i++) {  // find empty entry
    cook = new Cookie (document, "paycart" + i);
    cook.load();
    if (cook.qty*1.0 == 0 ||
        isNaN (cook.qty)) {
      cook.pcat = pcat
      cook.qty  = blk2q;
      cook.cod  = bcode;
      cook.des  = blk3n;
      cook.ihnd = blkhn;
      cook.ishp = blksh;
      cook.op1n = op1n;
      cook.op1v = op1v;
      cook.op2n = op2n;
      cook.op2v = op2v;
      cook.prc  = blk4a;
      cook.imgx = imgx;
      cook.ozs  = bozs;
      cook.store();
      ClearAll ();
      if (i == cmax - 1)
        alert ("Warning - that was your last cookie!");
      return;      
    }
  }
  alert ("Error 1 - out of cookies!");
}

function Where (val, loc) {  // store val at opt[loc]
  if (loc == 1) AddOpt1 (val);
  else          AddOpt2 (val);
}

function AddItem(i, qty, desc, each) {
var mystr;

  mystr = "&quantity_" + i + "=" + qty;						// Add the quantity
  mystr = mystr + "&item_name_" + i + "=" + escape(desc);	// Assign the description
  mystr = mystr + "&amount_" + i + "=" + each;				// Add the item each price
  
  return mystr;												// Return the constucted string
}

function Xbuild () {         				// build the PayPal string
var i,j;
var tot  = 0;               				// price total
var frst = 1;               				//  1st time thru marker
var str  = "";              				// string to PayPal
var disc = new Array ();    				// price per item to subtract for discount
var total_disc;  							// Total discount per category
var item_disc;								// Per item discount
var item_total_with_disc;					// Item total with discount (qty * each_price) - discount
var item_with_disc;							// Item with discount (each_price - discount)
var rounded_item_disc;						// Rounded per item discount
var price_of_last_item;						// Price of the last item to compensate for rounding errors
var total_item_price;						// Total item price = price per item * quantity
var tmps = root.stxt0+" "+ttxt+" "+ctxt;  	// the shipping text

  for (i=0; i<cats; i++) {  								// set item discounts
    disc[i] = ctot["d" + i] / ctot["q" + i];  				// discount per item
  }

  total_disc = Dollar(ctot["d1"]) * 1.0;					// Total discount for Category 1 items

  j = 0;       												// starting suffix
  for (i=1; i<cmax; i++) {  								// run all the data cookies
    cook = new Cookie (document, "paycart" + i);
    cook.load();         									// get contents

    if (cook.qty > 0) {  									// something here
      j = j + 1;         									// bump suffix

      pc = cook.pcat;  										// product category of this item
      sx = (root["sn" + pc] > 0) ||
//           (root["sv" + pc] > 0) ||
           (root.xx_ship == on)  ||
           (cook.ishp > 0);
    
	  // Intelligently apply the discount amount by taking the total discount and subtacting
	  // as much of the discount from each of the cart items
	  if (total_disc > 0) {
		total_item_price = Dollar(cook.prc * cook.qty)*1.0;	// Calculate the total price for the item (qty * each_price)

	    if (total_disc > total_item_price) {				// Total discount greater than item price
	  	  // Subtract the item price from discount total
		  total_disc = total_disc - ((cook.prc*1.0)*(cook.qty*1.0)) + (0.01 * cook.qty*1.0);
		  str = str + AddItem(j, cook.qty, cook.des, 0.01);	// Set the item price to one cent (PayPal does not allow zero amt)
		}
		else if (total_disc < total_item_price) {			// Item price is greater than discount total
		  item_disc = total_disc / (cook.qty*1.0);			// Amount of discount per item (not rounded)
		  rounded_item_disc = Dollar(item_disc);			// Amount of discount per item (rounded)
		  
		  if (rounded_item_disc*1.0 != item_disc*1.0) {
			// Difference between the rounded and not rounded discount
			item_with_disc = Dollar(cook.prc*1.0 - rounded_item_disc*1.0);					// Single item with discount
			item_total_with_disc = Dollar((cook.prc*1.0 - item_disc) * cook.qty*1.0);		// Total item with discount
			price_of_last_item = item_total_with_disc - (item_with_disc * (cook.qty - 1));	// Price of last item with discount
			
			// Add the items but the last one
			str = str + AddItem(j, (cook.qty*1.0 - 1), cook.des, Dollar(item_with_disc));
			
			// For the first item, append the disount code, tax rate, etc.
			if (tmps.length > 0) {
        	  str = str + "&on0_" + j + "=Shipping";
        	  str = str + "&os0_" + j + "=" + escape (tmps);
			  tmps = "";
	      	}

			// Append the shipping info for the first one
			if (frst > 0 && sx == true) {
        	  str = str + "&shipping_"  + j + "=" + Dollar (ship*1.0 + cook.ishp * cook.qty);
      		  frst = 0;  // set to false - true only on 1st item
			}
			
			// Now add the last one with the adjusted price
			j = j + 1;
			str = str + AddItem(j, 1, cook.des, Dollar(price_of_last_item));
		  }
		  else {
			// No difference between rounded and raw amount so just add the item by subtacting
			// the discount from the each price
	    	str = str + AddItem(j, cook.qty, cook.des, Dollar(cook.prc*1.0 - item_disc));
		  }
			
		  total_disc = 0;										// Set the discount total to zero
		}
		
		total_disc = Dollar(total_disc*1.0)*1.0;				// Round amount to the nearest cent
	  }
	  else {													// No discount to apply, just add the item
	    str = str + AddItem(j, cook.qty, cook.des, cook.prc);	// Assign the price of the items
	  }
	  
      if (cook.op1n.length > 0) {    // 1st option present
        str = str + "&on0_" + j + "=" + escape (cook.op1n);
        str = str + "&os0_" + j + "=" + escape (cook.op1v + ", " + tmps);
      } 
	  else if (tmps.length > 0) {
        str = str + "&on0_" + j + "=Shipping";
        str = str + "&os0_" + j + "=" + escape (tmps);
      }
	  
      if (gwtot > 0 && frst > 0) str = str + ', GIFT+WRAP';

      tmps = "";  // zap it
	  
      if (cook.op2n.length > 0) {    // 2nd option present
        str = str + "&on1_" + j + "=" + escape (cook.op2n);
        str = str + "&os1_" + j + "=" + escape (cook.op2v);
      }
	  
      if (cook.cod != "")
        str = str + "&item_number_" + j + "=" + escape (cook.cod);
		
      if (cook.cus != "")
        str = str + "&custom_" + j + "=" + escape (cook.cus);

      if (frst > 0 && (hand > 0 || insx > 0 || cook.ihnd > 0 || gwtot > 0)) {
        str = str + "&handling_" + j + "=" + Dollar (hand*1.0 + insx*1.0 + cook.ihnd*1.0 + gwtot*tqty);
      }
	  else if (frst == 0 && cook.ihnd > 0)
        str = str + "&handling_" + j + "=" + Dollar (cook.ihnd);

      if (frst > 0 && ttax > 0) {
        str = str + "&tax_" + j + "=" + Dollar (ttax/cook.qty);
      } else
      if (frst == 0 && ttax > 0) // zap any preference tax
        str = str + "&tax_"      + j + "=0";

      if (frst > 0 && sx == true) {
        str = str + "&shipping_"  + j + "=" + Dollar (ship*1.0 + cook.ishp * cook.qty);
	  }
      else if (frst == 0 && sx == true) {
        str = str + "&shipping_"  + j + "=" + Dollar (cook.ishp * cook.qty);
	  }

      frst = 0;  // set to false - true only on 1st item
    }    
  }
  
  // Return the constructed string
  return str;
}


// These are the 2008 Priority Mail zone charge tables (1-8) to 40lbs.
var pz1  = new Array (0,  // USPS priority zone one
  4.60,  4.60,  5.05,  5.70,  6.30,  6.85,  7.35,  7.75,  8.15,  8.50,
  8.80,  9.15,  9.50,  9.80, 10.15, 10.35, 10.50, 10.70, 11.10, 11.60,
 12.00, 12.50, 12.90, 13.35, 13.85, 14.25, 14.70, 15.15, 15.60, 16.10,
 16.50, 16.95, 17.40, 17.85, 18.30, 18.75, 19.20, 19.65, 20.05, 20.45);
var pz2  = new Array (0,
  4.60,  4.60,  5.05,  5.70,  6.30,  6.85,  7.35,  7.75,  8.15,  8.50,
  8.80,  9.15,  9.50,  9.80, 10.15, 10.35, 10.50, 10.70, 11.10, 11.60,
 12.00, 12.50, 12.90, 13.35, 13.85, 14.25, 14.70, 15.15, 15.60, 16.10,
 16.50, 16.95, 17.40, 17.85, 18.30, 18.75, 19.20, 19.65, 20.05, 20.45);
var pz3  = new Array (0,
  4.60,  4.90,  5.70,  6.65,  7.55,  8.25,  8.85,  9.60, 10.25, 10.75,
 11.20, 11.70, 12.20, 12.70, 13.20, 13.45, 13.70, 13.90, 14.15, 14.35,
 14.55, 14.80, 15.00, 15.20, 15.40, 15.60, 15.80, 16.00, 16.20, 16.40,
 16.55, 16.95, 17.40, 17.85, 18.30, 18.75, 19.20, 19.65, 20.05, 20.45);
var pz4  = new Array (0, 
  4.60,  5.30,  6.40,  7.70,  8.90, 10.00, 11.00, 11.95, 12.50, 13.10,
 13.65, 14.20, 14.75, 15.35, 15.90, 16.20, 16.50, 16.80, 17.10, 17.40,
 17.70, 17.95, 18.45, 19.00, 19.65, 20.25, 20.85, 21.40, 22.05, 22.65,
 23.25, 23.85, 24.40, 25.05, 25.65, 26.25, 26.95, 27.50, 28.25, 28.90);
var pz5  = new Array (0,
  4.60,  6.20,  8.25, 10.20, 11.90, 12.95, 13.95, 14.90, 15.90, 16.95,
 17.95, 18.95, 20.00, 20.90, 21.55, 22.00, 22.55, 23.00, 23.55, 23.95,
 24.35, 24.90, 25.30, 25.85, 26.25, 26.80, 27.20, 27.55, 27.90, 28.30,
 28.65, 29.00, 29.35, 30.00, 30.65, 31.30, 31.90, 32.55, 33.20, 33.85);
var pz6  = new Array (0,
  4.60,  6.55,  9.10, 11.10, 12.90, 13.10, 14.35, 15.60, 16.85, 18.25,
 19.75, 21.30, 22.85, 24.10, 24.65, 25.20, 25.85, 26.35, 27.00, 27.50,
 27.95, 28.60, 29.10, 29.70, 30.15, 30.80, 31.25, 31.70, 32.10, 32.55,
 32.95, 33.40, 33.80, 34.80, 35.75, 36.70, 37.65, 38.70, 39.65, 40.55);
var pz7  = new Array (0,
  4.60,  7.00,  9.65, 12.20, 14.35, 14.75, 16.40, 18.00, 19.60, 21.30,
 22.90, 24.10, 25.05, 26.50, 26.75, 27.35, 28.05, 28.60, 29.30, 29.85,
 30.40, 31.10, 31.65, 32.35, 32.85, 33.55, 34.05, 34.55, 35.00, 35.50,
 35.95, 36.80, 37.85, 38.90, 39.95, 41.05, 42.10, 43.10, 44.20, 45.20);
var pz8  = new Array (0,
  4.60,  7.50, 10.55, 13.45, 15.85, 16.05, 18.30, 20.55, 22.85, 25.05,
 26.35, 27.50, 28.45, 29.85, 30.50, 31.25, 32.10, 32.85, 33.70, 34.40,
 35.10, 35.95, 36.60, 37.50, 38.15, 39.35, 40.80, 42.30, 43.70, 45.15,
 46.65, 48.10, 49.50, 50.95, 52.40, 53.85, 55.30, 56.75, 58.25, 59.65);
var pzx  = new Array (0,pz1,pz2,pz3,pz4,pz5,pz6,pz7,pz8);

// These are the 2008 US Parcel Post mail zone charge tables (1-8) to 40lbs.
var pp1  = new Array (0,
  4.38,  4.50,  4.95,  5.60,  6.20,  6.75,  7.25,  7.65,  8.05,  8.40,
  8.70,  8.96,  9.14,  9.32,  9.48,  9.62,  9.80,  9.93, 10.10, 10.22,
 10.37, 10.49, 10.63, 10.73, 10.87, 10.97, 11.12, 11.21, 11.34, 11.44,
 11.57, 11.65, 11.75, 11.87, 11.97, 15.95, 16.05, 16.14, 16.25, 16.34);
var pp2  = new Array (0,
  4.38,  4.50,  4.95,  5.60,  6.20,  6.75,  7.25,  7.65,  8.05,  8.40,
  8.70,  8.96,  9.14,  9.32,  9.48,  9.62,  9.80,  9.93, 10.10, 10.22,
 10.37, 10.49, 10.63, 10.73, 10.87, 10.97, 11.12, 11.21, 11.34, 11.44,
 11.57, 11.65, 11.75, 11.87, 11.97, 15.95, 16.05, 16.14, 16.25, 16.34);
var pp3  = new Array (0,
  4.50,  4.80,  5.60,  6.55,  7.45,  8.15,  8.61,  8.94,  9.27, 10.37,
 10.69, 10.97, 11.22, 11.53, 11.79, 12.04, 12.25, 12.48, 12.71, 12.92,
 13.14, 13.31, 13.55, 13.72, 13.90, 14.07, 14.25, 14.42, 14.60, 14.74,
 14.89, 15.05, 15.21, 15.31, 15.48, 19.50, 19.62, 19.79, 19.88, 20.04);
var pp4  = new Array (0, 
  4.50,  5.20,  6.30,  7.47,  8.23,  8.97,  9.67, 10.36, 10.99, 11.62,
 12.22, 12.80, 13.37, 13.91, 14.44, 14.96, 15.46, 15.78, 16.13, 16.42,
 16.72, 17.02, 17.33, 17.58, 17.85, 18.10, 18.33, 18.60, 18.84, 19.05,
 19.27, 19.49, 19.71, 19.88, 20.09, 24.20, 24.35, 24.53, 24.70, 24.89);
var pp5  = new Array (0,
  4.50,  5.67,  7.02,  7.78,  8.59,  9.36, 10.09, 10.79, 11.47, 12.12,
 12.75, 13.36, 13.95, 14.53, 15.09, 15.64, 16.18, 16.70, 17.21, 17.71,
 18.20, 18.69, 19.16, 19.62, 20.08, 20.53, 20.97, 21.40, 21.83, 22.24,
 22.66, 23.06, 23.46, 23.86, 24.25, 28.52, 28.90, 29.27, 29.65, 30.01);
var pp6  = new Array (0,
  4.50,  6.00,  7.05,  8.04,  8.98,  9.83, 10.64, 11.41, 12.14, 12.84,
 13.52, 14.17, 14.80, 15.41, 15.99, 16.56, 17.12, 17.66, 18.18, 18.70,
 19.19, 19.68, 20.16, 20.62, 21.08, 21.53, 21.97, 22.39, 22.81, 23.23,
 23.63, 24.03, 24.42, 24.81, 25.19, 29.45, 29.81, 30.17, 30.53, 30.88);
var pp7  = new Array (0,
  4.50,  6.15,  7.33,  8.45,  9.50, 10.48, 11.44, 12.32, 13.14, 13.92,
 14.68, 15.40, 16.10, 16.77, 17.43, 18.06, 18.67, 19.27, 19.85, 20.41,
 20.96, 21.50, 22.02, 22.54, 23.04, 23.53, 24.01, 24.48, 24.94, 25.39,
 25.83, 26.27, 26.69, 27.11, 27.53, 31.82, 32.22, 32.61, 33.00, 33.38);
var pp8  = new Array (0,
  4.50,  6.15,  7.93,  9.25, 10.50, 11.77, 12.88, 14.08, 15.21, 16.17,
 17.08, 17.96, 18.80, 19.61, 20.40, 21.16, 21.89, 22.61, 23.30, 23.98,
 24.64, 25.28, 25.90, 26.51, 27.11, 27.69, 28.26, 28.82, 29.36, 29.90,
 30.42, 30.94, 31.44, 31.93, 32.42, 36.79, 37.26, 37.72, 38.17, 38.62);
var ppx  = new Array (0,pp1,pp2,pp3,pp4,pp5,pp6,pp7,pp8);

// UPS residential ground, lower 48 charges to 70 lbs. Jan 2008
var uz1  = new Array (0,
  6.13,  6.23,  6.29,  6.46,  6.78,  7.00,  7.37,  7.66,  7.88,  8.15,
  8.43,  8.68,  8.97,  9.16,  9.35,  9.50,  9.60,  9.74,  9.95, 10.15,
 10.39, 10.62, 10.88, 11.13, 11.39, 11.70, 11.98, 12.22, 12.50, 12.81,
 13.06, 13.17, 13.44, 13.68, 13.92, 14.16, 14.43, 14.65, 14.85, 15.08,
 15.32, 15.55, 15.76, 15.96, 16.13, 16.31, 16.48, 16.66, 16.83, 17.01,
 17.18, 17.36, 17.53, 17.71, 17.88, 18.06, 18.24, 18.41, 18.59, 18.76,
 18.95, 19.10, 19.26, 19.42, 19.58, 19.74, 19.90, 20.06, 20.22, 20.38);
var uz2  = new Array (0,
  6.13,  6.23,  6.29,  6.46,  6.78,  7.00,  7.37,  7.66,  7.88,  8.15,
  8.43,  8.68,  8.97,  9.16,  9.35,  9.50,  9.60,  9.74,  9.95, 10.15,
 10.39, 10.62, 10.88, 11.13, 11.39, 11.70, 11.98, 12.22, 12.50, 12.81,
 13.06, 13.17, 13.44, 13.68, 13.92, 14.16, 14.43, 14.65, 14.85, 15.08,
 15.32, 15.55, 15.76, 15.96, 16.13, 16.31, 16.48, 16.66, 16.83, 17.01,
 17.18, 17.36, 17.53, 17.71, 17.88, 18.06, 18.24, 18.41, 18.59, 18.76,
 18.95, 19.10, 19.26, 19.42, 19.58, 19.74, 19.90, 20.06, 20.22, 20.38);
var uz3  = new Array (0,
  6.30,  6.62,  6.93,  7.18,  7.29,  7.54,  7.78,  8.04,  8.27,  8.33,
  8.72,  9.02,  9.31,  9.60,  9.91, 10.09, 10.43, 10.77, 11.12, 11.48,
 11.85, 12.20, 12.56, 12.88, 13.23, 13.55, 13.86, 14.19, 14.52, 14.88,
 15.19, 15.51, 15.86, 16.21, 16.59, 16.88, 17.26, 17.58, 17.91, 18.31,
 18.61, 18.95, 19.29, 19.61, 19.96, 20.28, 20.57, 20.86, 21.12, 21.37,
 21.56, 21.75, 21.98, 22.17, 22.36, 22.57, 22.80, 23.05, 23.30, 23.55,
 23.76, 23.95, 24.19, 24.43, 24.71, 25.02, 25.28, 25.53, 25.78, 26.02);
var uz4  = new Array (0,
  6.51,  7.28,  7.64,  8.02,  8.40,  8.55,  8.75,  8.99,  9.18,  9.39,
  9.57,  9.79,  9.95, 10.15, 10.33, 10.49, 10.81, 11.16, 11.58, 11.99,
 12.37, 12.81, 13.23, 13.67, 14.09, 14.52, 14.94, 15.40, 15.86, 16.34,
 16.76, 17.21, 17.65, 18.07, 18.53, 18.92, 19.34, 19.78, 20.22, 20.66,
 21.07, 21.47, 21.91, 22.28, 22.68, 23.02, 23.38, 23.75, 24.10, 24.42,
 24.76, 25.06, 25.35, 25.69, 25.94, 26.23, 26.51, 26.81, 27.12, 27.43,
 27.72, 27.97, 28.23, 28.52, 28.86, 29.18, 29.47, 29.74, 30.02, 30.31);
var uz5  = new Array (0,
  6.78,  7.41,  7.91,  8.43,  8.83,  9.09,  9.41,  9.63,  9.88, 10.15,
 10.37, 10.61, 10.85, 11.10, 11.36, 11.58, 12.06, 12.68, 13.26, 13.87,
 14.46, 15.00, 15.55, 16.06, 16.54, 17.08, 17.61, 18.15, 18.67, 19.23,
 19.75, 20.31, 20.86, 21.40, 21.94, 22.48, 23.02, 23.57, 24.10, 24.65,
 25.19, 25.73, 26.29, 26.83, 27.37, 27.86, 28.37, 28.86, 29.35, 29.79,
 30.24, 30.65, 31.06, 31.47, 31.92, 32.37, 32.84, 33.19, 33.51, 33.76,
 34.14, 34.43, 34.72, 34.98, 35.22, 35.45, 35.65, 35.86, 36.06, 36.27);
var uz6  = new Array (0,
  7.13,  7.95,  8.49,  8.99,  9.39,  9.67, 10.01, 10.33, 10.58, 11.03,
 11.50, 12.02, 12.60, 13.30, 14.00, 14.54, 15.27, 16.02, 16.73, 17.46,
 18.19, 18.92, 19.64, 20.38, 21.11, 21.88, 22.63, 23.36, 24.11, 24.89,
 25.60, 26.33, 27.02, 27.76, 28.48, 29.18, 29.83, 30.50, 31.17, 31.85,
 32.50, 33.13, 33.76, 34.35, 34.95, 35.49, 35.99, 36.51, 37.00, 37.48,
 37.93, 38.40, 38.83, 39.30, 39.77, 40.22, 40.66, 41.11, 41.49, 41.84,
 42.22, 42.52, 42.79, 43.09, 43.47, 43.91, 44.26, 44.49, 44.73, 44.96);
var uz7  = new Array (0,
  7.25,  8.14,  8.77,  9.28,  9.76, 10.14, 10.50, 10.98, 11.58, 12.41,
 13.30, 14.19, 15.10, 15.97, 16.86, 17.59, 18.45, 19.29, 20.13, 20.99,
 21.82, 22.68, 23.52, 24.35, 25.18, 26.01, 26.84, 27.67, 28.50, 29.34,
 30.17, 31.00, 31.83, 32.66, 33.49, 34.33, 35.16, 35.99, 36.82, 37.65,
 38.48, 39.31, 40.15, 40.98, 41.81, 42.64, 43.47, 44.30, 45.14, 45.97,
 46.75, 47.48, 48.07, 48.51, 48.87, 49.23, 49.60, 49.89, 50.18, 50.47,
 50.77, 51.06, 51.39, 51.74, 52.02, 52.27, 52.52, 52.81, 53.10, 53.39);
var uz8  = new Array (0,
  7.41,  8.53,  9.48, 10.09, 10.71, 11.07, 11.60, 12.33, 13.13, 14.02,
 15.03, 16.12, 17.21, 18.31, 19.40, 20.32, 21.33, 22.41, 23.49, 24.58,
 25.66, 26.77, 27.86, 28.94, 30.02, 31.10, 32.18, 33.30, 34.43, 35.54,
 36.60, 37.71, 38.77, 39.85, 40.89, 41.87, 42.67, 43.47, 44.27, 45.08,
 45.88, 46.68, 47.48, 48.29, 49.09, 49.89, 50.69, 51.50, 52.30, 53.10,
 53.90, 54.71, 55.51, 56.31, 57.11, 57.91, 58.64, 59.23, 59.66, 60.03,
 60.39, 60.76, 61.12, 61.49, 61.85, 62.31, 62.47, 62.61, 62.77, 62.92);
var uzx  = new Array (0,uz1,uz2,uz3,uz4,uz5,uz6,uz7,uz8);

function CalcCost () {  // given weight and ZIP, calc cost
  
  amt = 0;		    //  Reset amount to zero
  shipmethod = 0;	//  Reset shippping method
  
  if (usps < 0 && ups < 0)      // nothing selected
    root.stxt0 = "";			// reset shipping text

  wte = Math.floor ((tozs + 15.999) / 16.0);
  if (uspp > 0) {   // user selected USPS Parcel Post shipping
    SetUspsZ ();    // set up USPS Parcel Post mail zones
	shipmethod = 1;	// set ship method to Priority Mail
	root.stxt0 = "USPS Parcel Post";
  } else
  if (usps > 0) {   // user selected USPS Priority shipping
    SetUspsZ ();    // set up USPS Priority mail zones
	shipmethod = 2;	// set ship method to USPS
	root.stxt0 = "USPS Priority Mail";
  } else
  if (ups > 0) {    // user has selected UPS ground shipping
    SetUpsZ ();     // set up UPS ground shipping zones
	shipmethod = 3;	// set ship method to UPS
	root.stxt0 = "UPS Ground";
  }
  
  for (var i=zn-1; i>=0; i--) { // run table backwards
    if (zip >= zzip[i]) {       // zip value
      zne = zone[i];            // corresponding zone
      break;                    // get out, now
    }
  }
  
  // Look-up the shipping charge based on the weight  
  if (usps > 0) {   // user selected USPS Priority shipping
    if (wte <= 40)
      amt = pzx[zne][wte];
	else
	  amt = pzx[zne][40] + ((wte - 40) * 0.25);
  } else
  if (uspp > 0) {   // user selected USPS Parcel Post shipping
	if (wte <= 40)
      amt = ppx[zne][wte];
	else
	  amt = ppx[zne][40] + ((wte - 40) * 0.25);
  } else
  if (ups > 0) {    // user has selected UPS ground shipping
 	if (wte <= 70)
      amt = uzx[zne][wte];
	else
	  amt = uzx[zne][70] + ((wte - 70) * 0.25);
 
  	  amt = amt + 1.50;	// Adjust for UPS ground shipping costs
  }

  if (zne > 0) {
  	root.stxt0 = root.stxt0 + " (Zone " + zne + ")";
  	amt = amt + 0.75;	// Adjust for fuel surcharge for all shipping methods
	  
	if (zne = 8) {
		if (zip >= 995 && zip <= 999) {		// Shipping to Alaska
			root.stxt0 = root.stxt0 + " - AK"
			switch (shipmethod) {
				case 1:		// USPS
					amt = amt + 3.00;		// Add $3.00 adjustment for shipping
					break;
				
				case 2:		// Priority Mail
					amt = amt + 16.00;		// Add $16.00 adjustment for shipping
					break;
				
				case 3:		// UPS
					amt = amt + 30.00;		// Add $30.00 adjustment for shipping
					break;
					
				default:					// Error condition
					amt = amt + 20.00;		// Add $20 adjustment for shipping (to cover difference)
			}
		}
		
		if (zip >= 967 && zip <= 968) {		// Shipping to Hawaii
			root.stxt0 = root.stxt0 + " - HI"
			switch (shipmethod) {
				case 1:		// USPS
					amt = amt + 3.00;		// Add $3.00 adjustment for shipping
					break;
				
				case 2:		// Priority Mail
					amt = amt + 16.00;		// Add $16.00 adjustment for shipping
					break;
				
				case 3:		// UPS
					amt = amt + 30.00;		// Add $30.00 adjustment for shipping
					break;
					
				default:					// Error condition
					amt = amt + 20.00;		// Add $20 adjustment for shipping (to cover difference)
			}
		}
	}
  }

  // Free shipping promo for USPS Parcel Post
  //if (uspp > 0) {   // user selected USPS Parcel Post shipping
  //  if (GetProductTotal() > 50)
  //	    amt = 0.0;
  //}

  root.ship = amt;	// remember the shipping amount
  
  root.zne = zne;
  root.usps = usps;
  root.uspp = uspp;
  root.ups  = ups;
  root.insu = insu;
  root.store ();
}

function SetUspsZ () {  // set USPS zone chart in memory
  // built from USPS 22310 zone chart
  SetZone (
      5, 3,   6, 7,  10, 4,  60, 3,  80, 2,
     87, 3, 120, 4, 124, 3, 128, 4, 130, 3,
    133, 4, 137, 3, 155, 2, 158, 3, 159, 2,
    160, 3, 166, 2, 167, 3, 168, 2, 169, 3,
    170, 2, 177, 3, 178, 2, 180, 3, 189, 2,
    200, 1, 215, 2, 216, 1, 224, 2, 226, 1,
    228, 2, 242, 3, 243, 3, 246, 3, 254, 1,
    255, 3, 262, 2, 266, 3, 267, 2, 270, 3,
    287, 4, 297, 3, 298, 4, 316, 5, 318, 4,
    320, 5, 356, 4, 359, 5, 362, 4, 363, 5,
    370, 4, 375, 5, 376, 4, 380, 5, 384, 4,
    386, 5, 399, 4, 411, 3, 413, 4, 415, 3,
    417, 4, 420, 5, 421, 4, 437, 3, 448, 4,
    456, 3, 458, 4, 498, 5, 510, 6, 514, 5,
    515, 6, 520, 5, 562, 6, 563, 5, 565, 6,
    588, 7, 596, 8, 600, 4, 610, 5, 618, 4,
    620, 5, 669, 6, 673, 5, 674, 6, 700, 5,
    705, 6, 707, 5, 718, 6, 719, 5, 730, 6,
    744, 5, 745, 6, 749, 5, 750, 6, 769, 7,
    770, 6, 785, 7, 786, 6, 797, 7, 832, 8,
    845, 7, 850, 8, 865, 7, 889, 8);
}

function SetUpsZ () {  // set UPS lower 48 ground Zones
  // built from UPS 22310 zone chart, lower 48
  SetZone (
      4, 3,  10, 4,  12, 3,  13, 4,  47, 5,
     48, 4,  60, 3,  62, 4,  63, 3,  80, 2,
     87, 3, 120, 4, 124, 3, 128, 4, 130, 3,
    133, 4, 137, 3, 143, 4, 144, 3, 154, 2,
    157, 3, 159, 2, 160, 3, 166, 2, 167, 3,
    168, 2, 169, 3, 170, 2, 177, 3, 178, 2,
    180, 3, 182, 2, 183, 3, 189, 2, 242, 3,
    244, 2, 246, 3, 254, 2, 255, 3, 262, 2,
    266, 3, 267, 2, 270, 3, 287, 4, 297, 3,
    298, 4, 316, 5, 318, 4, 320, 5, 256, 4,
    360, 6, 362, 4, 363, 5, 368, 4, 369, 5,
    370, 4, 375, 5, 376, 4, 380, 5, 384, 4,
    386, 5, 399, 4, 411, 3, 413, 4, 415, 3,
    417, 4, 420, 5, 421, 4, 437, 3, 448, 4,
    456, 3, 458, 4, 498, 5, 510, 6, 512, 5,
    534, 4, 535, 5, 562, 6, 563, 5, 565, 6,
    588, 7, 596, 8, 600, 4, 610, 5, 618, 4,
    620, 5, 668, 6, 673, 5, 674, 6, 700, 5,
    705, 6, 707, 5, 730, 6, 734, 5, 745, 6,
    749, 5, 750, 6, 785, 7, 786, 6, 788, 7,
    789, 6, 797, 7, 807, 6, 808, 7, 832, 8,
    845, 7, 846, 8, 865, 7, 889, 8);
}

function GetZip() {		// Get the zip code
var errflg;

  errflg = false;					// Initialize error flag
  zipfull = prompt("Enter destination ZIP...", "");
  //zip = prompt("Enter destination ZIP...", "").substring (0, 3);
  
  if (zipfull.length == 5) {			// Correct length?
    if (zipfull.substring(0,1) == " " || zipfull.substring(1,1) == " " || zipfull.substring(2,1) == " " || zipfull.substring(3,1) == " " || zipfull.substring(4,1) == " ")
	  errflg = true;
	else if (isNaN(zipfull) == true) 	// Check for non-numbers
      errflg = true;
	else if (zipfull == "00000")		// Check for zip codes that are all zeros
	  errflg = true;
	else if (zipfull < 0)				// Check for negative zip codes
	  errflg = true;
  }
  else									// Wrong length - return error
   errflg = true;

  // Check error flag and return an error or the first three digit zip  
  if (errflg == true) {
    alert ("You must enter a valid ZIP code!");
    return false;					// Let calling program that the zip is bad
  }
  else
    zip = zipfull.substring(0,3);	// Return only the first three digits of the zip for shipping calculations
  	return true;					// Return the good zip
}

function ClearShippingText() {
  root.stxt0 = "";				// reset shipping text
  root.ship = 0;
  root.store ();
  document.location.reload ();  // update the screen
}

function Shipper (obj1) {  // use either amt or qty based shipping
var pos;
  SetAmtSH (0);            // assume the worst
  SetCartSH (0);
  SetWgtSH (0);
  pos = obj1.selectedIndex;  // which option selected
  //root.stxt0 = obj1.options[pos].text;  <---- Aleady set in CalcCost;

  if (GetProductTotal() > 0) {		// Is there something in the cart?
  
    if (pos == 1) {    // 1st option
        usps = -1;
        uspp = 1;
        ups  = -1;
        insu = -1;
	
	    // Call funtion to get the zip code
	    if (GetZip() == false) {
          obj1.selectedIndex = 0;		// Reset shipping method
          uspp = -1;  				// zap everything
		  ClearShippingText();
 	      return;
	    }
	    CalcCost();
    }
    else if (pos == 2) {    // 2nd option
      usps = 1;
      uspp = -1;
      ups  = -1;
      insu = -1;
	
	  // Call funtion to get the zip code
	  if (GetZip() == false) {
	    obj1.selectedIndex = 0;	// Reset shipping method
        usps = -1;  				// zap everything
        ClearShippingText();
	    return;
	  }
      CalcCost();
    }
    else if (pos == 3) {    // 3rd option
      usps = -1;
      uspp = -1;
      ups  = 1;
      insu = -1;
	
	  // Call funtion to get the zip code
	  if (GetZip() == false) {
	    obj1.selectedIndex = 0;	// Reset shipping method
        ups = -1;  				// zap everything
        ClearShippingText();
	    return;
	  }
      CalcCost();
    }

    SetAmtSH (0,0,0);  // LEAVE ALONE!!
    document.location.reload ();  // show the latest info...
  }
  else {
    alert ("There are no items in the shopping cart!");
	
	obj1.selectedIndex = 0;		  // Reset the shipping drop-down
    document.location.reload ();  // Redisplay the shopping cart
  }
}

function LoadIt () {
// executed at load time
  Cookie.prototype.store  = _Cookie_store;   // load proto methods
  Cookie.prototype.load   = _Cookie_load;
  Cookie.prototype.remove = _Cookie_remove;
  
  cook = new Cookie (document, "paycart1");
  cook.load();
  if (!cook.qty) {  //create the structure
    root = new Cookie (document, "paycart0");  // root cookie
    root.load();
    InitRoot ();
    for (var i=1; i<cmax; i++) {  // load or init data cookies
      cook = new Cookie (document, "paycart" + i);
      InitData ();              // create it
    }
  }
  root = new Cookie (document, "paycart0");  // root cookie
  root.load();
  stax  = root.stax;  // load defaults
  ttxt  = root.ttxt;
  coup  = root.coup;
  cdis  = root.cdis;
  camt  = root.camt;
  cval  = root.cval;
  ctxt  = root.ctxt;
  gwtot = root.gwtot;
}
