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

// DC: moved globals to nopcart-init.js

//=====================================================================||
//---------------------------------------------------------------------||
//    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";
   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 ( thisForm.ID_NUM == null )
      strID_NUM    = "";
   else
      strID_NUM    = thisForm.ID_NUM.value;

   if ( thisForm.QUANTITY == null )
      strQUANTITY  = "1";
   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.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;
   }

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

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

      if ( fields[0] == strID_NUM &&
           fields[2] == strPRICE  &&
           fields[3] == strNAME   &&
           fields[5] == strADDTLINFO
         ) {
         bAlreadyInCart = true;
         dbUpdatedOrder = strID_NUM    + "|" +
                          (parseInt(strQUANTITY)+parseInt(fields[1]))  + "|" +
                          strPRICE     + "|" +
                          strNAME      + "|" +
                          strSHIPPING  + "|" +
                          strADDTLINFO;
         strNewOrder = "Order." + i;
         DeleteCookie(strNewOrder, "/");
         SetCookie(strNewOrder, dbUpdatedOrder, null, "/");
         notice = strQUANTITY + " x \"" + strNAME + "\"" + strAdded;
         break;
      }
   }


   if ( !bAlreadyInCart ) {
      iNumberOrdered++;

      if ( iNumberOrdered > 12 )
         alert( strSorry );
      else {
         dbUpdatedOrder = strID_NUM    + "|" +
                          strQUANTITY  + "|" +
                          strPRICE     + "|" +
                          strNAME      + "|" +
                          strSHIPPING  + "|" +
                          strADDTLINFO;

         strNewOrder = "Order." + iNumberOrdered;
         SetCookie(strNewOrder, dbUpdatedOrder, null, "/");
         SetCookie("NumberOrdered", iNumberOrdered, null, "/");
         notice = strQUANTITY + " x \"" + strNAME + "\"" + strAdded;
      }
   }

   if ( DisplayNotice )
      alert(notice);
}

// DC: moved getCookieVal() to nopcart-init.js


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

// DC: moved GetCookie() to nopcart-init.js


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

// DC: moved moneyFormat() to nopcart-init.js


//---------------------------------------------------------------------||
// 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 = GetLocationHref(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) ) {
      alert( strErrQty );
   } 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 = GetLocationHref(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;
      }
   }
}

// DC: moved ManageCart() to nopcart-init.js

//---------------------------------------------------------------------||
// FUNCTION:    ValidateCart                                           ||
// PARAMETERS:  Form to validate                                       ||
// RETURNS:     true/false                                             ||
// PURPOSE:     Validates the managecart form                          ||
//---------------------------------------------------------------------||
//var g_TotalCost = 0; // DC: needed to remove when split to nopcart-init.js
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;
      }
   }

   var vPostcode = document.getElementsByName("postcode")[0].value;
   vPostcode = vPostcode.replace(/\s+/, '')
   if (vPostcode.length < 4 || isNaN(vPostcode)) {
     setDeliveryMethod(vPostcode, true);
     return false;
   }

   theForm.submit();

   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 fTotalShipping = 0;    //Total cost of order for shipping calc (some items might be excluded)
   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

   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>" +
                  (DisplayIdColumn?"<TD CLASS=\"nopheader\"><B>"+strILabel+"</B></TD>":"") +
                  "<TD CLASS=\"nopheader\"><B>"+strDLabel+"</B></TD>" +
                  "<TD CLASS=\"nopheader\"><B>"+strQLabel+"</B></TD>" +
                  "<TD CLASS=\"nopheader\"><B>"+strPLabel+"</B></TD>" +
                  (DisplayShippingColumn?"<TD CLASS=\"nopheader\"><B>"+strSLabel+"</B></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] = database.substring( Token3+1, Token4 );          // Shipping Cost
      fields[5] = database.substring( Token4+1, database.length ); //Additional Information

      fTotal     += (parseInt(fields[1]) * parseFloat(fields[2]) );
      if ((fields[0] != "hilly-lie-clinic") &&
          (fields[0] != "hilly-lie-clinic-group")) {
        fTotalShipping += (parseInt(fields[1]) * parseFloat(fields[2]) );
      }
      if ( GetCookie("DeliveryMethod") == "remote" ) {
        fShipping = fTotalShipping * ShippingRate;
      }
      else { fShipping = 0; }
      if ( !TaxByRegion ) fTax = ((fTotal + fShipping) * TaxRate);
      strTotal    = moneyFormat(fTotal);
      if ( !TaxByRegion ) strTax = moneyFormat(fTax);
      strShipping = moneyFormat(fShipping);

      if ( bDisplay ) {
         if ( DisplayIdColumn ) {
           strOutput += "<TR><TD CLASS=\"nopentry\"><DIV>"  + fields[0] + "</DIV></TD>";
         }

         if ( fields[5] == "" )
            strOutput += "<TD CLASS=\"nopentry\"><DIV>"  + fields[3] + "</DIV></TD>";
         else
            strOutput += "<TD CLASS=\"nopentry\"><DIV>"  + fields[3] + " - <I>"+ fields[5] + "</I></DIV></TD>";

         strOutput += "<TD CLASS=\"nopentry\"><DIV>" + fields[1] + "</DIV></TD>";
         strOutput += "<TD CLASS=\"nopentry\"><DIV>"+ MonetarySymbol + moneyFormat(fields[2]) + " each</DIV></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.
        if ( PaymentProcessor == 'do' ) {
          strOutput += "<input type=\"hidden\" name=\"" + fields[3] + "\" value=\"" + fields[1] + "," + fields[2] + "\">";
        } else {
         //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 ) {
      strOutput += "<TR><TD CLASS=\"noptotal\" COLSPAN=3><B>"+strSUB+"</B></TD>";
      strOutput += "<TD CLASS=\"noptotal\" COLSPAN=2 ALIGN=RIGHT><B>" + MonetarySymbol + strTotal + "</B></TD>";
      strOutput += "</TR>";

      if ( DisplayShippingRow ) {
         strOutput += "<TR><TD CLASS=\"noptotal\" COLSPAN=3><B>"+strSHIP+"</B></TD>";
         strOutput += "<TD CLASS=\"noptotal\" COLSPAN=2 ALIGN=RIGHT><B>" + MonetarySymbol + strShipping + "</B></TD>";
         strOutput += "</TR>";
      }

      if ( DisplayTaxRow || TaxByRegion ) {
         strOutput += "<TR><TD CLASS=\"noptotal\" COLSPAN=3><B>"+strTAX+"</B></TD>";
         strOutput += "<TD CLASS=\"noptotal\" COLSPAN=2 ALIGN=RIGHT><B>" + MonetarySymbol + strTax + "</B></TD>";
         strOutput += "</TR>";
      }

      strOutput += "<TR><TD CLASS=\"noptotal\" COLSPAN=3><B>"+strTOT+"</B></TD>";
      strOutput += "<TD CLASS=\"noptotal\" COLSPAN=2 ALIGN=RIGHT><B>" + MonetarySymbol + moneyFormat((fTotal + fShipping + fTax)) + "</B></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=\""+ 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 if ( PaymentProcessor == 'do') {
         // directone.com.au and webadvantage.com.au
         strOutput += "<input type=\"hidden\" name=\"vendor_name\" value=\"VAR0021\">";
         strOutput += "<input type=\"hidden\" name=\"information_fields\" value=\"Name, Address, postcode, Phone, Comments, Newsletter\">";
//FIXME
         if (fShipping > 0) {
           strOutput += "<input type=\"hidden\" name=\"Remote Area Delivery Surcharge\" value=\"" + strShipping + "\">";
         }
         strOutput += "<input type=\"hidden\" name=\"gst_rate\" value=\"10\">";
         strOutput += "<input type=\"hidden\" name=\"return_link_url\" value=\"http://www.varietee.com.au/store-thankyou.html\">";
         strOutput += "<input type=\"hidden\" name=\"payment_alert\" value=\"xleyb7@fastmail.fm,admin@varietee.com.au,sales@varietee.com.au,cam.crossley@gmail.com\">";
      } else {
         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)) + "\">";
      }
   }

   document.write(strOutput);
   document.close();
}

//=====================================================================||
//               END NOP Design SmartPost Shopping Cart                ||
//=====================================================================||

function GetLocationHref(href) {
  // Remove trailing characters after "#"
  var re = /^(.+)#.*$/;
  return href.replace(re, "$1");
}

function UpdateCart() {
  location.href = GetLocationHref(location.href);
}

function ClearCart(){
   var iNumberOrdered = GetCookie("NumberOrdered");
   if ( iNumberOrdered != null ){
     for ( i = 1; i <= iNumberOrdered; i++ ) {
       NewOrder = "Order." + i;
       DeleteCookie(NewOrder, "/");
     }
   }
   DeleteCookie("NumberOrdered", "/");
//   DeleteCookie("Postcode", "/");
//   DeleteCookie("DeliveryMethod", "/");
   UpdateCart();
}

function getRadioValue(radioGroup) {
  radios = document.getElementsByName(radioGroup);
  for (i = 0; i < radios.length; i++) {
    if (radios[i].checked) return radios[i].value;
  }
}

function HandleSubmit(e) {
 CancelSubmit(e);
 var vPostcode = document.getElementsByName("postcode")[0].value;
 setDeliveryMethod(vPostcode, true);
 return false;
}

function setDeliveryMethod(postcode, showAlert) {
 var cPostcode = GetCookie("Postcode");
 var fPostcode = document.getElementsByName("postcode")[0];
 var vPostcode = fPostcode.value;
 var cDeliveryMethod = GetCookie("DeliveryMethod");
 var fDeliveryMethod;
 var text = document.getElementsByTagName("span");
 for (i = 0; i < text.length; i++) {
  if (text[i].getAttribute("id") == "deliveryMethod") {
   fDeliveryMethod = text[i];
  }
 }
 var tDeliveryMethod = "Free for this Postcode";
if (debug) { alert("start cPostcode=" + cPostcode +" vPostcode=" + vPostcode + " postcode=" + postcode + " cDeliveryMethod=" + cDeliveryMethod); }
 if (postcode == null || postcode == "") {
  if (cPostcode != null) {
if (debug) { alert("null postcode, using cookie"); }
   fPostcode.value = cPostcode;
   if (cDeliveryMethod == "remote") {
// FIXME: use ShippingRate
    tDeliveryMethod = "5% surcharge for this Postcode";
   }
   for (i = 0; i < text.length; i++) {
    if (text[i].getAttribute("id") == "deliveryMethod") {
     text[i].className = "okay";
    }
   }
   fDeliveryMethod.firstChild.nodeValue = tDeliveryMethod;
   return true;
  }
  else {
   // not yet supplied
   var str = "Please provide the delivery postcode.\n"
       + "This enables calculation of delivery charges for remote areas,"
       + " and to show total costs up-front.";
   for (i = 0; i < text.length; i++) {
    if (text[i].getAttribute("id") == "deliveryMethod") {
     text[i].className = "error";
    }
   }
   fPostcode.focus();
   if (showAlert) { alert(str); }
   return false;
  }
 }
 // changing postcode
if (debug) { alert("Changing Postcode"); }
 postcode = postcode.replace(/\s+/, '')
 if (postcode.length < 4 || isNaN(postcode)) {
  alert("Australian postcodes are 4 digit numbers.");
  for (i = 0; i < text.length; i++) {
   if (text[i].getAttribute("id") == "deliveryMethod") {
    text[i].className = "error";
    text[i].firstChild.nodeValue = "Not yet specified";
   }
  }
  return false;
 }
 fPostcode.value = postcode;
 SetCookie("Postcode", postcode, null, "/");
if (debug) { alert("SetCookie postcode=" + postcode); }
 var isRemote = "n";
 if (postcode >= 800 && postcode <= 999) { isRemote = "y"; }
 if (postcode >= 6000 && postcode <= 6999) { isRemote = "y"; }
 if (postcode >= 5200 && postcode <= 5749) { isRemote = "y"; }
 if (postcode >= 4450 && postcode <= 4499) { isRemote = "y"; }
 if (postcode >= 4700 && postcode <= 4899) { isRemote = "y"; }
 if (postcode >= 9920 && postcode <= 9999) { isRemote = "y"; }
 if (postcode >= 7000 && postcode <= 7999) { isRemote = "y"; }
 if (postcode == 2880) { isRemote = "y"; }
 if (postcode == 2899) { isRemote = "y"; }
 if (isRemote == "y") {
  DeliveryMethod = "remote";
// FIXME: use ShippingRate
  tDeliveryMethod = "5% surcharge for this Postcode";
 }
 SetCookie("DeliveryMethod", DeliveryMethod, null, "/");
 for (i = 0; i < text.length; i++) {
  if (text[i].getAttribute("id") == "deliveryMethod") {
   text[i].className = "okay";
  }
 }
 fDeliveryMethod.firstChild.nodeValue = tDeliveryMethod;
if (debug) { alert("SetCookie DeliveryMethod=" + DeliveryMethod); }
 UpdateCart();
 return true;
}

function DeliveryDetails() {
 var str = "Unless otherwise indicated, postage and handling " +
  "is free to all but remote areas. For remote areas, a surcharge is applied, " +
  "calculated as " +
  ShippingRate*100 +
  "% of the total order value.\n" +
  "Remote area postcodes are:\n" +
  "- Northern Territory (0800-0999)\n" +
  "- Western Australia (6000-6999)\n" +
  "- South Australia excluding Adelaide (5200-5749)\n" +
  "- Mid and North Queensland (4450-4499, 4700-4899, 9920-9999)\n" +
  "- Tasmania (7000-7999)\n" +
  "- Broken Hill (2880)\n" +
  "- Norfolk Island (2899)";
 alert(str);
}

function DeliveryPolicy(item) {
 var str = "";
 if (item == "platform") {
  str = "All varieteeTM Adjustable Golf Practice Platforms are made to order. " +
   "The lead time for delivery is normally three months. However, we may be " +
   "able to offer you short term use of a demonstration unit in the " +
   "interim.  Please contact us for current delivery status.";
 }
 if (item == "hill-shot") {
  str = "For the Hill Shot Golf Trainer, under normal circumstances your " +
   "purchase will be dispatched within two working days of your payment " +
   "clearing. Delivery will take from one to seven days (depending on " +
   "your location).  In some cases, due to the popularity of this " +
   "product, delays in dispatch of up to six weeks may occur.  Under such " +
   "circumstances, we will contact you to advise the expected delivery " +
   "lead time.  If you have any concerns, please contact us for current " +
   "delivery status.";
 }
 alert(str);
}

function TestCookies() {
  SetCookie ("Test", 1, null, "/");
  var testC = GetCookie("Test");
  if (testC == null || testC == "" || testC == "null") {
   return false;
  }
  DeleteCookie("Test", "/");
  return true;
}

window.onload = function() {
 if (document.location.href.match(/checkout/)) {
  ClearTextAreas(document.forms[0]);
  var postcode = GetCookie("Postcode");
  if (postcode == null || postcode == "" || postcode == "null") {
    postcode = "None supplied";
  }
  var dm = GetCookie("DeliveryMethod");
  var tDeliveryMethod = "Free for this Postcode";
  if (dm == "remote") {
// FIXME: use ShippingRate
   tDeliveryMethod = "5% surcharge for this Postcode";
  }
  var text = document.getElementsByTagName("span");
  for (i = 0; i < text.length; i++) {
   if (text[i].getAttribute("name") == "tpostcode") {
    text[i].firstChild.nodeValue = postcode;
   }
  }
  var thisField = document.getElementsByName("postcode");
  thisField[0].value = postcode;
  for (i = 0; i < text.length; i++) {
   if (text[i].getAttribute("id") == "deliveryMethod") {
    text[i].firstChild.nodeValue = tDeliveryMethod;
   }
  }
  document.forms[0].Name.focus();
 }
 else {
  var message = document.getElementsByTagName("div");
  for (i = 0; i < message.length; i++) {
   if (message[i].getAttribute("id") == "msgL") {
    message[i].style.display = "none";
   }
   if (message[i].getAttribute("id") == "msgC") {
    if ( !TestCookies() ) {
     message[i].style.display = "block";
    }
   }
  }
  setDeliveryMethod("", false);
 }
}
