﻿
function show_generic(toshow, tocenter, toeffect) {

    var top = 0;
    var left = 0;
    switch (tocenter) {
        case "all":
            {
                left = $(document).scrollLeft() + ($(window).width() - $("#" + toshow).width()) / 2;
                top = $(document).scrollTop() + ($(window).height() - $("#" + toshow).height()) / 2;

                break
            }
        default:
            {
                var offset = $("#" + tocenter).offset();
                left = offset.left + ($("#" + tocenter).width() - $("#" + toshow).width()) / 2;
                top = offset.top + ($("#" + tocenter).height() - $("#" + toshow).height()) / 2;

                break
            }

    }

    $("#" + toshow).css("left", left);
    $("#" + toshow).css("top", top);

    
    switch (toeffect) {
        case "show":
            {
                $("#" + toshow).show();
                break
            }
        case "fadeIn":
            {
                $("#" + toshow).fadeIn("slow");
                break
            }
        case "slide":
            {
                $("#" + toshow).slideDown("slow");
                break
            }
        default:
            {
                $("#" + toshow).show();
                break
            }
    }
    
};


function hide_generic(tohide, toeffect) {

    
    switch (toeffect) {
        case "show":
            {
                $("#" + tohide).hide();
                break
            }
        case "fadeOut":
            {
                $("#" + tohide).fadeOut("slow");
                break
            }
        case "slide":
            {
                $("#" + tohide).slideUp("slow");
                break
            }
        default:
            {
                $("#" + tohide).hide();
                break
            }
    }    
    
};



function obscure(tooverlay, obscureby) {

    var altezza = 0;
    var larghezza = 0;
    var top = 0;
    var left = 0;

    switch (tooverlay) {
        case "all":
            {
                if ($(window).width() > $("body").width()) {
                    larghezza = $(window).width();
                } else {
                    larghezza = $("body").width();
                }

                if ($(window).height() > $("body").height()) {
                    altezza = $(window).height();
                } else {
                    altezza = $("body").height();
                }
                break
            }
        default:
            {

                larghezza = $("#" + tooverlay).width();
                altezza = $("#" + tooverlay).height();

                var offset = $("#" + tooverlay).offset();
                left = offset.left;
                top = offset.top;

                $("#" + obscureby).css("background-color", "#ffffff");

                break
            }

    }


    $("#" + obscureby).width(larghezza);
    $("#" + obscureby).height(altezza);

    $("#" + obscureby).css("left", left);
    $("#" + obscureby).css("top", top);

    $("#" + obscureby).css("opacity", .6);

    $("#" + obscureby).show();
};

function obscurenot(obscuredby) { $("#" + obscuredby).hide(); }


function showmodal(toshow, tooverlay, obscureby, toeffect) {
    if (tooverlay = "all") $(".zindexbug_tohide").hide();
    obscure(tooverlay, obscureby);
    show_generic(toshow, tooverlay, toeffect);
}

function hidemodal(tohide, obscuredby, toeffect) {
    hide_generic(tohide, toeffect);
    obscurenot(obscuredby);
    $(".zindexbug_tohide").show();
}

if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();


