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 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 = "";

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 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 zn   = 0;             // count of zip/zone pairs
var zzip = new Array ();  // zip code
var zone = new Array ();  // zone for that zip

var cdis = 0;            // amount of coupon discount
var coupval = "TNC000";         // coupon value user entered
var coupons = new Array ();
var coup = -1;            // cart discount coupon not active

// 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

// cart display options...
var on  = 1;       // on and off variables
var off = 0;
 
var chkby = 0;  // status of the checkbox

function winopen( url, name, features ) 
{
        win = window.open( url, name, features );
		win.focus();
}

function CartQty () 
{
	var total_items = 0;		// total items

	for (i=1; i<cmax; i++) 
	{  
		// get cookie info

    	cook = new Cookie (document, "paycart" + i);
	
		// load cookie

	    cook.load();

		// see if cookie has item qty 

	    if (cook.qty > 0) 
	    {
			// keep a running total of items

			total_items = total_items +  cook.qty * 1.0;
		}
	}

	// display number of items 

   	document.writeln (total_items, ' Items');
}

function UpdateQty(i, newQty)
{
	// get cookie info

   	cook = new Cookie (document, "paycart" + i);

	// load cookie

    cook.load();

	// update cookie qty

	cook.qty = cook.qty*1.0 + newQty*1.0;  

	// save cookie
	cook.store();

	ClearAll ();
}

function TotalSale()
{
	var item_price = 0;			// item price
	var	total_price = 0;		// total price
	var total_items = 0;		// total items

	for (i=1; i<cmax; i++) 
	{  
		// get cookie info

    	cook = new Cookie (document, "paycart" + i);
	
		// load cookie

	    cook.load();

		// see if cookie has item qty 

	    if (cook.qty > 0) 
	    {
			// item price

			item_price = Dollar(cook.prc) * 1.0;

			// qty of items (rounded off)

			total_items = cook.qty * 1.0;

			// calculate total price

			total_price = ((total_price * 1.0) + (Dollar(total_items * item_price) * 1.0));
		}
	}

	// display totals
	// NOTE: This does not include shipping

	document.writeln('Total: $', Dollar(total_price));
}

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));  
}

function AddPrice (strn) 
{  
	// add to current price

	blk4a = Dollar (blk4a*1.0 + strn*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;
	blkcc = "";                  // check default settings

	// set currency code 

	if (root.xx_cur.length > 0)  
		blkcc = blkcc + "&currency_code=" + root.xx_cur;

	// set country code

	if (root.xx_lc.length > 0)   
		blkcc = blkcc + "&lc=" + root.xx_lc;

	// set cancel return path

	if (root.xx_can.length > 0)  
		blkcc = blkcc + "&cancel_return=" + root.xx_can;

	// set return path 

	if (root.xx_ret.length > 0)  
		blkcc = blkcc + "&return=" + root.xx_ret;

	strn = blk1 + blk1u + blk2 + root.xx_id + blkcc + bmisc + Xbild ();

	ClearAll ();

	window.location = strn;
}

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

	window.location = "http://tncscooters.com/view.php?page=Cart";
}

function ChkCoup(amt) 
{  
	// check for a discount coupon
	var i;
	coup = -1;          // assume the worst

	for (i=0; i<coupons.length; i++) 
	{
		if (coupval == coupons[i]) 
		{
			// user hit the coupon value

			coup = 1;       

			// remember the discount amt

			cdis = amt;     

			root.coup = coup;
			root.cdis = cdis;

			// suppress display

			root.xx_coup = off;  
			root.store ();

			// display valid coupon code

			alert ("Valid coupon number! \n\n" + cdis + "% discount now in effect.");

			// show the latest info...

			document.location.reload ();  
			return;
		}
	}


	// user missed the coupon value

	coup = 0;       

	// remember the discount amt

	cdis = 0;     

	root.coup = coup;
	root.cdis = cdis;

	// suppress display

	root.xx_coup = off;  
	root.store ();

	// display invalid coupon code

	alert ("'" + coupval + "'  not a valid coupon!");

	// show the latest info...

	document.location.reload ();  
	return;
}

function ChkFlg (temp) 
{     
	// check for special flag char

	var pos;

	// is there a initial value?  

	pos  = temp.indexOf ("@"); 
	if (pos > 0) SetPrice (temp.substring (pos + 1));

	// is there a price adjustment?  

	pos  = temp.indexOf ("+"); 
	if (pos > 0) AddPrice (temp.substring (pos + 1));

	// is there a percent adjustment?  

	pos  = temp.indexOf ("%"); 
	if (pos > 0) AddPrcnt (temp.substring (pos + 1));
}

function ChkOpts () 
{  
	// check if user has selected everything

	if (root.xx_chkbx == on && chkby == 0) 
	{  
		// agree checkbox

		alert ('You must agree to terms!');
		return false;
	} 
	else if (root.xx_tax == on && ttxt.length == 0) 
	{  
		// tax selection

		alert ('Select tax!');
		return false;
	} 
	else if (root.xx_ship == on && root.sv0 == 0) 
	{  
		// shipping selection

		alert ('Select Shipping!');
		return false;
	}

	return true;
}

function ClearAll () 
{  
	// wipe out the last entry
	// quantity

	blk2q = "";  

	// name

	blk3n = "";  

	// price

	blk4a = "0"; 

	// item number

	bcode = "";  

	// extra data

	bmisc = "";  

	// clear options

	op1n  = "";  
	op1v  = "";
	op2n  = "";
	op2v  = "";
	imgx  = "dummy.jpg";
	bozs  = 0;
	dn    = 0;
	an    = 0;
	pcat  = 0;
}

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);
	InitData ();
}

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;

	// force, for now

	this.$path = "/";  

  	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';
/*
	// cookie diagnostic dump

	if (root.xx_cdmp == on)           
		alert(cookie.length + " chars - " + cookie);
*/
	// store with magic property

	this.$document.cookie = cookie;  
}

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 + '=');

	// Cookie not defined for this page.

	if (start == -1) 
		return false;   

	// Skip name and equals sign.

	start += this.$name.length + 1;  

	var end = allcookies.indexOf(';', start);

	if (end == -1) 
		end = allcookies.length;

	var cookieval = allcookies.substring(start, end);

	// array of name/value pairs.

	var a = cookieval.split('&');  

	// break each pair into an array.

	for(i=0; i < a.length; i++)  
		a[i] = a[i].split(':');

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

	// we're done, so return the success code.

	return true;     
}

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';

	// magic store

	this.$document.cookie = cookie;  
}

function Dollar (val) 
{  
	// force to valid dollar amount
	var str,pos,rnd=0;

	// for old Netscape browsers

	if (val < .995) 
		rnd = 1;  

	// float, round, escape

	str = escape (val*1.0 + 0.005001 + rnd);  

	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.des  = "";

	// option name and value

	cook.op1n = "";  
	cook.op1v = "";
	cook.op2n = "";
	cook.op2v = "";
	cook.prc  = 0;
	cook.ozs  = 0;
	cook.imgx = "dummy.jpg";

	// stash it off

	cook.store();    
}

function InitRoot () 
{  
	// Build the base root cookie

	var i;
	root.stax  = stax;     // stuff all base values
	root.ttxt  = ttxt;
	root.coup  = coup;
	root.cdis  = cdis;
	root.chkbx = chkby;

	// USPS flag

	root.usps = usps;     

	// USPS pp flag

	root.uspp = uspp;     

	// UPS flag

	root.ups  = ups;      

	// insurance flag

	root.insu = insu;     

	// destination zone

	root.zne  = zne;      
	root.xx_can  = "";
	root.xx_cc   = on;
	root.xx_cdmp = off;
	root.xx_chkbx= on;
	root.xx_coup = on;
	root.xx_cper = 0;
	root.xx_cur  = "USD";
	root.xx_dadd = on;
	root.xx_img  = on;
	root.xx_lc   = "US";
	root.xx_pc   = on;
	root.xx_prt  = on;
	root.xx_ret  = "";
	root.xx_ship = on;
	root.xx_sum  = on;
	root.xx_tax  = on;
	root.xx_wt   = on;

	for (i=0; i<cats; i++) 
	{
		// number of handling brkpts

		root["hn" + i]   = 0;                

		// cart hndl qty breakpoints

		root["hqty" + i] = new Array ();  

		// amount charged

		root["hamt" + i] = new Array ();  

		// number of qty breakpoints

		root["qd" + i]   = 0;              

		// cart QD breakpoints

		root["qqty" + i] = new Array ();  

		// amount of discount

		root["qamt" + i] = new Array ();  

		// number of shipping brkpts

		root["sn" + i]   = 0;              

		// cart ship qty breakpoints

		root["sqty" + i] = new Array ();  

		// amount charged

		root["samt" + i] = new Array ();  

		// text describing shipping

		root["stxt" + i] = "";             

		// number of bkpts

		root["sv" + i]   = 0;              

		// cart ship val breakpoints

		root["sval" + i] = new Array ();  

		// amount charged

		root["schg" + i] = new Array ();  

		// number of bkpts

		root["wv" + i]   = 0;             

		// cart ship val breakpoints

		root["wval" + i] = new Array ();  

		// amount charged

		root["wchg" + i] = new Array ();  
	}

	root.store();
}

function PrintCart () 
{  
	// print out entire cart

	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

	for (i=0; i<cats; i++) 
	{  
		// init pcat totals

		// amount in this cat

		ctot["a" + i] = 0;      

		// quantity in this cat

		ctot["q" + i] = 0;      

		// handling in this cat

		ctot["h" + i] = 0;      

		// shipping in this cat

		ctot["s" + i] = 0;      

		// discount in this cat

		ctot["d" + i] = 0;      
	}

	for (i=1; i<cmax; i++) 
	{  
		// print all entries

		cook = new Cookie (document, "paycart" + i);

		cook.load();

		if (cook.qty > 0) 
		{
			PrintItem (i);
		}
	}

	twgt = Math.floor ((tozs*1.0 + 15.999) / 16.0);
	tprc = Dollar (tprc)*1.0;             // round, float

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

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

		sh  = 0;                               
		ha  = 0;
		qt  = 0;

		var q = ctot["q" + p]*1.0;             // quantity this catagory
		var a = ctot["a" + p]*1.0;             // amount this category

		tmp1 = root["hqty" + p].split(",");
		tmp2 = root["hamt" + p].split(",");

		for (i=root["hn" + p]-1; i>=0; i--) 
		{  
			// run the table (if one)

			if (q >= tmp1[i]*1.0) 
			{              
				// Check the quantity
				// yep, set it

				ha = tmp2[i]*1.0;                  

				// a-dios, mo-fo

				break;                             
			}
		}

		ctot["h" + p] = ha;
		hand = hand + ha;

		tmp1 = root["sqty" + p].split(",");
		tmp2 = root["samt" + p].split(",");

		for (i=root["sn" + p]-1; i>=0; i--) 
		{  
			// run the table (if one)

			if (q >= tmp1[i]*1.0) 
			{              
				// Check the price
				// yep, set it

				sh = tmp2[i]*1.0;                  
				break;
			}
		}

		if (sh == 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
					// yep, set it

					sh = tmp2[i]*1.0;      
					break;
				}
			}
		}

		ctot["s" + p] = sh;
		ship = ship + sh;

		tmp1 = root["qqty" + p].split(",");
		tmp2 = root["qamt" + p].split(",");

		for (i=root["qd" + p]-1; i>=0; i--) 
		{
			if (q >= tmp1[i]*1.0) 
			{
				qt = tmp2[i]*1.0;
				break;
			}
		}

		if (coup > 0) 
		{
			qt = qt + a * cdis/100.0;
		}

		ctot["d" + p] = qt;
		qtyd = qtyd + qt;
	}

	// for special stuff...

	s = 0;  

	wte = Math.floor ((tozs + 15.999) / 16.0);

	if (usps > 0) 
	{  
		// usps priority mail

		if (wte > pz2.length) 
		{
			alert (wte + " is greater than length of USPS charge array!");
			s = 99999;
		} 
		else
			s = pzx[zne][wte]; // USPS charges to that zone
	}
	else if (uspp  > 0) 
	{  
		// usps parcel post

		if (wte > pp2.length) 
		{
			alert (wte + " is greater than length of USPS PP charge array!");
			s = 99999;
		} 
		else
			s = ppx[zne][wte]; // UPS charges
	} 
	else if (ups  > 0) 
	{  
		// ups ground

		if (wte > uz2.length) 
		{
			alert (wte + " is greater than length of UPS charge array!");
			s = 99999;
		} 
		else
			s = uzx[zne][wte]; // UPS charges
	}

	// only if wt shipping set

	ship = ship + s;  

	if (insu > 0) 
		insx = CalcInsu (tprc - qtyd);

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

function PrintItem (i) 
{  
	// make one entry in cart

	var tm,t1,t2,wt;
	document.writeln ('<tr valign="top" align="center">');
	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>');

//	document.writeln ('		<td >');
//	document.writeln ('         <input type="text" name="newQty" ');
//	document.writeln ('              value=' , cook.qty);
//	document.writeln ('              size="3" ');
//
//	document.writeln ('              onchange="UpdateQty(', i, newQty.value, '); ');
//	document.writeln ('              document.location.reload();" />');
//
//	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.op1n + ' ' + 
						cook.op1v + ' ' + 
						cook.op2n + ' ' + 
						cook.op2v,'</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" width="80" height="60"',
							' alt = "Image: Item" />',
							'</td>');
	}

	document.writeln ('</tr>');
}

function ReadForm (obj1) 
{ 
	//get form data for PayPal

	var i,j,obj,temp,pos,val,nam3,nam4;

	// default value

	var qty  = 0;              

	// quantity discount

	var dis  = 0;              

	for (i=0; i<obj1.length; i++) 
	{     
		// run whole form
		// ref particular element

		obj = obj1.elements[i];           

		// 3-char name (maybe)

		nam3 = obj.name.substring (0, 3); 

		// where to store it

		nam4 = obj.name.substring (3, 4); 

		if (obj.type == "select-one") 
		{   
			// dropdowns
			// which option selected

			pos = obj.selectedIndex;        
			val = obj.options[pos].value;   // get selection
			ChkFlg (val);                   // check for flag char
			if (nam3 == "opt") 
			{            
				// user says where to store
				// stash it
				Where (val, nam4);            
			} 
			else 
			{
				// add to data

				AddDesc (val);                
			}
		} 
		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;

					// flag chars?

					ChkFlg (val);                   

					// user says where to store

					if (nam3 == "opt") 
					{            
						// stash it

						Where (val, nam4);            
					} 
					else 
					{
						// add to data

						AddDesc (val);                
					}
				}
			}
		} 
		else if (obj.type == "checkbox" || obj.type == "radio") 
		{
			if (obj.checked) 
			{             
				// was selected

				val = obj.value;

				// flag chars?

				ChkFlg (val);                

				if (nam3 == "opt") 
				{         
					// user says where to store
					// stash it

					Where (val, nam4);         
				} 
				else 
				{
					// add to data

					AddDesc (val);             
				}
			}
		} 
		else if (obj.type == "text") 
		{  
			// user input fields
			// get input

			val = obj.value;         

			if (qty == 0) 
			{          
				// this is 1st time
				// get user input

				qty = val;             

				if (qty == "" || qty < 1 || isNaN (qty)) 
				{  
					// test

					alert ("Enter a valid integer quantity!");
					return false;
				}
			} 
			else 
			{
				if (nam3 == "opt") 
				{ 
					// user says where to store
					// stash it

					Where (val, nam4); 
        		} 
				else 
				{
					// add to data

					AddDesc (val);     
				}
			}
		}
	}

	// make sure we have something

	if (qty == 0) 
		qty = 1;     

	// record for posterity

	blk2q = qty;               

	for (i=an-1; i>=0; i--) 
	{  
		// qty amount?

		if (qty >= aqty[i]) 
		{    
			// qty brkpt
			// force it

			SetPrice (aamt[i]);    
			AddDesc ("AMT");

			// get out, now

			break;                 
		}
	}

	// any qty discounts?

	dis = 0;                   

	for (i=dn-1; i>=0; i--) 
	{  
		// run backwards

		if (qty >= dqty[i]) 
		{    
			// qty brkpt
			// set qty amount

			dis = damt[i];         

			// get out, now

			break;                 
		}
	}

	if (dis > 0) 
	{             
		// there is an item discount, here
		// apply the discount

		AddPrcnt (-dis);         

		// mark it

		AddDesc ("DIS=" + dis + "%");  
	}

	StoreCart ();

	// hide cart display

	if (root.xx_dadd == off) 
		return false;  

	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;
	}

	// count of breakpoints

	sv = 0;                      
	for (i=1; i<arguments.length; i=i+2) 
	{
		// price breakpoint

		sval[sv] = arguments[i];   

		// discount amount

		schg[sv] = arguments[i+1]; 

		// number of bkpts

		sv = sv + 1;               
	}

	// stash that bad boy off

	root["sv" + pcat]   = sv;    
	root["sval" + pcat] = sval;
	root["schg" + pcat] = schg;

	// remember forever...

	root.store();                
}

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;
	}

	// count of breakpoints

	hn = 0;                      
	for (i=1; i<arguments.length; i=i+2) 
	{
		// price breakpoint

		hqty[hn] = arguments[i];   

		// discount amount

		hamt[hn] = arguments[i+1]; 

		// number of bkpts

		hn = hn + 1;               
	}

	// stash that bad boy off

	root["hn" + pcat] = hn;      
	root["hqty" + pcat] = hqty;
	root["hamt" + pcat] = hamt;

	// remember forever...

	root.store();                
}

function SetCartQD (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 ("SetCartQD cat arg too big!");
		return;
	}

	// count of breakpoints

	qd = 0;                      

	for (i=1; i<arguments.length; i=i+2) 
	{
		// price breakpoint

		qqty[qd] = arguments[i];   

		// discount amount

		qamt[qd] = arguments[i+1]; 

		// number of bkpts

		qd = qd + 1;               
	}

	// stash that bad boy off

	root["qd" + pcat] = qd;      
	root["qqty" + pcat] = qqty;
	root["qamt" + pcat] = qamt;

	// remember forever...

	root.store();                
}

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;
	}

	// count of breakpoints

	sn = 0;                      
	for (i=1; i<arguments.length; i=i+2) 
	{
		// price breakpoint

		sqty[sn] = arguments[i];   

		// handling charge

		samt[sn] = arguments[i+1]; 

		// number of bkpts

		sn = sn + 1;               
	}

	// stash that bad boy off

	root["sn" + pcat] = sn;      
	root["sqty" + pcat] = sqty;
	root["samt" + pcat] = samt;

	// remember forever...

	root.store();                
}

function SetCartTX (obj1) 
{    
	// set cart tax value

	var i,pos;

	// which item selected

	pos  = obj1.selectedIndex;   
	stax = obj1.options[pos].value;
	ttxt = obj1.options[pos].text;
	root.stax = stax;
	root.ttxt = ttxt;

	// remember forever...

	root.store();                

	// show the latest info...

	document.location.reload ();  
}

function SetCode (cd) 
{ 
	// set product code

	bcode = cd;
}

function SetDesc (strn) 
{  
	// set the desc field

	blk3n = strn;
}

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;

	// count of breakpoints

	an = 0;                      
	for (i=0; i<arguments.length; i=i+2) 
	{
		// quantity

		aqty[an] = arguments[i];   

		// amount

		aamt[an] = arguments[i+1]; 

		// number of discount bkpts

		an = an + 1;               
	}
}

function SetQtyD (q1, d1) 
{    
	// set item qty discount breakpoints

	var i;

	// count of breakpoints

	dn = 0;                      

	for (i=0; i<arguments.length; i=i+2) 
	{
		// quantity

		dqty[dn] = arguments[i];   

		// percent

		damt[dn] = arguments[i+1]; 

		// number of discount bkpts

		dn = dn + 1;               
	}
}

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;
	}

	// count of breakpoints

	wv = 0;                      

	for (i=1; i<arguments.length; i=i+2) 
	{
		// price breakpoint

		wval[wv] = arguments[i];   

		// discount amount

		wchg[wv] = arguments[i+1]; 

		// number of bkpts

		wv = wv + 1;               
	}

	// stash that bad boy off

	root["wv" + pcat]   = wv;    
	root["wval" + pcat] = wval;
	root["wchg" + pcat] = wchg;

	// remember forever...

	root.store();                
}

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

function SetZone (zi1, zn1) 
{  
	// record zip/zone info into table
	var i;

	// count of breakpoints
	zn = 0;                      
	for (var i=0; i<arguments.length; i=i+2) 
	{
		// zip code index

		zzip[zn] = arguments[i];   
		
		// zone

		zone[zn] = arguments[i+1]; 

		// number of bkpts

		zn = zn + 1;               
	}
}

function StoreCart () 
{  
	// store data in local cart
	var i;

	for (i=1; i<cmax; i++) 
	{      
		//check for dup entry
		// run
		cook = new Cookie (document, "paycart" + i);  

		// get values

		cook.load();                

		if (cook.qty*1.0 > 0) 
		{     
			// check it out - combine dups
			// check everything!!!

			if (cook.cod == bcode &&  
				cook.des == blk3n &&
				cook.prc*1.0 == blk4a*1.0 &&
				cook.op1n == op1n &&
				cook.op1v == op1v &&
				cook.op2n == op2n &&
				cook.op2v == op2v) 
			{
				// combine

				cook.qty = cook.qty*1.0 + blk2q*1.0;  
				cook.store();
				ClearAll ();

				// th-th-thats all, folks

				return;                 
			}
		}
	}

	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.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 Xbild () 
{         
	// 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 tmps = root.stxt0+" "+ttxt;  // the shipping text

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

	// starting suffix

	j = 0;       

	for (i=1; i<cmax; i++) 
	{  
		// run all the data cookies

		cook = new Cookie (document, "paycart" + i);

		// get contents

		cook.load();         

		if (cook.qty > 0) 
		{  
			// something here
			// bump suffix

			j = j + 1;         

			str = str + "&quantity_"    + j + "=" + cook.qty;
			str = str + "&item_name_"   + j + "=" + escape (cook.des);
			str = str + "&amount_"      + j + "=" + Dollar (cook.prc*1.0 - disc[cook.pcat]);

			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 && ship > 0) 
			{
		        str = str + "&on0_"       + j + "=Shipping";
    		    str = str + "&os0_"       + j + "=" + escape (tmps);
		      }

		// zap it

		tmps = "";  

		// 2nd option present

		if (cook.op2n.length > 0) 
		{    
			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*1.0 > 0 || insx*1.0 > 0)) 
		{
			str = str + "&handling_" + j + "=" + 
			Dollar (hand*1.0 + insx*1.0);
		}

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

		if (frst > 0) 
		{
			str = str + "&shipping_"  + j + "=" + Dollar (ship);
		} 
		else if (frst == 0 && ship > 0) 
		{
			str = str + "&shipping_"  + j + "=0";
		}

		// set to false;

		frst = 0;  
	}  
  }

  return str;
}


// these are the priority mail zone charge tables (1-8) to 70 lbs.
// NOTE: $0.75 cents has been added to all zone charges.

//var pz1  = new Array (0,  
//  5.00,   5.15,   5.95,   6.55,   7.10,   7.60,   8.10,   8.70,   9.30,   9.80, 
// 10.40,  10.95,  11.50,  12.05,  12.60,  13.20,  13.75,  14.30,  14.85,  15.45, 
// 15.95,  16.55,  17.10,  17.65,  18.25,  18.75,  19.35,  19.90,  20.45,  21.05, 
// 21.55,  22.15,  22.70,  23.25,  23.80,  24.40,  24.95,  25.50,  26.00,  26.50,
// 27.00,  27.50,  28.00,  28.50,  29.00,  29.50,  30.00,  30.50,  30.05,  31.45, 
// 32.00,  32.45,  33.00,  33.45,  34.00,  34.45,  35.00,  35.45,  36.00,  36.45, 
// 37.00,  37.45,  38.00,  38.45,  39.00,  39.45,  40.00,  40.45,  50.00,  50.50);
//var pz2  = new Array (0,
//  5.00,   5.15,   5.95,   6.55,   7.10,   7.60,   8.10,   8.70,   9.30,   9.80, 
// 10.40,  10.95,  11.50,  12.05,  12.60,  13.20,  13.75,  14.30,  14.85,  15.45, 
// 15.95,  16.55,  17.10,  17.65,  18.25,  18.75,  19.35,  19.90,  20.45,  21.05, 
// 21.55,  22.15,  22.70,  23.25,  23.80,  24.40,  24.95,  25.50,  26.00,  26.50,
// 27.00,  27.50,  28.00,  28.50,  29.00,  29.50,  30.00,  30.50,  30.05,  31.45, 
// 32.00,  32.45,  33.00,  33.45,  34.00,  34.45,  35.00,  35.45,  36.00,  36.45, 
// 37.00,  37.45,  38.00,  38.45,  39.00,  39.45,  40.00,  40.45,  50.00,  50.50);
//var pz3  = new Array (0,
//  5.00,   5.15,   5.95,   6.55,   7.10,   7.60,   8.10,   8.70,   9.30,   9.80, 
// 10.40,  10.95,  11.50,  12.05,  12.60,  13.20,  13.75,  14.30,  14.85,  15.45, 
// 15.95,  16.55,  17.10,  17.65,  18.25,  18.75,  19.35,  19.90,  20.45,  21.05, 
// 21.55,  22.15,  22.70,  23.25,  23.80,  24.40,  24.95,  25.50,  26.00,  26.50,
// 27.00,  27.50,  28.00,  28.50,  29.00,  29.50,  30.00,  30.50,  30.05,  31.45, 
// 32.00,  32.45,  33.00,  33.45,  34.00,  34.45,  35.00,  35.45,  36.00,  36.45, 
// 37.00,  37.45,  38.00,  38.45,  39.00,  39.45,  40.00,  40.45,  50.00,  50.50);
//var pz4  = new Array (0, 
//  5.00,   5.75,   7.35,   8.40,   9.40,  10.30,  11.30,  12.30,  13.30,  14.25, 
// 15.00,  15.75,  16.50,  17.25,  18.00,  18.75,  19.50,  20.25,  21.00,  21.75, 
// 22.50,  23.25,  24.00,  24.70,  25.50,  26.25,  27.00,  27.70,  28.50,  29.25, 
// 30.00,  30.75,  31.45,  32.25,  33.00,  33.75,  34.65,  35.35,  36.25,  37.10,
// 38.85,  38.75,  39.55,  40.35,  41.20,  42.05,  42.85,  43.75,  44.55,  45.40, 
// 46.20,  47.05,  47.85,  48.65,  49.55,  50.35,  51.15,  52.00,  52.85,  53.65, 
// 54.55,  55.30,  56.20,  57.00,  57.75,  58.65,  59.55,  60.30,  61.15,  62.05);
//var pz5  = new Array (0,
//  5.00,   6.10,   8.15,   9.45,  10.75,  11.40,  12.20,  13.00,  14.80,  14.65, 
// 15.45,  16.25,  17.10,  17.85,  18.70,  19.50,  20.30,  21.30,  22.25,  23.25, 
// 24.50,  25.15,  26.15,  27.15,  28.10,  29.00,  30.00,  31.00,  32.00,  32.95, 
// 33.85,  34.85,  35.85,  36.75,  37.75,  38.75,  39.75,  40.70,  41.70,  42.70,
// 43.60,  44.55,  45.55,  46.55,  47.50,  48.45,  49.45,  50.45,  51.45,  52.35, 
// 53.30,  54.30,  55.25,  56.25,  57.35,  58.15,  59.10,  60.10,  61.10,  62.10, 
// 63.00,  64.00,  65.00,  66.00,  66.85,  67.85,  68.85,  69.85,  70.80,  71.75);
//var pz6  = new Array (0,
//  5.00,   6.25,   8.50,   9.90,  11.35,  11.55,  12.55,  13.55,  14.55,  15.70, 
// 16.90,  18.15,  19.40,  20.55,  21.75,  22.95,  24.20,  25.35,  26.55,  27.65, 
// 28.95,  30.10,  31.30,  32.45,  33.75,  34.95,  36.10,  37.30,  38.45,  39.75, 
// 40.85,  42.05,  43.20,  44.45,  45.65,  46.85,  48.00,  49.30,  50.50,  51.65,
// 52.85,  53.95,  55.25,  56.40,  57.60,  58.75,  60.05,  61.25,  62.40,  63.60, 
// 64.75,  66.05,  67.20,  68.35,  69.50,  70.80,  71.95,  73.15,  74.30,  75.55, 
// 76.80,  77.95,  79.15,  80.35,  81.55,  82.70,  83.90,  85.05,  86.30,  87.50);
//var pz7  = new Array (0,
//  5.00,   6.65,   9.20,  10.90,  12.55,  12.85,  14.20,  15.50,  16.80,  18.15, 
// 19.45,  20.75,  22.10,  23.35,  24.65,  26.00,  27.30,  28.60,  29.95,  31.25, 
// 32.55,  33.90,  35.15,  36.45,  37.80,  39.10,  40.40,  41.75,  43.05,  44.35, 
// 45.65,  46.95,  48.25,  49.60,  50.90,  52.25,  53.55,  54.85,  56.20,  57.45,
// 58.75,  60.15,  61.45,  62.80,  64.15,  65.45,  66.85,  68.15,  69.50,  70.85, 
// 72.15,  73.45,  74.80,  76.10,  77.35,  78.70,  80.00,  81.30,  82.65,  83.95, 
// 85.25,  86.60,  87.90,  89.15,  90.50,  91.80,  93.10,  94.45,  95.75,  97.05);
//var pz8  = new Array (0,
//  5.00,   7.00,   9.95,  11.85,  13.75,  14.90,  15.75,  17.55,  19.40,  21.20, 
// 23.00,  24.80,  26.60,  28.40,  30.25,  32.05,  33.85,  35.70,  37.45,  39.30, 
// 41.10,  42.90,  44.75,  46.55,  48.35,  50.15,  51.95,  53.80,  55.60,  57.40, 
// 59.25,  61.05,  62.80,  64.65,  66.45,  68.25,  70.10,  71.90,  73.75,  75.50,
// 77.30,  79.15,  80.95,  82.75,  84.60,  86.40,  88.15,  90.00,  91.80,  93.65, 
// 95.45,  97.25,  99.10, 100.85, 102.65, 104.55, 106.30, 108.10, 109.95, 111.75, 
//113.55, 115.35, 117.15, 119.00, 120.80, 122.60, 124.45, 126.20, 128.00, 129.85);

var pz1  = new Array (0, 
 5.90,  6.00,  6.70,  7.45,  8.65,  9.30,  9.95, 10.60, 11.25, 11.90, 
12.70, 13.50, 14.25, 15.05, 15.65, 16.10, 16.65, 16.95, 17.45, 17.85, 
18.35, 18.75, 19.15, 19.60, 20.00, 20.40, 20.95, 21.55, 22.20, 22.85, 
23.40, 23.70, 24.00, 24.25, 24.55, 24.80, 25.05, 25.30, 25.55, 25.80, 
26.05, 26.25, 26.50, 26.70, 26.90, 27.10, 27.30, 27.50, 27.70, 27.85, 
28.00, 28.25, 28.75, 29.10, 29.60, 30.00, 30.45, 30.85, 31.35, 31.70, 
32.20, 32.55, 33.10, 33.45, 33.90, 34.30, 34.80, 35.20, 35.65, 36.05);

var pz2  = new Array (0, 
 5.90,  6.00,  6.70,  7.45,  8.65,  9.30,  9.95, 10.60, 11.25, 11.90, 
12.70, 13.50, 14.25, 15.05, 15.65, 16.10, 16.65, 16.95, 17.45, 17.85, 
18.35, 18.75, 19.15, 19.60, 20.00, 20.40, 20.95, 21.55, 22.20, 22.85, 
23.40, 23.70, 24.00, 24.25, 24.55, 24.80, 25.05, 25.30, 25.55, 25.80, 
26.05, 26.25, 26.50, 26.70, 26.90, 27.10, 27.30, 27.50, 27.70, 27.85, 
28.00, 28.25, 28.75, 29.10, 29.60, 30.00, 30.45, 30.85, 31.35, 31.70, 
32.20, 32.55, 33.10, 33.45, 33.90, 34.30, 34.80, 35.20, 35.65, 36.05);

var pz3  = new Array (0,
 5.95,  6.35,  7.55,  8.55,  9.75, 10.65, 11.55, 12.45, 13.35, 14.25, 
15.20, 16.20, 17.15, 18.10, 19.10, 20.05, 21.00, 21.65, 22.10, 22.40, 
22.70, 23.15, 23.40, 23.65, 24.00, 24.25, 24.60, 24.90, 25.15, 25.50, 
25.70, 26.30, 26.95, 27.65, 28.30, 29.05, 29.60, 30.30, 30.90, 31.55, 
32.15, 32.75, 33.25, 33.80, 34.10, 34.40, 34.65, 34.95, 35.20, 35.45, 
35.70, 35.90, 36.15, 36.35, 36.55, 36.75, 36.95, 37.10, 37.25, 37.45, 
37.60, 37.70, 37.85, 37.95, 38.05, 38.15, 38.25, 38.35, 38.40, 38.50);

var pz4  = new Array (0, 
 6.05,  6.95,  8.50,  9.60, 10.85, 12.00, 12.75, 14.30, 15.40, 16.70, 
17.90, 19.15, 20.20, 21.35, 22.50, 23.65, 24.85, 26.00, 26.50, 26.95, 
27.35, 27.80, 28.55, 29.40, 30.30, 31.25, 32.15, 33.00, 33.90, 34.65, 
35.20, 35.75, 36.30, 36.85, 37.35, 37.85, 38.35, 38.85, 39.30, 39.75, 
40.20, 40.65, 41.05, 41.50, 41.85, 42.25, 42.65, 43.00, 43.35, 43.65, 
44.00, 44.30, 44.60, 44.90, 45.15, 45.45, 45.70, 45.95, 46.15, 46.60, 
47.40, 48.05, 48.80, 49.50, 50.15, 50.90, 51.75, 52.40, 53.05, 53.90);

var pz5  = new Array (0,
 6.15,  8.50, 10.00, 12.90, 14.50, 16.05, 17.80, 19.20, 20.75, 22.35, 
24.05, 25.70, 27.15, 28.80, 30.40, 32.00, 33.65, 35.25, 36.15, 36.75, 
37.35, 38.15, 38.80, 39.60, 40.25, 41.05, 41.60, 42.10, 42.65, 43.25, 
43.80, 44.30, 44.85, 45.80, 46.75, 47.75, 48.60, 49.55, 50.55, 51.55, 
52.05, 53.10, 54.30, 55.45, 56.65, 57.70, 58.95, 60.10, 61.20, 62.35, 
63.40, 63.90, 64.40, 64.90, 65.35, 65.80, 66.20, 66.60, 67.00, 67.35, 
67.70, 68.00, 68.35, 68.65, 68.90, 69.15, 69.40, 69.60, 69.80, 70.00);

var pz6  = new Array (0,
 6.25,  9.10, 10.95, 14.00, 15.85, 17.65, 19.40, 21.20, 23.00, 24.75, 
26.55, 28.75, 30.75, 32.40, 33.80, 35.60, 37.40, 39.25, 41.05, 42.05, 
42.70, 43.65, 44.40, 45.30, 45.95, 47.00, 47.65, 48.30, 48.90, 49.55, 
50.20, 50.85, 51.50, 53.00, 54.40, 55.75, 57.15, 58.75, 60.20, 61.55, 
62.95, 64.30, 65.85, 66.90, 67.65, 68.35, 69.05, 69.70, 70.35, 71.00,  
71.60, 72.20, 72.75, 73.30, 73.85, 74.35, 74.85, 75.30, 75.75, 76.15, 
76.55, 76.95, 77.30, 77.65, 77.95, 78.25, 78.55, 78.80, 79.00, 79.20);

var pz7  = new Array (0,
 6.35,  9.60, 11.70, 14.80, 16.85, 18.80, 21.05, 23.05, 24.95, 27.30, 
30.05, 32.40, 33.65, 35.50, 36.25, 38.20, 40.15, 42.10, 44.05, 45.60, 
46.35, 47.45, 48.20, 49.30, 50.05, 51.10, 51.80, 52.55, 53.25, 54.00, 
54.70, 56.00, 57.50, 59.05, 60.65, 62.25, 63.85, 65.30, 66.95, 68.45, 
69.90, 70.80, 71.65, 72.50, 73.30, 74.10, 74.90, 75.60, 76.35, 77.05, 
77.75, 78.40, 79.00, 79.60, 80.20, 80.75, 81.30, 81.80, 82.30, 82.80, 
83.25, 83.65, 84.05, 84.45, 84.80, 85.10, 85.45, 85.70, 86.00, 86.35);

var pz8  = new Array (0,
 6.55, 10.55, 13.70, 16.30, 18.65, 20.90, 23.40, 26.10, 28.95, 31.40, 
34.35, 36.85, 38.10, 39.95, 41.05, 43.30, 45.55, 47.80, 50.00, 52.25, 
53.40, 54.70, 55.65, 57.00, 57.95, 59.75, 61.95, 64.20, 65.90, 67.35, 
68.70, 70.05, 71.35, 72.65, 73.90, 75.15, 76.35, 77.55, 78.70, 79.80, 
80.90, 82.00, 83.05, 84.05, 85.05, 86.05, 87.00, 87.90, 88.80, 89.70, 
90.50, 91.35, 92.15, 92.90, 93.65, 94.35, 95.05, 95.75, 96.45, 97.15, 
98.45, 100.00, 101.55, 103.10, 104.70, 106.20, 107.85, 109.35, 110.95, 112.50);

var pzx  = new Array (0,pz1,pz2,pz3,pz4,pz5,pz6,pz7,pz8);

// these are the parcel post mail zone charge tables (1-8) to 40lbs.
var pp1  = new Array (0,
  3.69,  3.85,  4.65,  4.86,  5.03,  5.63,  5.80,  5.98,  6.11,  6.28,
  6.41,  6.54,  6.67,  6.80,  6.92,  7.02,  7.15,  7.25,  7.37,  7.46,
  7.57,  7.66,  7.76,  7.83,  7.93,  8.01,  8.11,  8.18,  8.27,  8.35,
  8.44,  8.50,  8.58,  8.66,  8.74,  8.80,  8.87,  8.94,  9.02,  9.09);
var pp2  = new Array (0,
  3.69,  3.85,  4.65,  4.86,  5.03,  5.63,  5.80,  5.98,  6.11,  6.28,
  6.41,  6.54,  6.67,  6.80,  6.92,  7.02,  7.15,  7.25,  7.37,  7.46,
  7.57,  7.66,  7.76,  7.83,  7.93,  8.01,  8.11,  8.18,  8.27,  8.35,
  8.44,  8.50,  8.58,  8.66,  8.74,  8.80,  8.87,  8.94,  9.02,  9.09);
var pp3  = new Array (0,
  3.75,  3.85,  4.65,  5.20,  5.71,  6.01,  6.28,  6.53,  6.75,  7.57,
  7.80,  8.01,  8.19,  8.42,  8.61,  8.79,  8.94,  9.11,  9.28,  9.43,
  9.58,  9.72,  9.89, 10.01, 10.14, 10.27, 10.40, 10.52, 10.65, 10.76,
 10.86, 10.99, 11.10, 11.18, 11.30, 11.39, 11.48, 11.60, 11.67, 11.78);
var pp4  = new Array (0, 
  3.75,  4.14,  5.55,  6.29,  6.94,  7.44,  7.91,  8.30,  8.74,  9.10,
  9.47,  9.80, 10.12, 10.43, 10.73, 11.00, 11.28, 11.52, 11.77, 11.98,
 12.20, 12.42, 12.65, 12.83, 13.03, 13.21, 13.38, 13.58, 13.75, 13.90,
 14.06, 14.22, 14.38, 14.51, 14.66, 14.82, 14.93, 15.07, 15.19, 15.32);
var pp5  = new Array (0,
  3.75,  4.14,  5.65,  6.93,  7.75,  8.50,  9.20,  9.84, 10.45, 11.01,
 11.54, 12.04, 12.51, 12.95, 13.38, 13.78, 14.16, 14.52, 14.87, 15.20,
 15.52, 15.82, 16.11, 16.39, 16.66, 16.92, 17.17, 17.41, 17.64, 17.87,
 18.08, 18.29, 18.49, 18.69, 18.88, 21.06, 19.23, 19.41, 19.57, 19.73);
var pp6  = new Array (0,
  3.75,  4.49,  5.71,  7.14,  8.58,  9.52, 10.35, 11.11, 11.83, 12.50,
 13.13, 13.72, 14.28, 14.81, 15.31, 15.79, 16.24, 16.68, 17.09, 17.48,
 17.86, 18.22, 18.57, 18.90, 19.22, 19.53, 19.83, 20.11, 20.39, 20.65,
 20.91, 21.16, 21.40, 21.63, 21.85, 22.07, 22.28, 22.48, 22.68, 22.87);
var pp7  = new Array (0,
  3.75,  4.49,  5.77,  7.20,  8.64,  9.90, 11.38, 12.54, 13.38, 14.17,
 14.92, 15.62, 16.27, 16.90, 17.49, 18.05, 18.59, 19.09, 19.58, 20.05,
 20.49, 20.92, 21.65, 21.72, 22.09, 22.46, 22.81, 23.14, 23.47, 23.78,
 24.08, 24.37, 24.65, 24.93, 25.19, 25.25, 25.69, 25.93, 26.17, 26.39);
var pp8  = new Array (0,
  3.75,  4.49,  6.32,  7.87,  9.43, 11.49, 12.83, 15.04, 17.04, 18.14,
 19.15, 20.10, 20.99, 21.84, 22.64, 23.41, 24.13, 24.82, 25.48, 26.12,
 26.72, 27.30, 27.85, 28.39, 28.90, 29.39, 29.87, 30.32, 30.76, 31.19,
 31.60, 32.00, 32.38, 32.75, 33.11, 33.45, 33.79, 34.12, 34.43, 40.24);
var ppx  = new Array (0,pp1,pp2,pp3,pp4,pp5,pp6,pp7,pp8);

// UPS residential ground, lower 48 charges to 70 lbs. 5 Jan 2004
var uz1  = new Array (0,
  6.25,  6.35,  6.50,  6.65,  6.90,  7.05,  7.30,  7.50,  7.70,  7.90,
  8.10,  8.35,  8.55,  8.70,  8.90,  9.00,  9.10,  9.25,  9.40,  9.60,
  9.80, 10.00, 10.20, 10.40, 10.60, 10.85, 11.05, 11.25, 11.45, 11.70,
 11.90, 12.10, 12.30, 12.50, 12.70, 12.90, 13.10, 13.30, 13.45, 13.65,
 13.80, 14.00, 14.15, 14.35, 14.50, 14.60, 14.75, 14.85, 15.00, 15.10,
 15.25, 15.40, 15.50, 15.65, 15.75, 15.90, 16.00, 16.15, 16.30, 16.40,
 16.55, 16.65, 16.80, 16.95, 17.05, 17.20, 17.30, 17.45, 17.55, 17.65);
var uz2  = new Array (0,
  6.25,  6.35,  6.50,  6.65,  6.90,  7.05,  7.30,  7.50,  7.70,  7.90,
  8.10,  8.35,  8.55,  8.70,  8.90,  9.00,  9.10,  9.25,  9.40,  9.60,
  9.80, 10.00, 10.20, 10.40, 10.60, 10.85, 11.05, 11.25, 11.45, 11.70,
 11.90, 12.10, 12.30, 12.50, 12.70, 12.90, 13.10, 13.30, 13.45, 13.65,
 13.80, 14.00, 14.15, 14.35, 14.50, 14.60, 14.75, 14.85, 15.00, 15.10,
 15.25, 15.40, 15.50, 15.65, 15.75, 15.90, 16.00, 16.15, 16.30, 16.40,
 16.55, 16.65, 16.80, 16.95, 17.05, 17.20, 17.30, 17.45, 17.55, 17.65);
var uz3  = new Array (0,
  6.40,  6.65,  6.85,  7.15,  7.35,  7.50,  7.65,  7.85,  8.05,  8.25,
  8.40,  8.65,  8.90,  9.10,  9.35,  9.60,  9.85, 10.10, 10.40, 10.70,
 11.00, 11.30, 11.60, 11.85, 12.10, 12.40, 12.60, 12.85, 13.15, 13.40,
 13.65, 13.95, 14.20, 14.50, 14.75, 15.05, 15.39, 15.60, 15.85, 16.15,
 16.45, 16.70, 17.00, 17.25, 17.50, 17.80, 18.00, 18.25, 18.45, 18.65,
 18.80, 19.00, 19.15, 19.30, 19.45, 19.65, 19.80, 19.95, 20.10, 20.25,
 20.40, 20.55, 20.70, 20.85, 21.00, 21.15, 21.25, 21.40, 21.55, 21.70);
var uz4  = new Array (0,
  6.75,  7.20,  7.50,  7.85,  8.10,  8.25,  8.45,  8.60,  8.80,  8.95,
  9.10,  9.25,  9.40,  9.55,  9.70,  9.90, 10.15, 10.45, 10.80, 11.10,
 11.45, 11.80, 12.10, 12.45, 12.80, 13.15, 13.50, 13.85, 14.20, 14.55,
 14.90, 15.25, 15.65, 16.00, 16.35, 16.65, 17.00, 17.35, 17.70, 18.05,
 18.40, 18.75, 19.00, 19.40, 19.70, 20.00, 20.30, 20.60, 20.85, 21.15,
 21.40, 21.65, 21.90, 22.15, 22.35, 22.60, 22.80, 23.00, 23.20, 23.40,
 23.60, 23.75, 23.95, 24.10, 24.25, 24.40, 24.55, 24.70, 24.85, 25.00);
var uz5  = new Array (0,
  6.85,  7.35,  7.75,  8.15,  8.45,  8.70,  8.95,  9.15,  9.35,  9.60,
  9.80, 10.00, 10.20, 10.40, 10.65, 10.90, 11.30, 11.75, 12.25, 12.75,
 13.25, 13.70, 14.15, 14.55, 14.95, 15.35, 15.75, 16.20, 16.65, 17.10,
 17.50, 17.95, 18.40, 18.85, 19.30, 19.75, 20.15, 20.60, 21.05, 21.50,
 21.95, 22.40, 22.85, 23.25, 23.70, 24.15, 24.55, 24.95, 25.35, 25.70,
 26.05, 26.40, 26.75, 27.05, 27.35, 27.65, 27.95, 28.25, 28.50, 28.70,
 28.90, 29.10, 29.25, 29.45, 29.65, 29.80, 30.00, 30.20, 30.40, 30.55);
var uz6  = new Array (0,
  7.15,  7.80,  8.20,  8.60,  8.95,  9.20,  9.50,  9.80, 10.00, 10.35,
 10.75, 11.15, 11.65, 12.20, 12.80, 13.30, 13.90, 14.50, 15.10, 15.70,
 16.30, 16.90, 17.50, 18.10, 18.70, 19.30, 19.90, 20.50, 21.10, 21.70,
 22.30, 22.90, 23.45, 24.05, 24.65, 25.20, 25.75, 26.30, 26.80, 27.35,
 27.90, 28.40, 28.95, 29.40, 29.90, 30.35, 30.75, 31.20, 31.55, 32.00,
 32.35, 32.70, 33.10, 33.45, 33.80, 34.20, 34.55, 34.90, 35.20, 35.55,
 35.85, 36.10, 36.30, 36.55, 36.75, 37.00, 37.25, 37.45, 37.65, 37.85);
var uz7  = new Array (0,
  7.20,  7.95,  8.45,  8.85,  9.25,  9.60,  9.95, 10.35, 10.80, 11.50,
 12.20, 12.95, 13.65, 14.40, 15.10, 15.80, 16.50, 17.20, 17.90, 18.60,
 19.30, 20.00, 20.65, 21.40, 22.10, 22.75, 23.40, 24.05, 24.80, 25.50,
 26.25, 26.95, 27.70, 28.45, 29.15, 29.90, 30.60, 31.35, 32.05, 32.80,
 33.55, 34.25, 34.95, 35.70, 36.40, 37.05, 37.65, 38.30, 38.90, 39.50,
 40.10, 40.55, 41.00, 41.35, 41.65, 41.85, 42.10, 42.30, 42.55, 42.75,
 43.00, 43.25, 43.50, 43.75, 44.00, 44.25, 44.45, 44.70, 44.95, 45.20);
var uz8  = new Array (0,
  7.35,  7.35,  9.10,  9.60, 10.10, 10.40, 10.80, 11.45, 12.10, 12.85,
 13.70, 14.60, 15.45, 16.35, 17.25, 18.05, 18.95, 19.85, 20.75, 21.65,
 22.50, 23.40, 24.30, 25.15, 26.05, 26.90, 27.75, 28.65, 29.50, 30.40,
 31.25, 32.15, 33.05, 33.90, 34.80, 35.65, 36.50, 37.35, 38.20, 39.00,
 39.85, 40.65, 41.30, 42.35, 43.15, 43.95, 44.70, 45.40, 46.05, 46.65,
 47.25, 47.80, 48.30, 48.70, 49.10, 49.40, 49.75, 50.10, 50.40, 50.75,
 51.05, 51.40, 51.70, 52.05, 52.35, 62.70, 53.05, 53.35, 53.70, 54.00);
var uzx  = new Array (0,uz1,uz2,uz3,uz4,uz5,uz6,uz7,uz8);

function CalcCost () 
{  
	// given weight and ZIP, calc cost

	wte = Math.floor ((tozs + 15.999) / 16.0);

	// user selected USPS Priority shipping

	if (usps > 0) 
	{   
		// set up USPS Priority mail zones	
		SetUspsZ ();    
	} 

	// user selected USPS Parcel Post shipping

	else if (uspp > 0) 
	{   
		// set up USPS Parcel Post mail zones

		SetUspsZ ();    
	} 

	// user has selected UPS ground shipping

	else if (ups > 0) 
	{    
		// set up UPS ground shipping zones

		SetUpsZ ();     
	}

	for (var i=zn-1; i>=0; i--) 
	{ 
		// run table backwards

		if (zip >= zzip[i]) 
		{       
			// zip value
			// corresponding zone

			zne = zone[i];            

			// get out, now

			break;                    
		}
	}

	if (usps > 0) 
	{
		if (wte > pz2.length) 
		{
			alert (wte + " is greater than length of USPS charge array!");
			amt = 99999;
		} 
		else
		{
			amt = pzx[zne][wte]; // USPS charges to that zone
		}
	} 
	else if (uspp > 0) 
	{
		if (wte > pp2.length) 
		{
			alert (wte + " is greater than length of USPS PP charge array!");
			amt = 99999;
		} 
		else
		{
			amt = ppx[zne][wte]; // USPS charges to that zone
		}
	} 
	else if (ups  > 0) 
	{
		if (wte > uz2.length) 
		{
			alert (wte + " is greater than length of UPS charge array!");
			amt = 99999;
		} 
		else
		{
			amt = uzx[zne][wte]; // UPS charges
		}
	}

	root.stxt0 = root.stxt0 + ", zone " + zne;
	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 38301 zone chart

  SetZone (000, 8,
      5, 5,   6, 8,  10, 5,  18, 6,  54, 5,
     55, 6,  56, 5,  57, 6,  60, 5, 129, 6,
    130, 5, 150, 4, 155, 5, 156, 4, 157, 5,
    160, 4, 164, 5, 214, 5, 215, 4, 216, 5,
    228, 4, 230, 5, 239, 4, 254, 5, 255, 4,
    270, 4, 278, 5, 280, 4, 285, 5, 286, 4,
    300, 3, 304, 4, 307, 3, 308, 4, 311, 3,
    312, 4, 327, 5, 344, 4, 346, 5, 349, 5,
    350, 3, 354, 3, 356, 2, 359, 3, 363, 4,
    367, 3, 369, 3, 370, 2, 373, 3, 375, 2,
    376, 4, 377, 3, 380, 2, 382, 1, 384, 2,
    385, 3, 386, 2, 387, 3, 388, 2, 390, 3,
    395, 4, 396, 3, 398, 4, 399, 3, 410, 4,
    413, 3, 415, 4, 420, 2, 425, 3, 430, 4,
    460, 3, 463, 4, 471, 3, 473, 4, 474, 3,
    476, 2, 478, 3, 479, 4, 497, 5, 500, 4,
    520, 4, 530, 4, 534, 4, 537, 4, 540, 5,
    546, 4, 547, 5, 549, 4, 550, 5, 559, 4,
    560, 5, 570, 5, 580, 5, 587, 6, 590, 6,
    596, 7, 600, 4, 617, 3, 622, 3, 629, 2,
    630, 3, 636, 2, 640, 4, 644, 4, 648, 3,
    649, 4, 650, 3, 660, 4, 677, 5, 680, 4,
    683, 4, 686, 5, 688, 4, 690, 5, 700, 4,
    703, 4, 706, 4, 707, 4, 710, 4, 712, 3,
    713, 4, 716, 3, 718, 4, 719, 3, 723, 2,
    725, 3, 730, 4, 733, 5, 734, 4, 739, 5,
    740, 4, 743, 4, 749, 3, 750, 4, 768, 5,
    770, 4, 779, 5, 798, 6, 800, 5, 813, 6,
    820, 5, 821, 6, 822, 5, 833, 7, 834, 6,
    835, 7, 840, 6, 850, 6, 852, 6, 855, 6,
    859, 6, 863, 6, 864, 7, 865, 6, 870, 5,
    873, 6, 875, 5, 877, 5, 878, 6, 881, 5,
    885, 6, 889, 7, 893, 7, 897, 7, 900, 7,
    910, 7, 930, 7, 939, 8, 942, 7, 943, 8,
    952, 7, 954, 8, 956, 7, 959, 8, 961, 7,
    962, 8, 976, 7, 980, 8, 988, 7, 995, 8);
}

function SetUpsZ () 
{  
	// set UPS lower 48 ground Zones
	// built from UPS 38301 zone chart, lower 48

  SetZone (000, 8, 
  		  4, 5,   6, 8,   8, 8,   9, 8,
		 10, 5,  14, 6,  15, 5,  17, 6,
		 34, 5,  35, 6,  36, 5,  37, 6,
		 51, 5,  55, 6,  57, 5,  58, 6,
		 60, 5,  90, 8, 100, 5, 129, 6,
		130, 5, 150, 4, 158, 5, 160, 4,
		164, 5, 200, 5, 215, 4, 216, 5,
		228, 4, 230, 5, 239, 4, 254, 5,
		255, 4, 278, 5, 280, 4, 284, 5,
		286, 4, 289, 3, 290, 4, 300, 3,
		304, 4, 305, 3, 306, 4, 307, 3,
		308, 4, 311, 3, 312, 4, 327, 5,
		340, 8, 341, 5, 344, 4, 346, 5,
		350, 3, 355, 2, 359, 3, 363, 4,
		367, 3, 370, 2, 373, 3, 375, 2,
		376, 4, 377, 3, 380, 2, 385, 3,
		386, 2, 387, 3, 388, 2, 390, 3,
		395, 4, 396, 3, 398, 4, 399, 3,
		400, 3, 410, 4, 413, 3, 415, 4,
		420, 2, 425, 3, 430, 4, 460, 3,
		463, 4, 471, 3, 473, 4, 474, 3,
		476, 2, 478, 3, 479, 4, 497, 5,
		500, 4, 512, 5, 514, 4, 540, 5,
		546, 4, 547, 5, 549, 4, 550, 5,
		559, 4, 560, 5, 586, 6, 596, 7,
		600, 4, 617, 3, 629, 2, 630, 3,
		635, 4, 636, 3, 637, 2, 640, 4,
		650, 3, 653, 4, 654, 3, 660, 4,
		677, 5, 680, 4, 687, 5, 688, 4,
		690, 5, 700, 4, 712, 3, 713, 4,
		716, 3, 723, 2, 725, 3, 730, 4,
		733, 5, 734, 4, 739, 5, 740, 4,
		749, 3, 750, 4, 768, 5, 770, 4,
		779, 5, 789, 4, 790, 5, 798, 6,
		800, 5, 813, 6, 820, 5, 821, 6,
		822, 5, 823, 6, 833, 7, 834, 6,
		835, 7, 840, 6, 854, 7, 855, 6,
		864, 7, 865, 6, 870, 5, 873, 6,
		875, 5, 878, 6, 881, 5, 885, 6,
		889, 7, 900, 7, 939, 8, 942, 7,
		943, 8, 952, 7, 954, 8, 956, 7,
		959, 8, 961, 7, 962, 8, 967, 8,
		969, 8, 970, 8, 976, 7, 980, 8,
		988, 7, 995, 8);
	 }


function Shipper (obj1, zipcode) 
{  
	// use either amt or qty based shipping

	var pos;

	// assume the worst

	SetAmtSH (0);  
	SetCartSH (0);

	// see if zip code is valid

	if ((isNaN (zipcode.value)) || (zipcode.value == null) || (zipcode.value == ""))
	{
		// alert about invalid zip code

		alert ("You must enter a valid ZIP code!");

		usps = -1;
		uspp = -1;
		ups  = -1;
		insu = -1;
		root.usps = -1;
		root.uspp = -1;
		root.ups  = -1;
		root.insu = -1;
		SetCartSH (0, 0, 0);

		document.location.reload ();  
		return;
	}
	else
	{
		zip = zipcode.value;
	}

	// which option selected

	pos = obj1.selectedIndex;  
	root.stxt0 = obj1.options[pos].text;

	// 1st option

	if (pos == 1) 
	{    
		usps = 1;
		uspp = -1;
		ups  = -1;
		insu = 1;
		
		// get first 3 numbers

		zip = zip.substring(0,3);

		// calculate shipping costs

		CalcCost();

 	}  

	// 2nd option

 	else if (pos == 2) 
	{    
		usps = 1;
		uspp = -1;
		ups  = -1;
		insu = -1;

		// get first 3 numbers

		zip = zip.substring(0,3);

		// calculate shipping costs

		CalcCost();
	} 

	// 3rd option

	else if (pos == 3) 
	{    
		usps = -1;
		uspp = 1;
		ups  = -1;
		insu = -1;
	
		// get first 3 numbers

		zip = zip.substring(0,3);

		// calculate shipping costs

		CalcCost();
	} 
	
	// 4th option

	else if (pos == 4) 
	{    
		usps = -1;
		uspp = -1;
		ups  = 1;
		insu = -1;

		// get first 3 numbers

		zip = zip.substring(0,3);

		// calculate shipping costs

		CalcCost();
	} 

	// 5th option

	else if (pos == 5) 
	{   
		usps = -1;
		uspp = -1;
		ups  = -1;
		insu = -1;
		root.usps = -1;
		root.uspp = -1;
		root.ups  = -1;
		root.insu = -1;
		SetCartSH (0, 0, 0);
	}

	// LEAVE ALONE!!

	SetAmtSH (0,0,0);  

	// show the latest info...

	document.location.reload ();  
}

// executed at load time
// (backward compatibility)

new Cookie (document, "xcxc");  

// load proto methods

Cookie.prototype.store  = _Cookie_store;   
Cookie.prototype.load   = _Cookie_load;
Cookie.prototype.remove = _Cookie_remove;

// special root cookie

var root = new Cookie (document, "paycart0");  
if (!root.load () || !root.stax) 
{ 
	// gotta create it
	InitRoot ();                  
} 
else 
{                        
	// load up globals

    stax  = root.stax;
    ttxt  = root.ttxt;
    coup  = root.coup;
    cdis  = root.cdis;
    chkby = root.chkbx;
    usps  = root.usps;
    uspp  = root.uspp;
    ups   = root.ups;
    insu  = root.insu;
    zne   = root.zne;
}

for (var i=1; i<cmax; i++) 
{  
	// load or init data cookies

	cook = new Cookie (document, "paycart" + i);

	if (!cook.load () || !cook.des) 
	{
		// create it
		InitData ();              
	}
}

