﻿$(function() {
    AddCSS('/App_Themes/Common/jqueryui/ui.theme.css'); //National Theme does not have ui.theme.css. Wanted to be inside the click event but it did not work well in IE6 and 7.
    var savingsSelector = $("#dialog");
    var savingsProductRecommendationTool = new SavingsProductRecommendationTool();
    $(".OpenSavingsSelector").click(function() {
        if (jQuery.data(document.body, 'isSavingSelectorSetup') !== true) {
            var width = 760;
            if ($.browser.msie && /7.0/.test(navigator.userAgent)) {
                width = 770; //fix broken layout in IE7
            }
            savingsSelector.dialog({ width: width, modal: true, position: 'top', autoOpen: false,
                open: function() {
                    AddCSS('/_styles/savingselector.css');
                    AddCSS('/_styles/Print_PopUp.css');
                    $(this).parent().siblings("div.ui-widget-overlay").bgiframe();
                    $("#SavingsSelectorCloseButton").removeClass("hide").click(function() {
                        savingsSelector.dialog("close");
                    });
                    allLinksOpenNewWindow(savingsSelector);
                }, close: function() {
                    $("link[href$='savingselector.css']").remove();
                    $("link[href$='Print_PopUp.css']").remove();
                }
            });
            savingsProductRecommendationTool.Initialise();
            jQuery.data(document.body, 'isSavingSelectorSetup', true);
        }
        savingsSelector.dialog('open');
        savingsSelector.prev(".ui-dialog-titlebar").hide();
        savingsProductRecommendationTool.GetRecommendedProductsOnPageLoad();
    });
});

