﻿
var g_max_iframe_height;
var g_iframe_stylesheet_url;

function getClientWidth() {
    return document.compatMode == 'CSS1Compat' && !window.opera ? document.documentElement.clientWidth : document.body.clientWidth;
}

function getClientHeight() {
    return document.compatMode == 'CSS1Compat' && !window.opera ? document.documentElement.clientHeight : document.body.clientHeight;
}


function addExternalSearch(iframe_id, stylesheet_url, max_height) {
    // add load event
    $("#" + iframe_id).load(calcHeight);

    if (max_height == undefined) {
        g_max_iframe_height = getClientHeight() - 50;
    }
    else {
        g_max_iframe_height = max_height;
    }
    g_iframe_stylesheet_url = stylesheet_url;

}

function calcHeight() {

    if (g_iframe_stylesheet_url != undefined) {
        var css_link = this.contentWindow.document.createElement("LINK");
        css_link.rel = "stylesheet";
        css_link.type = "text/css";
        css_link.href = g_iframe_stylesheet_url;

        $("head", this.contentWindow.document).after(css_link);

        //this.contentWindow.document.head.appendChild(css_link);
    }

    //find the height of the internal page    
    //var the_height = this.contentWindow.document.body.scrollHeight;

    /*if (g_max_iframe_height != undefined) {
        if (the_height > g_max_iframe_height) {
            the_height = g_max_iframe_height;
        }
    }

    //change the height of the iframe
    this.height = the_height + 20;
*/
}