var ppPaymentAddress = 'Q46UM9EVG9GNU';

function ITEMS(type, group, name, price, unit, shipRate1, shipRate2, shipRate3, shipRate4) {
this.type = type;
this.group = group;
this.name = name;
this.price = price;
this.unit = unit;
}

var MyTeas = 0;
var MyMatcha = 0;
var MySalts = 0;
var MyA = 0;
var MyB = 0;
var Shipping = 0;
var ShippingTea = 0;
var ShippingSalts = 0;
var ShippingA = 0;
var ShippingB = 0;
var DiscountPercent = 0;
var DiscountPrice = 0;
var TeaTotal = 0;
var DiscountTeaMessage ='';
var DiscountMatchaMessage ='';
var DiscountMessage ='';
var itemsArray=[];
$(document).ready(function(){
    $("body").append('\
<!-- CART REQUIRED -->\
<div onclick="hideCart();" id="darkBackgroundLayer" class="darkenBackground" style="display: none;"></div>\
<div id="cart" style="width:625px; display: none; position: absolute; z-index: 1000; background:#FFF; height:auto;" align="center">\
  <iframe name="iframe" id="iframe1" src ="cart.html"  width="622px" class="autoHeight"></iframe>\
</div>\
<!-- END CART REQUIRED -->');    
});


//Shipping Calculations Contact us if you do not understand how to edit the shipping options
/*
To edit shipping rates find the rate below and edit it.  Example to edit shipping option 'Tea'  for 80-240 oz from $10.70 - 12.00
Find case 'Tea': (This starts the Tea shipping option)
locate case (MyTeas>80 && MyTeas<=240): (this starts the option of shipping between 80 and 240 oz)
Edit the line ShippingTea = 10.70; in that block to ShippingTea = 12.00;

Same goes for discounts
*/
function calculateShipping(mySHIPPING, quantity, lineTotal){
    quantity = quantity*1;
    switch(mySHIPPING)
    {
        case 'Tea':
            MyTeas = (MyTeas*1) + (quantity);
	    TeaTotal = (TeaTotal*1) + (lineTotal*1);
	   DiscountTeaMessage='';
            switch(true)
            {
                case (MyTeas<=16):
                    ShippingTea = 4.95;
                break;

                case (MyTeas>16 && MyTeas<=80):
                    ShippingTea = 10.70;
                break;
                case (MyTeas>80 && MyTeas<=240):
                    ShippingTea = 14.50;
                break;
                case (MyTeas>240):
                    ShippingTea = 19.50;
                break;
            }
	    switch(true)
            {
                case ((MyTeas - MyMatcha) >15 && (MyTeas - MyMatcha)<=31):
                    DiscountPercent = .1;
		    DiscountTeaMessage = 'You have reached our 10% bulk discount level!';
                break;
                case ((MyTeas - MyMatcha)>=32 && (MyTeas - MyMatcha)<=79):
                    DiscountPercent = .2;
		    DiscountTeaMessage = 'You have reached our 20% bulk discount level!';
                break;
                case ((MyTeas - MyMatcha)>=80):
                    DiscountPercent = .3;
		    DiscountTeaMessage = 'You have reached our 30% bulk discount level!';
                break;
            }
	    if ((MyTeas - MyMatcha) >= 12  && (MyTeas - MyMatcha) <= 15){
		neededForDiscount = 16 - (MyTeas - MyMatcha);
		DiscountTeaMessage = 'Order '+neededForDiscount+' more ounces to reach our 10% bulk discount level!';
		}
	    if ((MyTeas - MyMatcha) >= 28  && (MyTeas - MyMatcha) <= 31){
		neededForDiscount = 32 - (MyTeas - MyMatcha);
		DiscountTeaMessage = 'Order '+neededForDiscount+' more ounces to reach our 20% bulk discount level!';
	    }
	    if ((MyTeas - MyMatcha) >= 76  && (MyTeas - MyMatcha) <= 79){
		neededForDiscount = 80 - (MyTeas - MyMatcha);
		DiscountTeaMessage = 'Order '+neededForDiscount+' more ounces to reach our 30% bulk discount level!';
	    }
	    DiscountMessage = DiscountMatchaMessage +"<br/>"+ DiscountTeaMessage;
	break;
	case 'Matcha':
	    DiscountMatchaMessage = '';
            MyTeas = (MyTeas*1) + (quantity);
	    MyMatcha = (MyMatcha*1) + (quantity);
            switch(true)
            {
                case (MyTeas<=16):
                    ShippingTea = 4.95;
                break;

                case (MyTeas>16 && MyTeas<=32):
                    ShippingTea = 10.70;
                    DiscountPercent = .1;
                break;
                case (MyTeas>36 && MyTeas<=80):
                    ShippingTea = 10.70;
                    DiscountPercent = .2;
                break;
                case (MyTeas>80 && MyTeas<=240):
                    ShippingTea = 14.50;
                    DiscountPercent = .3;
                break;
                case (MyTeas>240):
                    ShippingTea = 19.50;
                    DiscountPercent = .3;
                break;
            }
	    Numberofmatcha = (MyMatcha*1)/4;
	    Numberofmatcha = Numberofmatcha.toString();

	    var NumberofmatchaParts = Numberofmatcha.split('.');
	    Numberofmatcha = NumberofmatchaParts[1];
	    if (Numberofmatcha === '5'){
		DiscountMatchaMessage = 'Buy 4 ounces for $40!<br/>';
	    }
	    if (Numberofmatcha === '75'){
		addCartCookie(itemNumber, 1);
		location.reload(true);
	    }
	    if (MyMatcha >= 4){
		//addCartCookie('PTOMGTPG', 1);
		DiscountMatchaMessage += 'You have received the 4oz. Matcha discount!';
	    }
	    		DiscountMessage = DiscountMatchaMessage +"<br/>"+ DiscountTeaMessage;

	    DiscountPrice = Math.floor((MyMatcha*1)/4) * (mySTORE['PTOMGTPG4'].price * .25);
        break;
        case 'A':
            
            MyA=MyA*1 +quantity;
             ShippingA = (1.95*MyA);
        break;
        case 'B':
            
             MyB=MyB*1 +quantity;
             ShippingB=(4.95*MyB);
        break;
        case 'Salts':
            
             MySalts=MySalts*1 +quantity;
             ShippingSalts=(4.95*MySalts);
        break;
    }
    Shipping = ShippingTea*1+ShippingA*1+ShippingB*1+ShippingSalts*1;
    return Shipping;
}



var mySTORE = new Array();
/* ADD items by creating a new line in the following manner

mySTORE["Your Item Number HERE"] = new ITEMS('Category', 'Shipping Option', 'Item Name', 'Price', 'Unit');

*/
//Blended Teas:
mySTORE["BTEB"] = new ITEMS('Blended Teas', 'Tea', 'Exotic Black', '4.00', 'oz.');
mySTORE["BTVC"] = new ITEMS('Blended Teas', 'Tea', 'Vanilla Chai', '4.00', 'oz.');
mySTORE["BTPPC"] = new ITEMS('Blended Teas', 'Tea', 'Pumpkin Patch Chai', '4.50', 'oz.');
mySTORE["BGiP"] = new ITEMS('Blended Teas', 'Tea', 'Ginger Pear', '4.00', 'oz.');
mySTORE["BTSAN"] = new ITEMS('Blended Teas', 'Tea', 'Sangria', '4.00', 'oz.');
mySTORE["BTMJ"] = new ITEMS('Blended Teas', 'Tea', 'Mint Mojito', '4.00', 'oz.');
mySTORE["BTBG"] = new ITEMS('Blended Teas', 'Tea', 'Blueberry Ginger', '4.00', 'oz.');
mySTORE["BTAIW"] = new ITEMS('Blended Teas', 'Tea', 'Alice In Wonderland', '4.00', 'oz.');
mySTORE["BTLP"] = new ITEMS('Blended Teas', 'Tea', 'Lavender-Peppermint', '4.00', 'oz.');
mySTORE["BTBA"] = new ITEMS('Blended Teas', 'Tea', 'Berry Antioxidant', '4.00', 'oz.');
mySTORE["BTGP"] = new ITEMS('Blended Teas', 'Tea', 'Ginger-Papaya', '4.00', 'oz.');
mySTORE["BTMM"] = new ITEMS('Blended Teas', 'Tea', 'Moxie Man', '4.00', 'oz.');
mySTORE["BTPM"] = new ITEMS('Blended Teas', 'Tea', 'Peach Morning', '4.00', 'oz.');
mySTORE["BTACC"] = new ITEMS('Blended Teas', 'Tea', 'Apple Cinnamon Chai', '4.00', 'oz.');
mySTORE["BTRD"] = new ITEMS('Blended Teas', 'Tea', 'Raspberry Detox', '4.00', 'oz.');
mySTORE["BTSUN"] = new ITEMS('Blended Teas', 'Tea', 'Sunset', '4.00', 'oz.');
mySTORE["BTSJ"] = new ITEMS('Blended Teas', 'Tea', 'Strawberry Jubilee', '4.00', 'oz.');
mySTORE["BTNLD"] = new ITEMS('Blended Teas', 'Tea', 'Nettle Leaf Detox', '4.00', 'oz.');
mySTORE["BTPC"] = new ITEMS('Blended Teas', 'Tea', 'Pina Colada', '4.00', 'oz.');
mySTORE["BTCG"] = new ITEMS('Blended Teas', 'Tea', 'Clean Green', '4.00', 'oz.');
mySTORE["BTRC"] = new ITEMS('Blended Teas', 'Tea', 'No-Caf Red Chai', '4.00', 'oz.');
mySTORE["BTRCA"] = new ITEMS('Blended Teas', 'Tea', 'Red Carmamel Apple', '4.00', 'oz.');
mySTORE["BTGS"] = new ITEMS('Blended Teas', 'Tea', 'Lemon Gingersnap', '4.00', 'oz.');
mySTORE["PNK"] = new ITEMS('Blended Teas', 'Tea', 'PINK', '4.00', 'oz.');
// Tea Samplers:
mySTORE["TSG"] = new ITEMS('Blended Teas', 'Tea', 'Green Tea Sampler', '15.00', '3 oz.');
mySTORE["TSB"] = new ITEMS('Blended Teas', 'Tea', 'Black Tea Sampler', '15.00', '3 oz.');
mySTORE["TSC"] = new ITEMS('Blended Teas', 'Tea', 'Chai Tea Sampler', '15.00', '3 oz.');
mySTORE["TSH"] = new ITEMS('Blended Teas', 'Tea', 'Herbal Tea Sampler', '15.00', '3 oz.');
mySTORE["TSM"] = new ITEMS('Blended Teas', 'Tea', 'Matcha Tea Sampler', '20.00', '2.5 oz.');

//Salts:
mySTORE["ARSS2"] = new ITEMS('Sea Salts', 'Salts', 'Alaea Red Salt 2oz', '4.00', '2 oz.');
mySTORE["ARSS4"] = new ITEMS('Sea Salts', 'Salts', 'Alaea Red Salt 4oz', '8.00', '4 oz.');
mySTORE["ARSS6"] = new ITEMS('Sea Salts', 'Salts', 'Alaea Red Salt 6oz', '12.00', '6 oz.');
mySTORE["ARSS8"] = new ITEMS('Sea Salts', 'Salts', 'Alaea Red Salt 8oz', '16.00', '8 oz.');
mySTORE["BLSS2"] = new ITEMS('Sea Salts', 'Salts', 'Black Lava Salt 2oz', '4.00', '2 oz.');
mySTORE["BLSS4"] = new ITEMS('Sea Salts', 'Salts', 'Black Lava Salt 4oz', '8.00', '4 oz.');
mySTORE["BLSS6"] = new ITEMS('Sea Salts', 'Salts', 'Black Lava Salt 6oz', '12.00', '6 oz.');
mySTORE["BLSS8"] = new ITEMS('Sea Salts', 'Salts', 'Black Lava Salt 8oz', '16.00', '8 oz.');
mySTORE["HSS2"] = new ITEMS('Sea Salts', 'Salts', 'Hickory Salt 2oz', '4.00', '2 oz.');
mySTORE["HSS4"] = new ITEMS('Sea Salts', 'Salts', 'Hickory Salt 4oz', '8.00', '4 oz.');
mySTORE["HSS6"] = new ITEMS('Sea Salts', 'Salts', 'Hickory Salt 6oz', '12.00', '6 oz.');
mySTORE["HSS8"] = new ITEMS('Sea Salts', 'Salts', 'Hickory Salt  8oz', '16.00', '8 oz.');
mySTORE["SGSS2"] = new ITEMS('Sea Salts', 'Salts', 'Sel Gris Salt 2oz', '4.00', '2 oz.');
mySTORE["SGSS4"] = new ITEMS('Sea Salts', 'Salts', 'Sel Gris Salt 4oz', '8.00', '4 oz.');
mySTORE["SGSS6"] = new ITEMS('Sea Salts', 'Salts', 'Sel Gris Salt 6oz', '12.00', '6 oz.');
mySTORE["SGSS8"] = new ITEMS('Sea Salts', 'Salts', 'Sel Gris Salt 8oz', '16.00', '8 oz.');
mySTORE["SSS2"] = new ITEMS('Sea Salts', 'Salts', 'Seasoning Salt 2oz', '4.00', '2 oz.');
mySTORE["SSS4"] = new ITEMS('Sea Salts', 'Salts', 'Seasoning Salt 4oz', '8.00', '4 oz.');
mySTORE["SSS6"] = new ITEMS('Sea Salts', 'Salts', 'Seasoning Salt 6oz', '12.00', '6 oz.');
mySTORE["SSS8"] = new ITEMS('Sea Salts', 'Salts', 'Seasoning Salt 8oz', '16.00', '8 oz.');
mySTORE["YSS2"] = new ITEMS('Sea Salts', 'Salts', 'Yakima Smoked Salt 2oz', '4.00', '2 oz.');
mySTORE["YSS4"] = new ITEMS('Sea Salts', 'Salts', 'Yakima Smoked Salt 4oz', '8.00', '4 oz.');
mySTORE["YSS6"] = new ITEMS('Sea Salts', 'Salts', 'Yakima Smoked Salt 6oz', '12.00', '6 oz.');
mySTORE["YSS8"] = new ITEMS('Sea Salts', 'Salts', 'Yakima Smoked Salt 8oz', '16.00', '8 oz.');
mySTORE["ASS2"] = new ITEMS('Sea Salts', 'Salts', 'Ayurveda Blend Salt 2oz', '4.00', '2 oz.');
mySTORE["ASS4"] = new ITEMS('Sea Salts', 'Salts', 'Ayurveda Blend Salt 4oz', '8.00', '4 oz.');
mySTORE["ASS6"] = new ITEMS('Sea Salts', 'Salts', 'Ayurveda Blend Salt 6oz', '12.00', '6 oz.');
mySTORE["ASS8"] = new ITEMS('Sea Salts', 'Salts', 'Ayurveda Blend Salt 8oz', '16.00', '8 oz.');
mySTORE["GSS2"] = new ITEMS('Sea Salts', 'Salts', 'Sizzlin Grille Blend Salt 2oz', '4.00', '2 oz.');
mySTORE["GSS4"] = new ITEMS('Sea Salts', 'Salts', 'Sizzlin Grille Blend Salt 4oz', '8.00', '4 oz.');
mySTORE["GSS6"] = new ITEMS('Sea Salts', 'Salts', 'Sizzlin Grille Blend Salt 6oz', '12.00', '6 oz.');
mySTORE["GSS8"] = new ITEMS('Sea Salts', 'Salts', 'Sizzlin Grille Blend Salt 8oz', '16.00', '8 oz.');
mySTORE["SSSS1"] = new ITEMS('Sea Salts', 'Salts', 'Sea Salt Sampler 1 Pack', '18.00', '1 pack');
mySTORE["SSSS2"] = new ITEMS('Sea Salts', 'Salts', 'Sea Salt Sampler 2 Pack', '36.00', '2 pack');
mySTORE["SSSS3"] = new ITEMS('Sea Salts', 'Salts', 'Sea Salt Sampler 3 Pack', '54.00', '3 pack');
mySTORE["SSSS4"] = new ITEMS('Sea Salts', 'Salts', 'Sea Salt Sampler 4 Pack', '72.00', '4 pack');

//Pure Teas:
mySTORE["PTOMGTPG"] = new ITEMS('Pure Teas', 'Matcha', 'Organic Matcha Green Tea - Premium Grade', '12.50', 'oz.');
mySTORE["PTOMGTPG4"] = new ITEMS('Pure Teas', 'Matcha', 'Organic Matcha Green Tea - Premium Grade 4 oz.', '40', '4 oz.');
mySTORE["PTOMC"] = new ITEMS('Pure Teas', 'Tea', 'Organic Matcha Chai', '5.50', 'oz.');
mySTORE["PTOMC4"] = new ITEMS('Pure Teas', 'Tea', 'Organic Matcha Chai - 4 oz.', '20.00', '4 oz.');
mySTORE["PTCHM"] = new ITEMS('Pure Teas', 'Tea', 'Cocoa-Hazelnut Matcha', '5.50', 'oz.');
mySTORE["PTCHM4"] = new ITEMS('Pure Teas', 'Tea', 'Cocoa-Hazelnut Matcha 4 oz.','20.00', '4 oz.');
mySTORE["PTCM"] = new ITEMS('Pure Teas', 'Tea', 'Coconut Matcha', '5.50', 'oz.');
mySTORE["PTCM4"] = new ITEMS('Pure Teas', 'Tea', 'Coconut Matcha 4 oz.', '20.00', '4 oz.');




mySTORE["PTOFTSGT"] = new ITEMS('Pure Teas', 'Tea', 'Organic, Fair Trade Sencha Green Tree', '7.75', 'oz.');
mySTORE["PTOJP"] = new ITEMS('Pure Teas', 'Tea', 'Organic Jasmine Pearls', '7.00', 'oz.');
mySTORE["PTOFTNB"] = new ITEMS('Pure Teas', 'Tea', 'Organic, Fair Trade Nepalese Black', '5.50', 'oz.');
mySTORE["PTOFTWP"] = new ITEMS('Pure Teas', 'Tea', 'Organic, Fair Trade White Peony', '4.00', 'oz.');
mySTORE["PTOFTO"] = new ITEMS('Pure Teas', 'Tea', 'Organic, Fair Trade Oolong', '4.00', 'oz.');
mySTORE["PTOLS"] = new ITEMS('Pure Teas', 'Tea', 'Organic Lapsang Souchong ', '4.00', 'oz.');
mySTORE["PTOFTRA"] = new ITEMS('Pure Teas', 'Tea', 'Organic, Fair Trade Rich Assam', '3.00', 'oz.');
mySTORE["PTOFTRR"] = new ITEMS('Pure Teas', 'Tea', 'Organic, Fair Trade Red Rooibos', '3.00', 'oz.');
mySTORE["PTOFTGR"] = new ITEMS('Pure Teas', 'Tea', 'Organic, Fair Trade Green Rooibos', '3.00', 'oz.');
mySTORE["PTOYM"] = new ITEMS('Pure Teas', 'Tea', 'Organic Yerba Mate', '2.75', 'oz.');

//Other Items
mySTORE["OIFTBC"] = new ITEMS('Pure Teas', 'A', 'Flowering Tea: Blooming Crysanthemum', '8.00', 'ea');
mySTORE["OIMW"] = new ITEMS('Pure Teas', 'B', 'Matcha Whisk', '20.00', 'ea');
mySTORE["OIPMS"] = new ITEMS('Pure Teas', 'B', 'Pureblend Matcha Set', '50.00', 'ea');


//FUNCTION TO ADD CART BUTTONS
function addButton(itemNumber)
{
    document.write('<strong>$</strong>'+mySTORE[itemNumber].price+"/"+mySTORE[itemNumber].unit+"<form><table border='0' cellpadding='3'>\
  <tr>\
    <td><input type='hidden' name='itemNumber' value='"+itemNumber+"'>  <input name='quantity' type='text' size='3' maxlength='3'>&nbsp;"+mySTORE[itemNumber].unit+"</td>\
  </tr>\
  <tr>\
    <td><input type='image' src='https://www.paypal.com/en_US/i/btn/btn_cart_SM.gif' border='0' onclick='return addToCart(this.form);'>&nbsp;</td>\
  </tr>\
  <tr>\
    <td>&nbsp;</td>\
  </tr>\
</table>\
</form>"  );
    
    
}
//FUNCTION ADD TO CART

function addToCart(form)
{
    var itemNumber = form.itemNumber.value;
    var quantity = form.quantity.value*1;
    addCartCookie(itemNumber, quantity);
     el = document.getElementById('darkBackgroundLayer');
        el.style.display = '';
	elb = document.getElementById('cart');
        elb.style.display = '';
        elb.style.top = '10px';
        elb.style.left = '390px';
       document.getElementById('iframe1').contentWindow.location.reload(true);
       window.scrollTo(0,0);

    return false; 
}
function viewCart()
{
     el = document.getElementById('darkBackgroundLayer');
        el.style.display = '';
	elb = document.getElementById('cart');
        elb.style.display = '';
        elb.style.top = '10px';
        elb.style.left = '390px';
       document.getElementById('iframe1').contentWindow.location.reload(true);
       window.scrollTo(0,0);
}
function hideCart() {
    el = parent.document.getElementById('darkBackgroundLayer');
        el.style.display = 'none';
	elb = parent.document.getElementById('cart');
        elb.style.display = 'none';    
}
//FUNCTION Delete FROM CART

function deleteCartItem(position)
{
    Cart = $.cookie("Cart");
    
    var Items = Cart.split('||');
    var NewCookie=[];
     for (x in Items)
    {
        NewCookie.push(Items[x]);
    }
    NewCookie.splice(position, 1);
    NewCookie=NewCookie.join("||");
    $.cookie("Cart", NewCookie, { path: '/'  });
    location.reload(true);

}
//FUNCTION ADD CART COOKIE
function addCartCookie(itemNumber, quantity){
      if ($.cookie("Cart") !== null && $.cookie("Cart") !== ''){
        Cart = $.cookie("Cart");
	
        Cookie= Cart+'||'+itemNumber+':'+quantity
    }else{
    Cookie= itemNumber+':'+quantity;
    }
    
    $.cookie("Cart", Cookie, { path: '/'  });
    sortCart($.cookie("Cart"));
}
//function Sort Cart

function sortCart(str){
    //alert (str);
    var myarray  =[];
var MyCookie ='';
myarray = str.split('||')

//alert(myarray +'<br/>');

for (x in myarray)
{

  Item = myarray[x].split(':');
  itemNumber = Item[0];
  quantity = Item[1];


if (window[itemNumber] !=null){
	window[itemNumber] =(window[itemNumber]*1) + (quantity*1);
}else{
    window[itemNumber] =(quantity*1);
    itemsArray.push(itemNumber);
    //alert("Item Arrar = " +itemsArray);
}


//alert (itemNumber +' '+window[itemNumber]+'<br />');


}
//alert ("Item Array: "+itemsArray+'<br />');

for (x in itemsArray)
{

    itemnumber=itemsArray[x];
    if (MyCookie != ''){
	MyCookie = MyCookie +'||'+itemnumber+':'+window[itemnumber];
	window[itemnumber] = null;
	//alert ("Not Null COOKIE: "+MyCookie);
    }else{
	MyCookie = itemnumber+':'+window[itemnumber];
	window[itemnumber] = null;
	//alert ("Null COOKIE: "+MyCookie);
    }

}
itemsArray.length = 0;

//alert ("Final COOKIE: "+MyCookie);
 $.cookie("Cart", MyCookie, { path: '/'  });
}

//FUNCTION SHOW CART

function showCart()
{
    
    Cart = $.cookie("Cart");
    if ($.cookie("Cart") !== null && $.cookie("Cart") !== ''){
    
    var cartHeadHtml = '    <table width="600" border="0" cellpadding="3" class="ssCartContent">  <tr>        <td colspan="5" class="ssCartTitle">Shopping Cart</td>      </tr>  <tr>        <td  class="ssCartheading">Remove</td>        <td  class="ssCartheading">Item</td>        <td  class="ssCartheading">Quantity</td>        <td  class="ssCartheading">Price</td>        <td class="ssCartheading">Line Total</td>      </tr>  ';
  
  //Create Line Item list
  var Items = Cart.split('||');
  var ShippingCount= [];
  var subTotal = 0;
  var cartLineHtml = '';
  var payPalCartLineItems ='';
  var lineclass=1;
  for (x in Items)
  {
  Item = Items[x].split(':');
  
  itemNumber = Item[0];
  quantity = Item[1];
  var lineTotal = (quantity *1)* (mySTORE[itemNumber].price*1);
  lineTotal = lineTotal.toFixed(2);
  var group = mySTORE[itemNumber].group;
  orderShipping = calculateShipping(group, quantity, lineTotal);
  
  subTotal = (subTotal*1) + (lineTotal*1);
  DiscountAmount = (TeaTotal*1)*(DiscountPercent*1);
  
  orderShipping = orderShipping.toFixed(2);
  subTotal = subTotal.toFixed(2);
  DiscountAmount = (DiscountAmount*1)+(DiscountPrice*1);
  DiscountAmount = DiscountAmount.toFixed(2);
  OrderTotal = (subTotal*1)-(DiscountAmount*1)+(orderShipping*1);
  OrderTotal = OrderTotal.toFixed(2);
  
  cartLineHtml = cartLineHtml + '  <tr class="ssCartline'+lineclass+'">        <td align="center"><input type="button" name="ContinueShopping" border="0" value="" onclick="deleteCartItem('+x+');"></td>        <td>'+mySTORE[itemNumber].type+' '+mySTORE[itemNumber].name+'</td>        <td>'+quantity+' '+mySTORE[itemNumber].unit+'</td>        <td>'+mySTORE[itemNumber].price+'/'+mySTORE[itemNumber].unit+'</td>        <td>'+lineTotal+'</td>      </tr>  ';
 
  payPalCartLineItems = payPalCartLineItems+'  <input type="hidden" name="item_name_'+((x*1)+1)+'" value="'+mySTORE[itemNumber].type+' '+mySTORE[itemNumber].name+'">  <input type="hidden" name="quantity_'+((x*1)+1)+'" value="'+quantity+'">  <input type="hidden" name="amount_'+((x*1)+1)+'" value="'+mySTORE[itemNumber].price+'">  ';
  if (lineclass === 1){
  lineclass = 2;
  }else{
  lineclass = 1;
  }
  }
  var ppCartForm = '  <form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">        <!-- Identify your business so that you can collect the payments. -->        <input type="hidden" name="business" value="'+ppPaymentAddress+'">        <!-- Specify a PayPal Shopping Cart Add to Cart button. -->        <input type="hidden" name="cmd" value="_cart">        <input type="hidden" name="upload" value="1">        <!-- Specify details about the item that buyers will purchase. -->        '+payPalCartLineItems+'        <input type="hidden" name="currency_code" value="USD">        <input type="hidden" name="shipping_1" value="'+orderShipping+'">        <INPUT TYPE="hidden" name="discount_amount_cart" value="'+DiscountAmount+'">        <!-- Display the payment button. -->        <input type="submit" name="submit" border="0" value="Checkout">        <img alt="" border="0" width="1" height="1"  src="https://www.paypal.com/en_US/i/scr/pixel.gif" >      </form>  ';
  var cartTotalsHtml = '  <tr>        <td colspan="3" rowspan="4">&nbsp;</td>        <td class="ssCartheading">Subtotal</td>        <td>'+subTotal+'</td>      </tr>  <tr>        <td class="ssCartheading">Discount </td>        <td>'+DiscountAmount+'</td>      </tr>  <tr>        <td class="ssCartheading">Shipping</td>        <td>'+orderShipping+'</td>      </tr>  <tr>        <td class="ssCartheading">Order Total</td>        <td>'+OrderTotal+'</td>      </tr>  ';
  var cartFooterHtml = '  <tr>        <td colspan="2">&nbsp;</td>        <td colspan="2" align="center"><input type="button" name="ContinueShopping" border="0" value="Continue Shopping" onclick="hideCart();"></td>        <td align="center">'+ppCartForm+'  </td>      </tr></table>    ';
    var cartHTML = cartHeadHtml+cartLineHtml+cartTotalsHtml+cartFooterHtml;
     document.write(cartHTML);
     if (DiscountMessage !== ''){
     document.write('<span class="ssCartTitle">'+DiscountMessage+'</span>');
     }
    }else{
        document.write('<span class="ssCartTitle">Cart is empty.</span>');
    }
}
