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; } }); } 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 = 0; posY = 0; getDocMode = true; var windowWidth = document.getElementById("mainContainer").offsetWidth; var leftBuffer = (windowWidth / 2) - 230 /* width of #compare-layer */; var bWindowOffsets = getScrollXY(); var bWindowViewport = getViewportSize(); try { 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; } } } catch(e){ /* ie6 has some trouble with this, but it should work despite the error thrown */ } if (posX + objPopup.offsetWidth > bWindowViewport[1]) { objPopup.style.left = posX - leftBuffer + "px"; } else { objPopup.style.left = posX - objPopup.offsetWidth + "px"; } objPopup.style.top = posY + 15 + "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"); else $(this).html("Compare"); }); } 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"); }); }