//=====================================================================||
//               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:
DisplayNotice         = true;
DisplayShippingColumn = false;
DisplayShippingRow    = true;
DisplayTaxRow         = true;
TaxByRegion           = false;
TaxPrompt             = 'For tax purposes, please select if you are an Arizona resident before continuing';
TaxablePrompt         = 'Arizona Residents';
NonTaxablePrompt      = 'Other States';
MinimumOrder          = 20.00;
MinimumOrderPrompt    = 'Your cart is below our minimum order value of twenty pounds, please add more items';
gNumOrdered           = 0;
gTotalWeight          = 0;
EmptyCartPrompt       = 'Your cart is empty, please add items';
Taxexempt             = false;
JumpToCart	      = false;
ReloadPage	      = true;

//Payment Processor Options:
PaymentProcessor      = '';

//Options for Programmers:
OutputItemId          = 'ID_';
OutputItemQuantity    = 'QUANTITY_';
OutputItemPrice       = 'PRICE_';
OutputItemName        = 'NAME_';
OutputItemShipping    = 'SHIPPING_';
OutputItemAddtlInfo   = 'ADDTLINFO_';
OutputOrderSubtotal   = 'SUBTOTAL';
OutputOrderShipping   = 'SHIPPING';
OutputOrderTax        = 'TAX';
TaxRate               = 'TAXRATE';
OutputOrderTotal      = 'TOTAL';
AppendItemNumToOutput 	= true;
HiddenFieldsToCheckout 	= true;
holdjump 		= false;
searchon = "true";
strDISCOUNT = 0;
strDISCOUNTTEXT = "";
strDISCOUNTPAGE ="";
discountamount = 0;
discountprod = "Fairtrade_Instant_Coffee_Sticks_(500), Fairtrade_Caramelised_Speculoo_Biscuits_(1x300), Caprice_Vanilla_(6x400g), Fairtrade_Instant_Coffee_Sticks_(1x500), Belcolade_Chocolate_Shavings_(3kg), Lavazza_Super_Creme_Espresso_Beans_(6x1kg), Lotus_Speculoo_Biscuits_(1x300), Fairtrade_Caramelised_Biscuits_(1x300), Ghiradelli_Dark_Liquid_Chocolate_(64floz), Ghiradelli_White_Liquid_Chocolate_(64floz), Ghiradelli_Creamy_Caramel_Sauce_(64floz), Cioccobon_Italian_Hot_Chocolate_(1.5kg)";
discountfive = "";
discountten = "";
discountfivecases = "Fairtrade_Instant_Coffee_Sticks_(500), Caprice_Vanilla_(6x400g), Fairtrade_Instant_Coffee_Sticks_(1x500), Belcolade_Chocolate_Shavings_(3kg)";
discountsixcases = "Ghiradelli_Dark_Liquid_Chocolate_(64floz), Ghiradelli_White_Liquid_Chocolate_(64floz), Ghiradelli_Creamy_Caramel_Sauce_(64floz), Cioccobon_Italian_Hot_Chocolate_(1.5kg)";
discounteightcases = "";
discounttencases = "Fairtrade_Caramelised_Speculoo_Biscuits_(1x300), Lavazza_Super_Creme_Espresso_Beans_(6x1kg), Lotus_Speculoo_Biscuits_(1x300), Fairtrade_Caramelised_Biscuits_(1x300)";


//=====================================================================||
//---------------------------------------------------------------------||
//    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  = "Im 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";
   strPLabel = "Price";
   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:    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) {
   var iNumberOrdered = 0;
   var bAlreadyInCart = false;
   var notice = "";
   iNumberOrdered = GetCookie("NumberOrdered");
   
   if ( iNumberOrdered == null )
      iNumberOrdered = 0;


      





   if ( DisplayNotice ) 
 	{
notice = "This product is now available to buy in our new store, click OK to be transferred";
      		ShowAlert(notice);
		    var webpage = location.href.lastIndexOf("/");
		    var cartpage = location.href.substring(0,webpage)+"";
		    window.location.href= cartpage; 
		}
		else 
		{   
		        if ( ReloadPage )
		        {
            			var webpage = location.href;
			        window.location.href= webpage;
		        }
		}
	
return false;
}


//---------------------------------------------------------------------||
// FUNCTION:    getCookieVal                                           ||
// PARAMETERS:  offset                                                 ||
// RETURNS:     URL unescaped Cookie Value                             ||
// PURPOSE:     Get a specific value from a cookie                     ||
//---------------------------------------------------------------------||
function getCookieVal (offset) {
   var endstr = document.cookie.indexOf (";", offset);

   if ( endstr == -1 )
      endstr = document.cookie.length;
   return(unescape(document.cookie.substring(offset, endstr)));
}


//---------------------------------------------------------------------||
// FUNCTION:    FixCookieDate                                          ||
// PARAMETERS:  date                                                   ||
// RETURNS:     date                                                   ||
// PURPOSE:     Fixes cookie date, stores back in date                 ||
//---------------------------------------------------------------------||
function FixCookieDate (date) {
   var base = new Date(0);
   var skew = base.getTime();

   date.setTime (date.getTime() - skew);
}


//---------------------------------------------------------------------||
// FUNCTION:    GetCookie                                              ||
// PARAMETERS:  Name                                                   ||
// RETURNS:     Value in Cookie                                        ||
// PURPOSE:     Retrieves cookie from users browser                    ||
//---------------------------------------------------------------------||
function GetCookie (name) {
   var arg = name + "=";
   var alen = arg.length;
   var clen = document.cookie.length;
   var i = 0;

   while ( i < clen ) {
      var j = i + alen;
      if ( document.cookie.substring(i, j) == arg ) return(getCookieVal (j));
      i = document.cookie.indexOf(" ", i) + 1;
      if ( i == 0 ) break;
   }

   return(null);
}


//---------------------------------------------------------------------||
// FUNCTION:    SetCookie                                              ||
// PARAMETERS:  name, value, expiration date, path, domain, security   ||
// RETURNS:     Null                                                   ||
// PURPOSE:     Stores a cookie in the users browser                   ||
//---------------------------------------------------------------------||
function SetCookie (name,value,expires,path,domain,secure) {
   document.cookie = name + "=" + escape (value) +
                     ((expires) ? "; expires=" + expires.toGMTString() : "") +
                     ((path) ? "; path=" + path : "") +
                     ((domain) ? "; domain=" + domain : "") +
                     ((secure) ? "; secure" : "");
}


//---------------------------------------------------------------------||
// FUNCTION:    DeleteCookie                                           ||
// PARAMETERS:  Cookie name, path, domain                              ||
// RETURNS:     null                                                   ||
// PURPOSE:     Removes a cookie from users browser.                   ||
//---------------------------------------------------------------------||
function DeleteCookie (name,path,domain) {
   if ( GetCookie(name) ) {
      document.cookie = name + "=" +
                        ((path) ? "; path=" + path : "") +
                        ((domain) ? "; domain=" + domain : "") +
                        "; expires=Thu, 01-Jan-70 00:00:01 GMT";
   }
}


//---------------------------------------------------------------------||
// FUNCTION:    MoneyFormat                                            ||
// PARAMETERS:  Number to be formatted                                 ||
// RETURNS:     Formatted Number                                       ||
// PURPOSE:     Reformats Dollar Amount to #.## format                 ||
//---------------------------------------------------------------------||
function moneyFormat(num) {
  num = num.toString().replace(/\&pound;|\,/g,'');
  if(isNaN(num))
  num = "0";
  sign = (num == (num = Math.abs(num)));
  num = Math.floor(num*100+0.50000000001);
  cents = num%100;
  num = Math.floor(num/100).toString();
  if(cents<10)
  cents = "0" + cents;
  for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
  num = num.substring(0,num.length-(4*i+3))+','+
  num.substring(num.length-(4*i+3));
  return (((sign)?'':'-') + num + '.' + cents);

/*
   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);
   
   // ShowAlert( "moneyFormat; cents=" + cents + "; dollars=" + dollars );


   cents = cents.substring(cents.length-2, cents.length);
   dollars += ((tmp.charAt(decimalAt+2)=="9")&&(cents=="00"))? 1 : 0;

   if ( cents == "0" )
      cents = "00";

   return (dollars + "." + cents);
   */
}


//---------------------------------------------------------------------||
// FUNCTION:    RemoveFromCart                                         ||
// PARAMETERS:  Order Number to Remove                                 ||
// RETURNS:     Null                                                   ||
// PURPOSE:     Removes an item from a users shopping cart             ||
//---------------------------------------------------------------------||
function RemoveFromCart(RemOrder) {
   if ( confirm( strRemove ) ) {
      NumberOrdered = GetCookie("NumberOrdered");
      for ( i=RemOrder; i < NumberOrdered; i++ ) {
         NewOrder1 = "Order." + (i+1);
         NewOrder2 = "Order." + (i);
         database = GetCookie(NewOrder1);
         SetCookie (NewOrder2, database, null, "/");
      }
      NewOrder = "Order." + NumberOrdered;
      SetCookie ("NumberOrdered", NumberOrdered-1, null, "/");
      DeleteCookie(NewOrder, "/");
      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 ChangeQuantity(OrderItem,NewQuantity) {
   if ( isNaN(NewQuantity) ) {
      ShowAlert( strErrQty, "red" );
   } else {
      NewOrder = "Order." + OrderItem;
      database = "";
      database = GetCookie(NewOrder);

      Token0 = database.indexOf("|", 0);
      Token1 = database.indexOf("|", Token0+1);
      Token2 = database.indexOf("|", Token1+1);
      Token3 = database.indexOf("|", Token2+1);
      Token4 = database.indexOf("|", Token3+1);

      fields = new Array;
      fields[0] = database.substring( 0, Token0 );
      fields[1] = database.substring( Token0+1, Token1 );
      fields[2] = database.substring( Token1+1, Token2 );
      fields[3] = database.substring( Token2+1, Token3 );
      fields[4] = database.substring( Token3+1, Token4 );
      fields[5] = database.substring( Token4+1, database.length );

      dbUpdatedOrder = fields[0] + "|" +
                       NewQuantity + "|" +
                       fields[2] + "|" +
                       fields[3] + "|" +
                       fields[4] + "|" +
                       fields[5];
      strNewOrder = "Order." + OrderItem;
      DeleteCookie(strNewOrder, "/");
      SetCookie(strNewOrder, dbUpdatedOrder, null, "/");
      location.href=location.href;      
   }
}


//---------------------------------------------------------------------||
// 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( ) {
   var iNumberOrdered = 0;    //Number of products ordered
   var fTotal         = 0;    //Total cost of order
   var fTax           = 0;    //Tax amount
   var fShipping      = 0;    //Shipping amount (nett)
   var fShipTax       = 0;    //Shipping Tax
   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 userZone		= GetCookie("zone");    //Zone
	 if ( userZone == null ) userZone = 0;

	 var userShipping		= GetCookie("shipping");    //Shipping type
	 if ( userShipping == null ) userShipping = 0;

   iNumberOrdered = GetCookie("NumberOrdered");
   if ( iNumberOrdered == null )
      iNumberOrdered = 0;
       
   if ( bDisplay )
      strOutput = "<TABLE class=\"nopcart\"><tr>" +
                  //Remove cart ID title		"<td class=\"nopheader\"><strong>"+strILabel+"</strong></td>" +
                  "<td class=\"nopheader\"><strong>"+strDLabel+"</strong></td>" +
                  "<td class=\"nopheader\"><strong>"+strQLabel+"</strong></td>" +
                  "<td class=\"nopheader\"><strong>"+strPLabel+"</strong></td>" +
                  (DisplayShippingColumn?"<td class=\"nopheader\"><strong>"+strSLabel+"</strong></td>":"") +
                  "<td class=\"nopheader\"><strong>"+strRLabel+" </strong></td></tr>";

   if ( iNumberOrdered == 0 ) {
      strOutput += "<tr><td colspan=6 class=\"nopentry\"><right><br /><strong>" + EmptyCartPrompt + "</strong><br /><br /></CENTER></td></tr>";
   }

   //Get the Total number of Products Ordered and Basket weight
   for ( i = 1; i <= iNumberOrdered; i++ ) {
      NewOrder = "Order." + i;
      database = "";
      database = GetCookie(NewOrder);

      Token0 = database.indexOf("|", 0);
      Token1 = database.indexOf("|", Token0+1);
      Token2 = database.indexOf("|", Token1+1);
      Token3 = database.indexOf("|", Token2+1);
      Token4 = database.indexOf("|", Token3+1);

      fields = new Array;
      fields[0] = database.substring( 0, Token0 );                 // Product ID
      fields[1] = database.substring( Token0+1, Token1 );          // Quantity
      fields[2] = database.substring( Token1+1, Token2 );          // Price
      fields[3] = database.substring( Token2+1, Token3 );          // Product Name/Description
      gNumOrdered   +=  Number(fields[1]);
      gTotalWeight += Number( fields[1] * GetProductWeight( fields[0] ));
      }
      
   for ( i = 1; i <= iNumberOrdered; i++ ) {
      NewOrder = "Order." + i;
      database = "";
      database = GetCookie(NewOrder);

      Token0 = database.indexOf("|", 0);
      Token1 = database.indexOf("|", Token0+1);
      Token2 = database.indexOf("|", Token1+1);
      Token3 = database.indexOf("|", Token2+1);
      Token4 = database.indexOf("|", Token3+1);

      fields = new Array;
      fields[0] = database.substring( 0, Token0 );                 // Product ID
      fields[1] = database.substring( Token0+1, Token1 );          // Quantity
      fields[2] = database.substring( Token1+1, Token2 );          // Price
      fields[3] = database.substring( Token2+1, Token3 );          // Product Name/Description
      fields[4] = CalculateShipping( GetProduct( fields[0] ), userZone );   //fields[4] = database.substring( Token3+1, Token4 );          // Shipping Cost
      fields[5] = database.substring( Token4+1, database.length ); //Additional Information
	
      fTotal     += (parseInt(fields[1]) * parseFloat(fields[2]) );
      fShipping  += (parseInt(fields[1]) * parseFloat(fields[4]) );
      fTax			 += parseInt(fields[1]) * CalculateTax( GetProduct( fields[0] ), userZone, fields[2] ); //fTax        = (fTotal * TaxRate);
      strTotal    = moneyFormat(fTotal);
      strTax      = moneyFormat(fTax);
      strShipping = moneyFormat(fShipping);
      strDISCOUNT = 0;

//ADS
      slink = new String(fields[3]);
      slink = slink.replace( / /g, "_" );

//Give discount calculators values

if ( discountfive.indexOf(fields[0]) > -1 && fields[1] >= 5 ) {
       strDISCOUNT = 5;
}

if ( discountten.indexOf(fields[0]) > -1 && fields[1] >= 10 ) {
       strDISCOUNT = 10;
}

if (discountfivecases.indexOf(fields[0]) > -1 && fields[1] == 5 ) {
     strDISCOUNT = 5;
}

if (discountfivecases.indexOf(fields[0]) > -1 && fields[1] == 10) { 
     strDISCOUNT = 10;
}

//above five of an item gets a discount or ten of an item

if (discountsixcases.indexOf(fields[0]) > -1 && fields[1] == 6 ) {
     strDISCOUNT = 5;
}

if (discountsixcases.indexOf(fields[0]) > -1 && fields[1] == 12) {
     strDISCOUNT = 10;
}

if (discounteightcases.indexOf(fields[0]) > -1 && fields[1] == 8 ) {
     strDISCOUNT = 5;
}

if (discounteightcases.indexOf(fields[0]) > -1 && fields[1] == 10) {
     strDISCOUNT = 10;
}

if (discounttencases.indexOf(fields[0]) > -1 && fields[1] == 10 ) {
     strDISCOUNT = 5;
}

if (discounttencases.indexOf(fields[0]) > -1 && fields[1] == 20) {
     strDISCOUNT = 10;
}



      
      if ( bDisplay ) {
  //remove link       strOutput += "<tr><td class=\"nopentry\"><a href='" + fields[0] + ".htm'>"  + fields[0] + "</a></td>";

//check is the product id is in our discount table and if so supress quantity change
if (discountprod.indexOf(fields[0]) > -1 && strDISCOUNT >= 1 ) {
  strOutput += "<td class=\"nopentry\"><a href='" + slink + ".htm'>"  + fields[3] + " - <i>"+ fields[5] + "</i></a></td>";

         strOutput += "<td class=\"nopentry\">"+ fields[1] + "</td>";
         strOutput += "<td align=left class=\"nopentry\">"+ MonetarySymbol + moneyFormat(fields[2]) + "/ea</td>";
         strOutput += "<td align=left class=\"nopentry\">"+ strDISCOUNT + "% Discount</td>";
}
else {

//check if there are no additional info fields
        if ( fields[5] == "" )
            //strOutput += "<td class=\"nopentry\">"  + fields[3] + "</td>";
	    strOutput += "<td class=\"nopentry\"><a href='" + slink + ".htm'>"  + fields[3] + "</td>";

//or if there are additional fields show them
       else
            strOutput += "<td class=\"nopentry\"><a href='" + slink + ".htm'>"  + fields[3] + " - <i>"+ fields[5] + "</i></td>";

         strOutput += "<td class=\"nopentry\"><input type=TEXT NAME=Q SIZE=2 VALUE=\"" + fields[1] + "\" onChange=\"ChangeQuantity("+i+", this.value);\"></td>";
         strOutput += "<td align=left class=\"nopentry\">"+ MonetarySymbol + moneyFormat(fields[2]) + "/ea</td>";

}

         if ( DisplayShippingColumn ) {
            if ( parseFloat(fields[4]) > 0 ){
               strOutput += "<td class=\"nopentry\">"+ MonetarySymbol + moneyFormat(fields[4]) + "/ea</td>";
            }else
               strOutput += "<td class=\"nopentry\">N/A</td>";
         }

         strOutput += "<td class=\"nopentry\" ALIGN=left><input type=button value=\" "+strRButton+" \" onClick=\"RemoveFromCart("+i+")\" class=\"nopbutton\"></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=\"" + OutputItemAddtlInfo + strFooter + "\" value=\"" + fields[5] + "\">";
      }

   }

   if ( bDisplay ) {
      strOutput += "<tr><td class=\"noptotal\" colspan=2><strong>"+strSUB+"</strong></td>";	// Subtotal title position was colspan=4 
      strOutput += "<td class=\"noptotal\" colspan=2><strong>" + MonetarySymbol + strTotal + "</strong></td>";	//Subtotal price
      strOutput += "</tr>";

      //--- Calculate the actual shipping
      //ShowAlert( fTotal + " : " + fShipping + " : " + userZone );
      fShipping     = calculateTotalShipping(fTotal,fShipping,userZone);
      strShipping   = moneyFormat(fShipping);
      //Calculate the Tax on the shipping
      fTax += CalculateShippingTax(fShipping, userZone);
      strTax      = moneyFormat(fTax);
      
      if ( DisplayShippingRow ) {
         strOutput += "<tr><td class=\"noptotal\" colspan=2><strong>"+strSHIP+"</strong></td>";	// shipping title position was colspan=2
         strOutput += "<td class=\"noptotal\"><strong>" + MonetarySymbol + strShipping + "</strong></td>"; //shipping total price
		 strOutput += "<td class=\"noptotal\" colspan=2>" + displayZone(userZone) + "</td>";	//shipping zone box
		 strOutput += "<td class=\"noptotal\"></td>";
         strOutput += "</tr>";
      }

      if ( DisplayTaxRow || TaxByRegion ) {
         if ( TaxByRegion ) {
            strOutput += "<tr><td class=\"noptotal\" colspan=2><strong>"+strTAX+"</strong></td>"; // display tax position was 4
            strOutput += "<td class=\"noptotal\" colspan=2><strong>";
            strOutput += "<input type=radio name=\""+OutputOrderTax+"\" value=\"" + strTax + "\">";
            strOutput += TaxablePrompt + ": " + MonetarySymbol + strTax;
            strOutput += "<br /><input type=radio name=\""+OutputOrderTax+"\" value=\"0.00\">";
            strOutput += NonTaxablePrompt + ": " + MonetarySymbol + "0.00";
            strOutput += "</strong></td>";
            strOutput += "</tr>";
         } else {
            if (Taxexempt);
            {
                var exemptcookie = GetCookie("exempt");
                if (exemptcookie != null) 
                {
                    if (exemptcookie == "true")
                    {
                        fTax        = 0;
                        strTax      = moneyFormat(fTax);
                    }
                }
            }
            
            if (DisplayTaxRow == false)
            {
                fTax        = 0;
                strTax      = moneyFormat(fTax);
            }
            strOutput += "<tr><td class=\"noptotal\" colspan=2><strong>"+strTAX+"</strong></td>"; // display tax position was 4
            strOutput += "<td class=\"noptotal\" colspan=1><strong>" + MonetarySymbol + strTax + "</strong></td>";
            if (Taxexempt)
            {
                if (exemptcookie == "true")
                {
                    strOutput +="<td class=\"noptotal\"><input type=\"checkbox\" id=\"sf-no-vat\" onclick='ChangeExemptFlag( this.checked );' checked/>" + strTAX + " exempt</td>";    // display tax exempt
                }
                else
                {
                    strOutput +="<td class=\"noptotal\"><input type=\"checkbox\" id=\"sf-no-vat\" onclick='ChangeExemptFlag( this.checked );' />" + strTAX + " exempt</td>";
                }
            
            }
            strOutput += "</tr>";
         }
      }
      if (isNaN(fTotal))
        {
        fTotal = 0;
        }
      if (isNaN(fShipping))
        {
        fShipping = 0;
        }
      if (isNaN(fTax))
        {
        fTax = 0;
        }
      if ( !TaxByRegion ) {
         strOutput += "<tr><td class=\"noptotal\" colspan=2><strong>"+strTOT+"</strong></td>";	//total - position was colspan=4
         strOutput += "<td class=\"noptotal\" colspan=2><strong>" + MonetarySymbol + moneyFormat((fTotal + fShipping + fTax)) + "</strong></td>";
         strOutput += "</tr>";
      }
      strOutput += "</TABLE>";

      if ( HiddenFieldsToCheckout ) {
         strOutput += "<input type=hidden name=\""+OutputOrderSubtotal+"\" value=\""+ MonetarySymbol + strTotal + "\">";
         strOutput += "<input type=hidden name=\""+OutputOrderShipping+"\" value=\""+ MonetarySymbol + strShipping + "\">";
         strOutput += "<input type=hidden name=\""+OutputOrderTax+"\"      value=\""+ MonetarySymbol + strTax + "\">";
         strOutput += "<input type=hidden name=\""+OutputOrderTotal+"\"    value=\""+ MonetarySymbol + moneyFormat((fTotal + fShipping + fTax)) + "\">";
      }
   }
   g_TotalCost = (fTotal + fShipping + fTax);
   g_TotalNett = (fTotal);

   document.write(strOutput);
   document.close();
}

//---------------------------------------------------------------------||
// FUNCTION:    SmallCart                                             ||
// PARAMETERS:  Null                                                   ||
// RETURNS:     Product Table Written to Document                      ||
// PURPOSE:     Draws current cart product table on HTML page          ||
//---------------------------------------------------------------------||
function SmallCart( ) {
   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 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 userZone		= GetCookie("zone");    //Zone
	 if ( userZone == null ) userZone = 0;

	 var userShipping		= GetCookie("shipping");    //Shipping type
	 if ( userShipping == null ) userShipping = 0;

   iNumberOrdered = GetCookie("NumberOrdered");
   if ( iNumberOrdered == null )
      iNumberOrdered = 0;

   if ( bDisplay )
      strOutput = "<TABLE class=\"nopcart\"><tr>" +
                  //Remove cart ID title		"<td class=\"nopheader\"><strong>"+strILabel+"</strong></td>" +
                  "<td class=\"nopheader\"><strong>"+strDLabel+"</strong></td>" +
                  "<td class=\"nopheader\"><strong>"+strQLabel+"</strong></td>" +
                  "<td class=\"nopheader\"><strong>"+strPLabel+"</strong></td>" +
                  (DisplayShippingColumn?"<td class=\"nopheader\"><strong>"+strSLabel+"</strong></td>":"") +
                  "<td class=\"nopheader\"><strong>"+strRLabel+" </strong></td></tr>";

   if ( iNumberOrdered == 0 ) {
      strOutput += "<tr><td colspan=6 class=\"nopentry\"><right><br /><strong>" + EmptyCartPrompt + "</strong><br /><br /></CENTER></td></tr>";
   }

   for ( i = 1; i <= iNumberOrdered; i++ ) {
      NewOrder = "Order." + i;
      database = "";
      database = GetCookie(NewOrder);

      Token0 = database.indexOf("|", 0);
      Token1 = database.indexOf("|", Token0+1);
      Token2 = database.indexOf("|", Token1+1);
      Token3 = database.indexOf("|", Token2+1);
      Token4 = database.indexOf("|", Token3+1);

      fields = new Array;
      fields[0] = database.substring( 0, Token0 );                 // Product ID
      fields[1] = database.substring( Token0+1, Token1 );          // Quantity
      fields[2] = database.substring( Token1+1, Token2 );          // Price
      fields[3] = database.substring( Token2+1, Token3 );          // Product Name/Description
      fields[4] = CalculateShipping( GetProduct( fields[0] ), userZone );   //fields[4] = database.substring( Token3+1, Token4 );          // Shipping Cost
      fields[5] = database.substring( Token4+1, database.length ); //Additional Information
	
      fTotal     += (parseInt(fields[1]) * parseFloat(fields[2]) );
      fShipping  += (parseInt(fields[1]) * parseFloat(fields[4]) );
      fTax			 += parseInt(fields[1]) * CalculateTax( GetProduct( fields[0] ), userZone ); //fTax        = (fTotal * TaxRate);
      strTotal    = moneyFormat(fTotal);
      strTax      = moneyFormat(fTax);
      strShipping = moneyFormat(fShipping);

//ADS
      slink = new String(fields[3]);
      slink = slink.replace( / /g, "_" );

      
      if ( bDisplay ) {
  //remove link       strOutput += "<tr><td class=\"nopentry\"><a href='" + fields[0] + ".htm'>"  + fields[0] + "</a></td>";

         if ( fields[5] == "" )
            //strOutput += "<td class=\"noclpentry\">"  + fields[3] + "</td>";
	    strOutput += "<td class=\"nopentry\"><a href='" + slink + ".htm'>"  + fields[3] + "</td>";
         else
            strOutput += "<td class=\"nopentry\">"  + fields[3] + " - <i>"+ fields[5] + "</i></td>";

         strOutput += "<td class=\"nopentry\"><input type=TEXT NAME=Q SIZE=2 VALUE=\"" + fields[1] + "\" onChange=\"ChangeQuantity("+i+", this.value);\"></td>";
         strOutput += "<td align=left class=\"nopentry\">"+ MonetarySymbol + moneyFormat(fields[2]) + "/ea</td>";

         if ( DisplayShippingColumn ) {
            if ( parseFloat(fields[4]) > 0 ){
               strOutput += "<td class=\"nopentry\">"+ MonetarySymbol + moneyFormat(fields[4]) + "/ea</td>";
            }else
               strOutput += "<td class=\"nopentry\">N/A</td>";
         }

         strOutput += "<td class=\"nopentry\" ALIGN=left><input type=button value=\" "+strRButton+" \" onClick=\"RemoveFromCart("+i+")\" class=\"nopbutton\"></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=\"" + OutputItemAddtlInfo + strFooter + "\" value=\"" + fields[5] + "\">";
      }

   }

   if ( bDisplay ) {
      strOutput += "<tr><td class=\"noptotal\" colspan=2><strong>"+strSUB+"</strong></td>";	// Subtotal title position was colspan=4 
      strOutput += "<td class=\"noptotal\" colspan=2><strong>" + MonetarySymbol + strTotal + "</strong></td>";	//Subtotal price
      strOutput += "</tr>";

      //--- Calculate the actual shipping
      //ShowAlert( fTotal + " : " + fShipping + " : " + userZone );
      fShipping     = calculateTotalShipping(fTotal,fShipping,userZone);
      strShipping   = moneyFormat(fShipping);
      
      if ( DisplayShippingRow ) {
         strOutput += "<tr><td class=\"noptotal\" colspan=2><strong>"+strSHIP+"</strong></td>";	// shipping title position was colspan=2
         strOutput += "<td class=\"noptotal\"><strong>" + MonetarySymbol + strShipping + "</strong></td>"; //shipping total price
		 strOutput += "<td class=\"noptotal\" colspan=2>" + displayZone(userZone) + "</td>";	//shipping zone box
		 strOutput += "<td class=\"noptotal\"></td>";
         strOutput += "</tr>";
      }

      if ( DisplayTaxRow || TaxByRegion ) {
         if ( TaxByRegion ) {
            strOutput += "<tr><td class=\"noptotal\" colspan=2><strong>"+strTAX+"</strong></td>"; // display tax position was 4
            strOutput += "<td class=\"noptotal\" colspan=2><strong>";
            strOutput += "<input type=radio name=\""+OutputOrderTax+"\" value=\"" + strTax + "\">";
            strOutput += TaxablePrompt + ": " + MonetarySymbol + strTax;
            strOutput += "<br /><input type=radio name=\""+OutputOrderTax+"\" value=\"0.00\">";
            strOutput += NonTaxablePrompt + ": " + MonetarySymbol + "0.00";
            strOutput += "</strong></td>";
            strOutput += "</tr>";
         } else {
            strOutput += "<tr><td class=\"noptotal\" colspan=2><strong>"+strTAX+"</strong></td>"; // display tax position was 4
            strOutput += "<td class=\"noptotal\" colspan=2><strong>" + MonetarySymbol + strTax + "</strong></td>";
            strOutput += "</tr>";
         }
      }

      if ( !TaxByRegion ) {
         strOutput += "<tr><td class=\"noptotal\" colspan=2><strong>"+strTOT+"</strong></td>";	//total - position was colspan=4
         strOutput += "<td class=\"noptotal\" colspan=2><strong>" + MonetarySymbol + moneyFormat((fTotal + fShipping + fTax)) + "</strong></td>";
         strOutput += "</tr>";
      }
      strOutput += "</TABLE>";

      if ( HiddenFieldsToCheckout ) {
         strOutput += "<input type=hidden name=\""+OutputOrderSubtotal+"\" value=\""+ MonetarySymbol + strTotal + "\">";
         strOutput += "<input type=hidden name=\""+OutputOrderShipping+"\" value=\""+ MonetarySymbol + strShipping + "\">";
         strOutput += "<input type=hidden name=\""+OutputOrderTax+"\"      value=\""+ MonetarySymbol + strTax + "\">";
         strOutput += "<input type=hidden name=\""+OutputOrderTotal+"\"    value=\""+ MonetarySymbol + 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;
var g_TotalNett = 0;
function ValidateCart( theForm ) {
   if ( TaxByRegion ) {
      if ( !RadioChecked(eval("theForm."+OutputOrderTax)) ) {
         ShowAlert( TaxPrompt , "red");
         return false;
      }
   }
   
   if ( g_TotalCost == 0) {
        ShowAlert( EmptyCartPrompt , "red");
        return false;
       }
   iNumberOrdered = GetCookie("NumberOrdered");
   if ( iNumberOrdered == null )
      iNumberOrdered = 0;
   if ( iNumberOrdered == 0) {
	ShowAlert( EmptyCartPrompt , "red");
        return false;
       }

   if ( MinimumOrder >= 0.01 ) {
      if ( g_TotalNett < MinimumOrder ) {
         ShowAlert( MinimumOrderPrompt , "red");
         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 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
   var taxexempt      = GetCookie("exempt");    //TaxExempt
   if ( taxexempt == null ) taxexempt = "false";
   

	 var userZone		= GetCookie("zone");    //Zone
	 if ( userZone == null ) userZone = 0;

	 var userShipping		= GetCookie("shipping");    //Shipping type
	 if ( userShipping == null ) userShipping = 0;

   iNumberOrdered = GetCookie("NumberOrdered");
   if ( iNumberOrdered == null )
      iNumberOrdered = 0;

   if ( TaxByRegion ) {
      QueryString_Parse();
      fTax = parseFloat( QueryString( OutputOrderTax ) );
      strTax = moneyFormat(fTax);
   }

   if ( bDisplay )
      strOutput = "<TABLE class=\"nopcart\"><tr>" +
                  //remove checkout ID			"<td class=\"nopheader\"><strong>"+strILabel+"</strong></td>" +
                  "<td class=\"nopheader\"><strong>"+strDLabel+"</strong></td>" +
                  "<td class=\"nopheader\"><strong>"+strQLabel+"</strong></td>" +
                  "<td class=\"nopheader\"><strong>"+strPLabel+"</strong></td>" +
                  (DisplayShippingColumn?"<td class=\"nopheader\"><strong>"+strSLabel+"</strong></td>":"") +
                  "</tr>";
                  
   //Get the Total number of Products Ordered and Basket weight
   for ( i = 1; i <= iNumberOrdered; i++ ) {
      NewOrder = "Order." + i;
      database = "";
      database = GetCookie(NewOrder);

      Token0 = database.indexOf("|", 0);
      Token1 = database.indexOf("|", Token0+1);
      Token2 = database.indexOf("|", Token1+1);
      Token3 = database.indexOf("|", Token2+1);
      Token4 = database.indexOf("|", Token3+1);

      fields = new Array;
      fields[0] = database.substring( 0, Token0 );                 // Product ID
      fields[1] = database.substring( Token0+1, Token1 );          // Quantity
      fields[2] = database.substring( Token1+1, Token2 );          // Price
      fields[3] = database.substring( Token2+1, Token3 );          // Product Name/Description
      gNumOrdered   +=  Number(fields[1]);
      gTotalWeight += Number( fields[1] * GetProductWeight( fields[0] ));
      }

   for ( i = 1; i <= iNumberOrdered; i++ ) {
      NewOrder = "Order." + i;
      database = "";
      database = GetCookie(NewOrder);

      Token0 = database.indexOf("|", 0);
      Token1 = database.indexOf("|", Token0+1);
      Token2 = database.indexOf("|", Token1+1);
      Token3 = database.indexOf("|", Token2+1);
      Token4 = database.indexOf("|", Token3+1);

      fields = new Array;
      fields[0] = database.substring( 0, Token0 );                 // Product ID
      fields[1] = database.substring( Token0+1, Token1 );          // Quantity
      fields[2] = database.substring( Token1+1, Token2 );          // Price
      fields[3] = database.substring( Token2+1, Token3 );          // Product Name/Description
	  fields[4] = CalculateShipping( GetProduct( fields[0] ), userZone );   //fields[4] = database.substring( Token3+1, Token4 );          // Shipping Cost
      fields[5] = database.substring( Token4+1, database.length ); //Additional Information

      fTotal     += (parseInt(fields[1]) * parseFloat(fields[2]) );
      fShipping  += (parseInt(fields[1]) * parseFloat(fields[4]) );
      if (taxexempt != "true")
      {
      fTax		 += parseInt(fields[1]) * CalculateTax( GetProduct( fields[0] ), userZone, fields[2] );
      }
      strTotal    = moneyFormat(fTotal);
      strShipping = moneyFormat(fShipping);
	  strTax    = moneyFormat(fTax);

      if ( bDisplay ) {
         //remove checkout ID		strOutput += "<tr><td class=\"nopentry\">"  + fields[0] + "</td>";

         if ( fields[5] == "" )
            strOutput += "<td class=\"nopentry\">"  + fields[3] + "</td>";
         else
            strOutput += "<td class=\"nopentry\">"  + fields[3] + " - <i>"+ fields[5] + "</i></td>";

         strOutput += "<td class=\"nopentry\">" + fields[1] + "</td>";
         strOutput += "<td class=\"nopentry\">"+ MonetarySymbol + moneyFormat(fields[2]) + "/ea</td>";

         if ( DisplayShippingColumn ) {
            if ( parseFloat(fields[4]) > 0 ){
               strOutput += "<td class=\"nopentry\">"+ MonetarySymbol + moneyFormat(fields[4]) + "/ea</td>";
            }else
               strOutput += "<td class=\"nopentry\">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[5] != "" )
            strPP += " - " + fields[5];
         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=\"" + OutputItemAddtlInfo + strFooter + "\" value=\"" + fields[5] + "\">";
      } 

   }

   if ( bDisplay ) {
   
      //--- Calculate the actual shipping and display checkout page
      fShipping     = calculateTotalShipping(fTotal,fShipping,userZone);
      strShipping   = moneyFormat(fShipping);
      
      fTax += CalculateShippingTax(fShipping, userZone);
      strTax    = moneyFormat(fTax);
   
      strOutput += "<tr><td class=\"noptotal\" colspan=2><strong>"+strSUB+"</strong></td>";  //Subtotal title edit colspan for position was 3
      strOutput += "<td class=\"noptotal\" colspan=2 ALIGN=RIGHT><strong>" + MonetarySymbol + strTotal + "</strong></td>";	//Subtotal price
      strOutput += "</tr>";

      strOutput += "<tr><td class=\"noptotal\" colspan=2><strong>"+strSHIP+"</strong></td>";  //Shipping title edit colspan for position was 3
      strOutput += "<td class=\"noptotal\" colspan=2 ALIGN=RIGHT><strong>" + MonetarySymbol + strShipping + "</strong></td>";		//Shipping price
      strOutput += "</tr>";
      //displays tax in checkout screen
      if ( DisplayTaxRow )
      {
        strOutput += "<tr><td class=\"noptotal\" colspan=2><strong>"+strTAX+"</strong></td>";  //Tax Title edit colspan for position was 3
        strOutput += "<td class=\"noptotal\" colspan=2 ALIGN=RIGHT><strong>" + MonetarySymbol + strTax + "</strong></td>";	//Tax price
	    strOutput += "</tr>";
      }
      strOutput += "<tr><td class=\"noptotal\" colspan=2><strong>"+strTOT+"</strong></td>";  //Total Title edit colspan for position was 3
      strOutput += "<td class=\"noptotal\" colspan=2 ALIGN=RIGHT><strong>" + MonetarySymbol + moneyFormat((fTotal + fShipping + fTax)) + "</strong></td>";		//Total price
      strOutput += "</tr>";

      strOutput += "</TABLE>";

      strOutput += "<input type=hidden name=\"x_zone\" value=\"" + userZone + "\">";
      strOutput += "<input type=hidden name=\"x_shippingmethod\" value=\"" + userShipping + "\">";
			
			
      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=\""+ MonetarySymbol + strTax + "\">";
         strOutput += "<input type=hidden name=\"subtotal\" value=\""+ MonetarySymbol + strTotal + "\">";
         strOutput += "<input type=hidden name=\"shipping\" value=\""+ MonetarySymbol + 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:    ChangeShipping                                         ||
// PARAMETERS:  shipping                                               ||
// RETURNS:     nothing                                                ||
// PURPOSE:     Updates the cookie                                     ||
//---------------------------------------------------------------------||
function ChangeShipping( newShipping ) {
	DeleteCookie( "shipping", "/" );
	SetCookie( "shipping", newShipping, null, "/" );
	location.href=location.href;
}

//---------------------------------------------------------------------||
// FUNCTION:    ChangeZone                                             ||
// PARAMETERS:  zone                                                   ||
// RETURNS:     nothing                                                ||
// PURPOSE:     Updates the cookie                                     ||
//---------------------------------------------------------------------||
function ChangeZone( newZone ) {
	DeleteCookie( "zone", "/" );
	SetCookie( "zone", newZone, null, "/" );
	location.href=location.href;
}

//---------------------------------------------------------------------||
// FUNCTION:    ChangeExempt                                           ||
// PARAMETERS:  zone                                                   ||
// RETURNS:     nothing                                                ||
// PURPOSE:     Updates the cookie                                     ||
//---------------------------------------------------------------------||
function ChangeExemptFlag( Exempt ) {
	DeleteCookie( "exempt", "/" );
	SetCookie( "exempt", Exempt, null, "/" );
	location.href=location.href;
}

//---------------------------------------------------------------------|| 
// FUNCTION: Print_total                                               || 
// PARAMETERS: true/false if you want MonetarySymbol added to string   || 
// RETURNS: Total cost currently racked up by shopper                  || 
// PURPOSE: Aesthetics                                                 || 
//---------------------------------------------------------------------|| 
function Print_total(bSymbol) { 
var strOutput = ""; //String to be written to page 
var strTotal = ""; //Total cost formatted as money 
var fTotal = 0; 
var iNumberOrdered = 0; //Number of products ordered 


iNumberOrdered = GetCookie("NumberOrdered"); 
if ( iNumberOrdered == null ) 
iNumberOrdered = 0; 


for ( i = 1; i <= iNumberOrdered; i++ ) { 

NewOrder = "Order." + i; 
database = ""; 
database = GetCookie(NewOrder); 

Token0 = database.indexOf("|", 0); 
Token1 = database.indexOf("|", Token0+1); 
Token2 = database.indexOf("|", Token1+1); 
Token3 = database.indexOf("|", Token2+1); 
Token4 = database.indexOf("|", Token3+1); 

fields = new Array; 
fields[0] = database.substring( 0, Token0 ); // Product ID 
fields[1] = database.substring( Token0+1, Token1 ); // Quantity 
fields[2] = database.substring( Token1+1, Token2 ); // Price 
fields[3] = database.substring( Token2+1, Token3 ); // Product Name/Description 
fields[4] = database.substring( Token3+1, Token4 ); // Weight 
fields[5] = database.substring( Token4+1, database.length ); //Additional Information 

fTotal += (parseInt(fields[1]) * parseFloat(fields[2]) ); 

} 

strTotal = moneyFormat(fTotal); 
strOutput+=strTotal; 
if ( bSymbol ) 
   strOutput = MonetarySymbol + strOutput 
document.write(strOutput); 

} 

//---------------------------------------------------------------------|| 
// FUNCTION: Print_total_products                                      || 
// PARAMETERS: true/false if you want "item(s)" added to string        || 
// RETURNS: Total cost currently racked up by shopper                  || 
// PURPOSE: Aesthetics                                                 || 
//---------------------------------------------------------------------|| 
function Print_total_products(bVerbose) { 
var strOutput = ""; //String to be written to page 
var fTotal = 0; 
var iNumberOrdered = 0; //Number of products ordered 


iNumberOrdered = GetCookie("NumberOrdered"); 
if ( iNumberOrdered == null ) 
iNumberOrdered = 0; 


for ( i = 1; i <= iNumberOrdered; i++ ) { 

NewOrder = "Order." + i; 
database = ""; 
database = GetCookie(NewOrder); 

Token0 = database.indexOf("|", 0); 
Token1 = database.indexOf("|", Token0+1); 
Token2 = database.indexOf("|", Token1+1); 
Token3 = database.indexOf("|", Token2+1); 
Token4 = database.indexOf("|", Token3+1); 

fields = new Array; 
fields[0] = database.substring( 0, Token0 ); // Product ID 
fields[1] = database.substring( Token0+1, Token1 ); // Quantity 
fields[2] = database.substring( Token1+1, Token2 ); // Price 
fields[3] = database.substring( Token2+1, Token3 ); // Product Name/Description 
fields[4] = database.substring( Token3+1, Token4 ); // Weight 
fields[5] = database.substring( Token4+1, database.length ); //Additional Information 

fTotal += (parseInt(fields[1])); 

} 

strOutput+=fTotal; 
if ( bVerbose ) { 
   if (fTotal == 1) { 
      strOutput+=" item" 
   } 
   else { 
      strOutput+=" items" 
   } 
} 
document.write(strOutput); 

} 

//---------------------------------------------------------------------|| 
// FUNCTION: Cart_is_empty                                             || 
// PARAMETERS: none                                                    || 
// RETURNS: Total true if cart is empty, false otherwise               || 
// PURPOSE: Aesthetics                                                 || 
//---------------------------------------------------------------------|| 
function Cart_is_empty( ) { 
   iNumInCart = GetCookie("NumberOrdered"); 
                
   if ( iNumInCart == null ) iNumInCart = 0; 

   if ( iNumInCart == 0 ) return true; 
    
   return false; 

}

//------------------------------------------------
//  FUNCTION:	ShowAlert
//  PARAMETERS:	None
//  RETURNS: 	Nothing
//  PURPOSE:    Show SF4-Alert DIV
//------------------------------------------------
//Use
//<INPUT TYPE="button" VALUE="Show" 
//onClick=ShowDiv();>
//Theme must contain the class sf4-alert

function ShowAlert(sMessage, lShowRed ) {
	var AlertMessage = document.getElementById("basketmessage");
	if (AlertMessage != null)
	{
	AlertMessage.innerHTML = sMessage;
	
	if (typeof lShowRed == 'undefined')
	{
	AlertMessage.style.color = RGBtoHex ( 0 , 0 , 0 )
	}
	else
	{
	AlertMessage.style.color = RGBtoHex ( 255 , 0 , 0 )
	}
	}
	//Verticle
	var ScrollPosition = getScrollingPosition();
	var location = ScrollPosition[1] + 230;
	var position = String(location) + "px";
	//Horizontal
	var WindowSize = getViewportSize();
	var horizontal = WindowSize[0];
	var hposition = (horizontal / 2) + ScrollPosition[0];
	var hlocation = String(hposition) + "px";
	var popup = document.getElementById("message-container");
	if (popup == null)
	{
	alert(sMessage);
	}
	else
	{
	popup.style.top=position;
	popup.style.left=hlocation;
	}
}

//------------------------------------------------
//  FUNCTION:	HideAlert
//  PARAMETERS:	None
//  RETURNS: 	Nothing
//  PURPOSE:    Hides SF4-Alert DIV
//------------------------------------------------

function HideAlert() {
	document.getElementById("message-container").style.top="-230px";
	if ( holdjump ) 
        {
	    var webpage = location.href.lastIndexOf("/");
	    var cartpage = location.href.substring(0,webpage)+"/cart.htm";
	    window.location.href= cartpage; 
	}
	else 
	{   
	        if ( ReloadPage )
	        {
        		var webpage = location.href;
		        window.location.href= webpage;
	        }
	}
	holdjump = false;
	return false;		
}

//------------------------------------------------
//  FUNCTION:	getScrollingPosition
//  PARAMETERS:	None
//  RETURNS: 	Array
//  PURPOSE:    Get the scoll position of the page
//------------------------------------------------

function getScrollingPosition()
{
  var position = [0, 0];

  if (typeof window.pageYOffset != 'undefined')
  {
    position = [
        window.pageXOffset,
        window.pageYOffset
    ];
  }

  else if (typeof document.documentElement.scrollTop != 'undefined'
      && (document.documentElement.scrollTop > 0 ||
      document.documentElement.scrollLeft > 0))
  {
    position = [
        document.documentElement.scrollLeft,
        document.documentElement.scrollTop
    ];
  }

  else if (typeof document.body.scrollTop != 'undefined')
  {
    position = [
        document.body.scrollLeft,
        document.body.scrollTop
    ];
  }

  return position;
}
 
//------------------------------------------------
//  FUNCTION:	getViewportSize
//  PARAMETERS:	None
//  RETURNS: 	Array
//  PURPOSE:    Get the window size position of the page
//------------------------------------------------   
    
function getViewportSize()
{
  var size = [0, 0];

  if (typeof window.innerWidth != 'undefined')
  {
    size = [
        window.innerWidth,
        window.innerHeight
    ];
  }
  else if (typeof document.documentElement != 'undefined'
      && typeof document.documentElement.clientWidth != 'undefined'
      && document.documentElement.clientWidth != 0)
  {
    size = [
        document.documentElement.clientWidth,
        document.documentElement.clientHeight
    ];
  }
  else
  {
    size = [
        document.getElementsByTagName('body')[0].clientWidth,
        document.getElementsByTagName('body')[0].clientHeight
    ];
  }

  return size;
}

function ChangeExempt()
{
    var exemptbox = document.getElementById("sf-no-vat");
    if (exemptbox != null)
    {
    Taxexempt =  exemptbox.checked;
    }
    
}

function submitbutton( theForm ){
	var userZone		= GetCookie("zone");
	if (ValidateCart(theForm) == false){
	return false;
	}
	if ( userZone == null ){
	            notice = "From the drop down menu please select Delivery"
                ShowAlert( notice, "red");
			return false;
		}else if ( userZone == 0 ){
	            notice = "From the drop down menu please select Delivery"
                ShowAlert( notice, "red");
			return false;
		}else{
			theForm.action='checkout.htm';theForm.submit();
		}	
	}

//------------------------------------------------
//  FUNCTION:	RGBtoHex
//  PARAMETERS:	red, green, blue
//  RETURNS: 	HTML Value
//  PURPOSE:    converts RGB onto HTML
//------------------------------------------------ 
function RGBtoHex(R,G,B) {return "#"+toHex(R)+toHex(G)+toHex(B)}
function toHex(N) {
 if (N==null) return "00";
 N=parseInt(N); if (N==0 || isNaN(N)) return "00";
 N=Math.max(0,N); N=Math.min(N,255); N=Math.round(N);
 return "0123456789ABCDEF".charAt((N-N%16)/16)
      + "0123456789ABCDEF".charAt(N%16);
}

function searchBox( theForm ){
		if ( theForm.search.value.length == 0 ){
			return false;
		}else{
            
			document.cookie = "sf4=" + escape(theForm.search.value)
            if (searchon == "true") { aValue="searchall.htm";
            theForm.setAttribute("action",aValue);
			return true;}
          else {
             return true;}
		}
        
	}
		function changeAction(aForm,aValue)
                                {
                                                searchon = "false";
                                                if(aValue=="")
                                                                return;
                                                aForm.setAttribute("action",aValue);
                                                
                                }
function gotocart()
        	{
		    var webpage = location.href.lastIndexOf("/");
		    var cartpage = location.href.substring(0,webpage)+"/cart.htm";
		    window.location.href= cartpage; 
		}

function initialize() {
  var testFrame =
        document.createElement("IFRAME");
  testFrame.id = "testFrame";
  testFrame.src = "http://www.pennineltd.co.uk/commercialmaintenance/tree/sample1.html";
  document.write(testFrame);
}
function goImgWin(myImage,myWidth,myHeight,origLeft,origTop) {
myHeight += 24;
myWidth += 24;
TheImgWin = window.open(myImage,'image','height=' +
myHeight + ',width=' + myWidth +
',toolbar=no,directories=no,status=no,' +
'menubar=no,scrollbars=no,resizable=no');
TheImgWin.resizeTo(myWidth+2,myHeight+30);
TheImgWin.moveTo(origLeft,origTop);
TheImgWin.focus();
}
