﻿$(document).ready(function() {
    $('ul.AspNet-Menu li:last a').css('background','none');
    $(".department_menu [id$=btnDepartment]").click(function() {
        DepartmentSelected(this.id);
    });

    $("[id$=btnTermsAndConditions]").click(function() {
        CheckBoxMustBeChecked_SetHiddenField(this.id);
    });
});


function pageLoad() {

    var siteUrlWithTheme = $("*[ID$='hfSiteUrlWithTheme']").val();

    MM_preloadImages(siteUrlWithTheme + "/images/tab_home_on.gif",
        siteUrlWithTheme + "/images/tab_shoponline_on.gif",
        siteUrlWithTheme + "/images/tab_rewardcard_on.gif",
        siteUrlWithTheme + "/images/icons/icon_go_on.png");
    
    // attach event handler for product listings, Choose Weight button.
    $("#productListingContainer A[id$=btnChooseWeight]").click(function() {

        var inBasket = false;

        if ($("#" + this.id).attr("class") == "updateweight") {
            inBasket = true;
        }

        chooseWeightFromProductListing(this.id, inBasket);
    });

    $("#productListingContainer A[id$=btnChooseWeight]").css("cursor", "pointer");
    
    
    
    // attach event handler for product listings, Add button.
    $("#productListingContainer A[id$=btnAddToBasket]").click(function() {

        // ----- Referential event handlers -----

        if ($("#" + this.id).attr("class") == "update") {
            inBasket = true;
        }

        var pid = getProductIDFromListingRow(this.id);
        addItemToBasket(pid);
    });

    $("#productListingContainer A[id$=btnAddToBasket]").css("cursor", "pointer");

    

    // hook up the event for the favourite button on the Product listing.
    $("#productListingContainer A[id$=btnFavourites]").click(function() {

        var isFavourite = false;

        if ($("#" + this.id).attr("class") == "favourite active") {
            isFavourite = true;
        }      
        if(typeof(IE6Fixes) == 'function'){
            if(isFavourite){                
                $(this).attr('style','background:url(../App_Themes/SuperQuinn_en/Images/buttons/icon_favourite.png) no-repeat');
            }
            else{
                $(this).removeAttr('class');
                $(this).addClass('favourite active');
                $(this).attr('style','background:url(../App_Themes/SuperQuinn_en/Images/buttons/icon_favourite_on.png) no-repeat');
            }           
        }

        AddRemoveFavouriteFromProductListing(this.id);
    });

    $("#productListingContainer A[id$=btnFavourites]").css("cursor", "pointer");




    // ----- Referential event handlers -----

    $(".product_referential A[class$=add], .product_referential_wrap A[class$=add]").click(function(event) {
        addEachItemFromReferential(this.id);
    });

    $(".product_referential A[class$=add], .product_referential_wrap A[class$=add]").css("cursor", "pointer");
    
    
    
    
    $(".product_referential A[class$=updateweight], .product_referential A[class$=selectweight], .product_referential_wrap A[class$=updateweight]," +
    " .product_referential_wrap A[class$=selectweight]").click(function(event) {
        var inBasket = false;

        if ($("#" + this.id).attr("class") == "updateweight") {
            inBasket = true;
        }

        chooseWeightFromReferential(this.id, inBasket);
    });

    $(".product_referential A[class$=updateweight], .product_referential A[class$=selectweight], .product_referential_wrap A[class$=updateweight]," +
    " .product_referential_wrap A[class$=selectweight]").css("cursor", "pointer");
    
    

    
    // contains 'override for btn click event handler'
    if (typeof AttachFavouritesEventHandlers == 'function') {
        AttachFavouritesEventHandlers();
    }

    if (typeof AttachCardTypeEventHandlers == 'function') {
        AttachCardTypeEventHandlers();
    }

    // attaches click event handlers to chooseWeight buttons in the basket listings control.
    if (typeof AddBasketListingEventHandlers == 'function') {
        AddBasketListingEventHandlers();
    }
    //LoadDepartments();
    categoryHover();
    
    if (typeof(pngfix) == 'function')
        pngfix();
    if (typeof(IE6Fixes) == 'function')
        IE6Fixes();

    
    
    
    //turn the cursor to a wait symbol when an update is proccessing
     var prm = Sys.WebForms.PageRequestManager.getInstance();
        prm.add_initializeRequest(InitializeRequest);
        prm.add_endRequest(EndRequest);

        
// end page load
}




function InitializeRequest(sender, args) {
    document.body.style.cursor = 'wait';
    //postBackElement = args.get_postBackElement();
   
    
    //postBackElement.disabled = true;

}

function EndRequest(sender, args) {
    document.body.style.cursor = 'auto';
    //postBackElement = args.get_postBackElement();

}


$("select").change(function() {
    var str = "";
    $("select option:selected").each(function() {
        str += $(this).text() + " ";
    });
    $("div").text(str);
})
        .change();
