//-----------------------------------------------------------------
// Licensed Materials - Property of IBM
//
// WebSphere Commerce
//
// (C) Copyright IBM Corp. 2007, 2009 All Rights Reserved.
//
// US Government Users Restricted Rights - Use, duplication or
// disclosure restricted by GSA ADP Schedule Contract with
// IBM Corp.
//-----------------------------------------------------------------

//
//

/**
* @fileOverview This file holds methods to perform client side operations in relation to catalog browsing, usually at the category level.<b> 
* 			For example, this file holds methods to add items to the shopping cart, wish list and compare zone and to resolve SKUs.<b> 
*			This file is referenced in a collection of JSPs including all of the catalog entry display JSPs such as
*			CachedBundleDisplay.jsp, CachedItemDisplay.jsp , CachedPackageDisplay.jsp, CachedProductOnlyDisplay.jsp.
*			As well this file is included in CategoryOnlyResultsDisplay.jsp and in none catalog browsing pages such as 
*			CatalogSearchDisplay.jsp and MyAccountDisplay.jsp.
*
* @version 1.0
**/

/**
* @class categoryDisplayJS This class defines all the variables and functions used by the CategoryDisplay.js. Any page that will use a function in this file
*		can access that function thru this class. Pages that use categoryDisplayJS include CachedProductOnlyDisplay.jsp which is responsible for
*		displaying product details. As well CategoryOnlyResultsDisplay.jsp uses this page to facilitate the category browsing functionality such as add to cart, 
*		wish list and compare zone.
*
**/
categoryDisplayJS={
	
	/** An array of entitled items which is used in various methods throughout CategoryDisplay.js **/
	entitledItems:[],
	
	/** An map which holds the attributes of a set of products **/
	selectedProducts:new Object(),
	
	/** A map of attribute name value pairs for the currently selected attribute values **/
	selectedAttributes:new Object(),
	
	/** Can be used to hold a map of error messages **/
	errorMessages: new Object(),
	
	/** The language ID currently in use **/
	langId: "-1",
	
	/** The store ID currently in use **/
	storeId: "",
	
	/** The catalog ID currently in use **/
	catalogId: "",
	
	/** The ship mode ID currently in use **/
	shipModeId: "",
	
	/** Holds a boolean value indicating whether or not AJAX shopping cart is enabled or not. **/
	ajaxShopCart:true,
	
	/** Holds a boolean value indicating whether or not AJAX My Account is enabled or not. **/
	ajaxMyAccount:true,
	
	/** Can be used to indicate whether or not there has been a context change event **/
	contextChanged:false, 
	
	/** Set to true in the goBack and goForward methods **/
	isHistory:false,
	
	/** Holds an array of  JSON objects representing properties of merchandising associations **/
	merchandisingAssociationItems:[],
	
	/** Holds an array of JSON objects holding information about the parent catalog entries of merchandising associations **/
	baseCatalogEntryDetails:[],
	
	/** Used to determine the index of the next association to display and is used as a global storage variable to share data between methods. **/
	associationThumbnailIndex:1,
	
	/** A count of the number of merchandising associations available. **/
	totalAssociationCount:0,
	
	/** A boolean used in a variety of the add to cart methods to tell whether or not the base item was added to the cart. **/
	baseItemAddedToCart:false,
	
	/** A boolean used to determine whether or not to add merchandising associations to the cart **/
	merchandisingProductAssociationAddToCart:false,
	
	/** The form which holds information about merchandising associations to be added to the cart **/
	merchandisingProductAssociationForm:"",
	
	/** A boolean used to determine whether or not the parent catalog entry is a bundle bean. **/
	isParentBundleBean:false,
	
	/** Holds the current user type such as guest or registered user. Allowed values are 'G' for guest and 'R' for registered.**/
	userType:"",
	
	/** The text to display as an alt to the image used on the MerchandisingAssociationDisplay.jsp to show the previous assoication **/
	displayPrevAssociation:"",
	
	/** The text to display as an alt to the image used on the MerchandisingAssociationDisplay.jsp to show the next assoication **/
	displayNextAssociation:"",
	
	/** A map holding a mapping between product IDs as its key and the first entitled item ID of that product as its value **/
	defaultItemArray:[],
	
	/**
	* initHistory This function will take elementId and changeUrl as inputs and create a new history tracker object and sets the initial state.
	*			  This is used on CategoriesDisplay.jsp to initialize the page history to the CategoryDisplay URL of the category you are on.
	* @param {String} elementId  HistoryTracker elementId.
	* @param {String} changeUrl HistoryTracker URL.
	*
	**/
	initHistory:function(elementId, changeUrl){
		var historyObject = new categoryDisplayJS.HistoryTracker(elementId, changeUrl);
		dojo.back.setInitialState(historyObject);	
	},
	
	/**
	* setAjaxShopCart This function will set the flag "ajaxShopCart" which is used to determine if the shopping cart is using the Ajax flow or not.
	*
	* @param {Boolean} ajaxShopCart Flag which indicates whther to use AJAX shopping cart or not.
	*
	**/
	setAjaxShopCart:function(ajaxShopCart){
		this.ajaxShopCart = ajaxShopCart;
	},
	
	/**
	* setAjaxMyAccount This function will set the flag "ajaxMyAccount" which is used to determine if the My Account page is using the Ajax flow or not.
	*
	* @param {Boolean} ajaxMyAccount Flag which indicates whether to use AJAX My Account or not.
	*
	**/	
	setAjaxMyAccount:function(ajaxMyAccount){
		this.ajaxMyAccount = ajaxMyAccount;
	},	
	
	/**
	* setCommonParameters This function initializes storeId, catalogId, and langId.
	*
	* @param {String} langId The language id to use.
	* @param {String} storeId The store id to use.
	* @param {String} catalogId The catalog id to use.
	* @param {String} userType The type of user. G for Guest user.
	* 
	**/
	setCommonParameters:function(langId,storeId,catalogId,userType){
		this.langId = langId;
		this.storeId = storeId;
		this.catalogId = catalogId;
		this.userType = userType;
	},
	
	setCurrentShipMode:function(shipModeId){
		this.shipModeId = shipModeId;
	},
	
	/**
	* setEntitledItems Sets an array of entitled items for a product. 
	*				   This function is used in CachedBundleDisplay.jsp to add all the entitled SKUs of the products in a particular bundle to this array.
	*				   The array that is generated is used later in {@link fastFinderJS.resolveSKU}.
	* 
	* @param {Object} entitledItemArray An object which holds both the catalog entry ID as well as an array of attributes for the entitled items of a product.
	*
	**/
	setEntitledItems : function(entitledItemArray){
		this.entitledItems = entitledItemArray;
	},

	/**
	* setSelectedAttribute Sets the selected attribute value for a particular attribute not in reference to any catalog entry.
	*					   One place this function is used is on CachedProductOnlyDisplay.jsp where there is a drop down box of attributes.
	*					   When an attribute is selected from that drop down this method is called to update the selected value for that attribute.
	*
	* @param {String} selectedAttributeName The name of the attribute.
	* @param {String} selectedAttributeValue The value of the selected attribute.
	*
	**/
	setSelectedAttribute : function(selectedAttributeName , selectedAttributeValue){
		console.debug(selectedAttributeName +" : "+ selectedAttributeValue);
		this.selectedAttributes[selectedAttributeName] = selectedAttributeValue;
	},
	
	/**
	* setSelectedAttributeOfProduct Sets the selected attribute value for an attribute of a specified product.
	*								This function is used to set the assigned value of defining attributes to specific 
	*								products which will be stored in the selectedProducts map.
	*
	* @param {String} productId The catalog entry ID of the catalog entry to use.
	* @param {String} selectedAttributeName The name of the attribute.
	* @param {String} selectedAttributeValue The value of the selected attribute.
	*
	**/
	setSelectedAttributeOfProduct : function(productId,selectedAttributeName,selectedAttributeValue){
		
		selectedAttributesForProduct = new Object();

		if(this.selectedProducts[productId]) selectedAttributesForProduct = this.selectedProducts[productId];
		
		selectedAttributesForProduct[selectedAttributeName] = selectedAttributeValue;
		this.selectedProducts[productId] = selectedAttributesForProduct;
		
	},
	
	// Function for subcategory display pagination	
	
	/**
	* gotoASubCategoryDisplayPage  This function is used to validate the entered page number and loads the page if valid or displays an error message otherwise.
	*
	* @param {String} pageNum The page number entered.
	* @param {String} totalPages The total number of pages.
	* @param {String} pageSize The page size.
	* @param {String} subCatDispUrl The sub category display URL.
	*
	**/
	gotoASubCategoryDisplayPage : function(pageNum, totalPages, pageSize, subCatDispUrl) {
		pageNum = trim(pageNum);
		if (pageNum == "") {	
			 MessageHelper.formErrorHandleClient(document.getElementById('subCategoriesListDisplayPageNum').id,MessageHelper.messages['ERROR_EMPTY_NUM']);
			return;
		}
		
		if (MessageHelper.IsNumeric(pageNum,false) == false){ 
			 MessageHelper.formErrorHandleClient(document.getElementById('subCategoriesListDisplayPageNum').id,MessageHelper.messages['ERROR_PAGE_NUM']);

			return;
		}	
		
		if (pageNum >= 1 && pageNum <= totalPages) {
		    MessageHelper.hideAndClearMessage();
			var url = subCatDispUrl + "&beginIndex=" + ((pageNum-1) * pageSize);
			this.loadSubCategoryContentURL(url)
		} else {
			MessageHelper.formErrorHandleClient(document.getElementById('subCategoriesListDisplayPageNum').id,MessageHelper.messages['ERROR_PAGE_NUM']);
			
			return;
		}
	}, 

	/**
	* getCatalogEntryId Returns the catalog entry ID of the catalog entry with the selected attributes as specified in the {@link fastFinderJS.selectedAttributes} value.
	*					This method uses {@link fastFinderJS.resolveSKU} to find the SKU with the selected attributes values.
	*
	* @see fastFinderJS.resolveSKU
	*
	* @return {String} catalog entry ID.
	*
	**/
	getCatalogEntryId : function(){
		var attributeArray = [];
		for(attribute in this.selectedAttributes){
			attributeArray.push(attribute + "_" + this.selectedAttributes[attribute]);
		}
		return this.resolveSKU(attributeArray);
	},
	
	/**
	* getCatalogEntryIdforProduct Returns the catalog entry ID for a catalog entry that has the same attribute values as a specified product's selected attributes as passed in via the selectedAttributes parameter.
	*
	* @param {String[]} selectedAttributes The array of selected attributes upon which to resolve the SKU.
	*
	* @return {String} catalog entry ID of the SKU.
	*
	**/
	getCatalogEntryIdforProduct : function(selectedAttributes){
		var attributeArray = [];
		for(attribute in selectedAttributes){
			attributeArray.push(attribute + "_" + selectedAttributes[attribute]);
		}
		return this.resolveSKU(attributeArray);
	},


	/**
	* resolveSKU Resolves a SKU using an array of defining attributes.
	*
	* @param {String[]} attributeArray An array of defining attributes upon which to resolve a SKU.
	*
	* @return {String} catentry_id The catalog entry ID of the SKU.
	*
	**/
	resolveSKU : function(attributeArray){
	
		console.debug("Resolving SKU >> " + attributeArray +">>"+ this.entitledItems);
		var catentry_id = "";
		var attributeArrayCount = attributeArray.length;
		
		for(x in this.entitledItems){
			var catentry_id = this.entitledItems[x].catentry_id;
			var Attributes = this.entitledItems[x].Attributes;
			var attributeCount = 0;
			for(index in Attributes){
				attributeCount ++;
			}

			// Handle special case where a catalog entry has one sku with no attributes
			if (attributeArrayCount == 0 && attributeCount == 0){
				return catentry_id;
			}
			if(attributeCount != 0 && attributeArrayCount >= attributeCount){
				var matchedAttributeCount = 0;

				for(attributeName in attributeArray){
					var attributeValue = attributeArray[attributeName];
					if(attributeValue in Attributes){
						matchedAttributeCount ++;
					}
				}
				
				if(attributeCount == matchedAttributeCount){
					console.debug("CatEntryId:" + catentry_id + " for Attribute: " + attributeArray);
					return catentry_id;
				}
			}
		}
		return null;
	},



	/**
	* updateParamObject This function updates the given params object with a key to value pair mapping.
	*				    If the toArray value is true, It creates an Array for duplicate entries otherwise it overwrites the old value.
	*			        This is useful while making a service call which accepts a few parameters of type array.
	*					This function is used to prepare a a map of parameters which can be passed to XMLHttpRequests. 
	* 					The keys in this parameter map will be the name of the parameter to send and the value is the corresponding value for each parameter key.
	* @param {Object} params The parameters object to add name value pairs to.
	* @param {String} key The new key to add.
	* @param {String} value The new value to add to the specified key.
	* @param {Boolean} toArray Set to true to turn duplicate keys into an array, or false to override previous values for a specified key.
	* @param {int} index The index in an array of values for a specified key in which to place a new value.
	*
	* @return {Object} params A parameters object holding name value pairs.
	*
	**/
	updateParamObject:function(params, key, value, toArray, index){
	
	   if(params == null){
		   params = [];
	   }

	   if(params[key] != null && toArray)
	   {
			if(dojo.lang.isArrayLike(params[key]))
			{
				//3rd time onwards
			    if(index != null && index != "")
				{
					//overwrite the old value at specified index
				     params[key][index] = value;
				}
				else
				{
				    params[key].push(value);
			     }
		    }
			else
			{
			     //2nd time
			     var tmpValue = params[key];
			     params[key] = [];
			     params[key].push(tmpValue);
			     params[key].push(value);
		    }
	   }
	   else
	   {
			//1st time
		   if(index != null && index != "" && index != -1)
		   {
		      //overwrite the old value at specified index
		      params[key+"_"+index] = value;
		   }
		   else if(index == -1)
		   {
		      var i = 1;
		      while(params[key + "_" + i] != null)
			  {
			       i++;
		      }
		      params[key + "_" + i] = value;
		   }
		   else
		   {
		      params[key] = value;
		    }
	   }
	   return params;
	 },
	 
	 /**
	  *  This function associates the product id with its first entitledItemId.
	  *  @param {String} productId The id of the product.
	  *  @param {String} entitledItemId The id of the first entitledItem of the product.
	  */
	 setDefaultItem : function(productId,entitledItemId){
		this.defaultItemArray[productId] = entitledItemId;
		
},
	/*
     *	This function retrieves the first entitledItemId of the product.
	 *  @param {String} productId The id of the product.
	 *  
	 *  @return {String} The id of the first entitledItem of the product.
	 */
getDefaultItem : function(productId){
		return this.defaultItemArray[productId];
},


	/**
	* AddBundle2ShopCartAjax This function is used to add a bundle to the shopping cart. This is for the ajax flow which will take a form as input and retrieves all the items catentry IDs and adds them to the form.
	*						 
	* @param {form} form The form which contains all the inputs for the bundle.
	*					 The form is expected to have the following values: 
	*						numberOfProducts The number of products in the bundle.
	*						catEntryId_<index> where index is between 1 and numberOfProduct.
	*						quantity_<index> where index is between 1 and numberOfProduct.
	**/
	AddBundle2ShopCartAjax : function(form){
		
		var params = [];
		//var queryString = dojo.io.encodeForm(dojo.byId(form));

		params.storeId		= this.storeId;
		params.catalogId	= this.catalogId;
		params.langId		= this.langId;
		params.orderId		= ".";
			
		var productCount = form["numberOfProduct"].value;
		for(var i = 1; i <= productCount; i++){
			var catEntryId = form["catEntryId_" + i].value;
			if(this.selectedProducts[catEntryId])
				catEntryId = this.getCatalogEntryIdforProduct(this.selectedProducts[catEntryId]);
			var qty = form["quantity_" + i].value;
			if(qty == null || qty == "" || qty<=0){ MessageHelper.displayErrorMessage(MessageHelper.messages['QUANTITY_INPUT_ERROR']); return;}
			if(qty!=null && qty!='' && catEntryId!=null){
				this.updateParamObject(params,"catEntryId",catEntryId,false,-1);
				this.updateParamObject(params,"quantity",qty,false,-1);
				this.baseItemAddedToCart=true;
			}
			else{
				MessageHelper.displayErrorMessage(MessageHelper.messages['ERR_RESOLVING_SKU']);
				return;
			}
		}
		//For Handling multiple clicks
		if(!submitRequest()){
			return;
		}   		
		cursor_wait();		
		wc.service.invoke("AjaxAddOrderItem", params);

	},


	/**
	* AddBundle2ShopCart This function is used to add a bundle to the shopping cart. This is for the non ajax flow which  will take a form as input and submits the form.
	*
	* @param {form} form The form which contains all the inputs for the bundle.
	*					 The form is expected to have the following values:
	*						numberOfProducts The number of products in the bundle.
	*						catEntryId_<index> where index is between 1 and numberOfProduct.
	*						quantity_<index> where index is between 1 and numberOfProduct. 
	*
	**/
	AddBundle2ShopCart : function(form){
		
		form.URL.value = "AjaxOrderItemDisplayView";
		var productCount = form["numberOfProduct"].value;
		for(var i = 1; i <= productCount; i++){
			var catEntryId = form["catEntryId_" + i].value;
			if(this.selectedProducts[catEntryId]){
				catEntryId = this.getCatalogEntryIdforProduct(this.selectedProducts[catEntryId]);
				if(catEntryId != null)
				form["catEntryId_" + i].value = catEntryId;
				else{
					MessageHelper.displayErrorMessage(MessageHelper.messages['ERR_RESOLVING_SKU']);
					return;
				}
			}
			var qty = form["quantity_" + i].value;
			if(qty == null || qty == "" || qty<=0){ MessageHelper.displayErrorMessage(MessageHelper.messages['QUANTITY_INPUT_ERROR']); return;}
		}
		
		//For Handling multiple clicks
		if(!submitRequest()){
			return;
		}
		
		form.submit();
	},
	
	
	/**
	* Add2ShopCart This function is used to add to a catalog entry to the shopping cart. This will resolve the catentryId using entitledItemId and adds the item to the cart.
	*			   This function will call AddItem2ShopCart after resolving the entitledItemId to a SKU.
	*
	* @param {String} entitledItemId A DIV containing a JSON object which holds information about a catalog entry. You can reference CachedProductOnlyDisplay.jsp to see how that div is constructed.
	* @param {form} form The form which contains all the inputs for the item. The catEntryId and productId values of the form you pass in
	*					 will be set to the catalog entry Id of the SKU resolved from the list of skus whos defining attributes match those in the {@link fastFinderJS.selectedAttributes} array.
	* @param {int} quantity quantity of the item.
	*					
	*
	**/
	Add2ShopCart : function(entitledItemId,form,quantity){
		
		var entitledItemJSON = eval('('+ dojo.byId(entitledItemId).innerHTML +')');
		this.setEntitledItems(entitledItemJSON);
		var catalogEntryId = this.getCatalogEntryId();
		if(catalogEntryId!=null){
			if(this.merchandisingProductAssociationAddToCart){
				this.AddAssociation2ShopCart(catalogEntryId,quantity);
				return;
			}
			form.catEntryId.value = catalogEntryId;
			form.productId.value = catalogEntryId;
			this.AddItem2ShopCart(form,quantity);
		}else{
			MessageHelper.displayErrorMessage(MessageHelper.messages['ERR_RESOLVING_SKU']);
		}

	},
	
	
	
	/**
	* AddItem2ShopCart This function is used to add a SKU to the shopping cart.
	*
	* @param {form} form The form which contains all the inputs for the item.
    * 					The form must have the following values:
    *						quantity The quantity of the item that you want to add to the cart.
	* @param {int} quantity The quantity of the item to add to the shopping cart.
	*
	**/
	AddItem2ShopCart : function(form,quantity){
		
		if(quantity) form.quantity.value = quantity;
		var invalidQTY = new RegExp(/^\d*$/);
		if(form.quantity.value == 0 || form.quantity.value == "" || !invalidQTY.test(form.quantity.value)){ MessageHelper.displayErrorMessage(MessageHelper.messages['QUANTITY_INPUT_ERROR']);return;}
		
		//For Handling multiple clicks
		if(!submitRequest()){
			return;
		}
		
		form.submit();
	},


	/**
	* Add2ShopCartAjax This function is used to add a catalog entry to the shopping cart using an AJAX call. This will resolve the catentryId using entitledItemId and adds the item to the cart.
	*				This function will resolve the SKU based on the entitledItemId passed in and call {@link fastFinderJS.AddItem2ShopCartAjax}.
	* @param {String} entitledItemId A DIV containing a JSON object which holds information about a catalog entry. You can reference CachedProductOnlyDisplay.jsp to see how that div is constructed.
	* @param {int} quantity The quantity of the item to add to the cart.
	*
	**/
	Add2ShopCartAjax : function(entitledItemId,quantity)
	{	
		var entitledItemJSON = eval('('+ dojo.byId(entitledItemId).innerHTML +')');
		this.setEntitledItems(entitledItemJSON);
		var catalogEntryId = this.getCatalogEntryId();
		if(catalogEntryId!=null){
			this.AddItem2ShopCartAjax(catalogEntryId , quantity);
			this.baseItemAddedToCart=true;
		}
		else{
			MessageHelper.displayErrorMessage(MessageHelper.messages['ERR_RESOLVING_SKU']);
			this.baseItemAddedToCart=false;
		}
	},
	
	/**
	* ReplaceItemAjax This function is used to replace an item in the shopping cart when the AJAX Checkout flow is enabled. This will be called from the shopping cart and checkout pages.
	*
	* @param {String} entitledItemId A DIV containing a JSON object which holds information about a catalog entry. You can reference CachedProductOnlyDisplay.jsp to see how that div is constructed.
	* @param {int} quantity The quantity of the item to add to the shopping cart.
	*
	**/
	ReplaceItemAjax : function(entitledItemId,quantity){
	
		var entitledItemJSON = eval('('+ dojo.byId(entitledItemId).innerHTML +')');
		this.setEntitledItems(entitledItemJSON);
		var catalogEntryId = this.getCatalogEntryId();
		var removeOrderItemId = "";
		//if(entitledItemJSON[0] != null){
		//	removeOrderItemId = entitledItemJSON[0].orderItemId_remove;
		//}
		var removeOrderItemId = replaceOrderItemId;
		var typeId = document.getElementById("shipmentTypeId");
		var addressId = "";
		var shipModeId = "";
		if(typeId != null && typeId != ""){
			if(typeId.value == "2"){
				//Multiple shipment..each orderItem will have its own addressId and shipModeId..
				addressId = document.getElementById("MS_ShipmentAddress_"+removeOrderItemId).value;
				shipModeId = document.getElementById("MS_ShippingMode_"+removeOrderItemId).value;
			}
			else {
				//Single Shipment..get the common addressId and shipModeId..
				addressId = document.getElementById("addressId_all").value;;
				shipModeId = document.getElementById("shipModeId_all").value;
			}
		}
		if(catalogEntryId!=null){
			if(removeOrderItemId == ""){
				//Just add new catentryId to shop cart in ajax way, since this is AjaxCheckout page
				//This code will never be executed, since we dont have Add To Cart link..
				/*var params = [];
				params.storeId		= this.storeId;
				params.catalogId	= this.catalogId;
				params.langId			= this.langId;
				params.orderId		= ".";
				params.catEntryId	= catalogEntryId;
				params.quantity		= quantity;
				params.addressId = addressId;
				params.shipModeId = shipModeId;
				wc.service.invoke("AjaxAddOrderItem", params);
				*/
			}
			else{
				//Else remove existing catEntryId and then add new one...
				this.ReplaceItemAjaxHelper(catalogEntryId,quantity,removeOrderItemId,addressId,shipModeId);
			}
		}
		else{
				MessageHelper.displayErrorMessage(MessageHelper.messages['ERR_RESOLVING_SKU']);
		}
	},

	/**
	* ReplaceItemNonAjax This function is used to replace an item in the shopping cart when the Non Ajax checkout flow is enabled. This will be called from shopcart and checkout pages.
	* 
	* @param {String} entitledItemId A DIV containing a JSON object which holds information about a catalog entry. You can reference CachedProductOnlyDisplay.jsp to see how that div is constructed.
	* @param {int} quantity The quantity of the item to replace in the shopping cart.
	* @param {form} form The form which contains all the inputs for the item.
	*
	**/ 
	ReplaceItemNonAjax : function(entitledItemId,quantity,form){
	
		var entitledItemJSON = eval('('+ dojo.byId(entitledItemId).innerHTML +')');
		this.setEntitledItems(entitledItemJSON);
		var catalogEntryId = this.getCatalogEntryId();
		var removeOrderItemId = "";
		//if(entitledItemJSON[0] != null){
		//	removeOrderItemId = entitledItemJSON[0].orderItemId_remove;
		//}
		var removeOrderItemId = replaceOrderItemId;
		if(catalogEntryId!=null){
			if(removeOrderItemId == ""){
				//Prepare form to just add this item.. This code will never be executed...
				//Needed only when we plan to show add to cart link also in the quick info..
				//form.action = "orderChangeServiceItemAdd";
				//form.submit();
			}
			else{
				//Else remove existing catEntryId and then add new one...
				form.orderItemId.value = removeOrderItemId;
				var addressId, shipModeId;
				if(quantity == 0){
					console.debug("An invalid quantity was selected");

				}
				if(form.shipmentTypeId != null && form.shipmenTypeId != ""){
					if(form.shipmentTypeId.value == "2"){
						//Multiple shipment..each orderItem will have its own addressId and shipModeId..
						addressId = document.getElementById("MS_ShipmentAddress_"+removeOrderItemId).value;;
						shipModeId = document.getElementById("MS_ShippingMode_"+removeOrderItemId).value;;
					}
					else {
						//Single Shipment..get the common addressId and shipModeId..
						addressId = document.getElementById("addressId_all").value;;
						shipModeId = document.getElementById("shipModeId_all").value;
					}
					form.URL.value = "OrderChangeServiceItemAdd?catEntryId="+catalogEntryId+"&quantity="+quantity+"&addressId="+addressId+"&shipModeId="+shipModeId+"&URL=OrderChangeServiceShipInfoUpdate?URL="+form.URL.value;
			    }
				else{
					form.URL.value = "OrderChangeServiceItemAdd?catEntryId="+catalogEntryId+"&quantity="+quantity+"&URL="+form.URL.value;
				}

				//For Handling multiple clicks
				if(!submitRequest()){
					return;
				}
				
				form.submit();
			}
		}
		else{
			MessageHelper.displayErrorMessage(MessageHelper.messages['ERR_RESOLVING_SKU']);
		}
	},

	/**
	* AddItem2ShopCartAjax This function is used to add an item to the shopping cart using an ajax call.
	*
	* @param {String} catEntryIdentifier The catalog entry ID of the item to add to the cart.
	* @param {int} quantity The quantity of the item to add to the cart.
	*
	**/
	AddItem2ShopCartAjax : function(catEntryIdentifier , quantity)
	{
		var params = [];
		params.storeId		= this.storeId;
		params.catalogId	= this.catalogId;
		params.langId			= this.langId;
		params.orderId		= ".";
		params.catEntryId	= catEntryIdentifier;
		params.quantity		= quantity;
		if( this.shipModeId != "" )
		{
			params.shipModeId = this.shipModeId;
		}
		var invalidQTY = new RegExp(/^\d*$/);
		if(params.quantity == 0 || params.quantity == "" || !invalidQTY.test(params.quantity)){ MessageHelper.displayErrorMessage(MessageHelper.messages['QUANTITY_INPUT_ERROR']); return;}
		//For Handling multiple clicks
		if(!submitRequest()){
			return;
		}   
		cursor_wait();		
		if(this.ajaxShopCart){
			wc.service.invoke("AjaxAddOrderItem", params);
			this.baseItemAddedToCart=true;
		}else{
			wc.service.invoke("AjaxAddOrderItem_shopCart", params);
			this.baseItemAddedToCart=true;
		}
		document.links[2].focus();

	},
	
	/**
	* ReplaceItemAjaxHelper This function is used to replace an item in the cart. This will be called from the {@link fastFinderJS.ReplaceItemAjax} method.
	*
	* @param {String} catalogEntryId The catalog entry of the item to replace to the cart.
	* @param {int} qty The quantity of the item to add.
	* @param {String} removeOrderItemId The order item ID of the catalog entry to remove from the cart.
	* @param {String} addressId The address ID of the order item.
	* @param {String} shipModeId The shipModeId of the order item.
	*
	**/
	ReplaceItemAjaxHelper : function(catalogEntryId,qty,removeOrderItemId,addressId,shipModeId){
		
		var params = [];
		params.storeId = this.storeId;
		params.catalogId = this.catalogId;
		params.langId = this.langId;
		params.orderItemId	= removeOrderItemId;
		params.orderId = ".";

		var params2 = [];
		params2.storeId = this.storeId;
		params2.catalogId = this.catalogId;
		params2.langId = this.langId;
		params2.catEntryId	= catalogEntryId;
		params2.quantity = qty;
		params2.orderId = ".";

		var params3 = [];
		params3.storeId = this.storeId;
		params3.catalogId = this.catalogId;
		params3.langId = this.langId;
		params3.orderId = ".";
		var shipInfoUpdateNeeded = false;
		if(addressId != null && addressId != "" && shipModeId != null && shipModeId != ""){
			params3.addressId = addressId;
			params3.shipModeId = shipModeId;
			shipInfoUpdateNeeded = true;
		}

		//Delcare service for deleting item...
		wc.service.declare({
			id: "AjaxReplaceItem",
			actionId: "AjaxReplaceItem",
			url: "AjaxOrderChangeServiceItemDelete",
			formId: ""

			,successHandler: function(serviceResponse) {
				//Now add the new item to cart..
				if(!shipInfoUpdateNeeded){
					//We dont plan to update addressId and shipMOdeId..so call AjaxAddOrderItem..
					wc.service.invoke("AjaxAddOrderItem", params2);
				}
				else{
					//We need to update the adderessId and shipModeId..so call our temp service to add..
					wc.service.invoke("AjaxAddOrderItemTemp", params2);
				}
			}

			,failureHandler: function(serviceResponse) {
				if (serviceResponse.errorMessage) {
							 MessageHelper.displayErrorMessage(serviceResponse.errorMessage);
					  } else {
							 if (serviceResponse.errorMessageKey) {
									MessageHelper.displayErrorMessage(serviceResponse.errorMessageKey);
							 }
					  }
					  cursor_clear();
			}

		});

		//Delcare service for adding item..
		wc.service.declare({
			id: "AjaxAddOrderItemTemp",
			actionId: "AjaxAddOrderItemTemp",
			url: "AjaxOrderChangeServiceItemAdd",
			formId: ""

			,successHandler: function(serviceResponse) {
				//Now item is added.. call update to set addressId and shipModeId...
				wc.service.invoke("OrderItemAddressShipMethodUpdate", params3);
			}

			,failureHandler: function(serviceResponse) {
				MessageHelper.displayErrorMessage(serviceResponse.errorMessageKey);
			}
		});

		//For Handling multiple clicks
		if(!submitRequest()){
			return;
		}   
		cursor_wait();
		wc.service.invoke("AjaxReplaceItem",params);
	},
		
	/**
	* AddBundle2WishList This function is used to add a bundle to the wish list and it can be called by the product/bundle/package details pages.
	*
	* @param {form} form The form which contains all the inputs for the bundle.
	*
	**/	
	AddBundle2WishList : function(form){
		
		var productCount = form["numberOfProduct"].value; 
		for(var i = 1; i <= productCount; i++){
			var catEntryId = form["catEntryId_" + i].value;
			if(this.selectedProducts[catEntryId]){
				catEntryId = this.getCatalogEntryIdforProduct(this.selectedProducts[catEntryId]);
				if(catEntryId != null)
				form["catEntryId_" + i].value = catEntryId;
				else{
					MessageHelper.displayErrorMessage(MessageHelper.messages['ERR_RESOLVING_SKU']);
					return;
				}
			}
		}
			form.action="InterestItemAdd";
			form.page.value="customerlinkwishlist";
		if (this.ajaxMyAccount){
			if(this.userType=='G'){
				form.URL.value='InterestItemDisplay';
			}else {
				form.URL.value='AjaxLogonForm';
			}
		}else{
			if(this.userType=='G'){
				form.URL.value='InterestItemDisplay';
			}else {
				form.URL.value='NonAjaxAccountWishListDisplayView';
			}
		}
		//For Handling multiple clicks
		if(!submitRequest()){
			return;
		}
		
		form.submit();
	},
	
	/**
	* AddBundle2WishListAjax This fuction is used to add a bundle to the wish list using the ajax flow and it is called by the product/bundle/package details pages.
	*
	* @param {form} form The form which contains all the inputs for the bundle.
	*
	**/
	AddBundle2WishListAjax : function(form){
	
		var params = [];
		//var queryString = dojo.io.encodeForm(dojo.byId(form));

		params.storeId		= this.storeId;
		params.catalogId	= this.catalogId;
		params.langId		= this.langId;
		params.orderId		= ".";
			
		var catEntryArray = [];
		catEntryArray = form.catEntryIDS.value.toString().split(",");
		
		for(var i = 0; i < catEntryArray.length; i++){
			var qty = document.getElementById("quantity_" + catEntryArray[i]).value;
			var catEntryId = catEntryArray[i];
			if(this.selectedProducts[catEntryArray[i]])
				catEntryId = this.getCatalogEntryIdforProduct(this.selectedProducts[catEntryArray[i]]);
			if(qty==0 || qty == null) qty = 1;
			if(qty!=null && qty!='' && catEntryId!=null){
				this.updateParamObject(params,"catEntryId",catEntryId,false,-1);
				this.updateParamObject(params,"quantity",qty,false,-1);
			}
			else{
				MessageHelper.displayErrorMessage(MessageHelper.messages['ERR_RESOLVING_SKU']);
				return;
			}
		}
		//For Handling multiple clicks
		if(!submitRequest()){
			return;
		}   		
		cursor_wait();		
		wc.service.invoke("AjaxInterestItemAdd", params);

	},
	
	/**
	* Add2WishListAjaxByID. This function is used to add a catalog entry to the wish list using ajax by passing in a catalog entry ID.
	*
	* @param {int} catalogEntryId The catalog entry ID of the catalog entry.
	*
	**/
	Add2WishListAjaxByID:function(catalogEntryId)
	{
		if(catalogEntryId!=null){
			var params = [];
			params.storeId		= this.storeId;
			params.catalogId	= this.catalogId;
			params.langId			= this.langId;
			params.catEntryId	= catalogEntryId;
			params.URL = "SuccessfulAJAXRequest";
			if(document.getElementById("controllerURLWishlist")!=null && document.getElementById("controllerURLWishlist")!='undefined')
					CommonControllersDeclarationJS.setControllerURL("WishlistDisplay_Controller",document.getElementById("controllerURLWishlist").value);

			//For Handling multiple clicks
			if(!submitRequest()){
				return;
			}   
			cursor_wait();			
			if(this.ajaxShopCart)
				wc.service.invoke("AjaxInterestItemAdd", params);
			else
				wc.service.invoke("AjaxInterestItemAdd_shopCart", params);
		}
		else MessageHelper.displayErrorMessage(MessageHelper.messages['ERR_RESOLVING_SKU']);
	},
	
	/**
	* Add2WishListAjax This function is used to add an item to the wishlist using ajax by passing in the id of an HTML element containing a JSON object representing a catalog entry.
	*				   This fuction is called by product/bundle/package detail pages.
	* 
	* @param {HTMLDivElement} entitledItemId A DIV containing a JSON object which holds information about a catalog entry. You can reference CachedProductOnlyDisplay.jsp to see how that div is constructed.
	*
	**/
	Add2WishListAjax:function(entitledItemId)
	{
		var entitledItemJSON = eval('('+ dojo.byId(entitledItemId).innerHTML +')');
		this.setEntitledItems(entitledItemJSON);
		
		
		
		var catalogEntryId = this.getCatalogEntryId();
		
		this.Add2WishListAjaxByID(catalogEntryId);
		
	},
	
	/**
	* AddItem2WishListAjax. This function is used to add an item to the wishlist using AJAX by passing in its catentryId. 
	* 						This function can be called by item detail page.
	*
	* @param {String} itemId The catalog entry ID of the catalog entry to add to the wish list.
	*
	**/
	AddItem2WishListAjax:function(itemId)
	{
		var params = [];
		params.storeId		= this.storeId;
		params.catalogId	= this.catalogId;
		params.langId			= this.langId;
		params.catEntryId	= itemId;
		params.URL = "SuccessfulAJAXRequest";

		//For Handling multiple clicks
		if(!submitRequest()){
			return;
		}   		
		cursor_wait();			
		if(this.ajaxShopCart)
			wc.service.invoke("AjaxInterestItemAdd", params);
		else
			wc.service.invoke("AjaxInterestItemAdd_shopCart", params);
	},

	/**
	* Add2WishList This function is used to add a catalog entry to the wish list using the non ajax flow by passing in the ID of an HTML element containing a JSON which represents a catalog entry 
	*			   This fuction is called by the product/bundle/package detail pages.
	*
	* @param {String} entitledItemId A DIV containing a JSON object which holds information about a catalog entry. You can reference CachedProductOnlyDisplay.jsp to see how that div is constructed.
	* @param {form} form form to submit the request.
	*
	**/
	Add2WishList:function(entitledItemId,form)
	{
		var entitledItemJSON = eval('('+ dojo.byId(entitledItemId).innerHTML +')');
		this.setEntitledItems(entitledItemJSON);
		var catalogEntryId = this.getCatalogEntryId();
		this.Add2WishListByID(catalogEntryId,form);
	},


	/**
	* Add2WishListByID Add a catalog entry to the wish list using the non-AJAX flow. This fuction is called by the product/bundle/package detail pages.
	*
	* @param {String} catalogEntryId The catalog entry ID of the catalog entry to be added.
	* @param {form} form  form to submit the request.
	*
	**/
	Add2WishListByID:function(catalogEntryId,form)
	{
		if(catalogEntryId!=null){
			form.productId.value = catalogEntryId;
			form.catEntryId.value = catalogEntryId;
			form.action="InterestItemAdd";
			form.page.value="customerlinkwishlist";
		if (this.ajaxMyAccount){
			if(this.userType=='G'){
				form.URL.value='InterestItemDisplay';
			}else {
				form.URL.value='AjaxLogonForm';
			}
		}else{
			if(this.userType=='G'){
				form.URL.value='InterestItemDisplay';
			}else {
				form.URL.value='NonAjaxAccountWishListDisplayView';
			}
		}
			form.quantity.value = "1";
			
			//For Handling multiple clicks
			if(!submitRequest()){
				return;
			}
			
			form.submit();
		}
		else MessageHelper.displayErrorMessage(MessageHelper.messages['ERR_RESOLVING_SKU']);
	},
	
	
	/** 
	* AddItem2WishList Add a SKU to the wish list using the non-AJAX flow. This function is called by the item detail page.
	*
	* @param {form} form The form to submit the request.
	*
	**/
	AddItem2WishList:function(form)
	{
		form.action="InterestItemAdd"
		form.quantity.value = "1";
		form.page.value="customerlinkwishlist";
		if (this.ajaxMyAccount){
			if(this.userType=='G'){
				form.URL.value='InterestItemDisplay';
			}else {
				form.URL.value='AjaxLogonForm';
			}
		}else{
			if(this.userType=='G'){
				form.URL.value='InterestItemDisplay';
			}else {
				form.URL.value='NonAjaxAccountWishListDisplayView';
			}
		}
		//For Handling multiple clicks
		if(!submitRequest()){
			return;
		}
			
		form.submit();
	},
	
	/**
	* Add2CompareAjax Add a catalog entry to the compare zone using the AJAX flow.
	*
	* @param {String} catEntryIdentifier The catalog entry ID of the catalog entry to add to the compare zone.
	* @param {String} dragImagePath The image path of the image to show in the compare zone.
	* @param {String} url The catalog entry display URL.
	* @param {String} dragImageDescription The description associated with the image to show in the compare zone.
	*
	**/
	Add2CompareAjax:function(catEntryIdentifier, dragImagePath , url, dragImageDescription) 
	{
		if(compareProductJS != null)
			compareProductJS.Add2CompareAjax(catEntryIdentifier, dragImagePath, url, dragImageDescription);
	},

	/**
	* loadContentURL Sets the URL of the page to load into CategoryDisplay_Controller which in turn is used to display categories
	* 				 on the CategoryDisplay.jsp and DepartmentDisplay.jsp. The HistoryTracker is also updated.
	*
	* @param {String} contentURL The URL to load contents from.
	*
	**/
	loadContentURL:function(contentURL){
		
		//For Handling multiple clicks
		if(!submitRequest()){
			return;
		}   		
		cursor_wait();
		CommonControllersDeclarationJS.setControllerURL('CategoryDisplay_Controller',contentURL);		
		wc.render.updateContext("CategoryDisplay_Context");
	},
	
	
	/**
	* loadSubCategoryContentURL Sets the URL of the page to load into SubCategoryDisplay_Controller which in turn is used to display sub categories 
	* 							on the CategoryDisplay.jsp and DepartmentDisplay.jsp. The HistoryTracker is also updated.
	* 
	* @param {String} contentURL The URL to display for a sub category.
	*
	**/
	loadSubCategoryContentURL:function(contentURL){
		
		MessageHelper.hideAndClearMessage();

		//For Handling multiple clicks
		if(!submitRequest()){
			return;
		}   		
		cursor_wait();
		CommonControllersDeclarationJS.setControllerURL('SubCategoryDisplay_Controller',contentURL);	
		wc.render.updateContext("SubCategoryDisplay_Context");
	},
	
	/**
	* goBack Called when the back button is clicked in the browser. 
	*		 Uses the changeUrl set by the HistoryTracker and calls the loadContentURL method so that the state of the page get 
	* 		 loaded from a previous state in the page history.
	**/
	goBack:function(){
		
		categoryDisplayJS.loadContentURL(this.changeUrl);
		categoryDisplayJS.isHistory=true;

	},


	/**
	* goForward Called when the forward button is clicked in the browser. 
	*			Uses the changeUrl set by HistoryTracker and calls the loadContentURL method so that the state of the page gets
	*           loaded from the next available point in the page history.
	**/
	goForward:function(){
		
		categoryDisplayJS.loadContentURL(this.changeUrl);
		isHistory=true;
	},


	/**
	* HistoryTracker Used to track the history for the browser back and forward buttons.
	*
	* @param {String} elementId HistoryTracker id.
	* @param {String} changeUrl The change url of the current state.
	*
	**/
	HistoryTracker:function(elementId, changeUrl){
	
		this.elementId = elementId; 
		this.changeUrl =  changeUrl;

	},
	
	/**
	* processBookmarkURL Processes the bookmark using the bookmarkId which is stored in location.hash.
	**/
	processBookmarkURL : function(){
		
			var bookmarkId = location.hash;	
			if(bookmarkId){					        
				bookmarkId = bookmarkId.substring(1, bookmarkId.length);
			}   
			if(bookmarkId){
				var indexOfIdentifier = bookmarkId.indexOf("identifier", 0);
				if ( indexOfIdentifier >= 0) {
					var realUrl = bookmarkId.substring(0, indexOfIdentifier - 1);
				}
			}

			if(bookmarkId == null || bookmarkId == ""){

			}
	},
	
	
	/**
	* initializeMerchandisingAssociation Since the merchandising associations are only displayed one at a time with a scrolling widget this method
	*									 will initialize that widget with a specified starting index represented by thumbnailIndex so that the correct 
	*									 merchandising association is displayed first.
	*									 This function is called on MerchandisingAssociationsDisplay.jsp.s
	* 
	* @param {String} thumbnailIndex The index of the association that needs to be displayed.
	*
	**/
	initializeMerchandisingAssociation:function(thumbnailIndex){
	
	var associationDisplay = document.getElementById("marchandisingAssociationDisplay");
	var totalPriceMsg = document.getElementById("totalPriceMsg").value;
	var baseCatEntryJSON = eval('('+ dojo.byId("baseCatEntryDetails").innerHTML +')');
	this.baseCatalogEntryDetails = baseCatEntryJSON;
	var basePrice=this.baseCatalogEntryDetails[0].baseCatEntry_Price;
	this.totalAssociationCount= this.baseCatalogEntryDetails[0].toatlAssociations;
	var identifierJSON = "associatedCatEntries_"+thumbnailIndex;
	var associationEntryJSON = eval('('+ dojo.byId(identifierJSON).innerHTML +')');
	this.merchandisingAssociationItems = associationEntryJSON;
	var toatlPrice = parseFloat(basePrice)+ parseFloat(this.merchandisingAssociationItems[0].catEntry_Price);
	var dragType = "";
		
	if(this.merchandisingAssociationItems[0].catEntry_Type =='ProductBean'){
		dragType = "product";
	}else if (this.merchandisingAssociationItems[0].catEntry_Type =='ItemBean'){
		dragType = "item";
	}else if (this.merchandisingAssociationItems[0].catEntry_Type =='PackageBean'){
		dragType = "package";
	}else if (this.merchandisingAssociationItems[0].catEntry_Type =='BundleBean'){
		dragType = "bundle";
	}
//Creates the inner HTML of the associated item determined by the thumbnailIndex which needs to be displayed in the page.
var widgetHTML = "";
if(document.getElementById('addToCartLink')){
var url = "AjaxOrderItemDisplayView?storeId="+this.storeId+"&catalogId="+this.catalogId+"&langId="+this.langId;
						widgetHTML = widgetHTML
						+"<form name='OrderItemAddForm_"+this.merchandisingAssociationItems[0].catEntry_Identifier+"' action='OrderChangeServiceItemAdd' method='post' id='OrderItemAddForm_"+this.merchandisingAssociationItems[0].catEntry_Identifier+"'>\n"
						+"<input type='hidden' name='storeId' value='"+this.storeId+"' id='OrderItemAddForm_storeId_"+this.merchandisingAssociationItems[0].catEntry_Identifier+"'/>\n"
						+"<input type='hidden' name='orderId' value='.' id='OrderItemAddForm_orderId_"+this.merchandisingAssociationItems[0].catEntry_Identifier+"'/>\n"
						+"<input type='hidden' name='catalogId' value='"+this.catalogId+"' id='OrderItemAddForm_orderId_"+this.merchandisingAssociationItems[0].catEntry_Identifier+"'/>\n"
						+"<input type='hidden' name='URL' value='"+ url + "' id='OrderItemAddForm_url_"+this.merchandisingAssociationItems[0].catEntry_Identifier+"'/>\n"
						+"<input type='hidden' name='errorViewName' value='InvalidInputErrorView' id='OrderItemAddForm_errorViewName_"+this.merchandisingAssociationItems[0].catEntry_Identifier+"'/>\n"
						+"<input type='hidden' name='catEntryId' value='"+this.merchandisingAssociationItems[0].catEntry_Identifier+"' id='OrderItemAddForm_catEntryId_"+this.merchandisingAssociationItems[0].catEntry_Identifier+"'/>\n"
						+"<input type='hidden' name='productId' value='"+this.merchandisingAssociationItems[0].catEntry_Identifier+"' id='OrderItemAddForm_productId_"+this.merchandisingAssociationItems[0].catEntry_Identifier+"'/>\n"
						+"<input type='hidden' value='1' name='quantity' id='OrderItemAddForm_quantity_"+this.merchandisingAssociationItems[0].catEntry_Identifier+"'/>\n"
						+"<input type='hidden' value='' name='page' id='OrderItemAddForm_page_"+this.merchandisingAssociationItems[0].catEntry_Identifier+"'/>\n"
						+"</form>\n";
						}
widgetHTML = widgetHTML					
			+"<div class='scroller' id='WC_CategoryDisplayJS_div_1'>";
			if(this.totalAssociationCount > 1){
				if(this.associationThumbnailIndex < this.totalAssociationCount){
					widgetHTML = widgetHTML
					+"		<a href='Javascript:categoryDisplayJS.showNextAssociation()'  id='WC_ProductAssociation_UpArrow_Link_1'>";
				}
				widgetHTML = widgetHTML
				+"		<img src='"+this.baseCatalogEntryDetails[0].storeImage_Path+"i_up_arrow.png' alt='"+this.displayNextAssociation+"'/></a>";
			}
			widgetHTML = widgetHTML +" <br />"
			+"<div id='baseContent_"+this.merchandisingAssociationItems[0].catEntry_Identifier+"'";
			if(this.merchandisingAssociationItems[0].showProductQuickView == 'true'){
				widgetHTML = widgetHTML
				+" onmouseover='showPopupButton("+this.merchandisingAssociationItems[0].catEntry_Identifier+");' onmouseout='hidePopupButton("+this.merchandisingAssociationItems[0].catEntry_Identifier+");'>";
			}else{
				widgetHTML = widgetHTML
				+" >";
			}
			if(this.merchandisingAssociationItems[0].productDragAndDrop == 'true'){
				widgetHTML = widgetHTML
					+" <div dojoType='dojo.dnd.Source' jsId='dndSource' id="+this.merchandisingAssociationItems[0].catEntry_Identifier+" copyOnly='true' dndType='"+dragType+"'>"
					+"		<div class='dojoDndItem' dndType='"+dragType+"' id='WC_CategoryDisplayJS_div_draganddrop'>";
			}
			widgetHTML = widgetHTML
			+"	<a href='"+this.merchandisingAssociationItems[0].catEntry_ProductLink+"'  id='img"+this.merchandisingAssociationItems[0].catEntry_Identifier+"' onfocus='showPopupButton("+this.merchandisingAssociationItems[0].catEntry_Identifier+");'>"
			+"		<img src='"+this.merchandisingAssociationItems[0].catEntry_Thumbnail+"' alt='"+this.merchandisingAssociationItems[0].catEntry_ShortDescription+"' class='img'/>"
			+"	</a><br />";
			if(this.merchandisingAssociationItems[0].productDragAndDrop == 'true'){
				widgetHTML = widgetHTML
					+"		</div>"
					+"	</div>";
			}
			if(this.merchandisingAssociationItems[0].showProductQuickView == 'true'){
				widgetHTML = widgetHTML
				+" <div id='popupButton_"+this.merchandisingAssociationItems[0].catEntry_Identifier+"' class='main_quickinfo_button'>"
					+"<span class='secondary_button' >\n"
						+"<span class='button_container' >\n"
							+"<span class='button_bg' >\n"
								+"<span class='button_top'>\n"
									+"<span class='button_bottom'>\n"
										+"<a id='QuickInfoButton_"+this.merchandisingAssociationItems[0].catEntry_Identifier+"' href='#' onclick='javaScript:var actionListImageAcct = new popupActionProperties(); actionListImageAcct.showWishList="+this.merchandisingAssociationItems[0].associationProductBuyable+"; actionListImageAcct.showAddToCart="+this.merchandisingAssociationItems[0].associationProductBuyable+"; showPopup("+this.merchandisingAssociationItems[0].catEntry_Identifier+","+this.storeId+","+this.langId+","+this.catalogId+",event,null,null,actionListImageAcct);' onkeypress='javaScript:var actionListImageAcct = new popupActionProperties(); actionListImageAcct.showWishList="+this.merchandisingAssociationItems[0].associationProductBuyable+"; actionListImageAcct.showAddToCart="+this.merchandisingAssociationItems[0].associationProductBuyable+"; showPopup("+this.merchandisingAssociationItems[0].catEntry_Identifier+","+this.storeId+","+this.langId+","+this.catalogId+",event,null,null,actionListImageAcct);' onblur='hidePopupButton("+this.merchandisingAssociationItems[0].catEntry_Identifier+");' role='wairole:button' waistate:haspopup='true'>"+this.merchandisingAssociationItems[0].showProductQuickViewLable+"</a>"
									+"</span>\n"
								+"</span>\n"
							+"</span>\n"
						+"</span>\n"
					+"</span>\n"										
				+"</div>\n";
			}
			widgetHTML = widgetHTML
			+"</div>";	
		
			if(this.totalAssociationCount > 1){
				if(this.associationThumbnailIndex > 1 ){
					widgetHTML = widgetHTML
					+"		<a href='Javascript:categoryDisplayJS.showPreviousAssociation()'  id='WC_ProductAssociation_DownArrow_Link_1'>";
				}
				widgetHTML = widgetHTML
				+"		<img src='"+this.baseCatalogEntryDetails[0].storeImage_Path+"i_down_arrow.png' alt='"+this.displayPrevAssociation+"'/></a>";
			}
			
			var comboText = this.baseCatalogEntryDetails[0].associatedProductsName.replace("{0}", this.baseCatalogEntryDetails[0].baseCatEntry_Name);
			comboText = comboText.replace("{1}", this.merchandisingAssociationItems[0].catEntry_Name);
			
			widgetHTML = widgetHTML
			+"</div>"
			+"<div class='combo_text' id='WC_CategoryDisplayJS_div_2'>\n"
			+"	<h1 class='status_msg'>"+ comboText +"</h1>\n"
			+"	<span class='grey'>"+totalPriceMsg+dojo.currency.format(toatlPrice.toFixed(2), {currency: this.baseCatalogEntryDetails[0].currency})+"</span>\n"
			+"</div>\n";
			widgetHTML = widgetHTML
			+"<input type='hidden' id='compareImgPath_"+this.merchandisingAssociationItems[0].catEntry_Identifier+"' value='"+this.merchandisingAssociationItems[0].catEntry_Thumbnail_compare+"'/>"
			+"<input type='hidden' id='compareProductDetailsPath_"+this.merchandisingAssociationItems[0].catEntry_Identifier+"' value='"+this.merchandisingAssociationItems[0].catEntry_ProductLink+"'/>"
			+"<input type='hidden' id='compareImgDescription_"+this.merchandisingAssociationItems[0].catEntry_Identifier+"' value='"+this.merchandisingAssociationItems[0].catEntry_Name+"'/>";
			associationDisplay.innerHTML=null;
			associationDisplay.innerHTML=widgetHTML;
			dojo.parser.parse(associationDisplay);
},


	/**
	* showNextAssociation Displays the next association in the association array. No action is performed if it is already at the last item.
	*				      This function is used with the merchandising association widget on the MerchandisingAssociationDisplay.jsp to display the next
	*					  association available.
	**/
	showNextAssociation : function(){
		
		if(this.associationThumbnailIndex < this.totalAssociationCount){
			this.associationThumbnailIndex = this.associationThumbnailIndex+1;
			this.initializeMerchandisingAssociation(this.associationThumbnailIndex);
		}
	},

	/**
	* showPreviousAssociation Displays the previous association in the association array. No action is performed if it is already the first item.
	*				      This function is used with the merchandising association widget on the MerchandisingAssociationDisplay.jsp to display the previous
	*					  association available.
	**/
	showPreviousAssociation : function(){
		
	if(this.associationThumbnailIndex > 1 ){
			this.associationThumbnailIndex = this.associationThumbnailIndex-1;
			this.initializeMerchandisingAssociation(this.associationThumbnailIndex);
		}
	},

	/**
	* AddAssociation2ShopCartAjax Adds the associated product to the shopping cart when AjaxAddToCart is enabled.
	*
	* @param {String} baseProductId The catalog entry ID of the parent product.
	* @param {int} baseProductQuantity The quantity of the parent product to add.
	*
	**/
	AddAssociation2ShopCartAjax:function(baseProductId,baseProductQuantity){
	
		var identifierJSON = "associatedCatEntries_"+this.associationThumbnailIndex;
		//Get the associated item from the JSON object.
		var associationEntryJSON = eval('('+ dojo.byId(identifierJSON).innerHTML +')');
		this.merchandisingAssociationItems = associationEntryJSON;
		this.baseItemAddedToCart = false;
		//Add the parent product to the cart.
		if(this.merchandisingAssociationItems[0].catEntry_Type=='ProductBean'){
			this.Add2ShopCartAjax(baseProductId,baseProductQuantity);
			if(this.baseItemAddedToCart){
				//Show the pop-up to select the attributes of the associated product.
				showPopup(this.merchandisingAssociationItems[0].catEntry_Identifier,this.storeId,this.langId,this.catalogId,function(e){return e;},'marchandisingAssociationDisplay');
			}
		}else if (this.merchandisingAssociationItems[0].catEntry_Type=='ItemBean' || this.merchandisingAssociationItems[0].catEntry_Type=='PackageBean' || this.merchandisingAssociationItems[0].catEntry_Type=='BundleBean'){
			//Get the associated item from the JSON object.
			var entitledItemJSON = eval('('+ dojo.byId(baseProductId).innerHTML +')');
			this.setEntitledItems(entitledItemJSON);
			var catalogEntryId = this.getCatalogEntryId();
			var params = [];
				params.storeId		= this.storeId;
				params.catalogId	= this.catalogId;
				params.langId			= this.langId;
				params.orderId		= ".";
			if(catalogEntryId!=null){
				this.updateParamObject(params,"catEntryId",catalogEntryId,false,-1);
				this.updateParamObject(params,"quantity",baseProductQuantity,false,-1);
				if(this.merchandisingAssociationItems[0].catEntry_Type=='BundleBean'){
					var form = document.getElementById(this.merchandisingAssociationItems[0].catEntry_BundleFormId);
					var catEntryArray = [];
					// add the individual bundle items to the request.
					catEntryArray = form.catEntryIDS.value.toString().split(",");
					for(var i = 0; i < catEntryArray.length; i++){
						var qty = document.getElementById("quantity_" + catEntryArray[i]).value;
						var catEntryId = catEntryArray[i];
						if(this.getDefaultItem(catEntryArray[i]))
							catEntryId = this.getDefaultItem(catEntryArray[i]);
						if(qty==0 || qty == null) qty = 1;
						if(qty!=null && qty!='' && catEntryId!=null){
							this.updateParamObject(params,"catEntryId",catEntryId,false,-1);
							this.updateParamObject(params,"quantity",qty,false,-1);
						}else{
							MessageHelper.displayErrorMessage(MessageHelper.messages['ERR_RESOLVING_SKU']);
							return;
						}
					}
				}else{
					this.updateParamObject(params,"catEntryId",this.merchandisingAssociationItems[0].catEntry_Identifier,false,-1);
					this.updateParamObject(params,"quantity",1,false,-1);
				}
			}else{
				MessageHelper.displayErrorMessage(MessageHelper.messages['ERR_RESOLVING_SKU']);
				return;
			}
			//For Handling multiple clicks
			if(!submitRequest()){
				return;
			}   		
			cursor_wait();				
			//Invoke service to add to the cart.
			wc.service.invoke("AjaxAddOrderItem", params);
		}
	},

	/**
	* AddMarchandisingAssociation2ShopCart Adds the associated product to the shopping cart when AjaxAddToCart is disabled.
	*
	* @param {String} entitledItemId A DIV containing a JSON object which holds information about a catalog entry. You can reference CachedProductOnlyDisplay.jsp to see how that div is constructed.
	* @param {form} form The form which contains the details of the item that needs to be added to the cart. This method will set the quanitty, catEntryId_1, productId_1 as well as
	*					 quantity_2, catEntryId_2 and productId_2 values in the form based on the values from the quantity you enter into this method and the catalog entry ID 
	* 					 resolved from retrieving the catalog entry ID of the entitled item passed in.						
	* @param {int} quantity The quantity of the parent product to add.
	*
	**/
	AddMarchandisingAssociation2ShopCart : function(entitledItemId,form,quantity){
	
	var identifierJSON = "associatedCatEntries_"+this.associationThumbnailIndex;
	var associationEntryJSON = eval('('+ dojo.byId(identifierJSON).innerHTML +')');
	this.merchandisingAssociationItems = associationEntryJSON;
	//get the item form the JSON object	
	var entitledItemJSON = eval('('+ dojo.byId(entitledItemId).innerHTML +')');
	this.setEntitledItems(entitledItemJSON);
	var catalogEntryId_1 = this.getCatalogEntryId();
	//Add the product to the cart if the product attributes are selected otherwise show the pop-up dialog.	
	if(this.merchandisingAssociationItems[0].catEntry_Type=='ProductBean'){
		if(catalogEntryId_1!=null){
			form.catEntryId_1.value = catalogEntryId_1;
			form.productId_1.value = catalogEntryId_1;
			form.quantity_1.value = quantity;
			this.merchandisingProductAssociationAddToCart = true;
			this.merchandisingProductAssociationForm = form;
			showPopup(this.merchandisingAssociationItems[0].catEntry_Identifier,this.storeId,this.langId,this.catalogId,function(e){return e;},'marchandisingAssociationDisplay');
		}else{
			MessageHelper.displayErrorMessage(MessageHelper.messages['ERR_RESOLVING_SKU']);
			return;
		}
	}else if (this.merchandisingAssociationItems[0].catEntry_Type=='ItemBean' || this.merchandisingAssociationItems[0].catEntry_Type=='PackageBean' || this.merchandisingAssociationItems[0].catEntry_Type=='BundleBean'){
		//Add the  items to the shop cart.
		if(catalogEntryId_1!=null){
			form.catEntryId_1.value = catalogEntryId_1;
			form.productId_1.value = catalogEntryId_1;
			form.quantity_1.value = quantity;
			if(this.merchandisingAssociationItems[0].catEntry_Type=='BundleBean'){
				// add the individual bundle items to the request.
				var bundleForm = document.getElementById(this.merchandisingAssociationItems[0].catEntry_BundleFormId);
				var catEntryArray = [];
				catEntryArray = bundleForm.catEntryIDS.value.toString().split(",");
				var catEntryCount = 3;
				for(var i = 0; i < catEntryArray.length; i++){
					var qty = document.getElementById("quantity_" + catEntryArray[i]).value;
					var catEntryId = catEntryArray[i];
					if(this.getDefaultItem(catEntryArray[i]))
							catEntryId = this.getDefaultItem(catEntryArray[i]);
					if(qty==0 || qty == null) qty = 1;
					if(qty!=null && qty!='' && catEntryId!=null){
						if(i==0){
							form.catEntryId_2.value = catEntryId;
							form.productId_2.value = catEntryId;
							form.quantity_2.value = qty;	
						}else{
							var input1 = document.createElement("input");
							input1.setAttribute("id", "OrderAssociationItemAddForm_catEntryId_"+catEntryId);
							input1.setAttribute("type", "hidden");
							input1.setAttribute("name", "catEntryId_"+catEntryCount);
							input1.setAttribute("value", catEntryId);
							form.appendChild(input1);
							var input2 = document.createElement("input");
							input2.setAttribute("id", "OrderAssociationItemAddForm_productId_"+catEntryId);
							input2.setAttribute("type", "hidden");
							input2.setAttribute("name", "productId_"+catEntryCount);
							input2.setAttribute("value", catEntryId);
							form.appendChild(input2);
							var quantity1 = document.createElement("input");
							quantity1.setAttribute("id", "OrderAssociationItemAddForm_quantity_"+catEntryId);
							quantity1.setAttribute("type", "hidden");
							quantity1.setAttribute("name", "quantity_"+catEntryCount);
							quantity1.setAttribute("value", "1");
							form.appendChild(quantity1);
							catEntryCount = catEntryCount+1;
						}
						
					}else{
						MessageHelper.displayErrorMessage(MessageHelper.messages['ERR_RESOLVING_SKU']);
						return;
					}
				}
			}else{
				form.catEntryId_2.value = this.merchandisingAssociationItems[0].catEntry_Identifier;
				form.productId_2.value = this.merchandisingAssociationItems[0].catEntry_Identifier;
				form.quantity_2.value = "1";
			}
			
			//For Handling multiple clicks
			if(!submitRequest()){
				return;
			}

			// submit the form to add the items to the shop cart.
			form.submit();	
		}else{
			MessageHelper.displayErrorMessage(MessageHelper.messages['ERR_RESOLVING_SKU']);
			return;
		}
		}
	},

	/** 
	* AddAssociation2ShopCart Adds an associated product to the shopping cart. This function is called by other functions in the FastFinderDisplay.js such as Add2ShopCart().
	* 
	* @param {String} associatedItemId The catalog entry ID of the associated item.
	* @param {int} quantity The quantity of the associated item to add.
	*
	**/
	AddAssociation2ShopCart:function(associatedItemId,quantity){
	
	var form = this.merchandisingProductAssociationForm;
	this.merchandisingProductAssociationAddToCart = false;
	if(this.isParentBundleBean){
		// add the individual bundle items to the request.
		var catEntryArray = [];
		catEntryArray = form.catEntryIDS.value.toString().split(",");
		var bundleItemsCount = 1;
		for(var i = 0; i < catEntryArray.length; i++){
			var qty = document.getElementById("quantity_" + catEntryArray[i]).value;
			var catEntryId = catEntryArray[i];
			if(this.selectedProducts[catEntryArray[i]])
				catEntryId = this.getCatalogEntryIdforProduct(this.selectedProducts[catEntryArray[i]]);
			if(qty==0 || qty == null) qty = 1;
			if(qty!=null && qty!='' && catEntryId!=null){
				var input1 = document.createElement("input");
				input1.setAttribute("id", "OrderItemAddForm_catEntryId_"+catEntryId);
				input1.setAttribute("type", "hidden");
				input1.setAttribute("name", "catEntryId_"+bundleItemsCount);
				input1.setAttribute("value", catEntryId);
				bundleItemsCount = bundleItemsCount + 1;
				form.appendChild(input1);
			}else{
				MessageHelper.displayErrorMessage(MessageHelper.messages['ERR_RESOLVING_SKU']);
				return;
			}
		}
		var input2 = document.createElement("input");
		input2.setAttribute("id", "OrderItemAddForm_catEntryId_"+associatedItemId);
		input2.setAttribute("type", "hidden");
		input2.setAttribute("name", "catEntryId_"+bundleItemsCount);
		input2.setAttribute("value", associatedItemId);
		form.appendChild(input2);
		var quantity1 = document.createElement("input");
		quantity1.setAttribute("id", "OrderItemAddForm_quantity_"+associatedItemId);
		quantity1.setAttribute("type", "hidden");
		quantity1.setAttribute("name", "quantity_"+bundleItemsCount);
		quantity1.setAttribute("value", quantity);
		form.appendChild(quantity1);
		form.URL.value = "AjaxOrderItemDisplayView";
		this.isParentBundleBean = false;
	}else{
		form.catEntryId_2.value = associatedItemId;
		form.productId_2.value = associatedItemId;
		form.quantity_2.value = quantity;
	}
	
	//For Handling multiple clicks
	if(!submitRequest()){
		return;
	}
	
	// submit the form to add the items to the shop cart.
	form.submit();
	this.merchandisingProductAssociationForm = "";
	},

	/**
	* AddAssociationItem2ShopCartAjax Adds the associated item to the shopping cart when AjaxAddToCart is enabled.
	*								  This function is called from MerchandisingAssociationsDisplay.jsp to add an associated item to the shopping cart.
	*
	* @param {String} baseItemId The catalog entry ID of the item to add.
	* @param {int} baseItemQuantity The quantity to add.
	*
	**/
	AddAssociationItem2ShopCartAjax:function(baseItemId , baseItemQuantity){
	
	var identifierJSON = "associatedCatEntries_"+this.associationThumbnailIndex;
	//get the item form the JSON object	
	var associationEntryJSON = eval('('+ dojo.byId(identifierJSON).innerHTML +')');
	this.merchandisingAssociationItems = associationEntryJSON;
	this.baseItemAddedToCart = false;
	//Add the parent item to the cart and if the associated catentry is a product bean then show the pop-up dialog.
	if(this.merchandisingAssociationItems[0].catEntry_Type=='ProductBean'){
		this.AddItem2ShopCartAjax(baseItemId,baseItemQuantity);
		if(this.baseItemAddedToCart){
			showPopup(this.merchandisingAssociationItems[0].catEntry_Identifier,this.storeId,this.langId,this.catalogId,function(e){return e;},'marchandisingAssociationDisplay');
		}
	}else if (this.merchandisingAssociationItems[0].catEntry_Type=='ItemBean' || this.merchandisingAssociationItems[0].catEntry_Type=='PackageBean' || this.merchandisingAssociationItems[0].catEntry_Type=='BundleBean'){
			var params = [];
				params.storeId		= this.storeId;
				params.catalogId	= this.catalogId;
				params.langId			= this.langId;
				params.orderId		= ".";
			this.updateParamObject(params,"catEntryId",baseItemId,false,-1);
			this.updateParamObject(params,"quantity",baseItemQuantity,false,-1);
			// add the individual bundle items to the request.
			if(this.merchandisingAssociationItems[0].catEntry_Type=='BundleBean'){
				var form = document.getElementById(this.merchandisingAssociationItems[0].catEntry_BundleFormId);
				var catEntryArray = [];
				catEntryArray = form.catEntryIDS.value.toString().split(",");
				for(var i = 0; i < catEntryArray.length; i++){
					var qty = document.getElementById("quantity_" + catEntryArray[i]).value;
					var catEntryId = catEntryArray[i];
					if(this.getDefaultItem(catEntryArray[i]))
							catEntryId = this.getDefaultItem(catEntryArray[i]);
					if(qty==0 || qty == null) qty = 1;
					if(qty!=null && qty!='' && catEntryId!=null){
						this.updateParamObject(params,"catEntryId",catEntryId,false,-1);
						this.updateParamObject(params,"quantity",qty,false,-1);
					}else{
						MessageHelper.displayErrorMessage(MessageHelper.messages['ERR_RESOLVING_SKU']);
						return;
					}
				}
			}else{
				this.updateParamObject(params,"catEntryId",this.merchandisingAssociationItems[0].catEntry_Identifier,false,-1);
				this.updateParamObject(params,"quantity",1,false,-1);
			}
			
			//For Handling multiple clicks
			if(!submitRequest()){
				return;
			} 			
			cursor_wait();			
			//Invoke service to add item to the cart.
			wc.service.invoke("AjaxAddOrderItem", params);
		}
	},

	/**
	* AddAssociationItem2ShopCart Adds the parent item with associated catentry to the shopping cart when AjaxAddToCart is disabled.
	*
	* @param {form} form The form which contains the details of the item that needs to be added to the cart. The {@link fastFinderJS.merchandisingProductAssociationForm}
	*				      is set to the the form passed in. The forms quanitity_1 and quantity_2 values are set according to the values passed in 
	*					  for quantity and the value of the quantity_<catEntryId> element for the two quantity values respectively. The catEntryId_2 and productId_2 values
	*					  are also set. 
	* @param {int} quantity The quantity of the item to add to the cart.
	*
	**/
	AddAssociationItem2ShopCart : function(form,quantity){

	var identifierJSON = "associatedCatEntries_"+this.associationThumbnailIndex;
	//Get the associated item from the JSON object.
	var associationEntryJSON = eval('('+ dojo.byId(identifierJSON).innerHTML +')');
	this.merchandisingAssociationItems = associationEntryJSON;
	//Add the parent item to the cart and if the associated catentry is a product bean then show the pop-up dialog.
	if(this.merchandisingAssociationItems[0].catEntry_Type=='ProductBean'){
		if(quantity) form.quantity_1.value = quantity;
		this.merchandisingProductAssociationAddToCart = true;
		this.merchandisingProductAssociationForm = form;
		showPopup(this.merchandisingAssociationItems[0].catEntry_Identifier,this.storeId,this.langId,this.catalogId,function(e){return e;},'marchandisingAssociationDisplay');
	}else if (this.merchandisingAssociationItems[0].catEntry_Type=='ItemBean' || this.merchandisingAssociationItems[0].catEntry_Type=='PackageBean' || this.merchandisingAssociationItems[0].catEntry_Type=='BundleBean'){
		if(quantity) form.quantity_1.value = quantity;
			// add the individual bundle items to the request.
			if(this.merchandisingAssociationItems[0].catEntry_Type=='BundleBean'){
				var bundleForm = document.getElementById(this.merchandisingAssociationItems[0].catEntry_BundleFormId);
				var catEntryArray = [];
				catEntryArray = bundleForm.catEntryIDS.value.toString().split(",");
				var catEntryCount = 3;
				for(var i = 0; i < catEntryArray.length; i++){
					var qty = document.getElementById("quantity_" + catEntryArray[i]).value;
					var catEntryId = catEntryArray[i];
					if(this.getDefaultItem(catEntryArray[i]))
							catEntryId = this.getDefaultItem(catEntryArray[i]);
					if(qty==0 || qty == null) qty = 1;
						if(i==0){
							form.catEntryId_2.value = catEntryId;
							form.productId_2.value = catEntryId;
							form.quantity_2.value = qty;	    
						}else{
							var input1 = document.createElement("input");
							input1.setAttribute("id", "OrderAssociationItemAddForm_catEntryId_"+catEntryId);
							input1.setAttribute("type", "hidden");
							input1.setAttribute("name", "catEntryId_"+catEntryCount);
							input1.setAttribute("value", catEntryId);
							form.appendChild(input1);
							var input2 = document.createElement("input");
							input2.setAttribute("id", "OrderAssociationItemAddForm_productId_"+catEntryId);
							input2.setAttribute("type", "hidden");
							input2.setAttribute("name", "productId_"+catEntryCount);
							input2.setAttribute("value", catEntryId);
							form.appendChild(input2);
							var quantity1 = document.createElement("input");
							quantity1.setAttribute("id", "OrderAssociationItemAddForm_quantity_"+catEntryId);
							quantity1.setAttribute("type", "hidden");
							quantity1.setAttribute("name", "quantity_"+catEntryCount);
							quantity1.setAttribute("value", "1");
							form.appendChild(quantity1);
							catEntryCount = catEntryCount+1;
						}
					}
			}else{
				form.catEntryId_2.value = this.merchandisingAssociationItems[0].catEntry_Identifier;
				form.productId_2.value = this.merchandisingAssociationItems[0].catEntry_Identifier;
				form.quantity_2.value = "1";
			}
			
			//For Handling multiple clicks
			if(!submitRequest()){
				return;
			}
			
			//submit the form to add the item to the cart.
			form.submit();	
		}
	},

	/**
	* AddAssociationBundle2ShopCartAjax Adds the parent bundle and associated products to the shopping cart when AjaxAddToCart is enabled.
	*									This function is used on MerchandisingAssociationsDisplay.jsp.
	*
	* @param {form} form The form which contains the details of the catalog entries that need to be added to the cart.
	* 				      This form is expected to have a comma separated list of catalog entry IDs of catalog entries in the bundle which should be added to the shopping cart.
	*
	**/
	AddAssociationBundle2ShopCartAjax:function(form){

	var identifierJSON = "associatedCatEntries_"+this.associationThumbnailIndex;
	//Get the associated item from the JSON object.
	var associationEntryJSON = eval('('+ dojo.byId(identifierJSON).innerHTML +')');
	this.merchandisingAssociationItems = associationEntryJSON;
	this.baseItemAddedToCart = false;
//Add the parent bundle to the cart and show the pop-up dialog for the associated product.
			
			var params = [];
			
			params.storeId		= this.storeId;
			params.catalogId	= this.catalogId;
			params.langId		= this.langId;
			params.orderId		= ".";
		// add the individual bundle items of the parent bundle to the request.
			var catEntryArray = [];
			catEntryArray = form.catEntryIDS.value.toString().split(",");
			for(var i = 0; i < catEntryArray.length; i++){
				var qty = document.getElementById("quantity_" + catEntryArray[i]).value;
				var catEntryId = catEntryArray[i];
				if(this.getDefaultItem(catEntryArray[i]))
							catEntryId = this.getDefaultItem(catEntryArray[i]);
				if(qty==0 || qty == null) qty = 1;
				if(qty!=null && qty!='' && catEntryId!=null){
					this.updateParamObject(params,"catEntryId",catEntryId,false,-1);
					this.updateParamObject(params,"quantity",qty,false,-1);
					this.baseItemAddedToCart = "true";
				}else{
					MessageHelper.displayErrorMessage(MessageHelper.messages['ERR_RESOLVING_SKU']);
					return;
				}
			}
			// add the individual bundle items of the associated bundle to the request.
			if(this.merchandisingAssociationItems[0].catEntry_Type=='BundleBean'){
					var bundleForm = document.getElementById(this.merchandisingAssociationItems[0].catEntry_BundleFormId);
					var innerCatEntryArray = [];
					innerCatEntryArray = bundleForm.catEntryIDS.value.toString().split(",");
					for(var i = 0; i < innerCatEntryArray.length; i++){
						var qty = document.getElementById("quantity_" + innerCatEntryArray[i]).value;
						var innerCatEntryId = innerCatEntryArray[i];
						if(this.getDefaultItem(innerCatEntryArray[i]))
							innerCatEntryId = this.getDefaultItem(innerCatEntryArray[i]);
						if(qty==0 || qty == null) qty = 1;
						if(qty!=null && qty!='' && innerCatEntryId!=null){
							this.updateParamObject(params,"catEntryId",innerCatEntryId,false,-1);
							this.updateParamObject(params,"quantity",qty,false,-1);
						}else{
							MessageHelper.displayErrorMessage(MessageHelper.messages['ERR_RESOLVING_SKU']);
							return;
						}
					}
				}else if(this.merchandisingAssociationItems[0].catEntry_Type=='PackageBean' || this.merchandisingAssociationItems[0].catEntry_Type=='ItemBean'){
					this.updateParamObject(params,"catEntryId",this.merchandisingAssociationItems[0].catEntry_Identifier,false,-1);
					this.updateParamObject(params,"quantity",1,false,-1);
				}
			//For Handling multiple clicks
			if(!submitRequest()){
				return;
			}   
			cursor_wait();			
			//Invoke service to add to the cart.
			wc.service.invoke("AjaxAddOrderItem", params);
	
	   if(this.merchandisingAssociationItems[0].catEntry_Type=='ProductBean'){
		   showPopup(this.merchandisingAssociationItems[0].catEntry_Identifier,this.storeId,this.langId,this.catalogId,function(e){return e;},'marchandisingAssociationDisplay');
	   }
},

	/**
	* AddAssociationBundle2ShopCart Adds the parent bundle and associated product to the shopping cart when AjaxAddToCart is disabled.
	*								This function is used on MerchandisingAssociationsDisplay.jsp. 
	* 
	* @param {form} form The form which contains the details of the catalog entries that need to be added to the cart.
	* 						The {@link fastFinderJS.merchandisingProductAssociationForm} is set to the form passed in.
	*						The form is expected to have a value for catEntryIDS which is a list of catalog entry IDs of the catalog entries in the bundle which should be
	*						added to the shopping cart.
	*
	**/
	AddAssociationBundle2ShopCart : function(form){
	
	var identifierJSON = "associatedCatEntries_"+this.associationThumbnailIndex;
	//get the item form the JSON object	
	var associationEntryJSON = eval('('+ dojo.byId(identifierJSON).innerHTML +')');
	this.merchandisingAssociationItems = associationEntryJSON;
	this.isParentBundleBean = true;
	//Add the parent bundle to the cart and show the pop-up dialog for the associated product.
	if(this.merchandisingAssociationItems[0].catEntry_Type=='ProductBean'){
		this.merchandisingProductAssociationAddToCart = true;
		this.merchandisingProductAssociationForm = form;
		var catEntryArray = [];
		// add the individual bundle items of the parent bundle to the request.
		catEntryArray = form.catEntryIDS.value.toString().split(",");
		var bundleItemsCount = 1;
		for(var i = 0; i < catEntryArray.length; i++){
			var qty = document.getElementById("quantity_" + catEntryArray[i]).value;
			var catEntryId = catEntryArray[i];
			if(this.getDefaultItem(catEntryArray[i]))
							catEntryId = this.getDefaultItem(catEntryArray[i]);
			if(catEntryId != null)
							form["catEntryId_" + catEntryArray[i]].value = catEntryId;				
			else{
					MessageHelper.displayErrorMessage(MessageHelper.messages['ERR_RESOLVING_SKU']);
					return;
			}
			bundleItemsCount = bundleItemsCount + 1;
			
		}
		showPopup(this.merchandisingAssociationItems[0].catEntry_Identifier,this.storeId,this.langId,this.catalogId,function(e){return e;},'marchandisingAssociationDisplay');
	}else if (this.merchandisingAssociationItems[0].catEntry_Type=='ItemBean' || this.merchandisingAssociationItems[0].catEntry_Type=='PackageBean' || this.merchandisingAssociationItems[0].catEntry_Type=='BundleBean'){
		var catEntryArray = [];
		// add the individual bundle items of the parent bundle to the request.
		catEntryArray = form.catEntryIDS.value.toString().split(",");
		var bundleItemsCount = 1;
		for(var i = 0; i < catEntryArray.length; i++){
			var qty = document.getElementById("quantity_" + catEntryArray[i]).value;
			var catEntryId = catEntryArray[i];
			if(this.getDefaultItem(catEntryArray[i]))
							catEntryId = this.getDefaultItem(catEntryArray[i]);
			if(catEntryId != null)
							form["catEntryId_" + catEntryArray[i]].value = catEntryId;				
			else{
					MessageHelper.displayErrorMessage(MessageHelper.messages['ERR_RESOLVING_SKU']);
					return;
			}
			bundleItemsCount = bundleItemsCount + 1;
			
		}
		if(this.merchandisingAssociationItems[0].catEntry_Type=='BundleBean'){
			// add the individual bundle items of the associated bundle to the request.
			var bundleForm = document.getElementById(this.merchandisingAssociationItems[0].catEntry_BundleFormId);
			var innerCatEntryArray = [];
			innerCatEntryArray = bundleForm.catEntryIDS.value.toString().split(",");
			for(var i = 0; i < innerCatEntryArray.length; i++){
				var qty = document.getElementById("quantity_" + innerCatEntryArray[i]).value;
				var innerCatEntryId = innerCatEntryArray[i];
				if(this.getDefaultItem(innerCatEntryArray[i])){
							innerCatEntryId = this.getDefaultItem(innerCatEntryArray[i]);
							}
				if(qty==0 || qty == null) qty = 1;
				if(qty!=null && qty!='' && innerCatEntryId!=null){
					var input2 = document.createElement("input");
					input2.setAttribute("id", "OrderItemAddForm_catEntryId_"+innerCatEntryId);
					input2.setAttribute("type", "hidden");
					input2.setAttribute("name", "catEntryId_"+bundleItemsCount);
					input2.setAttribute("value", innerCatEntryId);
					form.appendChild(input2);
					var quantity2 = document.createElement("input");
					quantity2.setAttribute("id", "OrderItemAddForm_quantity_"+innerCatEntryId);
					quantity2.setAttribute("type", "hidden");
					quantity2.setAttribute("name", "quantity_"+bundleItemsCount);
					quantity2.setAttribute("value", "1");
					form.appendChild(quantity2);
					bundleItemsCount = bundleItemsCount + 1;
				}else{
					MessageHelper.displayErrorMessage(MessageHelper.messages['ERR_RESOLVING_SKU']);
					return;
				}
			}
		}else{
			var input2 = document.createElement("input");
			input2.setAttribute("id", "OrderItemAddForm_catEntryId_"+this.merchandisingAssociationItems[0].catEntry_Identifier);
			input2.setAttribute("type", "hidden");
			input2.setAttribute("name", "catEntryId_"+bundleItemsCount);
			input2.setAttribute("value", this.merchandisingAssociationItems[0].catEntry_Identifier);
			form.appendChild(input2);
			var quantity2 = document.createElement("input");
			quantity2.setAttribute("id", "OrderItemAddForm_quantity_"+this.merchandisingAssociationItems[0].catEntry_Identifier);
			quantity2.setAttribute("type", "hidden");
			quantity2.setAttribute("name", "quantity_"+bundleItemsCount);
			quantity2.setAttribute("value", "1");
			form.appendChild(quantity2);
		}
		form.URL.value = "AjaxOrderItemDisplayView";
		
		//For Handling multiple clicks
		if(!submitRequest()){
			return;
		}
		
		//submit the form to add to cart.
		form.submit();
	}
	
}	
}

categoryDisplayJS.HistoryTracker.prototype.back = categoryDisplayJS.goBack;
categoryDisplayJS.HistoryTracker.prototype.forward=categoryDisplayJS.goForward;
		
		
	
