function isIE() {
    var ua = window.navigator.userAgent; //Check the userAgent property of the window.navigator object
    var msie = ua.indexOf('MSIE '); // IE 10 or older
    var trident = ua.indexOf('Trident/'); //IE 11

    return (msie > 0 || trident > 0);
}
if(isIE()) {
document.getElementById('outer').style.position='absolute';
document.getElementById('outer').style.left='33px';
document.getElementById('header').style.left='25px';
document.getElementById('header').getElementsByTagName('img')[0].src='/r/eidgpng/eidgpng_de.png';
document.getElementById('header').getElementsByTagName('img')[0].style.marginLeft='12px';
document.getElementById('header').style.marginBottom='22px';
}

(function () {
    const fadeTime = 333;
    const restoreTime = 7777;

    function restore() {
        document.documentElement.style.transition = '';
        document.documentElement.style.opacity = '1';
    }

    function fadeAndGo(url) {
        // Zielseite bereits anfordern
        try {
            fetch(url, {
                method: 'GET',
                credentials: 'same-origin'
            }).catch(function () {});
        } catch (e) {}

        document.documentElement.style.transition =
            'opacity ' + fadeTime + 'ms ease';

        document.documentElement.style.opacity = '0';

        setTimeout(function () {
            window.location.href = url;
        }, fadeTime);

        setTimeout(restore, restoreTime);
    }

    document.addEventListener('click', function (event) {
        const link = event.target.closest('a');

        if (!link || !link.href) return;
        if (link.target === '_blank') return;
        if (link.hasAttribute('download')) return;

        if (
            event.metaKey ||
            event.ctrlKey ||
            event.shiftKey ||
            event.altKey
        ) {
            return;
        }

        const url = new URL(link.href, window.location.href);

        if (
            url.protocol !== 'http:' &&
            url.protocol !== 'https:'
        ) {
            return;
        }

        if (
            url.pathname === window.location.pathname &&
            url.search === window.location.search &&
            url.hash
        ) {
            return;
        }

        event.preventDefault();

        fadeAndGo(link.href);
    }, true);

    window.addEventListener('pageshow', restore);
})(); 