﻿
var OpenWindowsAsPopIns = false;

var popinContainerTemplate = "" +
    "<div id='\\1\\' class='popin \\2\\'>" +
        "<a href='#' class='topright' onClick='CloseWindow(\"\\1\\\")' >close</a>" +
        "<div>" +
            "<iframe src='\\0\\' />" +
        "</div>" +
    "</div>";

function OpenWindow(url, id, height, width, scrollable) {
    if( OpenWindowsAsPopIns )
    {
        var newFrame = popinContainerTemplate;
        newFrame = newFrame.replace("\\0\\", url);
        newFrame = newFrame.replace("\\1\\", id).replace("\\1\\", id);
        newFrame = newFrame.replace("\\2\\", scrollable ? "scrollable " : "");
        var popin = document.createElement("div");
        popin.innerHTML = newFrame;
        if (document.getElementById(id)) {
            document.body.replaceChild(document.getElementById(id), popin);
        } else {
            document.body.appendChild(popin);
        }
        //$("#"+id).draggable();
    } else {
        if(id == null || id == "") {
            id = "_blank";
        }
        var scrollbars = "scrollbars=no"
        if(scrollable) {
            scrollbars = "scrollbars=yes"
        }
        var defaultOptions = ",location=no,menubar=no,resizable=no,status=no,toolbar=no"
        newwin = window.open(url, id, "height=" + height + ",width=" + width + "," + scrollbars + defaultOptions, false);
        newwin.focus();
    }
    return false;
}

/*function OpenWindow(url) {
    return OpenWindow(url, null, 600, 820, true);
}*/

function ViewerLink(url)
{
    if (window.location.href != top.location.href) {
        top.location.href = url;
    } else {
        OpenWindow(url);
    }
}

function CloseWindow(id) {
    if( OpenWindowsAsPopIns ) {
        var node = document.getElementById(id);
        node.parentNode.removeChild(node);
    }
}

function OpenViewerWindow(url) {
    return OpenWindow(url, null, 600, 900, true);
}

function SetSize() {
    var htmlheight = document.body.parentNode.scrollHeight;
    var windowheight = window.innerHeight;
    if (!windowheight) {
        if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
            //IE 6+ in 'standards compliant mode'
            windowheight = document.documentElement.clientHeight;
        } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
            //IE 4 compatible
            windowheight = document.body.clientHeight;
        } else {
            windowheight = 600;
        }
    }
    var headerheight = document.getElementById("HeaderRow").offsetHeight;
    var rowheight = document.getElementById("ContentContainer").parentNode.clientHeight;
    var contentheight = windowheight - headerheight - 45;
    /*if (rowheight > contentheight) {
        contentheight = rowheight - 5;
    }*/

    document.body.style.height = windowheight + "px";
    document.getElementById("Content").style.height = (contentheight) + "px";
}
