var persistentCartCommands = new Array(8); persistentCartCommands[0] = '/checkout/universal_cart.jsp'; persistentCartCommands[1] = '/checkout/add_item_pc.cmd'; persistentCartCommands[2] = '/checkout/add_items_pc.cmd'; persistentCartCommands[3] = '/checkout/delete_item_in_cart.cmd'; persistentCartCommands[4] = '/checkout/add_catalog_order_item_pc.cmd'; persistentCartCommands[5] = '/user/add_wishlist_item_to_basket_pc.cmd'; persistentCartCommands[6] = '/user/add_all_wishlist_items_to_basket_pc.cmd'; persistentCartCommands[7] = '/user/instore_pickup_zip_json_pc.jsp'; var persistentCartContainerId = "#ucart"; var persistentCartCloseButClass = "#ucart .close"; var hideTimeOuts= new Array(); var ucartLoadingHTML = '
' + '
' + '
'+ '
Loading...
' + '
' + '
' + '
'; var ucartSimpleHTML = '
'; var persistentCartIsShowing = false; /* Function(s) to Show the Basket Layer */ function showBasket(action, params, refreshPage, refreshDelayTime) { var miniCart = $(persistentCartContainerId); var miniCartPos = miniCart.position(); switch (action) { case "show": case "showFromQuickview": showloading(ucartLoadingHTML); requestURL = persistentCartCommands[0]; break; case "addProduct": showloading(ucartSimpleHTML); requestURL = persistentCartCommands[1]; break; case "addEnsemble": showloading(ucartSimpleHTML); requestURL = persistentCartCommands[2]; break; case "remove": showloading(ucartLoadingHTML); requestURL = persistentCartCommands[3]; //$(persistentCartContainerId).css('left',miniCartPos.left); $(persistentCartContainerId).css('top',miniCartPos.top); break; case "addCatalogItems": showloading(ucartSimpleHTML); requestURL = persistentCartCommands[4]; break; case "addProductWishlist": showloading(ucartSimpleHTML); requestURL = persistentCartCommands[5]; break; case "addAllProductsWishlist": showloading(ucartSimpleHTML); requestURL = persistentCartCommands[6]; break; default: alert("missing action"); } params = "ts=" + timestamp() + "&action=" + action + "&" + params; $.ajax({ type: "POST", url: requestURL, data: params, dataType: "html", timeout: 15000, success: function(data) { //if($.colorbox() != undefined || $.colorbox() != null){$.colorbox.close();} hideloading(); if (data.indexOf('DOCTYPE') > -1) { return; } if(action == 'remove' && data.indexOf('AddItemWithLinks') < 0) { data = data.replace('/*_ltk.SCA.ClearCart();*/','_ltk.SCA.ClearCart();'); } $(persistentCartContainerId).append(data); $(persistentCartContainerId).show(); if (refreshPage != undefined && refreshPage) { setTimeout( function() { location.reload(true); }, refreshDelayTime != undefined? refreshDelayTime : 0); } persistentCartIsShowing = true; return true; }, error: function() { hideloading(); if (refreshPage != undefined && refreshPage) { setTimeout( function() { location.reload(true); }, refreshDelayTime != undefined? refreshDelayTime : 0); } return false; } }); }; //load, position, show new cart function showloading(htmlToShow) { $(persistentCartContainerId).remove(); $("#js-ucart").append(htmlToShow); positionpersistentCart(); $(persistentCartContainerId).animate({ height: 'toggle' }, 300); }; function hideloading() { $(persistentCartContainerId + " *").remove(); $(persistentCartContainerId).html(""); }; //edit this function to position cart. function positionpersistentCart() { newLeft = $(persistentCartContainerId).width(); console.log(($("body").width() / 2)); console.log($(".common-template-shell").width() / 2); console.log( $(persistentCartContainerId).width()); //$(persistentCartContainerId).css("right", "-"+newLeft+"px"); $(persistentCartContainerId).css("top", "27px"); }; //edit this function to update the setup function setupPersistentCartButtons() { // draw focus near this //window.location = "#"; $(persistentCartCloseButClass).unbind("click").click(function() { hideBasket(); }); $(persistentCartCloseButClass).attr("href","javascript:void(0)"); clearAllTimeouts(); }; //Edit this function if need to do something special on basket close. function hideBasket() { $(persistentCartContainerId).animate( { height: 'toggle' }, 300, function() { $(persistentCartContainerId).remove(); persistentCartIsShowing = false; } ); }; function isShowingBasket() { return persistentCartIsShowing; } // update the header to include the amt function updateHeader(amt, total) { var itemTxt = amt == 1 ? "" : ""; $("#ucart .itemCount").html(''+ amt +' ' + itemTxt); $("#cartInfo .cartItemText").html('(' + amt + ' ' + itemTxt + ')'); $("#cartInfo .ucartSubtotal").html('Subtotal: '+total) }; function addToCart(prefix, container) { var scope = $(prefix); var action = 'addProduct'; if (container) { if (container.preventDefault) { container.preventDefault(); } scope = $(container).parents(prefix); } var productVariantId = $("input[name=productVariantId]", scope).val(); if (productVariantId == null || productVariantId == undefined) productVariantId = $("input[name=productVariantId2]", scope).val(); params = "productName=" + $("input[name=productName]", scope).val() + "&productId=" + $("input[name=productId]", scope).val() + "&categoryId=" + $("input[name=categoryId]", scope).val() + "&parentCategoryId=" + $("input[name=parentCategoryId]", scope).val() + "&subCategoryId=" + $("input[name=subCategoryId]", scope).val() + "&quantity=" + $("input[name=quantity]", scope).val() + "&productVariantId=" + productVariantId + "&crossSellItem=" + $("input[name=crossSellItem]", scope).val() + "&deliveryMethod=" + $( "input[type=radio][name=deliveryMethod]:checked").val() + "&deliveryMethodNotRequired=true" + "&selectedStore=" + $("input[name=selectedStore]", scope).val(); //see if this is an update. if ( $("input[name=itemGUID]", scope).length > 0 ) { params = params + "&itemGUID=" + $("input[name=itemGUID]", scope).val() + "&isUpdate=1"; } if ( $("input[name=onBasketPage]", scope).length > 0 ) { params = params + "&onBasketPage=" + $("input[name=onBasketPage]", scope).val(); } if (prefix != undefined) { params = params + "&prefix=" + prefix; } persistentCartIsShowing = false; showBasket(action, params); }; function wishListAddToCart(params,refreshPage,refreshDelayTime) { showBasket('addProductWishlist',params,refreshPage,refreshDelayTime); }; function wishListAddAllToCart(params,refreshPage,refreshDelayTime) { showBasket('addAllProductsWishlist',params,refreshPage,refreshDelayTime); }; function addCatalogOrderItemsToCart() { params = "productId=" + $("input[name=productId]").val() + "&itemNumber=" + $("input[name=itemNumber]").val() + "&productName=" + $("input[name=productName]").val() + "&productVariantId=" + $("input[name=productVariantId]").val() + "&quantity=" + $("input[name=quantity]").val(); showBasket('addCatalogItems',params); }; function addEnsembleToCart(type) { params = "productName=" + $("input[name=productName]").val() + "&ensembleId=" + $("input[name=ensembleId]").val() + "&categoryId=" + $("input[name=categoryId]").val() + "&parentCategoryId=" + $("input[name=parentCategoryId]").val(); // iterate through products in the ensemble for variant id $(".the-variant-ids").each(function() { params = params + "&" + $(this).attr("name") + "=" + $(this).val(); }); // iterate through products for qty $(".the-variant-qtys").each(function() { if( type == 'all' ){ $(this).val("1"); params = params + "&" + $(this).attr("name") + "=1"; } else { params = params + "&" + $(this).attr("name") + "=" + $(this).val(); } }); // iterate through products variant count $(".the-variant-count").each(function() { params = params + "&" + $(this).attr("name") + "=" + $(this).val(); }); params = params + "&productCount=" + $(".the-variant-ids").length; persistentCartIsShowing = false; showBasket('addEnsemble',params); }; function addEnsembleToCart(type, submittedIndex) { params = "productName=" + $("input[name=productName]").val() + "&ensembleId=" + $("input[name=ensembleId]").val() + "&ensembleId=" + $("input[name=ensembleId]").val() + "&selectedIndex=" + submittedIndex + "&parentCategoryId=" + $("input[name=parentCategoryId]").val(); // iterate through products in the ensemble for variant id $(".the-variant-ids").each(function() { params = params + "&" + $(this).attr("name") + "=" + $(this).val(); }); // iterate through products for qty $(".the-variant-qtys").each(function() { if( type == 'all' ){ $(this).val("1"); params = params + "&" + $(this).attr("name") + "=1"; } else { params = params + "&" + $(this).attr("name") + "=" + $(this).val(); } }); // iterate through products variant count $(".the-variant-count").each(function() { params = params + "&" + $(this).attr("name") + "=" + $(this).val(); }); params = params + "&productCount=" + $(".the-variant-ids").length; persistentCartIsShowing = false; showBasket('addEnsemble',params); }; function setUserZipCodePC(refresh) { var params = "ts=" + timestamp() + "&action=updateUserZipCode" + "&storesListZipCode=" + $("input[name=storesListZipCodePC]").val() + "&storesListLatitude=" + $("input[name=storesListLatitudePC]").val() + "&storesListLongitude=" + $("input[name=storesListLongitudePC]").val(); var requestURL = persistentCartCommands[7]; $.ajax({ type: "GET", url: requestURL, data: params, dataType: "json", timeout: 15000, success: function(data) { if (data.validZip) { if (refresh) { showBasket('show', ''); } return true; } else { alert(data.result); return false; } }, error: function() { alert('There was an error trying to save your zip code.'); return false; } }); } // Edit this per site to adjust location function adjustDivLocation(divToAdjust) { var bWindowOffsets = getScrollXY(); var bWindowViewport = getViewportSize(); var qvTop = ((bWindowViewport[1] / 2) - ($(divToAdjust).height() / 2)) + bWindowOffsets[1]; qvTop = (qvTop < 0) ? 100 : qvTop; $(divToAdjust).css("top",qvTop+"px"); $(divToAdjust).css("left","50%"); $(divToAdjust).css("margin-left",-($(divToAdjust).width()/2)); }; // Helper Function(s) function getScrollXY() { var scrOfX = 0, scrOfY = 0; if( typeof( window.pageYOffset ) == 'number' ) { //Netscape compliant scrOfY = window.pageYOffset; scrOfX = window.pageXOffset; } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) { //DOM compliant scrOfY = document.body.scrollTop; scrOfX = document.body.scrollLeft; } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) { //IE6 standards compliant mode scrOfY = document.documentElement.scrollTop; scrOfX = document.documentElement.scrollLeft; } return [ scrOfX, scrOfY ]; } function getViewportSize() { var vpW = 0, vpH = 0; if (typeof window.innerWidth != 'undefined'){ vpW = window.innerWidth, vpH = window.innerHeight } else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth != 'undefined' && document.documentElement.clientWidth != 0) { vpW = document.documentElement.clientWidth, vpH = document.documentElement.clientHeight } else { vpW = document.getElementsByTagName('body')[0].clientWidth, vpH = document.getElementsByTagName('body')[0].clientHeight } return [ vpW, vpH ]; } function errorAppend(area,msg) { $(area).html(msg.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/'/g, "'")); $(area).show(); }; function resetErrorFields() { $(".errorText").hide(); $(".errorText").html(""); }; function messageAppend(area,msg) { $(area).html(msg); $(area).show(); }; function resetMessageFields() { $(".infoText").hide(); }; function clearAllTimeouts() { for (x = 0; x < hideTimeOuts.length; x++) { clearTimeout(hideTimeOuts[x]); } }; function timestamp() { return new Date().getTime(); } function loadQuickView(overlayURL) { $.colorbox({"href":overlayURL}); hideBasket(); } function hideQuickView() { if (typeof OverlayWidget != "undefined") { OverlayWidget.hideAll(); } } function loadOverlay(overlay, overlayURL) { if (typeof OverlayWidget != "undefined") { OverlayWidget.show(overlay, null, { sourceURL : overlayURL }); } }