
var LR = {
    JSLogin:function(){
        $("#popuploginerrors").html("").hide();
        var b=""+$("#loginemail").val();if(b.length == 0) return $("#popuploginerrors").html('<p class="centered red padtb10">Please enter your email address</p>').show(), $("#loginemail").focus(), !1;
        var c=""+$("#loginpassword").val(); if(c.length == 0) return $("#popuploginerrors").html('<p class="centered red padtb10">Please enter your password</p>').show(), $("#loginpassword").focus(), !1;
        var d="";$("#rememberme").attr("checked") && (d="set");
        $("#lbbtnlogin").hide();
        $("#lbloginwait").show();
        $.post("/users/login_ajax.aspx", { u: b, p: c, r: d }, function(a) {
	        if(a.error!=null){$("#popuploginerrors").html('<p class="centered red padtb10">'+a.error+'</p>').show();$("#lbbtnlogin").show();$("#lbloginwait").hide();}
	        else if(a.loggedin != null)
	        {
		        $.get("/users/init.asp", { k: a.init }, function(){
                    jQuery('#popout').toggleClass( 'open' );
                    jQuery('#overlay').toggle();

                    $("#sdactions").html("");
                    $("#mobile-login").html("");
                    $("#actions-top").html("<ul class=\"none actions nav navpills\"><li><a href=\"/myaccount/\">Welcome back, " + a.userfirstname + "!</a></li></ul>");

                    if(a.subscription == "no")
                    {   location.href = "/myaccount/";  }
                    else
                    {
                        if(document.getElementById("refreshpage") != null)
                        {
                            location.href = (document.getElementById("actualurl")!=null?document.getElementById("actualurl").value:location.href) +"?" +(new Date().getMilliseconds());
                        }
                    }
		        });
                $("#liloginlogout").html('<a href="/logout/">Logout</a>');
	        }
        }, "json");
        return false;
    },
    JSRegister: function(){},
    DoLogin:function(){$(".popuploginerrors").html("").hide();var b=""+$("#lgemail").val();if(b.length == 0) return $(".popuploginerrors").html("Please enter your email address").show(), $("#lgemail").focus(), !1; var c = "" + $("#lgpass").val(); if (c.length == 0) return $(".popuploginerrors").html("Please enter your password").show(), $("#lgpass").focus(), !1; var d = ""; $("#lgrmbr").attr("checked") && (d = "set"); $("#lbbtnlogin").hide(); $("#lbloginwait").show(); $.post("/users/login_ajax.aspx", { u: b, p: c, r: d }, function(a) { a.error != null ? ($(".popuploginerrors").html(a.error).show(), $("#lbbtnlogin").show(), $("#lbloginwait").hide()) : a.loggedin != null ? ($("#topbar").html(a.welcomemsg), a.wordpressuserkey != null && (wpk = "" + a.wordpressuserkey, wpk.length > 0 && WPRemoteLogin(a.wordpressuid, a.wordpressuserkey, a.wordpressuserpass)), $.get("/users/init.asp", { k: a.init }, function() { $(".ndjoinus").hide(); a.subscription == "no" ? location.href = "/myaccount/" : document.getElementById("refreshpage") != null ? location.href=(document.getElementById("actualurl")!=null?document.getElementById("actualurl").value:location.href)+"?"+(new Date().getMilliseconds()) : $.fancybox.close() })) : ($("#lbbtnlogin").show(), $("#lbloginwait").hide()) }, "json"); return !1 },
    DoLoginPopup:function(){$(".popuploginerrors").html("").hide();var b=""+$("#lgemail").val();if(b.length == 0) return $(".popuploginerrors").html("Please enter your email address").show(), $("#lgemail").focus(), !1; var c = "" + $("#lgpass").val(); if (c.length == 0) return $(".popuploginerrors").html("Please enter your password").show(),$("#lgpass").focus(), !1;var d = ""; $("#lgrmbr").attr("checked") && (d = "set"); $("#lbbtnlogin").hide(); $("#lbloginwait").show(); $.post("/users/login_ajax.aspx", { u: b, p: c, r: d }, function(a){a.error != null ? ($(".popuploginerrors").html(a.error).show(), $("#lbbtnlogin").show(), $("#lbloginwait").hide()) : a.loggedin != null ? (parent.$("#topbar").html(a.welcomemsg),a.wordpressuserkey != null && (wpk = "" + a.wordpressuserkey, wpk.length > 0 && WPRemoteLogin(a.wordpressuid, a.wordpressuserkey, a.wordpressuserpass)), $.get("/users/init.asp", { k: a.init }, function() {a.subscription == "no" ? parent.location.href = "/myaccount" : parent.$.fancybox.close();})) : ($("#lbbtnlogin").show(), $("#lbloginwait").hide()) }, "json"); return !1 },
    RegReset:function(){$(".lbbtnreg").show();$(".lbregwait").hide();},
    DoRegistration:function(){$(".popupregerrors").html("").hide();    var a=""+$("#rghow").val();var b=""+$("#rgname").val();if(b.length==0) return $(".popupregerrors").html("Please enter your first name").show(), $("#rgname").focus(), LR.RegReset(), !1; var c=""+$("#rgemail").val();if(c.length == 0) return $(".popupregerrors").html("Please enter your email address").show(), $("#rgemail").focus(), LR.RegReset(), !1;var d=""+$("#rgpass").val();if(d.length == 0) return $(".popupregerrors").html("Please choose a password").show(), $("#rgpass").focus(), LR.RegReset(), !1;var prc=""+$("#rgpcode").val();$(".lbbtnreg").hide();$(".lbregwait").show();$.post("/users/register_ajax.aspx",{n:b,e:c,p:d,h:a,ccode:prc,token:$("#rgetoken").val()},function(a){a.error != null ? ($(".popupregerrors").html(a.error).show(), LR.RegReset()): a.loggedin != null ? $.get("/users/init.asp",{k:a.init},function(){$(".ndjoinus").hide();location.href = $("#rgsub").attr("checked") ? "/cart/WinePicks/":"/cart/welcome.aspx"}):($(".lbbtnreg").show(),$(".lbregwait").hide())},"json");return !1},
    DoLogin2:function(){var b="" + $("#lgemail2").val(); if (b.length == 0) return alert("Please enter your email address"), $("#lgemail2").focus(), !1; var c = "" + $("#lgpass2").val(); if (c.length == 0) return alert("Please enter your password"), $("#lgpass2").focus(), !1; var d = ""; $("#lgrmbr2").attr("checked") && (d = "set"); $("#lbbtnlogin2").hide(); $("#lbloginwait2").show(); $.post("/users/login_ajax.aspx", { u: b, p: c, r: d }, function(a) { a.error != null ? (alert(a.error), $("#lbbtnlogin2").show(), $("#lbloginwait2").hide()) : a.loggedin != null ? ($("#topbar").html(a.welcomemsg), a.wordpressuserkey != null && (wpk = "" + a.wordpressuserkey, wpk.length > 0 && WPRemoteLogin(a.wordpressuid, a.wordpressuserkey, a.wordpressuserpass)), $.get("/users/init.asp", { k: a.init }, function() { $("#ndpaypopup").hide(); if (a.subscription == "no") location.href = "/myaccount/"; document.getElementById("refreshpage") != null ? location.reload() : $.fancybox.close() })) : ($("#lbbtnlogin2").show(), $("#lbloginwait2").hide()) }, "json"); return !1 },
    DoRegistration2:function(){$(".popupregerrors2").html("").hide();var a = "" + $("#rghow2").val(); var b=""+$("#rgname2").val(); if(b.length==0) return $(".popupregerrors2").html("Please enter your first name").show(), $("#rgname2").focus(), LR.RegReset(), !1;var c=""+$("#rgemail2").val();if(c.length==0) return $(".popupregerrors2").html("Please enter your email address").show(), $("#rgemail2").focus(), LR.RegReset(), !1;var d=""+$("#rgpass2").val();if(d.length == 0) return $(".popupregerrors2").html("Please choose a password").show(), $("#rgpass2").focus(), LR.RegReset(), !1;var prc=""+$("#rgpcode2").val();$(".lbbtnreg").hide();$(".lbregwait").show();$.post("/users/register_ajax.aspx",{n:b,e:c,p:d,h:a,ccode:prc,token:$("#rgetoken").val()},function(a){a.error != null ? ($(".popupregerrors2").html(a.error).show(),LR.RegReset()) : a.loggedin != null ? $.get("/users/init.asp",{k:a.init},function(){$(".join-signin").html("");$("#ndpaypopup").hide();location.href=$("#rgsub2").attr("checked") ? "/cart/WinePicks/" : "/cart/welcome.aspx" }) : ($(".lbbtnreg").show(), $(".lbregwait").hide()) }, "json"); return !1 },
    PayPP:function(){$("#paypopup").trigger("click")},
    PPClose:function(){$.fancybox.close()},
    LogLB:function(){},
    CHKYES:function(){if($('#rgsub').attr("checked")){ $('#dvsubyes').addClass("greyroundbg"); $('#dvsbno').removeClass("greyroundbg"); } else { $('#dvsubyes').removeClass("greyroundbg"); } },CHKNO: function() { if ($('#rgsubno').attr("checked")) { $('#dvsbno').addClass("greyroundbg"); $('#dvsubyes').removeClass("greyroundbg"); } else { $('#dvsbno').removeClass("greyroundbg"); } },CHKYES2: function() { if ($('#rgsub2').attr("checked")) { $('#dvsubyes2').addClass("greyroundbg"); $('#dvsbno2').removeClass("greyroundbg"); } else { $('#dvsubyes2').removeClass("greyroundbg");}},
    CHKNO2:function(){if($('#rgsubno2').attr("checked")) { $('#dvsbno2').addClass("greyroundbg");$('#dvsubyes2').removeClass("greyroundbg");}else{$('#dvsbno2').removeClass("greyroundbg");}},
    CPRegReset:function(){$("#cplbbtnreg").show();$("#cpnregwaitimg").hide();},
    CPRegistration:function(){$(".popupregerrors").html("").hide();var a = "" + $("#cprghow").val(); var b=""+$("#cprgname").val(); if(b.length==0) return $(".popupregerrors").html("Please enter your first name").show(), $("#cprgname").focus(), LR.CPRegReset(), !1;var c=""+$("#cprgemail").val();if(c.length==0) return $(".popupregerrors").html("Please enter your email address").show(), $("#cprgemail").focus(), LR.CPRegReset(), !1;var d=""+$("#cprgpass").val();if(d.length == 0) return $(".popupregerrors").html("Please choose a password").show(), $("#cprgpass").focus(), LR.CPRegReset(), !1;var prc=""+$("#cprgpcode").val();$("#cplbbtnreg").hide();$("#cpnregwaitimg").show();$.post("/users/register_ajax.aspx",{n:b,e:c,p:d,h:a,ccode:prc},function(a){if(a.error!=null){$(".popupregerrors").html(a.error).show();LR.CPRegReset();}if(a.loggedin!=null){$.get("/users/init.asp",{k:a.init},function(){$("#ndcpnbox").hide();location.href="/cart/welcome.aspx";});}else{LR.CPRegReset();}},"json");return !1}
};


var WinePicksUI = {
    shoppingAjaxURL:    "/winepicks/shoppinglist_ajax.aspx",
    wishListAjaxURL:    "/winepicks/wishlist_ajax.aspx",
    searchAJAXURL:      "/winepicks/search_ajax.aspx",
    lcboAjaxURL:        "/stores/ontario/ajax_userstores.aspx",
    categoriesAJAXURL:  "/winepicks/categorylisting_ajax.aspx",
    scrollerAJAXURL:    "/winepicks/index_ajax.aspx",
    winelistsURL:       "/mywinelists/handler.aspx",
    buyagainURL:        "/buy-again/handler.aspx",
    listsURL:           "/winelists/handler.aspx",
    AddToShoppingList:function(a){$.getJSON(WinePicksUI.shoppingAjaxURL + "?adding=set&wid=" + escape(a), function(a) { a.added != null && ($("#wslistadd").hide(), $("#wslistrmv").fadeOut().fadeIn()) }) },
    RemoveFromShoppingList:function(a){$.getJSON(WinePicksUI.shoppingAjaxURL + "?removing=set&wid=" + escape(a), function(a) { a.removed != null && ($("#wslistrmv").hide(), $("#wslistadd").fadeOut().fadeIn()) }) },
    AddWToShoppingList:function(a){$.getJSON(WinePicksUI.shoppingAjaxURL + "?adding=set&wid=" + escape(a), function(b) { b.subscribe != null ? location.href = "/winepicks/subscription/" : b.added != null && ($("#wslistadd_" + a).hide(), $("#wslistrmv_" + a).fadeOut().fadeIn()) }) }, RemoveWFromShoppingList: function(a) { $.getJSON(WinePicksUI.shoppingAjaxURL + "?removing=set&wid=" + escape(a), function(b) { b.removed != null && ($("#wslistrmv_" + a).hide(), $("#wslistadd_" + a).fadeOut().fadeIn()) }) },
    ShoppingListRemove:function(a){$.getJSON(WinePicksUI.shoppingAjaxURL + "?removing=set&wid=" + escape(a), function(b) { b.removed != null && $("#wp_" + a).fadeOut() }) },
    ShoppingListReset:function(){if(!confirm("Removing all wines from your Shopping list. Continue?")) { return; } $.getJSON(WinePicksUI.shoppingAjaxURL + "?resetall=set", function(a) { a.removed != null && $(".printwp").fadeOut() }) },
    AddToWishList:function(a){$.getJSON(WinePicksUI.wishListAjaxURL + "?adding=set&wid=" + escape(a), function(a) { a.added != null && ($("#wwlistadd").hide(), $("#wwlistrmv").fadeOut().fadeIn()) }) },
    RemoveFromWishList:function(a){$.getJSON(WinePicksUI.wishListAjaxURL + "?removing=set&wid=" + escape(a), function(a) { a.removed != null && ($("#wwlistrmv").hide(), $("#wwlistadd").fadeOut().fadeIn()) }) },
    AddWToWishList:function(a){$.getJSON(WinePicksUI.wishListAjaxURL + "?adding=set&wid=" + escape(a), function(b) { b.subscribe != null ? location.href = "/winepicks/subscription/" : b.added != null && ($("#wwlistadd_" + a).hide(), $("#wwlistrmv_" + a).fadeOut().fadeIn()) }) }, RemoveWFromWishList: function(a) { $.getJSON(WinePicksUI.wishListAjaxURL + "?removing=set&wid=" + escape(a), function(b) { b.removed != null && ($("#wwlistrmv_" + a).hide(), $("#wwlistadd_" + a).fadeOut().fadeIn()) }) }, WishListRemove: function(a) { $.getJSON(WinePicksUI.wishListAjaxURL + "?removing=set&wid=" + escape(a), function(b) { b.removed != null && $("#wp_" + a).fadeOut() }) }, WishListReset: function() { if (!confirm("Removing all wines from your Wish List. Continue?")) { return; } $.getJSON(WinePicksUI.wishListAjaxURL + "?resetall=set", function(a) { a.removed != null && $(".printwp").fadeOut() }) },  searchPageNumber: 0, searchSortBy: "", searchResults: "", searchTotals: "", releaseDateDropdown: "#reviewdates", WineTypeSelected: function() { $.getJSON(WinePicksUI.searchAJAXURL + "?mode=getwines&wtype=" + $("#wrwt").val(), function(a) { if (a.wines != null) { var b = '<option value="">Please Choose</option>'; $.each(a.wines, function(a, c) { b += '<option value="' + c + '">' + c + "</option>" }); $("#wrgrape").html("").html(b).fadeOut().fadeIn() } }) }, FoodMatchSelected: function() { fm = "" + $("#wrfood").val(); "_" != fm.substring(0, 1) && $.getJSON(WinePicksUI.searchAJAXURL + "?mode=getfoods&ftype=" + $("#wrfood").val(), function(a) { a.foods != null && (a = '<option value="">Please Choose</option>' + a.foods, $("#wrfood").html("").html(a).fadeOut("slow").fadeIn("slow").val(fm)) }) }, ReviewDateSelected: function() { rd = "" + $("#reviewdates").val(); rd.length == 0 ? ($("#wrrdm").val(""), $("#wrrdd").val(""), $("#wrrdy").val("")) : rd == "AllDates" ? ($("#reviewdates").hide(), WinePicksUI.releaseDateDropdown = "#reviewdatesall", $("#reviewdatesall").show().fadeOut().fadeIn()) : rd.length == 10 && (rdparts = rd.split("-"), rdm = parseInt(rdparts[0], 10), isNaN(rdm) || $("#wrrdm").val(rdm), rdd = parseInt(rdparts[1], 10), isNaN(rdd) || $("#wrrdd").val(rdd), rdy = parseInt(rdparts[2], 10), isNaN(rdy) || $("#wrrdy").val(rdy)) }, ReviewDateSelectedFromAll: function() { rd = "" + $("#reviewdatesall").val(); rd.length == 0 ? ($("#wrrdm").val(""), $("#wrrdd").val(""), $("#wrrdy").val("")) : rd.length == 10 && (rdparts = rd.split("-"), rdm = parseInt(rdparts[0], 10), isNaN(rdm) || $("#wrrdm").val(rdm), rdd = parseInt(rdparts[1], 10), isNaN(rdd) || $("#wrrdd").val(rdd), rdy = parseInt(rdparts[2], 10), isNaN(rdy) || $("#wrrdy").val(rdy)) }, SelectLatestRelease: function() { $("#wrrdm").val(parseInt(wrpldM, 10)); $("#wrrdd").val(parseInt(wrpldD, 10)); $("#wrrdy").val(wrpldY); $(WinePicksUI.releaseDateDropdown).val("" + wrpldM + "-" + wrpldD + "-" + wrpldY) }, SelectLastRelease: function() { $("#wrrdm").val(parseInt(wrplldM, 10)); $("#wrrdd").val(parseInt(wrplldD, 10)); $("#wrrdy").val(wrplldY); $(WinePicksUI.releaseDateDropdown).val("" + wrplldM + "-" + wrplldD + "-" + wrplldY) }, PrintReview: function() { var a = "" + $(WinePicksUI.releaseDateDropdown).val(); a.length > 0 ? ndpopup("/winepicks/winepicks_bydate.aspx?wdate=" + a, 800, 600) : $(WinePicksUI.releaseDateDropdown).fadeOut().fadeIn() }, TopRatedPicked: function() { }, PrintTopRated: function() { var a = "" + $("#wrtp").val(); a.length > 0 ? (tpurl = "/winepicks/winepicks_toppicks.aspx?tp=" + a + "&", a = "wrpd wrwt wrgrape wrrg wrsc wrrdm wrrdd wrrdy wrwn wrtp wrfood wrpricea wrpriceb wrvintagea wrvintageb".split(" "), $.each(a, function(a, d) { ("" + $("#" + d).val()).length > 0 && (tpurl += d + "=" + $("#" + d).val() + "&") }), ndpopup(tpurl, 800, 600)) : $("#wrtp").fadeOut().fadeIn() }, WPSearchParameters: function() { var a = "", b = "wrpd wrwt wrgrape wrrg wrgs wrsc wrrdm wrrdd wrrdy wrwn wrtp wrfood wrpricea wrpriceb wrvintagea wrvintageb wagent".split(" "); $.each(b, function(b, c) { var e = "" + $("#" + c).val(); e.length > 0 && (a += c + "=" + e + "&") }); wpreset == 1 && (a += "&wpreset=set"); return a }, DoSearch: function(a) { var b = "" + $("#wrfood").val(); b.length > 1 && b.substring(0, 1) != "_" && $("#wrfood").val(""); WinePicksUI.searchResults = ""; $("#searchWaitImage").show(); b = WinePicksUI.WPSearchParameters(); $.getJSON(WinePicksUI.searchAJAXURL + "?" + b + ("&pnum=" + WinePicksUI.searchPageNumber) + ("&psort=" + WinePicksUI.searchSortBy) + a, function(a) { if (a.wpsubscribeplz != null) location.href = "/winepicks/subscription/"; else if ($("#searchWaitImage").hide(), a.content != null) $("#wpresults").slideUp(), WinePicksUI.searchResults = a.content, WinePicksUI.searchTotals = a.currentlyshowing, setTimeout("WinePicksUI.ViewUpdate()", 800) }); return !1 }, ViewUpdate: function() { $("#wpresults").html(WinePicksUI.searchResults).slideDown(); $("#wppages").html(WinePicksUI.searchTotals); $("#wppages2").html(WinePicksUI.searchTotals) }, SearchForWines: function() { WinePicksUI.searchPageNumber = 0; WinePicksUI.DoSearch("&dosearch=set"); return !1 }, PagePrevious: function() { WinePicksUI.searchPageNumber -= 1; if (WinePicksUI.searchPageNumber < 0) WinePicksUI.searchPageNumber = 0; WinePicksUI.DoSearch(""); return !1 }, PageNext: function() { WinePicksUI.searchPageNumber += 1; WinePicksUI.DoSearch(""); return !1 }, SortWinery: function() { WinePicksUI.searchSortBy = "winery"; WinePicksUI.DoSearch("&dosearch=set"); return !1 }, SortWine: function() { WinePicksUI.searchSortBy = "wine"; WinePicksUI.DoSearch("&dosearch=set"); return !1 }, SortReview: function() { WinePicksUI.searchSortBy = "review"; WinePicksUI.DoSearch("&dosearch=set"); return !1 }, StoresClick: function(a) { $(".stores").hide(); $("#storesfor_" + a).fadeIn(); location.href = "#sdiv_" + a; return !1 }, AnonLCBOSearch: function() { pc = $("#lcbo_pcode"); pc != null && (pcode = "" + $("#lcbo_pcode").val(), pcode.length > 0 ? pcode.length == 6 || pcode.length == 7 ? (wid = $("#lcbo_wid").val(), whash = $("#lcbo_whash").val(), $("#lcbo_wait").show(), $("#lcbo_sub").hide(), $.getJSON(WinePicksUI.lcboAjaxURL + "?mode=anon&pcode=" + pcode + "&wid=" + wid + "&whash=" + whash, function(a) { a.lcbourl != null ? location.href = a.lcbourl : a.error != null ? alert(a.error) : alert("Unable to look up LCBO stock right now. Please try again later.") })) : alert("Please enter a valid Ontario postal code") : (alert("Please enter a Postal code"), pc.focus())); return !1 }, ToggleSection: function(a) { $("#" + a).toggle(); t = "" + $("#href_" + a).text(); "Compress" == t && $("#href_" + a).text("Expand"); "Expand" == t && $("#href_" + a).text("Compress") }, OpenSort: function() { $("#sortheader").hide(); $("#sortbtns").show() }, HandleShoppingListScroller: function(a) { $.post($("#whandlerurl").val(), { mode: "shoppinglist", wid: a }, function(b) { b.error != null ? ($("#scrollermsgs").html("").fadeOut(), $("#scrollermsgs").html("" + b.error).fadeIn()) : b.shoppinglistremoved != null ? ($("#shplnk_" + a).removeClass("wdShopOK").addClass("wdShop").fadeOut().fadeIn(), $("#scrollermsgs").html('Wine removed from your <a href="/winepicks/shoppinglist.aspx">Shopping List</a>').fadeIn()) : b.shoppinglistadded != null && ($("#shplnk_" + a).removeClass("wdShop").addClass("wdShopOK").fadeOut().fadeIn(), $("#scrollermsgs").html('Wine added to your <a href="/winepicks/shoppinglist.aspx">Shopping List</a>').fadeIn()) }, "json") }, HandleWishListScroller: function(a) { $.post($("#whandlerurl").val(), { mode: "wishlist", wid: a }, function(b) { b.error != null ? $("#scrollermsgs").html("" + b.error).fadeIn() : b.wishlistremoved != null ? ($("#wshlnk_" + a).removeClass("wdWishOK").addClass("wdWish").fadeOut().fadeIn(), $("#scrollermsgs").html("").fadeOut(), $("#scrollermsgs").html('Wine removed from your <a href="/winepicks/wishlist.aspx">Wish List</a>').fadeIn()) : b.wishlistadded != null && ($("#wshlnk_" + a).removeClass("wdWish").addClass("wdWishOK").fadeOut().fadeIn(), $("#scrollermsgs").html("").fadeOut(), $("#scrollermsgs").html('Wine added to your <a href="/winepicks/wishlist.aspx">Wish List</a>').fadeIn()) }, "json") }, HandleShoppingListBottleScroller: function(a) { $.post($("#whandlerurl").val(), { mode: "shoppinglist", wid: a }, function(b) { b.error != null ? ($("#bottlescrollermsgs").html("").fadeOut(), $("#bottlescrollermsgs").html("" + b.error).fadeIn()) : b.shoppinglistremoved != null ? ($("#shplnk_" + a).removeClass("wdShopOK").addClass("wdShop").fadeOut().fadeIn(), $("#bottlescrollermsgs").html('Wine removed from your <a href="/winepicks/shoppinglist.aspx">Shopping List</a>').fadeIn()) : b.shoppinglistadded != null && ($("#shplnk_" + a).removeClass("wdShop").addClass("wdShopOK").fadeOut().fadeIn(), $("#bottlescrollermsgs").html('Wine added to your <a href="/winepicks/shoppinglist.aspx">Shopping List</a>').fadeIn()) }, "json") }, HandleWishListBottleScroller: function(a) { $.post($("#whandlerurl").val(), { mode: "wishlist", wid: a }, function(b) { b.error != null ? $("#bottlescrollermsgs").html("" + b.error).fadeIn() : b.wishlistremoved != null ? ($("#wshlnk_" + a).removeClass("wdWishOK").addClass("wdWish").fadeOut().fadeIn(), $("#bottlescrollermsgs").html("").fadeOut(), $("#bottlescrollermsgs").html('Wine removed from your <a href="/winepicks/wishlist.aspx">Wish List</a>').fadeIn()) : b.wishlistadded != null && ($("#wshlnk_" + a).removeClass("wdWish").addClass("wdWishOK").fadeOut().fadeIn(), $("#bottlescrollermsgs").html("").fadeOut(), $("#bottlescrollermsgs").html('Wine added to your <a href="/winepicks/wishlist.aspx">Wish List</a>').fadeIn()) }, "json") }, HandleShoppingList: function(a) { $.post($("#whandlerurl").val(), { mode: "shoppinglist", wid: a }, function(b) { b.error != null ? $("#wmsg_" + a).html("" + b.error).fadeIn() : b.shoppinglistremoved != null ? ($("#shplnk_" + a).removeClass("wdShopOK").addClass("wdShop").fadeOut().fadeIn(), $("#wmsg_" + a).html('<span class="ndMsg">Wine removed from your <a href="/winepicks/shoppinglist.aspx">Shopping List</a></span>').fadeIn()) : b.shoppinglistadded != null && ($("#shplnk_" + a).removeClass("wdShop").addClass("wdShopOK").fadeOut().fadeIn(), $("#wmsg_" + a).html('<span class="ndMsg">Wine added to your <a href="/winepicks/shoppinglist.aspx">Shopping List</a></span>').fadeIn()) }, "json") }, HandleWishList: function(a) { $.post($("#whandlerurl").val(), { mode: "wishlist", wid: a }, function(b) { b.error != null ? $("#wmsg_" + a).html("" + b.error).fadeIn() : b.wishlistremoved != null ? ($("#wshlnk_" + a).removeClass("wdWishOK").addClass("wdWish").fadeOut().fadeIn(), $("#wmsg_" + a).html('Wine removed from your <a href="/winepicks/wishlist.aspx">Wish List</a>').fadeIn()) : b.wishlistadded != null && ($("#wshlnk_" + a).removeClass("wdWish").addClass("wdWishOK").fadeOut().fadeIn(), $("#wmsg_" + a).html('Wine added to your <a href="/winepicks/wishlist.aspx">Wish List</a>').fadeIn()) }, "json") },  LoadCategoryContent: function(a) { $.getJSON(WinePicksUI.categoriesAJAXURL + "?cid=" + escape(a), function(a) { a.uicontent != null ? (location.href = "#wine", $("#winecategoryscrollerdiv").html(a.uicontent)) : (location.href = "#wine", $("#winecategoryscrollerdiv").html('<p align="center">No Wines Found</p>')); a.titlelink != null && $("#winecatlink").html(a.titlelink); a.title != null && $("#winecattitle").html(a.title) }); return !1 }, LoadCategoryContentNoJump: function(a) { $.getJSON(WinePicksUI.categoriesAJAXURL + "?cid=" + escape(a), function(a) { a.uicontent != null ? $("#winecategoryscrollerdiv").html(a.uicontent) : $("#winecategoryscrollerdiv").html('<p align="center">No Wines Found</p>'); a.titlelink != null && $("#winecatlink").html(a.titlelink); a.title != null && $("#winecattitle").html(a.title) }); return !1 }, LoadMoreCategories: function() { $.getJSON("/winepicks/category_ajax.aspx?mode=loadmore&catids=" + escape($("#showncatids").val()), function(a) { a.uicontent != null ? ("" + a.uicontent).length > 0 ? $("#morewinecategories").append(a.uicontent) : $("#showmorelink").hide() : $("#showmorelink").hide() }) }, ScrollerTopPicks: function() { if ($("#uwss").val() == "false") return $("#paypopup").trigger("click"), !1; witems = $("#wine-review-selection li a"); witems.removeClass("active"); $("#wine-picks-gettoppicks").addClass("active"); wcontainer = $("#latest-wine-reviews .wine-picks-scroller-container"); wcontainer.animate({ opacity: 0 }, 500, function() { $.getJSON(WinePicksUI.scrollerAJAXURL + "?type=toppicks", function(a) { a.error != null ? wcontainer.html(a.error) : a.content != null && ($("#latest-wine-reviews .wine-picks-items").html(""), wcontainer.html(a.content)); wcontainer.animate({ opacity: 1 }, 500); WinePicksUI.ScrollerWidthFix() }) }); return !1 }, ScrollerAllWines: function() { witems = $("#wine-review-selection li a"); witems.removeClass("active"); $("#wine-picks-getallpicks").addClass("active"); wcontainer = $("#latest-wine-reviews .wine-picks-scroller-container"); $.getJSON(WinePicksUI.scrollerAJAXURL + "?type=allwines", function(a) { a.error != null ? wcontainer.html(a.error) : a.content != null && ($("#latest-wine-reviews .wine-picks-items").html(""), wcontainer.animate({ opacity: 0 }, 500), wcontainer.html(a.content)); wcontainer.animate({ opacity: 1 }, 500); WinePicksUI.ScrollerWidthFix() }); return !1 }, WSAllNext: function() { wcontainer = $("#latest-wine-reviews .wine-picks-scroller-container"); var a = parseInt($("#wsallpage").val(), 10) + 1; wcontainer.html('<p align="center"><img src="/images/wait_arrows.gif" alt="Loading..." /></p>'); $.getJSON("/winepicks/scroller_ajax.aspx?type=allwines&pg=" + a, function(b) { b.error != null ? wcontainer.html(b.error) : b.content != null && ($("#latest-wine-reviews .wine-picks-items").html(""), wcontainer.animate({ opacity: 0 }, 500), wcontainer.html(b.content), $("#wsallpage").val(a)); wcontainer.animate({ opacity: 1 }, 500); WinePicksUI.ScrollerWidthFix(); wcontainer.scrollLeft(0) }) }, WSTopNext: function() { wcontainer = $("#latest-wine-reviews .wine-picks-scroller-container"); var a = parseInt($("#wstoppage").val(), 10) + 1; wcontainer.html('<p align="center"><img src="/images/wait_arrows.gif" alt="Loading..." /></p>'); $.getJSON("/winepicks/scroller_ajax.aspx?type=toppicks&pg=" + a, function(b) { b.error != null ? wcontainer.html(b.error) : b.content != null && ($("#latest-wine-reviews .wine-picks-items").html(""), wcontainer.animate({ opacity: 0 }, 500), wcontainer.html(b.content), $("#wstoppage").val(a)); wcontainer.animate({ opacity: 1 }, 500); WinePicksUI.ScrollerWidthFix(); wcontainer.scrollLeft(0) }) }, ScrollerWidthFix: function() { var a = 0; $("#latest-wine-reviews .wine-picks-items > li").each(function() { a += $(this).outerWidth(!0) }); $("#latest-wine-reviews .wine-picks-items").css("width", a + 50) }, LoadScrollerContent: function() { },
    AddToMyList:function(wid){$("#addtomylist").hide();$("#mylists").show();},
    ListSelection:function(wid)
    {
        if(document.getElementById("lguid")==null){$("#listmsgs").html('Please <a href="/login/?r=/winepicks/">login</a> to continue').addClass("ndError").show();return;}
        uid = parseInt($("#lguid").val(),10);sval=""+$("#uwl").val();if(sval.length == 0){return;}
        $("#uwlwait").show();$("#listmsgs").html("").removeClass("ndError").removeClass("ndMsg").hide();
        if(/^cl-yes/i.test(sval)){location.href="/mycellar/mywines/"+wid+"/"+uid;}
        else if(/^cl/i.test(sval)){location.href="/mycellar/addwine.aspx?wid="+wid;}
        else if(/^newlist/i.test(sval)){location.href="/mywinelists/create.aspx?wid="+wid;}
        else if(/^managelists/i.test(sval)){location.href="/mywinelists/";}
        else if(/^llyes-/i.test(sval)){lid=parseInt(sval.replace("llyes-",""),10);$.post(WinePicksUI.winelistsURL,{mode:"removefromlist",wineid:wid,listid:lid},function(data){if(data.removed != null){$("#uwl option:selected").attr("value","ll-"+lid).removeClass("woptYES");$("#uwl").val("");$("#listmsgs").html('<div class="ndMsg">Wine removed from your <a href="/mywinelists/update.aspx?lid='+lid+'">List</a></div>').show();$("#uwlwait").hide();}},"json");}
        else if(/^ll-/i.test(sval)){lid=parseInt(sval.replace("ll-",""),10);$.post(WinePicksUI.winelistsURL,{mode:"addtolist",wineid:wid,listid:lid},function(data){if(data.success!=null){$("#uwl option:selected").attr("value","llyes-"+lid).addClass("woptYES");$("#uwl").val("");$("#listmsgs").html('<div class="ndMsg">Wine added to your <a href="/mywinelists/update.aspx?lid='+lid+'">List</a></div>').show();$("#uwlwait").hide();}},"json");}
    },
    WineListRemove:function(wid){$.post("/mywinelists/handler.aspx",{mode:"removefromlist",wineid:wid,listid:$("#winelistid").val()},function(data){if(data.error!= null){alert(data.error);}else if (data.removed != null){$("#wp_" + wid).fadeOut();}else{alert("Unable to process request")}},"json");},
    DDHandler: function (wid)
    {
        sval = "" + $("#wopts_" + wid).val(); if (sval.length == 0) { return; }
        if(/^logincellar/i.test(sval)){location.href="/login/?r=/mycellar/";return;}
        else if(/^loginlists/i.test(sval)){location.href="/login/?r=/mywinelists/";return;}
        if(document.getElementById("lguid")==null){$("#wmsg_"+wid).html('<div class="ndError">Please <a href="/login/?r=/winepicks/">login</a> to continue</div>').show();return;}
        uid = parseInt($("#lguid").val(),10);$("#woptswait_"+wid).show();$("#wmsg_"+wid).html("").hide();
        if(/^cl-yes/i.test(sval)){location.href="/mycellar/mywines/"+wid+"/"+uid;}
        else if(/^cl/i.test(sval)){location.href="/mycellar/addwine.aspx?wid="+wid;}
        else if(/^newlist/i.test(sval)){location.href="/mywinelists/create.aspx?wid="+wid;}
        else if(/^managelists/i.test(sval)){location.href="/mywinelists/";}
        else if(/^llyes-/i.test(sval)){lid=parseInt(sval.replace("llyes-",""),10);$.post(WinePicksUI.winelistsURL,{mode:"removefromlist",wineid:wid,listid:lid},function(data){if(data.removed != null){$("#wopts_"+wid+" option:selected").attr("value","ll-"+lid).removeClass("woptYES");$("#wopts_"+wid).val("");$("#wmsg_"+wid).html('<div class="ndMsg">Wine removed from your <a href="/mywinelists/update.aspx?lid='+lid+'">List</a></div>').show();$("#woptswait_"+wid).hide();}},"json");}
        else if (/^ll-/i.test(sval)) { lid = parseInt(sval.replace("ll-", ""), 10); $.post(WinePicksUI.winelistsURL, { mode: "addtolist", wineid: wid, listid: lid }, function (data) { if (data.success != null) { $("#wopts_" + wid + " option:selected").attr("value", "llyes-" + lid).addClass("woptYES"); $("#wopts_" + wid).val(""); $("#wmsg_" + wid).html('<div class="ndMsg">Wine added to your <a href="/mywinelists/update.aspx?lid=' + lid + '">List</a></div>').show(); $("#woptswait_" + wid).hide(); } }, "json"); }
    },
    DDHandlerText:function(wid)
    {
        if(document.getElementById("lguid")==null){alert('Please login to continue');return;}
        uid = parseInt($("#lguid").val(),10);sval=""+$("#wopts_"+wid).val();if(sval.length == 0){return;}
        if(/^sl/i.test(sval)){location.href="/winepicks/addtoshoppinglist.aspx?wid="+wid;}
        else if(/^wl/i.test(sval)){location.href="/winepicks/addtowishlist.aspx?wid="+wid;}
        else if(/^cl/i.test(sval)){location.href="/mycellar/addwine.aspx?wid="+wid;}
        else if(/^ml/i.test(sval)){location.href="/mywinelists/create.aspx?wid="+wid+"&fromtxt=set";}
        else if(/^newlist/i.test(sval)){location.href="/mywinelists/create.aspx?wid="+wid;}
        else if(/^managelists/i.test(sval)){location.href="/mywinelists/";}
        else if(/^llyes-/i.test(sval)){lid=parseInt(sval.replace("llyes-",""),10);$.post(WinePicksUI.winelistsURL,{mode:"removefromlist",wineid:wid,listid:lid},function(data){if(data.removed != null){$("#wopts_"+wid+" option:selected").attr("value","ll-"+lid).removeClass("woptYES");$("#wopts_"+wid).val("");}},"json");}
        else if(/^ll-/i.test(sval)){lid=parseInt(sval.replace("ll-",""),10);$.post(WinePicksUI.winelistsURL,{mode:"addtolist",wineid:wid,listid:lid},function(data){if(data.success!=null){$("#wopts_"+wid+" option:selected").attr("value","llyes-"+lid).addClass("woptYES");$("#wopts_"+wid).val("");}},"json");}
    },
    ShowLoginBox:function(){/*$(".ndlogin").trigger('click');*/location.href="/login/";},
    WAPXReplace:function(ahref,wid,cwid){ahref.style.display = "none";$("img.wexwait_"+cwid).show();$.getJSON("/winepicks/updateimages_handler.aspx?wdst="+wid+"&wsrc="+cwid,function(a){if(a.error!=null){alert(a.error);ahref.style.display = "";$("img.wexwait_"+cwid).hide();}else if(a.updated!=null){location.href=$("#wurl").val();}else{alert("Unable to process request");ahref.style.display = "";$("img.wexwait_"+cwid).hide();}});},
    WPS2ValidateBasic:function(){var sval=""+$(".tasc").val();var tval=""+$(".tatp").val();if(sval.length>0 || tval.length>0){if($("#accesscontenttextdiv")!=null){$("#accesscontenttextdiv").show("slow");}LR.PayPP();return false;}return true;},
    WPS2ValidateAdvanced:function(){var svalmin=""+$(".tascmin").val();var svalmax=""+$(".tascmax").val();var tval=""+$(".tatp").val();if(svalmin.length>0 || svalmax.length>0 || tval.length>0){if($("#accesscontenttextdiv")!=null){$("#accesscontenttextdiv").show("slow");}LR.PayPP();return false;}return true;}
};

function getDaysInMonth(m,y){return /8|3|5|10/.test(--m)?30:m==1?(!(y%4)&&y%100)||!(y%400)?29:28:31;}
function strpad(n,len){ s = n.toString(); if (s.length < len) { s = ('0000000000' + s).slice(-len); } return s; }
function WPRemoteLogin(b, c, d) { $.get("/blog/wp-dotnetinit.php", { wuid: b, userkey: c, userpass: d }, function() { }, "json") };
function WPDateSel(){$("#tabscroll").html(""); bid = parseInt($("#wpbd").val(), 10);if (bid > 0) {$("#wptabs li a").each(function(i, e) { $(e).removeClass("current"); }); $(".pane").load("/winepicks/tabcontent.aspx?wdate=" + bid);$("#scrollall").addClass("current");}}
function WPScrollLoadMore(type, imgwaitid, imgmoreid) {$("#" + imgmoreid).hide(); api = $("#scrollable").data("scrollable"); pgnum = parseInt($("#tabpg").val(), 10) + 1;imgobj = $("#" + imgwaitid);if (imgobj != null) { imgobj.show(); }$.get('/winepicks/tabcontentmore.aspx?type=' + type + '&pg=' + pgnum, function (data){if(imgobj != null){imgobj.hide();} $("div.itempg_" + $("#tabpg").val()).remove(); api.addItem(data); $("#arrright").removeClass("disabled"); $("#tabpg").val(pgnum); WPScrollerSListVUpdate(); });}
function WPScrollLoadMoreByBatch(type){ api = $("#scrollable").data("scrollable"); pgnum = parseInt($("#tabpg").val(), 10) + 1; $.get('/winepicks/tabcontentmore.aspx?wdate=' + $("#wpbd").val() + '&pg=' + pgnum, function(data) { $("div.itempg_" + $("#tabpg").val()).remove(); api.addItem(data); $("#arrright").removeClass("disabled"); $("#tabpg").val(pgnum); WPScrollerSListVUpdate(); }); }
function WPMoreTabs(){$("#wptabs").html('<li><a href="/winepicks/tabcontent.aspx?type=bestvalueroses">Best Value Ros&eacute;s</a></li><li><a href="/winepicks/tabcontent.aspx?type=topratedroses">Top Rated Ros&eacute;s</a></li><li><a href="/winepicks/tabcontent.aspx?type=bestvaluebubblies">Best Value Bubblies</a></li><li><a href="/winepicks/tabcontent.aspx?type=topratedbubblies">Top Rated Bubblies</a></li><li><a href="/winepicks/archive.aspx" onclick="return false;">more...</a></li>'); $(".tabs").tabs("div.pane", { effect: 'ajax' }); var apitabs = $(".tabs").data("tabs"); apitabs.onClick(function(e, index) { $("#tabpg").val(0); }); apitabs.onBeforeClick(function(e, index) { $("#tabscroll").html(""); if (index == 4) { e.stopPropagation(); WPEvenMoreTabs(); return false; } }); }
function WPEvenMoreTabs(){$("#wptabs").html('<li><a href="/winepicks/tabcontent.aspx?type=bestvaluedesserts">Best Value Dessert</a></li><li><a href="/winepicks/tabcontent.aspx?type=toprateddesserts">Top Rated Dessert</a></li><li><a href="/winepicks/archive.aspx">more...</a></li>'); $(".tabs").tabs("div.pane", { effect: 'ajax' }); var apitabs = $(".tabs").data("tabs"); apitabs.onClick(function(e, index) { $("#tabpg").val(0); }); apitabs.onBeforeClick(function(e, index) { $("#tabscroll").html(""); if (index == 2) { e.stopPropagation(); WPResetTabs(); return false; } }); }
function WPResetTabs(){$("#wptabs").html('<li><a href="/winepicks/tabcontent.aspx?type=all">All Wines</a></li><li><a href="/winepicks/tabcontent.aspx?type=bestvaluereds" >Best Value Reds</a></li><li><a href="/winepicks/tabcontent.aspx?type=bestvaluewhites" >Best Value Whites</a></li><li><a href="/winepicks/tabcontent.aspx?type=topratedreds">Top Rated Reds</a></li><li><a href="/winepicks/tabcontent.aspx?type=topratedwhites">Top Rated Whites</a></li><li><a href="/winepicks/archive.aspx" onclick="return false;">more...</a></li>'); $(".tabs").tabs("div.pane", { effect: 'ajax' }); var apitabs = $(".tabs").data("tabs"); apitabs.onClick(function(e, index) { $("#tabpg").val(0); }); apitabs.onBeforeClick(function(e, index) { $("#tabscroll").html(""); if (index == 5) { e.stopPropagation(); WPMoreTabs(); /*location.href = "/winepicks/search.aspx";*/return false; } }) }
function WPScrollerSListVUpdate(){if (window.winesids == null) { return; }   $(winesids).each(function(index, val){if ($("#wpsl_" + val) != null){$("#wpsl_" + val).attr("src", "/images/winepicks/listing-icon-inshop.jpg");}});}
function WPScrollerATS(wid){$.getJSON(WinePicksUI.shoppingAjaxURL + "?adding=set&wid=" + escape(wid), function(data){if (data.added != null){winesids[winesids.length] = wid;$("#wpsl_" + wid).attr("src", "/images/winepicks/listing-icon-inshop.jpg");}});}
function FWPScrollLoadMore(type){api = $("#scrollable").data("scrollable");pgnum = parseInt($("#tabpg").val(), 10) + 1;$.get('/food/tabcontentmore.aspx?type=' + type + '&pg=' + pgnum, function(data) {$("div.itempg_" + $("#tabpg").val()).remove();api.addItem(data); $("#arrright").removeClass("disabled");$("#tabpg").val(pgnum);});}
function FWPMoreTabs(){$("#wptabs").html('<li><a href="/food/tabcontent.aspx?type=dazzlingdeal">Dazzling Deal</a></li><li><a href="/food/tabcontent.aspx?type=plushpork">Plush Pork</a></li><li><a href="/food/tabcontent.aspx?type=scrumptiousseafood">Scrumptious Seafood</a></li><li><a href="/food/tabcontent.aspx?type=splendidsalad">Splendid Salad</a></li><li><a href="/food/tabcontent.aspx?type=divinedessert">Divine Dessert</a></li><li><a href="/recipes/" onclick="return false;">more...</a></li>');$(".tabs").tabs("div.foodpane", { effect: 'ajax' });var apitabs = $(".tabs").data("tabs");apitabs.onClick(function(e, index) { $("#tabpg").val(0); });apitabs.onBeforeClick(function(e, index) { $("#tabscroll").html(""); if (index == 5) { e.stopPropagation(); FWPEvenMoreTabs(); return false; } });}
function FWPEvenMoreTabs() { $("#wptabs").html('<li><a href="/food/tabcontent.aspx?type=gorgeousgift">Gorgeous Gift</a></li><li><a href="/food/tabcontent.aspx?type=heavenlyhamburger">Heavenly Hamburger</a></li><li><a href="/food/tabcontent.aspx?type=lusciouslamb">Lamb</a></li><li><a href="/food/tabcontent.aspx?type=spectacularspicy">Spicy</a></li><li><a href="/food/tabcontent.aspx?type=outstandingorganic">Organic</a></li><li><a href="/food/tabcontent.aspx?type=terrificturkey">Turkey</a></li><li><a href="/food/tabcontent.aspx?type=voluptuousveal">Veal</a></li><li><a href="/recipes/" onclick="return false;">more...</a></li>'); $(".tabs").tabs("div.foodpane", { effect: 'ajax' }); var apitabs = $(".tabs").data("tabs"); apitabs.onClick(function (e, index) { $("#tabpg").val(0); }); apitabs.onBeforeClick(function (e, index) { $("#tabscroll").html(""); if (index == 6) { e.stopPropagation(); FWPResetTabs(); return false; } }); }
function FWPResetTabs(){$("#wptabs").html('<li><a href="/food/tabcontent.aspx?type=perfectpasta">Perfect Pasta</a></li><li><a href="/food/tabcontent.aspx?type=charmingchicken">Charming Chicken</a></li><li><a href="/food/tabcontent.aspx?type=captivatingcheese">Captivating Cheese</a></li><li><a href="/food/tabcontent.aspx?type=pizzapleaser">Pizza Pleaser</a></li><li><a href="/food/tabcontent.aspx?type=bestbeef">Best Beef</a></li><li><a href="/recipes/" onclick="return false;">more...</a></li>'); $(".tabs").tabs("div.foodpane", { effect: 'ajax' }); var apitabs = $(".tabs").data("tabs"); apitabs.onClick(function(e, index) { $("#tabpg").val(0); }); apitabs.onBeforeClick(function(e, index) { $("#tabscroll").html(""); if (index == 5) { e.stopPropagation(); FWPMoreTabs(); return false; } }) }

function UserWineListsHandler(wicon,wurl,wmode,wmsgadded,wmsgremoved)
{
    // logged out users have data-recid and data-title
    recid = parseInt($(wicon).attr("data-recid"), 10);
    if (recid > 0)
    {
        usermsg = 'Please <a href="/login/">login</a> to add this Wine to your ' + $(wicon).attr("data-title");
        if(document.getElementById("wmsg_" + recid) != null){$("#wmsg_" + recid).removeClass("text-success").addClass("text-warning").html(usermsg).show();}
        else if (document.getElementById("listmsgs") != null) {$("#listmsgs").removeClass("text-success").addClass("text-warning").html(usermsg).show();}
    }
    else
    {
        // logged in users have data-wineid
        wineid = parseInt($(wicon).attr("data-wineid"),10);
        if (wineid > 0) {
            $("#wmsg_" + wineid).html("").hide();
            $("#woptswait_" + wineid).show();
            $.post(wurl, { mode: wmode, wid: wineid }, function (data) {
                $("#woptswait_" + wineid).hide();
                if (data.error != null) { $("#wmsg_" + wineid).removeClass("text-success").addClass("text-warning").html(data.error).show(); }
                else if (data.removed != null) { $(wicon).removeClass('added'); $("#wmsg_" + wineid).removeClass("text-success").addClass("text-warning").html(wmsgremoved).show(); }
                else if (data.added != null) {
                    $(wicon).addClass('added');
                    // [201503 removed] // [201504 re-added]
                    wmsgadded += '<br /><a class="button-2 medium emailsharebutton" data-toggle="modal" data-target="#emailshare" onClick="UserWineShareButton(' + wineid + ');">Email this wine to a friend!&nbsp;&nbsp;<i class="fa fa-paper-plane"></i></a>';
                    $("#wmsg_" + wineid).removeClass("text-warning").addClass("text-success").html(wmsgadded).show();
                }
            }, "json");
        }
    }
}

function UserWineShareButton(wid) {
    if ($("#wurlfor_" + wid)) {
        $("#sharewine-message").val('');$("#sharewine-done").hide();$("#sharewine-wait").hide();
        $("#sharewine-sub").show();$("#sharewine-id").val(wid);
        wurl = "https://www.nataliemaclean.com/winepicks/";
        if (document.getElementById("wurlfor_" + wid) != null) { wurl = location.host + $("#wurlfor_" + wid).attr("href"); }
        else if (document.getElementById("actualurl") != null) { wurl = $("#actualurl").val();}
        $("#sharewine-url").val(wurl);
    }
}

function UtilGetURLParameters(name, searchinstring) {
    name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
    var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
    var results = regex.exec(searchinstring);
    return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
};

function WPVideoEmbed(id, vurl)
{
    $("#videopreview_" + id).html('').hide();
    if (vurl.length > 0) {
        lowvurl = vurl.toLowerCase();
        if (lowvurl.indexOf("youtube.com") > 0) {vidid = UtilGetURLParameters("v", vurl);$('#videopreview_' + id).show().prettyEmbed({ videoID: vidid, showRelated: false, useFitVids: true });}
        else if (lowvurl.indexOf("youtu.be") > 0) {vidid = vurl.substr(vurl.lastIndexOf("/") + 1);$('#videopreview_' + id).show().prettyEmbed({ videoID: vidid, showRelated: false, useFitVids: true });}
        else if (lowvurl.indexOf("vimeo.com") > 0) {$('#videopreview_' + id).show();vimoptions = { url: vurl};vimPlayer = new Vimeo.Player('videopreview_' + id, vimoptions);}
    }
}

$(function(){
    if(document.getElementById("sicemail")!=null){$("#sicsubmit").click(function(){location.href="/joinus/?e="+$("#sicemail").val();});}
    if(document.getElementById("fljusemail")!=null){$("#fljussubmit").click(function(){location.href="/joinus/?e="+$("#fljusemail").val();});}
    if(document.getElementById("ptmemail")!=null){$("#ptmsubmit").click(function(){location.href="/joinus/?e="+$("#ptmemail").val();});}
    if(document.getElementById("toswemail")!=null){$("#toswsubmit").click(function(){location.href="/joinus/?e="+$("#toswemail").val();});}
    if(document.getElementById("mipemail")!=null){$("#mipsubmit").click(function(){location.href="/joinus/?e="+$("#mipemail").val();});}

    // 2020-09
    //$("input#isstoresignupbtn").click(function () { if ($("#isstoresignup").val().length > 0) { $("#isstoreemail").val($("#isstoresignup").val()); $("#isstoresignupform").submit(); } });
    $("input#isstoresignupbtnv2").click(function () {if ($("#isstoresignupv2").val().length > 0) {location.href = "/join-us/?inf_field_Email=" + $("#isstoresignupv2").val();}});


    $(".icon-buyagain").click(function () { UserWineListsHandler(this, WinePicksUI.buyagainURL, "buyagain", 'Wine added to <a href="/winelists/buy-again/" target="_blank">Buy Again</a> list', 'Wine removed from <a href="/winelists/buy-again/" target="_blank">Buy Again</a> list'); });
    $(".icon-shoppinglist").click(function () { UserWineListsHandler(this, WinePicksUI.listsURL, "shopping", 'Wine added to <a href="/winelists/shopping-list/" target="_blank">Shopping List</a>', 'Wine removed from <a href="/winelists/shopping-list/" target="_blank">Shopping List</a>'); });
    $(".icon-wishlist").click(function () { UserWineListsHandler(this, WinePicksUI.listsURL, "wish", 'Wine added to <a href="/winelists/wish-list/" target="_blank">Wish List</a>', 'Wine removed from <a href="/winelists/wish-list/" target="_blank">Wish List</a>'); });
    $(".icon-userwinelist").click(function()
    {
        wineid = parseInt($(this).attr("data-wineid"),10);
        listid = parseInt($(this).attr("data-listid"),10);
        if(wineid > 0 && listid > 0)
        {
            $("#wmsg_"+wineid).html("").hide();$("#woptswait_"+wineid).show();wchkbox = $(this);
            $.post(WinePicksUI.listsURL,{mode:"userlist",wid:wineid,lid:listid},function(data){
                $("#woptswait_"+wineid).hide();
                if(data.error!=null){$("#wmsg_"+wineid).removeClass("text-success").addClass("text-warning").html(data.error).show();}
                else if(data.removed != null){wchkbox.checked=false;$("#wmsg_"+wineid).removeClass("text-success").addClass("text-warning").html("Wine removed from your List").show();}
                else if(data.added != null){wchkbox.checked = true;$("#wmsg_"+wineid).removeClass("text-warning").addClass("text-success").html("Wine added to your List").show();}
                /* check lists for this wine and if any are checked then update icon otherwise remove added */
                var n = $(wchkbox).closest('.icon-customlists');if(n!=null){if($(".lists_"+wineid+":checked").length > 0){n.addClass("added");}else{n.removeClass("added");}}
            },"json");
        }
    });
    $(".loggedout-iconaddceller").click(function ()
    {
        recid = parseInt($(this).attr("data-recid"), 10);
        if (recid > 0)
        {
            usermsg = 'Please <a href="/login/">login</a> to add this Wine to your ' + $(this).attr("data-title");
            if (document.getElementById("wmsg_" + recid) != null) { $("#wmsg_" + recid).removeClass("text-success").addClass("text-warning").html(usermsg).show(); }
            else if (document.getElementById("listmsgs") != null) { $("#listmsgs").removeClass("text-success").addClass("text-warning").html(usermsg).show(); }
        }
    });
    $(".loggedout-iconcustomlist").click(function ()
    {
        recid = parseInt($(this).attr("data-recid"), 10);
        if (recid > 0)
        {
            usermsg = 'Please <a href="/login/">login</a> to add this Wine to your ' + $(this).attr("data-title");
            if (document.getElementById("wmsg_" + recid) != null) { $("#wmsg_" + recid).removeClass("text-success").addClass("text-warning").html(usermsg).show(); }
            else if (document.getElementById("listmsgs") != null) { $("#listmsgs").removeClass("text-success").addClass("text-warning").html(usermsg).show(); }
        }
    });

    $("#sharewine-sub").click(function () {
        $("#sharewine-sub").hide();
        $("#sharewine-wait").show();

        wid = "" + $("#sharewine-id").val();if(wid.length == 0){alert("Sorry, unable to share this wine");return false;}
        toemail = "" + $("#sharewine-to-email").val();if (toemail.length == 0) {alert("Please enter your friend's email address"); $("#sharewine-to-email").focus();$("#sharewine-wait").hide();$("#sharewine-sub").show();return false;}
        msubject = "" + $("#sharewine-subject").val();if (msubject.length == 0) { alert("Please enter a subject for your email"); $("#sharewine-subject").focus(); $("#sharewine-wait").hide(); $("#sharewine-sub").show(); return false; }
        mmessage = "" + $("#sharewine-message").val();//if (mmessage.length == 0) { alert("Please enter a message for your friend"); $("#sharewine-message").focus(); $("#sharewine-wait").hide(); $("#sharewine-sub").show(); return false; }
        $.post("/winepicks/handler_share.aspx", { wid:$("#sharewine-id").val(), femail:toemail, esubject:msubject, emessage:mmessage}, function (data) {
            if (data.error != null){alert(data.error);$("#sharewine-sub").show();}
            else if (data.esent != null){$("#sharewine-done").show();}
            else { alert("Unable to process email"); $("#sharewine-sub").show(); }
            $("#sharewine-wait").hide();
        }, "json");
        return false;
    });

    $(".sharewine-donebtn").click(function () {$("#sharewine-done").hide();$("#sharewine-wait").hide();$("#sharewine-sub").show();$('#emailshare').modal('hide');return false;});

    $("#userbetaf").click(function () {
        $("#ubetadivwait").show();
        $.post("/users/beta.aspx", { "ubetareq": ndbetauhash }, function (data) {
            if (data.error != null) { alert(data.error);  $("#ubetadivwait").hide(); }
            else if (data.betaremoved != null){document.getElementById("userbetaf").checked = false;$("#ubetadivwait").hide();}
            else if (data.betaadded != null){document.getElementById("userbetaf").checked = true;$("#ubetadivwait").hide();}
        }, "json");
        return false;
    });

    $("#usromoptout").click(function () {
        $("#usromoptoutwait").show();
        $.post("/users/optinmonster.aspx", { "process": "set" }, function (data) {
            if (data.error != null) { alert(data.error); $("#usromoptoutwait").hide(); }
            else if (data.optremoved != null) { document.getElementById("usromoptout").checked = false; $("#usromoptoutwait").hide(); }
            else if (data.optadded != null) { document.getElementById("usromoptout").checked = true; $("#usromoptoutwait").hide(); }
        }, "json");
        return false;
    });

    $("#followuser").click(function () {
        $.post("/users/follow.aspx", {"fuid": $("#wfuid").val(), "followuserhash": $("#followuserhash").val() }, function(data){
            if (data.error != null) { alert(data.error);}
            else if (data.isfollowing != null) {$("#followuser").hide(); $("#unfollowuser").fadeIn();}
        }, "json");
        return false;
    });

    $("#unfollowuser").click(function () {
        $.post("/users/unfollow.aspx", { "fuid": $("#wfuid").val(),"followuserhash": $("#followuserhash").val() }, function (data) {
            if (data.error != null) { alert(data.error); }
            else if (data.notfollowing != null) { $("#unfollowuser").hide(); $("#followuser").fadeIn(); }
        }, "json");
        return false;
    });

});





