﻿/// <summary>
/// 用层实现类模态窗口
/// </summary>
var ModalDialog = function()
{  
}
ModalDialog.prototype = 
{
    /// <summary>
    /// 创建窗口
    /// </summary>
    create : function(url, width, height)
    {
        //定义变量
        var scrollWidth = Math.max(document.body.scrollWidth,document.documentElement.scrollWidth);
        //var scrollHeight = Math.max(document.body.scrollHeight,document.documentElement.scrollHeight);
           var scrollHeight=window.screen.height-150;
        var form = document.getElementById("aspnetForm") == null ? document.getElementById("form1") : document.getElementById("aspnetForm");
    
        //创建遮罩层
        var mask = document.createElement("div");
        mask.id = "mask";
        mask.style.position = "absolute";
        mask.style.zIndex = "1";
        mask.style.width = scrollWidth + "px";
       // mask.style.width = 20 + "px";
        mask.style.height = scrollHeight + "px";
        mask.style.top = "0px";
        mask.style.left = "0px";
        mask.style.background = "#33393C";
        mask.style.filter = "alpha(opacity=20)";
        mask.style.opacity = "0.20";
        form.appendChild(mask);
        
        //创建显示层
	    var show = document.createElement("div");
	    show.id = "show";
	    show.style.position = "absolute";
	    show.style.zIndex = "20";
	    show.style.width = width/3*2 + "px";
	    //show.style.width = 20 + "px";
        show.style.height = height/3*2 + "px";
        show.style.background = "#EFEFEF";
        show.style.left = (scrollWidth - width/3*2)/2 + "px";//左右居中
        show.style.top = (scrollHeight - height/3*2)/2 + "px";//上下居中
        show.style.textAlign = "left";
        show.style.borderLeft = "solid 1px #87b4e5";
        show.style.borderRight = "solid 1px #87b4e5";
        show.style.borderBottom = "solid 1px #87b4e5";

        //创建Iframe
        var iframe = document.createElement("iframe");
        //iframe.style.width = 20 + "px";
        iframe.style.width = width/3*2 + "px";
        iframe.style.height = height/3*2 + "px";
        iframe.frameBorder = "0px"; 
        iframe.src = url;
        
        show.appendChild(iframe);
        form.appendChild(show);  
    },
    
    /// <summary>
    /// 关闭窗口
    /// </summary>
    close : function()
    {
        var form = parent.document.getElementById("aspnetForm") == null ? parent.document.getElementById("form1") : parent.document.getElementById("aspnetForm");
        var mask = parent.document.getElementById("mask");
        var show = parent.document.getElementById("show");

        form.removeChild(show);
        form.removeChild(mask);
    },
    
    /// <summary>
    /// 刷新父窗口
    /// </summary>
    refresh : function()
    {
        window.parent.location.href = parent.location.href;
    },
    
    /// <summary>
    /// 获取窗口标题
    /// </summary>
    getTitle : function()
    {
        var title = document.getElementById("formTitle");
        title.innerHTML = document.title;
    }

}

var dlg = new ModalDialog();

function openModalDialog(url, width, height)
{
    dlg.create(url, width, height);
}

function getTitle()
{
    dlg.getTitle();
}

function closeModalDialog(returnValue)
{
    if(returnValue)
    {
        dlg.refresh();
    }
    else
    {
        dlg.close();
    }
}
