productCompareCommands = new Array(2); productCompareCommands[0] = '/user/add_item_to_comparison.cmd'; productCompareCommands[1] = '/catalog/compare_items.jsp'; productCompareCommands[2] = '/catalog/get_compare_items.jsp'; function addProdToCompare(frm, divIdToUpdate){ var url = productCompareCommands[0]; var pars = "formName=compareItemsForm" + "&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; } }); document.cookie = "COMPARE_PRODUCT=x;path=/"; } var clInterval; function showCompareList(){ var url = productCompareCommands[1]; var pars = 'formName=compareItemsForm'; 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 getCompareItems(compareItemsForm){ var url = productCompareCommands[2]; var pars = ''; var divToUpdate = "#compare-items-list"; $.ajax({ type: "POST", url: url, data: pars, dataType: "html", success: function(data) { productList = data.replace(/\[/,"").replace(/\]/,"").split("\,"); resetCompareItems(productList, compareItemsForm); return true; }, error: function() { return false; } }); } function resetCompareItems(prodCompareList, compareItemsForm) { clearAndToggleCompareCheckBoxes(); for (var i = 0; i < prodCompareList.length; i++) { checkCompareBox(prodCompareList[i].trim(), compareItemsForm, true); } } 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 { if (posX) objPopup.style.left = posX + "px"; } objPopup.style.top = posY - objPopup.offsetHeight - 150 + "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 removeCompareBox(prodId){ var cBoxName = "checkbox_" + prodId; var oCb = document.getElementById(cBoxName); if (oCb) oCb.checked = false; checkCompareBox(prodId, null, false); } function checkCompareBox(prodId, formName, itemAdded){ $("#checkbox_" + prodId, ".compare-items").each(function() { $(this).attr('checked', itemAdded); }); $("#compare_" + prodId, ".compare-items").each(function() { if (itemAdded) $(this).html("Compare Items"); else $(this).html("Compare Items"); }); } function compareItem(productId, event) { document.compareItemsForm.dest.value='/catalog/compare_pop.jsp'; document.compareItemsForm.productId.value = productId; addProdToCompare(document.compareItemsForm, 'compare-layer'); comparePopup(event); return false; } function clearAndToggleCompareCheckBoxes(){ $("[id^=checkbox]", ".compare-items").each(function() { $(this).attr('checked', false); }); $("[id^=compare]", ".compare-items").each(function() { $(this).html("Compare Items"); }); }