﻿//----------------------modal - window.js---------------------------------
var modalWindow = {
    parent: "body",
    windowId: null,
    content: null,
    width: null,
    height: null,
    type: null,
    divName: null,
    close: function(modalObj) {
        if (modalObj.type == 1)
            $(modalObj.divName).appendTo($(document.body)).hide();
        $(".modal-window").remove();
        $(".modal-overlay").remove();

    },
    open: function() {
        var modal = "";
        modal += "<div class=\"modal-overlay\"></div>";
        modal += "<div id=\"" + this.windowId + "\" class=\"modal-window\" style=\"width:" + this.width + "px; height:" + this.height + "px; margin-top:-" + (this.height / 2) + "px; margin-left:-" + (this.width / 2) + "px;\">";
        if (this.type == 0) {
            modal += this.content;
            modal += "</div>";
            $(this.parent).append(modal);
        }
        else {
            modal += "</div>";
            $(this.parent).append(modal);
            $(this.divName).appendTo($('#' + this.windowId)).show();
        }
        var modalObj = this;
        $(".modal-window").append("<a class=\"close-window\"></a>");
        $(".close-window").click(function() { modalWindow.close(modalObj); });
        $(".modal-overlay").click(function() { modalWindow.close(modalObj); });
    }
};


var openMyModal = function(source, type, Width, Height) {
    alert("call 1");
    modalWindow.type = type;
    modalWindow.windowId = "myModal";
    modalWindow.width = Width; //Width//480;
    modalWindow.height = Height; //Height//370;
    if (type == 0) {
        alert("call 2 , source = " + source);
        modalWindow.content = "<iframe width='370' height='480' frameborder='0' scrolling='no' allowtransparency='true' src='" + source + "'>&lt/iframe>";
    }
    else {
        alert("call 3");
        modalWindow.divName = source;
    }
    modalWindow.open();
};
//-------------------------------------------------------------------------------
