﻿function ShowDivForm(OpenURL, IsScroll, FormWidth, FormHeight, FormTitle, ImagePath, PageTime) {
    window.setTimeout(function() {

        {
            var msgw, msgh, bordercolor;
            msgw = FormWidth; //提示窗口的宽度
            msgh = FormHeight; //提示窗口的高度
            msch = FormHeight - 20; //内容高度
            formtitle = FormTitle; //屏幕标题
            imagepath = ImagePath; //图标路径

            var sWidth, sHeight;
            sWidth = document.body.clientWidth;
            //sHeight = document.body.clientHeight;
            sHeight = (document.documentElement) ? document.documentElement.scrollHeight : document.body.scrollHeight;

            //sHeight=window.screen.availHeight;
            var iframeObj = document.createElement("iframe");
            iframeObj.setAttribute('id', 'bgiframe');
            iframeObj.style.position = "absolute";
            iframeObj.style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75);";
            iframeObj.style.opacity = "0.8";
            iframeObj.style.top = "0";
            iframeObj.style.left = "0";
            iframeObj.style.width = sWidth + "px";
            iframeObj.style.height = sHeight + "px";
            iframeObj.style.zIndex = "10000";
            document.body.appendChild(iframeObj);

            var bgObj = document.createElement("div");
            bgObj.setAttribute('id', 'bgDiv');
            bgObj.style.position = "absolute";
            bgObj.style.top = "0";
            bgObj.style.background = "#E7EBEF";
            bgObj.style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75);";
            bgObj.style.opacity = "0.8";
            bgObj.style.left = "0";
            bgObj.style.width = sWidth + "px";
            bgObj.style.height = sHeight + "px";
            bgObj.style.zIndex = "10000";
            document.body.appendChild(bgObj);

            var msgObj = document.createElement("div")
            msgObj.setAttribute("id", "msgDiv");
            msgObj.setAttribute("align", "center");
            msgObj.style.background = "white";
            msgObj.style.position = "absolute";

            /*if (sWidth > msgw) {
            msgObj.style.left = (sWidth - msgw) / 2 + document.documentElement.scrollLeft + "px";
            }
            else {
            msgObj.style.left = 0;
            }

            if (sHeight > msgh) {
            msgObj.style.top = (sHeight - msgh) / 2 + document.documentElement.scrollTop + "px";
            }
            else {
            msgObj.style.top = 0;
            }*/

            msgObj.style.font = "12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif";
            msgObj.style.width = msgw + "px";
            msgObj.style.height = msgh + "px";

            msgObj.style.textAlign = "left";
            msgObj.style.zIndex = "10001";
            document.body.appendChild(msgObj);
            var txt = document.createElement("content");
            txt.style.margin = "1em 0"
            txt.setAttribute("id", "msgTxt");

            var sHtml = "<table border='0' width='" + msgw + "px' cellspacing='2' cellpadding='2' style='background-color: #B4C5D5;'>" +
                       "<tr><td style='width: 100%'>" +
                            "<table border='0' cellspacing='0' cellpadding='0' style='height: 100%; width: 100%'>" +
                                "<tr style='height:20px'>" +
                                     "<td><table border='0' cellspacing='0' cellpadding='0' style='height: 100%; width: 100%'>" +
                                         "<tr style='height:20px'>";
            if (imagepath != "")
                sHtml += "<td  style='cursor: hand; width: 100%; color: White; cursor:move;' onmousedown='moveStart(event, \"msgDiv\");'>" +
                                                    "&nbsp;&nbsp;<img src=" + imagepath + "/DivIcon.gif alt='' style='vertical-align:middle'/>&nbsp;" + formtitle +
                                                    "</td> <td style='cursor: hand'>" +
                                                    "<img src=" + imagepath + "/DivClose.gif alt='关闭' onclick='FormDivClose();return false;' style='border: 0px;' id='winFormCloseImg' />&nbsp;&nbsp;</td>";
            else
                sHtml += "<td  style='cursor: hand; width: 100%; color: White;'>" +
                                                    "&nbsp;&nbsp;&nbsp;" + formtitle + "</td> <td>&nbsp;</td>";
            sHtml += "</tr></table></td></tr>" +
                                "<tr style='height:" + msch + "px'>" +
                                "<td style='background-color: White; width: 100%;vertical-align:top;text-align:center' colspan='2'>" +
                                "<div id='Frmiframe' style='display: none'><iframe width=" + msgw + " height=" + msch + " scrolling=" + IsScroll +
                                    "marginwidth=0 marginheight=0 frameborder=0 src=" + OpenURL + " onload='HideDiv()' id='popWinMainIframe'></iframe></div>" +
                                "<div id='Loading' style='z-index: 12000; filter: Alpha(Opacity=50); '>" +
                                    "<table style='height: 100%; width: 100%; background-color: #f6f6f6'>" +
                                        "<tr align='center' valign='middle'>" +
                                            "<td>正在处理中......<br /><img src=" + imagepath + "/loading.gif alt=''/></td>" +
                                       "</tr>" +
                                    "</table>" +
                                "</div>" +
                   "</td></tr></table></td></tr></table>";
            txt.innerHTML = sHtml;
            document.getElementById("msgDiv").appendChild(txt);
            HideDiv = function() {
                var objDialogLoad = document.getElementById('Loading');
                if (objDialogLoad) objDialogLoad.style.display = 'none'
                var objDialogIframe = document.getElementById('Frmiframe');
                if (objDialogIframe) objDialogIframe.style.display = "";
            }

            FormDivClose = function() {
                document.body.removeChild(iframeObj);
                document.body.removeChild(bgObj);
                document.body.removeChild(msgObj);
            }

            showFormMiddle(msgObj);
        }
    }, PageTime);
}

function showFormMiddle(elementObj) {
    var theWidth;
    var theHeight;
    if (document.documentElement && document.documentElement.clientWidth) {
        theWidth = document.documentElement.clientWidth + document.documentElement.scrollLeft * 2;
        theHeight = document.documentElement.clientHeight + document.documentElement.scrollTop * 2;
    } else if (document.body) {
        theWidth = document.body.clientWidth;
        theHeight = document.body.clientHeight;
    } else if (window.innerWidth) {
        theWidth = window.innerWidth;
        theHeight = window.innerHeight;
    }

    elementObj.style.left = (theWidth / 2) - (elementObj.offsetWidth / 2) + 8 + "px";
    elementObj.style.top = (theHeight / 2) - (elementObj.offsetHeight / 2) + "px";
}


function ShowDivLocation(msgw,msgh)
{
    var msgObj=window.document.getElementById("msgDiv");
    if (msgObj!=null)
    {
        sWidth=document.body.clientWidth;
        sHeight=document.body.clientHeight;
        if (sWidth>msgw)
        {
       	    msgObj.style.left = (sWidth-msgw)/2+document.documentElement.scrollLeft+"px" ;
        }
        else
        {
            msgObj.style.left = 0;
        }
       
        if (sHeight>msgh)
        {
       	    msgObj.style.top = 0 ;
        }
        else
        {
            msgObj.style.top = 0;
        }   
        this.timervar=window.setTimeout("ShowDivLocation("+msgw+","+msgh+","+sWidth+","+sHeight+")",1000);

    }
}