//=====================================================================||
//               NOP Design JavaScript Shopping Cart                   ||
//                                                                     ||
// For more information on SmartSystems, or how NOPDesign can help you ||
// Please visit us on the WWW at http://www.nopdesign.com              ||
//                                                                     ||
// Javascript portions of this shopping cart software are available as ||
// freeware from NOP Design.  You must keep this comment unchanged in  ||
// your code.  For more information contact FreeCart@NopDesign.com.    ||
//                                                                     ||
// JavaScript Shop Module, V.4.4.0                                     ||
//=====================================================================||

//---------------------------------------------------------------------||
//                       Global Options                                ||
//                      ----------------                               ||
// Shopping Cart Options, you can modify these options to change the   ||
// the way the cart functions.                                         ||
//                                                                     ||
// Language Packs                                                      ||
// ==============                                                      ||
// You may include any language pack before nopcart.js in your HTML    ||
// pages to change the language.  Simply include a language pack with  ||
// a script src BEFORE the <SCRIPT SRC="nopcart.js">... line.          ||
//  For example: <SCRIPT SRC="language-en.js"></SCRIPT>                ||
//                                                                     ||
// Options For Everyone:                                               ||
// =====================                                               ||
// * MonetarySymbol: string, the symbol which represents dollars/euro, ||
//   in your locale.                                                   ||
// * DisplayNotice: true/false, controls whether the user is provided  ||
//   with a popup letting them know their product is added to the cart ||
// * DisplayShippingColumn: true/false, controls whether the managecart||
//   and checkout pages display shipping cost column.                  ||
// * DisplayShippingRow: true/false, controls whether the managecart   ||
//   and checkout pages display shipping cost total row.               ||
// * DisplayTaxRow: true/false, controls whether the managecart        ||
//   and checkout pages display tax cost total row.                    ||
// * TaxRate: number, your area's current tax rate, ie: if your tax    ||
//   rate was 7.5%, you would set TaxRate = 0.075                      ||
// * TaxByRegion: true/false, when set to true, the user is prompted   ||
//   with TaxablePrompt to determine if they should be charged tax.    ||
//   In the USA, this is useful to charge tax to those people who live ||
//   in a particular state, but no one else.                           ||
// * TaxPrompt: string, popup message if user has not selected either  ||
//   taxable or nontaxable when TaxByRegion is set to true.            ||
// * TaxablePrompt: string, the message the user is prompted with to   ||
//   select if they are taxable.  If TaxByRegion is set to false, this ||
//   has no effect. Example: 'Arizona Residents'                       ||
// * NonTaxablePrompt: string, same as above, but the choice for non-  ||
//   taxable people.  Example: 'Other States'                          ||
// * MinimumOrder: number, the minium dollar amount that must be       ||
//   purchased before a user is allowed to checkout.  Set to 0.00      ||
//   to disable.                                                       ||
// * MinimumOrderPrompt: string, Message to prompt users with when     ||
//   they have not met the minimum order amount.                       ||
//                                                                     ||
// Payment Processor Options:                                          ||
// ==========================                                          ||
// * PaymentProcessor: string, the two digit payment processor code    ||
//   for support payment processor gateways.  Setting this field to    ||
//   anything other than an empty string will override your OutputItem ||
//   settings -- so please be careful when receiving any form data.    ||
//   Support payment processor gateways are:                           ||
//    * Authorize.net (an)                                             ||
//    * Worldpay      (wp)                                             ||
//    * LinkPoint     (lp)
//                                                                     ||
// Options For Programmers:                                            ||
// ========================                                            ||
// * OutputItem<..>: string, the name of the pair value passed at      ||
//   checkouttime.  Change these only if you are connecting to a CGI   ||
//   script and need other field names, or are using a secure service  ||
//   that requires specific field names.                               ||
// * AppendItemNumToOutput: true/false, if set to true, the number of  ||
//   each ordered item will be appended to the output string.  For     ||
//   example if OutputItemId is 'ID_' and this is set to true, the     ||
//   output field name will be 'ID_1', 'ID_2' ... for each item.       ||
// * HiddenFieldsToCheckout: true/false, if set to true, hidden fields ||
//   for the cart items will be passed TO the checkout page, from the  ||
//   ManageCart page.  This is set to true for CGI/PHP/Script based    ||
//   checkout pages, but should be left false if you are using an      ||
//   HTML/Javascript Checkout Page. Hidden fields will ALWAYS be       ||
//   passed FROM the checkout page to the Checkout CGI/PHP/ASP/Script  ||
//---------------------------------------------------------------------||

//Options for Everyone:
MonetarySymbol        = '&#163;';
DisplayNotice         = false;
DisplayShippingColumn = false;
DisplayShippingRow    = false;
DisplayTaxRow         = true;
TaxRate               = 0.175;
TaxByRegion           = false;
TaxPrompt             = 'UK residents need to add VAT';
TaxablePrompt         = 'UK';
NonTaxablePrompt      = 'Non-UK';
MinimumOrder          = 0.00;
MinimumOrderPrompt    = 'Your order is below our minimum order, please order more before checking out.';
ItemLinkPrefix        = 'wineinfo.aspx?code=';

//Payment Processor Options:
PaymentProcessor      = '';

//Options for Programmers:
OutputItemId          = 'ID_';
OutputItemUOM         = 'UOM_';
OutputItemQuantity    = 'QUANTITY_';
OutputItemPrice       = 'PRICE_';
OutputItemName        = 'NAME_';
OutputItemShipping    = 'SHIPPING_';
OutputItemAddtlInfo   = 'ADDTLINFO_';
OutputOrderSubtotal   = 'SUBTOTAL';
OutputOrderShipping   = 'SHIPPING';
OutputOrderTax        = 'TAX';
OutputOrderTotal      = 'TOTAL';
AppendItemNumToOutput = true;
HiddenFieldsToCheckout = true;

//TVISION options
CookieName = 'NOPCart.';
MaxCookieLength = 500;
var CookieBasket;

//=====================================================================||
//---------------------------------------------------------------------||
//    YOU DO NOT NEED TO MAKE ANY MODIFICATIONS BELOW THIS LINE        ||
//---------------------------------------------------------------------||
//=====================================================================||


//---------------------------------------------------------------------||
//                      Language Strings                               ||
//                     ------------------                              ||
// These strings will not be used unless you have not included a       ||
// language pack already.  You should NOT modify these, but instead    ||
// modify the strings in language-**.js where ** is the language pack  ||
// you are using.                                                      ||
//---------------------------------------------------------------------||
if ( !bLanguageDefined ) {
   strSorry  = "I'm Sorry, your cart is full, please proceed to checkout.";
   strAdded  = " added to your shopping cart.";
   strRemove = "Click 'Ok' to remove this product from your shopping cart.";
   strILabel = "Product Id";
   strDLabel = "Product Name/Description";
   strQLabel = "Quantity";
   strULabel = "Unit";
   strPLabel = "Price"; //"Price Each";
   strSLabel = "Shipping";
   strRLabel = "Remove From Cart";
   strRButton= "";// "Remove";
   strSUB    = "SUBTOTAL";
   strSHIP   = "SHIPPING";
   strTAX    = "TAX";
   strTOT    = "TOTAL";
   strErrQty = "Invalid Quantity.";
   strNewQty = 'Please enter new quantity:';
   bLanguageDefined = true;
}

//---------------------------------------------------------------------||
// FUNCTION:    Split                                                  ||
// PARAMETERS:  Pattern string, Data string                            ||
// RETURNS:     Array of strings like string.split()                   ||
// PURPOSE:     Compatibility with javascript 1.0                      ||
//---------------------------------------------------------------------||
function Split(string, splitString)
{
//   if (string.split) {
//       this = string.split(splitString);
//       return;
//   } 

   var curString = "", restString = string;
   var loc, leng, i=0, rest;

   while( (loc = restString.indexOf(splitString)) >= 0)
   {
      leng = restString.length;
      
      curString = restString.substring(0, loc);
      restString = restString.substring(loc+1,leng);
      this[i++] = curString;
   }
   this[i++] = restString;
   this["length"]=i;
}

//---------------------------------------------------------------------||
// FUNCTION:    CKquantity                                             ||
// PARAMETERS:  Quantity to                                            ||
// RETURNS:     Quantity as a number, and possible alert               ||
// PURPOSE:     Make sure quantity is represented as a number          ||
//---------------------------------------------------------------------||
function CKquantity(checkString) {
   var strNewQuantity = "";

   for ( i = 0; i < checkString.length; i++ ) {
      ch = checkString.substring(i, i+1);
      if ( (ch >= "0" && ch <= "9") || (ch == '.') )
         strNewQuantity += ch;
   }

   if ( strNewQuantity.length < 1 )
      strNewQuantity = "1";

   return(strNewQuantity);
}


//---------------------------------------------------------------------||
// FUNCTION:    AddToCart                                              ||
// PARAMETERS:  Form Object                                            ||
// RETURNS:     Cookie to user's browser, with prompt                  ||
// PURPOSE:     Adds a product to the user's shopping cart             ||
//---------------------------------------------------------------------||
//function AddToCart(thisForm) { tvt changed
function AddToCart(thisForm,isDuty) { 
   var iNumberOrdered = 0;
   var bAlreadyInCart = false;
   var notice = "";

   iNumberOrdered = GetCookie("NumberOrdered");

   if ( iNumberOrdered == null )
      iNumberOrdered = 0;

   if ( thisForm.ID_NUM == null )
      strID_NUM    = "";
   else
      strID_NUM    = thisForm.ID_NUM.value;

   if ( thisForm.QUANTITY == null ) {
      if (thisForm.QTYREF == null) {
         strQUANTITY = "1";
      } else {
         var QTYFld = document.getElementById(thisForm.QTYREF.value);
         if (QTYFld == null) 
            strQUANTITY = "1";
         else
            strQUANTITY = QTYFld.value;
      }
   } else
      strQUANTITY  = thisForm.QUANTITY.value;

   if ( thisForm.PRICE == null )
      strPRICE     = "0.00";
   else
      strPRICE     = thisForm.PRICE.value;

   if ( thisForm.NAME == null )
      strNAME      = "";
   else
      strNAME      = thisForm.NAME.value;

   if ( thisForm.SHIPPING == null )
      strSHIPPING  = "0.00";
   else
      strSHIPPING  = thisForm.SHIPPING.value;

   if ( thisForm.INC_VAT == null )
      strINCVAT = "0";
   else
      strINCVAT = thisForm.INC_VAT.value;
   if ( thisForm.UOM == null )
      strUOM = "";
   else
      strUOM = thisForm.UOM.value;

   if ( thisForm.ADDITIONALINFO == null ) {
      strADDTLINFO = "";
   } else {
      strADDTLINFO = thisForm.ADDITIONALINFO[thisForm.ADDITIONALINFO.selectedIndex].value;
   }
   if ( thisForm.ADDITIONALINFO2 != null ) {
      strADDTLINFO += "; " + thisForm.ADDITIONALINFO2[thisForm.ADDITIONALINFO2.selectedIndex].value;
   }
   if ( thisForm.ADDITIONALINFO3 != null ) {
      strADDTLINFO += "; " + thisForm.ADDITIONALINFO3[thisForm.ADDITIONALINFO3.selectedIndex].value;
   }
   if ( thisForm.ADDITIONALINFO4 != null ) {
      strADDTLINFO += "; " + thisForm.ADDITIONALINFO4[thisForm.ADDITIONALINFO4.selectedIndex].value;
   }

   var UserItemNo = new Split(strID_NUM + "/", "/");
   if (strUOM == "") { strUOM = UserItemNo[1]; strID_NUM = UserItemNo[0]; }

   //Is this product already in the cart?  If so, increment quantity instead of adding another.
   for ( i = 1; i <= iNumberOrdered; i++ ) {
      NewOrder = "Order." + i;
      database = "";
      database = GetCookie(NewOrder);      
      fields = new Split(database,"|");

      if ( fields[0] == strID_NUM &&
//         fields[2] == strPRICE  &&
           fields[3] == strNAME   &&
           fields[6] == strUOM    &&
           fields[7] == strADDTLINFO
         ) {
         bAlreadyInCart = true;
         dbUpdatedOrder = strID_NUM    + "|" +
                          (parseInt(strQUANTITY)+parseInt(fields[1]))  + "|" +
                          strPRICE     + "|" +
                          strNAME      + "|" +
                          strSHIPPING  + "|" +
                          strINCVAT    + "|" +
                          strUOM       + "|" +
                          strADDTLINFO;
         strNewOrder = "Order." + i;
         DeleteCookie(strNewOrder, "/");
         SetCookie(strNewOrder, dbUpdatedOrder, "/");
         notice = strQUANTITY + " " + strNAME + strAdded;
         break;
      }
   }

   if ( !bAlreadyInCart ) {
      iNumberOrdered++;

      if ( iNumberOrdered > 30 )
         alert( strSorry );
      else {
         dbUpdatedOrder = strID_NUM    + "|" + 
                          strQUANTITY  + "|" +
                          strPRICE     + "|" +
                          strNAME      + "|" +
                          strSHIPPING  + "|" +
                          strINCVAT    + "|" +
                          strUOM       + "|" +
                          strADDTLINFO;

         strNewOrder = "Order." + iNumberOrdered;
         SetCookie(strNewOrder, dbUpdatedOrder, "/");
         SetCookie("NumberOrdered", iNumberOrdered, "/");
         notice = strQUANTITY + " " + strNAME + strAdded;
      }
   }

   if ( DisplayNotice )
      alert(notice);

   if (! document.getElementById ) return true;
   if (document.getElementById("your-order") == null) return true;
		
   //tvt
    //MiniCart();
   if (isDuty=="1") {
     MiniCart(1);
   }
   else {
     MiniCart(0);
   }
   return false;
}


//---------------------------------------------------------------------||
// FUNCTION:    MoneyFormat                                            ||
// PARAMETERS:  Number to be formatted                                 ||
// RETURNS:     Formatted Number                                       ||
// PURPOSE:     Reformats Dollar Amount to #.## format                 ||
//---------------------------------------------------------------------||
function moneyFormat(input) {
   var dollars = Math.floor(input);
   var tmp = new String(input);

   for ( var decimalAt = 0; decimalAt < tmp.length; decimalAt++ ) {
      if ( tmp.charAt(decimalAt)=="." )
         break;
   }

   var cents  = "" + Math.round(input * 100);
   cents = cents.substring(cents.length-2, cents.length)
           dollars += ((tmp.charAt(decimalAt+2)=="9")&&(cents=="00"))? 1 : 0;

   if ( cents == "0" )
      cents = "00";

   if (isNaN(dollars) || isNaN(cents) || dollars + "." + cents == "0.00" )
      return ("N/S");
   return(MonetarySymbol + dollars + "." + cents);
}


//---------------------------------------------------------------------||
// FUNCTION:    RemoveFromCart                                         ||
// PARAMETERS:  Order Number to Remove                                 ||
// RETURNS:     Null                                                   ||
// PURPOSE:     Removes an item from a users shopping cart             ||
//---------------------------------------------------------------------||

function DoRemoveFromCart(RemOrder) {
   NumberOrdered = GetCookie("NumberOrdered");
   for ( i=RemOrder; i < NumberOrdered; i++ ) {
      NewOrder1 = "Order." + (i+1);
      NewOrder2 = "Order." + (i);
      database = GetCookie(NewOrder1);
      SetCookie (NewOrder2, database, "/");
   }
   NewOrder = "Order." + NumberOrdered;
   DeleteCookie(NewOrder, "/");
   SetCookie ("NumberOrdered", NumberOrdered-1, "/");
}

function RemoveFromCart(RemOrder) {
   if ( confirm( strRemove ) ) {
      DoRemoveFromCart(RemOrder);
      location.href=location.href;
   }
}

//tvt changed function DynRemoveFromCart(RemOrder) {
function DynRemoveFromCart(RemOrder,isDuty) {
   if ( confirm( strRemove ) ) {
      DoRemoveFromCart(RemOrder);
      if(isDuty=="1"){
        MiniCart(1);
      }
      else{
        MiniCart(0);
      }
      
   }
}

//---------------------------------------------------------------------||
// FUNCTION:    ChangeQuantity                                         ||
// PARAMETERS:  Order Number to Change Quantity                        ||
// RETURNS:     Null                                                   ||
// PURPOSE:     Changes quantity of an item in the shopping cart       ||
//---------------------------------------------------------------------||
function ChangeQuantity(OrderItem,NewQuantity) {
   if ( isNaN(NewQuantity) ) {
      alert( strErrQty );
   } else {
      NewOrder = "Order." + OrderItem;
      database = "";
      database = GetCookie(NewOrder);
      fields = new Split(database, "|");

      dbUpdatedOrder = fields[0] + "|" +
                       NewQuantity + "|" +
                       fields[2] + "|" +
                       fields[3] + "|" +
                       fields[4] + "|" +
                       fields[5] + "|" +
                       fields[6] + "|" +
                       fields[7];
      strNewOrder = "Order." + OrderItem;
      DeleteCookie(strNewOrder, "/");
      SetCookie(strNewOrder, dbUpdatedOrder, "/");
      location.href=location.href;      
   }
}

//---------------------------------------------------------------------||
// FUNCTION:    ChangeQuantity                                         ||
// PARAMETERS:  Order Number to Change Quantity                        ||
// RETURNS:     Null                                                   ||
// PURPOSE:     Changes quantity of an item in the shopping cart       ||
//---------------------------------------------------------------------||
function DynChangeQuantity(OrderItem,NewQuantity,isDuty) {
   if ( isNaN(NewQuantity) ) {
      alert( strErrQty );
   } else {
      NewOrder = "Order." + OrderItem;
      database = "";
      database = GetCookie(NewOrder);
      fields = new Split(database, "|");

      dbUpdatedOrder = fields[0] + "|" +
                       NewQuantity + "|" +
                       fields[2] + "|" +
                       fields[3] + "|" +
                       fields[4] + "|" +
                       fields[5] + "|" +
                       fields[6] + "|" +
                       fields[7];
      strNewOrder = "Order." + OrderItem;
      DeleteCookie(strNewOrder, "/");
      SetCookie(strNewOrder, dbUpdatedOrder, "/");
      //tvtMiniCart();
      if (isDuty =="1") {
        MiniCart(1);
      }else{
        MiniCart(0);
      }
   }
}


//---------------------------------------------------------------------||
// FUNCTION:    GetFromCart                                            ||
// PARAMETERS:  Null                                                   ||
// RETURNS:     Product Table Written to Document                      ||
// PURPOSE:     Draws current cart product table on HTML page          ||
//              **DEPRECATED FUNCTION, USE ManageCart or Checkout**    ||
//---------------------------------------------------------------------||
function GetFromCart( fShipping ) {
   ManageCart( );
}


//---------------------------------------------------------------------||
// FUNCTION:    RadioChecked                                           ||
// PARAMETERS:  Radio button to check                                  ||
// RETURNS:     True if a radio has been checked                       ||
// PURPOSE:     Form fillin validation                                 ||
//---------------------------------------------------------------------||
function RadioChecked( radiobutton ) {
   var bChecked = false;
   var rlen = radiobutton.length;
   for ( i=0; i < rlen; i++ ) {
      if ( radiobutton[i].checked )
         bChecked = true;
   }    
   return bChecked;
} 


//---------------------------------------------------------------------||
// FUNCTION:    QueryString                                            ||
// PARAMETERS:  Key to read                                            ||
// RETURNS:     value of key                                           ||
// PURPOSE:     Read data passed in via GET mode                       ||
//---------------------------------------------------------------------||
QueryString.keys = new Array();
QueryString.values = new Array();
function QueryString(key) {
   var value = null;
   for (var i=0;i<QueryString.keys.length;i++) {
      if (QueryString.keys[i]==key) {
         value = QueryString.values[i];
         break;
      }
   }
   return value;
} 

//---------------------------------------------------------------------||
// FUNCTION:    QueryString_Parse                                      ||
// PARAMETERS:  (URL string)                                           ||
// RETURNS:     null                                                   ||
// PURPOSE:     Parses query string data, must be called before Q.S.   ||
//---------------------------------------------------------------------||
function QueryString_Parse() {
   var query = window.location.search.substring(1);
   var pairs = query.split("&"); for (var i=0;i<pairs.length;i++) {
      var pos = pairs[i].indexOf('=');
      if (pos >= 0) {
         var argname = pairs[i].substring(0,pos);
         var value = pairs[i].substring(pos+1);
         QueryString.keys[QueryString.keys.length] = argname;
         QueryString.values[QueryString.values.length] = value;
      }
   }
}


//---------------------------------------------------------------------||
// FUNCTION:    ManageCart                                             ||
// PARAMETERS:  Null                                                   ||
// RETURNS:     Product Table Written to Document                      ||
// PURPOSE:     Draws current cart product table on HTML page          ||
//---------------------------------------------------------------------||
//function ManageCart( ) { //tvt changed
function ManageCart(isDuty) {
   var iNumberOrdered = 0;    //Number of products ordered
   var fTotal         = 0;    //Total cost of order
   var fTax           = 0;    //Tax amount
   var fShipping      = 0;    //Shipping amount

   var fLineTax       = 0;    //Line Tax Amount
   var fLine          = 0;    //Line Amount

   var strTotal       = "";   //Total cost formatted as money
   var strTax         = "";   //Total tax formatted as money
   var strShipping    = "";   //Total shipping formatted as money
   var strOutput      = "";   //String to be written to page
   var bDisplay       = true; //Whether to write string to the page (here for programmers)
   var bDispTotals    = true; // Do we want to to display the total on the Cart page
   var bDispUpdate    = true; // Add a button for 'Update quantity'

   iNumberOrdered = GetCookie("NumberOrdered");
   if ( iNumberOrdered == null )
      iNumberOrdered = 0;

   if ( bDisplay )
      strOutput = "<table><thead><tr>" +
                  "<th>"+strDLabel+"</th>" +
                  "<th>"+strILabel+"</th>" +
                  "<th>"+strULabel+"</th>" +
                  "<th>"+strPLabel+"</th>" +
                  "<th>"+strQLabel+"</th>" +
                  (DisplayShippingColumn?"<th>"+strSLabel+"</th>":"") +
                  "<th></th></tr></thead><tbody>";
                  //"<th>"+strRLabel+"</th></tr></thead><tbody>";

   if ( iNumberOrdered == 0 ) {
      strOutput += "<tr><td colspan='6'><center><br/>Your order is empty<br/><br/></center></td></tr>";
	bDispUpdate = false;
   }

    if ( iNumberOrdered == 0 ) {
           $(document).ready(function(){ 
                var hider = document.getElementById("iforder");
                if (hider)
                    hider.style.display = "none"; 
            });
    } else {
           $(document).ready(function(){ 
                var hider = document.getElementById("iforder");
                if (hider)
                    hider.style.display = "inline"; 
            });
    }

   for ( i = 1; i <= iNumberOrdered; i++ ) {
      NewOrder = "Order." + i;
      database = "";
      database = GetCookie(NewOrder);
      fields = new Split(database, "|");

      iIncVAT     = parseInt(fields[5])
      fLine       = (parseInt(fields[1]) * parseFloat(fields[2]) );
      if (iIncVAT == 0 ) {	  
	  fLineTax   = (fLine * TaxRate);
	  fTax      += fLineTax;
	  fTotal    += fLine;
	  fShipping += (parseInt(fields[1]) * parseFloat(fields[4]) );
      } else {
	  fLineTax   = (fLine/(1+TaxRate) * TaxRate);
	  fTax      += fLineTax;
	  fTotal    += fLine - fLineTax;
	  fShipping += (parseInt(fields[1]) * parseFloat(fields[4]) );
      }

      //tvt
      if (isDuty=="1"){
      fTax=0; 
      }
      //tvt end

      strTotal    = moneyFormat(fTotal);
      strTax      = moneyFormat(fTax);
      strShipping = moneyFormat(fShipping);

      if ( bDisplay ) {
         if ( fields[7] == "" )
            strOutput += "<tr><td><a href=\""+ ItemLinkPrefix  + fields[0] + "\">"+fields[3]+"</a></td>";
         else
            strOutput += "<td>"  + fields[3] + " - <I>"+ fields[7] + "</I></td>";

         strOutput += "<td>" + fields[0] + "</td>";
                      //"<a href=\"" + ItemLinkPrefix + fields[0] + "\">" + fields[0] + "</a></td>";         
         
         strOutput += "<td>"  + fields[6] + "</td>";
         strOutput += "<td>"+ moneyFormat(fields[2]) + "</td>";
         strOutput += "<td><input type=text name=q size=2 value=\"" + fields[1] + "\" onChange=\"ChangeQuantity("+i+", this.value);\"></td>";

         if ( DisplayShippingColumn ) {
            if ( parseFloat(fields[4]) > 0 )
               strOutput += "<td>"+ moneyFormat(fields[4]) + "</td>";
            else
               strOutput += "<td>N/A</td>";
         }

         strOutput += "<td align=center><button type=button value=\" "+strRButton+" \" onClick=\"RemoveFromCart("+i+")\" class=\"button\">"+strRButton+"</button></td></tr>";
      }

      if ( AppendItemNumToOutput ) {
         strFooter = i;
      } else {
         strFooter = "";
      }
      if ( HiddenFieldsToCheckout ) {
         strOutput += "<input type=hidden name=\"" + OutputItemId        + strFooter + "\" value=\"" + fields[0] + "\">";
         strOutput += "<input type=hidden name=\"" + OutputItemQuantity  + strFooter + "\" value=\"" + fields[1] + "\">";
         strOutput += "<input type=hidden name=\"" + OutputItemPrice     + strFooter + "\" value=\"" + fields[2] + "\">";
         strOutput += "<input type=hidden name=\"" + OutputItemName      + strFooter + "\" value=\"" + fields[3] + "\">";
         strOutput += "<input type=hidden name=\"" + OutputItemShipping  + strFooter + "\" value=\"" + fields[4] + "\">";
         strOutput += "<input type=hidden name=\"" + OutputItemUOM       + strFooter + "\" value=\"" + fields[6] + "\">";
         strOutput += "<input type=hidden name=\"" + OutputItemAddtlInfo + strFooter + "\" value=\"" + fields[7] + "\">";
      }

   }

   // Enotria Shipping
//   if ( fTotal + fShipping + fTax < 200 && fTotal + fShipping + fTax > 0 ) {
//      fShipping += 7.50;
//      strShipping = moneyFormat(fShipping);
//   }
   if ( bDisplay && bDispUpdate ) {
         strOutput += "<tr>"
         strOutput += "<td>&nbsp;</td>"
         strOutput += "<td>&nbsp;</td>"         
         strOutput += "<td>&nbsp;</td>"
         strOutput += "<td>&nbsp;</td>"
         strOutput += "<td align=left><button type=button value=\" Update \" onClick=\"\" class=\"button\">Update</button></td>"
         strOutput += "<td>&nbsp;</td>"         
         if ( DisplayShippingColumn ) {
	     strOutput += "<td>&nbsp;</td>"
	 }
	 strOutput += "</tr>";
   }

   if ( bDisplay ) {
      strOutput += "</tbody></table><table id=total>";
   }   

   if ( bDisplay && bDispTotals && fTotal + fShipping + fTax > 0 && !isNaN(fTotal)) {
      strOutput += "<tr><td class=\"head\" COLSPAN=4>"+strSUB+"</td>";
      strOutput += "<td class=\"head\" COLSPAN=2>" + strTotal + "</td>";
      strOutput += "</tr>";

      if ( DisplayShippingRow || fShipping > 0 ) {
         strOutput += "<tr><td class=\"head\" COLSPAN=4>"+strSHIP+"</td>";
         strOutput += "<td class=\"head\" COLSPAN=2>" + strShipping + "</td>";
         strOutput += "</tr>";
      }

      if ( DisplayTaxRow || TaxByRegion ) {
         if ( TaxByRegion ) {
            strOutput += "<tr><td class=\"head\" COLSPAN=4>"+strTAX+"</td>";
            strOutput += "<td class=\"head\" COLSPAN=2>";
            strOutput += "<input type=radio name=\""+OutputOrderTax+"\" value=\"" + strTax + "\">";
            strOutput += TaxablePrompt + ": " + strTax;
            strOutput += "<br/><input type=radio name=\""+OutputOrderTax+"\" value=\"0.00\">";
            strOutput += NonTaxablePrompt + ": " + MonetarySymbol + "0.00";
            strOutput += "</td>";
            strOutput += "</tr>";
         } else {
            strOutput += "<tr><td class=\"head\" COLSPAN=4>"+strTAX+"</td>";
            strOutput += "<td class=\"head\" COLSPAN=2>" + strTax + "</td>";
            strOutput += "</tr>";
         }
      }

      if ( !TaxByRegion ) {
         strOutput += "<tr><td class=\"head\" COLSPAN=4>"+strTOT+"</td>";
         strOutput += "<td class=\"head\" COLSPAN=2>" + moneyFormat((fTotal + fShipping + fTax)) + "</td>";
         strOutput += "</tr>";
      }
   }
   if ( bDisplay ) {
      strOutput += "</table>";

      if ( HiddenFieldsToCheckout ) {
         strOutput += "<input type=hidden name=\""+OutputOrderSubtotal+"\" value=\""+ strTotal + "\">";
         strOutput += "<input type=hidden name=\""+OutputOrderShipping+"\" value=\""+ strShipping + "\">";
         strOutput += "<input type=hidden name=\""+OutputOrderTax+"\"      value=\""+ strTax + "\">";
         strOutput += "<input type=hidden name=\""+OutputOrderTotal+"\"    value=\""+ moneyFormat((fTotal + fShipping + fTax)) + "\">";
      }
   }
   g_TotalCost = (fTotal + fShipping + fTax);

   document.write(strOutput);
   document.close();
   
}

//---------------------------------------------------------------------||
// FUNCTION:    ValidateCart                                           ||
// PARAMETERS:  Form to validate                                       ||
// RETURNS:     true/false                                             ||
// PURPOSE:     Validates the managecart form                          ||
//---------------------------------------------------------------------||
var g_TotalCost = 0;
function ValidateCart( theForm ) {
   if ( TaxByRegion ) {
      if ( !RadioChecked(eval("theForm."+OutputOrderTax)) ) {
         alert( TaxPrompt );
         return false;
      }
   }

   if ( MinimumOrder >= 0.01 ) {
      if ( g_TotalCost < MinimumOrder ) {
         alert( MinimumOrderPrompt );
         return false;
      }
   }

   return true;
}

//---------------------------------------------------------------------||
// FUNCTION:    CheckoutCart                                           ||
// PARAMETERS:  Null                                                   ||
// RETURNS:     Product Table Written to Document                      ||
// PURPOSE:     Draws current cart product table on HTML page for      ||
//              checkout.                                              ||
//---------------------------------------------------------------------||
function CheckoutCart( ) {
   var iNumberOrdered = 0;    //Number of products ordered
   var fTotal         = 0;    //Total cost of order
   var fTax           = 0;    //Tax amount
   var fShipping      = 0;    //Shipping amount

   var fLineTax       = 0;    //Line Tax Amount
   var fLine          = 0;    //Line Amount

   var strTotal       = "";   //Total cost formatted as money
   var strTax         = "";   //Total tax formatted as money
   var strShipping    = "";   //Total shipping formatted as money
   var strOutput      = "";   //String to be written to page
   var bDisplay       = true; //Whether to write string to the page (here for programmers)
   var strPP          = "";   //Payment Processor Description Field

   iNumberOrdered = GetCookie("NumberOrdered");
   if ( iNumberOrdered == null )
      iNumberOrdered = 0;

   if ( TaxByRegion ) {
      QueryString_Parse();
      fTax = parseFloat( QueryString( OutputOrderTax ) );
      strTax = moneyFormat(fTax);
   }

   if ( bDisplay )
      strOutput = "<table><tr>" +
                  "<td>"+strILabel+"</td>" +
                  "<td>"+strDLabel+"</td>" +
                  "<td>"+strQLabel+"</td>" +
                  "<td>"+strPLabel+"</td>" +
                  (DisplayShippingColumn?"<td>"+strSLabel+"</td>":"") +
                  "</tr>";

   for ( i = 1; i <= iNumberOrdered; i++ ) {
      NewOrder = "Order." + i;
      database = "";
      database = GetCookie(NewOrder);
      fields = new Split(database, "|");

      iIncVAT     = parseInt(fields[5])
      fLine       = (parseInt(fields[1]) * parseFloat(fields[2]) );
      if (iIncVAT == 0 ) {
	  fLineTax   = (fLine * TaxRate);
	  fTax      += fLineTax;
	  fTotal    += fLine;
	  fShipping += (parseInt(fields[1]) * parseFloat(fields[4]) );
      } else {
	  fLineTax   = (fLine/(1+TaxRate) * TaxRate);
	  fTax      += fLineTax;
	  fTotal    += fLine - fLineTax;
	  fShipping += (parseInt(fields[1]) * parseFloat(fields[4]) );
      }

      strTotal    = moneyFormat(fTotal);
      strTax      = moneyFormat(fTax);
      strShipping = moneyFormat(fShipping);

//      fTotal     += (parseInt(fields[1]) * parseFloat(fields[2]) );
//      fShipping  += (parseInt(fields[1]) * parseFloat(fields[4]) );
//      if ( !TaxByRegion ) fTax = (fTotal * TaxRate);
//      strTotal    = moneyFormat(fTotal);
//      if ( !TaxByRegion ) strTax = moneyFormat(fTax);
//      strShipping = moneyFormat(fShipping);

      if ( bDisplay ) {
         strOutput += "<tr><td>"  + fields[0] + "</td>";

         if ( fields[7] == "" )
            strOutput += "<td>"  + fields[3] + "</td>";
         else
            strOutput += "<td>"  + fields[3] + " - <I>"+ fields[7] + "</I></td>";

         strOutput += "<td>" + fields[1] + "</td>";
         strOutput += "<td>"+ moneyFormat(fields[2]) + "</td>";

         if ( DisplayShippingColumn ) {
            if ( parseFloat(fields[4]) > 0 )
               strOutput += "<td>"+ moneyFormat(fields[4]) + "</td>";
            else
               strOutput += "<td>N/A</td>";
         }

         strOutput += "</tr>";
      }

      if ( AppendItemNumToOutput ) {
         strFooter = i;
      } else {
         strFooter = "";
      }
      if ( PaymentProcessor != '' ) {
         //Process description field for payment processors instead of hidden values.
         //Format Description of product as:
         // ID, Name, Qty X
         strPP += fields[0] + ", " + fields[3];
         if ( fields[7] != "" )
            strPP += " - " + fields[7];
         strPP += ", Qty. " + fields[1] + "\n";
      } else {
         strOutput += "<input type=hidden name=\"" + OutputItemId        + strFooter + "\" value=\"" + Fields[0] + "\">";
         strOutput += "<input type=hidden name=\"" + OutputItemQuantity  + strFooter + "\" value=\"" + fields[1] + "\">";
         strOutput += "<input type=hidden name=\"" + OutputItemPrice     + strFooter + "\" value=\"" + fields[2] + "\">";
         strOutput += "<input type=hidden name=\"" + OutputItemName      + strFooter + "\" value=\"" + fields[3] + "\">";
         strOutput += "<input type=hidden name=\"" + OutputItemShipping  + strFooter + "\" value=\"" + fields[4] + "\">";
         strOutput += "<input type=hidden name=\"" + OutputItemUOM       + strFooter + "\" value=\"" + Fields[6] + "\">";
         strOutput += "<input type=hidden name=\"" + OutputItemAddtlInfo + strFooter + "\" value=\"" + fields[7] + "\">";
      } 

   }

   // Enotria Shipping
//   if ( fTotal + fShipping + fTax < 200 && fTotal + fShipping + fTax > 0 ) {
//      fShipping += 7.50;
//      strShipping = moneyFormat(fShipping);
//   }

   if ( bDisplay ) {
      strOutput += "<tr><td class=\"noptotal\" COLSPAN=3>"+strSUB+"</td>";
      strOutput += "<td class=\"noptotal\" COLSPAN=2 ALIGN=RIGHT>" + strTotal + "</td>";
      strOutput += "</tr>";

      if ( DisplayShippingRow || fShipping > 0 ) {
         strOutput += "<tr><td class=\"noptotal\" COLSPAN=3>"+strSHIP+"</td>";
         strOutput += "<td class=\"noptotal\" COLSPAN=2 ALIGN=RIGHT>" + strShipping + "</td>";
         strOutput += "</tr>";
      }

      if ( (DisplayTaxRow || TaxByRegion) && strTax != "N/S" ) {
         strOutput += "<tr><td class=\"noptotal\" COLSPAN=3>"+strTAX+"</td>";
         strOutput += "<td class=\"noptotal\" COLSPAN=2 ALIGN=RIGHT>" + strTax + "</td>";
         strOutput += "</tr>";
      }

      strOutput += "<tr><td class=\"noptotal\" COLSPAN=3>"+strTOT+"</td>";
      strOutput += "<td class=\"noptotal\" COLSPAN=2 ALIGN=RIGHT>" + moneyFormat((fTotal + fShipping + fTax)) + "</td>";
      strOutput += "</tr>";

      strOutput += "</TABLE>";

      
      if ( PaymentProcessor == 'an') {
         //Process this for Authorize.net WebConnect
         strOutput += "<input type=hidden name=\"x_Version\" value=\"3.0\">";
         strOutput += "<input type=hidden name=\"x_Show_Form\" value=\"PAYMENT_FORM\">";
         strOutput += "<input type=hidden name=\"x_Description\" value=\""+ strPP + "\">";
         strOutput += "<input type=hidden name=\"x_Amount\" value=\""+ moneyFormat((fTotal + fShipping + fTax)) + "\">";
      } else if ( PaymentProcessor == 'wp') {
         //Process this for WorldPay
         strOutput += "<input type=hidden name=\"desc\" value=\""+ strPP + "\">";
         strOutput += "<input type=hidden name=\"amount\" value=\""+ moneyFormat((fTotal + fShipping + fTax)) + "\">";
      } else if ( PaymentProcessor == 'lp') {
         //Process this for LinkPoint         
         strOutput += "<input type=hidden name=\"mode\" value=\"fullpay\">";
         strOutput += "<input type=hidden name=\"chargetotal\" value=\""+ moneyFormat((fTotal + fShipping + fTax)) + "\">";
         strOutput += "<input type=hidden name=\"tax\" value=\""+ strTax + "\">";
         strOutput += "<input type=hidden name=\"subtotal\" value=\""+ strTotal + "\">";
         strOutput += "<input type=hidden name=\"shipping\" value=\""+ strShipping + "\">";
         strOutput += "<input type=hidden name=\"desc\" value=\""+ strPP + "\">";
      } else {
         strOutput += "<input type=hidden name=\""+OutputOrderSubtotal+"\" value=\""+ strTotal + "\">";
         strOutput += "<input type=hidden name=\""+OutputOrderShipping+"\" value=\""+ strShipping + "\">";
         strOutput += "<input type=hidden name=\""+OutputOrderTax+"\"      value=\""+ strTax + "\">";
         strOutput += "<input type=hidden name=\""+OutputOrderTotal+"\"    value=\""+ moneyFormat((fTotal + fShipping + fTax)) + "\">";
      }
   }

   document.write(strOutput);
   document.close();
}

//---------------------------------------------------------------------||
// FUNCTION:    MiniCart                                               ||
// PARAMETERS:  Null                                                   ||
// RETURNS:                                                            ||
// PURPOSE:     Alters displayed HTML to show mini basket              ||
//                                                                     ||
//---------------------------------------------------------------------||
//function MiniCart( ) { tvt changed
  function MiniCart(isDuty) {
   var iNumberOrdered = 0;    //Number of products ordered
   var fTotal         = 0;    //Total cost of order
   var fTax           = 0;    //Tax amount
   var fShipping      = 0;    //Shipping amount

   var fLineTax       = 0;    //Line Tax Amount
   var fLine          = 0;    //Line Amount

   var strTotal       = "";   //Total cost formatted as money
   var strTax         = "";   //Total tax formatted as money
   var strShipping    = "";   //Total shipping formatted as money
   var strOutput      = "";   //String to be written to page
   var bDisplay       = true; //Whether to write string to the page (here for programmers)
   var bRemove       = false; //Whether to include the remove column.
   var strPP          = "";   //Payment Processor Description Field
   
   iNumberOrdered = GetCookie("NumberOrdered");
   if ( iNumberOrdered == null )
      iNumberOrdered = 0;

   if ( TaxByRegion ) {
      QueryString_Parse();
      fTax = parseFloat( QueryString( OutputOrderTax ) );
      strTax = moneyFormat(fTax);
   }

   if ( bDisplay ) {
      if (isDuty=="1")
        strOutput = "<h3>Your Duty Free order</h3>";
      else  
        strOutput = "<h3>Your Order Basket</h3>";
        
      strOutput += 
                  "<table><thead><tr>" +
                  "<th>"+strILabel+"</th>" +
                  "<th>"+strULabel+"</th>" +
                  "<th>"+strPLabel+"</th>" +
                  "<th>"+strQLabel+"</th>" +
                  "<th> Del. </th>";
                                   

      if (bRemove)
	        strOutput += "<th>"+strRLabel+"</th>";
      strOutput += "</tr></thead><tbody>";
   }

   if ( iNumberOrdered == 0 ) {
      strOutput += "<tr><td colspan=5 ><center><br/>Your order is empty<br/><br/></center></td></tr>";
   }
   
   for ( i = 1; i <= iNumberOrdered; i++ ) {
      NewOrder = "Order." + i;
      database = "";
      database = GetCookie(NewOrder);           
      if  (database == null) {
		database = ""
		}
      fields = new Split(database,"|");
      
      iIncVAT     = parseInt(fields[5])
      fLine       = (parseInt(fields[1]) * parseFloat(fields[2]) );
      if (iIncVAT == 0 ) { 	    
	  fLineTax   = (fLine * TaxRate);
	  fTax      += fLineTax;
	  fTotal    += fLine;
	  fShipping += (parseInt(fields[1]) * parseFloat(fields[4]) );
      } else {
	  fLineTax   = (fLine/(1+TaxRate) * TaxRate);
	  fTax      += fLineTax;
	  fTotal    += fLine - fLineTax;
	  fShipping += (parseInt(fields[1]) * parseFloat(fields[4]) );
      }

      //added by TVT      
      if ( isDuty=="1" ) {
        fTax=0;
      }
      //end TVT   

      strTotal    = moneyFormat(fTotal);
      strTax      = moneyFormat(fTax);
      strShipping = moneyFormat(fShipping);

//      fTotal     += (parseInt(fields[1]) * parseFloat(fields[2]) );
//      fShipping  += (parseInt(fields[1]) * parseFloat(fields[4]) );
//      if ( !TaxByRegion ) fTax = (fTotal * TaxRate);
//      strTotal    = moneyFormat(fTotal);
//      if ( !TaxByRegion ) strTax = moneyFormat(fTax);
//      strShipping = moneyFormat(fShipping);

      if ( bDisplay ) {
         //strOutput += "<tr><td>"  + fields[0] + "</td>";
         
         strOutput += "<tr><td>" + 
                      "<a href=\"" + ItemLinkPrefix + fields[0] + "\" " + 
                      "title=\"" + fields[3] + "\" " + 
                      " class=\"\shlink\">" +
	              fields[0] + "</a></td>";
         strOutput += "<td>" + fields[6];
         strOutput += "<td>"+ moneyFormat(fields[2]);
         
         strOutput += "<td>"+ fields[1]+"</td><td>";
	 if (parseInt(fields[1]) > 0) {
            strOutput += "<a title=\"Reduce by one\" href=\"\" " + 
                         "onClick=\"DynChangeQuantity(" + i + "," + 
                         (parseInt(fields[1]) - 1) + ","+isDuty+"); return false;\">" +
                         "<img border=0 src=\"graphics/blue_minus.gif\">" +"</a>" ;
         } else if (!bRemove) {
	    strOutput += "<a title=\"Remove item\" href=\"\" " + 
                         "onClick=\"DynRemoveFromCart("+i+","+isDuty+"); return false;\" class=\"nopbutton\">" +
			 "<img border=0 src=\"graphics/red-x.gif\">" + "</a>" ;
         }         
	 if (bRemove) 
	    strOutput += "<td>" +
			 "<a href=\"\" onClick=\"DynRemoveFromCart("+i+","+isDuty+"); return false;\" class=\"nopbutton\">" +
			 "<img border=0 src=\"graphics/red-x.gif\">" + "</a>" ;

         strOutput += "</tr>";
      }
   }

   // Enotria Shipping
//   if ( fTotal + fShipping + fTax < 200 && fTotal + fShipping + fTax > 0 ) {
//      fShipping += 7.50;
//      strShipping = moneyFormat(fShipping);
//   }

   if ( bDisplay && iNumberOrdered != 0 && fTotal + fShipping + fTax > 0 && !isNaN(fTotal)) {
      strOutput += "<tr><td colspan=3 align=right>"+strSUB+"</td>";
      strOutput += "<td colspan=2 align=right>" + strTotal + "</td>";
      strOutput += "</tr>";

      if ( DisplayShippingRow || fShipping > 0 ) {
         strOutput += "<tr><td colspan=3 align=right>"+strSHIP+"</td>";
         strOutput += "<td colspan=2 align=right>" + strShipping + "</td>";
         strOutput += "</tr>";
      }

      if ( (DisplayTaxRow || TaxByRegion) && strTax != "N/S" ) {
         strOutput += "<tr><td colspan=3 align=right>"+strTAX+"</td>";
         strOutput += "<td colspan=2 align=right>" + strTax + "</td>";
         strOutput += "</tr>";
      }

      strOutput += "<tr><td colspan=3 align=right>"+strTOT+"</td>";
      strOutput += "<td colspan=2 align=right>" + moneyFormat((fTotal + fShipping + fTax)) + "</td>";
      strOutput += "</tr>";
   }
   if ( bDisplay ) {
      strOutput += "</tbody></table>";
      strOutput += "<div><a href=\"managecart.aspx\">checkout</a></div>";
   }

   var divhtml = document.getElementById("your-order")
   if (divhtml == null) return true;
   divhtml.innerHTML= strOutput;
}

//=====================================================================||
//               END NOP Design SmartPost Shopping Cart                ||
//=====================================================================||
//
//=====================================================================||
// Rewrite of Cookie Functions.
//=====================================================================||
function GetCookie (name) {
	FetchBasketFromCookies();

	if (name == "NumberOrdered") {
		if (CookieBasket.length < 1) 
			return null;
		return (CookieBasket.length-1) + "";
	} else if (name.slice(0,6) == "Order.") {
		return CookieBasket[parseInt(name.slice(6))];
	} else {
		return null;
	}
}

function SetCookie (name,value,path,domain,secure) {
	FetchBasketFromCookies();

    if (name.slice(0,6) == "Order.") {
		CookieBasket[parseInt(name.slice(6))] = value;
	}

	if (name == "NumberOrdered") {
		CookieBasket.length = (value-0) + 1;
	}

	SaveBasketToCookies();
}

function DeleteCookie (name,path,domain) {
	FetchBasketFromCookies();

    if (name.slice(0,6) == "Order.") {
		CookieBasket[parseInt(name.slice(6))] = "";
	}
}

function FetchBasketFromCookies () {
	var j, i, ck, s, v, n;
	var StrCookieBasket;

	if (CookieBasket != void null ) return;

	var ACookieBasket = new Array(10);
    var ac = document.cookie.split(';');

    for(i=0; i<ac.length;i++) {
        ck = ac[i];

        s = ck.indexOf('=');
        v = ck.indexOf(CookieName);
        if (s >= 0 && v >= 0) {
			n = parseInt(ck.substring(v+CookieName.length));
            ACookieBasket[n] = ck.substring(s+1);
        }
    }

	StrCookieBasket = ACookieBasket.join("");
	StrCookieBasket = StrCookieBasket.replace(/%7[bB]/g,";");
	StrCookieBasket = StrCookieBasket.replace(/%7[Dd]/g,"=");

	CookieBasket = new Array();

	var numOrdered = -1;
    ac = StrCookieBasket.split(';');
    for(i=0; i<ac.length;i++) {
        ck = ac[i];

        s = ck.indexOf('=');
        v = ck.indexOf("Order.");
		if (s >= 0 && v >= 0) {
			n = parseInt(ck.substring(v+6));
			CookieBasket[n] = decodeURIComponent(ck.substring(s+1));
		} else {
        	v = ck.indexOf("NumberOrdered");
			if (s >= 0 && v >= 0) {
				numOrdered = ck.substring(s+1) - 0;
			}
		}
	}
	if (numOrdered >= 0) 
		CookieBasket.length = numOrdered+1;

	for (i = 1, j = 1; i<CookieBasket.length; i++) {
        if ( CookieBasket[i] != null && CookieBasket[i] != "")
			CookieBasket[j++] = CookieBasket[i]
		else alert("Warning: Lost basket item No. " + i);
	}
	CookieBasket.length = j;
}

function SaveBasketToCookies() {
	var TempBasket, i;

	DoSaveBasketToCookies();
	
	TempBasket = CookieBasket;
	CookieBasket = void null;
	FetchBasketFromCookies();

	if (TempBasket.length != CookieBasket.length) {
		CookieBasket.length = TempBasket.length - 1;
		for(i = 1; i<CookieBasket.length; i++)
			CookieBasket[i] = TempBasket[i];

		DoSaveBasketToCookies();
		CookieBasket = void null;
		FetchBasketFromCookies();

		alert("Your cookiejar has overflowed, your basket may be damaged. You had " + TempBasket.length + " items but only " + CookieBasket.length + " got saved.");
	}

	CookieBasket = TempBasket;
}

function DoSaveBasketToCookies() {
	var i;
	var CookieString = "";
	var CookieNum = 1;

	while (CookieBasket.length > 1 && CookieBasket[CookieBasket.length-1] == "" )
		CookieBasket.length = CookieBasket.length-1;

	if (CookieBasket.length < 1) return;

	for(i=1; i<20; i++) {
		document.cookie = CookieName + CookieNum + "=" + "; path=/" + "; expires=Thu, 01-Jan-70 00:00:01 GMT"
	}

	CookieString = "{NumberOrdered}" + (CookieBasket.length-1);
    for(i=1; i<CookieBasket.length;i++) {
		if (CookieString.length + CookieBasket[i].length > MaxCookieLength ) {
    		document.cookie = CookieName + CookieNum + "=" + encodeURIComponent (CookieString) + "; path=/";
			CookieNum ++;
			CookieString = "";
		}

		CookieString = CookieString  + "{Order." + i + "}" + CookieBasket[i];
	}

	if (CookieString != "") {
   		document.cookie = CookieName + CookieNum + "=" + encodeURIComponent (CookieString) + "; path=/";
		CookieNum ++;
		CookieString = "";
	}
}
