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 = "scrollbars,location,resizable,status,menubar,toolbar";
var cartwin;

var cmax  = 45;            // 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 thnd  = 0;      // item specific handling
var tshp  = 0;      // item specific shipping
var hand;           // cart totals
var ship = 0;			// ship starts as 0
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 ader = 0;       // add a flat cost to an item
var adtx = "";      // text for flat add

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 coupval = "";         // coupon value user entered
var coupons = new Array ();  // coupon codes
var couponp = new Array ();  // discount percent
var coupona = new Array ();  // discount amount
var cval = "";            // recorded ocupon value
var ctxt = "";            // coupon text
var coup = -1;            // cart discount coupon not active
var cfull = 0;	         // shopping cart full

// stuff for shipping support...
var zip = -1;        // 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 ups2 = -1;  // flag for UPS 2nd day air
var cntry = ""; // holds shipping country
var zipp = -1;	// holds shipping zip/postal code
var insu = -1;  // flag for insurance
var stxt1 = "";

//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 (strn.length < 1 || strn == " ") return;
  if (blk3n.length > 0) c = ", ";
  blk3n = blk3n + c + strn;
}

function AddFixed (amt, txt) {  // add flat charge to item
  ader = ader*1.0 + amt*1.0;
  if (txt.length > 0) adtx = adtx + ", " + txt;
}

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 (val.length == 0 || val == " ") return;
  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 (val.length == 0 || val == " ") return;
  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 AddShip()
{
//	alert(ship+' '+stxt1);
	if (isNaN(ship))
		return 0;
	else {
//		ship = obj1*1.0;
//		alert('call set totals');
//		stxt1 = obj2;
		SetTotals();
		return 1;
	}
}

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

function CalcInsu (amt) {  // calculate insurance on an amount
    if (amt == 0) return 0;
    if (amt <= 50) return 1.70;
    if (amt <= 100) return 2.15;
    if (amt <= 200) return 2.60;
    return 2.80 + (Math.floor (amt / 100.0) * .95);
  }


function CallView () { // call the local shopping cart view
  cartwin = window.open ("http://www.digitalheroes.com/cart.asp", "DHCart", winpar);
//  cartwin.focus ();
}

/*
function ChkCoup () {  // check for a discount coupon
var i;
  coup = -1;          // assume the worst
  coupons = root.xx_cval.split (",");
  couponp = root.xx_cdis.split (",");
  coupona = root.xx_camt.split (",");
  for (i=0; i<coupons.length; i++) {
    if (coupval == coupons[i]) {
      coup = 1;              // user hit the coupon value
      cdis = couponp[i];     // remember the discount percent
      camt = coupona[i];     // discount amount 
      cval = coupval;        // remember entered value
      if (cdis > 0) {
        alert ("Valid coupon number! \n\n" +
               cdis + "% discount now in effect.");
        ctxt = "COUPON-" + cdis + "%" + cval;
      }
      if (camt > 0) {
        alert ("Valid coupon number! \n\n" +
               "$" + camt + " discount now in effect.");
        ctxt = "COUPON-$" + camt + "-" + 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;
    }
  }
  alert ("'" + coupval + "'  not a valid code!");
}
*/

function ChkFlg (temp) {     // check for special flag chars
var j,tok,val;
var ary = new Array ();      // where we break down input
  ary = temp.split (" ");    // divide on spaces
  for (j=0; j<ary.length; j++) {
// first we do single character tokens...
    if (ary[j].length < 2) continue;
    tok = ary[j].substring (0,1); // first character
    val = ary[j].substring (1);   // get data
    if (tok == "@") SetPrice (parseFloat(val));
    if (tok == "+") AddPrice (parseFloat(val));
    if (tok == "%") AddPrcnt (parseFloat(val));
    if (tok == "#") {             // record weight
      AddWt (parseFloat(val));
      ary[j] = "";                // zap this array element
    }
// Now we do 3-character tokens...
    if (ary[j].length < 4) continue;
    tok = ary[j].substring (0,3); // first 3 chars
    val = ary[j].substring (3);   // get data
    if (tok == "cd=") {           // value for part number
      SetCode (val);
      ary[j] = "";                // clear it out
    }
  }
  return ary.join (" ");          // rebuild val with what's left
}

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;
  } else
  if (root.xx_chkbx == on && root.chkby == off) {  // agree checkbox
    alert ('You must agree to terms!');
    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";
  ader  = 0;
  adtx  = "";
  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);
  }
}

function ClearEntry (i) {  // knock out a specific entry
  cook = new Cookie (document, "paycart" + i);
  cook.load();
  InitData ();
  ShipZap();
}

function are_cookies_enabled()
{
	var cookieEnabled = (navigator.cookieEnabled) ? true : false;

	if (typeof navigator.cookieEnabled == "undefined" && !cookieEnabled)
	{ 
		document.cookie="testcookie";
		cookieEnabled = (document.cookie.indexOf("testcookie") != -1) ? true : false;
	}
	return (cookieEnabled);
}

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 GetTots (indx) {  // return cart totals
  root.load();             // get the cookie values

}

function InitData () {  // zap a data cookie
  cook.pcat = 0;
  cook.qty  = 0;
  cook.cod  = "";
  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.ader = 0;   // add fixed amount
  cook.adtx = "";  // text for fixed amount
  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.camt  = camt;
  root.chkby = off;
//  root.gwtot = gwtot;
  root.stxt0 = " ";
  root.stxt1 = "&nbsp;";
  root.usps = usps;     // USPS flag
  root.uspp = uspp;     // USPS pp flag
  root.ups  = ups;      // UPS flag
  root.ups2 = ups2;     // UPS 2nd day air flag
  root.cntry = cntry;
  root.zipp = zipp;
  root.insu = insu;     // insurance flag
  root.zne  = zne;      // destination zone

  root.qty   = 0;
  root.tot   = 0;

  root.xx_bn   = "";
  root.xx_can  = "";
  root.xx_cbt  = "";
  root.xx_cc   = off;
  root.xx_cdis = "";
  root.xx_camt = "";
  root.xx_cdmp = off;
  root.xx_chkbx= off;
  root.xx_coup = off;
  root.xx_cper = 0;
  root.xx_cur  = "USD";
  root.xx_dadd = on;
  root.xx_id   = "";
  root.xx_img  = on;
  root.xx_lc   = "US";
  root.xx_mamt = 0;
  root.xx_mqty = 0;
  root.xx_pc   = off;
  root.xx_prt  = on;
  root.xx_prtx = off;
  root.xx_ret  = "http://www.digitalheroes.com";
  root.xx_ship = off;
  root.xx_siz  = on;
  root.xx_sty  = "";
  root.xx_sum  = off;
  root.xx_tax  = off;
  root.xx_uas  = off;
  root.xx_uasp = 0;
  root.xx_wt   = off;
  root.xx_wtent= "oz";
  root.xx_wtrup= 10;

  for (i=0; i<cats; i++) {
    root["hn" + i] = 0;         // qty-based handling brkpts
    root["qd" + i] = 0;         // qty-based percent dis brkpts
    root["sn" + i] = 0;         // qty-based shipping brkpts
    root["pv" + 1] = 0;         // cart-quantity charges
    root["ad" + i] = 0;         // amt-based percent dis brkpts
    root["sv" + i] = 0;         // amt-based shipping bkpts
    root["wv" + i] = 0;         // wgt-based shipping bkpts
  }
  root.store();                 // record it all..
}

function initValues()
{
// required entry to load the cookies (for older browsers)
  LoadIt ();           // force load of data
//  if (root.xx_id == "") {  // REQUIRED!
// set-list for any cart-wide options here
//  SetCartSH (0, 1, 0);
//  SetCartSH (1, 1, 0);
//  SetCartHN (0, 1, 2.5);  // $2.50 handling charge for whole cart.
//  SetCartHN (1, 1, 2.5);  // $2.50 handling charge for whole cart.
//  SetWgtSH (0, 1, 0); // Sep ship charge for cat 0.
//  SetWgtSH (1, 2, 0); // Sep ship charge for cat 1.
// set cart display options, and internal PayPal options
  root.xx_cc   = on;   // display credit card line
  root.xx_cdmp = off;  // root diagnostic cookie dump (leave off)
  root.xx_chkbx= off;   // agreement checkbox
  root.xx_coup = off;   // ask for coupon code on cart page
  root.xx_cval = "xcoup1,xcoup2"; // coupon values
  root.xx_cdis = "10,0"; // corresponding coupon percent discounts
  root.xx_camt = "0,1";  // corresponding coupon amount discount
  root.xx_dadd = off;   // display cart when add-cart is clicked.
  root.xx_gwbx = off;   // gift wrapping checkbox
  root.xx_gwcg = 10;   // giftwrapping charge per item (if selected)
  root.xx_img  = on;   // show images in cart (SetImg)
  root.xx_mamt = 0;    // minimum amount of order, or zero.
  root.xx_mqty = 1;    // minimum quantity of order, or zero.
  root.xx_pc   = off;   // display product category in item list
  root.xx_prt  = on;   // print email line and addr form
  root.xx_ship = on;   // ask user for shipping options
  root.xx_siz  = on;   // for img, on = resize, off = use orig size
  root.xx_sum  = off;   // display product cat summaries
  root.xx_tax  = on;   // ask user for tax options
  root.xx_ugs  = on;  // UPS added air surcharge for fuel active
  root.xx_ugsp = 3.75;  // UPS air surcharge percent (if active).
  root.xx_uas  = on;  // UPS added air surcharge for fuel active
  root.xx_uasp = 9.5;  // UPS air surcharge percent (if active).
  root.xx_wt   = off;   // display weight totals
  root.xx_wtent= "";   // default entry = ounces, "gm" = grams.
  root.xx_wtrup= 10;   // rounding value - oz always up to lbs
                       //  gm rounds up to these grams.
// place for user-specific options
  root.xx_bn   = "";   // business code, or null
  root.xx_can  = "http://www.digitalheroes.com/cart.asp";   // place for PayPal cancel return path
  root.xx_cbt  = "";   // continue button text, or null
  root.xx_cur  = "USD";// enter default currency code (or null)
  root.xx_id   = "info@digitalheroes.com";  // PayPal ID
  root.xx_lc   = "US"; // enter default country code (or null)
  root.xx_ret  = "http://www.digitalheroes.com/cart.asp";   // place for PayPal return path
  root.xx_sty  = "";   // place for PayPal page style
// required entry to store stuff off
  root.store ();       // required entry!!
// }
}

function LoadTots (obj1) {          // get access to cart totals
var i;
  for (i=0; i<obj1.length; i++) {   // Look in all FORMs
    if (obj1[i].ctot) obj1[i].ctot.value = '$' + Dollar (root.tot);
    if (obj1[i].cqty) obj1[i].cqty.value = root.qty;
  }
}

function PrintCart (updt) {  // 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
  ttax = 0;                 // total cart tax
  tqty = 0;                 // total qty of items
  insx = 0;                 // insurance amount
  thnd = 0;                 // item specific handling
  tshp = 0;                 // item specific shipping

  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) {
//		if (updt==1) 
				PrintItem (i);
//		else
//				PrintItem2 (i);
	 }
  }

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

  hand = 0;  // line display totals
  //ship = 0;
  tpkg = 0; // was "1" changed by Jeff
  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;             // weight this category
    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
    ctot["h" + p] = ha;
    hand = hand + ha;
    if (coup > 0) {
      qt = qt + a * cdis/100.0;  // percent discount
      qt = qt + q/tqty * camt;   // amount discount
    }
    ctot["d" + p] = qt;
    qtyd = qtyd + qt;
  }
  
  s = 0;  // for special stuff...
  wte = Math.floor ((tozs + 15.999) / 16.0);
  twte = wte;
  SetTotals();
}

function SetTotals(){	
	if (insu > 0) insx = CalcInsu (tprc - qtyd);  //testing
	if (ship == undefined) ship = 0;
  ttax = Dollar ((tprc + ship*1.0) * stax/100.0);
  gtot = Dollar (tprc + ship*1.0 + ttax*1.0 + insx);
// alert("gtot = " + gtot);
  // record global totals for ref on other pages
  root.ttax = ttax;
  root.qty = tqty;
  root.tot = gtot;
  root.stxt1 = stxt1;
  root.store ();   // save it off
}

function PrintItem (i) {  // make one entry in cart
var userAgentVar = navigator.userAgent;
var tm,t1,t2,wt, itqty;
  itqty = cook.qty
  document.writeln ('<tr valign = "top"');
  document.writeln ('    align = "center">');
  document.writeln ('  <td>');
  document.writeln ('    <input type  = "checkbox" ');
  document.writeln ('           value = "BOX1"');
  document.writeln ('           onclick = "ClearEntry (', i, ');');
  document.writeln ('             document.location.reload ();" />');
  document.writeln ('  </td>');
  document.writeln ('  <td align = "right">');
  document.writeln ('    <input type  = "text" ');
  document.write ('             value = ');
  document.writeln (itqty);
  document.writeln ('           onchange = "UpdCart (', i, ', this.value); ');
  document.writeln ('             document.location.reload ();" ');
  document.writeln ('           size = "1" />');
  document.writeln ('  </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 + cook.adtx);

  if (cook.op1n.length > 0) {  // see if we append stuff
    document.writeln (', ' +
      cook.op1n + ' ' + 
      cook.op1v + ' ' +
      cook.op2n + ' ' +
      cook.op2v);
  }
  document.writeln ('</td>');
  tm = Dollar (cook.prc);
  t1 = cook.qty*1.0;
  t2 = cook.pcat;
  document.writeln ('  <td align = "right"> $',
    tm,'</td>');
  tm = Dollar (t1*cook.prc + cook.ader*1.0);
  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 align = "right"> $',
    tm,'</td>');

  wt = cook.ozs*1.0 * cook.qty;
  tozs = tozs + wt;
  ctot["w" + t2] = ctot["w" + t2] + wt;
  if (root.xx_wt == on) {  // do we show weight?
    document.writeln ('  <td>',
      cook.ozs,'</td>');
    document.writeln ('    <td>',
      wt,'</td>');
  }

  document.writeln ('  <td align = "center">',
      '<img src = "', 
      cook.imgx,
      '" border="0"');
    if (userAgentVar.indexOf("MSIE") == "-1")
  	document.writeln (' class="detail"');
  else
  	document.writeln (' width="80"')
  document.writeln (' alt = "Image: Item" />',
      '</td>');
  document.writeln ('</tr>');
}

function PrintItem2 (i) {  // make one entry in cart
var tm,t1,t2,wt;
  document.writeln ('<tr valign = "top"');
  document.writeln ('    align = "center">');
  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 + cook.adtx);

  if (cook.op1n.length > 0) {  // see if we append stuff
    document.writeln (', ' +
      cook.op1n + ' ' + 
      cook.op1v + ' ' +
      cook.op2n + ' ' +
      cook.op2v);
  }
  document.writeln ('</td>');
  tm = Dollar (cook.prc);
  t1 = cook.qty*1.0;
  t2 = cook.pcat;
  document.writeln ('  <td align = "right"> $',
    tm,'</td>');
  tm = Dollar (t1*cook.prc + cook.ader*1.0);
  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 align = "right"> $',
    tm,'</td>');

  wt = cook.ozs*1.0 * cook.qty;
  tozs = tozs + wt;
  ctot["w" + t2] = ctot["w" + t2] + wt;
  if (root.xx_wt == on) {  // do we show weight?
    document.writeln ('  <td>',
      cook.ozs,'</td>');
    document.writeln ('    <td>',
      wt,'</td>');
  }
  document.writeln ('  <td align = "center">',
      '<img src = "', 
      cook.imgx,
      '" border="0"'); 
  document.writeln ('class="detail"');
  document.writeln (' alt = "Image: Item" />',
      '</td>');
  document.writeln ('</tr>');
}

function ReadForm (obj1, tst) { //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
    if (obj.name == "tot" ||          // stkp some junk
        obj.name == "cqty" ||
        obj.name == "ctot") continue;
    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
      if (val == "@-1") continue;     // skip the crap
      if (obj.name == "qty") {        // this is the quantity
        qty = val;                    // get user input
        if ((qty == "" || qty < 1 || isNaN (qty)) && tst) {  // test
          alert ("Enter a valid integer quantity!");
          return false;
        }
      } else {                        // this was not qty
        val = 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;
          val = 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;
        val = ChkFlg (val);          // flag chars?
        if (nam3 == "opt") {         // user says where to store
          Where (val, nam4);         // stash it
        } else if (val.length > 0) {
          AddDesc (val);             // add to data
        }
      }
    } else
    if (obj.type == "text" ||
        obj.type == "textarea") {  // user input fields
      val = obj.value;             // get input
      if (obj.name == "qty") {     // this is the quantity
        qty = val;                 // get user input
        if ((qty == "" || qty < 1 || isNaN (qty)) && tst) {  // 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 && tst) {   // minimum items ordered?
    alert ("You must order at least " + iqty + " of this item!");
    return false;
  }
  if (qty > xqty && tst) {   // maximum items that can be ordered
    alert ("Sorry. We only have " + xqty + " of this item available.");
    qty=xqty;
  }
  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 ("DIS=" + dis + "%");  // mark it
  }
  if (obj1.tot) obj1.tot.value = "$" + blk4a;
  if (tst) {
    StoreCart ();
//    if (root.xx_dadd == off) {
//     if (cfull = 0)
      alert("Item has been added to cart!");
//     else
//      alert("You must check out first before adding more items!");
      return false;            // hide cart display
//    }
  }
  return true;
}

/*
function replaceDoc() {
   window.location.replace("http://www.digitalheroes.com/cart2.asp")
}

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

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 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 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 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 SetCode (cd) { // set product code
  bcode = cd;
}

function SetDesc (strn) {  // set the desc field
  blk3n = strn;
}
/*
function SetFixed (amt, txt) {  // set flat charge to item
  ader = amt*1.0;
  if (txt.length > 0) adtx = ", " + txt;
  else adtx = "";
}

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 SetPerSH (pcat, a1, p1) {   // % of amt-based shipping brkpts
var i,pv;
var pval = new Array ();
var pper = new Array ();
  if (pcat >= cats) {          // check him out
    alert ("SetPerSH cat arg too big!");
    return;
  }
  pv = 0;                      // count of breakpoints
  for (i=1; i<arguments.length; i=i+2) {
    pval[pv] = arguments[i];   // price breakpoint
    pper[pv] = arguments[i+1]; // discount amount
    pv = pv + 1;               // number of bkpts
  }
  root["pv" + pcat]   = pv;    // stash that bad boy off
  root["pval" + pcat] = pval;
  root["pper" + pcat] = pper;
  root.store();                // remember forever...
}
*/
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 SetVBShip() // set values for VB Shipping Function
{
  var userAgentVar = navigator.userAgent;
  var goodStuff = false;
  if ((root.ups == -1)||(root.ups == undefined))
  {	
//  	root.cntry = document.getElementById("receivercountryname").value;
	var selectCountry = document.getElementById("receivercountryname"); 
	root.cntry = selectCountry.options[selectCountry.selectedIndex].text; 

  	root.zipp = document.getElementById("receiverpostalcode").value;
//	alert ("Submitting form: "+root.cntry+" "+root.zipp);
//	alert (document.getElementById("receiverpostalcode").value);
	if (document.getElementById("shipmentweight").value == "")
		document.getElementById("shipmentweight").value = twte * 1.0;	
//	alert (document.getElementById("shipmentweight").value);
	if (document.getElementById("receivercountrycode").value == "")
	{
		if (root.cntry == "Andorra")
			document.getElementById("receivercountrycode").value = "AD";
		else	
		if (root.cntry == "Argentina")
			document.getElementById("receivercountrycode").value = "AR";
		else		
		if (root.cntry == "Australia")
			document.getElementById("receivercountrycode").value = "AU";
		else
		if (root.cntry == "Austria")
			document.getElementById("receivercountrycode").value = "AT";
		else
		if (root.cntry == "Belgium")
			document.getElementById("receivercountrycode").value = "BE";
		else
		if (root.cntry == "Brazil")
			document.getElementById("receivercountrycode").value = "BR";
		else
		if (root.cntry == "Canada")
			document.getElementById("receivercountrycode").value = "CA";
		else
		if (root.cntry == "Chile")
			document.getElementById("receivercountrycode").value = "CL";
		else
		if (root.cntry == "China")
			document.getElementById("receivercountrycode").value = "CN";
		else
		if (root.cntry == "Colombia")
			document.getElementById("receivercountrycode").value = "CO";
		else
		if (root.cntry == "China")
			document.getElementById("receivercountrycode").value = "CN";
		else
		if (root.cntry == "Czech Republic")
			document.getElementById("receivercountrycode").value = "CZ";
		else
		if (root.cntry == "Denmark")
			document.getElementById("receivercountrycode").value = "DK";
		else
		if (root.cntry == "Denmark")
			document.getElementById("receivercountrycode").value = "DK";
		else
		if (root.cntry == "Finland")
			document.getElementById("receivercountrycode").value = "FI";
		else
		if (root.cntry == "France")
			document.getElementById("receivercountrycode").value = "FR";
		else
		if (root.cntry == "Germany")
			document.getElementById("receivercountrycode").value = "DE";
		else
		if (root.cntry == "Greece")
			document.getElementById("receivercountrycode").value = "GR";
		else	
		if (root.cntry == "Greenland")
			document.getElementById("receivercountrycode").value = "GL";
		else
		if (root.cntry == "Guam")
			document.getElementById("receivercountrycode").value = "GU";
		else
		if (root.cntry == "Hong Kong")
			document.getElementById("receivercountrycode").value = "HK";
		else
		if (root.cntry == "Hungary")
			document.getElementById("receivercountrycode").value = "HU";
		else
		if (root.cntry == "Iceland")
			document.getElementById("receivercountrycode").value = "IS";
		else
		if (root.cntry == "India")
			document.getElementById("receivercountrycode").value = "IN";
		else
		if (root.cntry == "Indonesia")
			document.getElementById("receivercountrycode").value = "ID";
		else
		if (root.cntry == "Ireland")
			document.getElementById("receivercountrycode").value = "IE";
		else
		if (root.cntry == "Israel")
			document.getElementById("receivercountrycode").value = "IL";
		else
		if (root.cntry == "Italy")
			document.getElementById("receivercountrycode").value = "IT";
		else
		if (root.cntry == "Japan")
			document.getElementById("receivercountrycode").value = "JP";
		else
		if (root.cntry == "Liechtenstein")
			document.getElementById("receivercountrycode").value = "LI";
		else
		if (root.cntry == "Luxembourg")
			document.getElementById("receivercountrycode").value = "LU";
		else
		if (root.cntry == "Malaysia")
			document.getElementById("receivercountrycode").value = "MY";
		else
		if (root.cntry == "Mexico")
			document.getElementById("receivercountrycode").value = "MX";
		else
		if (root.cntry == "Monaco")
			document.getElementById("receivercountrycode").value = "MC";
		else
		if (root.cntry == "Netherlands")
			document.getElementById("receivercountrycode").value = "NL";
		else
		if (root.cntry == "New Zealand")
			document.getElementById("receivercountrycode").value = "NZ";
		else
		if (root.cntry == "Norway")
			document.getElementById("receivercountrycode").value = "NO";
		else
		if (root.cntry == "Peru")
			document.getElementById("receivercountrycode").value = "PE";
		else
		if (root.cntry == "Philippines")
			document.getElementById("receivercountrycode").value = "PH";
		else
		if (root.cntry == "Poland")
			document.getElementById("receivercountrycode").value = "PL";
		else
		if (root.cntry == "Portugal")
			document.getElementById("receivercountrycode").value = "PT";
		else
		if (root.cntry == "Puerto Rico")
			document.getElementById("receivercountrycode").value = "PR";
		else
		if (root.cntry == "Russia")
			document.getElementById("receivercountrycode").value = "RU";
		else
		if (root.cntry == "Singapore")
			document.getElementById("receivercountrycode").value = "SG";
		else		
		if (root.cntry == "South Africa")
			document.getElementById("receivercountrycode").value = "ZA";
		else
		if (root.cntry == "South Korea")
			document.getElementById("receivercountrycode").value = "KR";
		else		
		if (root.cntry == "Spain")
			document.getElementById("receivercountrycode").value = "ES";
		else
		if (root.cntry == "Sri Lanka")
			document.getElementById("receivercountrycode").value = "LK";
		else
		if (root.cntry == "Sweden")
			document.getElementById("receivercountrycode").value = "SE";
		else
		if (root.cntry == "Switzerland")
			document.getElementById("receivercountrycode").value = "CH";
		else
		if (root.cntry == "Taiwan")
			document.getElementById("receivercountrycode").value = "TW";
		else
		if (root.cntry == "Thailand")
			document.getElementById("receivercountrycode").value = "TH";
		else
		if (root.cntry == "Turkey")
			document.getElementById("receivercountrycode").value = "TR";
		else
		if (root.cntry == "United Kingdom")
			document.getElementById("receivercountrycode").value = "GB";
		else
		if (root.cntry == "Vatican City")
			document.getElementById("receivercountrycode").value = "VA";
		else		
		if (root.cntry == "Vietnam")
			document.getElementById("receivercountrycode").value = "VN";
		else
		{		
			document.getElementById("receivercountrycode").value = "US";
			document.getElementById("receiverpostalcode").value = root.zipp.substring (0, 5);
		}
	}
	root.ups = 0;
	ccode = document.getElementById("receivercountrycode").value;
	if (Shipper(root.zipp, ccode))//validate zip code including sales tax stuff
		{	
		if (userAgentVar.indexOf("Firefox") == "-1")
			alert('Please wait while we get your shipping options.');
			goodStuff = true;			
		}		
  }
 return goodStuff;
}

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 &&
          cook.op1n == op1n &&
          cook.op1v == op1v &&
          cook.op2n == op2n &&
          cook.op2v == op2v) {
          cook.qty = cook.qty*1.0 + blk2q*1.0;  // combine
          if (cook.qty > xqty) {  // check for max qty
           alert ("Sorry. We only have " + xqty + " of this item available.");
           cook.qty = xqty; // set qty to max
           }
          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.xqty = xqty;
      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.ader = ader;
      cook.adtx = adtx;
      cook.store();
      ClearAll ();
      if (i == cmax - 1)
        alert ("Warning - Your Cart is now full! Please complete checkout before purchasing additional items.");
      return;      
    }
  }
  alert ("Your shopping cart is full! Please complete checkout before purchasing additional items.");
}

function UpdCart (i, itqty) {// added by jeff to change item qty in the cart
  ShipZap();
  itqty = itqty *1.0
  cook = new Cookie (document, "paycart" + i);
  cook.load();
//  alert ("max quantity  =  "  + cook.xqty);
  if (itqty > cook.xqty) {          // maximum items that can be ordered
     alert ("Sorry. We only have " + cook.xqty + " of this item available.");
     itqty = cook.xqty; // set qty to max   
  }
  cook.qty = itqty;
  cook.store();
  root.ups = -1; //reset shipping choice
  root.store();
  document.location.reload ();
}

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

function Xbild () {         // build the PayPal FORM
//alert("building PP form");
var inp = '<input type="hidden" name=';
var ary1 = new Array ();
var ary2 = new Array ();
var i,j,pc,sx;
var tot  = 0;               // price total
var tpr  = 0;               // price total
var frst = 1;               //  1st time thru marker
var str  = "";              // temp string
var disc = new Array ();    // price per item to subtract for discount
//var tmps = root.stxt0+" "+ttxt+" "+ctxt;  // the shipping text
var tmps = root.stxt1+" "+root.stxt0;  // the shipping text


  if (bmisc.length > 0) {            // apply misc codes
    ary1 = bmisc.split ("&");        // individual commands
    for (i=0; i<ary1.length; i++) {  // process individual entries
      if (ary1(i).length > 0) {      //  but only if something there
        ary2 = ary1[i].split ("=");  // get parts
        document.writeln (inp, '"', ary2[0], // build line
          '" value="', ary2[1], '" />');
      }
    }
  }

  if (ttax > 0)             // do we have a calculated tax
    document.writeln (inp, '"tax_cart" value="', Dollar(ttax), '" />');
  for (i=0; i<cats; i++) {  // set item discounts
    disc[i] = ctot["d" + i] / ctot["a" + i];  // % discount per item
  }

  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
	  tpr = Dollar (cook.prc * (1.0 - disc[cook.pcat]) + cook.ader / cook.qty);
      document.writeln (inp, '"quantity_', 
        j, '" value="', cook.qty, '" />');
      document.writeln (inp, '"item_name_', 
        j, '" value="', cook.des, cook.adtx, '" />');
      document.writeln (inp, '"amount_',
        j, '" value="', tpr, '" />');

//       document.writeln (inp, '"amount_',
//        j, '" value="', Dollar (cook.prc * (1.0 - disc[cook.pcat]) + cook.ader / cook.qty), '" />');
  
//	  if (gwtot > 0 && frst > 0) str = ', GIFT-WRAP';
      if (cook.op1n.length > 0) {    // 1st option present
        document.writeln (inp, '"on0_',
          j, '" value="', cook.op1n, '" />');
        document.writeln (inp, '"os0_',
          j, '" value="', cook.op1v + ', ' + tmps, '" />');
      } else if (tmps.length > 0) {
        document.writeln (inp, '"on0_',
          j, '" value="Shipping" />');
        document.writeln (inp, '"os0_',
          j, '" value="', tmps, str, '" />');
      }
      tmps = "";  // zap it
      str  = "";

      if (cook.op2n.length > 0) {    // 2nd option present
        document.writeln (inp, '"on1_',
          j, '" value="', cook.op2n, '" />');
        document.writeln (inp, '"os1_',
          j, '" value="', cook.op2v, '" />');
      }
      if (cook.cod != "")
        document.writeln (inp, '"item_number_',
          j, '" value="',cook.cod, '" />');
/*      if (frst > 0 && (hand > 0 || insx > 0 || gwtot > 0)) {
        document.writeln (inp, '"handling_',
          j,'" value="', Dollar (hand*1.0 + insx*1.0 + gwtot*tqty), '" />');
      } */
      if (frst > 0 && ship > 0) 
        document.writeln (inp, '"shipping_',
          j, '" value="', Dollar (ship), '" />');  
      else
        document.writeln (inp, '"shipping_',
          j, '" value="0" />');

      frst = 0;  // set to false - true only on 1st item
    }
  }
}

function Shipper (obj1, obj2) {  // use either amt or qty based shipping
/* Note - when using something other than SetAmtSH you must include
SetAmtSH (0,0,0); within every position to kill shipping question. 
AND, every call used here must have a zero call under the worst area.*/
var pos;
  zip = obj1.substring (0, 3);
  if ((zip >= 980) && (zip < 995)) // added by jeff - automatically calculate sales tax based on zip code
    {
       stax = 8.70;
       ttxt = "Washington State (8.7%) Sales Tax";
    }
  else
    {
       stax = 0;
       ttxt = "No Sales Tax";
    } 
	root.stax = stax;
	root.ttxt  = ttxt;     
  	root.stxt0 = obj2 + ' ' + obj1 + ' '; // Country and Postal Code
    usps = 1;

    if (!ShipChk (obj1, obj2)) return false;  // see if ZIP ok
//    SetAmtSH  (0,0,0);  //Do I still need?
  root.store();
  document.location.reload ();  // show the latest info...
  return true;
}

function ShipChk (obj1, obj2) {  // check for proper ZIP code
  if (obj2 == "US")
  {
  	zip = obj1.substring (0, 5);	
  	if (zip.length < 5 || isNaN(zip)) 
	{ // keep them honest  
   	 alert ("You must enter a valid ZIP code!");
   	 ShipZap ();
   	 document.location.reload ();  // show the latest info...
   	 return false;
  	}
  }
  return true;
}

function ShipZap () {  // error - zap all selections
  ship = 0;
  ttax = 0;
  usps = -1;
  uspp = -1;
  ups  = -1;
  ups2 = -1;
  cntry = "";
  zipp = -1;
  insu = -1;
  stxt0 = "Please select a shipping option!";
  stxt1 = "&nbsp;";
  root.usps = -1;
  root.uspp = -1;
  root.ups  = -1;
  root.ups2 = -1;
  root.insu = -1;
  root.cntry = "";
  root.zipp = "";
  root.stxt0 = stxt0;
  root.stxt1 = stxt1;
  root.ttax = 0;
  root.store ()
}

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;

  zne   = root.zne;
  usps  = root.usps;
  uspp  = root.uspp;
  ups   = root.ups;
  ups2  = root.ups2;
  cntry = root.cntry;
  zipp	= root.zipp;
  insu  = root.insu;
}

