sfHover = function () {
    $('.hmenu li').each(function () {
        $(this).mouseover(function () {
            $(this).addClass('sfhover');
        });
        $(this).mouseout(function () {
            $(this).removeClass('sfhover');
        });
    });
};
if (window.attachEvent) window.attachEvent("onload", sfHover);

// Max length for TextAreas
// THIS NEEDS TO BE BEFORE THE DOCUMENT READY.
jQuery.fn.limitMaxlength = function (options) {

    var settings = jQuery.extend({
        attribute: "maxlengthcustom",
        onLimit: function () { },
        onEdit: function () { }
    }, options);

    // Event handler to limit the textarea
    var onEdit = function () {
        var textarea = jQuery(this);
        var maxlength = parseInt(textarea.attr(settings.attribute), 10);

        if (textarea.val().length > maxlength) {
            textarea.val(textarea.val().substr(0, maxlength));

            // Call the onlimit handler within the scope of the textarea
            jQuery.proxy(settings.onLimit, this)();
        }

        // Call the onEdit handler within the scope of the textarea
        jQuery.proxy(settings.onEdit, this)(maxlength - textarea.val().length);
    };

    this.each(onEdit);

    return this.keyup(onEdit)
        .keydown(onEdit)
        .focus(onEdit);
};
// End Max length for TextAreas

$(document).ready(function () {

    var addthis_config = {
        ui_cobrand: "Wine Selectors",
        ui_header_color: "#ffffff",
        ui_header_background: "#822433"
    };

    if ($('.hmenu').length) {
        $('li.selected').parentsUntil('menu11').addClass('selected');
    }


    if ($('a.lightbox').length) {
        $('a.lightbox').lightBox();
    }

    if ($('a.preview').length) {
        $("a.preview").preview({
            xOffset: 80,
            yOffset: 10,
            border: 2,
            borderOpacity: 60
        });
    }

    $(".BestSellerItemsItem > a.festiveWrapping").click(function () {
        $(this).fadeOut(1000)
               .prev(".FestiveContents")
                  .fadeIn(1000);
    });

    if ($('input[placeholder]').placeholder != null) {
        $('input[placeholder]').placeholder();
    }

    $('h1.img').each(function () {
        string = $(this).text();
        filename = string.toLowerCase().replace(/ /g, '-').replace(/([^0-9a-z-])/g, '');
        $(this).html('<img src="/images/headings/' + filename + '.png" alt="' + string + '" />');
    });
    $('h2.img').each(function () {
        string = $(this).text();
        filename = string.toLowerCase().replace(/ /g, '-').replace(/([^0-9a-z-])/g, '');
        $(this).html('<img src="/images/headings/' + filename + '.png" alt="' + string + '" />');
    });
    //personaliseLogin();
    hideCartMessage();
    var article = self.document.location.hash.substring(8);
    var number = wordToNumber(article);
    showArticle(number); setupSearch();
    if ($('#tabbedContentWrapperRHSide').length) {
        memberOnlyBanner();
    }
    if ($('#buyWineRotatorWrapper').length) {
        rotatingTabSelect();
    }
    if ($('#cellarRotatorWrapper').length) {
        cellarTabSelect();
    }
    if ($('.regularDeliveriesPlans').length) {
        var tabSelect = getUrlEncodedKey("tab");
        $("#nav-tab-" + tabSelect).addClass("ui-tabs-selected");
        $("#tabbedContent").tabs();
    }

    if ($('.innerfadeAutoStart').length) {
        $('.innerfadeAutoStart').innerfade({
            speed: 150,
            timeout: 12000,
            type: 'random',
            containerheight: '170px'
        });
    }

    homePageTabSelect();

    // Max length for TextAreas
    var onEditCallback = function (remaining) {

        if (remaining > 0) {
            $(this).css('background-color', 'white');
            $(this).siblings('.overflowWarning').text("");
        }
    };

    var onLimitCallback = function () {
        $(this).css('background-color', 'red');
        var maxLength = $(this).attr('maxlengthcustom');
        var myLength = $(this).val().length;
        $(this).siblings('.overflowWarning').text("You have exceeded the maximum length of " + maxLength + ' characters. The comment has been truncated so please check it before saving.');
    };

    if ($('textarea[maxlengthcustom]').length) {
        $('textarea[maxlengthcustom]').limitMaxlength({
            onEdit: onEditCallback,
            onLimit: onLimitCallback
        });
    }
    // End Max length for TextAreas

    $('.aeLblPackSize').each(function () {
        if ($(this).text() == '1 bottles') {
            $(this).text('         ');
        }
    });

});

function CallPageMethod(pageName, methodName, onSuccess, onFail) {
    var data = new Object();
    if ($('input[name*="hdnProductID"]').length) {
        data["txtReview"] = $('[name*="NewReviewDescription"]').val();
        data["txtRating"] = $('input[name*="lstNewReviewRating"]:checked').val();
        data["productID"] = $('input[name*="hdnProductID"]').val();
        data["txtAnonName"] = '';
        var anonName = $('[name*="AnonName"]');
        if (anonName != null) {
            data["txtAnonName"] = anonName.val();
        }
    }
    else {
        data["txtReview"] = $('#NewReviewDescription').val();
        data["txtRating"] = $('select#lstNewReviewRating').val();
        data["productID"] = $('#hdnProductID').val();
        data["txtAnonName"] = '';
    }
    $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        url: "/" + pageName + "/" + methodName,
        data: Sys.Serialization.JavaScriptSerializer.serialize(data),
        dataType: "json",
        success: onSuccess,
        fail: onFail
    });
}

function OnSucceeded(response) { alert(response.d); $("#dialog-form").dialog('close'); }
function OnFailed(response) { alert(response.get_message()); }
function setupSearch() { if ($("#aeProductSelector").length) { var red = $('.ddlRed'); var white = $('.ddlWhite'); var sparkling = $('.ddlSparkling'); var fortified = $('.ddlFortified'); var mixed = $('.ddlMixed'); $(".VarietyDDL").parent().append(red, white, sparkling, fortified, mixed); $(".VarietyDDL").addClass("active"); $(".TypeDDL").change(function () { switch ($(".TypeDDL").val()) { case '4': red.show(); $(".active").hide(); $(".active").removeClass("active"); red.addClass("active"); break; case '5': white.show(); $(".active").hide(); $(".active").removeClass("active"); white.addClass("active"); break; case '41': sparkling.show(); $(".active").hide(); $(".active").removeClass("active"); sparkling.addClass("active"); break; case '39': fortified.show(); $(".active").hide(); $(".active").removeClass("active"); fortified.addClass("active"); break; case '6': mixed.show(); $(".active").hide(); $(".active").removeClass("active"); mixed.addClass("active"); break; default: $(".VarietyDDL").show(); $(".active").hide(); $(".active").removeClass("active"); $(".VarietyDDL").addClass("active"); break; } }); } }
function hideCartMessage() { setTimeout(function () { this.fadeoutCartDiv(); }, 3000); }
function fadeoutCartDiv() { $("div.CartMessage").fadeOut(2000, function () { }); }
function showArticle(ArticleNumber) { if ($('#article_' + ArticleNumber).is(":hidden")) { $('#article_' + ArticleNumber).slideDown('normal'); } else { $('#article_' + ArticleNumber).hide(); } }
function wordToNumber(word) {
    var number = 0; switch (word) { case 'One': number = 1; break; case 'Two': number = 2; break; case 'Three': number = 3; break; case 'Four': number = 4; break; case 'Five': number = 5; break; case 'Six': number = 6; break; case 'Seven': number = 7; break; case 'Eight': number = 8; break; case 'Nine': number = 9; break; case 'Ten': number = 10; break; case 'Eleven': number = 11; break; case 'Twelve': number = 12; break; default: ''; break; }
    return number;
}
function MM_findObj(n, d) {
    var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) { d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p); }
    if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n]; for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document); if (!x && d.getElementById) x = d.getElementById(n); return x;
}
if (document.getElementById('aeFpFindOutMore')) { document.getElementById('aeFpFindOutMore').innerHTML = "."; }
if (document.getElementById('TDForMiddleCell')) { document.getElementById('TDForMiddleCell').style.backgroundColor = "transparent"; }
if (MM_findObj('youruniqueid')) { bannerSrcStart = 'Images/UserUploadedImages/11/image_prefix'; bannerSrcEnd = '.jpg'; maxRandomNumber = 18; randomNumber = Math.floor(Math.random() * maxRandomNumber) + 1; bannerSrc = bannerSrcStart + randomNumber + bannerSrcEnd; MM_findObj('youruniqueid').innerHTML = '<img border=0 src=' + bannerSrc + '>'; }
function biggerFont() {
    if (!document.getElementById)
        return; if (!document.getElementsByTagName)
        return; var heading1 = document.getElementsByTagName("h1"); var heading2 = document.getElementsByTagName("h2"); var heading3 = document.getElementsByTagName("h3"); var heading4 = document.getElementsByTagName("h4"); var heading5 = document.getElementsByTagName("h5"); var heading6 = document.getElementsByTagName("h6"); var heading7 = document.getElementsByTagName("body"); for (var a = 0; a < heading1.length; a++) { heading1[a].style.fontSize = "22px"; }
    for (var e = 0; e < heading2.length; e++) { heading2[e].style.fontSize = "20px"; }
    for (var e = 0; e < heading3.length; e++) { heading3[e].style.fontSize = "19px"; }
    for (var e = 0; e < heading4.length; e++) { heading4[e].style.fontSize = "18px"; }
    for (var e = 0; e < heading5.length; e++) { heading5[e].style.fontSize = "18px"; }
    for (var e = 0; e < heading6.length; e++) { heading6[e].style.fontSize = "17px"; }
    for (var e = 0; e < heading7.length; e++) { heading7[e].style.fontSize = "17px"; }
    if (document.getElementById("tblContentTD1")) {
        contentText = document.getElementById("tblContentTD1"); contentText.style.fontSize = "14px"; var cellHeadText = contentText.getElementsByTagName("th"); var cellText = contentText.getElementsByTagName("td"); var paraText = contentText.getElementsByTagName("p"); var anchorText = contentText.getElementsByTagName("a"); for (var x = 0; x < cellHeadText.length; x++) { cellHeadText[x].style.fontSize = "14px"; }
        for (var x = 0; x < cellText.length; x++) { cellText[x].style.fontSize = "14px"; }
        for (var x = 0; x < paraText.length; x++) { paraText[x].style.fontSize = "14px"; }
        for (var x = 0; x < anchorText.length; x++) {
            if (anchorText[x].className == "clsAltNormalOneSmaller") { anchorText[x].style.fontSize = "14px"; }
            else { anchorText[x].style.fontSize = "14px"; }
        }
    }
    var rightText = document.getElementsByTagName("p"); for (var e = 0; e < rightText.length; e++) { if (rightText[e].className == "actionBox") { rightText[e].style.fontSize = "13px"; var anchorText = rightText[e].getElementsByTagName("a"); for (var x = 0; x < anchorText.length; x++) { anchorText[x].style.fontSize = "13px"; } } }
    if (!document.getElementById("tblContentTD1")) {
        var normal = document.getElementsByTagName("td"); for (var e = 0; e < normal.length; e++) { if (normal[e].className == "clsNormal") { normal[e].style.fontSize = "14px"; } }
        var altNormal = document.getElementsByTagName("a"); for (var e = 0; e < altNormal.length; e++) {
            if (altNormal[e].className == "clsNormal") { altNormal[e].style.fontSize = "14px"; }
            else if (altNormal[e].className == "clsAltNormal") { altNormal[e].style.fontSize = "14px"; }
            else if (altNormal[e].className == "clsMidHeader") { altNormal[e].style.fontSize = "25px"; }
        }
    }
}
function normalFont() {
    if (!document.getElementById)
        return; if (!document.getElementsByTagName)
        return; var heading1 = document.getElementsByTagName("h1"); var heading2 = document.getElementsByTagName("h2"); var heading3 = document.getElementsByTagName("h3"); var heading4 = document.getElementsByTagName("h4"); var heading5 = document.getElementsByTagName("h5"); var heading6 = document.getElementsByTagName("h6"); for (var a = 0; a < heading1.length; a++) { heading1[a].style.fontSize = "17px"; }
    for (var e = 0; e < heading2.length; e++) { heading2[e].style.fontSize = "15px"; }
    for (var e = 0; e < heading3.length; e++) { heading3[e].style.fontSize = "14px"; }
    for (var e = 0; e < heading4.length; e++) { heading4[e].style.fontSize = "13px"; }
    for (var e = 0; e < heading5.length; e++) { heading5[e].style.fontSize = "13px"; }
    for (var e = 0; e < heading6.length; e++) { heading6[e].style.fontSize = "12px"; }
    if (document.getElementById("tblContentTD1")) {
        contentText = document.getElementById("tblContentTD1"); contentText.style.fontSize = "12px"; var cellHeadText = contentText.getElementsByTagName("th"); var cellText = contentText.getElementsByTagName("td"); var paraText = contentText.getElementsByTagName("p"); var anchorText = contentText.getElementsByTagName("a"); for (var x = 0; x < cellHeadText.length; x++) { cellHeadText[x].style.fontSize = "12px"; }
        for (var x = 0; x < cellText.length; x++) { cellText[x].style.fontSize = "12px"; }
        for (var x = 0; x < paraText.length; x++) { paraText[x].style.fontSize = "12px"; }
        for (var x = 0; x < anchorText.length; x++) {
            if (anchorText[x].className == "clsAltNormalOneSmaller") { anchorText[x].style.fontSize = "11px"; }
            else { anchorText[x].style.fontSize = "12px"; }
        }
    }
    var rightText = document.getElementsByTagName("p"); for (var e = 0; e < rightText.length; e++) { if (rightText[e].className == "actionBox") { rightText[e].style.fontSize = "11px"; var anchorText = rightText[e].getElementsByTagName("a"); for (var x = 0; x < anchorText.length; x++) { anchorText[x].style.fontSize = "11px"; } } }
    if (!document.getElementById("tblContentTD1")) {
        var normal = document.getElementsByTagName("td"); for (var e = 0; e < normal.length; e++) { if (normal[e].className == "clsNormal") { normal[e].style.fontSize = "12px"; } }
        var altNormal = document.getElementsByTagName("a"); for (var e = 0; e < altNormal.length; e++) {
            if (altNormal[e].className == "clsNormal") { altNormal[e].style.fontSize = "12px"; }
            else if (altNormal[e].className == "clsAltNormal") { altNormal[e].style.fontSize = "12px"; }
            else if (altNormal[e].className == "clsMidHeader") { altNormal[e].style.fontSize = "17px"; }
        }
    }
}
function WSAddToCartNoRedirect(productId, qtyTextboxName, campaign, radioButtonGroupName, selectedTabIndex, subcategory) {
    var choiceid;
    var errorMsg = '';
    var qty = 1;
    if (qtyTextboxName != '') {
        qty = $('input[name$=' + qtyTextboxName + ']').val();
        if (qty == '') {
            errorMsg = 'Please enter a quantity';
        }
        else if (IsNumber(qty) == false) {
            errorMsg = 'Please enter a valid quantity';
        }
    }
    if (errorMsg == '') {
        if (radioButtonGroupName == '') {
            choiceid = '0';
            errorMsg = '';
        }
        else {
            if (IsButtonGroupSelected($('input[name*=' + radioButtonGroupName + ']')) == true) {
                choiceid = getSelectedButtonValue($('input[name*=' + radioButtonGroupName + ']'));
                errorMsg = '';
            }
            else {
                if ($('#' + radioButtonGroupName + ' input:radio:checked')) {
                    choiceid = $('#' + radioButtonGroupName + ' input:radio:checked').val();
                    errorMsg = '';
                }
                else {
                    errorMsg = 'Please make a selection before attempting to add to your cart.';
                }
            }
        }
    }
    if (subcategory === undefined) {
        subcategory = -1;
    }
    if (errorMsg == '') {
        var oldUrl = location.href;
        if (oldUrl.toLowerCase().endsWith("shop.aspx")) {
            oldUrl = "/shop/eProduct.aspx?ProductID=" + productId;
        }
        var newUrl = '/CustomRedirects/AddToCartRedirect.aspx?product=' + productId + '&choiceId=' + choiceid + '&qty=' + qty + '&campaign=' + campaign + '&subcategory=' + subcategory + "&tab=" + selectedTabIndex + "&redirect=" + escape(oldUrl); location.href = newUrl;
    }
    else { alert(errorMsg); }
}
String.prototype.endsWith = function (str) { return (this.match(str + "$") == str); };
function getQuerystringParameterByName(name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]"); var regexS = "[\\?&]" + name + "=([^&#]*)"; var regex = new RegExp(regexS, "i"); var results = regex.exec(window.location.href); if (results == null)
        return ""; else
        return results[1];
}
function biggerFont() {
    if (!document.getElementById)
        return; if (!document.getElementsByTagName)
        return; var heading1 = document.getElementsByTagName("h1"); var heading2 = document.getElementsByTagName("h2"); var heading3 = document.getElementsByTagName("h3"); var heading4 = document.getElementsByTagName("h4"); var heading5 = document.getElementsByTagName("h5"); var heading6 = document.getElementsByTagName("h6"); var heading7 = document.getElementsByTagName("p"); for (var a = 0; a < heading1.length; a++) { heading1[a].style.fontSize = "25px"; }
    for (var a = 0; a < heading2.length; a++) { heading2[a].style.fontSize = "23px"; }
    for (var a = 0; a < heading3.length; a++) { heading3[a].style.fontSize = "20px"; }
    for (var a = 0; a < heading4.length; a++) { heading4[a].style.fontSize = "17px"; }
    for (var a = 0; a < heading5.length; a++) { heading5[a].style.fontSize = "17px"; }
    for (var a = 0; a < heading6.length; a++) { heading6[a].style.fontSize = "17px"; }
    for (var a = 0; a < heading7.length; a++) { heading7[a].style.fontSize = "17px"; }
    var contentText = document.getElementsByTagName("table");
    for (var e = 0; e < contentText.length; e++) {
        if (contentText[e].className == "content") {
            contentText[e].style.fontSize = "13px"; var cellText = contentText[e].getElementsByTagName("td"); var paraText = contentText[e].getElementsByTagName("p"); var anchorText = contentText[e].getElementsByTagName("a"); for (var x = 0; x < cellText.length; x++) { cellText[x].style.fontSize = "15px"; }
            for (var x = 0; x < paraText.length; x++) { paraText[x].style.fontSize = "15px"; }
            for (var x = 0; x < anchorText.length; x++) { anchorText[x].style.fontSize = "15px"; }
        }
    }
    var puggleText = document.getElementsByTagName("table");
    for (var e = 0; e < puggleText.length; e++) {
        if (puggleText[e].className == "puggleinfo") {
            puggleText[e].style.fontSize = "13px"; var cellText = puggleText[e].getElementsByTagName("td"); var headText = puggleText[e].getElementsByTagName("th"); var paraText = puggleText[e].getElementsByTagName("p"); var anchorText = puggleText[e].getElementsByTagName("a"); for (var x = 0; x < cellText.length; x++) { cellText[x].style.fontSize = "15px"; }
            for (var x = 0; x < headText.length; x++) { headText[x].style.fontSize = "15px"; }
            for (var x = 0; x < paraText.length; x++) { paraText[x].style.fontSize = "15px"; }
            for (var x = 0; x < anchorText.length; x++) { anchorText[x].style.fontSize = "15px"; }
        }
    }
    var basicText = document.getElementsByTagName("table");
    for (var e = 0; e < basicText.length; e++) {
        if (basicText[e].className == "basictable") {
            basicText[e].style.fontSize = "15px"; var cellText = basicText[e].getElementsByTagName("td"); var paraText = basicText[e].getElementsByTagName("p"); var anchorText = basicText[e].getElementsByTagName("a"); for (var x = 0; x < cellText.length; x++) { cellText[x].style.fontSize = "15px"; }
            for (var x = 0; x < paraText.length; x++) { paraText[x].style.fontSize = "15px"; }
            for (var x = 0; x < anchorText.length; x++) { anchorText[x].style.fontSize = "15px"; }
        }
    }
    var linksText = document.getElementsByTagName("table");
    for (var e = 0; e < linksText.length; e++) {
        if (linksText[e].className == "linkstable") {
            linksText[e].style.fontSize = "13px"; var cellText = linksText[e].getElementsByTagName("td"); var paraText = linksText[e].getElementsByTagName("p"); var anchorText = linksText[e].getElementsByTagName("a"); for (var x = 0; x < cellText.length; x++) { cellText[x].style.fontSize = "15px"; }
            for (var x = 0; x < paraText.length; x++) { paraText[x].style.fontSize = "15px"; }
            for (var x = 0; x < anchorText.length; x++) { anchorText[x].style.fontSize = "15px"; }
        }
    }
    var linksText2 = document.getElementsByTagName("table");
    for (var e = 0; e < linksText2.length; e++) {
        if (linksText2[e].className == "linkstablenoarrow") {
            linksText2[e].style.fontSize = "15px"; var cellText = linksText2[e].getElementsByTagName("td"); var paraText = linksText2[e].getElementsByTagName("p"); var anchorText = linksText2[e].getElementsByTagName("a"); for (var x = 0; x < cellText.length; x++) { cellText[x].style.fontSize = "15px"; }
            for (var x = 0; x < paraText.length; x++) { paraText[x].style.fontSize = "15px"; }
            for (var x = 0; x < anchorText.length; x++) { anchorText[x].style.fontSize = "15px"; }
        }
    }
    var tables = document.getElementsByTagName("table"); if (tables.length == 0)
        return; for (var b = 0; b < tables.length; b++) {
        if (tables[b].className == "panelcontenttop") {
            tables[b].style.fontSize = "11px"; var paneltopText = tables[b].getElementsByTagName("td"); var paneltopText2 = tables[b].getElementsByTagName("p"); var paneltopText3 = tables[b].getElementsByTagName("a"); for (var x = 0; x < paneltopText.length; x++) { paneltopText[x].style.fontSize = "13px"; }
            for (var x = 0; x < paneltopText2.length; x++) { paneltopText2[x].style.fontSize = "13px"; }
            for (var x = 0; x < paneltopText3.length; x++) { paneltopText3[x].style.fontSize = "13px"; }
            var paneltoph1 = tables[b].getElementsByTagName("h1"); var paneltoph2 = tables[b].getElementsByTagName("h2"); var paneltoph3 = tables[b].getElementsByTagName("h3"); var paneltoph4 = tables[b].getElementsByTagName("h4"); var paneltoph5 = tables[b].getElementsByTagName("h5"); var paneltoph6 = tables[b].getElementsByTagName("h6"); for (var c = 0; c < paneltoph1.length; c++) { paneltoph1[c].style.fontSize = "15px"; }
            for (var c = 0; c < paneltoph2.length; c++) { paneltoph2[c].style.fontSize = "13px"; }
            for (var c = 0; c < paneltoph3.length; c++) { paneltoph3[c].style.fontSize = "11px"; }
            for (var c = 0; c < paneltoph4.length; c++) { paneltoph4[c].style.fontSize = "11px"; }
            for (var c = 0; c < paneltoph5.length; c++) { paneltoph5[c].style.fontSize = "11px"; }
            for (var c = 0; c < paneltoph6.length; c++) { paneltoph6[c].style.fontSize = "11px"; }
        }
        else if (tables[b].className == "panelcontent") {
            tables[b].style.fontSize = "11px"; var paneltopText = tables[b].getElementsByTagName("td"); var paneltopText2 = tables[b].getElementsByTagName("p"); var paneltopText3 = tables[b].getElementsByTagName("a"); for (var x = 0; x < paneltopText.length; x++) { paneltopText[x].style.fontSize = "11px"; }
            for (var x = 0; x < paneltopText2.length; x++) { paneltopText2[x].style.fontSize = "11px"; }
            for (var x = 0; x < paneltopText3.length; x++) { paneltopText3[x].style.fontSize = "11px"; }
            var panelh1 = tables[b].getElementsByTagName("h1"); var panelh2 = tables[b].getElementsByTagName("h2"); var panelh3 = tables[b].getElementsByTagName("h3"); var panelh4 = tables[b].getElementsByTagName("h4"); var panelh5 = tables[b].getElementsByTagName("h5"); var panelh6 = tables[b].getElementsByTagName("h6"); for (var d = 0; d < panelh1.length; d++) { panelh1[d].style.fontSize = "25px"; }
            for (var d = 0; d < panelh2.length; d++) { panelh2[d].style.fontSize = "23px"; }
            for (var d = 0; d < panelh3.length; d++) { panelh3[d].style.fontSize = "20px"; }
            for (var d = 0; d < panelh4.length; d++) { panelh4[d].style.fontSize = "17px"; }
            for (var d = 0; d < panelh5.length; d++) { panelh5[d].style.fontSize = "17px"; }
            for (var d = 0; d < panelh6.length; d++) { panelh6[d].style.fontSize = "17px"; }
        }
    }
    SetCookie('fontsize', 'big', 30, '/', '', '');
}
function normalFont() {
    if (!document.getElementById)
        return; if (!document.getElementsByTagName)
        return; var heading1 = document.getElementsByTagName("h1"); var heading2 = document.getElementsByTagName("h2"); var heading3 = document.getElementsByTagName("h3"); var heading4 = document.getElementsByTagName("h4"); var heading5 = document.getElementsByTagName("h5"); var heading6 = document.getElementsByTagName("h6"); var contentText = document.getElementsByTagName("table");
    for (var a = 0; a < heading1.length; a++) { heading1[a].style.fontSize = "17px"; }
    for (var a = 0; a < heading2.length; a++) { heading2[a].style.fontSize = "15px"; }
    for (var a = 0; a < heading3.length; a++) { heading3[a].style.fontSize = "13px"; }
    for (var a = 0; a < heading4.length; a++) { heading4[a].style.fontSize = "11px"; }
    for (var a = 0; a < heading5.length; a++) { heading5[a].style.fontSize = "11px"; }
    for (var a = 0; a < heading6.length; a++) { heading6[a].style.fontSize = "11px"; }
    for (var e = 0; e < contentText.length; e++) {
        if (contentText[e].className == "content") {
            contentText[e].style.fontSize = "11px"; var cellText = contentText[e].getElementsByTagName("td"); var paraText = contentText[e].getElementsByTagName("p"); var anchorText = contentText[e].getElementsByTagName("a"); for (var x = 0; x < cellText.length; x++) { cellText[x].style.fontSize = "11px"; }
            for (var x = 0; x < paraText.length; x++) { paraText[x].style.fontSize = "11px"; }
            for (var x = 0; x < anchorText.length; x++) { anchorText[x].style.fontSize = "11px"; }
        }
    }
    var puggleText = document.getElementsByTagName("table");
    for (var e = 0; e < puggleText.length; e++) {
        if (puggleText[e].className == "puggleinfo") {
            puggleText[e].style.fontSize = "11px"; var cellText = puggleText[e].getElementsByTagName("td"); var headText = puggleText[e].getElementsByTagName("th"); var paraText = puggleText[e].getElementsByTagName("p"); var anchorText = puggleText[e].getElementsByTagName("a"); for (var x = 0; x < cellText.length; x++) { cellText[x].style.fontSize = "11px"; }
            for (var x = 0; x < headText.length; x++) { headText[x].style.fontSize = "11px"; }
            for (var x = 0; x < paraText.length; x++) { paraText[x].style.fontSize = "11px"; }
            for (var x = 0; x < anchorText.length; x++) { anchorText[x].style.fontSize = "11px"; }
        }
    }
    var basicText = document.getElementsByTagName("table");
    for (var e = 0; e < basicText.length; e++) {
        if (basicText[e].className == "basictable") {
            basicText[e].style.fontSize = "11px"; var cellText = basicText[e].getElementsByTagName("td"); var paraText = basicText[e].getElementsByTagName("p"); var anchorText = basicText[e].getElementsByTagName("a"); for (var x = 0; x < cellText.length; x++) { cellText[x].style.fontSize = "11px"; }
            for (var x = 0; x < paraText.length; x++) { paraText[x].style.fontSize = "11px"; }
            for (var x = 0; x < anchorText.length; x++) { anchorText[x].style.fontSize = "11px"; }
        }
    }
    var linksText = document.getElementsByTagName("table");
    for (var e = 0; e < linksText.length; e++) {
        if (linksText[e].className == "linkstable") {
            linksText[e].style.fontSize = "11px"; var cellText = linksText[e].getElementsByTagName("td"); var paraText = linksText[e].getElementsByTagName("p"); var anchorText = linksText[e].getElementsByTagName("a"); for (var x = 0; x < cellText.length; x++) { cellText[x].style.fontSize = "11px"; }
            for (var x = 0; x < paraText.length; x++) { paraText[x].style.fontSize = "11px"; }
            for (var x = 0; x < anchorText.length; x++) { anchorText[x].style.fontSize = "11px"; }
        }
    }
    var linksText2 = document.getElementsByTagName("table");
    for (var e = 0; e < linksText2.length; e++) {
        if (linksText2[e].className == "linkstablenoarrow") {
            linksText2[e].style.fontSize = "11px"; var cellText = linksText2[e].getElementsByTagName("td"); var paraText = linksText2[e].getElementsByTagName("p"); var anchorText = linksText2[e].getElementsByTagName("a"); for (var x = 0; x < cellText.length; x++) { cellText[x].style.fontSize = "11px"; }
            for (var x = 0; x < paraText.length; x++) { paraText[x].style.fontSize = "11px"; }
            for (var x = 0; x < anchorText.length; x++) { anchorText[x].style.fontSize = "11px"; }
        }
    }
    var tables = document.getElementsByTagName("table"); if (tables.length == 0)
        return; for (var b = 0; b < tables.length; b++) {
        if (tables[b].className == "panelcontenttop") {
            tables[b].style.fontSize = "9px"; var paneltopText = tables[b].getElementsByTagName("td"); var paneltopText2 = tables[b].getElementsByTagName("p"); var paneltopText3 = tables[b].getElementsByTagName("a"); for (var x = 0; x < paneltopText.length; x++) { paneltopText[x].style.fontSize = "9px"; }
            for (var x = 0; x < paneltopText2.length; x++) { paneltopText2[x].style.fontSize = "9px"; }
            for (var x = 0; x < paneltopText3.length; x++) { paneltopText3[x].style.fontSize = "9px"; }
            tables[b].style.fontSize = "9px"; var paneltoph1 = tables[b].getElementsByTagName("h1"); var paneltoph2 = tables[b].getElementsByTagName("h2"); var paneltoph3 = tables[b].getElementsByTagName("h3"); var paneltoph4 = tables[b].getElementsByTagName("h4"); var paneltoph5 = tables[b].getElementsByTagName("h5"); var paneltoph6 = tables[b].getElementsByTagName("h6"); for (var c = 0; c < paneltoph1.length; c++) { paneltoph1[c].style.fontSize = "13px"; }
            for (var c = 0; c < paneltoph2.length; c++) { paneltoph2[c].style.fontSize = "11px"; }
            for (var c = 0; c < paneltoph3.length; c++) { paneltoph3[c].style.fontSize = "9px"; }
            for (var c = 0; c < paneltoph4.length; c++) { paneltoph4[c].style.fontSize = "9px"; }
            for (var c = 0; c < paneltoph5.length; c++) { paneltoph5[c].style.fontSize = "9px"; }
            for (var c = 0; c < paneltoph6.length; c++) { paneltoph6[c].style.fontSize = "9px"; }
        }
        else if (tables[b].className == "panelcontent") {
            tables[b].style.fontSize = "9px"; var paneltopText = tables[b].getElementsByTagName("td"); var paneltopText2 = tables[b].getElementsByTagName("p"); var paneltopText3 = tables[b].getElementsByTagName("a"); for (var x = 0; x < paneltopText.length; x++) { paneltopText[x].style.fontSize = "9px"; }
            for (var x = 0; x < paneltopText2.length; x++) { paneltopText2[x].style.fontSize = "9px"; }
            for (var x = 0; x < paneltopText3.length; x++) { paneltopText3[x].style.fontSize = "9px"; }
            var panelh1 = tables[b].getElementsByTagName("h1"); var panelh2 = tables[b].getElementsByTagName("h2"); var panelh3 = tables[b].getElementsByTagName("h3"); var panelh4 = tables[b].getElementsByTagName("h4"); var panelh5 = tables[b].getElementsByTagName("h5"); var panelh6 = tables[b].getElementsByTagName("h6"); for (var d = 0; d < panelh1.length; d++) { panelh1[d].style.fontSize = "13px"; }
            for (var d = 0; d < panelh2.length; d++) { panelh2[d].style.fontSize = "11px"; }
            for (var d = 0; d < panelh3.length; d++) { panelh3[d].style.fontSize = "9px"; }
            for (var d = 0; d < panelh4.length; d++) { panelh4[d].style.fontSize = "9px"; }
            for (var d = 0; d < panelh5.length; d++) { panelh5[d].style.fontSize = "9px"; }
            for (var d = 0; d < panelh6.length; d++) { panelh6[d].style.fontSize = "9px"; }
        }
    }
    SetCookie('fontsize', 'normal', 30, '/', '', '');
}
//function personaliseLogin() 
//{
//    var ctlUserName = "*[id$='Personalisation1_HiddenFieldUserName']";
//    if ($(ctlUserName).length > 0) 
//    {
//        var userName = "" + $(ctlUserName).val();
//        if (userName != "") 
//        {
//            $("#loginBox").html("Welcome back, <b>" + $(ctlUserName).val() + "</b>&nbsp;&nbsp;<a href='https://www.wineselectors.com.au/WineSelectorsMemberDetails.aspx?FolderID=91'>My Account&nbsp;&gt;&gt;</a>&nbsp;&nbsp;<a href='/Logout.aspx'>Logout</a>");
//        }
//    } 
//}
function memberOnlyBanner() { $("#tabbedContentRHSide").tabs({ fx: { opacity: "toggle"} }).tabs("rotate", 3000, false); var ctlUserName = "*[id$='Personalisation1_HiddenFieldUserName']"; }
function personaliseCompetition(competitionDivName, competitionReminderDivName, campaignCode) {
    var prefsSet = false; var enteredComp = false; var ctlPrefsSet = "*[id$='Personalisation1_HiddenFieldWebPreferencesSet']"; var ctlComps = "*[id$='Personalisation1_HiddenFieldCompetitions']"; if ($(ctlPrefsSet).length > 0) { var prefsSetString = "" + $(ctlPrefsSet).val(); prefsSet = (prefsSetString == "True"); }
    if ($(ctlComps).length > 0) { var compsString = "" + $(ctlComps).val(); compsString = compsString.toLowerCase(); var lowerCampaign = campaignCode.toString().toLowerCase(); if (compsString == lowerCampaign || compsString.indexOf(lowerCampaign + ",") == 0 || compsString.indexOf("," + lowerCampaign + ",") >= 0 || compsString.endsWith("," + lowerCampaign)) { enteredComp = true; } }
    if (!prefsSet || enteredComp) { $("#" + competitionDivName).attr("style", "display:none;visibility:hidden;"); }
    if (!enteredComp && !prefsSet) { $("#" + competitionReminderDivName).attr("style", ""); }
    else { $("#" + competitionReminderDivName).attr("style", "display:none;visibility:hidden;"); }
}
function getVisitCount() {
    var visitCount = 0; var ctlPersonalisationVisitCount = "*[id$='Personalisation1_HiddenFieldVisitCount']"; if ($(ctlPersonalisationVisitCount).length > 0) { visitCount = $(ctlPersonalisationVisitCount).val(); }
    return visitCount;
}
function getWineTypePreference() {
    var wineType = ""; var ctlPersonalisationWineType = "*[id$='Personalisation1_HiddenFieldWineType']"; if ($(ctlPersonalisationWineType).length > 0) { wineType = $(ctlPersonalisationWineType).val(); }
    return wineType;
}
function homepageMiddleSwapImage() { var visitCount = getVisitCount(); if (visitCount > 2) { $("#homepageCampaignLeft").hide(); $("#homepageCampaignLeft_RepeatVisitor").attr("style", "display:block;"); } }
function homePageTabSelect() {
    if ($('#homepageRotator').length)
    {
        $('#homepageRotator').tabs({ fx: { opacity: 'toggle'} });
        var visitCount = getVisitCount();
        if (visitCount < 2) {
            $("#homepageRotator").tabs('select', 1);
        }
    }
}
function buyWinePageTabSelect() {
    $("#buyWineRotator").tabs({ fx: { opacity: "toggle"} }).tabs("rotate", 0, false); var wineType = getWineTypePreference(); if (wineType.toLowerCase() == "red")
        $("#buyWineRotator").tabs('select', 0); else if (wineType.toLowerCase() == "white")
        $("#buyWineRotator").tabs('select', 1);
}
function rotatingTabSelect() { $("#buyWineRotator").tabs({ fx: { opacity: "toggle"} }).tabs("rotate", 4000, false); }
function cellarTabSelect() { $("#cellarRotator").tabs({ fx: { opacity: "toggle"} }).tabs("rotate", 4000, false); }
function campaignsTabSelect() { $("#campaignsRotator").tabs({ fx: { opacity: "toggle"} }).tabs("rotate", 4000, false); }
function updateProductWidget(prodID, priceTotal, price, usp, imageUrl, prodName) {
    var priceTotalField = $('#' + prodID + "_Price_total");
    var priceField = $('#' + prodID + "_Price");
    var imageField = $('#' + prodID + "_ImgBottle");
    var uspField = $('[name*=' + prodID + "_LblDescr");
    var nameField = $('[name*=' + prodID + "_LblName");
    if (priceTotalField) {
        priceTotalField.text(priceTotal);
    }
    if (priceField) {
        priceField.html(price);
    }
    if (imageField) {
        imageField.attr('src', "/shop/" + imageUrl);
    }
    if (uspField) {
        uspField.html(usp);
    }
    if (nameField) {
        nameField.html(prodName);
    }
}
function updateProduct(choiceID, productID) {
    //PageMethods.LookupProduct(productID, onSuccess);
    PageMethodProduct("Methods.aspx", "LookupProduct", onSuccess3, onError3, productID);
}

function PageMethodProduct(pageName, methodName, onSuccess, onFail, productID) {
    $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        url: "/" + pageName + "/" + methodName,
        data: "{'productID':'" + productID + "'}",
        dataType: "json",
        success: onSuccess,
        fail: onFail
    });
}

function onSuccess3(result) {
    var imageField = $("#ProductImage img");
    var longUSP = $(".lblDescription");
    var productName = $(".lblName");
    if (imageField) {
        imageField.attr('src', "/shop/" + result.d.ImageFileMedium);
    }
    if (longUSP) {
        longUSP.html(result.d.LongDescription);
    }
    if (productName) {
        productName.text(result.d.ProductName);
    }
}
function onError3(response) {
    alert(response.get_message());
}

var carousel_productList = [];

function product_id_for_index(index) {
    return carousel_productList[index - 1];
}

function carousel_itemVisibleInCallbackBeforeAnimation(carousel, item, index, state) {
    if (carousel.has(index)) {
        return;
    }

    if (index > carousel.length) {
        return;
    }

    var product_id = product_id_for_index(index);
    
    $.ajax({ type: "POST",
        contentType: "application/json; charset=utf-8",
        url: "/Methods.aspx/LookupProductHTML",
        data: Sys.Serialization.JavaScriptSerializer.serialize({ productID: product_id }),
        dataType: "json",
        success: function (data) { carousel_itemAddCallback(carousel, index, data); }
    });
}

function carousel_itemAddCallback(carousel, index, data) {
    carousel.add(index, data.d);
    var item = $('.jcarousel-item-' + index + ' img.aeImgBottle');
    if (item.attr('width') > 52) {
        item.addClass('shrink');
    }
}

function carousel_LoadListCallback(data) {
    carousel_productList = data.d.split(", ");
    $('#carousel').jcarousel({
        scroll: 1,
        size: carousel_productList.length,
        itemVisibleInCallback: {onBeforeAnimation: carousel_itemVisibleInCallbackBeforeAnimation}
    });
    $('.jcarousel-container .jcarousel-clip').addClass('aeSimpleCartProductWidget');
    
}

function carousel_load() {
    $.ajax({type: "POST",
            contentType: "application/json; charset=utf-8",
            url: "/Methods.aspx/LookupBestSellerProductIDs",
            data: Sys.Serialization.JavaScriptSerializer.serialize({}),
            dataType: "json",
            success: carousel_LoadListCallback
    });
}

function showHideRefine(selectedTabIndex) {
    if (selectedTabIndex == 0) { $("#ctl00_ContentPlaceHolderMainNoAjax_TDLeftArticle1").attr("style", ""); $("#ctl00_ContentPlaceHolderMainNoAjax_TDLeftArticle2").attr("style", "display:none;visibility:hidden;"); $("#ctl00_ContentPlaceHolderMainNoAjax_TDLeftArticle3").attr("style", "display:none;visibility:hidden;"); }
    else if (selectedTabIndex == 1) { $("#ctl00_ContentPlaceHolderMainNoAjax_TDLeftArticle1").attr("style", "display:none;visibility:hidden;"); $("#ctl00_ContentPlaceHolderMainNoAjax_TDLeftArticle2").attr("style", ""); $("#ctl00_ContentPlaceHolderMainNoAjax_TDLeftArticle3").attr("style", "display:none;visibility:hidden;"); }
    else if (selectedTabIndex == 2) { $("#ctl00_ContentPlaceHolderMainNoAjax_TDLeftArticle1").attr("style", "display:none;visibility:hidden;"); $("#ctl00_ContentPlaceHolderMainNoAjax_TDLeftArticle2").attr("style", "display:none;visibility:hidden;"); $("#ctl00_ContentPlaceHolderMainNoAjax_TDLeftArticle3").attr("style", ""); }
    else { $("#ctl00_ContentPlaceHolderMainNoAjax_TDLeftArticle1").attr("style", "display:none;visibility:hidden;"); $("#ctl00_ContentPlaceHolderMainNoAjax_TDLeftArticle2").attr("style", "display:none;visibility:hidden;"); $("#ctl00_ContentPlaceHolderMainNoAjax_TDLeftArticle3").attr("style", "display:none;visibility:hidden;"); }
}
function GetCount(controlName) { var count = 0; var ctl = "*[id$='" + controlName + "']"; count = $(ctl).val(); return count; }
function SelectMixed() { var straightCount = GetCount("straightCount"); var mixedCount = GetCount("mixedCount"); var limitedCount = GetCount("limitedCount"); return straightCount == 0 && mixedCount > 0 && limitedCount == 0; }
function SelectLimited() { var straightCount = GetCount("straightCount"); var mixedCount = GetCount("mixedCount"); var limitedCount = GetCount("limitedCount"); return straightCount == 0 && mixedCount == 0 && limitedCount > 0; }
function GoBack() { history.back(1); }
function Login() { $('#ctl00_hdnReturnURL').val(location.href); window.location = '/Login.aspx'; }

/* WINE TYPE TABS */
$(document).ready(function () {
    if ($('.wineTypeTabs').length) {
        var productWidgets = $('.aeFullProductWidget');
        var mixed = null;
        var white = null;
        var red = null;
        var rose = null;
        productWidgets.each(function () {
            var heading = $(this).first().children('h2.img');
            var productType = heading.children('IMG').attr('alt');
            if (productType) {
                if (productType.toLowerCase() == 'mixed') {
                    mixed = $(this);
                }
                else if (productType.toLowerCase() == 'reds') {
                    red = $(this);
                }
                else if (productType.toLowerCase() == 'whites') {
                    white = $(this);
                }
                else if (productType.toLowerCase() == 'rose') {
                    rose = $(this);
                }
            }
        }
    );

        if (document.location.href.indexOf('edit.aspx') == -1) {
            if (mixed != null) { $('#tab-1 .tabContent').append(mixed); }
            if (white != null) { $('#tab-2 .tabContent').append(white); }
            if (red != null) { $('#tab-3 .tabContent').append(red); }
            if (rose != null) { $('#tab-4 .tabContent').append(rose); }

            if ($('.wineTypeTabs').length) {
                var tabSelect = getUrlEncodedKey("tab");
                if (tabSelect == '' || tabSelect == null) {
                    $("#nav-tab-1").addClass("ui-tabs-selected");
                }
                else {
                    $("#nav-tab-" + tabSelect).addClass("ui-tabs-selected");
                }
                $("#tabbedContent").tabs();
            }
        }
        productWidgets.show();
    }
});
/* END WINE TYPE TABS */

// Start postcode search
function AddPostcodeSearch(elem, isInitialising) {
    if (elem.length) {
        var suburb = elem.find('.suburb');
        var postcode = elem.find('.postcode');
        var state = elem.find('.state');
        if ((elem.attr('class').indexOf('postcodeSearch') < 0) && suburb.length && postcode.length && state.length) {
            elem.addClass('postcodeSearch');
            if (((isInitialising == null) || isInitialising) && (elem.attr('initialising') == null)) {
                elem.attr('initialising', '1');
            }
            suburb.hide();
            suburb.parent().prepend('<select class="' + suburb.attr('class') + ' suburbSelector"></select>');
            var suburbSelector = elem.find('.suburbSelector');
            suburbSelector.removeClass('suburb');
            suburbSelector.change(function () {
                var elem = $(this);
                var parent = elem.parents('.postcodeSearch');
                var suburb = parent.find('.suburb');
                var state = parent.find('.state');
                if (elem.val()) {
                    suburb.val(elem.val());
                    var newState = elem.children('option:selected').attr('stateCode');
                    for (var i = 0; i < state.children('option').length; i++) {
                        if ($(state.children('option')[i]).text() == newState) {
                            state.val($(state.children('option')[i]).val());
                        }
                    }
                }
            });
            postcode.keyup(function () {
                var elem = $(this);
                var parent = elem.parents('.postcodeSearch');
                var suburbSelector = parent.find('.suburbSelector');
                var suburb = parent.find('.suburb');
                suburbSelector.hide();
                if (elem.val().length == 4) {
                    if (suburbSelector.attr('lastSearched') == elem.val()) {
                        if ($('option', suburbSelector).length) {
                            ShowSuburbSelector(parent, suburbSelector);
                        }
                    }
                    else {
                        LookupPostcode(elem.val(), elem.attr('id'));
                        suburbSelector.attr('lastSearched', elem.val());
                        var options = suburbSelector.attr('options');
                        if (!(suburb.parent().find('.pleaseWait').length)) {
                            $('option', suburbSelector).remove();
                            suburb.parent().prepend('<div class="pleaseWait"><p>Please wait...</p></div>');
                            parent.find('.pleaseEnter').fadeOut().parent().find('.pleaseWait').fadeIn();
                            parent.find('.pleaseEnter').remove();
                        }
                    }
                }
                else {
                    parent.find('.pleaseWait').remove();
                    if (!(suburb.parent().find('.pleaseEnter').length)) {
                        suburb.parent().prepend('<div class="pleaseEnter"><p>Enter a full postcode above</p></div>');
                        parent.find('.pleaseEnter').fadeIn();
                    }
                    suburbSelector.attr('lastSearched', null);
                }
            });
            postcode.keyup();
        }
    }
}

function RemovePostcodeSearch(elem) {
    var suburb = elem.find('.suburb');
    var postcode = elem.find('.postcode');
    var state = elem.find('.state');
    if ((elem.attr('class').indexOf('postcodeSearch') >= 0) && suburb.length && postcode.length && state.length) {
        var suburbSelector = elem.find('.suburbSelector');
        suburbSelector.remove();
        suburb.show();
        elem.find('.pleaseWait').remove();
        elem.find('.pleaseEnter').remove();
        elem.removeClass('postcodeSearch');
    }
}

function CallPageMethodGeneric(data, pageName, methodName, onSuccess, onFail) {
    $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        url: "/" + pageName + "/" + methodName,
        data: Sys.Serialization.JavaScriptSerializer.serialize(data),
        dataType: "json",
        success: onSuccess,
        fail: onFail
    });
}

function LookupPostcode(postcode, uniqueID) {
    var data = new Object();
    data['strPostCode'] = postcode;
    data['strUniqueID'] = uniqueID;
    CallPageMethodGeneric(data, 'Methods.aspx', 'LookupSuburbByPostcode',
        LookupPostcodeOnSuccess,
        LookupPostcodeOnFail);
}

function LookupPostcodeOnSuccess(response) {
    var elem = $('#' + response.d.UniqueID);
    if (elem.length) {
        var parent = elem.parents('.postcodeSearch');
        var suburbSelector = parent.find('.suburbSelector');
        var suburb = parent.find('.suburb');
        var newOptions = response.d.Response;
        var selectedOption = suburb.val();
        var state = parent.find('.state');
        var selectedState = state.children('option:selected').text();
        var options = suburbSelector.attr('options');
        $('option', suburbSelector).remove();

        var hasOldOption = false;
        if (response.d.Response.length) {
            options[options.length] = new Option('(select)', '');
            for (var i = 0; i < response.d.Response.length; i++) {
                var suburbName = response.d.Response[i].Name;
                var stateCode = response.d.Response[i].State;
                if (suburbName.toLowerCase() == selectedOption.toLowerCase()) {
                    hasOldOption = true;
                    selectedOption = suburbName;
                }
                options[options.length] = new Option(suburbName, suburbName);
                $(options[options.length - 1]).attr('stateCode', stateCode);
            }
        }
        else {
            options[options.length] = new Option('(no results)', '');
        }
        if (selectedOption && hasOldOption) {
            suburbSelector.val(selectedOption);
        }
        else if (selectedOption && (parent.attr('initialising') == '1')) {
            options[options.length] = new Option(selectedOption, selectedOption);
            suburbSelector.val(selectedOption);
        }
        else {
            if (options.length < 2) {
                suburbSelector.val(options[0].value);
            }
        }
        ShowSuburbSelector(parent, suburbSelector);
        parent.attr('initialising', '0');
    }
}

function ShowSuburbSelector(parent, suburbSelector) {
    parent.find('.pleaseWait').remove();
    parent.find('.pleaseEnter').remove();
    suburbSelector.change();
    suburbSelector.show();
}

function LookupPostcodeOnFail(response) {
    parent.find('.pleaseWait').html(response.get_message());
    parent.find('.pleaseEnter').html(response.get_message());
}
// End postcode search

// Handle Product Search

function HandleProductSearch(evt) {
    //NB: Note added by tracey on 3rd April 2006. Please note that this function is duplicated in the common.js
    //file. Any change you make to this function must also be made in that file.
    if (evt.keyCode == 13) {
        productsearch()
        if (!document.all && document.getElementById) {
            evt.preventDefault();
            evt.stopPropagation();
        }
        evt.cancelBubble = true;
        evt.returnValue = false;
        return false;
    }
}

function productsearch() {
    alert("in search");
    var startTax = '';
    var strKeywords = '';
    var strSiteURL = '';

    var aeProductSelector;
    aeProductSelector = document.getElementById('aeProductSelector');

    var inputControls = aeProductSelector.getElementsByTagName('input')
    var inputControl;

    if (inputControls.length > 0) {
        for (var i = 0; i < inputControls.length; i++) {
            inputControl = inputControls[i];

            if (inputControl.name.indexOf("txtWineSearchKeywords") != -1) {
                strKeywords = inputControl.value;
                strSiteURL = '/productsearchresults.aspx?';
            }
            else if (inputControl.name.indexOf("hiddenSimpleSearchSiteURL") != -1) {
                strSiteURL = inputControl.value + '/productsearchresults.aspx?';
            }
        }
    }

//    var selectFilters = aeProductSelector.getElementsByTagName('select');
//    var selectFilter;
//    if (selectFilters.length > 0) {
//        //alert("in select");
//        for (var i = 0; i < selectFilters.length; i++) {
//            selectFilter = selectFilters[i];
//            if (selectFilter[selectFilter.selectedIndex].value != 'none') {
//                startTax = startTax + ',' + selectFilter[selectFilter.selectedIndex].value;
//                //alert(startTax);
//            }
//        }
//    }

    if (strKeywords == 'Keywords') { strKeywords = ''; }
    if (startTax.substring(1).length > 0) {
        //alert(strSiteURL + 'Keywords=' + strKeywords + '&StartTax=' + startTax.substring(1));
        window.location.href = strSiteURL + 'Keywords=' + strKeywords + '&StartTax=' + startTax.substring(1);
    }
    else {
        if (strKeywords == '')
            alert('please enter any keywords or select any search criteria');
        else
            window.location.href = strSiteURL + 'Keywords=' + strKeywords;
    }
}   

// End Product Search

