﻿function Popup(url) {
    NewWindow(url, 'Popup', 530, 500, 100, 100, 'no', 'no', 'no', 'no', 'no', 'no', 'yes', 'no')
}

function printview() {
    var host = window.location.hostname;
    var url = window.location.href;
    var port = window.location.port;
    var protocol = window.location.protocol;
    var all = null;
    if (port != "") {
        all = protocol + "//" + host + ":" + port + "/_layouts/AxaCmsInternet/PrintView.aspx?url=" + url;
    }
    else {
        all = protocol + "//" + host + "/_layouts/AxaCmsInternet/PrintView.aspx?url=" + url;
    }
    printWindow = window.open(all, "PrintView", "width=600, height=600, scrollbars=yes, toolbars=no, resizable=yes");
    printWindow.moveTo(0, 0);
}

function getContentElement(documentNode) {
    var elements = getElementsByClass('content', documentNode, 'div');
    if (elements.length > 0) {
        return elements[0];
    }
    return null;
}

function getElementsByClass(searchClass, node, tag) {
    var classElements = new Array();
    if (node == null)
        node = document;
    if (tag == null)
        tag = '*';
    var els = node.getElementsByTagName(tag);
    var elsLen = els.length;
    var pattern = new RegExp("(^|\\s)" + searchClass + "(\\s|$)");
    for (i = 0, j = 0; i < elsLen; i++) {
        if (pattern.test(els[i].className)) {
            classElements[j] = els[i];
            j++;
        }
    }
    return classElements;
}

function copyNodeValues(sourceRootNode, targetRootNode, tags) {
    for (var t = 0; t < tags.length; t++) {
        copyNodeValuesForTag(sourceRootNode, targetRootNode, tags[t]);
    }
}

function copyNodeValuesForTag(sourceRootNode, targetRootNode, tag) {

    var textFields = targetRootNode.getElementsByTagName(tag);
    var n = 0;
    for (n = 0; n < textFields.length; n++) {
        try {
            var nId = "";
            try {
                nId = textFields[n].id;
            }
            catch (e1) {
            }

            if (nId != "") {

                el = sourceRootNode.getElementById(nId);
                if (el != null) {
                    textFields[n].value = el.value;
                    if (el.type == "checkbox" || el.type == "radio") {
                        textFields[n].checked = el.checked;
                    }
                }
            }
        }
        catch (err) {
            alert("Error: " + n + err.message + ", " + err.description + ", " + textFields[n].name);
        }
    }
}

function printview(languageLetter, languageLCID, labelClose, labelPrint) {
    printview2(document, languageLetter, languageLCID, labelClose, labelPrint);
}

function printview2(documentNode, languageLetter, languageLCID, labelClose, labelPrint) {

    var w = window.open("", "PrintView", "width=600, height=600, scrollbars=yes, toolbars=no, resizable=yes");

    var htmlButton = '';
    htmlButton = htmlButton + "<div class='axaCmsForm'><p class='submit' style='text-align:right;'>";
    htmlButton = htmlButton + "<input align='right' type='button' class='submit left' style='position:static;' onclick='javascript:window.close()' ";
    htmlButton = htmlButton + "value='" + labelClose + "' />";
    htmlButton = htmlButton + "<input type='button' class='submit right' style='position:static;' onclick='javascript:window.print()'";
    htmlButton = htmlButton + " value='" + labelPrint + "'/></div></p>";

    var content = getContentElement(documentNode);
    var htmlContent = '';
    if (content != null) {
        htmlContent = "<div class='content'>" + htmlButton + content.innerHTML + "</div>";
    }
    else {
        htmlContent = "Print view cannot be shown.";
    }

    //var htmlHead = documentNode.getElementsByTagName('head')[0].innerHTML;

    var htmlHead = "";
    htmlHead = htmlHead + "<link rel=\"stylesheet\" type=\"text/css\" media=\"screen\" href=\"/_layouts/" + languageLCID + "/AxaCmsInternet/AXA.css\" />";
    htmlHead = htmlHead + "<link rel=\"stylesheet\" type=\"text/css\" media=\"screen\" href=\"/_layouts/" + languageLCID + "/AxaCmsInternet/HtmlEditorCustomStyles.css\" />";
    htmlHead = htmlHead + "<link rel=\"stylesheet\" type=\"text/css\" media=\"screen\" href=\"/_layouts/" + languageLCID + "/AxaCmsInternet/HtmlEditorTableFormats.css\" />";
    htmlHead = htmlHead + "<link rel=\"stylesheet\" type=\"text/css\" media=\"screen\" href=\"/_layouts/" + languageLCID + "/styles/core.css\" />";
    htmlHead = htmlHead + "<link rel=\"stylesheet\" type=\"text/css\" media=\"screen\" href=\"/_layouts/" + languageLCID + "/AxaCmsInternet/AXACORE.css\" />";

    htmlHead = htmlHead + "<style type=\"text/css\" media=\"screen\">";
    htmlHead = htmlHead + " div.footer { width:98.3%; } ";
    htmlHead = htmlHead + "</style>";

    htmlHead = htmlHead + "<style type=\"text/css\" media=\"print\">";
    htmlHead = htmlHead + " * { color: Black; font-family: arial; font-size:9pt; } ";
    htmlHead = htmlHead + " .Text { width:100%; } ";
    htmlHead = htmlHead + " div { overflow:visible !important; padding:0px !important; margin:0px !important; } ";
    htmlHead = htmlHead + " table { page-break-inside:always; } ";
    htmlHead = htmlHead + " input { display:none; } ";
    htmlHead = htmlHead + " div.form_container input, input.TextBox { display:inline; } ";
    htmlHead = htmlHead + " #captchacontrol { display:none; } ";
    htmlHead = htmlHead + " p.Headline03 { font-size:10pt; } ";
    htmlHead = htmlHead + " p.Headline02 { font-size:11pt; } ";
    htmlHead = htmlHead + " p.Headline01 { font-size:12pt; } ";
    htmlHead = htmlHead + " div.BroschureOrderWebPart table { border-width: 0px; border-style: outset; border-color: black; ";
    htmlHead = htmlHead + " border-collapse: collapse; background-color: white;  } ";
    htmlHead = htmlHead + " table.axaCmsContentTable { border-width: 0px; border-style: outset; border-color: black; ";
    htmlHead = htmlHead + " border-collapse: collapse; background-color: white;  } ";
    htmlHead = htmlHead + " table.axaCmsContentTable td,table.axaCmsContentTable th { border-width: 1px; padding: 1px; border-style: inset; border-color: black; background-color: white; border-bottom:1px solid black; } ";
    htmlHead = htmlHead + " div.BroschureOrderWebPart table td,table.axaCmsContentTable th { border-width: 1px; padding: 1px; border-style: inset; border-color: black; background-color: white; border-bottom:1px solid black; } ";
    htmlHead = htmlHead + " .align_right { text-align:right; } ";
    htmlHead = htmlHead + " div.content { margin-left:0; overflow:visible; width:100%; } ";
    htmlHead = htmlHead + " div.content_wide { margin-left:0; overflow:visible; width:100%; } ";
    htmlHead = htmlHead + " div.footer { width:100% !important; font-size:8pt !important; padding-top:2pt !important; border-top:1pt solid black !important; margin-top:15pt !important; } ";
    htmlHead = htmlHead + " img.Logo { margin-left:0px !important; } ";
    /*Changes for the DataView Screen print mode*/
    htmlHead = htmlHead + " div.form .dataview{display:none}";
    htmlHead = htmlHead + " div.form div.text{display:inline!important;}";
    htmlHead = htmlHead + " div.form div.choice{display:inline!important;}";
    htmlHead = htmlHead + " div.form div.note{display:inline!important;}";
    htmlHead = htmlHead + " div.form div.selection{display:inline!important;}";
    htmlHead = htmlHead + "</style>";

    htmlHead = htmlHead + "<style>";
    htmlHead = htmlHead + " div.page_areas{display:none} ";
    htmlHead = htmlHead + " div.content{padding-left: 10px; margin-top: 0px;} ";
    htmlHead = htmlHead + " div.submit { display:none; }";
    htmlHead = htmlHead + " div.service_bar{ display:none; }";
    htmlHead = htmlHead + " div.BroschureOrderWebPart.ButtonPanel{ display:none; }";
    htmlHead = htmlHead + "</style>";

    var htmlLogo = "<img style='margin:11px' class='Logo' src=\"_layouts/AxaCmsInternet/Images/axawin_FinanzSicher_zs_unten_RGB_" + languageLetter + ".gif\" />";
    var htmlCopyright = getElementsByClass('footer', documentNode, 'div')[0].getElementsByTagName('p')[0].innerHTML;
    var htmlFooter = "<div class='footer'><p>" + htmlCopyright + "</p></div>";
    var html = "<html><head>" + htmlHead + "</head><body><form>" + htmlLogo + htmlContent + htmlFooter + "</form></body></html>";

    w.document.open();
    w.document.write(html);

    // for firefox
    var tags = new Array("input", "textarea");
    copyNodeValues(documentNode, w.document, tags);

    w.document.close();
    w.print();
}

function NewWindow(thepageurl, thename, w, h, l, t, toolbar, location, directories, statusbar, resize, menubar, scroll, copyhistory) {
    LeftPosition = l;
    TopPosition = t;
    if (w != '') {
        settings = 'height=' + h + ',width=' + w + ',top=' + TopPosition + ',left=' + LeftPosition + ',scrollbars=' + scroll + ',resizable=' + resize + ',status=' + statusbar + ',toolbar=' + toolbar + ',location=' + location + ',directories=' + directories + ',menubar=' + menubar + ',copyhistory=' + copyhistory;
    } else {
        settings = 'height=' + h + ',top=' + TopPosition + ',left=' + LeftPosition + ',scrollbars=' + scroll + ',resizable=' + resize + ',status=' + statusbar + ',toolbar=' + toolbar + ',location=' + location + ',directories=' + directories + ',menubar=' + menubar + ',copyhistory=' + copyhistory;
    }
    var win = window.open(thepageurl, thename, settings);
    win.focus();
}

function UnCryptMailto(s, shift) {
    var n = 0;
    var r = "";
    for (var i = 0; i < s.length; i++) {
        n = s.charCodeAt(i);
        if (n >= 8364) { n = 128; }
        r += String.fromCharCode(n - (shift));
    }
    return r;
}
function linkTo_UnCryptMailto(s) {
    var shift = 3;
    location.href = UnCryptMailto(s, shift);
}
/*Workaround for SearchBoxEx with FireFox Enter-Key-Bug*/
function replaceOnKeyPress() {
    var myid = '';
    var mysubmitid = '';
    var elem = document.forms['aspnetForm'].elements;

    for (var i = 0; i < elem.length; i++) {
        if (elem[i].name.match("_InputKeywords")) {
            myid = elem[i].id;

            var myIdElements = new Array();
            myIdElements = myid.split('_');
            /*Get the generated random ID*/
            mysubmitid = myIdElements[myIdElements.length - 2];

        }
    }
    /*Build the function name for the Searchbox*/
    var theFunction = mysubmitid + "_Submit();"; /*"S478E6F4F_Submit();";*/

    var theInputID = myid;

    var txt = document.getElementById(theInputID);

    var browser = navigator.appName;

    if (txt && (browser == "Netscape")) {
        txt.onkeypress = function(e) {
            var key = String.fromCharCode(e.keyCode);

            if (key == "\n" || key == "\r") {
                eval(theFunction);
                return false;
            }
        }
    }
}
/*Adds the current year in the footer, default value is 2009, in case javascript is disabled on browser.
Function is used in masterpages*/
function addCopyrightYear() {
    var pTags = document.getElementsByTagName("p");
    var d = new Date();
    yr = d.getFullYear();

    var regExp = /2009/;
    /* The Copyright p Tag must always be the last p Tag of the html file */
    var pString = pTags[pTags.length - 1].firstChild.data;
    if (pString != null) {
        var match = pString.search(regExp);
        if (match != -1 && yr != 2009) {
            pTags[pTags.length - 1].firstChild.data = pTags[pTags.length - 1].firstChild.data.replace("2009", yr);
        }
    }
}