﻿/* Custom jQuery functions
-------------------------------------------------------------------------------- */

jQuery.fn.center = function() {
    this.css("position", "fixed");
    this.css("top", ($(window).height() - this.height()) / 2 + "px");
    this.css("left", ($(window).width() - this.width()) / 2 + "px");
    return this;
}
jQuery.fn.fill = function() {
    this.css("position", "fixed");
    this.css("top", "0px");
    this.css("left", "0px");
    this.css("height", $(window).height() + "px");
    this.css("width", $(window).width() + "px");
    return this;
}

/* Functions
-------------------------------------------------------------------------------- */

function ShowModalPopup(ModalPopup, ModalBackground) {
    $(ModalBackground).delay(300).fill().fadeTo(250, 0.5,
        function() {
            $(ModalPopup).center().show();
            $(window).resize(
                function() {
                    $(ModalBackground).fill();
                    $(ModalPopup).center();
                }
            );
        });
}
function HideModalPopup(ModalPopup, ModalBackground) {
    $(ModalBackground).stop().css('display', 'none');
    $(ModalPopup).stop().css('display', 'none');
    $(window).unbind('resize');
}

function ClickButton(ButtonId) {
    if (window.event.keyCode == 13) {
        $('#' + ButtonId).click();
    }
}

/* Requires jquery.scrollTo-1.4.2-min.js */
function ScrollToElement(jQueryElement) {
    $.scrollTo(jQueryElement, 1000);
}

//function ShowModalPopup(ModalPopup) {
//    $(ModalPopup).center().show();
//    $(window).resize(function() {
//        $(ModalPopup).center();
//    });
//}
//function HideModalPopup(ModalPopup) {
//    $(ModalPopup).stop().css('display', 'none');
//    $(window).unbind('resize');
//}

//function HideControl(ControlId) {
//    $('#' + ControlId).slideUp("normal");
//}

//function ToggleControl(ControlId, State) {
//    if ($('#' + ControlId).css("display") == "none") {
//        if (State == true) {
//            $('#' + ControlId).slideDown("normal");
//        }
//    }
//    else if (State == false) {
//        $('#' + ControlId).slideUp("normal");
//    }
//}

//function ToggleInputs(ContainerId, State) {
//    var ContainerInputs = $('#' + ContainerId + ' input');
//    for (var i = 0; i < ContainerInputs.length; i++) {
//        ContainerInputs[i].checked = State;
//    }
//}

//function ShowLoading() {
//    var loadingbackground = $('#LoadingBackground');
//    var loadingpanel = $('#LoadingPanel');
//    var loadingpanel_header = $('#LoadingPanel_Header');
//    if (loadingpanel == null || loadingbackground == null) { return; }

//    loadingbackground.delay(300).fill().fadeTo(500, 0.6, function() {
//        loadingpanel.center().show(); /*.fadeTo(500, 1);*/
//        loadingpanel_header.show();
//    });
//}

//function HideLoading() {
//    $('#LoadingBackground').stop().css('display', 'none');
//    $('#LoadingPanel').stop().css('display', 'none');
//    $('#LoadingPanel_Header').stop().css('display', 'none');
//}

//function pageLoad() {
//    HideLoading();
//}

//var req = Sys.WebForms.PageRequestManager.getInstance();
//req.add_beginRequest(ShowLoading);
//req.add_endRequest(HideLoading);
