﻿function getWindowHeight(win) {
    var windowheight = 0;
    if (win == null) {
        win=window
    }
    if (typeof (win.innerHeight) == 'number') {
        windowheight = win.innerHeight;
    }
    else {
        if (win.document.documentElement && win.document.documentElement.clientHeight) {
            windowheight = win.document.documentElement.clientHeight;
        }
        else {
            if (win.document.body && win.document.body.clientHeight) {
                windowheight = win.document.body.clientHeight;
            }
        }
    }
    return windowheight;
}
function getWindowWidth(win) {
    var windowWidth = 0;
    if (win == null) {
        win = window
    }
    if (typeof (win.innerWidth) == 'number') {
        windowWidth = win.innerWidth;
    }
    else {
        if (win.document.documentElement && win.document.documentElement.clientWidth) {
            windowWidth = win.document.documentElement.clientWidth;
        }
        else {
            if (win.document.body && win.document.body.clientWidth) {
                windowWidth = win.document.body.clientWidth;
            }
        }
    }
    return windowWidth;
}
var _windowHeight = 0
function _windowResize() {
    //get all frames
    _windowHeight = getWindowHeight(window);
    if (_windowHeight > 0) {
        for (var i = 0; i < window.frames.length; i++) {
            try {
                if (window.frames[i].windowResize) {
                    if (window.frames[i].document.readyState == 'complete') {
                        window.frames[i].windowResize(window._windowHeight)
                    } else {
                        window.setTimeout('window.frames[' + i + '].windowResize(window._windowHeight)', 1000)
                    }
                }
                
                //get iframes
                for (var j = 0; j < window.frames[i].frames.length; j++) {
                    try {
                        if (window.frames[i].frames[j].windowResize) {
                            if (window.frames[i].frames[j].document.readyState == 'complete') {
                                window.frames[i].frames[j].windowResize(window._windowHeight)
                            } else {
                            window.setTimeout('window.frames[' + i + '].frames[' + j + '].windowResize(window._windowHeight)', 1000)
                            }
                        }
                    } catch (e) { }
                }
            } catch (ex) { }
        } 
    }
}

function elementResize(doc,id, height) {
    if (doc.getElementById) {        
        var el = doc.getElementById(id);
        if (el) {
            //el.style.position = 'absolute';
            el.style.height = height + 'px';
            return el
        }
    }
    return null
}
function elementResizeWidth(doc, id, width) {
    if (doc.getElementById) {
        var el = doc.getElementById(id);
        if (el) {
            //el.style.position = 'absolute';
            el.style.width = width + 'px';
            return el
        }
    }
    return null
}

if (location.href == window.parent.location.href) {
    window.onload = function() { _windowResize(); }
    window.onresize = function() { _windowResize(); }
}
        
