// need jquery (1.7.1+) to run current page

// trigger resizeIframe function if current page has a parent page
// id: ID of current page's body tag.
//     If body tag has no ID or the supplied ID is blank, it will resize ALL iframes in parent page
//     If the IDs match, it will resize ONLY the matching iframe(s)
// win: window DOM of child page
//     This parameter is used for fail safe when JQUERY cannot get height information from the content
function resizeParentIframe(id, win) {
    if (window.parent != window)
        window.parent.resizeIframe(id, win);
}

// private use only
// resizes iframe to its content height
function resizeIframe(id, win) {
    $($("iframe").get().reverse()).each(function () {
        var currBodyId = $(this).contents().find("body").attr("id");
        if(id == "" || currBodyId == "" || id == currBodyId) {
            //Reset iframe height to 0 - to make calculation for height consistant
            $(this).height(0);

            //Update iframe height to consistant
            var h = $(this).contents().find("html").height();
            if (h == 0)
                h = win.document.documentElement.scrollHeight || win.document.body.scrollHeight;

            $(this).height(h);

            return false;
        }
        return false;
    });
}