//=====================================================================||
//              NOPCART SHORT VERSION                                  ||
//=====================================================================||
//               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.5.0.draft   Feb 4, 2004                   ||
// Drop in replacement for V.4.4.0                                     ||
// MUST ADD A CART MANAGEMENT MODULE TO                                ||
//                              managecart.html and checkout.html      ||
//=====================================================================||
//                INSTALLED MODIFICATIONS
//
// product selector
// 2 Taxes
// Non-Taxable fields
// Quantity Limit field
// Product cost extended total or shipping column (Toggle)
// "Columnar" cookies
// Maximum Cart item content set by variable
// Change Quantity in managecart.html separate function
// Unable to order negative or fractional quantities
// odd/even background change in Cart tables
//
//---------------------------------------------------------------------||
//                       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 or extended price ||
// * 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.                    ||
// * FstRate: Federal Sales Tax Rate set and calculated separately from||
//   Provincial/State Tax.  FST row not shown when FstRate = 0         ||  
// * TaxRate: number, your area's current tax rate, ie: if your tax    ||
//   rate was 7.5%, you would set TaxRate = 0.075                      ||
// * ShippingFSTaxRate and ShippingTaxRate: Tax on shipping calculated ||
//   independently of tax on items. Useful when shipping out of country||
// * TaxByRegion: true/false, when set to true, the user is prompted   ||
//   with TaxablePrompt to determine if they should be charged tax.    ||
//   In North America, this is useful to charge tax to those people    ||
//   who live in a particular Province or 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, or set to 0.01 to prevent checkout with empty cart.   ||
// * 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     = '£'; 
MonetarySymbol        = '$';
DisplayNotice         = false;
DisplayShippingColumn = false;	// false displays product total (extension)
DisplayShippingRow    = false;		// toggles shipping row on or off
DisplayTaxRow         = false;		// TaxByRegion must also be false
TaxByRegion           = false;		// if true overrides DisplayTaxRow = false setting 
FstRate               = 0;		// FST row is off when FstRate = 0
TaxRate               = 0;   // State or Provincial Sales Tax Rate
ShippingFSTaxRate     = 0;   // Federal Sales Tax Rate applied to shipping costs
ShippingTaxRate       = 0;   // State Sales Tax Rate applied to shipping costs
WeightUnits           = "lbs"   // Unit of measurement oz, lbs, Kilograms, grams
TaxPrompt             = 'For tax purposes, please select if you are an Ontario resident before continuing';
TaxablePrompt         = 'Ontario'; //Tax by Region Radio button
NonTaxablePrompt      = 'Others';  //Tax by Region Radio button
MinimumOrder          =  0.02;	  // prevents Checkout below minimum Order amount
MinimumOrderPrompt    = '\nOpps! Your Cart is either empty or below the minimum order!\n\n Please increase your order before going through the checkout.\n\n';

//Payment Processor Options:
PaymentProcessor      = 'an';

//Options for Programmers:
OutputItemId           = 'ID_';
OutputItemQuantity     = 'QUANTITY_';
OutputItemPrice        = 'PRICE_';
OutputItemName         = 'NAME_';
OutputItemShipping     = 'SHIPPING_';
OutputItemAddtlInfo    = 'ADDTLINFO_';
OutputOrderSubtotal    = 'SUBTOTAL';
OutputOrderShipping    = 'SHIPPING';
OutputOrderZone        = "ZONE"
OutputOrderFst         = 'FST';
OutputOrderTax         = 'TAX';
OutputOrderTotal       = 'TOTAL';
CartMaxItems           =  20;				// Default Maximum number if items allowed in cart 
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.";
strEmpty  = "Your cart is empty!";
strILabel = "Prod Id";
strDLabel = "Description";
strQLabel = "Qty";
strPLabel = "Price each";
strPTLabel= "Price total";
strRLabel = "Remove";
strSLabel = "Shipping";
strWLabel = "Weight";
strRButton= "Remove";
strSUB    = "SUBTOTAL";
strSHIP   = "SHIPPING";
strFST    = "FEDERAL SALES TAX";
strTAX    = "PROVINCIAL SALES TAX";
strTOT    = "TOTAL";
strErrQty = "Invalid Quantity.";
strNewQty = 'Please enter new quantity:';
strSpace  = "   ";
   bLanguageDefined = true;
}

//---------------------------------------------------------------------||
//                       Array Variables                               ||
//                     -------------------                             ||
// These Variables are used in storing the cart contents in cookies    ||
// and translating the cookie strings into arrays for calculations.    ||
//---------------------------------------------------------------------||

ItemId         = new Array(CartMaxItems+1);
ItemQuantity   = new Array(CartMaxItems+1);
ItemPrice      = new Array(CartMaxItems+1);
ItemName       = new Array(CartMaxItems+1);
ItemShipping   = new Array(CartMaxItems+1);
ItemQtyLimit   = new Array(CartMaxItems+1);
ItemAddtlInfo  = new Array(CartMaxItems+1);
ItemAddtlInfo2 = new Array(CartMaxItems+1);
ItemAddtlInfo3 = new Array(CartMaxItems+1);
ItemUserEntry  = new Array(CartMaxItems+1);
ItemUserEntry2 = new Array(CartMaxItems+1);
ItemFsTx       = new Array(CartMaxItems+1);
ItemPsTx       = new Array(CartMaxItems+1);
ItemWeight     = new Array(CartMaxItems+1);
cookieLen      = "";
cooklen        = "";
strItemId         = "";
strItemQuantity   = "";
strItemPrice      = "";
strItemName       = "";
strItemShipping   = "";
strItemQtyLimit   = "";
strItemAddtlInfo  = "";
strItemAddtlInfo2 = "";
strItemAddtlInfo3 = "";
strItemUserEntry  = "";
strItemUserEntry2 = "";
strAddInfo        = "";
strItemFsTx       = "";
strItemPsTx       = "";
strItemWeight     = "";
strOutput         = ""

iNumberOrdered    = 0;

CartMaxItems      = 20;

g_TotalCost       = 0.00;

strID_NUM         = "";
strFSTAXABLE      = true ;
strTAXABLE        = true ;
strQTYLIMIT       = false;
strQUANTITY       = "";
strPRICE          = "";
strNAME           = "";
strSHIPPING       = "";
strADDTLINFO      = "";
strADDTLINFO2     = "";
strADDTLINFO3     = ""; 
strUSERENTRY      = "";
strUSERENTRY2     = "";
strWEIGHT         = "";


//---------------------------------------------------------------------||
// FUNCTION:    CKquantity                                             ||
// PARAMETERS:  Number string to check                                 ||
// RETURNS:     Quantity as a number, and possible alert               ||
// PURPOSE:     Make sure quantity is represented as a positive 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:	  ReadCookie                                             ||
// PARAMETERS:  Name                                                   ||
// RETURNS:     Value in Cookies translated into arrays                ||
// PURPOSE:     Calls GetCookie()                                      ||
//              Calculates how many items cart will hold               ||
//              based on length of cookie	                             ||
//---------------------------------------------------------------------||
	function ReadCookie(){

	  strItemId          = "";
    strItemQuantity    = "";
    strItemPrice       = "";
    strItemName        = "";
    strItemShipping    = "";
    strItemQtyLimit    = "";
    strItemAddtlInfo   = "";
		strItemAddtlInfo2  = "";
		strItemAddtlInfo3  = "";
		strItemUserEntry   = "";
		strItemUserEntry2  = "";
    strItemFsTx        = "";
    strItemPsTx        = "";
    strItemWeight      = "";
    Token              = new Array(CartMaxItems+1);
    fields             = new Array(CartMaxItems+1);
    

   iNumberOrdered = GetCookie("NumberOrdered");
   if ( iNumberOrdered == null || iNumberOrdered == 0) {
      iNumberOrdered = 0;
			return; 
      } else {  
         strItemId          = GetCookie("ItemId");
         cookieLen          = cooklen;
         strItemQuantity    = GetCookie("QuantY");
				 strItemPrice       = GetCookie("ItemPrice");
         strItemName        = GetCookie("ItemName");
         strItemAddtlInfo   = GetCookie("ItemAddtlInfo");
         strItemAddtlInfo2  = GetCookie("ItemAddtlInfo2");
         strItemAddtlInfo3  = GetCookie("ItemAddtlInfo3");
         strItemUserEntry   = GetCookie("ItemUserEntry");
         strItemUserEntry2  = GetCookie("ItemUserEntry2");
         strItemShipping    = GetCookie("ItemShipping");
         strItemQtyLimit    = GetCookie("ItemQtyLimit");
	       strItemFsTx        = GetCookie("ItemFsTx1");
         strItemPsTx        = GetCookie("ItemPsTx2");
         strItemWeight      = GetCookie("ItemWeight");

			Token[0]  = strItemId.indexOf("|", 0);
      fields[0] = strItemId.substring( 0, Token[0] ); 
  		ItemId[0] = fields[0];
   for ( i = 1; i <= iNumberOrdered; i++ ) {
      Token[i]  = strItemId.indexOf("|", Token[i-1]+1);
      fields[i] = strItemId.substring( Token[i-1]+1, Token[i]);
  		ItemId[i] = fields[i];
  }
      Token[0]  = strItemQuantity.indexOf("|", 0);
      fields[0] = strItemQuantity.substring( 0, Token[0] ); 
  		ItemQuantity[0] = fields[0];
   for ( i = 1; i <= iNumberOrdered; i++ ) {
      Token[i]  = strItemQuantity.indexOf("|", Token[i-1]+1);
      fields[i] = strItemQuantity.substring( Token[i-1]+1, Token[i]);
  		ItemQuantity[i] = fields[i];
  }
      Token[0]  = strItemPrice.indexOf("|", 0);
      fields[0] = strItemPrice.substring( 0, Token[0] ); 
  		ItemPrice[0] = fields[0];
   for ( i = 1; i <= iNumberOrdered; i++ ) {
      Token[i]  = strItemPrice.indexOf("|", Token[i-1]+1);
      fields[i] = strItemPrice.substring( Token[i-1]+1, Token[i]);
  		ItemPrice[i] = fields[i];
  }
      Token[0]  = strItemName.indexOf("|", 0);
      fields[0] = strItemName.substring( 0, Token[0] ); 
  		ItemName[0] = fields[0];
   for ( i = 1; i <= iNumberOrdered; i++ ) {
      Token[i]  = strItemName.indexOf("|", Token[i-1]+1);
      fields[i] = strItemName.substring( Token[i-1]+1, Token[i]);
  		ItemName[i] = fields[i];
  }
      Token[0]  = strItemAddtlInfo.indexOf("|", 0);
      fields[0] = strItemAddtlInfo.substring( 0, Token[0] ); 
  		ItemAddtlInfo[0] = fields[0];
   for ( i = 1; i <= iNumberOrdered; i++ ) {
      Token[i]  = strItemAddtlInfo.indexOf("|", Token[i-1]+1);
      fields[i] = strItemAddtlInfo.substring( Token[i-1]+1, Token[i]);
  		ItemAddtlInfo[i] = fields[i];
  }
      Token[0]  = strItemAddtlInfo2.indexOf("|", 0);
      fields[0] = strItemAddtlInfo2.substring( 0, Token[0] ); 
  		ItemAddtlInfo[0] = fields[0];
   for ( i = 1; i <= iNumberOrdered; i++ ) {
      Token[i]  = strItemAddtlInfo2.indexOf("|", Token[i-1]+1);
      fields[i] = strItemAddtlInfo2.substring( Token[i-1]+1, Token[i]);
  		ItemAddtlInfo2[i] = fields[i];
  }
      Token[0]  = strItemAddtlInfo3.indexOf("|", 0);
      fields[0] = strItemAddtlInfo3.substring( 0, Token[0] ); 
  		ItemAddtlInfo[0] = fields[0];
   for ( i = 1; i <= iNumberOrdered; i++ ) {
      Token[i] = strItemAddtlInfo3.indexOf("|", Token[i-1]+1);
      fields[i] = strItemAddtlInfo3.substring( Token[i-1]+1, Token[i]);
  		ItemAddtlInfo3[i] = fields[i];
  }
      Token[0]  = strItemUserEntry.indexOf("|", 0);
      fields[0] = strItemUserEntry.substring( 0, Token[0] ); 
  		ItemAddtlInfo[0] = fields[0];
   for ( i = 1; i <= iNumberOrdered; i++ ) {
      Token[i]  = strItemUserEntry.indexOf("|", Token[i-1]+1);
      fields[i] = strItemUserEntry.substring( Token[i-1]+1, Token[i]);
  		ItemUserEntry[i] = fields[i];
  }
      Token[0]  = strItemUserEntry2.indexOf("|", 0);
      fields[0] = strItemUserEntry2.substring( 0, Token[0] ); 
  		ItemAddtlInfo[0] = fields[0];
   for ( i = 1; i <= iNumberOrdered; i++ ) {
      Token[i]  = strItemUserEntry2.indexOf("|", Token[i-1]+1);
      fields[i] = strItemUserEntry2.substring( Token[i-1]+1, Token[i]);
  		ItemUserEntry2[i] = fields[i];
  }
      Token[0]  = strItemShipping.indexOf("|", 0);
      fields[0] = strItemShipping.substring( 0, Token[0] ); 
  		ItemShipping[0] = fields[0];
   for ( i = 1; i <= iNumberOrdered; i++ ) {
      Token[i]  = strItemShipping.indexOf("|", Token[i-1]+1);
      fields[i] = strItemShipping.substring( Token[i-1]+1, Token[i]);
  		ItemShipping[i] = fields[i];
  }
      Token[0]  = strItemQtyLimit.indexOf("|", 0);
      fields[0] = strItemQtyLimit.substring( 0, Token[0] ); 
  		ItemShipping[0] = fields[0];
   for ( i = 1; i <= iNumberOrdered; i++ ) {
      Token[i]  = strItemQtyLimit.indexOf("|", Token[i-1]+1);
      fields[i] = strItemQtyLimit.substring( Token[i-1]+1, Token[i]);
  		ItemQtyLimit[i] = fields[i];
  }
      Token[0]  = strItemFsTx.indexOf("|", 0);
      fields[0] = strItemFsTx.substring( 0, Token[0] ); 
  		ItemFsTx[0] = fields[0];
   for ( i = 1; i <= iNumberOrdered; i++ ) {
      Token[i]  = strItemFsTx.indexOf("|", Token[i-1]+1);
      fields[i] = strItemFsTx.substring( Token[i-1]+1, Token[i]);
  		ItemFsTx[i] = fields[i];
  }
      Token[0]  = strItemPsTx.indexOf("|", 0);
      fields[0] = strItemPsTx.substring( 0, Token[0] ); 
  		ItemPsTx[0] = fields[0];
   for ( i = 1; i <= iNumberOrdered; i++ ) {
      Token[i]  = strItemPsTx.indexOf("|", Token[i-1]+1);
      fields[i] = strItemPsTx.substring( Token[i-1]+1, Token[i]);
  		ItemPsTx[i] = fields[i];
  }
      Token[0]  = strItemWeight.indexOf("|", 0);
      fields[0] = strItemWeight.substring( 0, Token[0] ); 
  		ItemWeight[0] = fields[0];
   for ( i = 1; i <= iNumberOrdered; i++ ) {
      Token[i]  = strItemWeight.indexOf("|", Token[i-1]+1);
      fields[i] = strItemWeight.substring( Token[i-1]+1, Token[i]);
  		ItemWeight[i] = fields[i];
  }
 }
// Calculate how many items cart will hold
// based on length of cookie	
var avelen = (cookieLen/parseInt(iNumberOrdered));
CartMaxItems = (parseInt(4096/avelen)-2);
if ( isNaN(CartMaxItems)|| CartMaxItems <1 )
CartMaxItems = 20;
}


//---------------------------------------------------------------------||
// FUNCTION:    AddOneOfManyToCart                                     ||
// PARAMETERS:  Form Object PRODUCTSELECTOR                            ||
// RETURNS:     Product parameters to order form                       ||
// PURPOSE:     selects one of many products with different size,      ||
//              cost, shipping and/or tax to add to shopping cart      ||
//---------------------------------------------------------------------||
function AddOneOfManyToCart(formToUpdate) 
{ 

   selectedObj = formToUpdate.PRODUCTSELECTOR[formToUpdate.PRODUCTSELECTOR.selectedIndex]; 

   nameVal = selectedObj.getAttribute("name"); 
   if (nameVal == "select") { 
      alert('Please select an option'); 
      return false; 
   } 

   formToUpdate.NAME.value = nameVal; 

   costVal = selectedObj.getAttribute("cost"); 
   formToUpdate.PRICE.value = costVal; 


   id_numVal = selectedObj.getAttribute("id_num"); 
   formToUpdate.ID_NUM.value = id_numVal; 

   shippingVal = selectedObj.getAttribute("shipping"); 
   formToUpdate.SHIPPING.value = shippingVal;

   if (formToUpdate.WEIGHT == null) 
	     formToUpdate.WEIGHT = 0.00;
			else 
   var weightVal = selectedObj.getAttribute("weight"); 
   formToUpdate.WEIGHT.value = weightVal;

   if (formToUpdate.FSTAXABLE == null) 
	      formToUpdate.FSTAXABLE = true; 

				
   if (formToUpdate.TAXABLE == null) 
	      formToUpdate.TAXABLE = true; 

   switch( formToUpdate.PRODUCTSELECTOR[formToUpdate.PRODUCTSELECTOR.selectedIndex].value ) { 
   } 
   AddToCart(formToUpdate); 
} 


//---------------------------------------------------------------------||
// 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) {
   iNumberOrdered     = 0;
   var bAlreadyInCart = false;
   var notice         = "";
   var i              = 0;
	 strProductId       = "";
	 
	ReadCookie();

   if ( iNumberOrdered == null )
      iNumberOrdered = 0;

   if ( thisForm.ID_NUM == null )
      strID_NUM    = "";
   else {
      strID_NUM    = thisForm.ID_NUM.value;
			strProductId = strID_NUM.charAt(0);
			}

   if ( thisForm.FSTAXABLE == null) 
      strFSTAXABLE = true ;
	 else {
	  if ((thisForm.FSTAXABLE.value == "false") || (thisForm.FSTAXABLE.value == "FALSE")) 
      strFSTAXABLE = false ; 
   else  
      strFSTAXABLE = true ; 
			}

   if ( thisForm.TAXABLE == null) 
      strTAXABLE = true ;
	 else {
	  if ((thisForm.TAXABLE.value == "false") || (thisForm.TAXABLE.value == "FALSE")) 
      strTAXABLE = false ; 
   else  
      strTAXABLE = true ; 
			}

   if ( strProductId == 'd') {
      strFSTAXABLE = false ;
      strTAXABLE   = false ; 
			}

   if ( strProductId == 'n') {
      strTAXABLE   = false ; 
			}

   if ( (thisForm.LIMIT == null ) || (thisForm.LIMIT.value == "false" )) {
      strQTYLIMIT  = 1000;
      } else {
      strQTYLIMIT  = thisForm.LIMIT.value;
      }
   if ( thisForm.QUANTITY == null )
      strQUANTITY  = "1";
   else {
	 		strQUANTITY  = thisForm.QUANTITY.value;
		}
		if (parseInt(thisForm.QUANTITY.value)<= parseInt(strQTYLIMIT)) {
      strQUANTITY  = parseInt(thisForm.QUANTITY.value);
			} else {
			strQUANTITY = strQTYLIMIT;
			}	
   if ( thisForm.PRICE == null )
      strPRICE     = "0.00";
   else
      strPRICE     = thisForm.PRICE.value;

   if ( thisForm.NAME == null )
      strNAME      = "";
   else
      strNAME      = thisForm.NAME.value;

   if ( thisForm.SHIPPING == null )
      strSHIPPING  = "0.00";
   else
      strSHIPPING  = thisForm.SHIPPING.value;

   if ( thisForm.ADDITIONALINFO == null ) {
      strADDTLINFO = "";
   } else {
      strADDTLINFO = thisForm.ADDITIONALINFO[thisForm.ADDITIONALINFO.selectedIndex].value;
  		 }
 
   if ( thisForm.ADDITIONALINFO2 != null ) {
      strADDTLINFO2 = "; " + thisForm.ADDITIONALINFO2[thisForm.ADDITIONALINFO2.selectedIndex].value;
   }

   if ( thisForm.ADDITIONALINFO3 != null ) {
      strADDTLINFO3 = "; " + thisForm.ADDITIONALINFO3[thisForm.ADDITIONALINFO3.selectedIndex].value;
   }
 
   if ( thisForm.ADDITIONALINFO4 != null ) {
      strADDTLINFO3 += "; " + thisForm.ADDITIONALINFO4[thisForm.ADDITIONALINFO4.selectedIndex].value;
   }
if ( thisForm.USERENTRY != null ) {
		strUSERENTRY = thisForm.USERENTRY.value; 
} 
if ( thisForm.USERENTRY2 != null ) { 
		strUSERENTRY2 = thisForm.USERENTRY2.value; 
} 
if ( thisForm.USERENTRY3 != null ) { 
		strUSERENTRY2 += " " + thisForm.USERENTRY3.value; 
} 
   if ( thisForm.WEIGHT == null )
      strWEIGHT  = "0";
   else
      strWEIGHT  = thisForm.WEIGHT.value;

   //Is this product already in the cart?  If so, increment quantity instead of adding another.
   for ( i = 0; i <= iNumberOrdered; i++ ) {

	 		 if (ItemId[i]         == strID_NUM &&
				   ItemPrice[i]      == strPRICE  &&
				   ItemName[i]       == strNAME   &&
  				 ItemAddtlInfo[i]  == strADDTLINFO &&
  				 ItemAddtlInfo2[i] == strADDTLINFO2 &&
  				 ItemAddtlInfo3[i] == strADDTLINFO3 &&
  				 ItemUserEntry[i]  == strUSERENTRY &&
  				 ItemUserEntry2[i] == strUSERENTRY2
         ) {
         bAlreadyInCart = true;
            ItemQuantity[i] = (parseInt(strQUANTITY)+parseInt(ItemQuantity[i]));
		    if (parseInt(ItemQuantity[i]) > parseInt(strQTYLIMIT)) {
            ItemQuantity[i]  = parseInt(strQTYLIMIT);
			  
	         WriteCookie();
notice = strAdded  + "\n-------------------------------------------------------------------\n" + "Quantity is limited to : " + strQTYLIMIT + "\nof Product  : " + strNAME + " " + strADDTLINFO + " " + strADDTLINFO2 + " " + strADDTLINFO3 + "\n" + strUSERENTRY + " " + strUSERENTRY2;
         break;
      
			}else {
				
         WriteCookie();
notice = strAdded + "\n-------------------------------------------------------------------\n" + "Quantity : " + strQUANTITY + "\nProduct  : " + strNAME + " " + strADDTLINFO + " " + strADDTLINFO2 + " " + strADDTLINFO3 + "\n" + strUSERENTRY + " " + strUSERENTRY2;
         break;
      }
   }
}

   if ( !bAlreadyInCart ) {
      iNumberOrdered++;

      if ( iNumberOrdered > CartMaxItems )
         alert( strSorry );
      else {
				 i = iNumberOrdered

         ItemId[i]         = strID_NUM;
				 ItemQuantity[i]   = strQUANTITY;
				 ItemPrice[i]      = strPRICE;
				 ItemName[i]       = strNAME;
				 ItemShipping[i]   = strSHIPPING;
				 ItemQtyLimit[i]   = strQTYLIMIT;
				 ItemAddtlInfo[i]  = strADDTLINFO;
 				 ItemAddtlInfo2[i] = strADDTLINFO2;
 				 ItemAddtlInfo3[i] = strADDTLINFO3;
 				 ItemUserEntry[i]  = strUSERENTRY;
 				 ItemUserEntry2[i] = strUSERENTRY2;
				 ItemFsTx[i]       = strFSTAXABLE;
				 ItemPsTx[i]       = strTAXABLE;
				 ItemWeight[i]     = strWEIGHT;
         WriteCookie();
notice = strAdded + "\n-------------------------------------------------------------------\n" + "\nQuantity : " + strQUANTITY + "\nProduct  : " + strNAME + " " + strADDTLINFO + " " + strADDTLINFO2 + " " + strADDTLINFO3 + "\n" + strUSERENTRY + " " + strUSERENTRY2;
      }
   }

   if ( DisplayNotice && notice!='')
      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;
   cooklen = clen;
   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:    WriteCookie                                            ||
// PARAMETERS:  Cart arrays                                            ||
// RETURNS:     Null                                                   ||
// PURPOSE:     Translates Arrays into strings and                     || 
//              calls SetCookie()                                      ||
//---------------------------------------------------------------------||
	function WriteCookie() {
	  strItemId          = "";
    strItemQuantity    = "";
    strItemPrice       = "";
    strItemName        = "";
    strItemShipping    = "";
    strItemQtyLimit    = "";
    strItemAddtlInfo   = "";
		strItemAddtlInfo2  = "";
		strItemAddtlInfo3  = "";
		strItemUserEntry   = "";
		strItemUserEntry2  = "";
    strItemFsTx        = "";
    strItemPsTx        = "";
    strItemWeight      = "";
		ItemId[0]          = null;
    ItemQuantity[0]    = null;
		ItemPrice[0]       = null;
		ItemName[0]        = null;
		ItemShipping[0]    = null;
    ItemQtyLimit[0]    = null;
		ItemAddtlInfo[0]   = null;
		ItemAddtlInfo2[0]  = null;
		ItemAddtlInfo3[0]  = null;
		ItemUserEntry[0]   = null;
		ItemUserEntry2[0]  = null;
		ItemFsTx[0]        = null;
		ItemPsTx[0]        = null;
		ItemWeight[0]      = null;


	   for ( i = 0; i <= iNumberOrdered; i++ ) {
		strItemId          += (ItemId[i] + "|");
		strItemQuantity    += (ItemQuantity[i] + "|");
		strItemPrice       += (ItemPrice[i] + "|");
		strItemName        += (ItemName[i] + "|");
		strItemAddtlInfo   += (ItemAddtlInfo[i] + "|");
		strItemAddtlInfo2  += (ItemAddtlInfo2[i] + "|");
		strItemAddtlInfo3  += (ItemAddtlInfo3[i] + "|");
		strItemUserEntry   += (ItemUserEntry[i]  + "|");
		strItemUserEntry2  += (ItemUserEntry2[i] + "|");
		strItemShipping    += (ItemShipping[i] + "|");
		strItemQtyLimit    += (ItemQtyLimit[i] + "|");
		strItemFsTx        += (ItemFsTx[i] + "|");
		strItemPsTx        += (ItemPsTx[i] + "|");
		strItemWeight      += (ItemWeight[i] + "|");
		}

         SetCookie("ItemId", strItemId, null, "/");
         SetCookie("QuantY", strItemQuantity, null, "/");
         SetCookie("ItemPrice", strItemPrice, null, "/");
         SetCookie("ItemName", strItemName, null, "/");
         SetCookie("ItemAddtlInfo", strItemAddtlInfo, null, "/");
         SetCookie("ItemAddtlInfo2", strItemAddtlInfo2, null, "/");
         SetCookie("ItemAddtlInfo3", strItemAddtlInfo3, null, "/");
         SetCookie("ItemUserEntry", strItemUserEntry, null, "/");
         SetCookie("ItemUserEntry2", strItemUserEntry2, null, "/");
         SetCookie("ItemShipping", strItemShipping, null, "/");
         SetCookie("ItemQtyLimit", strItemQtyLimit, null, "/");
         SetCookie("ItemFsTx1", strItemFsTx, null, "/");
         SetCookie("ItemPsTx2", strItemPsTx, null, "/");
         SetCookie("ItemWeight", strItemWeight, null, "/");
         SetCookie("NumberOrdered", iNumberOrdered, 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.length <2 )
      cents = "0" + cents;

   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 ) ) {
	 ReadCookie()
	 if (iNumberOrdered ==1)
	 SetCookie ('NumberOrdered', 0, null, '/');
	 else{ 
      for ( i=RemOrder; i < iNumberOrdered; i++ ) {
 
         ItemId[i]        = ItemId[i+1];
				 ItemQuantity[i]  = ItemQuantity[i+1];
				 ItemPrice[i]     = ItemPrice[i+1];
				 ItemName[i]      = ItemName[i+1];
				 ItemShipping[i]  = ItemShipping[i+1];
				 ItemQtyLimit[i]  = ItemQtyLimit[i+1];
				 ItemAddtlInfo[i] = ItemAddtlInfo[i+1];
				 ItemAddtlInfo2[i]= ItemAddtlInfo2[i+1];
				 ItemAddtlInfo3[i]= ItemAddtlInfo3[i+1];
				 ItemUserEntry[i] = ItemUserEntry[i+1];
				 ItemUserEntry2[i]= ItemUserEntry2[i+1];
				 ItemFsTx[i]      = ItemFsTx[i+1];
				 ItemPsTx[i]      = ItemPsTx[i+1];
				 ItemWeight[i]    = ItemWeight[i+1];
		     }
		iNumberOrdered = iNumberOrdered -1;
    WriteCookie();
	}
     location.href  = location.href;      
 }
}

//---------------------------------------------------------------------||
// FUNCTION:    ChangeQuantity                                         ||
// PARAMETERS:  Order Number to Change Quantity                        ||
// RETURNS:     Null                                                   ||
// PURPOSE:     Changes quantity of an item in the shopping cart       ||
//              on the managecart.html table                           ||
//---------------------------------------------------------------------||
function ChangeQuantity(OrderNum,NewQuantity) {

   if ( isNaN(NewQuantity) ) {
      alert( strErrQty );
   } else {
	   NewQuantity = parseInt(NewQuantity);
	 if (NewQuantity < 1 ) 
       NewQuantity = 1;
       NewQuantity = parseInt(NewQuantity);

   }    

	 ReadCookie()
	 ItemQuantity[OrderNum] = NewQuantity;
		    if (parseInt(ItemQuantity[OrderNum]) > parseInt(ItemQtyLimit[OrderNum])) {
            ItemQuantity[OrderNum]  = parseInt(ItemQtyLimit[OrderNum]);
						}
						
   WriteCookie();
	 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;
      }
   }
}

//=====================================================================||
//               END NOP Design SmartPost Shopping Cart                ||
//=====================================================================||

