﻿var fModal = {
    Init: function (modalId, show)
    {
        //Agrego el blackout si no existe.
        if (document.getElementById('ModalBlackout') == null)
        {
            var modalBlackout = document.createElement("div");
            modalBlackout.id = "ModalBlackout";
            document.body.appendChild(modalBlackout);
        }

        if (show)
            fModal.Abrir(modalId);
        else
            fModal.Cerrar(modalId);
    },

    Cerrar: function (modalId)
    {
        document.getElementById('ModalBlackout').style.visibility = 'hidden';
        document.getElementById(modalId).style.visibility = 'hidden';
        document.body.scroll = "yes";
        document.body.style.overflow = "";
        if (window.lastScroll != undefined)
            window.scrollTo(0, window.lastScroll);
    },

    Abrir: function (modalId)
    {
        document.getElementById('ModalBlackout').style.visibility = 'visible';
        document.getElementById(modalId).style.visibility = 'visible';
        document.body.scroll = "no";
        document.body.style.overflow = "hidden";
        window.lastScroll = (document.all ? document.scrollTop : window.pageYOffset);
        window.scrollTo(0, 0);
    }
};
