//Preload the loading image for both uc and qv. preload_QV_UC_loading = new Image(); preload_QV_UC_loading.src = "/assets/images/img/ajax-loader-wordmark.gif"; /* Persistant Cart (universal cart) Javascript */ /* --------------------------------------------- */ // Commands // persistantCartCommands[0] = "showProduct" action // persistantCartCommands[1] = "addProduct" action // persistantCartCommands[2] = "addEnsemble" action // persistantCartCommands[3] = "remove" action // persistantCartCommands[4] = "addCatalogItems" action // persistantCartCommands[5] = "addProductWishlist" action // persistantCartCommands[6] = "addAllProductsWishlist" action var persistantCartCommands = new Array(8); persistantCartCommands[0] = "/checkout/universal_cart.jsp"; persistantCartCommands[1] = "/checkout/add_item_pc.cmd"; persistantCartCommands[2] = "/checkout/add_items_pc.cmd"; persistantCartCommands[3] = "/checkout/delete_item_in_cart.cmd"; persistantCartCommands[4] = "/checkout/add_catalog_order_item_pc.cmd"; persistantCartCommands[5] = "/user/add_wishlist_item_to_basket_pc.cmd"; persistantCartCommands[6] = "/user/add_all_wishlist_items_to_basket_pc.cmd"; persistantCartCommands[7] = "/user/instore_pickup_zip_json_pc.jsp"; productCompareCommands = new Array(2); productCompareCommands[0] = "/user/add_item_to_comparison.cmd"; productCompareCommands[1] = "/includes/compare_items.jsp"; var requestURL = ""; var persistantCartContainerId = "#widget-ucart"; var persistantCartCloseButClass = ".widget-ucart-close-but"; var hideTimeOuts= new Array(); var ucartLoadingHTML = '
' + '
' + '
' + '
'+ '
Loading...
' + '
' + '
' + '
' + '
'; /* Function(s) to Show the Basket Layer */ function showBasket(action,params,refreshPage,refreshDelayTime) { showloading(); if( (action == "show") || (action == "showFromQuickview") ) { requestURL = persistantCartCommands[0]; } else if(action == "addProduct") { requestURL = persistantCartCommands[1];} else if(action == "addEnsemble") { requestURL = persistantCartCommands[2];} else if(action == "remove") { requestURL = persistantCartCommands[3];} else if(action == "addCatalogItems") { requestURL = persistantCartCommands[4];} else if(action == "addProductWishlist") { requestURL = persistantCartCommands[5];} else if(action == "addAllProductsWishlist") { requestURL = persistantCartCommands[6];} else { alert("missing action"); } requestURL = requestURL; params = "ts=" + timestamp() + "&action=" + action + "&" + params; $.ajax({ type: "POST", url: requestURL, data: params, dataType: "html", timeout: 150000, success: function(data) { hideloading(); $(persistantCartContainerId).append(data); if (refreshPage != undefined && refreshPage) { setTimeout( function() { location.reload(true); }, refreshDelayTime != undefined? refreshDelayTime : 0); } return true; }, error: function() { hideloading(); return false; } }); lib.layer.ie6Fix("#widget-ucart","a"); }; function showloading() { $(persistantCartContainerId).remove(); //load, position, show new cart $("body").append(ucartLoadingHTML); positionPersistantCart(); //$(persistantCartContainerId).show(); // add an event for close layer. //$(persistantCartCloseButClass).click(function() { hideBasket(); }); }; function hideloading() { $(persistantCartContainerId + " *").remove(); $(persistantCartContainerId).html(""); }; function addToCart() { params = "productName=" + $("input[@name=productName]").val() + "&productId=" + $("input[@name=productId]").val() + "&categoryId=" + $("input[@name=categoryId]").val() + "&parentCategoryId=" + $("input[@name=parentCategoryId]").val() + "&subCategoryId=" + $("input[@name=subCategoryId]").val() + "&quantity=" + $("input[@name=quantity]").val() + "&productVariantId=" + $("input[@name=productVariantId]").val() + "&preOrderFlag=" + $("input[@name=preOrderFlag]").val() + "&reserveFlag=" + $("input[@name=reserveFlag]").val() + "&sku=" + $("input[@name=sku]").val() + "&onDetailsPage=1"; //see if this is an update. if( $("input[@name=itemGUID]").val().length > 0 ) { params = params + "&itemGUID=" + $("input[@name=itemGUID]").val() + "&isUpdate=1"; } showBasket('addProduct',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(); } }); params = params + "&productCount=" + $(".the-variant-ids").length; 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 = persistantCartCommands[7]; $.ajax({ type: "GET", url: requestURL, data: params, dataType: "json", timeout: 15000, success: function(data) { if (refresh) { alert(data.result); showBasket('show', ''); } return true; }, error: function() { alert('There was an error trying to save your zip code.'); return false; } }); } function updateHeader(amt) { if(amt == 1) { $("#widget-ucart-item-count").text(amt + " item(s)"); } else { $("#widget-ucart-item-count").text(amt + " item(s)");} }; function errorAppend(area,msg) { $(area).html(msg.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/'/g, "'")); $(area).show(); }; function resetErrorFields() { $(".glo-tex-error").hide(); $(".glo-tex-error").html(""); }; function messageAppend(area,msg) { $(area).html(msg); $(area).show(); }; function resetMessageFields() { $(".glo-tex-info").hide(); }; function clearAllTimeouts() { for(x = 0; x < hideTimeOuts.length; x++) { clearTimeout(hideTimeOuts[x]); } }; function timestamp() { return new Date().getTime(); } //Edit this function if need to do something special on basket close. function hideBasket() { $(persistantCartContainerId).hide(); $(persistantCartContainerId).remove(); lib.layer.ie6Fix("#widget-ucart","r"); shoppingBagBut = $("#widget-header-active-link").eq(0); $(shoppingBagBut).attr("id","") $(shoppingBagBut).mouseout(); }; //edit this function to update the setup function setupPersistantCartButtons() { // draw focus near this window.location = "#"; $(persistantCartCloseButClass).unbind("click").click(function() { hideBasket(); }); $(persistantCartCloseButClass).attr("href","javascript:void(0)"); clearAllTimeouts(); }; //edit this function to position cart. function positionPersistantCart() { newLeft = 355 + ($("body").width() / 2) + ( $("#mainDiv").width() / 2 ) - $(persistantCartContainerId).width(); $(persistantCartContainerId).css("left", newLeft+"px"); $(persistantCartContainerId).css("top", "112px"); }; /* ---------------------------------------- */ /* QuickView Javascript */ /* ---------------------------------------- */ //quickViewcommands[0] = "show" action //quickViewcommands[1] = "add product" action var quickViewCommands = new Array(2); quickViewCommands[0] = "/catalog/quickview.jsp"; quickViewCommands[1] = "/catalog/qv_add_item_pc.cmd"; var quickViewContainerId = "#widget-quickview"; var quickViewCloseButtonsClass = ".widget-quickview-but-close"; var quickViewCloseButtonsAdd = ".widget-quickview-but-add"; var quickViewCloseButtonsPreOrder = ".widget-quickview-but-preorder"; var quickViewCloseButtonsReserve = ".widget-quickview-but-reserve"; var quickviewContainerHTML = '
'; var quickviewLoadingHTML = '
' + '
' + '
'+ '
Loading...
' + '
' + '
' + '
'; /* Function(s) for QuickView */ function loadQuickView(params,selector) { if(document.getElementById("widget-ucart")) { $("#widget-ucart").hide(); } closeQuickView(); addQuickView(selector); ajaxQuickView(quickViewCommands[0],params); //ie6 layer fix for select boxes lib.layer.ie6Fix("#widget-quickview", "a"); // if this is an edit, want to have this appear above the cart. if( params.indexOf("itemGUID") != -1 ) { $(quickViewContainerId).css("z-index", "1020"); } }; function addQuickView(selector) { $(selector).append(quickviewContainerHTML); $(quickViewContainerId).append(quickviewLoadingHTML); adjustQuickviewLocation(); $(quickViewContainerId).show(); }; function closeQuickView() { $(quickViewContainerId).remove(); //ie6 layer fix for select boxes lib.layer.ie6Fix("#widget-quickview", "r"); }; function ajaxQuickView(page,params) { params = "rId=" + new Date().getTime() + "&" + params; $.ajax({ type: "POST", url: page, data: params, dataType: "html", success: function(msg) { $(quickViewContainerId +" *").remove(); $(quickViewContainerId).html(""); $(quickViewContainerId).append(msg); //ie6 layer fix for select boxes lib.layer.ie6Fix("#widget-quickview", "u"); } }); }; function addProductFromQuickView(params) { params = params + "&productName=" + $(quickViewContainerId + " input[@name=productName]").val() + "&productVariantId=" + $(quickViewContainerId + " input[@name=productVariantId]").val() + "&quantity=" + $(quickViewContainerId + " input[@name=quantity]").val() + "&sku=" + $(quickViewContainerId + " input[@name=sku]").val(); if( $(quickViewContainerId + " input[@name=itemGUID]").size() > 0 ) { params = params + "&itemGUID=" + $(quickViewContainerId + " input[@name=itemGUID]").val(); } if( $(quickViewContainerId + " input[@name=onBasketPage]").size() > 0 ) { params = params + "&onBasketPage=" + $(quickViewContainerId + " input[@name=onBasketPage]").val(); unicaUpdateCart($(quickViewContainerId + " input[@name=userId]").val(), $(quickViewContainerId + " input[@name=productName]").val(), $(quickViewContainerId + " input[@name=sku]").val(), $(quickViewContainerId + " input[@name=quantity]").val(), $(quickViewContainerId + " input[@name=price]").val()); } $(quickViewContainerId + " select").each(function() { params = params + "&" + $(this).attr("name") + "=" + $(this).val(); }); $(quickViewContainerId + " *").remove(); $(quickViewContainerId).append(quickviewLoadingHTML); ajaxQuickView(quickViewCommands[1],params); }; var qvInterval; function setupQuickViewButtons() { $(quickViewCloseButtonsClass).unbind("click").click(function() { closeQuickView(); }); $(quickViewCloseButtonsAdd).unbind("click").click(function() { params = "productId=" + $(this).attr("id").split("-")[1]; addProductFromQuickView(params); }); $(quickViewCloseButtonsPreOrder).unbind("click").click(function() { params = "productId=" + $(this).attr("id").split("-")[1]; params += "&preOrderFlag=Y"; addProductFromQuickView(params); }); $(quickViewCloseButtonsReserve).unbind("click").click(function() { params = "productId=" + $(this).attr("id").split("-")[1]; params += "&reserveFlag=Y"; addProductFromQuickView(params); }); $(quickViewCloseButtonsClass).add( $(quickViewCloseButtonsAdd) ).attr("href","javascript:void(0)"); $(quickViewCloseButtonsClass).add( $(quickViewCloseButtonsPreOrder) ).attr("href","javascript:void(0)"); $(quickViewCloseButtonsClass).add( $(quickViewCloseButtonsReserve) ).attr("href","javascript:void(0)"); qvInterval = setInterval( "adjustQuickviewLocation();" , 100); setTimeout(function() { clearInterval(qvInterval); }, 1000); adjustQuickviewLocation(); }; function adjustQuickviewLocation() { adjustDivLocation(quickViewContainerId); } // 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"); }; /* ---------------------- */ // 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 ]; }; var iframeFix = function($) { return { add : function(id ,selector) { iframeFix.remove(id); iframeHTML = '
' $("body").append(iframeHTML); $("#" + id).css("position", "absolute"); $("#" + id).css("top", $(selector).css("top")); $("#" + id).css("left", $(selector).css("left")); $("#" + id).css("margin-top", $(selector).css("margin-top")); $("#" + id).css("margin-right", $(selector).css("margin-right")); $("#" + id).css("margin-bottom", $(selector).css("margin-bottom")); $("#" + id).css("margin-left", $(selector).css("margin-left")); $("#" + id).css("height", $(selector).height() + "px" ); $("#" + id).css("width", $(selector).width() + "px" ); $("#" + id).css("z-index", $(selector).css("z-index") - 1); }, remove : function(id) { $("#" + id).remove(); } } }($); // ------------------------------------------------ /* Quickview setup */ function setup_quickview() { var qTimer; imgHTML = 'Quickview'; $(".widget-app-quickview").each(function() { $(this).parent().parent().css("position","relative"); $(this).mouseover(function() { if( typeof qTimer != undefined ) { clearTimeout(qTimer); $("#widget-quickview-but").parent().remove(); } $(this).parent().parent().append(imgHTML); $("#widget-quickview-but").css("position","absolute"); var containerWidth = $("#widget-quickview-but").parent().parent().width(); var btnWidth = $("#widget-quickview-but").width(); var btnLeft = containerWidth/2 - btnWidth/2; $("#widget-quickview-but").css("left", btnLeft+"px"); var containerHeight = $("#widget-quickview-but").parent().parent().height(); var btnHeight = $("#widget-quickview-but").height(); var btnTop = containerHeight/2 - btnHeight/2; $("#widget-quickview-but").css("top", btnTop+"px"); $("#widget-quickview-but").mouseover(function() { if(typeof qTimer != undefined) { clearTimeout(qTimer); } }); $("#widget-quickview-but").parent().click(function(ev) { type = $(this).parent().attr("id").split("_")[0]; id = $(this).parent().attr("id").split("_")[1]; if( type == "p" ) { params = "productVariantId="+id;} else { var id2 = $(this).parent().attr("id").split("_")[2] params = "sku=" + id + "&departmentCode=" + id2; } loadQuickView(params, $("body")); }); $("#widget-quickview-but").parent().attr("href","javascript:void(0)"); }); $(this).mouseout(function() { qTimer = setTimeout(function() { $("#widget-quickview-but").parent().remove(); }, 100); }); }); }; function setup_quickview_basket() { var qTimer; imgHTML = 'Quickview'; $(".widget-app-quickview-basket").each(function() { $(this).parent().parent().css("position","relative"); $(this).mouseover(function() { if( typeof qTimer != undefined ) { clearTimeout(qTimer); $("#widget-quickview-but").parent().remove(); } $(this).parent().parent().append(imgHTML); $("#widget-quickview-but").css("position","absolute"); var containerWidth = $("#widget-quickview-but").parent().parent().width(); var btnWidth = $("#widget-quickview-but").width(); var btnLeft = containerWidth/2 - btnWidth/2; $("#widget-quickview-but").css("left", btnLeft+"px"); var containerHeight = $("#widget-quickview-but").parent().parent().height(); var btnHeight = $("#widget-quickview-but").height(); var btnTop = containerHeight/2 - btnHeight/2; $("#widget-quickview-but").css("top", btnTop+"px"); $("#widget-quickview-but").mouseover(function() { if(typeof qTimer != undefined) { clearTimeout(qTimer); } }); $("#widget-quickview-but").click(function(e) { var currentParams = this; quickparams = this.parentNode.parentNode.getElementsByTagName("span")[0].firstChild.nodeValue; loadQuickView(quickparams, $("body")); unicaparams = this.parentNode.parentNode.getElementsByTagName("span")[1].firstChild.nodeValue; unicaEditItemQuickView(unicaparams); e.preventDefault(); }); //$("#widget-quickview-but").parent().attr("href","javascript:void(0)"); }); $(this).mouseout(function() { qTimer = setTimeout(function() { $("#widget-quickview-but").parent().remove(); }, 100); }); }); }; function addProdToCompare(frm, divIdToUpdate, formName){ var url = productCompareCommands[0]; var pars = "formName=" + formName + "&productId=" + $("input[@name=productId]").val() + "&dest=" + $("input[@name=dest]").val(); var divToUpdate = "#" + divIdToUpdate; $.ajax({ type: "POST", url: url, data: pars, dataType: "html", success: function(data) { $(divToUpdate + " *").remove(); $(divToUpdate).html(""); $(divToUpdate).append(data); $(divToUpdate).show(); return true; }, error: function() { return false; } }); } var clInterval; function showCompareList(formName){ var url = productCompareCommands[1]; var pars = 'formName=' + formName; var divToUpdate = "#compare-layer-items"; $.ajax({ type: "POST", url: url, data: pars, dataType: "html", success: function(data) { $(divToUpdate + " *").remove(); $(divToUpdate).html(""); $(divToUpdate).append(data); $(divToUpdate).show(); return true; }, error: function() { return false; } }); clInterval = setInterval( "adjustCompareList();" , 100); setTimeout(function() { clearInterval(clInterval); }, 1000); adjustCompareList(); } function adjustCompareList() { divToUpdate = "#compare-layer-items"; adjustDivLocation(divToUpdate); } function comparePopup(e) { showHideComparePopup('hide'); objPopup = document.getElementById("compare-layer"); posX = null; posY = null; getDocMode = true; var bWindowOffsets = getScrollXY(); var bWindowViewport = getViewportSize(); if (e.pageX || e.pageY) { posX = e.pageX; posY = e.pageY; } else if (e.clientX || e.clientY) { if (getDocMode == true) { posX = e.clientX + document.documentElement.scrollLeft; posY = e.clientY + document.documentElement.scrollTop; } else { posX = e.clientX + document.body.scrollLeft; posY = e.clientY + document.body.scrollTop; } } if (posX + objPopup.offsetWidth > bWindowViewport[1]) { objPopup.style.left = posX - objPopup.offsetWidth + "px"; } else { objPopup.style.left = posX + "px"; } objPopup.style.top = posY - objPopup.offsetHeight + "px"; return false; } function showHideCompare(objState) { if (objState == "show") { document.getElementById("compare-layer-items").style.visibility = "visible"; } else { document.getElementById("compare-layer-items").style.visibility = "hidden"; } } function showHideComparePopup(objState) { if (objState == "show") { document.getElementById("compare-layer").style.visibility = "visible"; document.getElementById("compare-layer").style.display = ""; } else { document.getElementById("compare-layer").style.visibility = "hidden"; document.getElementById("compare-layer").style.display = "none"; } } function toggleCompareBox(prodId, formName){ var cBoxName = "checkbox_" + prodId; var oCb = document.getElementById(cBoxName); if (oCb) { if (oCb.checked) oCb.checked = false; else oCb.checked = true; var link = document.getElementById("compare_" + prodId); if (link) { if (oCb.checked) link.innerHTML = "Compare Items"; else link.innerHTML = "Compare Items"; } } } $(function() { setup_quickview(); setup_quickview_basket(); }); /* -------------------------- */