﻿/// <reference path="Plugins/jquery-1.3.2-vsdoc.js" />

//change to your needs 
//please read the section defaults on each plugin of available customizations


//run MasterLoad on the whole page after document ready
$(document).ready(function () {
    jQuery.doLog = false;
    if (jQuery().Logger) $(document).Logger();

    //show a progress bar during each ajax request
    $("#loading").ajaxStart(function () {
        $("#loading").show();
    });
    $("#loading").ajaxStop(function () {
        $(this).hide();
    });

    // restore value
    $("#searchCategory").val("");
    $("#searchOnlyName").val("");

    //enable as you type search
    if (jQuery().AsYouTypeSearch) {
        $("#SearchTextBox").AsYouTypeSearch({ doPositioning: false, closeButton: "#AsYouTypeSearchResultCloseButton", closeOnBlur: false });
        $(".searchOnlyProductName").live("click", function () {
            $("#SearchTextBox").val($(this).data("name"));
            $("#searchOnlyName").val($(this).data("name"));
            $("#searchCategory").val("Product");
            $("#searchForm").submit();
        });
        $(".allProductPages").live("click", function () {
            $("#searchCategory").val("Product");
            $("#searchForm").submit();
        });
        $(".allInformationPages").live("click", function () {

            $("#searchCategory").val("InformationPage");
            $("#searchForm").submit();
        });

        $(".allSectionPages").live("click", function () {

            $("#searchCategory").val("SectionPage");
            $("#searchForm").submit();
        });

        //       if (($.browser.mozilla == true && $.browser.version <= "3.6"))
        //            CreatePopUp("#oldBrowserPopUp");

        if ($("#oldBrowserPopUp").length) {
            CreatePopUp("#oldBrowserPopUp");
        }
    }


    //        $("#top-menu").TopMenu(); TODO create top menu and left menu plugins if needed
    //        $("#SectionMenu").SectionMenu();

    $(".print").click(function () {
     
        window.print();
    });
    
   
});

function GetQueryStringValue(name) {
    var results = new RegExp('[?&]' + name + '=([^&#]*)').exec(window.location.href);
    if (!results) {
        return 0;
    }
    return results[1] || 0;
};

/// <summary>
/// This function runs on every load and after all ajax request made by AjaxLink plugin.
/// if you want to rebind events or other stuff after a ajax update on a specific div please create a function called dividLoad with arguments isAjax, context
/// </summary>
///<param name="isAjax">true if after a ajax request</param>
///<param name="context">parent jquery object so the function dont have to be evaluated on the whole document after a ajax update</param>
function MasterLoad(isAjaxRequest, context) {
    //PLEASE NOTE dont forger the ,context argument or the plugin will be created on the whole page after each ajax request
    if (!isAjaxRequest) {
        //code to execute on the specified div only the first time when no ajax
        //enable ajax on mini cartte
        $("#cartContainer", context).MiniCart({ onBuyEffect: function (element, ajaxLinkElement) {
            $("#cartContainer").fadeOut().fadeIn();

            var productId = $("input[name=productId]", ajaxLinkElement).value();

            var div = $("#confirmBuy_" + productId);
            if ($.browser.msie) {
                div.css("filter", "progid:DXImageTransform.Microsoft.gradient(startColorstr='#739500', endColorstr='#AEC16C');");
            }
            div.fadeIn(200, function () {

            });
            setTimeout(function () {



                div.fadeOut(2000);
            }, 1500);




        }
        });

    }
    //makes a form control able to post the form if it has one of this classes
    $(".submitOnChangeBehavior", context).bind("change", function () { if ($(this).data("oldValue") != $(this).val()) { $(this).data("oldValue", $(this).val()); $(this).submitParentForm(); } }).each(function () { $(this).data("oldValue", $(this).val()) });

    $(".submitOnClickBehavior", context).bind("click", function () { $(this).submitParentForm(); });

    if (jQuery().Hover) {
        $(".HoverBehavior", context).Hover();
    }

    //    if (jQuery().Hint) {
    //        $(".HintBehavior", context).Hint();
    //    }

    if (jQuery().AjaxLink) {
        $(".AjaxBehavior", context).AjaxLink();
    }

    //    if (jQuery().LazyLoad) {
    //        $(".LazyLoadBehavior", context).LazyLoad(); //this row must be after AjaxLink because of LazyLoad is dependent of AjaxLink
    //    }

    if (jQuery().MiniCart) {
        $("#cartContainer").MiniCart("registerBuyButttons", context); //collect all and new buy buttons
    }

    if (jQuery().MultiSubmitForm) {
        $("Form.MultiSubmit").MultiSubmitForm();
    }
}



function hidePagerIfOnePage(pageJson) {
    var pagers = pageJson.PageJSON("option", "pagers");
    if (pageJson.PageJSON("getNoOfPages") <= 1) {
        for (var i = 0; i < pagers.length; i++) {
            if (pagers[i] != "#pageSize") $(pagers[i]).hide();
        }
    }
    else {
        for (var i = 0; i < pagers.length; i++) {
            if (pagers[i] != "#pageSize") $(pagers[i]).show();
        }

    }

}

function RememberFilterForm(element) {
    $(element).RememberForm({ convertValueFromUrl: function (element, param, value) { if ((param == "pageSizeControl" || param == "pageControl") && value == "") { return element.val(); } else { return value; } } });
}


function CreatePopUp( divSelector) {
    if (jQuery().dialog) {
        $(divSelector).dialog({ modal: true });
        $(divSelector).dialog({ autoOpen: false });
        $(divSelector).dialog("width");
        $(divSelector).dialog('open');
        $(divSelector).dialog("option", "width", 560);
      
    }
    $("#close").live("click", function () {
        $(divSelector).dialog("close");
    });
}

