﻿function FloatShow(sUrl, iWidth, iHeight, OnOK, OnCancel, iLeft, iTop, oWin, fras)
{

    oWin = oWin || window;
    iLeft = typeof (iLeft) == "number" ? iLeft : GetTopLeftCorner(iWidth);
    iTop = typeof (iTop) == "number" ? iTop : -30;
    var ifras = null;
    if (typeof (fras) != "undefined" && fras != null && fras != "null")
    {
        ifras = fras;
    } else
    {
        ifras = [window, top.mainfra, top.leftfra, top.topfra];
    }
    FloatShow.Show = function(sUrl, iWidth, iHeight, iLeft, iTop)
    {
        MaskStart(ifras);
        var e = DivCreate(oWin, oWin.document.body, "ID_QQLOVE_FLOAT_WIN", 65530, 0, 50, "100%", "1", "none");
        e.style.top = (Math.max(Math.min(oWin.document.documentElement.scrollTop + 100, oWin.document.body.offsetHeight - 100), 50)) + "px";
        e.innerHTML = '<table id="w_head" align="left" style="position:absolute;left:' + iLeft + 'px;top:' + iTop + 'px;"><tr><td align="center"><iframe allowTransparency="true" id="ID_QQLOVE_FLOAT_IFRAME" name="ID_QQLOVE_FLOAT_IFRAME" width="' + iWidth + '" height="' + iHeight + '" frameborder="0" scrolling="no"></iframe></td></tr></table><div id="d_border" style="display:none;border:1px dotted #000000; position:absolute;"></div>';
        e.getElementsByTagName("IFRAME")[0].src = sUrl;
        e.style.display = "block";
    };

    FloatShow.Hide = function()
    {
        MaskEnd([window, top.mainfra, top.leftfra, top.topfra]);

        if (arguments[0])
        {
            var fra = arguments[0];
            if (fra && fra.document)
            {
                fra.document.getElementById("ID_QQLOVE_FLOAT_WIN").style.display = "none";
            }
        } else
        {
            document.getElementById("ID_QQLOVE_FLOAT_WIN").style.display = "none";
        }
    };

    FloatShow.DireOnCancel = function()
    {
        OnCancel && OnCancel(arguments[0]);
    };

    FloatShow.OnOK = function()
    {
        FloatShow.Hide();
        OnOK && OnOK(arguments[0]);
    };

    FloatShow.OnCancel = function()
    {
        FloatShow.Hide();
        OnCancel && OnCancel(arguments[0]);
    };

    FloatShow.AutoSize = function()
    {
        try
        {
            function FindIFrame(sName) { for (var i = 0; i < window.frames.length; ++i) { if (window.frames[i].name == sName) { return window.frames[i]; } } return null; };
            var e = document.getElementById("ID_QQLOVE_FLOAT_IFRAME");
            var w = _MSIE() ? window.frames["ID_QQLOVE_FLOAT_IFRAME"] : FindIFrame("ID_QQLOVE_FLOAT_IFRAME");
            if ((w.document.documentElement.scrollTop = 500) && (w.document.documentElement.scrollTop != 0))
            {
                e.height = parseInt(e.height) + w.document.documentElement.scrollTop + "px";
                w.document.documentElement.scrollTop = 0;
            }
            if ((w.document.documentElement.scrollLeft = 500) && (w.document.documentElement.scrollLeft != 0))
            {
                e.width = parseInt(e.width) + w.document.documentElement.scrollLeft + "px";
                w.document.documentElement.scrollLeft = 0;
            }
        }
        catch (e)
        {
        }
    };

    FloatShow.Show(sUrl, iWidth, iHeight, iLeft, iTop);
};

function MaskStart(lWin)
{
    for (var i = 0; i < arguments[0].length; ++i)
    {
        try { PageMaskShow(arguments[0][i]); } catch (e) { }
    }
};

function PageMaskShow(oWin)
{
    var e = PageMaskCreate(oWin);
    if (e)
    {
        e.style.height = Math.max((oWin.document.body.offsetHeight), oWin.document.documentElement.clientHeight) + "px";
        e.style.display = "block";
    }
};

function MaskEnd(lWin)
{
    for (var i = 0; i < arguments[0].length; ++i)
    {
        try { PageMaskHide(arguments[0][i]); } catch (e) { }
    }
};

function PageMaskHide(oWin)
{
    var e = PageMaskCreate(oWin);
    e.style.display = "none";
};

function PageMaskCreate(oWin)
{
    if (oWin && oWin.document)
    {
        if (!oWin.document.getElementById("ID_QQLOVE_WAIT_BACKGND"))
        {
            var ebg = DivCreate(oWin, oWin.document.body, "ID_QQLOVE_WAIT_BACKGND", 65529, 0, 0, "100%", "100%", "none");
            ebg.style.backgroundColor = "#000";
            ebg.style.opacity = 0.35;
            ebg.style.filter = "alpha(opacity=35)";
        }
        return oWin.document.getElementById("ID_QQLOVE_WAIT_BACKGND");
    }
    else return null;
};

// ########################################################

// 共用功能显示[进度屏蔽/浮动窗口/...]

function DivCreate(oWin, oParent, sID, zIndex, iLeft, iTop, sWidth, sHeight, sDisplay)
{
    if (!oWin.document.getElementById(sID))
    {
        var e = oWin.document.createElement("DIV");
        e.id = sID;
        e.style.position = "absolute";
        e.style.zIndex = zIndex;
        e.style.left = iLeft;
        e.style.top = iTop;
        e.style.width = sWidth;
        e.style.height = sHeight;
        e.style.display = sDisplay;
        try { oParent && oParent.appendChild(e); } catch (e) { }
        return e;
    }
    return oWin.document.getElementById(sID);
};

function GetTopLeftCorner(width)
{
    var clientWidth = document.body.clientWidth;
    var left = (clientWidth - width) / 2;
    return Math.round(left);
}
