/*
    project: WestLB
    type: javascript
    description: functions for printing
    (c) Aperto AG 2004. All rights reserved.
*/

/* print window */
function printWindow() {
    window.print();
    return false;
}


/* insert print time */
function insertPrintTime(text) {
    if (document.createElement && document.appendChild && document.getElementsByTagName && document.createTextNode) {
        var header = document.getElementById('header');

        if (header) {
            var headerP = document.createElement('P');

            var printDate = new Date();
            var headerTxt = document.createTextNode(text + ' ' + printDate.toLocaleString());

            headerP.appendChild(headerTxt);
            header.appendChild(headerP);
        }

    if (window.opener && !window.opener.closed) {
			var node = document.getElementById('urlcontainer');
            if (node) {
			    var referrerURI = window.opener.location.href;
			    var newNode = document.createTextNode(referrerURI);
			    var oldNode = node.firstChild;
			    if(oldNode) {
				    node.replaceChild(newNode, oldNode);
			     } else {
				     node.appendChild(newNode);
			    }
             }
        }
    }
}


/* insert print utility buttons */
function insertPrintUtilityButtons(id, headlineText, closeWindowText, printPageText) {
    if (document.createElement && document.appendChild && document.getElementsByTagName && document.createTextNode) {
        var info = document.getElementById(id);

        if (info) {
            var headline = document.createElement('h2');
            headline.className = 'hide';
            var headlineTxt = document.createTextNode(headlineText);
            headline.appendChild(headlineTxt);
            info.appendChild(headline);

            var iconList = document.createElement('ul');
            iconList.className = 'iconList';

            var closeWindowLi = createListItem(closeWindowText, 'closeWindow', closeWindow);
            iconList.appendChild(closeWindowLi);
            var printWindowLi = createListItem(printPageText, 'printPage', printWindow);
            iconList.appendChild(printWindowLi);

            info.insertBefore(iconList,info.firstChild);
        }
    }
}


/* creates a list item */
function createListItem(text, className, evt) {
    if (document.createElement && document.appendChild && document.createTextNode) {
        var listItem = document.createElement('LI');

        var listItemA = document.createElement('A');
        listItemA.className = className;
        listItemA.setAttribute('href', '#');
        listItemA.setAttribute('title', text);
        addEvent(listItemA, 'click', evt);

        var listItemTxt = document.createTextNode(text);
        listItemA.appendChild(listItemTxt);

        listItem.appendChild(listItemA);

        return listItem;
    } else {
        return null;
    }
}

