﻿var if_cWinHeight = "0px"; var if_EditMode = false; var if_scrollByX = 0; var if_scrollByY = 0; var if_openLinkIn = "self"; //new/selv/parent
function if_registerIframeEvent(iframeName) { if_AddJSevent(window, "load", function() { if_resizeFrame(iframeName) }); }
function if_resizeFrame(iframeName) {
    var f = document.getElementById(iframeName);
    if_setIframeHeight(f);
    try {
        if_AddJSevent(f.contentWindow, 'resize', function() { if_setIframeHeight(f); })
        addLinkEvent(f.contentWindow, if_openLinkIn);
    } catch (err) {
        if ((if_EditMode) && (!heightIsSpecified(if_cWinHeight))) {
            alert("Access is denied to the source page " + f.src + "\nThe source page is not on the same domain as IFRAME container page.\nPlease specify the height of IFRAME.");
        }
    }
}
function if_setIframeHeight(iframeObj) {
    var h = if_getSrcHeight(iframeObj);
    if (heightIsSpecified(h)) {
        iframeObj.style.height = h;
        if (if_scrollByX || if_scrollByY) {
            try { $(iframeObj.contentWindow.document.body).scrollTo(if_scrollByX, if_scrollByY); } catch (er) {
                try { iframeObj.contentWindow.scrollBy(if_scrollByX, if_scrollByY); } catch (er) { }
            }

        }
    }
}
function if_AddJSevent(element, eventName, functionName) {
    if (null != element) {
        if (window.addEventListener) {
            element.addEventListener(eventName, functionName, false);
        } else if (window.attachEvent) {
            element.attachEvent('on' + eventName, functionName);
        }
    }
}
function if_getSrcHeight(iframeObj) {
    if (heightIsSpecified(if_cWinHeight)) { return if_cWinHeight; }
    try { if_cWinHeight = $(iframeObj.document.body).getSize().y; } catch (err) {
        try {

            if_cWinHeight = iframeObj.contentWindow.document.body.scrollHeight + "px";
        }
        catch (err) { }
    }
    return if_cWinHeight;
}
function heightIsSpecified(height) { return (height != "0px"); }
function addLinkEvent(iframe, openLinkIn) {
    $(iframe.document.body).addEvent('click', function(event) { return if_openLink(iframe, event, openLinkIn); });
}
function if_openLink(iframe, e, openLinkIn) {
    try {
        if ((e.target) && (e.target != "[object]")) {
            if (openLinkIn == "parent") {
                iframe.parent.document.location.href = e.target;
            } else if (openLinkIn == "new") {
                var nWin = window.open(e.target, "nWin", "", true);
            } else {
                iframe.document.location.href = e.target;
            }
        }
    } catch (err) { return true; }
    return false;
}