//=====================================================================||
//              NOPCART SHORT VERSION (Priceless)                      ||
//=====================================================================||
//               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
// Quantity Limit field
// "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
// Cart is priceless (i.e., no price, shipping, tax or payment processor).
//
//---------------------------------------------------------------------||
//                       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:                                               ||
// =====================                                               ||
// * DisplayNotice: true/false, controls whether the user is provided  ||
//   with a popup letting them know their product is added to the cart ||
// * 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.                       ||
//                                                                     ||
// Options For Programmers:                                            ||
// ========================                                            ||
// * OutputItem<..>: string, the name of the pair value passed at      ||
//   checkouttime.  Change these only if you are connecting to a CGI   ||
//   script and need other field names, or are using a secure service  ||
//   that requires specific field names.                               ||
// * AppendItemNumToOutput: true/false, if set to true, the number of  ||
//   each ordered item will be appended to the output string.  For     ||
//   example if OutputItemId is 'ID_' and this is set to true, the     ||
//   output field name will be 'ID_1', 'ID_2' ... for each item.       ||
// * HiddenFieldsToCheckout: true/false, if set to true, hidden fields ||
//   for the cart items will be passed TO the checkout page, from the  ||
//   ManageCart page.  This is set to true for CGI/PHP/Script based    ||
//   checkout pages, but should be left false if you are using an      ||
//   HTML/Javascript Checkout Page. Hidden fields will ALWAYS be       ||
//   passed FROM the checkout page to the Checkout CGI/PHP/ASP/Script  ||
//---------------------------------------------------------------------||

//Options for Everyone:

DisplayNotice         = false;
WeightUnits           = "Kilograms"   // Unit of measurement oz, lbs, Kilograms, grams
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';

//Options for Programmers:
OutputItemId           = 'EDP_';
OutputItemQuantity     = 'QUANTITY_';
OutputItemName         = 'Name_';
OutputItemAddtlInfo    = 'Details_';
OutputOrderZone        = "ZONE"
CartMaxItems           =  20;	// Default Maximum number of items allowed in cart //wc
AppendItemNumToOutput  = true;
HiddenFieldsToCheckout = true;

WebSiteBaseURL         = "http://www.pferdusa.com/";

//=====================================================================||
//---------------------------------------------------------------------||
//    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 ) {
//wc strSorry  = "I'm Sorry, your cart is full, please proceed to checkout.";
strSorry  = "Your cart is full. Please view the cart and submit your request.";
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";
strRLabel = "Remove";
strWLabel = "Weight";
strRButton= "Remove";
strErrQty = "Invalid Quantity.";
strNewQty = 'Please enter new quantity:';
strSpace  = "   ";
   bLanguageDefined = true;
}
strRemoveAll = "Click 'OK' to empty your request cart.";

//---------------------------------------------------------------------||
//                       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);
ItemName       = 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);
ItemWeight     = new Array(CartMaxItems+1);
//wc cookieLen      = "";
//wc cooklen        = "";
maxCookieLen   = 0;
strItemId         = "";
strItemQuantity   = "";
strItemName       = "";
strItemQtyLimit   = "";
strItemAddtlInfo  = "";
strItemAddtlInfo2 = "";
strItemAddtlInfo3 = "";
strItemUserEntry  = "";
strItemUserEntry2 = "";
strAddInfo        = "";
strItemWeight     = "";

strOutput         = ""

iNumberOrdered    = 0;

//wc CartMaxItems      = 20;
actualCartMaxItems = CartMaxItems;

strID_NUM         = "";
strQUANTITY       = "";
strNAME           = "";
strQTYLIMIT       = false;
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          = "";
    strItemName        = "";
    strItemQuantity    = "";
    strItemQtyLimit    = "";
    strItemAddtlInfo   = "";
		strItemAddtlInfo2  = "";
		strItemAddtlInfo3  = "";
		strItemUserEntry   = "";
		strItemUserEntry2  = "";
    strItemWeight      = "";
    Token              = new Array(CartMaxItems+1);
    fields             = new Array(CartMaxItems+1);

   iNumberOrdered = GetCookie("NumberOrdered");
   if ( iNumberOrdered == null || iNumberOrdered == 0) {
      iNumberOrdered = 0;
			return; 
      } else {
         maxCookieLen		= 0;
         
         strItemId          = GetCookie("ItemId");
         //wc cookieLen          = cooklen;
         strItemQuantity    = GetCookie("QuantY");
		 strItemName        = GetCookie("ItemName");
         strItemQtyLimit    = GetCookie("ItemQtyLimit");
	     strItemAddtlInfo   = GetCookie("ItemAddtlInfo");
         strItemAddtlInfo2  = GetCookie("ItemAddtlInfo2");
         strItemAddtlInfo3  = GetCookie("ItemAddtlInfo3");
         strItemUserEntry   = GetCookie("ItemUserEntry");
         strItemUserEntry2  = GetCookie("ItemUserEntry2");
         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]  = 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] ); 
  		ItemAddtlInfo2[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] ); 
  		ItemAddtlInfo3[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] ); 
  		ItemUserEntry[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] ); 
  		ItemUserEntry2[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]  = strItemQtyLimit.indexOf("|", 0);
      fields[0] = strItemQtyLimit.substring( 0, Token[0] ); 
  		ItemQtyLimit[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]  = 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	
//wc var avelen = (cookieLen/parseInt(iNumberOrdered));
//wc CartMaxItems = (parseInt(4096/avelen)-2);
//wc if ( isNaN(CartMaxItems)|| CartMaxItems <1 )
//wc CartMaxItems = 20;
var avelen = (maxCookieLen/parseInt(iNumberOrdered));
actualCartMaxItems = (parseInt(4096/avelen)-2);
if ( isNaN(actualCartMaxItems) || actualCartMaxItems < 1 || actualCartMaxItems > CartMaxItems)
actualCartMaxItems = CartMaxItems;
}


//---------------------------------------------------------------------||
// FUNCTION:    AddOneOfManyToCart                                     ||
// PARAMETERS:  Form Object PRODUCTSELECTOR                            ||
// RETURNS:     Product parameters to order form                       ||
// PURPOSE:     selects one of many products 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; 

   id_numVal = selectedObj.getAttribute("id_num"); 
   formToUpdate.ID_NUM.value = id_numVal; 

   if (formToUpdate.WEIGHT == null) 
	     formToUpdate.WEIGHT = 0.00;
			else 
   var weightVal = selectedObj.getAttribute("weight"); 
   formToUpdate.WEIGHT.value = weightVal;

   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;
//wc   var bAlreadyInCart = false;
//wc   var notice         = "";
//wc   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.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.NAME == null )
      strNAME      = "";
   else
      strNAME      = thisForm.NAME.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;

	// Add to the cart.
	
	AddToCartWrapup()
}

//---------------------------------------------------------------------||
// FUNCTION:    AddToCart2                                             ||
// PARAMETERS:  (see below)                                            ||
// RETURNS:     Cookie to user's browser, with prompt                  ||
// PURPOSE:     Adds a product to the user's shopping cart             ||
//---------------------------------------------------------------------||
function AddToCart2(idNum, quantity, name, info1, info2, info3, user1, user2, user3, weight) {
	iNumberOrdered = 0;
	 
	ReadCookie();

   if ( iNumberOrdered == null )
      iNumberOrdered = 0;

	strID_NUM = idNum;
	if ( strID_NUM == "" )
		strProductId = "";
	else
		strProductId = strID_NUM.charAt(0);

	strQUANTITY = quantity;
	strQTYLIMIT  = 1000;

	strNAME = name;

	strADDTLINFO = info1;
	strADDTLINFO2 = info2;
	strADDTLINFO3 = info3;
 
	strUSERENTRY = user1; 
	strUSERENTRY2 = user2; 
	strUSERENTRY3 = user3; 

	strWEIGHT = weight;
	
	// Add to the cart.
	
	AddToCartWrapup()
}

//---------------------------------------------------------------------||
// FUNCTION:    AddReqToCart                                           ||
// PARAMETERS:  (see below)                                            ||
// RETURNS:     Cookie to user's browser, with prompt                  ||
// PURPOSE:     Adds a product to the user's shopping cart             ||
//---------------------------------------------------------------------||
function AddReqToCart(idNum, name, brand, details) {
	iNumberOrdered = 0;
	 
	ReadCookie();

   if ( iNumberOrdered == null )
      iNumberOrdered = 0;

	strID_NUM = idNum;
	strProductId = "";

	strQUANTITY = 1;
	strQTYLIMIT  = 1000;

	strNAME = name;

	strADDTLINFO = GetBaseURL(location.href).replace(WebSiteBaseURL,"") + "#b" + idNum;  // product page relative URL w/ anchor
	strADDTLINFO2 = brand;
	strADDTLINFO3 = details.replace(/,  /g,"");  // Strip missing details.
	
 
	strUSERENTRY = ""; 
	strUSERENTRY2 = ""; 
	strUSERENTRY3 = ""; 

	strWEIGHT = "";

	// Add to the cart.
	
	AddToCartWrapup();
	
	// Set the "continue shopping" URL to the current button.

	SetContinueURL("#b" + idNum);
}

//---------------------------------------------------------------------||
// FUNCTION:    AddToCartWrapup                                        ||
// PARAMETERS:  global str* variables                                  ||
// RETURNS:     Cookie to user's browser, with prompt                  ||
// PURPOSE:     Adds a product to the user's shopping cart             ||
//---------------------------------------------------------------------||
function AddToCartWrapup() {
   var bAlreadyInCart = false;
   var notice         = "";
   var i              = 0;

   //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 &&
				   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 > actualCartMaxItems ) //wc
         alert( strSorry );
      else {
				 i = iNumberOrdered

         ItemId[i]         = strID_NUM;
				 ItemQuantity[i]   = strQUANTITY;
				 ItemName[i]       = strNAME;
				 ItemQtyLimit[i]   = strQTYLIMIT;
				 ItemAddtlInfo[i]  = strADDTLINFO;
 				 ItemAddtlInfo2[i] = strADDTLINFO2;
 				 ItemAddtlInfo3[i] = strADDTLINFO3;
 				 ItemUserEntry[i]  = strUSERENTRY;
 				 ItemUserEntry2[i] = strUSERENTRY2;
				 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;
   var val = ""; //wc
   //wc cooklen = clen;
   while ( i < clen ) {
      var j = i + alen;
      //wc begin
      if ( document.cookie.substring(i, j) == arg ) {
      	val = getCookieVal(j);
      	if ( val.length > maxCookieLen ) maxCookieLen = val.length; 
		return val;
      }
      //wc end
      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    = "";
    strItemName        = "";
    strItemQtyLimit    = "";
    strItemAddtlInfo   = "";
		strItemAddtlInfo2  = "";
		strItemAddtlInfo3  = "";
		strItemUserEntry   = "";
		strItemUserEntry2  = "";
    strItemWeight      = "";
		ItemId[0]          = null;
    ItemQuantity[0]    = null;
		ItemName[0]        = null;
    ItemQtyLimit[0]    = null;
		ItemAddtlInfo[0]   = null;
		ItemAddtlInfo2[0]  = null;
		ItemAddtlInfo3[0]  = null;
		ItemUserEntry[0]   = null;
		ItemUserEntry2[0]  = null;
		ItemWeight[0]      = null;


	   for ( i = 0; i <= iNumberOrdered; i++ ) {
		strItemId          += (ItemId[i] + "|");
		strItemQuantity    += (ItemQuantity[i] + "|");
		strItemName        += (ItemName[i] + "|");
		strItemAddtlInfo   += (ItemAddtlInfo[i] + "|");
		strItemAddtlInfo2  += (ItemAddtlInfo2[i] + "|");
		strItemAddtlInfo3  += (ItemAddtlInfo3[i] + "|");
		strItemUserEntry   += (ItemUserEntry[i]  + "|");
		strItemUserEntry2  += (ItemUserEntry2[i] + "|");
		strItemQtyLimit    += (ItemQtyLimit[i] + "|");
		strItemWeight      += (ItemWeight[i] + "|");
		}

         SetCookie("ItemId", strItemId, null, "/");
         SetCookie("QuantY", strItemQuantity, 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("ItemQtyLimit", strItemQtyLimit, 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) {
//wc   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];
				 ItemName[i]      = ItemName[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];
				 ItemWeight[i]    = ItemWeight[i+1];
		     }
		iNumberOrdered = iNumberOrdered -1;
    WriteCookie();
	}
     location.href  = location.href;      
//wc }
}

//wc begin
//---------------------------------------------------------------------||
// FUNCTION:    RemoveAllFromCart                                      ||
// PARAMETERS:  ask - true = request confirmation                      ||
//				reload - true = reload the page						   ||
// RETURNS:     Null                                                   ||
// PURPOSE:     Removes an item from a users shopping cart             ||
//---------------------------------------------------------------------||
function RemoveAllFromCart(ask,reload) {
	ReadCookie();
	if ( iNumberOrdered > 1 && (!ask || confirm(strRemoveAll)) ) {
		iNumberOrdered = 0;
		// SetCookie ('NumberOrdered', 0, null, '/');
		WriteCookie();

		if ( reload ) {
			location.href  = location.href;
		}
    }
}
//wc end

//---------------------------------------------------------------------||
// 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();
//wc	 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;ipairs.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:    SetContinueURL                                         ||
// PARAMETERS:  page anchor ("#name")                                  ||
// RETURNS:     null                                                   ||
// PURPOSE:     Construct the "Continue Shopping" URL.                 ||
//---------------------------------------------------------------------||
function SetContinueURL(anchor) {
	var newbase = GetBaseURL(location.href);
	var newurl = "";

	var currenturl = GetContinueURL("");
	var currentbase = GetBaseURL(currenturl);
	//wc alert("currentbase = " + currentbase);
	//wc alert("newbase = " + newbase);
	
	if (newurl.search(/.com\/cart/) != -1)
		return; 
		
	if (newbase != currentbase || anchor.substr(0,2) == "#b")  // new base or button anchor?
		newurl = newbase + anchor;
	else if (GetAnchor(currenturl).substr(0,2) == "#b")  // current url is a button?
		newurl = currenturl;
	else
		newurl = newbase + anchor;

	//wc alert("Set = " + newurl);
	
	SetCookie("ContinueURL", newurl, null, "/");
}

//---------------------------------------------------------------------||
// FUNCTION:    GetContinueURL                                         ||
// PARAMETERS:  default URL                                            ||
// RETURNS:     "Continue" URL                                         ||
// PURPOSE:     Return the "Continue" URL or the default URL.          ||
//---------------------------------------------------------------------||
function GetContinueURL(defaultURL) {
	var continueURL = GetCookie("ContinueURL");
	//wc alert("Current = " + continueURL);

	if (continueURL == null || continueURL == "")
		return defaultURL;
	else
		return continueURL;
}

//---------------------------------------------------------------------||
// FUNCTION:    GetBaseURL                                             ||
// PARAMETERS:  URL with possible anchor                               ||
// RETURNS:     URL without the anchor                                 ||
// PURPOSE:     Strip an anchor from a URL.                            ||
//---------------------------------------------------------------------||
function GetBaseURL(url) {
	var baselen = url.search(/#/);
	if (baselen == -1)
		return url;
	else
		return url.substr(0,baselen);
}

//---------------------------------------------------------------------||
// FUNCTION:    GetAnchor                                              ||
// PARAMETERS:  URL with possible anchor                               ||
// RETURNS:     just the anchor                                        ||
// PURPOSE:     Extract an anchor from a URL.                          ||
//---------------------------------------------------------------------||
function GetAnchor(url) {
	var baselen = url.search(/#/);

	if (baselen == -1)
		return "";
	else
		return url.substr(baselen);
}

//=====================================================================||
//               END NOP Design SmartPost Shopping Cart                ||
//=====================================================================||

