﻿function getFrameHeight(aFrameName, aDocument)
{
    var doc = aDocument ? aDocument : document;
    var frameNode = doc.frames ? doc.frames[aFrameName] : doc.getElementById(aFrameName).contentWindow;    
    if (frameNode == null)
    {
        return 0;
    }
    var iHeight = 0;
    if(null != frameNode.scrollMaxY)  //是firefox
    {
        var tempWidth = frameNode.frameElement.style.height;
        frameNode.frameElement.style.height = "0px";
        iHeight = frameNode.document.documentElement.scrollHeight;
        frameNode.frameElement.style.height = tempWidth;
    }
    else if (frameNode.opera) // 是Opera
    {
        iHeight = frameNode.document.documentElement.scrollHeight;
    }
    else
    {
        iHeight = frameNode.document.body.scrollHeight;
    }
    
    return iHeight;
}

// 得到窗口的高度
function GetWindowHeight(aWin)
{
    if (!aWin) aWin=window;
    if (aWin.innerHeight) {return aWin.innerHeight;}
    if (aWin.document.documentElement.clientHeight) {return aWin.document.documentElement.clientHeight;}
    if (aWin.document.body.clientHeight) {return aWin.document.body.clientHeight;}
}

function adaptFrameHeight(aIframeID)
{
    // 如果在onload中调用此函数，opera会修改高度失效，所以用setTimeout延时执行
    setTimeout("realResizeHeight('"+aIframeID+"')", 0);
}

function realResizeHeight(aIframeID)
{
    var frame = document.getElementById(aIframeID);
    if (frame)
        frame.style.height=getFrameHeight(aIframeID) + 0 +  "px";
}

function adaptWindowHeight()
{
    setTimeout("realResizeWindowHeight()", 0);
}
function realResizeWindowHeight()
{
    var aWindow = this;
    if (aWindow.parent != null && aWindow.parent != aWindow)
    {
        aWindow.frameElement.style.height = getFrameHeight(aWindow.frameElement.id, aWindow.frameElement.ownerDocument) + 20 + "px";
    }
}
