var order = new Object();  // object to store order items in
var root  = new Object();  // selection criteria
var on    = true;
var off   = false;
var cntr  = 0;             // items in object
var opts  = 5;             // number of options to allow
var shpr  = function (wt) {return 0;} // what to charge for shipping;
var stxt  = "";            // shipping text
var spos  = -1;            // shipping position selector
var ttax  = 0;             // percent for taxes
var ttxt  = "0";           // tax text
var tpos  = -1;            // tax position selector
var tamt=0,tqty=0,twgt=0,wgt=0,thnd=0;  // totals

root.hamt = 0;     // amount, below which, handling charge applies
root.hand = 0;     // handling charge for orders less than hamt
root.shp  = on;    // shipping selection line
root.tax  = on;    // tax selection line
// place for user-specific options
root.xx_can  = ""; // place for PayPal cancel return path
root.xx_cur  = ""; // enter default currency code (or null)
root.xx_id   = ""; // PayPal ID
root.xx_img  = ""; // image URL
root.xx_lc   = ""; // enter default country code (or null)
root.xx_ret  = ""; // place for PayPal return path
root.xx_sty  = ""; // place for PayPal page style
root.xx_xtra = ""; // place for other PayPal commands

function CalcRoot () {  // calc root stuff
  if (root.shp) spos=0; 
  if (root.tax) tpos=0;
}

function DispTotsA () {  // display totals on the page

if (
	document.orderf.qty10.value + document.orderf.qty11.value == 0)
	  

  	{
  document.orderf.totala.value = '';
			return false;
	}
	
	else
	
	
  	{
  document.orderf.totala.value = 'US$ ' +(document.orderf.qty10.value*59.00 + document.orderf.qty11.value*59.00) +'.00';
			return false;
	}

}

function DispTotsB () {  // display totals on the page

if (
	document.orderf.qty21.value == 0)
	  

  	{
  document.orderf.totalb.value = '';
			return false;
	}
	
	else
  

  	{
  document.orderf.totalb.value = 'US$ ' +(document.orderf.qty21.value*54.00) +'.00';
			return false;
	}
	
	  

}

function DispTotsC () {  // display totals on the page

 if (
	document.orderf.qty13.value == 0)
	  

  	{
  document.orderf.totalc.value = '';
			return false;
	}
	
	else 

  	{
  document.orderf.totalc.value = 'US$ ' +(document.orderf.qty13.value*49.00) +'.00';
			return false;
	}
	
	  

}





function DispTots () {  // display totals on the page
var tmp,d;
 
 
   if(
	 
	 document.orderf.shipthree.options[document.orderf.shipthree.selectedIndex].value == "2"  && document.orderf.shipcount.options[document.orderf.shipcount.selectedIndex].value == "EU"
	 && (document.orderf.qty10.value*1 + document.orderf.qty11.value*1 + document.orderf.qty13.value*1 + document.orderf.qty21.value*1 ) < 3 )   {
  document.orderf.tot.value = 'US$ ' +(document.orderf.qty10.value*59.00 + document.orderf.qty11.value*59.00 + document.orderf.qty13.value*49.00 + document.orderf.qty21.value*54.00 + 27) +'.00';
  document.orderf.totalds.value = 'US$ 27.00';
  return false;

			
	}

	
	
	
	if (
	document.orderf.shipthree.options[document.orderf.shipthree.selectedIndex].value == "3"  && document.orderf.shipcount.options[document.orderf.shipcount.selectedIndex].value == "EU"
	 && (document.orderf.qty10.value*1 + document.orderf.qty11.value*1 + document.orderf.qty13.value*1 + document.orderf.qty21.value*1 ) < 3 )   {
  document.orderf.tot.value = 'US$ ' +(document.orderf.qty10.value*59.00 + document.orderf.qty11.value*59.00 + document.orderf.qty13.value*49.00 + document.orderf.qty21.value*54.00 + 92) +'.00';
    document.orderf.totalds.value = 'US$ 92.00';
			return false;
	}
	
	
	if (
	document.orderf.shipthree.options[document.orderf.shipthree.selectedIndex].value == "1"  && document.orderf.shipcount.options[document.orderf.shipcount.selectedIndex].value == "EU"
	 && (document.orderf.qty10.value*1 + document.orderf.qty11.value*1 + document.orderf.qty13.value*1 + document.orderf.qty21.value*1 ) < 3 )   {
  document.orderf.tot.value = 'US$ ' +(document.orderf.qty10.value*59.00 + document.orderf.qty11.value*59.00 + document.orderf.qty13.value*49.00 + document.orderf.qty21.value*54.00 + 17) +'.00';
    document.orderf.totalds.value = 'US$ 17.00';
			return false;
	}
	
	
 


  if(
	 
	 document.orderf.shipthree.options[document.orderf.shipthree.selectedIndex].value == "2"  && document.orderf.shipcount.options[document.orderf.shipcount.selectedIndex].value == "INT"
	 && (document.orderf.qty10.value*1 + document.orderf.qty11.value*1 + document.orderf.qty13.value*1 + document.orderf.qty21.value*1 ) < 3 )   {
  document.orderf.tot.value = 'US$ ' +(document.orderf.qty10.value*59.00 + document.orderf.qty11.value*59.00 + document.orderf.qty13.value*49.00 + document.orderf.qty21.value*54.00 + 57) +'.00';
  document.orderf.totalds.value = 'US$ 57.00';
  return false;

			
	}

	
	
	
	if (
	document.orderf.shipthree.options[document.orderf.shipthree.selectedIndex].value == "3"  && document.orderf.shipcount.options[document.orderf.shipcount.selectedIndex].value == "INT"
	 && (document.orderf.qty10.value*1 + document.orderf.qty11.value*1 + document.orderf.qty13.value*1 + document.orderf.qty21.value*1 ) < 3 )   {
  document.orderf.tot.value = 'US$ ' +(document.orderf.qty10.value*59.00 + document.orderf.qty11.value*59.00 + document.orderf.qty13.value*49.00 + document.orderf.qty21.value*54.00 + 139) +'.00';
    document.orderf.totalds.value = 'US$ 139.00';
			return false;
	}
	
	
	if (
	document.orderf.shipthree.options[document.orderf.shipthree.selectedIndex].value == "1"  && document.orderf.shipcount.options[document.orderf.shipcount.selectedIndex].value == "INT"
	 && (document.orderf.qty10.value*1 + document.orderf.qty11.value*1 + document.orderf.qty13.value*1 + document.orderf.qty21.value*1 ) < 3 )   {
  document.orderf.tot.value = 'US$ ' +(document.orderf.qty10.value*59.00 + document.orderf.qty11.value*59.00 + document.orderf.qty13.value*49.00 + document.orderf.qty21.value*54.00 + 19) +'.00';
    document.orderf.totalds.value = 'US$ 19.00';
			return false;
	}
	
	
	
	
  
    if(
	 
	 document.orderf.shipthree.options[document.orderf.shipthree.selectedIndex].value == "2"  && document.orderf.shipcount.options[document.orderf.shipcount.selectedIndex].value == "DE"
	 && (document.orderf.qty10.value*1 + document.orderf.qty11.value*1 + document.orderf.qty13.value*1 + document.orderf.qty21.value*1 ) < 3 )   {
  document.orderf.tot.value = 'US$ ' +(document.orderf.qty10.value*59.00 + document.orderf.qty11.value*59.00 + document.orderf.qty13.value*49.00 + document.orderf.qty21.value*54.00 + 13) +'.00';
  document.orderf.totalds.value = 'US$ 13.00';
  return false;

			
	}

	
	
	
	if (
	document.orderf.shipthree.options[document.orderf.shipthree.selectedIndex].value == "3"  && document.orderf.shipcount.options[document.orderf.shipcount.selectedIndex].value == "DE"
	 && (document.orderf.qty10.value*1 + document.orderf.qty11.value*1 + document.orderf.qty13.value*1 + document.orderf.qty21.value*1 ) < 3 )   {
  document.orderf.tot.value = 'US$ ' +(document.orderf.qty10.value*59.00 + document.orderf.qty11.value*59.00 + document.orderf.qty13.value*49.00 + document.orderf.qty21.value*54.00 + 32) +'.00';
    document.orderf.totalds.value = 'US$ 32.00';
			return false;
	}
	
	
	if (
	document.orderf.shipthree.options[document.orderf.shipthree.selectedIndex].value == "1"  && document.orderf.shipcount.options[document.orderf.shipcount.selectedIndex].value == "DE"
	 && (document.orderf.qty10.value*1 + document.orderf.qty11.value*1 + document.orderf.qty13.value*1 + document.orderf.qty21.value*1 ) < 3 )   {
  document.orderf.tot.value = 'US$ ' +(document.orderf.qty10.value*59.00 + document.orderf.qty11.value*59.00 + document.orderf.qty13.value*49.00 + document.orderf.qty21.value*54.00 + 10) +'.00';
    document.orderf.totalds.value = 'US$ 10.00';
			return false;
	}
	
	
	
	
	














   if(
	 
	 document.orderf.shipthree.options[document.orderf.shipthree.selectedIndex].value == "2"  && document.orderf.shipcount.options[document.orderf.shipcount.selectedIndex].value == "EU"
	 && (document.orderf.qty10.value*1 + document.orderf.qty11.value*1 + document.orderf.qty13.value*1 + document.orderf.qty21.value*1 ) >= 3 ) 
  
  
	{
  document.orderf.tot.value = 'US$ ' +(document.orderf.qty10.value*59.00 + document.orderf.qty11.value*59.00 + document.orderf.qty13.value*49.00 + document.orderf.qty21.value*54.00 + 27 - 59) +'.00';
  document.orderf.totalds.value = 'US$ 27.00';
  return false;

			
	}

	
	
	
	if (
	document.orderf.shipthree.options[document.orderf.shipthree.selectedIndex].value == "3"  && document.orderf.shipcount.options[document.orderf.shipcount.selectedIndex].value == "EU"
	 && (document.orderf.qty10.value*1 + document.orderf.qty11.value*1 + document.orderf.qty13.value*1 + document.orderf.qty21.value*1 ) >= 3 )  
	
	
	{
  document.orderf.tot.value = 'US$ ' +(document.orderf.qty10.value*59.00 + document.orderf.qty11.value*59.00 + document.orderf.qty13.value*49.00 + document.orderf.qty21.value*54.00 + 92 - 59) +'.00';
    document.orderf.totalds.value = 'US$ 92.00';
			return false;
	}
	
	
	if (
	document.orderf.shipthree.options[document.orderf.shipthree.selectedIndex].value == "1"  && document.orderf.shipcount.options[document.orderf.shipcount.selectedIndex].value == "EU"
	 && (document.orderf.qty10.value*1 + document.orderf.qty11.value*1 + document.orderf.qty13.value*1 + document.orderf.qty21.value*1 ) >= 3 )  
	
	{
  document.orderf.tot.value = 'US$ ' +(document.orderf.qty10.value*59.00 + document.orderf.qty11.value*59.00 + document.orderf.qty13.value*49.00 + document.orderf.qty21.value*54.00 + 17 - 59) +'.00';
    document.orderf.totalds.value = 'US$ 17.00';
			return false;
	}
	
	
 


  if(
	 
	 document.orderf.shipthree.options[document.orderf.shipthree.selectedIndex].value == "2"  && document.orderf.shipcount.options[document.orderf.shipcount.selectedIndex].value == "INT"
	 && (document.orderf.qty10.value*1 + document.orderf.qty11.value*1 + document.orderf.qty13.value*1 + document.orderf.qty21.value*1 ) >= 3 )  
  
  
	{
  document.orderf.tot.value = 'US$ ' +(document.orderf.qty10.value*59.00 + document.orderf.qty11.value*59.00 + document.orderf.qty13.value*49.00 + document.orderf.qty21.value*54.00 + 57 - 59) +'.00';
  document.orderf.totalds.value = 'US$ 57.00';
  return false;

			
	}

	
	
	
	if (
	document.orderf.shipthree.options[document.orderf.shipthree.selectedIndex].value == "3"  && document.orderf.shipcount.options[document.orderf.shipcount.selectedIndex].value == "INT"
	 && (document.orderf.qty10.value*1 + document.orderf.qty11.value*1 + document.orderf.qty13.value*1 + document.orderf.qty21.value*1 ) >= 3 )  
	
	
	{
  document.orderf.tot.value = 'US$ ' +(document.orderf.qty10.value*59.00 + document.orderf.qty11.value*59.00 + document.orderf.qty13.value*49.00 + document.orderf.qty21.value*54.00 + 139 - 59) +'.00';
    document.orderf.totalds.value = 'US$ 139.00';
			return false;
	}
	
	
	if (
	document.orderf.shipthree.options[document.orderf.shipthree.selectedIndex].value == "1"  && document.orderf.shipcount.options[document.orderf.shipcount.selectedIndex].value == "INT"
	 && (document.orderf.qty10.value*1 + document.orderf.qty11.value*1 + document.orderf.qty13.value*1 + document.orderf.qty21.value*1 ) >= 3 )  
	
	{
  document.orderf.tot.value = 'US$ ' +(document.orderf.qty10.value*59.00 + document.orderf.qty11.value*59.00 + document.orderf.qty13.value*49.00 + document.orderf.qty21.value*54.00 + 19 - 59) +'.00';
    document.orderf.totalds.value = 'US$ 19.00';
			return false;
	}
	
	
	
	
  
    if(
	 
	 document.orderf.shipthree.options[document.orderf.shipthree.selectedIndex].value == "2"  && document.orderf.shipcount.options[document.orderf.shipcount.selectedIndex].value == "DE"
	 && (document.orderf.qty10.value*1 + document.orderf.qty11.value*1 + document.orderf.qty13.value*1 + document.orderf.qty21.value*1 ) >= 3 )  
  
  
	{
  document.orderf.tot.value = 'US$ ' +(document.orderf.qty10.value*59.00 + document.orderf.qty11.value*59.00 + document.orderf.qty13.value*49.00 + document.orderf.qty21.value*54.00 + 13 - 59) +'.00';
  document.orderf.totalds.value = 'US$ 13.00';
  return false;

			
	}

	
	
	
	if (
	document.orderf.shipthree.options[document.orderf.shipthree.selectedIndex].value == "3"  && document.orderf.shipcount.options[document.orderf.shipcount.selectedIndex].value == "DE"
	 && (document.orderf.qty10.value*1 + document.orderf.qty11.value*1 + document.orderf.qty13.value*1 + document.orderf.qty21.value*1 ) >= 3 )  
	
	
	{
  document.orderf.tot.value = 'US$ ' +(document.orderf.qty10.value*59.00 + document.orderf.qty11.value*59.00 + document.orderf.qty13.value*49.00 + document.orderf.qty21.value*54.00 + 32 - 59) +'.00';
    document.orderf.totalds.value = 'US$ 32.00';
			return false;
	}
	
	
	if (
	document.orderf.shipthree.options[document.orderf.shipthree.selectedIndex].value == "1"  && document.orderf.shipcount.options[document.orderf.shipcount.selectedIndex].value == "DE"
	 && (document.orderf.qty10.value*1 + document.orderf.qty11.value*1 + document.orderf.qty13.value*1 + document.orderf.qty21.value*1 ) >= 3 )  
	
	{
  document.orderf.tot.value = 'US$ ' +(document.orderf.qty10.value*59.00 + document.orderf.qty11.value*59.00 + document.orderf.qty13.value*49.00 + document.orderf.qty21.value*54.00 + 10 - 59) +'.00';
    document.orderf.totalds.value = 'US$ 10.00';
			return false;
	}
	
	



 if(
	 
	  (document.orderf.qty10.value*1 + document.orderf.qty11.value*1 + document.orderf.qty13.value*1 + document.orderf.qty21.value*1 ) >= 3 ) 
  
	{
  document.orderf.totalds.value = (document.orderf.totalds.value - 59);
  
	} 

}



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 (".");  // should be one, but OK if not
  if (pos > 0) str = str.substring (rnd, pos + 3);
  return str;               // return valid string
}

function GetOrder (id, des, amt, wgt) {  // get all ordered items
var i,nr,val,qty,pos;
var op = new Array ();    // accumulate options here
  tamt=0,tqty=0,twgt=0;   // zero totals
  nr = id.substring (2);  // get number part of ID
  qty = document.orderf["qty" + nr].value;  // get qty
  if (isNaN (qty)) {      // test entry
    alert ("That is not a valid number!  Try again.");
    return;
  }
  for (i=1; i<=opts; i++) {     // see if any options
    if (document.orderf["op" + i + nr]) {
      val = document.orderf["op" + i + nr].value;  // get option
      op[i] = val;
      pos  = val.indexOf ("+"); // price increment?
      if (pos > 0) amt = amt + val.substring (pos + 1)*1.0;
      pos  = val.indexOf ("%"); // percent change?
      if (pos > 0) amt = amt + (amt * val.substring (pos + 1)/100.0);
    }
    else op[i] = "";
  }
  document.orderf["prc" + nr].value = Dollar (qty * amt);
  document.orderf["toz" + nr].value = qty * wgt;
  if (cntr == 0) order = new Object (); // zap object
  cntr = cntr + 1;               // bump counter so no zap next time
  order[id] = new Object ();     // create new entry
  for (i=1; i<=opts; i++)        // load options
    if (op[i] != "") des = des + ", OP" + i + "=" + op[i];
  order[id].des = des;           // load up values
  order[id].amt = Dollar (amt);
  order[id].qty = qty;
  if (wgt) order[id].wgt = wgt;
    else order[id].wgt = 0;
  for (i in order) {             // calc totals we might use
    qty = order[i].qty*1.0;
    tamt = tamt + order[i].amt * qty;  // total amount
    tqty = tqty + qty;                 // total quantity
    twgt = twgt + order[i].wgt * qty;  // total ounces
  }
  twgt = Math.floor ((twgt + 15.99)/16.0);  // get pounds
  DispTots (); 
	// calc totals
}

function SendCart () {  // send the cart to PayPal
var frst = true;
var winpar = "width=860,height=590,scrollbars," +
             "location,resizable,status";
var strn   = "https://www.paypal.com/cgi-bin/webscr?cmd=_cart" +
             "&upload=1" +
             "&business=" + root.xx_id + root.xx_xtra;
var i,j=0,des;
   if (root.xx_cur.length > 0)
    strn = strn + "&currency_code=" + root.xx_cur;
  if (root.xx_lc.length > 0)
    strn = strn + "&lc=" + root.xx_lc;
  if (root.xx_can.length > 0)
    strn = strn + "&cancel_return=" + root.xx_can;
  if (root.xx_ret.length > 0)
    strn = strn + "&return=" + root.xx_ret;
  if (root.xx_sty.length > 0)
    strn = strn + "&page_style=" + root.xx_sty;
  if (root.xx_img.length > 0)
    strn = strn + "&image_url=" + root.xx_img;
  if (tpos > 0) strn = strn + "&tax_cart=" + Dollar (tamt*ttax/100);
  for (i in order) {  // send all valid data
    if (order[i].qty > 0) {
      j = j + 1;
      des = order[i].des;
      if (j == 1) {  // put in descriptions for 1st item

        strn = strn + "&handling_cart=" + Dollar (thnd);
      }
      strn = strn + "&item_name_"   + j + "=" + escape (des) +

                    "&quantity_"    + j + "=" + order[i].qty +
                    "&amount_"      + j + "=" + order[i].amt;
  
  if(
	 
	 document.orderf.shipthree.options[document.orderf.shipthree.selectedIndex].value == "1" && document.orderf.shipcount.options[document.orderf.shipcount.selectedIndex].value == "EU") 
  
	{
  strn = strn + "&shipping_1=17";
  
	}
	
	if(
	 
	 document.orderf.shipthree.options[document.orderf.shipthree.selectedIndex].value == "2" && document.orderf.shipcount.options[document.orderf.shipcount.selectedIndex].value == "EU")  
  
  
	{
  strn = strn + "&shipping_1=27";
  
	}
	
	if(
	 
	 document.orderf.shipthree.options[document.orderf.shipthree.selectedIndex].value == "3" && document.orderf.shipcount.options[document.orderf.shipcount.selectedIndex].value == "EU")  
  
  
	{
  strn = strn + "&shipping_1=64";
  
	}
	
  if(
	 
	 document.orderf.shipthree.options[document.orderf.shipthree.selectedIndex].value == "1" && document.orderf.shipcount.options[document.orderf.shipcount.selectedIndex].value == "INT") 
  
	{
  strn = strn + "&shipping_1=19";
  
	}
	
	if(
	 
	 document.orderf.shipthree.options[document.orderf.shipthree.selectedIndex].value == "2" && document.orderf.shipcount.options[document.orderf.shipcount.selectedIndex].value == "INT")  
  
  
	{
  strn = strn + "&shipping_1=57";
  
	}
	
	if(
	 
	 document.orderf.shipthree.options[document.orderf.shipthree.selectedIndex].value == "3" && document.orderf.shipcount.options[document.orderf.shipcount.selectedIndex].value == "INT")  
  
  
	{
  strn = strn + "&shipping_1=139";
  
	}
	
	
	if(
	 
	 document.orderf.shipthree.options[document.orderf.shipthree.selectedIndex].value == "1" && document.orderf.shipcount.options[document.orderf.shipcount.selectedIndex].value == "DE") 
  
	{
  strn = strn + "&shipping_1=10";
  
	}
	
	if(
	 
	 document.orderf.shipthree.options[document.orderf.shipthree.selectedIndex].value == "2" && document.orderf.shipcount.options[document.orderf.shipcount.selectedIndex].value == "DE")  
  
  
	{
  strn = strn + "&shipping_1=13";
  
	}
	
	if(
	 
	 document.orderf.shipthree.options[document.orderf.shipthree.selectedIndex].value == "3" && document.orderf.shipcount.options[document.orderf.shipcount.selectedIndex].value == "DE")  
  
  
	{
  strn = strn + "&shipping_1=32";
  
	}



 if(
	 
	  (document.orderf.qty10.value*1 + document.orderf.qty11.value*1 + document.orderf.qty13.value*1 + document.orderf.qty21.value*1 ) >= 3 ) 
  
	{
  strn = strn + "&discount_amount_cart=59";
  
	}

      frst = false;
    }
  }
  if (j > 0) window.open (strn, "paypal", winpar);
}

function SetShp (obj) {  // set shipping on user selection
  shpr = function (wt) {return 15;}  // zap it
  spos = obj.selectedIndex;  // which option selected
  stxt = obj.options[spos].text;
  // set various shipping functions.
  if (spos == 0) shpr = function (wt) {return 15;}
  if (spos == 1) shpr = function (wt) {return 15;}
  if (spos == 2) shpr = function (wt) {return 15;}
  if (spos == 3) shpr = function (wt) {return 15;}
  if (spos == 4) shpr = function (wt) {return 15;}
  DispTots ();
}

function SetTax (obj) {
  tpos = obj.selectedIndex;  // which option selected
  ttxt = obj.options[tpos].text;
  ttax = obj.options[tpos].value*1.0;
  DispTots ();
}

