//=====================================================================||
//               NOP Design JavaScript Shopping Cart                   ||
//                                                                     ||
// For more information on SmartSystems, or how NOPDesign can help you ||
// Please visit us on the WWW at http://www.nopdesign.com              ||
//                                                                     ||
// Javascript portions of this shopping cart software are available as ||
// freeware from NOP Design.  You must keep this comment unchanged in  ||
// your code.  For more information contact FreeCart@NopDesign.com.    ||
//                                                                     ||
// JavaScript Shop Module, V.4.4.0                                     ||
//=====================================================================||

//---------------------------------------------------------------------||
//                       Global Options                                ||
//                      ----------------                               ||
// Shopping Cart Options, you can modify these options to change the   ||
// the way the cart functions.                                         ||
//                                                                     ||
// Language Packs                                                      ||
// ==============                                                      ||
// You may include any language pack before nopcart.js in your HTML    ||
// pages to change the language.  Simply include a language pack with  ||
// a script src BEFORE the <SCRIPT SRC="nopcart.js">... line.          ||
//  For example: <SCRIPT SRC="language-en.js"></SCRIPT>                ||
//                                                                     ||
// Options For Everyone:                                               ||
// =====================                                               ||
// * MonetarySymbol: string, the symbol which represents dollars/euro, ||
//   in your locale.                                                   ||
// * DisplayNotice: true/false, controls whether the user is provided  ||
//   with a popup letting them know their product is added to the cart ||
// * DisplayShippingColumn: true/false, controls whether the managecart||
//   and checkout pages display shipping cost column.                  ||
// * DisplayShippingRow: true/false, controls whether the managecart   ||
//   and checkout pages display shipping cost total row.               ||
// * DisplayTaxRow: true/false, controls whether the managecart        ||
//   and checkout pages display tax cost total row.                    ||
// * TaxRate: number, your area's current tax rate, ie: if your tax    ||
//   rate was 7.5%, you would set TaxRate = 0.075                      ||
// * TaxByRegion: true/false, when set to true, the user is prompted   ||
//   with TaxablePrompt to determine if they should be charged tax.    ||
//   In the USA, this is useful to charge tax to those people who live ||
//   in a particular state, but no one else.                           ||
// * TaxPrompt: string, popup message if user has not selected either  ||
//   taxable or nontaxable when TaxByRegion is set to true.            ||
// * TaxablePrompt: string, the message the user is prompted with to   ||
//   select if they are taxable.  If TaxByRegion is set to false, this ||
//   has no effect. Example: 'Arizona Residents'                       ||
// * NonTaxablePrompt: string, same as above, but the choice for non-  ||
//   taxable people.  Example: 'Other States'                          ||
// * MinimumOrder: number, the minium dollar amount that must be       ||
//   purchased before a user is allowed to checkout.  Set to 0.00      ||
//   to disable.                                                       ||
// * MinimumOrderPrompt: string, Message to prompt users with when     ||
//   they have not met the minimum order amount.                       ||
//                                                                     ||
// Payment Processor Options:                                          ||
// ==========================                                          ||
// * PaymentProcessor: string, the two digit payment processor code    ||
//   for support payment processor gateways.  Setting this field to    ||
//   anything other than an empty string will override your OutputItem ||
//   settings -- so please be careful when receiving any form data.    ||
//   Support payment processor gateways are:                           ||
//    * Authorize.net (an)                                             ||
//    * Worldpay      (wp)                                             ||
//    * LinkPoint     (lp)
//                                                                     ||
// Options For Programmers:                                            ||
// ========================                                            ||
// * OutputItem<..>: string, the name of the pair value passed at      ||
//   checkouttime.  Change these only if you are connecting to a CGI   ||
//   script and need other field names, or are using a secure service  ||
//   that requires specific field names.                               ||
// * AppendItemNumToOutput: true/false, if set to true, the number of  ||
//   each ordered item will be appended to the output string.  For     ||
//   example if OutputItemId is 'ID_' and this is set to true, the     ||
//   output field name will be 'ID_1', 'ID_2' ... for each item.       ||
// * HiddenFieldsToCheckout: true/false, if set to true, hidden fields ||
//   for the cart items will be passed TO the checkout page, from the  ||
//   ManageCart page.  This is set to true for CGI/PHP/Script based    ||
//   checkout pages, but should be left false if you are using an      ||
//   HTML/Javascript Checkout Page. Hidden fields will ALWAYS be       ||
//   passed FROM the checkout page to the Checkout CGI/PHP/ASP/Script  ||
//---------------------------------------------------------------------||

//Options for Everyone:
MonetarySymbol        = '$';
DisplayNotice         = false;
DisplayShippingColumn = true;
DisplayShippingRow    = true;
DisplayTaxRow         = true;
TaxRate               = 0.14;
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      = '';

//Options for Programmers:
OutputItemId          = 'item_number_';
OutputItemQuantity    = 'quantity_';
OutputItemPrice       = 'amount_';
OutputItemName        = 'item_name_';
OutputItemShipping    = 'SHIPPING2_';
OutputItemAddtlInfo   = 'on0_';
OutputItemAddtlInfo2   = 'on1_';
OutputItemAddtlInfo3   = 'os0_';
OutputItemAddtlInfo4   = 'os1_';
OutputOrderSubtotal   = 'SUBTOTAL';
OutputOrderShipping   = 'shipping2_';
OutputOrderTax        = 'TAXES';
OutputOrderTotal      = 'amount';
AppendItemNumToOutput = true;
HiddenFieldsToCheckout = true;


//=====================================================================||
//---------------------------------------------------------------------||
//    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";
   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.on0 == null )
      str_on0    = "";
   else
      str_on0    = thisForm.on0.value;
      
    if ( thisForm.on1 == null )
      str_on1    = "";
   else
      str_on1    = thisForm.on1.value;
      
   if ( thisForm.os0 == null )
      str_os0    = "";
   else
      str_os0    = thisForm.os0.value;
      
   if ( thisForm.os1 == null )
      str_os1    = "";
   else
      str_os1    = thisForm.os1.value;                 

   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  = "";
   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;
   }

   if ( thisForm.SALEPRICE == null )
      strSALEPRICE     = "0.00";
   else
      strSALEPRICE     = thisForm.SALEPRICE.value;
      
   if ( thisForm.SALE == null )
      strSALE    = "";
   else
      strSALE    = thisForm.SALE.value;
      
   if ( thisForm.DOD == null )
      strDOD    = "";
   else
      strDOD    = thisForm.DOD.value;   

   if ( thisForm.STOCK == null )
      strSTOCK    = "";
   else
      strSTOCK    = thisForm.STOCK.value;   

 


   if ( !bAlreadyInCart ) {
      iNumberOrdered++;

      if ( iNumberOrdered > 12 )
         alert( strSorry );
      else {
         dbUpdatedOrder = strID_NUM    + "|" + 
                          strQUANTITY  + "|" +
                          strPRICE     + "|" +
                          strNAME      + "|" +
                          strSHIPPING  + "|" +
                          strADDTLINFO  + "|" +
                          strSALEPRICE  + "|" +
                          strSALE  + "|" +
 													strDOD  + "|" +   
 													strSTOCK  + "|" +   
 													str_on0  + "|" +   
 													str_on1  + "|" +   
 													str_os0  + "|" +    													 													 													 													                       
                          str_os1;

         strNewOrder = "Order." + iNumberOrdered;
         SetCookie(strNewOrder, dbUpdatedOrder, null, "/");
         SetCookie("NumberOrdered", iNumberOrdered, null, "/");
         notice = strQUANTITY + " " + strNAME + strAdded;
      }
   }

   if ( DisplayNotice )
      alert(notice);
}


//---------------------------------------------------------------------||
// FUNCTION:    getCookieVal                                           ||
// PARAMETERS:  offset                                                 ||
// RETURNS:     URL unescaped Cookie Value                             ||
// PURPOSE:     Get a specific value from a cookie                     ||
//---------------------------------------------------------------------||
function getCookieVal (offset) {
   var endstr = document.cookie.indexOf (";", offset);

   if ( endstr == -1 )
      endstr = document.cookie.length;
   return(unescape(document.cookie.substring(offset, endstr)));
}


//---------------------------------------------------------------------||
// FUNCTION:    FixCookieDate                                          ||
// PARAMETERS:  date                                                   ||
// RETURNS:     date                                                   ||
// PURPOSE:     Fixes cookie date, stores back in date                 ||
//---------------------------------------------------------------------||
function FixCookieDate (date) {
   var base = new Date(0);
   var skew = base.getTime();

   date.setTime (date.getTime() - skew);
}


//---------------------------------------------------------------------||
// FUNCTION:    GetCookie                                              ||
// PARAMETERS:  Name                                                   ||
// RETURNS:     Value in Cookie                                        ||
// PURPOSE:     Retrieves cookie from users browser                    ||
//---------------------------------------------------------------------||
function GetCookie (name) {
   var arg = name + "=";
   var alen = arg.length;
   var clen = document.cookie.length;
   var i = 0;

   while ( i < clen ) {
      var j = i + alen;
      if ( document.cookie.substring(i, j) == arg ) return(getCookieVal (j));
      i = document.cookie.indexOf(" ", i) + 1;
      if ( i == 0 ) break;
   }

   return(null);
}


//---------------------------------------------------------------------||
// FUNCTION:    SetCookie                                              ||
// PARAMETERS:  name, value, expiration date, path, domain, security   ||
// RETURNS:     Null                                                   ||
// PURPOSE:     Stores a cookie in the users browser                   ||
//---------------------------------------------------------------------||
function SetCookie (name,value,expires,path,domain,secure) {
   document.cookie = name + "=" + escape (value) +
                     ((expires) ? "; expires=" + expires.toGMTString() : "") +
                     ((path) ? "; path=" + path : "") +
                     ((domain) ? "; domain=" + domain : "") +
                     ((secure) ? "; secure" : "");
}


//---------------------------------------------------------------------||
// FUNCTION:    DeleteCookie                                           ||
// PARAMETERS:  Cookie name, path, domain                              ||
// RETURNS:     null                                                   ||
// PURPOSE:     Removes a cookie from users browser.                   ||
//---------------------------------------------------------------------||
function DeleteCookie (name,path,domain) {
   if ( GetCookie(name) ) {
      document.cookie = name + "=" +
                        ((path) ? "; path=" + path : "") +
                        ((domain) ? "; domain=" + domain : "") +
                        "; expires=";
   }
}


//---------------------------------------------------------------------||
// 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, weight) {
   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, "/");
      
      iPostalCode = GetCookie("POSTALCODE"); 
      if (iPostalCode)
      {
      iTotalWeight = GetCookie("TOTALSHIPPINGWEIGHT");
      iTotalWeight = iTotalWeight - weight;
      SetCookie ("TOTALSHIPPINGWEIGHT",iTotalWeight, null, "/");
		  }
     
      
      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;
      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);
      Token5 = database.indexOf("|", Token4+1);
      Token6 = database.indexOf("|", Token5+1);
      Token7 = database.indexOf("|", Token6+1);
      Token8 = database.indexOf("|", Token7+1);
      Token9 = database.indexOf("|", Token8+1);
      Token10 = database.indexOf("|", Token9+1);
      Token11 = database.indexOf("|", Token10+1);
      Token12 = database.indexOf("|", Token11+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, Token5 );
      fields[6] = database.substring( Token5+1, Token6 );
      fields[7] = database.substring( Token6+1, Token7 );
      fields[8] = database.substring( Token7+1, Token8 );
      fields[9] = database.substring( Token8+1, Token9 );
      fields[10] = database.substring( Token9+1, Token10 );
      fields[11] = database.substring( Token10+1, Token11 );
      fields[12] = database.substring( Token11+1, Token12 );
      fields[13] = database.substring( Token12+1, database.length );

      dbUpdatedOrder = fields[0] + "|" +
                       NewQuantity + "|" +
                       fields[2] + "|" +
                       fields[3] + "|" +
                       fields[4] + "|" +
                       fields[5] + "|" +
                       fields[6] + "|" +
                       fields[7] + "|" +
                       fields[8] + "|" +
                       fields[9] + "|" +
                       fields[10] + "|" +
                       fields[11] + "|" +
                       fields[12] + "|" +
                       fields[13];
                       
      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(shippingamount) {
   var iNumberOrdered = 0;    //Number of products ordered
   var fTotal         = 0;    //Total cost of order
   var fTax           = 0;    //Tax amount
   var fShipping      = 0;    //Shipping amount
   var strTotal       = "";   //Total cost formatted as money
   var strTax         = "";   //Total tax formatted as money
   var strShipping    = "";   //Total shipping formatted as money
   var strOutput      = "";   //String to be written to page
   var bDisplay       = true; //Whether to write string to the page (here for programmers)
   var LineTotal      = "0";   
   var strSTOCK = 0;
   var strQ = 0;


   iNumberOrdered = GetCookie("NumberOrdered");
   if ( iNumberOrdered == null )
      iNumberOrdered = 0;

   if ( bDisplay )
      strOutput = "<TABLE CLASS=\"nopcart\"><TR>" +
                  "<TD CLASS=\"nopheader\"></TD>" +
                  "<TD CLASS=\"nopheader\" COLSPAN=2><B>"+strDLabel+"</B></TD>" +
                  "<TD CLASS=\"nopheader\" ALIGN=CENTER><B>"+strQLabel+"</B></TD>" +
                  "<TD CLASS=\"nopheader\" ALIGN=CENTER><B>"+strPLabel+"</B></TD>" +
                  (DisplayShippingColumn?"<TD CLASS=\"nopheader\" ALIGN=RIGHT WIDTH=100><B>"+strSLabel+"</B></TD>":"") +
                  "<TD CLASS=\"nopheader\"></TD></TR>";

   if ( iNumberOrdered == 0 ) {
      strOutput += "<TR><TD COLSPAN=7 CLASS=\"nopentry\"><CENTER><BR><B>Your cart is empty</B><BR><BR></CENTER></TD></TR>";
      strOutput += "<input type=hidden name=\"CARTSUBTOTAL\" value=\"0.00\">"; 
      strOutput += "<input type=hidden name=shipping_handling_cart value=\"0.00\">";
			strOutput += "<input type=hidden name=COUNTRY value=\"\">"; 
			strOutput += "<input type=hidden name=REGION value=\"\">";
			
			strOutput += "<input type=hidden name=GSTTXT value=\"1\">"; 
			strOutput += "<input type=hidden name=GST value=\"1\">"; 
			strOutput += "<input type=hidden name=PSTTXT value=\"1\">"; 
			strOutput += "<input type=hidden name=PST value=\"1\">"; 
			strOutput += "<input type=hidden name=DISPLAYTOTAL value=\"1\">"; 															 
  
   }
	else
		{
			
   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);
      Token5 = database.indexOf("|", Token4+1);
      Token6 = database.indexOf("|", Token5+1);
      Token7 = database.indexOf("|", Token6+1);
			Token8 = database.indexOf("|", Token7+1); 
			Token9 = database.indexOf("|", Token8+1); 
			Token10 = database.indexOf("|", Token9+1); 
			Token11 = database.indexOf("|", Token10+1); 
			Token12 = database.indexOf("|", Token11+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 Weight
      fields[5] = database.substring( Token4+1, Token5 );					 // Additional Info
      fields[6] = database.substring( Token5+1, Token6 );					 // Sale Price
      fields[7] = database.substring( Token6+1, Token7 );					 // Sale
      fields[8] = database.substring( Token7+1, Token8 ); 				 // DOD
      fields[9] = database.substring( Token8+1, Token9 ); 				 // STOCK
      fields[10] = database.substring( Token9+1, Token10 ); 				 // Additional Info 1
      fields[11] = database.substring( Token10+1, Token11 ); 				 // Additional Info 2
      fields[12] = database.substring( Token11+1, Token12 ); 				 // Additional Info 3                      
			fields[13] = database.substring( Token12+1, database.length ); // Additional Info 4

      strSALEPRICE = fields[6];
      strSALE = fields[7];
      strDOD = fields[8];
      strSTOCK = fields[9];
      strQ = fields[1];
      str_on0 = fields[10];
      str_on1 = fields[11];
      str_os0 = fields[12];
      str_os1 = fields[13];
      
      
      if ( bDisplay ) {
         strOutput += "<TR><TD CLASS=\"nopentry\" ALIGN=CENTER width=100><img src='http://www.ras-book.com/images/"  + fields[0] + ".gif' width=100 border=0 style=padding:2px 2px 2px 2px;></TD>";

				strOutput += "<TD CLASS=\"nopentry\" width=380 COLSPAN=2 valign=top><span class=\"productname\">"  + fields[3] + "</span><BR><span class=\"small\">SKU # "  + fields[0] + "</span><BR>";

if (str_on0 != "")
{
            strOutput += " " + str_on0 + "";
}
if (str_on1 != "")
{
            strOutput += " : " + str_on1;
}
if (str_os0 != "")
{
            strOutput += " : " + str_os0;
}
if (str_os1 != "")
{
            strOutput += " : " + str_os1;
}
if (strSALE == "Y")
{
            strOutput += "<BR><font color=red><b>On Sale</b></font>";
}
if (strDOD == "Y")
{
            strOutput += "<font color=#d06020><b>Deal of the Day</b></font>";
}
else
{
            strOutput += "";
}	
if (parseInt(fields[1]) > parseInt(fields[9]))
{
            strOutput += "<BR><font size=1 color=#f67308><u><b>Note:</u> Your request cannot be completed in full, as the product you wish to purchase is not available in the quantity you requested. The quantity has been adjusted to the amount available in stock.</b></font>";
           fields[1] = fields[9];
}

				strOutput += "</TD>";


      fTotal     += (parseInt(fields[1]) * parseFloat(fields[2]) );
      fShipping  += (parseInt(fields[1]) * parseFloat(fields[4]) );
      LineTotal  = fields[1] * fields[2];   
      fTax        = (fTotal * TaxRate);

      strTotal    = moneyFormat(fTotal);
      strTax      = moneyFormat(fTax);
      strShipping = moneyFormat(fShipping);
			shippingamount = moneyFormat(shippingamount);

        strOutput += "<TD CLASS=\"nopentry\" ALIGN=CENTER valign=top><INPUT TYPE=TEXT NAME=Q SIZE=2 VALUE=\"" + fields[1] + "\" onChange=\"ChangeQuantity("+i+", this.value);\"></TD>";
        
        
        strOutput += "<TD CLASS=\"nopentry\" ALIGN=CENTER valign=top>";
        
if (strSALE == "Y")
{
            strOutput += "<font color=red><b>";
}
if (strDOD == "Y")
{
            strOutput += "<font color=#d06020><b>";
}
else
{
            strOutput += "";
}	       
displayprice =  fields[2];       
        strOutput += MonetarySymbol + moneyFormat(displayprice) + "</font></TD>";


               strOutput += "<TD CLASS=\"nopentry\" ALIGN=RIGHT valign=top>"+ MonetarySymbol + moneyFormat(LineTotal) + "</TD>";


         strOutput += "<TD CLASS=\"nopentry\" ALIGN=CENTER valign=top>&nbsp;&nbsp;<a href='cgi-bin/cart.pl' onClick=RemoveFromCart("+i+","+fields[4]+")><u>Remove</u></a></TD></TR>";
      }

      if ( AppendItemNumToOutput ) {
         strFooter = i;
      } else {
         strFooter = "";
      }
      if ( HiddenFieldsToCheckout ) {
  	
         strOutput += "<input type=hidden name=\"" + OutputItemId        + strFooter + "\" value=\"" + fields[0] + "\">";
         strOutput += "<input type=hidden name=\"" + OutputItemQuantity  + strFooter + "\" value=\"" + fields[1] + "\">";
         strOutput += "<input type=hidden name=\"" + OutputItemPrice     + strFooter + "\" value=\"" + fields[2] + "\">";
         strOutput += "<input type=hidden name=\"" + OutputItemName      + strFooter + "\" value=\"" + fields[3] + "\">";
         strOutput += "<input type=hidden name=\"" + OutputItemShipping  + strFooter + "\" value=\"" + fields[4] + "\">";

if (str_on0 != "")
{
           strOutput += "<input type=hidden name=\"" + OutputItemAddtlInfo + strFooter + "\" value=\""+ str_on0 +"\">";
}
if (str_on1 != "")
{
           strOutput += "<input type=hidden name=\"" + OutputItemAddtlInfo2 + strFooter + "\" value=\""+ str_on1 +"\">";
}
if (str_os0 != "")
{
           strOutput += "<input type=hidden name=\"" + OutputItemAddtlInfo3 + strFooter + "\" value=\""+ str_os0 +"\">";
}
if (str_os1 != "")
{
           strOutput += "<input type=hidden name=\"" + OutputItemAddtlInfo4 + strFooter + "\" value=\""+ str_os1 +"\">";
}

      }

   }

      countryarray = new Array;
      countryarray[0] = "-- Select Country --";
      countryarray[1] = "Canada";;
      countryarray[2] = "United States";


      regionarray = new Array;
      regionarray[0] = "-- Select Region --";
      regionarray[1] = "Alberta";
      regionarray[2] = "British Columbia";
      regionarray[3] = "Manitoba";
      regionarray[4] = "New Brunswick";
      regionarray[5] = "Newfoundland";
      regionarray[6] = "Nova Scotia";
      regionarray[7] = "Ontario";
      regionarray[8] = "PEI";
      regionarray[9] = "Quebec";
      regionarray[10] = "Saskatchewan";

   if ( bDisplay ) {
      strOutput += "<TR><TD CLASS=\"noptotal\" COLSPAN=3 ALIGN=RIGHT>&nbsp;</TD><TD CLASS=\"noptotal\" COLSPAN=2 ALIGN=RIGHT><font size=2 color=#686868><b>"+strSUB+"</b></TD>";
      strOutput += "<TD CLASS=\"noptotal\" COLSPAN=1 ALIGN=RIGHT><B><font size=2>" + strTotal + "</B></TD><TD CLASS=\"noptotal\">&nbsp;</TD>";
      strOutput += "</TR>";
      
      strOutput += "<TR><TD CLASS=\"noptotal\" COLSPAN=3 ALIGN=LEFT>&nbsp;</TD><TD CLASS=\"noptotal\" COLSPAN=2 ALIGN=RIGHT><font size=2 color=#686868><b>SHIPPING</b></TD>";


      if (shippingamount != "0.00")
      {
 
      strOutput += "<TD CLASS=\"noptotal\" COLSPAN=1 ALIGN=RIGHT><B><font size=2><span id=\"SHIPPING\">" + shippingamount + "</span></B></TD><TD CLASS=\"noptotal\">&nbsp;</TD>";
      }
      else
      {
		iShipping = GetCookie("SHIPPING");
		if (iShipping != null)
		{
		      iShipping = GetCookie("SHIPPING");

		      strOutput += "<TD CLASS=\"noptotal\" COLSPAN=1 ALIGN=RIGHT><B><font size=2><span id=\"SHIPPING\">" + iShipping + "</span></B></TD><TD CLASS=\"noptotal\">&nbsp;</TD>";
		}
		else
		{
			strOutput += "<TD CLASS=\"noptotal\" COLSPAN=1 ALIGN=RIGHT><B><font size=2><span id=\"SHIPPING\">" + shippingamount + "</span></B></TD><TD CLASS=\"noptotal\">&nbsp;</TD>";
		}

      }	

      strOutput += "</TR>";      

      strOutput += "<TR><TD CLASS=\"noptotal\" COLSPAN=3 ALIGN=LEFT>&nbsp;&nbsp;<font size=2 color=\"#331A00\">&nbsp;</font></TD><TD CLASS=\"noptotal\" COLSPAN=2 ALIGN=RIGHT><font size=2 color=#686868><b><span id=\"GSTTXT\">TAX</span></b></TD>";
      strOutput += "<TD CLASS=\"noptotal\" COLSPAN=1 ALIGN=RIGHT><B><font size=2><span id=\"GST\">0.00</span></B></TD><TD CLASS=\"noptotal\">&nbsp;</TD>";
      strOutput += "</TR>"; 
      strOutput += "<TR><TD CLASS=\"noptotal\" COLSPAN=3 ALIGN=LEFT>&nbsp;</TD><TD CLASS=\"noptotal\" COLSPAN=2 ALIGN=RIGHT><font size=2 color=#686868><b><span id=\"PSTTXT\"></span></b></TD>";
      strOutput += "<TD CLASS=\"noptotal\" COLSPAN=1 ALIGN=RIGHT><B><font size=2><span id=\"PST\"></span></B></TD><TD CLASS=\"noptotal\">&nbsp;</TD>";
      strOutput += "</TR>";       
      strOutput += "<TR><TD CLASS=\"noptotal\" COLSPAN=3 ALIGN=LEFT>&nbsp;";
 
      strOutput += "</TD><TD CLASS=\"noptotal\" COLSPAN=2 ALIGN=RIGHT><font size=2 color=#686868><b>TOTAL</b></TD>";

      strOutput += "<TD CLASS=\"noptotal\" COLSPAN=1 ALIGN=RIGHT><B><font size=2>" + MonetarySymbol + "<span id=\"DISPLAYTOTAL\">" + strTotal + "</span></B></TD><TD CLASS=\"noptotal\"><font size=2 color=#686868><b>&nbsp;&nbsp;CAD</b></TD>";
      strOutput += "</TR>";       

 			strOutput += "<input type=hidden name=\"CARTSUBTOTAL\" value=\""+ strTotal + "\">"; 
 			strOutput += "<input type=hidden name=\"SHIPPINGWEIGHT\" value=\""+ fShipping + "\">";
 			strOutput += "<input type=hidden name=\"GSTTOTAL\" value=\"\">";
 			strOutput += "<input type=hidden name=\"PSTTOTAL\" value=\"\">";
 			strOutput += "<input type=hidden name=\"CARTTOTAL\" value=\"\">";   
			strOutput += "<input type=hidden name=\"tax_cart\" value=\"\">"; 			
			


      if (shippingamount != "0.00")
      {
      strOutput += "<input type=hidden name=shipping_handling_cart value=\"" + shippingamount + "\">";
      strOutput += "<input type=hidden name=shipping_1 value=\"" + shippingamount + "\">";
      }
      else
      {
		iShipping = GetCookie("SHIPPING");
		if (iShipping != null)
		{
		      strOutput += "<input type=hidden name=shipping_handling_cart value=\"" + iShipping + "\">";
		      strOutput += "<input type=hidden name=shipping_1 value=\"" + iShipping + "\">";
		        }
	        else
	      	{
		      strOutput += "<input type=hidden name=shipping_handling_cart value=\"" + shippingamount + "\">";
		}
      }		


			strOutput += "<input type=hidden name=\"noshipping\" value=\"2\">";
      strOutput += "</TABLE>";

      if ( HiddenFieldsToCheckout ) {
         strOutput += "<input type=hidden name=\""+OutputOrderSubtotal+"\" value=\""+ strTotal + "\">";
         strOutput += "<input type=hidden name=\""+OutputOrderShipping+"\" value=\""+ strShipping + "\">";
         strOutput += "<input type=hidden name=\""+OutputOrderTax+"\"      value=\""+ strTax + "\">";
         strOutput += "<input type=hidden name=\""+OutputOrderTotal+"\"    value=\""+ moneyFormat((fTotal + fShipping + fTax + shippingamount)) + "\">";
      }
   }
   g_TotalCost = (fTotal + fShipping + fTax);


         strOutput += "<BR>";
         strOutput += "<table width=100%><td style=\"height:1px; background-image: url(images/dotted.gif)\";></td></tr><tr><td><img src=\"images/spacer.gif\" height=10></table>";													



         strOutput += "<center>";
         strOutput += "<table width=100% cellspacing=4>";
         strOutput += "<tr><td width=\"40%\" valign=middle align=left>";
         strOutput += "<font size=2 color=#331A00><b>1. Calculate your Taxes</b></font>";
         strOutput += "<center>";
         strOutput += "<font size=1><b>Select your country and region:</b></font><BR>";
         strOutput += "<select name=\"COUNTRY\" onChange=\"CalculateTax();\">";

     iCountry = GetCookie("COUNTRY"); 
  		var x=0;
      for ( x = 0; x < 3; x++ )
      {
				if (iCountry == x)
				{
	      strOutput += "<option value='" + x + "' selected>" + countryarray[x] + "</option>";
	      }
        else
      	{
      	strOutput += "<option value='" + x + "'>" + countryarray[x] + "</option>";
      	}
      }
      strOutput += "</select><br><select name=\"REGION\" onChange=\"CalculateTax();\">";
      
      iRegion = GetCookie("REGION"); 
  		var y=0;
      for ( y = 0; y < 11; y++ )
      {
				if (iRegion == y)
				{
	      strOutput += "<option value='" + y + "' selected>" + regionarray[y] + "</option>";
	      }
        else
      	{
      	strOutput += "<option value='" + y + "'>" + regionarray[y] + "</option>";
      	}
      }      
      strOutput += "</select></TD>";

         strOutput += "</center>";
         strOutput += "</td>";
         strOutput += "</form>";         
         strOutput += "<td class=Vert_Dot><img src=\"images/spacer.gif\" height=\"60\" width=\"2\" border=\"0\"></td>";
         strOutput += "<td width=\"30%\" valign=middle align=left>";
         strOutput += "<font size=2 color=#331A00>&nbsp;<b>2. Calculate your Shipping</b></font>";
         strOutput += "<center>";
         strOutput += "<font size=1><b>Please enter your postal code:</b></font><BR>";
         strOutput += "<form name=\"shippingform\" action=\"/cart.pl\" method=\"post\"\"> ";
         strOutput += "<input type=hidden name=TOTALSHIPPINGWEIGHT value=\"" + fShipping + "\">";
      iPostalCode = GetCookie("POSTALCODE"); 
      if (iPostalCode)
      {
      strOutput += "<input type=text name=postalcode size=16 value=\"" + iPostalCode + "\" onChange=\"CalculateShipping();\">";
		  }
		else
      {
      strOutput += "<input type=text name=postalcode size=16 value=\"\" onChange=\"CalculateShipping();\">";
		  }			
        
         strOutput += "<br><input type=image src=\"/images/go.jpg\" onClick=\"CalculateShipping();\"></center>";
         strOutput += "</td>";
         strOutput += "</form>";         
         strOutput += "<td class=Vert_Dot><img src=\"images/spacer.gif\" height=\"60\" width=\"2\" border=\"0\"></td>";
         strOutput += "<td width=\"30%\" valign=middle align=left>";
         strOutput += "<font size=2 color=#331A00>&nbsp;<b>3. Checkout</b></font>";
         strOutput += "<center> <INPUT type=hidden name=fromform value=\"false\">";         
         strOutput += "<a href=\"#\" onClick=\"javascript:CheckTax(); return false;\"><img src=\"images/paypal_checkout.gif\" name=\"checkout\" alt=\"Make payments with PayPal - it's fast, free and secure!\" border=0></a>";
}
         strOutput += "</td>";
         strOutput += "</tr>";
         strOutput += "</table>";
         strOutput += "</center>";


   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;
}



//=====================================================================||
//               END NOP Design SmartPost Shopping Cart                ||
//=====================================================================||

//---------------------------------------------------------------------||
// FUNCTION:    WriteQuantity                                          ||
// PARAMETERS:  Null                                                   ||
// RETURNS:     Number of cart items                                   ||
// PURPOSE:     Draws current cart product table on HTML page          ||
//---------------------------------------------------------------------||
function WriteQuantity( ) {
   var iNumberOrdered = 0;    //Number of products ordered
   var fTotal         = 0;    //Total cost of order
   var fTax           = 0;    //Tax amount
   var fShipping      = 0;    //Shipping amount
   var strTotal       = "";   //Total cost formatted as money
   var strTax         = "";   //Total tax formatted as money
   var strShipping    = "";   //Total shipping formatted as money
   var strOutput      = "";   //String to be written to page
   var bDisplay       = true; //Whether to write string to the page (here for programmers)

   iNumberOrdered = GetCookie("NumberOrdered");
   if ( iNumberOrdered == null )
      iNumberOrdered = 0;

   document.write(iNumberOrdered);
   document.close();
}

//---------------------------------------------------------------------||
// FUNCTION:    WriteQuantity                                          ||
// PARAMETERS:  Null                                                   ||
// RETURNS:     Number of cart items                                   ||
// PURPOSE:     Draws current cart product table on HTML page          ||
//---------------------------------------------------------------------||
function WriteAmount( ) {
   var iNumberOrdered = 0;    //Number of products ordered
   var fTotal         = 0;    //Total cost of order
   var fTax           = 0;    //Tax amount
   var fShipping      = 0;    //Shipping amount
   var strTotal       = "";   //Total cost formatted as money
   var strTax         = "";   //Total tax formatted as money
   var strShipping    = "";   //Total shipping formatted as money
   var strOutput      = "";   //String to be written to page
   var bDisplay       = true; //Whether to write string to the page (here for programmers)

   iNumberOrdered = GetCookie("NumberOrdered");
   if ( iNumberOrdered == null )
      iNumberOrdered = 0;



   if ( iNumberOrdered == 0 ) {
      strOutput += "0.00";
   }

   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);
      Token5 = database.indexOf("|", Token4+1);
      Token6 = database.indexOf("|", Token5+1);
      Token7 = database.indexOf("|", Token6+1);
			Token8 = database.indexOf("|", Token7+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, Token5 );					 // Additional Info
      fields[6] = database.substring( Token5+1, Token6 );					 // Sale Price
      fields[7] = database.substring( Token6+1, Token7 );					 // Sale
      fields[8] = database.substring( Token7+1, Token8 ); 				 // DOD
			fields[9] = database.substring( Token8+1, database.length ); // STOCK

      strSALEPRICE = fields[6];
      strSALE = fields[7];
      strDOD = fields[8];
      strSTOCK = fields[9];
      strQ = fields[1];
      
if (parseInt(fields[1]) > parseInt(fields[9]))
{
            fields[1] = strSTOCK;

}

      fTotal     += (parseInt(fields[1]) * parseFloat(fields[2]) );
      fShipping  += (parseInt(fields[1]) * parseFloat(fields[4]) );
      LineTotal  = fields[1] * fields[2];   
      fTax        = (fTotal * TaxRate);
      strTotal    = moneyFormat(fTotal);
      strTax      = moneyFormat(fTax);
      strShipping = moneyFormat(fShipping);



   }

   if ( bDisplay ) {
      strOutput += strTotal;



   }
   g_TotalCost = (fTotal + fShipping + fTax);

   document.write(strOutput);
   document.close();
}

//---------------------------------------------------------------------||
// FUNCTION:    CheckTax                                               ||
// PARAMETERS:  Null                                                   ||
// RETURNS:     Taxes                                                  ||
// PURPOSE:     Check if taxes have been selected                      ||
//---------------------------------------------------------------------||
function CheckTax() {
   if (document.cart.COUNTRY.value == "0") {
   alert ("Before you checkout select your country and region to calcuate your taxes.");	
   return false;
  }
   if ((document.cart.COUNTRY.value == "1") && (document.cart.REGION.value == "0"))  {
   alert ("Before you checkout select your country and region to calcuate your taxes.");	
   return false;
  }  
   if (document.shippingform.postalcode.value == "") {
   alert ("Before you checkout enter your postal code to calcuate your shipping.");	
   return false;
  }   
  
  if (document.getElementById("SHIPPING").innerHTML == "0.00") {
  alert ("Before you checkout we needed to re-calculate your shipping. Please try again.");	
  return false;
  }
		document.cart.action="https://www.paypal.com/row/cgi-bin/webscr";
		document.cart.submit();
return true;
}

//---------------------------------------------------------------------||
// FUNCTION:    CalculateTax                                           ||
// PARAMETERS:  Null                                                   ||
// RETURNS:     Taxes                                                  ||
// PURPOSE:     Draws taxes on HTML page                               ||
//---------------------------------------------------------------------||
function CalculateTax() {

	 var DisplayTotal = 0;
   var CartSubTotal = document.cart.CARTSUBTOTAL.value;
   var temp_shipping = document.cart.shipping_handling_cart.value;
   var DisplayGST = 0;
	 var DisplayPST = 0;
	 
   cCountry = GetCookie("COUNTRY");
   cRegion = GetCookie("REGION");		 
	 
//	 if (cCountry != null)
//	 {
//	 	document.cart.COUNTRY.value = cCountry;
//	 }
//	 if (cRegion != null)
//	 {
//	 	document.cart.REGION.value = cRegion;
//	 }
	 
// Calculate Canada-Ontario Taxes
   if ((document.cart.COUNTRY.value == "1" ) && (document.cart.REGION.value == "7" )) {
			//GST
      document.getElementById("GSTTXT").innerHTML="HST (13%)";  
      DisplayGST = parseFloat(CartSubTotal) * 0.13;
      DisplayGST = DisplayGST.toFixed(2);
      document.getElementById("GST").innerHTML=DisplayGST;      
      DisplayTotal = parseFloat(CartSubTotal) + parseFloat(DisplayGST) + parseFloat(temp_shipping);
      DisplayTotal = DisplayTotal.toFixed(2);
      document.getElementById("DISPLAYTOTAL").innerHTML=DisplayTotal; 
      //PST
      document.getElementById("PSTTXT").innerHTML=""; 
      document.getElementById("PST").innerHTML="";  
      //Output
      document.cart.GSTTOTAL.value = DisplayGST;
      document.cart.PSTTOTAL.value = "0.00";
      document.cart.CARTTOTAL.value = DisplayTotal;  
    }

// Calculate Canada-Alberta & Manitoba Taxes
   if ((document.cart.COUNTRY.value == "1" ) && (document.cart.REGION.value == "1" ) || (document.cart.REGION.value == "3" )) {
			//GST
      document.getElementById("GSTTXT").innerHTML="GST (5%)";  
      DisplayGST = parseFloat(CartSubTotal) * 0.05;
      DisplayGST = DisplayGST.toFixed(2);
      document.getElementById("GST").innerHTML=DisplayGST;      
      DisplayTotal = parseFloat(CartSubTotal) + parseFloat(DisplayGST) + parseFloat(temp_shipping);
      DisplayTotal = DisplayTotal.toFixed(2);
      document.getElementById("DISPLAYTOTAL").innerHTML=DisplayTotal; 
      //PST
      document.getElementById("PSTTXT").innerHTML=""; 
      document.getElementById("PST").innerHTML="";  
      //Output
      document.cart.GSTTOTAL.value = DisplayGST;
      document.cart.PSTTOTAL.value = "0.00";
      document.cart.CARTTOTAL.value = DisplayTotal;
       }

// Calculate Canada-British Columbia Taxes
  if ((document.cart.COUNTRY.value == "1" ) && (document.cart.REGION.value == "2" )) {
			//GST
      document.getElementById("GSTTXT").innerHTML="HST (12%)";  
      DisplayGST = parseFloat(CartSubTotal) * 0.12;
      DisplayGST = DisplayGST.toFixed(2);
      document.getElementById("GST").innerHTML=DisplayGST;      
      DisplayTotal = parseFloat(CartSubTotal) + parseFloat(DisplayGST) + parseFloat(temp_shipping);
      DisplayTotal = DisplayTotal.toFixed(2);
      document.getElementById("DISPLAYTOTAL").innerHTML=DisplayTotal; 
      //PST
      document.getElementById("PSTTXT").innerHTML=""; 
      document.getElementById("PST").innerHTML="";  
      //Output
      document.cart.GSTTOTAL.value = DisplayGST;
      document.cart.PSTTOTAL.value = "0.00";
      document.cart.CARTTOTAL.value = DisplayTotal;  
       }

// Calculate Canada-New Brunswick, Newfoundland, Nova Scotia Taxes
   if ((document.cart.COUNTRY.value == "1" ) && (document.cart.REGION.value == "4" ) || (document.cart.REGION.value == "5" ) || (document.cart.REGION.value == "6" )  ) {
			//GST
      document.getElementById("GSTTXT").innerHTML="HST (13%)";  
      DisplayGST = parseFloat(CartSubTotal) * 0.13;
      DisplayGST = DisplayGST.toFixed(2);
      document.getElementById("GST").innerHTML=DisplayGST;      
      DisplayTotal = parseFloat(CartSubTotal) + parseFloat(DisplayGST) + parseFloat(temp_shipping);
      DisplayTotal = DisplayTotal.toFixed(2);
      document.getElementById("DISPLAYTOTAL").innerHTML=DisplayTotal; 
      //PST
      document.getElementById("PSTTXT").innerHTML=""; 
      document.getElementById("PST").innerHTML="";  
      //Output
      document.cart.GSTTOTAL.value = DisplayGST;
      document.cart.PSTTOTAL.value = "0.00";
      document.cart.CARTTOTAL.value = DisplayTotal;      
       }

// Calculate Canada-PEI Taxes
  if ((document.cart.COUNTRY.value == "1" ) && (document.cart.REGION.value == "8" )) {
			//GST
      document.getElementById("GSTTXT").innerHTML="GST (5%)";  
      DisplayGST = parseFloat(CartSubTotal) * 0.05;
      DisplayGST = DisplayGST.toFixed(2);
      document.getElementById("GST").innerHTML=DisplayGST;      
      DisplayTotal = parseFloat(CartSubTotal) + parseFloat(DisplayGST) + parseFloat(temp_shipping);
      DisplayTotal = DisplayTotal.toFixed(2);
      document.getElementById("DISPLAYTOTAL").innerHTML=DisplayTotal; 
      //PST
      document.getElementById("PSTTXT").innerHTML="PST (10%)"; 
      DisplayPST = parseFloat(CartSubTotal) * 0.10;
      DisplayPST = DisplayPST.toFixed(2);
      document.getElementById("PST").innerHTML=DisplayPST;  
      DisplayTotal = parseFloat(CartSubTotal) + parseFloat(DisplayGST) + parseFloat(DisplayPST) + parseFloat(temp_shipping);
      DisplayTotal = DisplayTotal.toFixed(2);
      document.getElementById("DISPLAYTOTAL").innerHTML=DisplayTotal; 
      //Output
      document.cart.GSTTOTAL.value = DisplayGST;
      document.cart.PSTTOTAL.value = DisplayPST;
      document.cart.CARTTOTAL.value = DisplayTotal;
       }

// Calculate Canada-Quebec Taxes
  if ((document.cart.COUNTRY.value == "1" ) && (document.cart.REGION.value == "9" )) {
			//GST
      document.getElementById("GSTTXT").innerHTML="GST (5%)";  
      DisplayGST = parseFloat(CartSubTotal) * 0.05;
      DisplayGST = DisplayGST.toFixed(2);
      document.getElementById("GST").innerHTML=DisplayGST;      
      DisplayTotal = parseFloat(CartSubTotal) + parseFloat(DisplayGST) + parseFloat(temp_shipping);
      DisplayTotal = DisplayTotal.toFixed(2);
      document.getElementById("DISPLAYTOTAL").innerHTML=DisplayTotal; 
      //PST
      document.getElementById("PSTTXT").innerHTML="QST (7.5%)"; 
      DisplayPST = (parseFloat(CartSubTotal) + parseFloat(DisplayGST)) * 0.075;
      DisplayPST = DisplayPST.toFixed(2);
      document.getElementById("PST").innerHTML=DisplayPST;  
      DisplayTotal = parseFloat(CartSubTotal) + parseFloat(DisplayGST) + parseFloat(DisplayPST) + parseFloat(temp_shipping);
      DisplayTotal = DisplayTotal.toFixed(2);
      document.getElementById("DISPLAYTOTAL").innerHTML=DisplayTotal; 
      //Output
      document.cart.GSTTOTAL.value = DisplayGST;
      document.cart.PSTTOTAL.value = DisplayPST;
      document.cart.CARTTOTAL.value = DisplayTotal;
       }

// Calculate Canada-Saskatchewan Taxes
  if ((document.cart.COUNTRY.value == "1" ) && (document.cart.REGION.value == "10" )) {
			//GST
      document.getElementById("GSTTXT").innerHTML="GST (5%)";  
      DisplayGST = parseFloat(CartSubTotal) * 0.05;
      DisplayGST = DisplayGST.toFixed(2);
      document.getElementById("GST").innerHTML=DisplayGST;      
      DisplayTotal = parseFloat(CartSubTotal) + parseFloat(DisplayGST) + parseFloat(temp_shipping);
      DisplayTotal = DisplayTotal.toFixed(2);
      document.getElementById("DISPLAYTOTAL").innerHTML=DisplayTotal; 
      //PST
      document.getElementById("PSTTXT").innerHTML=""; 
      document.getElementById("PST").innerHTML="";  
      //Output
      document.cart.GSTTOTAL.value = DisplayGST;
      document.cart.PSTTOTAL.value = "0.00";
      document.cart.CARTTOTAL.value = DisplayTotal;
       }




// Calculate USA or None Taxes
    if ((document.cart.COUNTRY.value == "0" ) || (document.cart.COUNTRY.value == "2" )) {
			//GST
      document.getElementById("GSTTXT").innerHTML="TAX"; 
      document.getElementById("GST").innerHTML="0.00"; 
      //PST
      document.getElementById("PSTTXT").innerHTML=""; 
      document.getElementById("PST").innerHTML=""; 
      document.getElementById("DISPLAYTOTAL").innerHTML=CartSubTotal; 
      document.cart.GSTTOTAL.value = "0.00";
      document.cart.PSTTOTAL.value = "0.00";
      DisplayTotal = parseFloat(CartSubTotal) + parseFloat(temp_shipping);
      DisplayTotal = DisplayTotal.toFixed(2);      
      document.cart.CARTTOTAL.value = DisplayTotal;       
      document.getElementById("DISPLAYTOTAL").innerHTML=DisplayTotal;
		}

    if (document.cart.COUNTRY.value == "2" )
    	{document.cart.REGION.disabled = 1;}
 		else
  	  {document.cart.REGION.disabled = 0;}   

   iNumberOrdered = GetCookie("NumberOrdered");
   if ( iNumberOrdered == null )
      iNumberOrdered = 0;
      
if (iNumberOrdered == 0)
{
			//GST
      document.getElementById("GSTTXT").innerHTML="TAX"; 
      document.getElementById("GST").innerHTML="0.00"; 
      //PST
      document.getElementById("PSTTXT").innerHTML=""; 
      document.getElementById("PST").innerHTML=""; 
      document.cart.GSTTOTAL.value = "0.00";
      document.getElementById("DISPLAYTOTAL").innerHTML=CartSubTotal; 
      document.cart.PSTTOTAL.value = "0.00";
      DisplayTotal = parseFloat(CartSubTotal) + parseFloat(temp_shipping);
      DisplayTotal = DisplayTotal.toFixed(2);      
      document.cart.CARTTOTAL.value = DisplayTotal;       
			document.getElementById("DISPLAYTOTAL").innerHTML=DisplayTotal;      
		}     

   TOTALTAX = parseFloat(DisplayGST) + parseFloat(DisplayPST);
   TOTALTAX = TOTALTAX.toFixed(2);   
   document.cart.tax_cart.value = TOTALTAX;
	 CountryCookie = document.cart.COUNTRY.value;
	 RegionCookie = document.cart.REGION.value;
   SetCookie ("COUNTRY",CountryCookie, null, "/");
   SetCookie ("REGION",RegionCookie, null, "/");
   

   SetCookie ("SHIPPING",temp_shipping, null, "/");
   var temp_weight = document.shippingform.TOTALSHIPPINGWEIGHT.value;
   SetCookie ("TOTALSHIPPINGWEIGHT",temp_weight, null, "/");
    

   document.close();
} 


//---------------------------------------------------------------------||
// FUNCTION:    CalculateShipping                                      ||
// PARAMETERS:  Null                                                   ||
// RETURNS:     Taxes                                                  ||
// PURPOSE:     Draws taxes on HTML page                               ||
//---------------------------------------------------------------------||
function CalculateShipping() {
	 
   cPostalCode = GetCookie("POSTALCODE");
	 PostalCodeCookie = document.shippingform.postalcode.value;
   SetCookie ("POSTALCODE",PostalCodeCookie, null, "/");
   document.shippingform.submit();	  
   document.close();
} 

