
/**
 */
function printPage() {
    // this has to be 3 seconds otherwise it does not work on FF
    var timeoutFF = 3 * 1000; // in miliseconds

    var timeoutIE = 1 * 1000;

    var table = document.getElementById("sublayout-default-content-table");
    var table2 = document.getElementById("sublayout-default-content-table2");
    var skyscraper = document.getElementById("skyscraper");
    var printViewIcon = document.getElementById("print-view-icon");
    var bookmarkIcon = document.getElementById("bookmark-icon");
    var leftBg = document.getElementById("left-bg");
    var rightBg = document.getElementById("right-bg");

    var display = "none";

    printViewIcon.style.display=display;
    if (bookmarkIcon != null) {
      bookmarkIcon.style.display=display;
    }
    _applyDisplay(table, display);
    _applyDisplay2(table2, display);
    if (skyscraper != null) {
        skyscraper.style.display=display;
    }
    table.style.height="100px";
    leftBg.style.display=display;
    rightBg.style.display=display;
    document.body.style.background="transparent";
    table.rows[1].cells[0].style.borderBottom="0px";
    
    var eventName = "";

    if ( window.addEventListener) {
        eventName = "focus";
        // console.log(eventName);
        window.addEventListener(eventName, function(e) {
            setTimeout(
                function() { 
                    display = "";
                    _applyDisplay(table, display);
                    _applyDisplay2(table2, display);
                    if (skyscraper != null) {
                        skyscraper.style.display=display;
                    }
                    table.style.height="100%";
                    printViewIcon.style.display=display;
                    if (bookmarkIcon != null) {
                        bookmarkIcon.style.display=display;
                    }
                    leftBg.style.display=display;
                    rightBg.style.display=display;
                    document.body.style.backgroundImage="url(/resources/images/layout/header_mp_bg.gif)";
                    document.body.style.backgroundRepeat="no-repeat";
                    table.rows[1].cells[0].style.borderBottom="#9A9B9C solid 1px";
                }
            , timeoutFF);
            this.removeEventListener(eventName, arguments.callee, false);

        }, false);
    }
    else if ( window.attachEvent ) {
        eventName = "onafterprint";
        window.attachEvent(eventName, function(e) {
            setTimeout(
                function() { 
                    display = "";
                    _applyDisplay(table, display);
                    _applyDisplay2(table2, display);
                    if (skyscraper != null) {
                        skyscraper.style.display=display;
                    }
                    table.style.height="100%";
                    printViewIcon.style.display=display;
                    if (bookmarkIcon != null) {
                        bookmarkIcon.style.display=display;
                    }
                    leftBg.style.display=display;
                    rightBg.style.display=display;
                    document.body.style.background="transparent";
                    document.body.style.backgroundImage="url(/resources/images/layout/header_mp_bg.gif)";
                    document.body.style.backgroundRepeat="no-repeat";
                    table.rows[1].cells[0].style.borderBottom="#9A9B9C solid 1px";
                }
            , timeoutIE);
            this.detachEvent(eventName, arguments.callee);

        });
    }

    window.print();
}

function _applyDisplay(table, display) {
    table.rows[0].style.display = display;
    table.rows[2].style.display = display;

//    var row = table.rows[0];
//    row.cells[0].style.display = display;
}

function _applyDisplay2(table, display) {
    table.rows[0].style.display = display;
    table.rows[1].style.display = display;

    var uristem = location.pathname;
    var contentRowIndex = 2;
    var row = table.rows[contentRowIndex];
    row.cells[0].style.display = display;
    row.cells[2].style.display = display;
}




