//=====================================================================||
//               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:
// Note that this value costs in the conversion fees and extra packaging effort for OS orders
USDExchangeRate       = 0.95;
MonetarySymbol        = '$';
DisplayNotice         = true;
DisplayShippingColumn = false;
DisplayShippingRow    = true;
DisplayWeightRow      = true;  // ADDED
DisplayTaxRow         = false;
TaxRate               = 0.00;
TaxByRegion           = false;
TaxPrompt             = 'For tax purposes, please select if you are an Arizona resident before continuing';
TaxablePrompt         = 'Arizona Residents';
NonTaxablePrompt      = 'Other States';
MinimumOrder          = 0.00;
MinimumOrderPrompt    = 'Your order is below our minimum order, please order more before checking out.';

//Payment Processor Options:
PaymentProcessor      = 'paypal';
//Options for Programmers:
OutputItemPrefix      = 'product_';
OutputItemId          = '_code';
OutputItemQuantity    = '_quantity';
OutputItemPrice       = '_price';
OutputItemName        = '_name';
OutputItemShipping    = '_shipping';
OutputItemWeight      = '_weight';    // ADDED
OutputItemAddtlInfo   = '_options';
OutputOrderSubtotal   = 'order_subtotal';
OutputOrderShipping   = 'order_shipping';
OutputOrderWeight     = 'order_weight';    // ADDED
OutputOrderTax        = 'order_tax';
OutputOrderTotal      = 'order_total';
OutputOrderTotalUsd   = 'order_total_usd';
AppendItemNumToOutput = true;
HiddenFieldsToCheckout = false;


    postage = new Array();

    // australia, express post
    postage[1] = new Array();
    postage[1][0] = 8;   // 250
    postage[1][1] = 8;   // 500
    postage[1][2] = 12;  // 1000
    postage[1][3] = 12;  // 2000
    postage[1][4] = 12;  // 3000
    postage[1][5] = 19;  // 4000
    postage[1][6] = 19;  // 5000

    // nz
    postage[2] = new Array();
    postage[2][0] = 11;  // 250
    postage[2][1] = 11;  // 500
    postage[2][2] = 41;  // 1000
    postage[2][3] = 49;  // 2000
    postage[2][4] = 58;  // 3000
    postage[2][5] = 76;  // 4000
    postage[2][6] = 76;  // 5000

    // asia / pacific
    postage[3] = new Array();
    postage[3][0] = 11;  // 250
    postage[3][1] = 11;  // 500
    postage[3][2] = 46;  // 1000
    postage[3][3] = 55;  // 2000
    postage[3][4] = 69;  // 3000
    postage[3][5] = 93;  // 4000
    postage[3][6] = 93;  // 5000

    // usa/canada/me
    postage[4] = new Array();
    postage[4][0] = 15;  // 250
    postage[4][1] = 15;  // 500
    postage[4][2] = 51;  // 1000
    postage[4][3] = 64;  // 2000
    postage[4][4] = 82;  // 3000
    postage[4][5] = 111;  // 4000
    postage[4][6] = 111;  // 5000

    // europe/rest
    postage[5] = new Array();
    postage[5][0] = 15;  // 250
    postage[5][1] = 15;  // 500
    postage[5][2] = 55;  // 1000
    postage[5][3] = 71;  // 2000
    postage[5][4] = 90;  // 3000
    postage[5][5] = 130; // 4000
    postage[5][6] = 130; // 5000  Default postage value if not selected

    pps   = 'contact';




//=====================================================================||
//---------------------------------------------------------------------||
//    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;
}
strWEIGHT = "WEIGHT";   // ADDED
pps += '@';


//---------------------------------------------------------------------||
// 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;

   // ADDED BEGIN
   if (thisForm.WEIGHT == null)
      strWEIGHT  = "0.00";
   else
      strWEIGHT  = thisForm.WEIGHT.value;
   if (thisForm.NOTES == null)
      strNOTES  = "none";
   else
      strNOTES  = thisForm.NOTES.value;
   // ADDED END

   // CHANGED/ADDED BEGIN
   strADDTLINFO = "";          
   if (thisForm.ADDITIONALINFO1 != null) {strADDTLINFO +=        thisForm.ADDITIONALINFO1.title + "=" + thisForm.ADDITIONALINFO1[thisForm.ADDITIONALINFO1.selectedIndex].value;}
   if (thisForm.ADDITIONALINFO2 != null) {strADDTLINFO += "; " + thisForm.ADDITIONALINFO2.title + "=" + thisForm.ADDITIONALINFO2[thisForm.ADDITIONALINFO2.selectedIndex].value;}
   if (thisForm.ADDITIONALINFO3 != null) {strADDTLINFO += "; " + thisForm.ADDITIONALINFO3.title + "=" + thisForm.ADDITIONALINFO3[thisForm.ADDITIONALINFO3.selectedIndex].value;}
   if (thisForm.ADDITIONALINFO4 != null) {strADDTLINFO += "; " + thisForm.ADDITIONALINFO4.title + "=" + thisForm.ADDITIONALINFO4[thisForm.ADDITIONALINFO4.selectedIndex].value;}
   if (thisForm.ADDITIONALINFO5 != null) {strADDTLINFO += "; " + thisForm.ADDITIONALINFO5.title + "=" + thisForm.ADDITIONALINFO5[thisForm.ADDITIONALINFO5.selectedIndex].value;}
   if (thisForm.ADDITIONALINFO6 != null) {strADDTLINFO += "; " + thisForm.ADDITIONALINFO6.title + "=" + thisForm.ADDITIONALINFO6[thisForm.ADDITIONALINFO6.selectedIndex].value;}
   if (thisForm.ADDITIONALINFO7 != null) {strADDTLINFO += "; " + thisForm.ADDITIONALINFO7.title + "=" + thisForm.ADDITIONALINFO7[thisForm.ADDITIONALINFO7.selectedIndex].value;}
   if (thisForm.ADDITIONALINFO8 != null) {strADDTLINFO += "; " + thisForm.ADDITIONALINFO8.title + "=" + thisForm.ADDITIONALINFO8[thisForm.ADDITIONALINFO8.selectedIndex].value;}
   if (thisForm.ADDITIONALINFO9 != null) {strADDTLINFO += "; " + thisForm.ADDITIONALINFO9.title + "=" + thisForm.ADDITIONALINFO9[thisForm.ADDITIONALINFO9.selectedIndex].value;}
   if (thisForm.ADDITIONALINFO10 != null) {strADDTLINFO += "; " + thisForm.ADDITIONALINFO10.title + "=" + thisForm.ADDITIONALINFO10[thisForm.ADDITIONALINFO10.selectedIndex].value;}
   if (thisForm.ADDITIONALINFO11 != null) {strADDTLINFO += "; " + thisForm.ADDITIONALINFO11.title + "=" + thisForm.ADDITIONALINFO11[thisForm.ADDITIONALINFO11.selectedIndex].value;}
   if (thisForm.ADDITIONALINFO12 != null) {strADDTLINFO += "; " + thisForm.ADDITIONALINFO12.title + "=" + thisForm.ADDITIONALINFO12[thisForm.ADDITIONALINFO12.selectedIndex].value;}
   if (thisForm.ADDITIONALINFO13 != null) {strADDTLINFO += "; " + thisForm.ADDITIONALINFO13.title + "=" + thisForm.ADDITIONALINFO13[thisForm.ADDITIONALINFO13.selectedIndex].value;}
   if (strNOTES != null && strNOTES.length > 0) 
   {
       if (strADDTLINFO != "") strADDTLINFO += "; ";
       strADDTLINFO += "notes=" + strNOTES;
   }

    // add any additional cost for the options selected.
    fPriceWithOptions = parseFloat(strPRICE);
    
   if (thisForm.ADDITIONALINFO1 != null && thisForm.ADDITIONALINFO1[thisForm.ADDITIONALINFO1.selectedIndex].title != null) {fPriceWithOptions += parseFloat(thisForm.ADDITIONALINFO1[thisForm.ADDITIONALINFO1.selectedIndex].title);}
   if (thisForm.ADDITIONALINFO2 != null && thisForm.ADDITIONALINFO2[thisForm.ADDITIONALINFO2.selectedIndex].title != null) {fPriceWithOptions += parseFloat(thisForm.ADDITIONALINFO2[thisForm.ADDITIONALINFO2.selectedIndex].title);} 
   if (thisForm.ADDITIONALINFO3 != null && thisForm.ADDITIONALINFO3[thisForm.ADDITIONALINFO3.selectedIndex].title != null) {fPriceWithOptions += parseFloat(thisForm.ADDITIONALINFO3[thisForm.ADDITIONALINFO3.selectedIndex].title);} 
   if (thisForm.ADDITIONALINFO4 != null && thisForm.ADDITIONALINFO4[thisForm.ADDITIONALINFO4.selectedIndex].title != null) {fPriceWithOptions += parseFloat(thisForm.ADDITIONALINFO4[thisForm.ADDITIONALINFO4.selectedIndex].title);} 
   if (thisForm.ADDITIONALINFO5 != null && thisForm.ADDITIONALINFO5[thisForm.ADDITIONALINFO5.selectedIndex].title != null) {fPriceWithOptions += parseFloat(thisForm.ADDITIONALINFO5[thisForm.ADDITIONALINFO5.selectedIndex].title);} 
   if (thisForm.ADDITIONALINFO6 != null && thisForm.ADDITIONALINFO6[thisForm.ADDITIONALINFO6.selectedIndex].title != null) {fPriceWithOptions += parseFloat(thisForm.ADDITIONALINFO6[thisForm.ADDITIONALINFO6.selectedIndex].title);} 
   if (thisForm.ADDITIONALINFO7 != null && thisForm.ADDITIONALINFO7[thisForm.ADDITIONALINFO7.selectedIndex].title != null) {fPriceWithOptions += parseFloat(thisForm.ADDITIONALINFO7[thisForm.ADDITIONALINFO7.selectedIndex].title);} 
   if (thisForm.ADDITIONALINFO8 != null && thisForm.ADDITIONALINFO8[thisForm.ADDITIONALINFO8.selectedIndex].title != null) {fPriceWithOptions += parseFloat(thisForm.ADDITIONALINFO8[thisForm.ADDITIONALINFO8.selectedIndex].title);} 
   if (thisForm.ADDITIONALINFO9 != null && thisForm.ADDITIONALINFO9[thisForm.ADDITIONALINFO9.selectedIndex].title != null) {fPriceWithOptions += parseFloat(thisForm.ADDITIONALINFO9[thisForm.ADDITIONALINFO9.selectedIndex].title);} 
   if (thisForm.ADDITIONALINFO10 != null && thisForm.ADDITIONALINFO10[thisForm.ADDITIONALINFO10.selectedIndex].title != null) {fPriceWithOptions += parseFloat(thisForm.ADDITIONALINFO10[thisForm.ADDITIONALINFO10.selectedIndex].title);} 
   if (thisForm.ADDITIONALINFO11 != null && thisForm.ADDITIONALINFO11[thisForm.ADDITIONALINFO11.selectedIndex].title != null) {fPriceWithOptions += parseFloat(thisForm.ADDITIONALINFO11[thisForm.ADDITIONALINFO11.selectedIndex].title);} 
   if (thisForm.ADDITIONALINFO12 != null && thisForm.ADDITIONALINFO12[thisForm.ADDITIONALINFO12.selectedIndex].title != null) {fPriceWithOptions += parseFloat(thisForm.ADDITIONALINFO12[thisForm.ADDITIONALINFO12.selectedIndex].title);}
   if (thisForm.ADDITIONALINFO13 != null && thisForm.ADDITIONALINFO13[thisForm.ADDITIONALINFO13.selectedIndex].title != null) {fPriceWithOptions += parseFloat(thisForm.ADDITIONALINFO13[thisForm.ADDITIONALINFO13.selectedIndex].title);} 
    strPRICE = "" + fPriceWithOptions;
   // CHANGED/ADDED END
   
   //Is this product already in the cart?  If so, increment quantity instead of adding another.
   for ( i = 1; i <= iNumberOrdered; i++ ) {
      NewOrder = "Order." + i;
      fields = nopGetFields(NewOrder); 

      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  + "|" +
                          strWEIGHT    + "|" +   // ADDED
                          strADDTLINFO;
         strNewOrder = "Order." + i;
         DeleteCookie(strNewOrder, "/");
         SetCookie(strNewOrder, dbUpdatedOrder, null, "/");
         notice = strQUANTITY + " " + strNAME + strAdded;
         break;
      }
   }


   if ( !bAlreadyInCart ) {
      iNumberOrdered++;

      if ( iNumberOrdered > 12 )
         alert( strSorry );
      else {
         dbUpdatedOrder = strID_NUM    + "|" + 
                          strQUANTITY  + "|" +
                          strPRICE     + "|" +
                          strNAME      + "|" +
                          strSHIPPING  + "|" +
                          strWEIGHT    + "|" +  // ADDED
                          strADDTLINFO;

    //alert(dbUpdatedOrder);

         strNewOrder = "Order." + iNumberOrdered;
         SetCookie(strNewOrder, dbUpdatedOrder, null, "/");
         SetCookie("NumberOrdered", iNumberOrdered, null, "/");
         notice = strQUANTITY + " " + strNAME + strAdded;
      }
   }

   if ( DisplayNotice )
   {
      alert(notice);
      location.href=location.href;
   }
}


//---------------------------------------------------------------------||
// 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);
}
pps += 'vlatex.com';


//---------------------------------------------------------------------||
// 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(input) {
   var dollars = Math.floor(input);
   var tmp = new String(input);

   for ( var decimalAt = 0; decimalAt < tmp.length; decimalAt++ ) {
      if ( tmp.charAt(decimalAt)=="." )
         break;
   }

   var cents  = "" + Math.round(input * 100);
   cents = cents.substring(cents.length-2, cents.length)
           dollars += ((tmp.charAt(decimalAt+2)=="9")&&(cents=="00"))? 1 : 0;

   if ( cents == "0" )
      cents = "00";

   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) ) {
      alert( strErrQty );
   } else {
      NewOrder = "Order." + OrderItem;
      fields = nopGetFields(NewOrder); 
      
      dbUpdatedOrder = fields[0] + "|" +
                       NewQuantity + "|" +
                       fields[2] + "|" +
                       fields[3] + "|" +
                       fields[4] + "|" +
                       fields[6] + "|" +  // ADDED
                       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
   var fWeight        = 0;    //Weight amount  ADDED
   var strTotal       = "";   //Total cost formatted as money
   var strTax         = "";   //Total tax formatted as money
   var strShipping    = "";   //Total shipping formatted as money
   var strWeight      = "";   //Total weight formatted as money  ADDED
   var strOutput      = "";   //String to be written to page
   var bDisplay       = true; //Whether to write string to the page (here for programmers)

   iNumberOrdered = GetCookie("NumberOrdered");
   if ( iNumberOrdered == null )
      iNumberOrdered = 0;

   if ( bDisplay )
      strOutput = "<table class=\"nopcart\"><tr>" +
                  "<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>":"") +
                  "<td class=\"nopheader\"><b>"+strRLabel+"</b></td></tr>";

   if ( iNumberOrdered == 0 ) 
   {
        strOutput += "<tr><td colspan=6 class=\"nopentry\"><CENTER><BR><b><font color=\"red\">Your cart is empty</font></b><BR><BR></CENTER></td></tr>";
   }

   for ( i = 1; i <= iNumberOrdered; i++ ) 
   {
      NewOrder = "Order." + i;
      fields = nopGetFields(NewOrder); 
      fTotal     += (parseInt(fields[1]) * parseFloat(fields[2]) );
      fShipping  += (parseInt(fields[1]) * parseFloat(fields[4]) );
      fWeight    += (parseInt(fields[1]) * parseInt(fields[6]) );  // ADDED
      fTax        = (fTotal * TaxRate);
      strTotal    = moneyFormat(fTotal);
      strTax      = moneyFormat(fTax);
      strWeight   = fWeight;      // ADDED
      strShipping = moneyFormat(fShipping);

      if ( bDisplay ) 
      {
         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\"><input type=\"text\" name=\"Q\" size=\"2\" value=\"" + fields[1] + "\" onchange=\"ChangeQuantity("+i+", this.value);\"></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 += "<td class=\"nopentry\" align=CENTER><input type=\"button\" value=\" "+strRButton+" \" onClick=\"RemoveFromCart("+i+")\" class=\"nopbutton\"/></td></tr>";
      }

      if ( AppendItemNumToOutput ) 
      {
         strFooter = i;
      } else 
      {
         strFooter = "";
      }
      
      // used to pass information to next page
      if (HiddenFieldsToCheckout)
      {
         strOutput += "<input type=\"hidden\" name=\"" + OutputItemPrefix + strFooter + OutputItemId        + "\" value=\"" + fields[0] + "\"/>";
         strOutput += "<input type=\"hidden\" name=\"" + OutputItemPrefix + strFooter + OutputItemQuantity  + "\" value=\"" + fields[1] + "\"/>";
         strOutput += "<input type=\"hidden\" name=\"" + OutputItemPrefix + strFooter + OutputItemPrice     + "\" value=\"" + fields[2] + "\"/>";
         strOutput += "<input type=\"hidden\" name=\"" + OutputItemPrefix + strFooter + OutputItemName      + "\" value=\"" + fields[3] + "\"/>";
         strOutput += "<input type=\"hidden\" name=\"" + OutputItemPrefix + strFooter + OutputItemShipping  + "\" value=\"" + fields[4] + "\"/>";
         strOutput += "<input type=\"hidden\" name=\"" + OutputItemPrefix + strFooter + OutputItemWeight    + "\" value=\"" + fields[6] + "\"/>";  // ADDED
         strOutput += "<input type=\"hidden\" name=\"" + OutputItemPrefix + strFooter + OutputItemAddtlInfo + "\" value=\"" + fields[5] + "\"/>";
      }

   }

   if ( bDisplay ) {
      strOutput += "<tr><td class=\"noptotal\" colspan=\"4\"><b>"+strSUB+"</b></td>";
      strOutput += "<td class=\"noptotal\" colspan=\"2\"><b>" + MonetarySymbol + strTotal + "</b></td>";
      strOutput += "</tr>";

      if ( DisplayWeightRow ) {
         strOutput += "<tr><td class=\"noptotal\" colspan=\"4\"><b>"+strWEIGHT+"</b></td>";
         strOutput += "<td class=\"noptotal\" colspan=\"2\"><b>" + strWeight + " g</b></td>";
         strOutput += "</tr>";
      }
      
      fShipping = nopGetPostage(vvvGetValueForKey('zone'), fWeight);      
      strShipping = nopGetFormattedPostage(fWeight);
      
      if ( DisplayShippingRow ) 
      {
         strOutput += "<tr><td class=\"noptotal\" colspan=\"4\"><b>"+strSHIP+" (" + nopGetZoneDisplayName() + ")</b></td>";  // XXX
         strOutput += "<td class=\"noptotal\" colspan=\"2\"><b>" + MonetarySymbol + strShipping + "</b></td>";
         strOutput += "</tr>";
      }

      if ( DisplayTaxRow || TaxByRegion ) {
         if ( TaxByRegion ) {
            strOutput += "<tr><td class=\"noptotal\" colspan=4><b>"+strTAX+"</b></td>";
            strOutput += "<td class=\"noptotal\" colspan=2><b>";
            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 += "</b></td>";
            strOutput += "</tr>";
         } else {
            strOutput += "<tr><td class=\"noptotal\" colspan=\"4\"><b>"+strTAX+"</b></td>";
            strOutput += "<td class=\"noptotal\" colspan=\"2\"><b>" + MonetarySymbol + strTax + "</b></td>";
            strOutput += "</tr>";
         }
      }

var fTotalTotal    = fTotal + fShipping + fTax;
var fTotalTotalUsd = fTotalTotal * USDExchangeRate;


      if (!TaxByRegion) 
      {
         strOutput += "<tr><td class=\"noptotal\" colspan=\"4\"><b>"+strTOT+"</b></td>";
         

strOutput += "<td class=\"noptotal\" colspan=\"2\">";
if (!nopOrderZoneIsAustralia() && (iNumberOrdered > 0))
{
    strOutput += "" + MonetarySymbol + moneyFormat(fTotalTotal) + " AUD<br/><b>(" + MonetarySymbol + moneyFormat(fTotalTotalUsd) + " US Dollars)</b>";
}
else
{
    strOutput += "<b>" + MonetarySymbol + moneyFormat((fTotalTotal)) + "</b>";
}
strOutput += "</td>";
         
         
         strOutput += "</tr>";
      }
      strOutput += "</table>";

      if ( HiddenFieldsToCheckout ) 
      {
         strOutput += "<input type=\"hidden\" name=\""+OutputOrderWeight+"\"   value=\""+ strWeight + " g\"/>";   // ADDED
         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(fTotalTotal) + "\"/>";
         strOutput += "<input type=\"hidden\" name=\""+OutputOrderTotalUsd+"\" value=\""+ MonetarySymbol + moneyFormat(fTotalTotalUsd) + "\"/>";
      }
   }
   g_TotalCost = (fTotalTotal);

   document.write(strOutput);
   document.close();
}

//---------------------------------------------------------------------||
// FUNCTION:    ValidateCart                                           ||
// PARAMETERS:  Form to validate                                       ||
// RETURNS:     true/false                                             ||
// PURPOSE:     Validates the managecart form                          ||
//---------------------------------------------------------------------||
var g_TotalCost = 0;
function ValidateCart( theForm ) {
   if ( TaxByRegion ) {
      if ( !RadioChecked(eval("theForm."+OutputOrderTax)) ) {
         alert( TaxPrompt );
         return false;
      }
   }

   if ( MinimumOrder >= 0.01 ) {
      if ( g_TotalCost < MinimumOrder ) {
         alert( MinimumOrderPrompt );
         return false;
      }
   }

   return true;
}

//---------------------------------------------------------------------||
// FUNCTION:    CheckoutCart                                           ||
// PARAMETERS:  Null                                                   ||
// RETURNS:     Product Table Written to Document                      ||
// PURPOSE:     Draws current cart product table on HTML page for      ||
//              checkout.                                              ||
//---------------------------------------------------------------------||
function CheckoutCart(showPaymentButton) 
{
   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 fWeight          = 0;    //Weight ADDED
   var strTotal         = "";   //Total cost formatted as money
   var strTax           = "";   //Total tax formatted as money
   var strShipping      = "";   //Total shipping formatted as money
   var strWeight        = "";   //Total Weight formatted as money  ADDED
   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 strFirstItemName = "";
   
   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>" +
                  "<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>";
   if (iNumberOrdered == 0) 
   {
      strOutput += "<tr><td colspan=6 class=\"nopentry\"><CENTER><BR><b><font color=\"red\">Your cart is empty</font></b><BR><BR></CENTER></td></tr>";
   }

    for (i = 1; i <= iNumberOrdered; i++) 
    {
        NewOrder = "Order." + i;
        fields = nopGetFields(NewOrder); 
        
        fTotal    += (parseInt(nopGetQuantity(fields)) * parseFloat(nopGetPrice(fields)) );
        fShipping += (parseInt(nopGetQuantity(fields)) * parseFloat(nopGetShipping(fields)) );
        fWeight   += (parseInt(nopGetQuantity(fields)) * parseInt(nopGetWeight(fields)) );   // ADDED
        if (!TaxByRegion) fTax = (fTotal * TaxRate);
        strTotal    = moneyFormat(fTotal);
        if (!TaxByRegion) strTax = moneyFormat(fTax);
        strShipping = moneyFormat(fShipping);
        strWeight = fWeight;  // ADDED

        if (i == 1)
        {
            strFirstItemName = nopGetName(fields);
        }

        if (bDisplay)
        {
            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 != '') 
        {
             // Create a summary text line in strPP to pass to the payment processors since they usually just accept a name and a price.
             //Format Description of product as:
             // ID, Name - notes, Qty. X
             strPP += nopGetCode(fields) + ", " + nopGetName(fields);
             if (nopGetNotes(fields) != "")
                strPP += " - " + nopGetNotes(fields);
             strPP += ", Qty. " + nopGetQuantity(fields) + "\n";
        }
        
        //if (PaymentProcessor == 'paypal')
        //{
        //   // Add hidden fields for paypal   
        //   strOutput += "<input type=\"hidden\" name=\"item_name_" + i + "\" value=\"" + strPP + "\"/>";
        //   strOutput += "<input type=\"hidden\" name=\"amount_" + i + "\" value=\"" + nopGetPrice(fields) + "\"/>";
        //}
        
        // Here we populate the form for the item
        strOutput += "<input type=\"hidden\" name=\"" + OutputItemPrefix + strFooter + OutputItemId        + "\" value=\"" + fields[0] + "\"/>";
        strOutput += "<input type=\"hidden\" name=\"" + OutputItemPrefix + strFooter + OutputItemQuantity  + "\" value=\"" + fields[1] + "\"/>";
        strOutput += "<input type=\"hidden\" name=\"" + OutputItemPrefix + strFooter + OutputItemPrice     + "\" value=\"" + fields[2] + "\"/>";
        strOutput += "<input type=\"hidden\" name=\"" + OutputItemPrefix + strFooter + OutputItemName      + "\" value=\"" + fields[3] + "\"/>";
        strOutput += "<input type=\"hidden\" name=\"" + OutputItemPrefix + strFooter + OutputItemShipping  + "\" value=\"" + fields[4] + "\"/>";
        strOutput += "<input type=\"hidden\" name=\"" + OutputItemPrefix + strFooter + OutputItemWeight    + "\" value=\"" + fields[6] + "\"/>";  // ADDED
        strOutput += "<input type=\"hidden\" name=\"" + OutputItemPrefix + strFooter + OutputItemAddtlInfo + "\" 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>";
        
        fShipping = nopGetPostage(vvvGetValueForKey('zone'), fWeight);
        strShipping = nopGetFormattedPostage(fWeight);
        
        if (DisplayShippingRow) 
        {
            strOutput += "<tr><td class=\"noptotal\" colspan=3><b>"+strSHIP+" (" + nopGetZoneDisplayName() + ")</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>";
        }
    
        var fTotalTotal    = fTotal + fShipping + fTax;
        var fTotalTotalUsd = fTotalTotal * USDExchangeRate;
    
        // Total Row
        strOutput += "<tr><td class=\"noptotal\" colspan=\"3\"><b>"+strTOT+"</b></td>";
        strOutput += "<td class=\"noptotal\" colspan=\"2\" align=\"RIGHT\">";
        
        if (!nopOrderZoneIsAustralia() && (iNumberOrdered > 0))
        {
            strOutput += "" + MonetarySymbol + moneyFormat(fTotalTotal) + " AUD<br/><b>(" + MonetarySymbol + moneyFormat(fTotalTotalUsd) + " US Dollars)</b><br/></font>";
        }
        else
        {
            strOutput += "<b>" + MonetarySymbol + moneyFormat(fTotalTotal) + "</b>";
        }
        
        strOutput += "</td>";
        strOutput += "</tr>";
        
        strOutput += "</table>";
        
        // USD total row
        if (!nopOrderZoneIsAustralia() && (iNumberOrdered > 0) && showPaymentButton)
        {
            strOutput += "<font color=\"orange\">Please make payment of " + MonetarySymbol + moneyFormat(fTotalTotalUsd) + " US Dollars using PayPal.<br/></font>";
        }
          
        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((fTotalTotal)) + "\"/>";
        } 
        else if (PaymentProcessor == 'wp') 
        {
            //Process this for WorldPay
            strOutput += "<input type=\"hidden\" name=\"desc\" value=\""+ strPP + "\"/>";
            strOutput += "<input type=\"hidden\" name=\"amount\" value=\""+ moneyFormat((fTotalTotal)) + "\"/>";
        }
        else if (PaymentProcessor == 'lp') 
        {
            //Process this for LinkPoint         
            strOutput += "<input type=\"hidden\" name=\"mode\" value=\"fullpay\"/>";
            strOutput += "<input type=\"hidden\" name=\"chargetotal\" value=\""+ moneyFormat((fTotalTotal)) + "\"/>";
            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 == 'paypal')
        {
            // Add hidden fields for paypal   
            //strOutput += "<input type=\"hidden\" name=\"cmd\" value=\"_cart\"/>";
            //strOutput += "<input type=\"hidden\" name=\"upload\" value=\"1\"/>";
            strOutput += "<input type=\"hidden\" name=\"cmd\" value=\"_xclick\"/>";
            strOutput += "<input type=\"hidden\" name=\"business\" value=\"" + pps + "\"/>";
            strOutput += "<input type=\"hidden\" name=\"item_name\" value=\"Your VL order of " + iNumberOrdered + " item(s)\"/>";
            if (nopOrderZoneIsAustralia())
            {
                // order should be paid in Australian dollars.
                strOutput += "<input type=\"hidden\" name=\"currency_code\" value=\"AUD\"/>";
                strOutput += "<input type=\"hidden\" name=\"amount\" value=\"" + moneyFormat(fTotalTotal) + "\"/>";
            }
            else
            {
                // order should be paid in US dollars.
                strOutput += "<input type=\"hidden\" name=\"currency_code\" value=\"USD\"/>";
                strOutput += "<input type=\"hidden\" name=\"amount\" value=\"" + moneyFormat(fTotalTotalUsd) + "\"/>";
            }
            
            if (iNumberOrdered > 0 && showPaymentButton == true)
            {
                strOutput += "<br/>";
                strOutput += "The button below connects you to PayPal which accepts credit card payments on our behalf.";
                strOutput += "<br/>";
                strOutput += "You can also choose to pay using an existing PayPal account through this link.";
                strOutput += "<br/>";
                strOutput += "<br/>";
                strOutput += "*Please note that once payment has been made, refunds for changing your mind are at our disgression.";
                strOutput += "<br/>";
                strOutput += "<br/>";
                strOutput += "<input type=\"submit\" value=\"Pay now\"/>";
            }
        }
        strOutput += "<input type=\"hidden\" name=\""+OutputOrderWeight+"\"   value=\"" + strWeight + " g\"/>";   // ADDED
        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(fTotalTotal) + "\"/>";
        strOutput += "<input type=\"hidden\" name=\""+OutputOrderTotalUsd+"\" value=\""+ MonetarySymbol + moneyFormat(fTotalTotalUsd) + "\"/>";
        //alert(strOutput);
   }

   document.write(strOutput);
   document.close();
}


function nopOrderZoneIsAustralia()
{
    return (vvvGetValueForKey('zone') == 1);
}

function nopGetZoneDisplayName()
{
    zoneText = vvvGetValueForKey('zonevalue');
    if (zoneText == '' || zoneText == null || zoneText == 'undefined') zoneText = '<font color="red">PLEASE SELECT SHIPPING ZONE TO AVOID MAXIMUM CHARGE</font>';
    return zoneText;
}

function DisplayItemCount() 
{
    iNumberOrdered = GetCookie("NumberOrdered");
    if (iNumberOrdered == null)
      iNumberOrdered = 0;
   
   total = 0;   
   for ( i = 1; i <= iNumberOrdered; i++ ) 
   {
      NewOrder = "Order." + i;
      database = "";
      database = GetCookie(NewOrder);
      indexProductId  = database.indexOf("|", 0);
      indexQuantity = database.indexOf("|", indexProductId+1);

      productId = database.substring( 0, indexProductId );            
      quantity = database.substring( indexProductId+1, indexQuantity );
      total += parseInt(quantity);
   }      
      
    document.write(total);
    document.close();
}


// Parses the database cookie to get the fields, returning an array of fields.
function nopGetFields(orderCookieName) 
{
    database = "";
    database = GetCookie(orderCookieName);
    Token0 = database.indexOf("|", 0);
    Token1 = database.indexOf("|", Token0+1);
    Token2 = database.indexOf("|", Token1+1);
    Token3 = database.indexOf("|", Token2+1);
    Token4 = database.indexOf("|", Token3+1);
    Token5 = database.indexOf("|", Token4+1); // ADDED
    
    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[6] = database.substring( Token4+1, Token5 );          // Weight  ADDED as field 6 to ensure other code still works
    fields[5] = database.substring( Token5+1, database.length ); //Additional Information  ADDED
    return fields;
}


function nopGetCode(fields)     {return fields[0];}
function nopGetQuantity(fields) {return parseInt(fields[1]);}
function nopGetPrice(fields)    {return parseFloat(fields[2]);}
function nopGetName(fields)     {return fields[3];}
function nopGetShipping(fields) {return parseFloat(fields[4]);}
function nopGetNotes(fields)    {return fields[5];}
function nopGetWeight(fields)   {return parseInt(fields[6]);}


function nopGetFormattedPostage(weight)
{
    var postageCost = nopGetPostage(vvvGetValueForKey('zone'), weight);
    if (postageCost == 0)
    {
        //return " SELECT ZONE ";
        postageCost = nopGetPostage(5, weight);
    }
    return moneyFormat(parseFloat(''+postageCost));
}


function nopGetPostage(postalZoneIndex, weight)
{
    if (postalZoneIndex == null || postalZoneIndex == 0)
    {
        // max price
        postalZoneIndex = 5;
    }
    if (!postage[postalZoneIndex])
    {
        // not set
        return 0;
    }
    if (weight <= 250)
    {
        return postage[postalZoneIndex][0];
    }
    if (weight <= 500)
    {
        return postage[postalZoneIndex][1];
    }
    if (weight <= 1000)
    {
        return postage[postalZoneIndex][2];
    }
    if (weight <= 2000)
    {
        return postage[postalZoneIndex][3];
    }
    if (weight <= 3000)
    {
        return postage[postalZoneIndex][4];
    }
    if (weight <= 4000)
    {
        return postage[postalZoneIndex][5];
    }
    return postage[postalZoneIndex][6];
}


function nopSetFieldValue(fieldId,newValue)
{
    var element = document.getElementById(fieldId);
    if (element == null)
    {
        alert("Field with id " + fieldId + " is not present on this page");
        return;
    }

    element.value = newValue;
}

function nopGetFieldValue(fieldId)
{
    var element = document.getElementById(fieldId);
    if (element == null)
    {
        alert("Field with id " + fieldId + " is not present on this page");
        return null;
    }
    return element.value;
}


function nopCheckCookiesEnabled()
{
    SetCookie("cookieSupport", "yes", null, "/");
   	supportsCookies = GetCookie("cookieSupport");
   	if (supportsCookies == null)
	{
   		document.write("<p><font color='yellow'>");
   		document.write("Oops, we detected that your browser might not support Cookies, or they are disabled.  Our product shopping cart requires that you have Cookies enabled in your browser's preferences to order from us.");
   		document.write("</font></p>");
   		document.close();
	}
	else
	{
         DeleteCookie("cookieSupport", "/");
	}
}

//=====================================================================||
//               END NOP Design SmartPost Shopping Cart                ||
//=====================================================================||

