//-----------------------------------------------------------------
// Licensed Materials - Property of IBM
//
// WebSphere Commerce
//
// (C) Copyright IBM Corp. 2008, 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 is to be included in all full pages that use the CatalogEntryThumbnailDisplay.jspf.
 * It prepares all the code required for the Product Quick Info pop-up reveal.
 */

	//Make the Product Quick Info pop-up window movable.
	dojo.require("dojo.dnd.move");
	//dojo.require("dijit.Dialog");
	
	/** The variable stores the Product Quick Info pop-up window. */
	var m1;

	var prodIDs = new Array();	
	
	/** The variable stores the identifier of the order item to be replaced */
	var replaceOrderItemId;

	var reviewsId = 0;
	
	/** 
	 * Initializes the Product Quick Info pop-up window to a movable dialog.
	 */	
	var initPopup = function(){
		//m1 = new dojo.dnd.Moveable("second_level_category_popup", {handle: "popupHeader"});
	};
	
	dojo.addOnLoad(initPopup);

	/** 
	 * Displays the Product Quick Info button.
	 * 
	 * @param {string} id The id of the div area to show.
	 */
	function showPopupButton(id){
		if(document.getElementById("popupButton_"+id)!=null && document.getElementById("popupButton_"+id)!='undefined'){
			var popupButton = document.getElementById("popupButton_"+id);
			popupButton.style.visibility="visible";
		}
	}

	/** 
	 * Hides the Product Quick Info button.
	 * 
	 * @param {string} id The id of the div area to hide. 
	 */	
	function hidePopupButton(id){
		if(document.getElementById("popupButton_"+id)!=null && document.getElementById("popupButton_"+id)!='undefined') {
			var popupButton = document.getElementById("popupButton_"+id);
			popupButton.style.visibility="hidden";
		}
	}

	/** 
	 * Displays the Product Quick Info pop-up containing product information.
	 * Retrieves product information in JSON format via an Ajax call.
	 * 
	 * @param {string} productId The id of the product to display.
	 * @param {string} storeId The id of the current store.
	 * @param {string} langId The id of the language used in the store.
	 * @param {string} catalogId The id of the current store catalog.
	 * @param {string} event The event triggered from user actions.
	 * @param {string} targetId The id of the dojo element to display the pop-up next to.
	 * @param {string} nodeId The id of element to display the pop-up around on <Enter> key click.
	 * @param {object} productActionList The object containing Product Quick Info pop-up action list settings.
	 * @param {string} popUpQty The quantity to be displayed for this product.
	 */		
	function showPopup(productId,storeId,langId, catalogId, event,targetId,nodeId,productActionList,popUpQty, sizeType){
		
		if(event == null || (event != null && event.type!="keypress") || (event != null && event.type=="keypress" && event.keyCode==13)){
			resetPopUp();
			
			//Default action list is used if it is not passed into this method
			if(productActionList == null){
				productActionList = new popupActionProperties();
			}
			
			//From the productActionList object properties
			//hide/show the action links from the Quick Info 		
			if(productActionList.showAddToCart){
				if(document.getElementById('addToCartAjaxButton')){
					document.getElementById('addToCartAjaxButton').style.visibility='visible';
				} else if(document.getElementById('addToCartButton')){
					document.getElementById('addToCartButton').style.visibility='visible';
				}			
			} else {
				if(document.getElementById('addToCartAjaxButton')){
					document.getElementById('addToCartAjaxButton').style.visibility='hidden';
				} else if(document.getElementById('addToCartButton')){
					document.getElementById('addToCartButton').style.visibility='hidden';
				}			
			}
	
			if(productActionList.showWishList){
				if(document.getElementById('addToWishListLinkAjax')){
					document.getElementById('addToWishListLinkAjax').style.display='block';
				} else if(document.getElementById('addToWishListLink')){
					document.getElementById('addToWishListLink').style.display='block';
				}
			} else {
				if(document.getElementById('addToWishListLinkAjax')){
					document.getElementById('addToWishListLinkAjax').style.display='none';
				} else if(document.getElementById('addToWishListLink')){
					document.getElementById('addToWishListLink').style.display='none';
				}
			}		
						
			if(productActionList.showReplaceCartItem){
				if(document.getElementById('replaceCartItemAjax')){
					document.getElementById('replaceCartItemAjax').style.display = 'block';
				} else if(document.getElementById('replaceCartItemNonAjax')){
					document.getElementById('replaceCartItemNonAjax').style.display = 'block';
				}		
			} else {
				if(document.getElementById('replaceCartItemAjax')){
					document.getElementById('replaceCartItemAjax').style.display = 'none';
				} else if(document.getElementById('replaceCartItemNonAjax')){
					document.getElementById('replaceCartItemNonAjax').style.display = 'none';
				}		
			}
					
			dijit.byId('pdpOverlayBox').closeButtonNode.style.display='none';
			dijit.byId('pdpOverlayBox').show();
			
			// hides the DialogUnderlayWrapper component, the component that grays out the screen behind,
			// as we do not want the background to be greyed out
			dojo.query('.dijitDialogUnderlayWrapper', document).forEach(function(tag) {		
				tag.style.display='none';
			});		
			
			var parameters = {};
			parameters.storeId = storeId;
			parameters.langId=langId;
			parameters.catalogId=catalogId;
			parameters.productId=productId;	
			parameters.sizeType = sizeType;

			dojo.xhrPost({
					url: getAbsoluteURL() + "GetCatalogEntryDetailsByID",				
					handleAs: "json-comment-filtered",
					content: parameters,
					service: this,
					load: populatePopUp,
					error: function(errObj,ioArgs) {
						console.debug("CatalogEntryThumbnailDisplay.showPopup: Unexpected error occurred during an xhrPost request.");
					}
				});
		}
	}

	/** 
	 * Populates all the contents of the Product Quick Info pop-up with the JSON returned from the server.
	 * 
	 * @param {object} serviceRepsonse The JSON response from the service.
	 * @param {object} ioArgs The arguments from the service call.
	 */		
	function populatePopUp(serviceResponse, ioArgs) {
		var PDPOverlayHTML = ""; 	
		var x = 0;
		var promoMsg;
		var specialSizesChk = false;
		var hasSizes = false;
		var currentPromoMsg = "";
		var currentProdTab = 0;
		var displayTab = false;

		PDPOverlayHTML = PDPOverlayHTML + 
			'<div class="simplemodal-close closeBox">' + 
				'<a href=# onclick="hideItem(\'pdpOverlayBox\');" id="closeLink">' + 
					'<div class="closeText">Close</div>' + 
					'<img src="/wcsstore/KGStorefrontAssetStore/images/icon_close.gif" width="17" height="17" alt="" class="closeIcon">' + 
				'</a>' + 
			'</div>' + 
			'<div id="pdpOverlayHeader">' + 
				'<h2 id="productName"></h2> <a href="#" onclick="javascript:hideItem(\'pdpOverlayBox\');" class="view-details" id="readMore">View Details</a>' +
				'<h1 style="display:none;" id="productSKUValue"></h1>' + 
			'</div>' + 
			'<div id="PopupMessageArea" style="display:none">' + 
				'<br />' + 
				'<span id="PopupErrorMessageText" class="error_msg" tabindex="-1">' + 
				'</span>' + 
				'<br />  ' + 
			'</div>';


			PDPOverlayHTML = PDPOverlayHTML +
			'<div id="description">' +
			'<div id="thumbnails">' + 
				'<div class="thumbHolder"><img width="60" height="60" class="prodImg" alt=""'   + 
					'src="/wcsstore/KGStorefrontAssetStore/images/scene7/noImage.jpeg"/>' + 
				'</div>' + 
			'</div>' + 
			'<div id="medImgHolder">' + 
				'<img src="/wcsstore/KGStorefrontAssetStore/images/scene7/noImage.jpeg" width="365" height="490" class="prodImg" id="productFullImage">' + 
			'</div>'; 
			for (var i=0; i<serviceResponse.KGProdCnt; i++) {
				prodIDs[x++] = serviceResponse.KGProdIDs[i].catalogEntry.catalogEntryIdentifier.uniqueID;			
				PDPOverlayHTML = PDPOverlayHTML + '<div id="entitledItem_' + serviceResponse.KGProdIDs[i].catalogEntry.catalogEntryIdentifier.uniqueID + '" style="display:none" >'; 			
				PDPOverlayHTML = PDPOverlayHTML + '[';
				for (var entItems in serviceResponse.KGProdIDs[i].entitledItems) {
					var attrHTML = "";
					PDPOverlayHTML = PDPOverlayHTML +
					' { "catentry_id" : "' +  serviceResponse.KGProdIDs[i].entitledItems[entItems].catentry_id + '", "Attributes" : {';
					
					for (var entAttrs in serviceResponse.KGProdIDs[i].entitledItems[entItems].Attributes) {
						attrHTML = attrHTML + '"' + entAttrs + '":"' + serviceResponse.KGProdIDs[i].entitledItems[entItems].Attributes[entAttrs] + '",'; 
					}	
					attrHTML = attrHTML.substring(0,attrHTML.length-1);
					PDPOverlayHTML = PDPOverlayHTML + attrHTML +  '}},';
				}
				PDPOverlayHTML = PDPOverlayHTML.substring(0,PDPOverlayHTML.length-1);
				PDPOverlayHTML = PDPOverlayHTML + ' ]';
				PDPOverlayHTML = PDPOverlayHTML + '</div>';
				
				specialSizesChk = false;
				if (serviceResponse.KGProdIDs[i].sizeType != 'default' || serviceResponse.KGProdIDs[i].sizeType != '' 
					|| serviceResponse.KGProdIDs[i].sizeType != 'noSpecialSizes' || serviceResponse.KGProdIDs[i].sizeType != null) {
					specialSizesChk = true;	
				}
				hasSizes = false;
				if (serviceResponse.KGProdIDs[i].prodBuyableSizes != null && serviceResponse.KGProdIDs[i].prodBuyableSizes != ""
					&& serviceResponse.KGProdIDs[i].prodBuyableSizes != "[]" && serviceResponse.KGProdIDs[i].prodBuyableSizes != "[ ]") {
					hasSizes = true;
				}

				PDPOverlayHTML = PDPOverlayHTML +
				'<div class="detail" id="detail_' + serviceResponse.KGProdIDs[i].catalogEntry.catalogEntryIdentifier.uniqueID + '">' + 
					'<div id="selection" class="selection ui-tabs ui-widget ui-widget-content ui-corner-all">'; 
						if (serviceResponse.KGProdIDs[i].productDataBeanURL !=0 && serviceResponse.KGProdIDs[i].productDataBeanURL !="-1" && serviceResponse.KGProdIDs[i].productDataBeanURL != null) {
							PDPOverlayHTML = PDPOverlayHTML + '<ul class="ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all">';  
								for (var tab=0; tab<serviceResponse.KGProdIDs[i].tabCount[0]; tab++) {
									displayTab = false;
									if (hasSizes == false) {
										displayTab = true;
									}
									if (hasSizes == true) {
										for (var buyableSizes in serviceResponse.KGProdIDs[i].prodBuyableSizes) {
											if (serviceResponse.KGProdIDs[i].tabs[0].sizeAttrLabelCheck[tab] == serviceResponse.KGProdIDs[i].prodBuyableSizes[buyableSizes].field3) {
												displayTab = true;
											}										
										}										
									}
									if (displayTab == true) {
										if ((specialSizesChk == false && tab ==0) || (specialSizesChk == true 
											&& serviceResponse.KGProdIDs[i].tabs[0].sizeAttrLabelCheck[tab] == serviceResponse.KGProdIDs[i].sizeType)) {
											if (serviceResponse.KGProdIDs[i].catalogEntry.catalogEntryIdentifier.uniqueID == serviceResponse.KGReqProdID) {
												currentProdTab = tab;
											}
											PDPOverlayHTML = PDPOverlayHTML + '<li class="ui-state-default ui-corner-top ui-tabs-selected ui-state-active">';
										} 
										else {PDPOverlayHTML = PDPOverlayHTML + '<li class="ui-state-default ui-corner-top">';}
										PDPOverlayHTML = PDPOverlayHTML + '<a href="#selTab' + tab + '_' + serviceResponse.KGProdIDs[i].catalogEntry.catalogEntryIdentifier.uniqueID + '">';  
										if (serviceResponse.KGProdIDs[i].tabs[0].labels[tab] == 'NA'){PDPOverlayHTML = PDPOverlayHTML + '&nbsp;';}
										else {PDPOverlayHTML = PDPOverlayHTML + serviceResponse.KGProdIDs[i].tabs[0].labels[tab] + '</a></li>';}									
									}				
								}
							PDPOverlayHTML = PDPOverlayHTML + '</ul>' + '<div class="selPanelT"><!-- --></div>';
						} else {
							PDPOverlayHTML = PDPOverlayHTML + '<div class="selPanelTNoTabs"><!-- --></div>' + '<div class="selPanel"><!-- --></div>';
						}
						for (var tab=0; tab<serviceResponse.KGProdIDs[i].tabCount[0]; tab++) {
						
							displayTab = false;
							if (hasSizes == false) {
								displayTab = true;
							}
							if (hasSizes == true) {
								if (serviceResponse.KGProdIDs[i].productDataBeanURL !=0 && serviceResponse.KGProdIDs[i].productDataBeanURL !="-1" && serviceResponse.KGProdIDs[i].productDataBeanURL != null) {
									for (var buyableSizes in serviceResponse.KGProdIDs[i].prodBuyableSizes) {
										if (serviceResponse.KGProdIDs[i].tabs[0].sizeAttrLabelCheck[tab] == serviceResponse.KGProdIDs[i].prodBuyableSizes[buyableSizes].field3) {
											displayTab = true;
										}										
									}										
								} else {displayTab = true;}
							}						
							if (displayTab == true) {
								PDPOverlayHTML = PDPOverlayHTML +
								'<div id="selTab' + tab + '_' + serviceResponse.KGProdIDs[i].catalogEntry.catalogEntryIdentifier.uniqueID;
								if(tab==0){
									PDPOverlayHTML = PDPOverlayHTML + '" class="ui-tabs-panel ui-widget-content ui-corner-bottom">';
								} else {
									PDPOverlayHTML = PDPOverlayHTML + '" class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide">';
								}		
								if (serviceResponse.KGProdIDs[i].promoMsg[tab].messageData !="") { 
									promoMsg="true";
									if (serviceResponse.KGProdIDs[i].catalogEntry.catalogEntryIdentifier.uniqueID == serviceResponse.KGReqProdID && currentProdTab == tab) {
										currentPromoMsg="true";
									} else { currentPromoMsg="";}	
								} else { promoMsg="";}													
								PDPOverlayHTML = PDPOverlayHTML +
									'<div class="selTabContent">' +
										'<div id="productAttributes">';
											var colorAttributeHTML = "";
											for (var KGProd=0; KGProd<serviceResponse.KGProdCnt; KGProd++) {
												for (var attr in serviceResponse.KGProdIDs[KGProd].catalogEntryAttributes.attributes) {
													if (serviceResponse.KGProdIDs[KGProd].catalogEntryAttributes.attributes[attr].usage == "Defining") {
														if (serviceResponse.KGProdIDs[KGProd].catalogEntryAttributes.attributes[attr].name == "Color") {
															if(serviceResponse.KGProdIDs[KGProd].catalogEntryAttributes.attributes[attr].allowedValue != "[]") {
																for (var k in serviceResponse.KGProdIDs[KGProd].catalogEntryAttributes.attributes[attr].allowedValue) {
																	colorAttributeHTML = colorAttributeHTML + 
																		'<a href="JavaScript:categoryDisplayJS.setSelectedAttribute(\'' + (serviceResponse.KGProdIDs[KGProd].catalogEntryAttributes.attributes[attr].name).replace("'","\\'") + '\',\'' + (serviceResponse.KGProdIDs[KGProd].catalogEntryAttributes.attributes[attr].allowedValue[k].value).replace("'","\\'") + '\');' + 
																		'JavaScript:setDIVOnColorSwatch(\'' + serviceResponse.KGProdIDs[KGProd].catalogEntry.catalogEntryIdentifier.uniqueID + '\',\'' + serviceResponse.KGProdIDs[KGProd].catalogEntry.description[0].shortDescription + '\',\'' + serviceResponse.KGProdIDs[KGProd].catalogEntryURL + '\',\'' + serviceResponse.KGProdIDs[KGProd].productImageSet + '\',\'' + serviceResponse.KGProdIDs[KGProd].productTag1 + '\',\'' + serviceResponse.KGProdIDs[KGProd].productTag2 + '\');' + 
																		'">';
																	if (serviceResponse.KGProdIDs[KGProd].catalogEntry.catalogEntryIdentifier.uniqueID == serviceResponse.KGProdIDs[i].catalogEntry.catalogEntryIdentifier.uniqueID) {
																		colorAttributeHTML = colorAttributeHTML + '<img width="18" height="18" src="https://a248.e.akamai.net/f/248/9086/10h/origin-d4.scene7.com/is/image/KG/' + serviceResponse.KGProdIDs[KGProd].currentProdSwatch + '?layer=1&src=SWATCHBORDER" /></a>';
																	}
																	if (serviceResponse.KGProdIDs[KGProd].catalogEntry.catalogEntryIdentifier.uniqueID != serviceResponse.KGProdIDs[i].catalogEntry.catalogEntryIdentifier.uniqueID) {
																		colorAttributeHTML = colorAttributeHTML + '<img width="18" height="18" src="https://a248.e.akamai.net/f/248/9086/10h/origin-d4.scene7.com/is/image/KG/' + serviceResponse.KGProdIDs[KGProd].currentProdSwatch + '" /></a>';
																	}
																}
															}
														}
													}
												}
											}
											if (colorAttributeHTML != "")
											{
												PDPOverlayHTML = PDPOverlayHTML + '<div class="selColor labelValueSetTop"><div class="selLabel">Color</div><div class="selColors">';
												PDPOverlayHTML = PDPOverlayHTML + colorAttributeHTML;
												PDPOverlayHTML = PDPOverlayHTML + '</div></div>';
											}
											if (hasSizes == true) {
												PDPOverlayHTML = PDPOverlayHTML + '<div class="selSize labelValueSetTop">';
												PDPOverlayHTML = PDPOverlayHTML + '<div class="selLabel">Size</div>';
												PDPOverlayHTML = PDPOverlayHTML + '<select name="attrValue" class="drop_down" id="attrValue_2' + '" onChange="JavaScript:categoryDisplayJS.setSelectedAttribute(\'Size' + '\',this.options[this.selectedIndex].value);' + 
												'JavaScript:categoryDisplayJS.ajaxKGCheckInventory(\'entitledItem_' + serviceResponse.KGProdIDs[i].catalogEntry.catalogEntryIdentifier.uniqueID + '\',\'' + serviceResponse.KGCheckInventoryURL + '\',\'addToCartLinkAjax_' + serviceResponse.KGProdIDs[i].catalogEntry.catalogEntryIdentifier.uniqueID + '_' + tab + '\',\'' + tab + '\',\'productPopUpQty_' + serviceResponse.KGProdIDs[i].catalogEntry.catalogEntryIdentifier.uniqueID + '_' + tab + '\',\'' + serviceResponse.KGProdIDs[i].catalogEntry.catalogEntryIdentifier.uniqueID + '\',\'' + serviceResponse.findAStoreURL + '\',\'' + promoMsg + '\');' + 
												'">';
												PDPOverlayHTML = PDPOverlayHTML + '<option value="">Select Size</option>';
												if (serviceResponse.KGProdIDs[i].productDataBeanURL !=0 && serviceResponse.KGProdIDs[i].productDataBeanURL !="-1" && serviceResponse.KGProdIDs[i].productDataBeanURL != null) {			
													for (var buyableSizes in serviceResponse.KGProdIDs[i].prodBuyableSizes) {
														if (serviceResponse.KGProdIDs[i].prodBuyableSizes[buyableSizes].field3 == serviceResponse.KGProdIDs[i].tabs[0].sizeAttrLabelCheck[tab]) {
															PDPOverlayHTML = PDPOverlayHTML + '<option value="' + serviceResponse.KGProdIDs[i].prodBuyableSizes[buyableSizes].size +'">' + serviceResponse.KGProdIDs[i].prodBuyableSizes[buyableSizes].size + '</option>';	
														}										
													}	
												} else {
													for (var buyableSizes in serviceResponse.KGProdIDs[i].prodBuyableSizes) {
															PDPOverlayHTML = PDPOverlayHTML + '<option value="' + serviceResponse.KGProdIDs[i].prodBuyableSizes[buyableSizes].size +'">' + serviceResponse.KGProdIDs[i].prodBuyableSizes[buyableSizes].size + '</option>';
													}																	
												}
												PDPOverlayHTML = PDPOverlayHTML + '</select></div>';
											}
										PDPOverlayHTML = PDPOverlayHTML + '</div>' + 
										'<div id="productQuantity" class="selQuant labelValueSetTop">' + 
											'<div class="selLabel">' + 
												'<label for="productPopUpQty">' + 'Quantity</label>' + 
											'</div>' + 
											'<select name="quantity_' + serviceResponse.KGProdIDs[i].catalogEntry.catalogEntryIdentifier.uniqueID + '_' + tab + '" id="productPopUpQty_' + serviceResponse.KGProdIDs[i].catalogEntry.catalogEntryIdentifier.uniqueID + '_' + tab + '" class="drop_down" onChange="' + 
											'JavaScript:categoryDisplayJS.ajaxKGCheckInventory(\'entitledItem_' + serviceResponse.KGProdIDs[i].catalogEntry.catalogEntryIdentifier.uniqueID + '\',\'' + serviceResponse.KGCheckInventoryURL + '\',\'addToCartLinkAjax_' + serviceResponse.KGProdIDs[i].catalogEntry.catalogEntryIdentifier.uniqueID + '_' + tab + '\',\'' + tab +  '\',\'productPopUpQty_' + serviceResponse.KGProdIDs[i].catalogEntry.catalogEntryIdentifier.uniqueID + '_' + tab + '\',\'' + serviceResponse.KGProdIDs[i].catalogEntry.catalogEntryIdentifier.uniqueID + '\',\'' + serviceResponse.findAStoreURL + '\',\'' + promoMsg + '\');' + 
											'">' + 
												'<option value="1">1</option>' + '<option value="2">2</option>' + '<option value="3">3</option>' + '<option value="4">4</option>' + '<option value="5">5</option>' + '<option value="6">6</option>' +
												'<option value="7">7</option>' + '<option value="8">8</option>' + '<option value="9">9</option>' + '<option value="10">10</option>' +
											'</select>' + 
										'</div>' +
										'<div class="divider"><!-- --></div>' + 
										'<div id="productPrice">';
											if (serviceResponse.KGProdIDs[i].priceDetails[tab].manufacturerPrice !="0.00"){
												PDPOverlayHTML =  PDPOverlayHTML + '<div class="mfrPrice labelValueSet"><div class="priceLabel">Compare at</div><div class="price">';  
												PDPOverlayHTML =  PDPOverlayHTML + serviceResponse.KGProdIDs[i].priceDetails[tab].manufacturerPrice + '</div></div>';
											} 
											if (serviceResponse.KGProdIDs[i].priceDetails[tab].listPrice !="0.00"){
												PDPOverlayHTML =  PDPOverlayHTML + '<div class="kgPrice labelValueSet"><div class="priceLabel">K &amp; G price</div><div class="price">' + serviceResponse.KGProdIDs[i].priceDetails[tab].listPrice + '</div></div>';											
											}
											PDPOverlayHTML =  PDPOverlayHTML + '<div class="todayPrice labelValueSet">';
											if (serviceResponse.KGProdIDs[i].priceDetails[tab].listPrice !="0.00"){
												PDPOverlayHTML =  PDPOverlayHTML +	'<div class="priceLabel">Today\'s price</div>';
											} else {
												PDPOverlayHTML =  PDPOverlayHTML +	'<div class="priceLabel">K &amp; G price</div>';
											}
											if (serviceResponse.KGProdIDs[i].priceDetails[tab].todayPrice !="0.00"){
												PDPOverlayHTML =  PDPOverlayHTML + '<div class="price">' + serviceResponse.KGProdIDs[i].priceDetails[tab].todayPrice + '</div>'; 
											} else {
												PDPOverlayHTML =  PDPOverlayHTML + '<div class="price">$' + serviceResponse.KGProdIDs[i].priceDetails[tab].todayPrice + '</div>'; 
											}										
											PDPOverlayHTML =  PDPOverlayHTML + '</div>';
											if (serviceResponse.KGProdIDs[i].priceDetails[tab].hasSavings == 'true'){
												PDPOverlayHTML =  PDPOverlayHTML + '<div class="selYouSave labelValueSet"><div>You Save '+ serviceResponse.KGProdIDs[i].priceDetails[tab].youSave + '</div></div>';										
											}
										PDPOverlayHTML =  PDPOverlayHTML + '</div>' + 
										'<div>';
										if (serviceResponse.KGProdIDs[i].promoMsg[tab].messageData !="") {
											PDPOverlayHTML =  PDPOverlayHTML + '<div class="save-long clearfix" id="promoMsg_' + serviceResponse.KGProdIDs[i].catalogEntry.catalogEntryIdentifier.uniqueID + '_' + tab + '">' + 
																'<p style="color: #CC0000;font-size: 11px;font-weight: bold;">' + serviceResponse.KGProdIDs[i].promoMsg[tab].messageData + 
																'</p></div>';									
										} else {
											PDPOverlayHTML =  PDPOverlayHTML + '<div class="save-long clearfix" style="display:none;" id="promoMsg_' + serviceResponse.KGProdIDs[i].catalogEntry.catalogEntryIdentifier.uniqueID + '_' + tab + '" >' + 
																'<p style="color: #CC0000;font-size: 11px;font-weight: bold;">' + serviceResponse.KGProdIDs[i].promoMsg[tab].messageData + 
																'</p></div>';									
										}
										PDPOverlayHTML =  PDPOverlayHTML + '<div style="display:none" class="save-long clearfix" id="invMsg_' + serviceResponse.KGProdIDs[i].catalogEntry.catalogEntryIdentifier.uniqueID + '_' + tab + '">' + 
																'<p style="color: #CC0000;font-size: 11px;font-weight: bold;">' +  
																'</p></div>';	
										PDPOverlayHTML =  PDPOverlayHTML + '<div style="display:none" class="save-longExt clearfix" id="promoMsgExt_' + serviceResponse.KGProdIDs[i].catalogEntry.catalogEntryIdentifier.uniqueID + '_' + tab + '">' + 
																'<p style="color: #CC0000;font-size: 11px;font-weight: bold;">' +  
																'</p></div>';										
										PDPOverlayHTML =  PDPOverlayHTML + '<div style="display:none" class="save-longExt1 clearfix" id="promoMsgExt1_' + serviceResponse.KGProdIDs[i].catalogEntry.catalogEntryIdentifier.uniqueID + '_' + tab + '">' + 
																'<p style="color: #CC0000;font-size: 11px;font-weight: bold;">' +  
																'</p></div>';	
										PDPOverlayHTML =  PDPOverlayHTML +
											'<form name="OrderItemAddForm_' + serviceResponse.KGProdIDs[i].catalogEntry.catalogEntryIdentifier.uniqueID + '_' + tab + '" action="' + serviceResponse.KGWishListURL + '" method="post" id="OrderItemAddForm_' + serviceResponse.KGProdIDs[i].catalogEntry.catalogEntryIdentifier.uniqueID + '_' + tab + '">' +
												'<input type="hidden" name="storeId" value="' + serviceResponse.storeId + '" id="OrderItemAddForm_storeId_' + serviceResponse.KGProdIDs[i].catalogEntry.catalogEntryIdentifier.uniqueID + '_' + tab + '"/>' +  
												'<input type="hidden" name="langId" value="' + serviceResponse.langId + '" id="OrderItemAddForm_langId_' + serviceResponse.KGProdIDs[i].catalogEntry.catalogEntryIdentifier.uniqueID + '_' + tab + '"/>' +
												'<input type="hidden" name="catalogId" value="' + serviceResponse.catalogId  + '" id="OrderItemAddForm_catalogId_' + serviceResponse.KGProdIDs[i].catalogEntry.catalogEntryIdentifier.uniqueID + '_' + tab + '"/>' +
												'<input type="hidden" name="URL" value="AjaxOrderItemDisplayView" id="OrderItemAddForm_url_' + serviceResponse.KGProdIDs[i].catalogEntry.catalogEntryIdentifier.uniqueID + '_' + tab + '"/>' +
												'<input type="hidden" name="errorViewName" value="InvalidInputErrorView" id="OrderItemAddForm_errorViewName_' + serviceResponse.KGProdIDs[i].catalogEntry.catalogEntryIdentifier.uniqueID + '_' + tab + '"/>' +
												'<input type="hidden" name="catEntryId" value="' + serviceResponse.KGProdIDs[i].catalogEntry.catalogEntryIdentifier.uniqueID + '" id="OrderItemAddForm_catEntryId_' + serviceResponse.KGProdIDs[i].catalogEntry.catalogEntryIdentifier.uniqueID + '_' + tab + '"/>' + 
												'<input type="hidden" name="productId" value="' + serviceResponse.KGProdIDs[i].catalogEntry.catalogEntryIdentifier.uniqueID + '" id="OrderItemAddForm_productId_' + serviceResponse.KGProdIDs[i].catalogEntry.catalogEntryIdentifier.uniqueID + '_' + tab + '"/>' + 
												'<input type="hidden" name="quantity" value="" id="OrderItemAddForm_quantity_' + serviceResponse.KGProdIDs[i].catalogEntry.catalogEntryIdentifier.uniqueID + '_' + tab + '"/>' + 
												'<input type="hidden" name="page" value="" id="OrderItemAddForm_page_' + serviceResponse.KGProdIDs[i].catalogEntry.catalogEntryIdentifier.uniqueID + '_' + tab + '"/>' + 
											'</form>' +
											'<a id="addToCartLinkAjax_' + serviceResponse.KGProdIDs[i].catalogEntry.catalogEntryIdentifier.uniqueID + '_' + tab + '" class="addToCartBtn" href="JavaScript:MessageHelper.hideAndClearMessageOnPopup();categoryDisplayJS.Add2ShopCartAjaxQV(\'entitledItem_' + serviceResponse.KGProdIDs[i].catalogEntry.catalogEntryIdentifier.uniqueID + '\',document.getElementById(\'productPopUpQty_' + serviceResponse.KGProdIDs[i].catalogEntry.catalogEntryIdentifier.uniqueID + '_' + tab + '\').value); hidePopup(\'pdpOverlayBox\');" >' + 
											'Add to Cart</a>' + 
											'<div class="divider"></div>' + 
											'<div class="wishStoreBtns" id="WC_CachedProductOnlyDisplay_div_12_' + serviceResponse.KGProdIDs[i].catalogEntry.catalogEntryIdentifier.uniqueID + '_' + tab + '">' + 
												'<ul id="productActions">' + 
													'<li>' + 
														'<flow:ifEnabled  feature="wishList">' + 
															'<a id="WC_CachedProductOnlyDisplay_links_4" class="btnArrowGreyR wishBtn" href="#" onclick="javascript: categoryDisplayJS.Add2WishList(\'entitledItem_' + serviceResponse.KGProdIDs[i].catalogEntry.catalogEntryIdentifier.uniqueID +'\',document.getElementById(\'OrderItemAddForm_' + serviceResponse.KGProdIDs[i].catalogEntry.catalogEntryIdentifier.uniqueID + '_' + tab + '\'),\'QV\');hidePopup(\'pdpOverlayBox\');">Add to Wish List</a>' +
														'</flow:ifEnabled>' + 
														'<a id="tab2StoreBtn" class="btnArrowGreyR storeBtn" href="' + serviceResponse.findAStoreURL + '" onclick="javascript:hideItem(\'pdpOverlayBox\');">Find a Store</a>' + 
													'</li>' + 
												'</ul>' + 
											'</div>' + 
	
											'<div style="display:none" class="wishStoreBtns" id="WishlistButtons_' + serviceResponse.KGProdIDs[i].catalogEntry.catalogEntryIdentifier.uniqueID + '_' + tab + '">' + 
												'<ul id="productActions">' + 
													'<li>' + 
														'<flow:ifEnabled  feature="wishList">' + 
															'<a id="WC_CachedProductOnlyDisplay_links_4" class="btnArrowGreyR wishBtn" href="#" onclick="javascript: categoryDisplayJS.Add2WishList(\'entitledItem_' + serviceResponse.KGProdIDs[i].catalogEntry.catalogEntryIdentifier.uniqueID +'\',document.getElementById(\'OrderItemAddForm_' + serviceResponse.KGProdIDs[i].catalogEntry.catalogEntryIdentifier.uniqueID + '_' + tab + '\'),\'QV\');hidePopup(\'pdpOverlayBox\');">Add to Wish List</a>' +
														'</flow:ifEnabled>' + 
														'<a id="tab2StoreBtn" class="btnArrowGreyR storeBtn" href="' + serviceResponse.findAStoreURL + '" onclick="javascript:hideItem(\'pdpOverlayBox\');">Find a Store</a>' + 
													'</li>' + 
												'</ul>' + 
											'</div>' + 
	
										'</div>' + 
									'</div>' + 
								'</div>';							
								}
							}
						PDPOverlayHTML = PDPOverlayHTML + '<br />' + 
							'<div id="custFeedback_' + serviceResponse.KGProdIDs[i].catalogEntry.catalogEntryIdentifier.uniqueID + '" class="clearfix">'  + 
							'</div>'; 						
						PDPOverlayHTML = PDPOverlayHTML +
					//	'</div>' + 
						'<div class="copy" id="copy' + serviceResponse.KGProdIDs[i].catalogEntry.catalogEntryIdentifier.uniqueID + '">' + 
							'<p id="productLongDescription">' + serviceResponse.KGProdIDs[i].catalogEntry.description[0].shortDescription + '</p><br />' + 
							'<p>' + serviceResponse.KGProdIDs[i].catalogEntry.description[0].longDescription + '</p>' + 
						'</div>' + 
					'</div>' + //end selection
				'</div>' + //end detail
				'<span style="display:none" id="requiredFieldText"><fmt:message key="Checkout_ACCE_required" bundle="${storeText}"/></span>' + 
				'<span style="display:none" id="selectText"><fmt:message key="QuickInfo_Select" bundle="${storeText}"/></span>' + 
				'<span tabindex="0" id="focusConveyer" onfocus="javaScript:gobackFocus();"></span>';
			}
		PDPOverlayHTML = PDPOverlayHTML + '</div>';
		document.getElementById('contentOverlayBox').innerHTML = PDPOverlayHTML;
		setDIVOnPageLoad(serviceResponse,serviceResponse.KGReqProdID, currentProdTab, currentPromoMsg);
		gobackFocus();//set the default focus to the Close button		
	}
	
	/** 
	 * Reset all contents of the Product Quick Info pop-up.
	 * This dialog will be re-used across all products on the page.
	 */			
	function resetPopUp() {
		document.getElementById('contentOverlayBox').innerHTML = 			
		'<div class="simplemodal-close closeBox">' + 
				'<a href=# onclick="hideItem(\'pdpOverlayBox\');" id="closeLink">' + 
					'<div class="closeText">Close</div>' + 
					'<img src="/wcsstore/KGStorefrontAssetStore/images/icon_close.gif" width="17" height="17" alt="" class="closeIcon">' + 
				'</a>' + 
		'</div>' + 
		'<div id="description"  class="descriptionOverlayBox">' + 
			'<div id="detail"">' + 
            '	<div id="selection" class="ui-tabs ui-widget ui-widget-content ui-corner-all">' + 
					'<img height="44" width="44" src="/wcsstore/KGStorefrontAssetStore/images/colors/color1/loading.gif">' + 
               '</div>' + 
            '</div>' + 
		'</div>';
		categoryDisplayJS.selectedAttributes = new Object();
		categoryDisplayJS.selectedProducts = new Object();
	}
	
	/** 
	 * Hides the Product Quick Info pop-up.
	 * 
	 * @param {string} id The id of the Product Quick Info pop-up to hide.
	 * @param {object} event The event triggered from user actions.
	 */		
	function hidePopup(id,event){
		if(event!=null && event.type=="keypress" && event.keyCode!="27"){
			return;
		}else{		
			var quickInfo = dijit.byId(id);
			if(quickInfo != null){
				if (dojo.byId('PopupErrorMessageText').innerHTML == "") {
					quickInfo.hide();
				}
			}
		}
	}

	/** 
	 * Stores the identifier of the order item which is the candidate for replacement.
	 * 
	 * @param {string} changeOrderItemId The id of the order item to be replaced.
	 */	
	function saveChangeOrderItemId(changeOrderItemId){
		replaceOrderItemId = changeOrderItemId;
	}

	/** 
	 * Defines the list of actions that show up in the Product Quick Info pop-up.
	 * Each property corresponds to an action.
	 * Default settings show the first 3 links.
	 */	
	function popupActionProperties() {
		this.showAddToCart = true;
		this.showWishList = true;
		this.showProductCompare = true;
		this.showReplaceCartItem = false;
	}

	/** 
	 * Transfers the focus to the "Close" button,
	 * when pressing the <Tab> key on the last focusable element in the Product Quick Info pop-up.
	 */	
	function gobackFocus() {
		document.getElementById('closeLink').focus();
	}

	/** 
	 * Transfers the focus to the last focusable element present in the Product Quick Info pop-up,
	 * when pressing the <Shift+Tab> keys on the "Close" button.
	 */		
	function setbackFocus(event) {
		if(event.shiftKey && event.keyCode == dojo.keys.TAB)
		{
			dojo.stopEvent(event);
		}
	}
	
	/** 
	 * Triggers a call to the hidePopup() function after a delay of a certain amount of time.
	 */			
	function delayHidePopup() {
		setTimeout(dojo.hitch(this,"hidePopup",'pdpOverlayBox'),200);
	}

	
	function setDIVOnColorSwatch(productID, productName, productURL, productImageSet, productTag1, productTag2) {			
		for (var x=0; x<prodIDs.length; x++) {				
			if (prodIDs[x]==productID) {				
				var medImgHTML = "";
				medImgHTML = '<img src="/wcsstore/KGStorefrontAssetStore/images/scene7/noImage.jpeg"' + 
							 ' width="365" height="490" class="prodImg" id="productFullImage">'; 
				if (productTag1 == "sale"){
					medImgHTML = medImgHTML + '<span class="tag-sale display-right transparent">&nbsp;</span>';
				} else if (productTag1 == "clearance"){
					medImgHTML = medImgHTML + '<span class="tag-clearance display-right transparent">&nbsp;</span>';
				} else if (productTag1 == "new"){
					medImgHTML = medImgHTML + '<span class="tag-new display-right transparent">&nbsp;</span>';
				} else if (productTag1 == "spotlight"){
					medImgHTML = medImgHTML + '<span class="tag-spotlight display-right transparent">&nbsp;</span>';
				}
				if (productTag2 == "sale"){
					medImgHTML = medImgHTML + '<span class="tag-sale display-left transparent">&nbsp;</span>';
				} else if (productTag2 == "clearance"){
					medImgHTML = medImgHTML + '<span class="tag-clearance display-left transparent">&nbsp;</span>';
				} else if (productTag2 == "new"){
					medImgHTML = medImgHTML + '<span class="tag-new display-left transparent">&nbsp;</span>';
				} else if (productTag2 == "spotlight"){
					medImgHTML = medImgHTML + '<span class="tag-spotlight display-left transparent">&nbsp;</span>';
				}				
				document.getElementById('medImgHolder').innerHTML = medImgHTML;
				getScene7URLs(productImageSet);	
				//bvLoadRR(productID);
				reviewsId = productID;
				setTimeout("setReviews()", 700);
				document.getElementById('detail_' + prodIDs[x]).style.display = 'block';				
				var prodURL = productURL;
				prodURL = prodURL.replace("WOMENS+PLUS+SIZE" , "WOMEN'S+PLUS+SIZE");
				prodURL = prodURL.replace("JUNIORS+PLUS+SIZE" ,"JUNIOR'S+PLUS+SIZE");
				document.getElementById('productName').innerHTML = productName;
				document.getElementById('readMore').href = prodURL;
				document.getElementById('productDisplayURL').value = prodURL;
			} else {
				document.getElementById('detail_' + prodIDs[x]).style.display = 'none';
			}
		}
		toggleReadMoreOnSwatchColor(productID);
		if (!$('.selPanelTNoTabs').length){ 
			$('.selection').tabs();
		}		
	}

	function setReviews() {	
		document.getElementById('custFeedback_' + reviewsId).innerHTML = document.getElementById('reviewHolder').innerHTML;
		reviewsId = 0;
	}

	function setDIVOnPageLoad(serviceResponse, productID, tab, promoMsg) {	
		var prodAvail = 'false';
		for (var i=0; i<serviceResponse.KGProdCnt; i++) {
			if (serviceResponse.KGProdIDs[i].catalogEntry.catalogEntryIdentifier.uniqueID==productID) {
				if (serviceResponse.KGProdBuyable != '0') {				
					var medImgHTML = "";
					medImgHTML = '<img src="/wcsstore/KGStorefrontAssetStore/images/scene7/noImage.jpeg"' + 
								 ' width="365" height="490" class="prodImg" id="productFullImage">'; 
					if (serviceResponse.KGProdIDs[i].productTag1 == "sale"){
						medImgHTML = medImgHTML + '<span class="tag-sale display-right transparent">&nbsp;</span>';
					} else if (serviceResponse.KGProdIDs[i].productTag1 == "clearance"){
						medImgHTML = medImgHTML + '<span class="tag-clearance display-right transparent">&nbsp;</span>';
					} else if (serviceResponse.KGProdIDs[i].productTag1 == "new"){
						medImgHTML = medImgHTML + '<span class="tag-new display-right transparent">&nbsp;</span>';
					} else if (serviceResponse.KGProdIDs[i].productTag1 == "spotlight"){
						medImgHTML = medImgHTML + '<span class="tag-spotlight display-right transparent">&nbsp;</span>';
					}
					if (serviceResponse.KGProdIDs[i].productTag2 == "sale"){
						medImgHTML = medImgHTML + '<span class="tag-sale display-left transparent">&nbsp;</span>';
					} else if (serviceResponse.KGProdIDs[i].productTag2 == "clearance"){
						medImgHTML = medImgHTML + '<span class="tag-clearance display-left transparent">&nbsp;</span>';
					} else if (serviceResponse.KGProdIDs[i].productTag2 == "new"){
						medImgHTML = medImgHTML + '<span class="tag-new display-left transparent">&nbsp;</span>';
					} else if (serviceResponse.KGProdIDs[i].productTag2 == "spotlight"){
						medImgHTML = medImgHTML + '<span class="tag-spotlight display-left transparent">&nbsp;</span>';
					}					
					document.getElementById('medImgHolder').innerHTML = medImgHTML;
					var prodURL = serviceResponse.KGProdIDs[i].catalogEntryURL;
					prodURL = prodURL.replace("WOMENS+PLUS+SIZE" , "WOMEN'S+PLUS+SIZE");
					prodURL = prodURL.replace("JUNIORS+PLUS+SIZE" ,"JUNIOR'S+PLUS+SIZE");					
					document.getElementById('productDisplayURL').value = prodURL;
					//bvLoadRR(productID);								
					reviewsId = productID;
					setTimeout("setReviews()", 700);				
					getScene7URLs(serviceResponse.KGProdIDs[i].productImageSet);
					document.getElementById('detail_' + serviceResponse.KGProdIDs[i].catalogEntry.catalogEntryIdentifier.uniqueID).style.display = 'block';
					document.getElementById('productName').innerHTML = serviceResponse.KGProdIDs[i].catalogEntry.description[0].shortDescription;
					document.getElementById('readMore').href = prodURL;
					for (var attr in serviceResponse.KGProdIDs[i].catalogEntryAttributes.attributes) {
						if (serviceResponse.KGProdIDs[i].catalogEntryAttributes.attributes[attr].usage == "Defining") {
							if (serviceResponse.KGProdIDs[i].catalogEntryAttributes.attributes[attr].name == "Color") {										
								for (var k in serviceResponse.KGProdIDs[i].catalogEntryAttributes.attributes[attr].allowedValue) {
									categoryDisplayJS.setSelectedAttribute(serviceResponse.KGProdIDs[i].catalogEntryAttributes.attributes[attr].name,serviceResponse.KGProdIDs[i].catalogEntryAttributes.attributes[attr].allowedValue[k].value);
								}
							}
						}
					}
					prodAvail = 'true';	
	
					categoryDisplayJS.ajaxKGCheckInventory('entitledItem_' + serviceResponse.KGProdIDs[i].catalogEntry.catalogEntryIdentifier.uniqueID, serviceResponse.KGCheckInventoryURL, 'addToCartLinkAjax_' + serviceResponse.KGProdIDs[i].catalogEntry.catalogEntryIdentifier.uniqueID + '_' + 
					tab, tab, 'productPopUpQty_' + serviceResponse.KGProdIDs[i].catalogEntry.catalogEntryIdentifier.uniqueID + '_' + tab, 
					serviceResponse.KGProdIDs[i].catalogEntry.catalogEntryIdentifier.uniqueID, serviceResponse.findAStoreURL, promoMsg);
				}
				else {
					document.getElementById('detail_' + serviceResponse.KGProdIDs[i].catalogEntry.catalogEntryIdentifier.uniqueID).style.display = 'none';
				}			
			} else {
				document.getElementById('detail_' + serviceResponse.KGProdIDs[i].catalogEntry.catalogEntryIdentifier.uniqueID).style.display = 'none';
			}
		}
		toggleReadMoreOnSwatchColor(productID);
		if (prodAvail == 'false' || serviceResponse.KGProdBuyable == '0') {
			setDefaultPage(serviceResponse.KGProdName, serviceResponse.KGProdImageSet);
		}
		if (!$('.selPanelTNoTabs').length){ 
			$('.selection').tabs();
		}
	}

	function toggleReadMoreOnSwatchColor(productID) {
	$('#readMore' + productID).click(function(e){
		var el = $('#copy' + productID).find("p.more");
		/*toggle the full product description*/
		el.toggle();
		if ($('#pdpOverlayBox').length) {
			//kg.overlayBox.setBoxHeight('pdpOverlayBox');
		}
		if (el.is(':visible')) {
			$(this).text('READ LESS');
		} else {
			$(this).text('READ MORE');
		}
		return false;
	});
	}
	
	function setDefaultPage(prodName, prodImageSet) {
		document.getElementById('contentOverlayBox').innerHTML = 			
		'<div class="simplemodal-close closeBox">' + 
				'<a href=# onclick="hideItem(\'pdpOverlayBox\');" id="closeLink">' + 
					'<div class="closeText">Close</div>' + 
					'<img src="/wcsstore/KGStorefrontAssetStore/images/icon_close.gif" width="17" height="17" alt="" class="closeIcon">' + 
				'</a>' + 
		'</div>' + 
		'<div id="pdpOverlayHeader">' + 
			'<h2 id="productName">' + prodName + '</h2>' +
			'<h1 style="display:none;" id="productSKUValue"></h1>' + 
		'</div><br>' + 
		'<div id="description"  class="descriptionOverlayBox">' + 		
		'<div class="thumbnails" id ="thumbnails" >' + 
			'<div class="thumbHolder thumbActive" id="thumbHolder"><img width="60" height="60" class="prodImg" src="/wcsstore/KGStorefrontAssetStore/images/scene7/noImage.jpeg"/></div>' + 
		'</div>' + 
		'<div id="medImgHolder">' + 
			'<img src="/wcsstore/KGStorefrontAssetStore/images/scene7/noImage.jpeg" width="365" height="490" class="prodImg" id="productFullImage">' + 
		'</div>' + 
		'<div class="detail" id="detail_default" style="display: block;">' + 		
			'<div class="selection ui-tabs ui-widget ui-widget-content ui-corner-all" id="selection">' + 					
				'<div class="selPanelTNoTabs"><!-- --></div>' + 
				'<div class="selPanel"><!-- --></div>' + 
				'<div class="ui-tabs-panel ui-widget-content ui-corner-bottom" id="selTab1">' + 
					'<div class="selTabContent">' + 	
						'<div class="divider"><!-- --></div>' + 
						'<div style="display: block;" id="prodNotAvailable" class="save-long clearfix"><p style="color: #CC0000;font-size: 11px;font-weight: bold;">Oops! We\'re sorry, this product is not available for purchase.</p></div>' + 
						'<div class="divider"><!-- --></div>' + 
					'</div>' + 
				'</div>' + 
			'</div>' + 
		'</div></div>';
		getScene7URLs(prodImageSet);
	}


