/*

    CONFIGURATION

*/



/*

    DO NOT CHANGE

*/
/* globals */
var isDOMCapable = false;

/* DOM methods and collections used in the script */
if (document.getElementsByTagName && document.getElementById
    && document.createElement && document.createTextNode
    && document.appendChild) {
    isDOMCapable = true;
}

function addEvent(obj, evType, fn) {
    if (obj.addEventListener) {
        obj.addEventListener(evType, fn, false);
        return true;
    } else if (obj.attachEvent) {
        var r = obj.attachEvent("on" + evType, fn);
        return r;
    } else {
        return false;
    }
}







if (!document.getElementById) {
    document.getElementById = function() { return null; }
}



addLoadEvent (printpage);
addLoadEvent (closewindow);
function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            oldonload();
            func();
        }
    }
}

var PRINT_TEXT_DE = 'drucken';  // print text deutsch
var PRINT_TEXT_EN = 'Print';    // print text englisch
var PRINT_TEXT_FR = 'Imprimer'; // print text franzoesisch

function printpage() {
    var hasPrintFeature = (window.print) ? true : false;

    if (hasPrintFeature && (document.createElementNS || document.createElement) && document.createTextNode && document.insertBefore && document.appendChild) {
        var elem = document.getElementsByTagName("html")[0];
        var printText = ""
        if (elem && elem.lang) {
            switch(elem.lang) {
                case "de":
                    printText = PRINT_TEXT_DE;
                    break;
                case "en":
                    printText = PRINT_TEXT_EN;
                    break;
                case "fr":
                    printText = PRINT_TEXT_FR;
                    break;
            }
            var a = document.createElement('a');
            a.setAttribute('href', '#');
            a.onclick = function() {
                window.print();
                return false;
            }
            a.appendChild(document.createTextNode(printText));
            var refNode = document.getElementById('print');
            if (refNode) {
                refNode.appendChild(a);
            }
        }
    }
}






var CLOSE_TEXT_DE = 'Fenster schlie\u00DFen';  // print text deutsch
var CLOSE_TEXT_EN = 'Close Window';    // print text englisch
var CLOSE_TEXT_FR = 'Fermer fen\u00EBtre'; // print text franzoesisch

function closewindow() {
    var hasCloseFeature = (window.close) ? true : false;

    if (hasCloseFeature && (document.createElementNS || document.createElement) && document.createTextNode && document.insertBefore && document.appendChild) {
        var elem = document.getElementsByTagName("html")[0];
        var closeText = ""
        if (elem && elem.lang) {
            switch(elem.lang) {
                case "de":
                    closeText = CLOSE_TEXT_DE;
                    break;
                case "en":
                    closeText = CLOSE_TEXT_EN;
                    break;
                case "fr":
                    closeText = CLOSE_TEXT_FR;
                    break;
            }
            var a = document.createElement('a');
            a.setAttribute('href', '#');
            a.onclick = function() {
               window.close();
                return false;
            }
            a.appendChild(document.createTextNode(closeText));
            var refNode = document.getElementById('close');
            if (refNode) {
                refNode.appendChild(a);
            }
        }
    }
}


// Global variable for subwindow reference
var newWindow;
// Generate and fill the new window
function makeNewWindow(obj) {
    newWindow = window.open("", "sub", "status,resizable,height=200,width=400");
    // handle Navigator 2, which doesn't have an opener property
    if (!newWindow.opener) {
        newWindow.opener = window;
    }
    // delay writing until window exists in IE/Windows
    setTimeout("writeToWindow('" + obj + "')", 500);
    newWindow.focus();
}

function writeToWindow(obj) {
    // assemble content for new window
    var newContent = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n";
    newContent += "    \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n\n";
    newContent += "<html>\n<head>\n";
    newContent += "<title>Online-Styleguide : Hinweis</title>\n";
    for(var i = 0; (a = document.getElementsByTagName("link")[i]); i++) {
        if (a.getAttribute("rel") == "stylesheet") {
            newContent += "<link rel=\"stylesheet\" href=\"" + a.getAttribute('href') + "\" type=\"text/css\" media=\"screen, projection\" title=\"Standard\" />\n";
        }
    }
    newContent += "</head>\n";
    newContent += "<body id=\"hinweis\"><div><p>Die Adresse <a href=\"" + obj + "\" target=\"_blank\" title=\"&Ouml;ffnet neues Fenster\">" + (obj.indexOf('http://www') != -1 ? obj.substring(7) : obj) + "</a> ist nur &uuml;ber einen Internetzugang erreichbar.</p></div>";
    newContent += "</body>\n</html>";
    // write HTML to new window document
    newWindow.document.write(newContent);
    newWindow.document.close(); // close layout stream
}


