var debug=false;var isCategoryEmpty=false;var initialCount;function filterLeftMenuCategories(parentDiv){debug=false;var nonDuplicateList=getValidCategoriesList(parentDiv);if(debug){alert("nonDuplicateList:"+nonDuplicateList);}var liCategory=null;var liIndex=new Array();var leftMenuUlLi=$(".leftmenuul li");leftMenuUlLi.show();var liLength=leftMenuUlLi.length;for(var it=0;it<liLength;it++){liCategory=$(leftMenuUlLi.get(it)).attr("class");if(debug){alert("liCategory:"+liCategory+",it:"+it);}var showLi=0;for(var j=0;j<nonDuplicateList.length;j++){if(liCategory==nonDuplicateList[j].split(":")[0]){if(debug){alert(liCategory+"="+nonDuplicateList[j]+",it:"+it);}showLi=1;break;}}if(showLi==0){liIndex.push(liCategory);}}if(debug){alert(liIndex);}jQuery.each(liIndex,function(){$("."+this).hide();});hideFilterUlCategories();if(debug){alert("hiding leftmenu elements over");}if(debug){alert("categoriesCountWithArray"+categoriesCountWithArray);}var leftMenuUlVisible=$(".leftmenuul li:visible");for(var it=0;it<leftMenuUlVisible.length;it++){categoryLi=$(leftMenuUlVisible.get(it)).attr("class");jQuery.each(nonDuplicateList,function(){var categorycount=this.split(":");if(categorycount[0]==categoryLi){var leftmenuulId=$(leftMenuUlVisible.get(it)).parent().attr("id");var anchorElement=$(".leftmenu > .filterdiv > #"+leftmenuulId+" > ."+categoryLi+" > a");var anchorText=$(anchorElement).text().split(" (")[0];$(anchorElement).text(anchorText+" ("+categorycount[1]+")");}});}$(".leftmenuul > li > a").attr("href","javascript:void(0)");}function getValidCategoriesList(parentDiv){var categoriesList=new Array();var leftMenuUl=$("ul.leftmenuul");var leftMenuUlLength=$(leftMenuUl).length;for(var i=0;i<leftMenuUlLength;i++){var ulElement=leftMenuUl.get(i);var liList=$(ulElement).children();var liLength=$(liList).length;for(var j=0;j<liLength;j++){var liElement=liList.get(j);var category=$(liElement).attr("class");categoriesList.push(category);}}var nonDuplicateList=new Array();for(var i=0;i<categoriesList.length;i++){var count=$("#productsdiv").children("div."+categoriesList[i]+":visible").length;if(count>0){var element=categoriesList[i]+":"+count;nonDuplicateList.push(element);}}var productsSize=$("#productsdiv > div.flowerproduct:visible").length;if(document.getElementById("productscount")){document.getElementById("productscount").innerHTML="<b>Showing 1 - "+productsSize+" of "+productsSize+"</b>";}return nonDuplicateList;}function nonDuplicateCategories(allowedCategoriesList){var nonDuplicateList=new Array();if(debug){alert("after sorting allowedCategoriesList:"+allowedCategoriesList);}for(var k=0;k<allowedCategoriesList.length;k++){isIn=0;for(var j=0;j<nonDuplicateList.length;j++){if(allowedCategoriesList[k]==nonDuplicateList[j]){if(debug){alert("elements are equal:"+allowedCategoriesList[k]+": :"+nonDuplicateList[j]+":");}isIn=1;}}if(isIn==0){nonDuplicateList.push(allowedCategoriesList[k]);}}return nonDuplicateList;}function countOfCategories(sortedCategoriesList){debug=false;var sortedArrayWithCount=new Array();var element=null;var count=0;element=sortedCategoriesList[0];for(var i=0;i<sortedCategoriesList.length;i++){if(element==sortedCategoriesList[i]){count++;}else{if(element!=sortedCategoriesList[i]){if(debug){alert(element+":"+count);}sortedArrayWithCount.push(element+":"+count);element=sortedCategoriesList[i];count=1;}}if(i==((sortedCategoriesList.length)-1)){if(debug){alert(element+":"+count);}sortedArrayWithCount.push(element+":"+count);}}debug=false;return sortedArrayWithCount;}function showFilters(){var afterFilterDiv;var filterDiv=$("div.filterdiv");if(filterDiv.length>0){filterDiv.show();}else{}addFiltersToDiv();}function addFiltersToDiv(){var liString="";var appliedFiltersList="";var category="";if(filtersApplied.indexOf(",")>=0){appliedFiltersList=filtersApplied.split(",");if(debug){alert("filtersApplied"+filtersApplied+" appliedFiltersList"+appliedFiltersList.length);}if(appliedFiltersList!=null){index=1;if(isCategoryEmpty){index=0;}for(var i=index;i<appliedFiltersList.length;i++){if(appliedFiltersList[i]){category=$("#"+appliedFiltersList[i]).text().split("(")[0];appliedFiltersList[i]='"'+appliedFiltersList[i]+'"';if(debug){alert("category"+category);}if(category==null||category==""){category=$("div.breadcrumbs > span.breadcrumbstext").text();if(debug){alert("inside if category is null or :"+category);}}if(category!=null&&category!=""){liString=liString+"<li>"+category+"  <a href='javascript:void(0);' onclick='removeFilter("+appliedFiltersList[i]+");'><img src='/images/images/close.jpg' /></a></li>";}if(i==(appliedFiltersList.length-1)&&countryForH1!="searchpage"&&countryForH1!="findagiftbox"){$("#singlepromoheadercategory > h1.flowerbloompurple").text(category);}}}}}else{if(isCategoryEmpty){appliedFiltersList=filtersApplied;if(appliedFiltersList!=null&&appliedFiltersList!=""){if(debug){alert("indide addfilters to div= filtersApplied:"+filtersApplied+",appliedFiltersList:"+appliedFiltersList);}category=$("a#"+appliedFiltersList).text().split("(")[0];if(category==null||category==""){category=$("div.breadcrumbs > span.breadcrumbstext").text();if(debug){alert("category"+category);}}if(debug){alert(" element"+$("a#"+appliedFiltersList)+" text"+category);}appliedFiltersList='"'+appliedFiltersList+'"';liString=liString+"<li>"+category+"  <a href='javascript:void(0);' onclick='removeFilter("+appliedFiltersList+");'><img src='/images/images/close.jpg' /></a></li>";if(debug){alert("else finished");}}}}var filterUl=$(".filterul");filterUl.empty();filterUl.append(liString);}function removeFilter(category){if(isCategoryEmpty?true:(initialSelectedCategory!=category)){if(debug){alert("before:"+filtersApplied+",category:"+category);}if(filtersApplied.indexOf(category)>=0){if(filtersApplied.indexOf(category+",")>=0){filtersApplied=filtersApplied.replace(category+",","");}else{if(filtersApplied.indexOf(","+category)>=0){filtersApplied=filtersApplied.replace(","+category,"");}else{filtersApplied=filtersApplied.replace(category,"");}}$.cookie("filtersApplied",filtersApplied,{path:"/"});if(debug){alert("after:"+filtersApplied);}filtersApplied=filtersApplied.replace(",,","");if(debug){alert("after:"+filtersApplied);}reflectFilterCategoryInH1(category,"remove");}addFiltersToDiv();showProductsByFilters();if(debug){alert($("#"+category));}var parentUl=$("#"+category).parent(".leftmenuul li").parent().attr("id");if(debug){alert("parentUl:"+parentUl);}var parentUl=$("#"+parentUl);if(debug){alert(parentUl.children().length);}for(var ite=0;ite<parentUl.children().length;ite++){if($(parentUl.children().get(ite)).is(":hidden")){if($(parentUl.children().get(ite)).attr("class")!=category){$(parentUl.children().get(ite)).show();}}}if(debug){alert("before update menu");}filterLeftMenuCategories();if(debug){alert("after update menu");}setCountOfProducts();}}function setProductsAlignment(){var length=$("#productsdiv > div.flowerproduct:visible").length;for(var i=0;i<length;i++){var liElement=$("#productsdiv > div.flowerproduct:visible").get(i);$(liElement).removeClass("fourthcolumnproduct");$(liElement).removeClass("firstcolumnproduct");if(i%4==3){$(liElement).children(".flowerproduct").removeClass("firstcolumnproduct");$(liElement).children(".flowerproduct").addClass("fourthcolumnproduct");}if(i%4==0){$(liElement).removeClass("fourthcolumnproduct");$(liElement).addClass("firstcolumnproduct");}}}function reflectFilterCategoryInH1(category,event){if(countryForH1!=null&&countryForH1!="searchpage"){if(event=="remove"){if(filtersApplied.indexOf(",")>=0){categoryList=filtersApplied.split(",");if(debug){alert(categoryList+"categoryList.length:"+categoryList.length);}category=categoryList[categoryList.length-1];if(debug){alert(category);}}else{category=filtersApplied;if(debug){alert(category);}}}anchorTitle=$("#"+category).attr("title");if(category=="lt50"){anchorTitle="Best Sellers under $50";}else{if(category=="50to70"){anchorTitle="Best Sellers between $50 and $70";}else{if(category=="70to90"){anchorTitle="Best Sellers between $70 and $90";}else{if(category=="gt90"){anchorTitle="Best Sellers over $90";}else{if(category=="saturday-delivery"){anchorTitle="Gifts delivered on Saturday in"+countryForH1;}else{if(category=="sunday-delivery"){anchorTitle="Gifts delivered on Sunday in"+countryForH1;}}}}}}if(debug){alert("anchorTitle"+anchorTitle);}anchorTitle=anchorTitle+" - ";anchorTitle=anchorTitle+countryForH1;if(category=="lt50"){anchorTitle="Best Sellers To"+countryForH1+"(under $50)";}else{if(category=="50to70"){anchorTitle="Best Sellers To"+countryForH1+"$50 - $70";}else{if(category=="70to90"){anchorTitle="Best Sellers To"+countryForH1+"$70 - $90";}else{if(category=="gt90"){anchorTitle="Best Sellers To"+countryForH1+"(over $90)";}else{if(category=="saturday-delivery"){anchorTitle="Gifts delivered on Saturday in"+countryForH1;}else{if(category=="sunday-delivery"){anchorTitle="Gifts delivered on Sunday in"+countryForH1;}}}}}}if(countryForH1!="searchpage"&&countryForH1!="findagiftbox"){$("#singlepromoheadercategory > h1.flowerbloompurple").text(anchorTitle);}}}function addPriceFilterClass(){var flowerProductVisible=$("#productsdiv > div.flowerproduct:visible");if(debug){alert($("."+categorycount[0]).find("span.price").text());}for(var it=0;it<flowerProductVisible.length;it++){visibleProductLi=flowerProductVisible.get(it);switch($(visibleProductLi).find("span.parentPrice").text()){case"":productPrice=$(visibleProductLi).find("span.price").text();break;default:productPrice=$(visibleProductLi).find("span.parentPrice").text();break;}price=productPrice.split("US$")[1];if(price<50){$(visibleProductLi).addClass("lt50");}else{if(price>50&&price<70){$(visibleProductLi).addClass("50to70");}else{if(price>70&&price<90){$(visibleProductLi).addClass("70to90");}else{if(price>90){$(visibleProductLi).addClass("gt90");}}}}}}function showProductsByFilters(){var filterValues=filtersApplied.split(",");if(debug){alert("inside showProductsByFilters filterValues"+filterValues);}if(filterValues.length>1){if(debug){alert("inside showProductsByFilters filterValues"+filterValues);}$("#productsdiv > div.flowerproduct").show();jQuery.each(filterValues,function(){if(debug){alert("1234:"+this);}$("#productsdiv > div.flowerproduct:not(."+this+")").hide();if(debug){alert($("#productsdiv > div.flowerproduct:."+this+""));}});}else{if(filtersApplied!=""&&filtersApplied!=null){$("#productsdiv > div.flowerproduct").show();$("#productsdiv > div.flowerproduct:not(."+filtersApplied+")").hide();}else{if(filtersApplied==""||filtersApplied==null){$("#productsdiv > div.flowerproduct").show();}}}setProductsAlignment();if(debug){alert("function closed");}}function setCountOfProducts(){if(initialCount){var filterValues=filtersApplied.split(",");var element;if(filterValues.length>1){element=filterValues[filterValues.length-1];}else{if(filtersApplied!=""&&filtersApplied!=null){element=filtersApplied;}}if(filtersApplied==""||filtersApplied==null){$("b.colorgrey").text("showing 1 -"+initialCount+" of "+initialCount);}else{var count=$("#"+element).text().split("(")[1];count=count.split(")")[0];$("b.colorgrey").text("showing 1 -"+count+" of "+count);}}}function hideFilterUlCategories(){if(filtersApplied!=""&&filtersApplied!=null){var filterValues=filtersApplied.split(",");if(filterValues.length>1){jQuery.each(filterValues,function(){var parentUl=$("#"+this).parent(".leftmenuul li").parent().attr("id");for(var ite=0;ite<$("#"+parentUl).children().length;ite++){if($($("#"+parentUl).children().get(ite)).is(":visible")){if($($("#"+parentUl).children().get(ite)).attr("class")!=this){$($("#"+parentUl).children().get(ite)).hide();}}}});}else{var parentUl=$("#"+filtersApplied).parent(".leftmenuul li").parent().attr("id");for(var ite=0;ite<$("#"+parentUl).children().length;ite++){if($($("#"+parentUl).children().get(ite)).is(":visible")){if($($("#"+parentUl).children().get(ite)).attr("class")!=filtersApplied){$($("#"+parentUl).children().get(ite)).hide();}}}}}}