﻿if (typeof SaveAPic == 'undefined') var SaveAPic = {};
SaveAPic.PopUp = SaveAPic.PopUp || {};

SaveAPic.PopUp.ShowV2 = function (header, content, buttons, focusElement, enterFunc) {
    if ((header != null) && (header != "")) $("#PopTempHeader").html(header);
    $("#PopUpContent").html(content);

    if (buttons != null && buttons != "") {
        $("#PopTempButtons").html(buttons);
        $("#PopTempButtons").show();
    }
    else $("#PopTempButtons").hide();

    //Set the height to the full height
    $("#PopUpOverlay").css("height", $(document).height());

    $("#PopUpBody").center();
    $("#PopUpOverlay").fadeIn('medium');
    $("#PopUpBody").fadeIn('medium', function () {
        if (focusElement != null) {
            $(focusElement).trigger("focus");

            if (enterFunc != null) {
                $(focusElement).bind('keyup', function (e) {
                    if (e.keyCode == 13) { enterFunc(); }
                });
            }
        } else {
            $("#PopUpBody Input").focus();
        }

        $("#PopUpBody").keyup(function (e) {
            if (e.keyCode == 27) { SaveAPic.PopUp.Hide(); }   // esc
        });
    });
}

SaveAPic.PopUp.Hide = function (func) {
    $("#PopUpOverlay").fadeOut('fast');
    $(".popUpBody").fadeOut('fast', function () {
        if (func != null) func();
    });
}

SaveAPic.PopUp.ShowWait = function (content) {
    $("#AjaxLoadingOverlay").css("height", $(document).height());  
    $("#AjaxLoadingOverlay").fadeIn('medium');
    
    if (content != null) output = content;
    else output = "Loading";
    $("#AjaxLoading .loadingContent").html(output);
    $("#AjaxLoading").center();
    $("#AjaxLoading").fadeIn('medium');
}

SaveAPic.PopUp.HideWait = function () {
    $("#AjaxLoadingOverlay").hide();
    $("#AjaxLoading").hide();
}
