﻿var BrowserDetect = {
    init: function() {
        this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
        this.version = this.searchVersion(navigator.userAgent) ||
		this.searchVersion(navigator.appVersion) ||
		"an unknown version";
    },
    searchString: function(data) {
        for (var i = 0; i < data.length; i++) {
            var dataString = data[i].string;
            var dataProp = data[i].prop;
            this.versionSearchString = data[i].versionSearch || data[i].identity;
            if (dataString) {
                if (dataString.indexOf(data[i].subString) != -1)
                    return data[i].identity;
            }
            else
                if (dataProp)
                return data[i].identity;
        }
    },
    searchVersion: function(dataString) {
        var index = dataString.indexOf(this.versionSearchString);
        if (index == -1)
            return;
        return parseFloat(dataString.substring(index + this.versionSearchString.length + 1));
    },
    dataBrowser: [{
        string: navigator.userAgent,
        subString: "Chrome",
        identity: "Chrome"
    },
	{
	    string: navigator.vendor,
	    subString: "Apple",
	    identity: "Safari"
	}, {
	    prop: window.opera,
	    identity: "Opera"
	}, {
	    string: navigator.userAgent,
	    subString: "Flock",
	    identity: "Flock"
	}, {
	    string: navigator.userAgent,
	    subString: "Firefox",
	    identity: "Firefox"
	}, {
	    string: navigator.userAgent,
	    subString: "MSIE",
	    identity: "IExplorer",
	    versionSearch: "MSIE"
}]
};
var BrowserCompatible = {
    check: function() {
        BrowserDetect.init();
        if ((this.useBlackList && this.unCompatibleBrowsers[BrowserDetect.browser] && BrowserDetect.version <= this.unCompatibleBrowsers[BrowserDetect.browser]) ||
		    (!this.useBlackList && (BrowserDetect.version < this.compatibleBrowsers[BrowserDetect.browser] || !this.compatibleBrowsers[BrowserDetect.browser]))) {
            if (!this.readCookie('browsercheck_dontShowAgain'))
                this.showWarning();
        }
    },
    getStyle: function(el, styleProp) {
        var x = el;
        if (x.currentStyle)
            var y = x.currentStyle[styleProp];
        else
            if (window.getComputedStyle)
            var y = document.defaultView.getComputedStyle(x, null).getPropertyValue(styleProp);
        return y;
    },
    cookieNamePrefix: "TAInvest_",
    createCookie: function(name, value, days) {
        if (days) {
            var date = new Date();
            date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
            var expires = ";expires=" + date.toGMTString();
        }
        else
            var expires = "";
        document.cookie = BrowserCompatible.cookieNamePrefix + name + "=" + value + expires + ";path=/";
    },
    readCookie: function(name) {
        var nameEQ = BrowserCompatible.cookieNamePrefix + name + "=";
        var ca = document.cookie.split(';');
        for (var i = 0; i < ca.length; i++) {
            var c = ca[i];
            while (c.charAt(0) == ' ')
                c = c.substring(1, c.length);
            if (c.indexOf(nameEQ) == 0)
                return c.substring(nameEQ.length, c.length);
        }
        return null;
    },

    eraseCookie: function(name) {
        this.createCookie(name, "", -1);
    },
    showWarning: function() {
        if (!this.lang) {
            this.lang = navigator.language || navigator.browserLanguage;
            if (!this.langTranslations[this.lang]) this.lang = "en";
        }
        var bg = document.createElement("div");
        bg.id = "browsercheck_bg";
        bg.style["background"] = "#fff";
        bg.style["filter"] = "alpha(opacity=70)";
        bg.style["-moz-opacity"] = "0.70";
        bg.style["opacity"] = "0.7";
        bg.style["position"] = "fixed";
        if (BrowserDetect.browser == "IExplorer" && BrowserDetect.version < 7)
            bg.style["position"] = "absolute";
        bg.style["z-index"] = "9998";
        bg.style["top"] = "0";
        bg.style["left"] = "0";
        bg.style["height"] = (screen.availHeight + 300) + "px";
        bg.style["width"] = (screen.availWidth + 300) + "px";

        var warning_html = "";
        if (this.allowCancel)
            warning_html += '<a href="javascript:BrowserCompatible.cancel()" style="background:url(' + this.images['cancel'] + ') no-repeat; height:15px; width:16px; position:absolute; right:10px; top:7px;" title="' + this.langTranslations[this.lang]['cancel'] + '"></a>';
        warning_html += '<div id="browsercheck_title" style="font-family:arial; font-size:24px; color:#000; margin:15px;">' + this.langTranslations[this.lang]['title'] + '</div>';
        warning_html += '<div id="browsercheck_description" style="font-family:arial; font-size:12px; color:#707070; margin:15px;">' + this.langTranslations[this.lang]['description'] + '</div>';
        warning_html += '<div id="browsercheck_recomendation" style="font-family:arial; font-size:12px; color:#707070; margin:15px;">' + this.langTranslations[this.lang]['recomendation'] + '</div>';
        for (var i = 0; i < this.offeredBrowsers.length; i++) {
            warning_html += '<a href="' + this.browsersList[this.offeredBrowsers[i]].link + '" style="height:60px; width:165px; display:block; float:left; margin:15px; text-decoration:none; background: url(' + this.browsersList[this.offeredBrowsers[i]].image + ') no-repeat;" target="_blank"> </a>';

        }
        warning_html += '<br/><br/>'
        warning_html += '<a href="javascript:BrowserCompatible.cancel();" class="compatibilityCloseLink">' + this.langTranslations[this.lang]['remindMeLater'] + '</a>';
        if (this.allowToHide)
            warning_html += '<div style="clear:both;font-family:arial; font-size:12px; color:#707070; padding:7px 15px;"><label><input type="checkbox" id="browsercheck_dontShowAgain" onclick="BrowserCompatible.dontShowAgain()" />' + this.langTranslations[this.lang]['dontShowAgain'] + '</label></div>';
        warning_html += '<br/><br/><br/>'
        var warning = document.createElement("div");
        warning.id = "browsercheck_warning";
        warning.style["background"] = "url(" + this.images['background'] + ") no-repeat";
        warning.style["padding"] = "2px";
        warning.style["width"] = "600px";
        warning.style["height"] = "400px";
        warning.style["position"] = "fixed";
        if (BrowserDetect.browser == "IExplorer" && BrowserDetect.version < 7)
            warning.style["position"] = "absolute";
        warning.style["z-index"] = "9999";
        warning.style["top"] = ((window.innerHeight || document.body.parentNode.offsetHeight) - 400) / 2 + "px";
        warning.style["left"] = ((window.innerWidth || document.body.parentNode.offsetWidth) - 600) / 2 + "px";
        warning.innerHTML = warning_html;

        this.old_overflow_style = this.getStyle(document.body.parentNode, "overflow") || this.getStyle(document.body, "overflow");
        if (BrowserDetect.browser == "Opera" && this.old_overflow_style == "visible")
            this.old_overflow_style = "auto";
        document.body.parentNode.style["overflow"] = "hidden";
        document.body.style["overflow"] = "hidden";

        document.body.appendChild(bg);
        document.body.appendChild(warning);

        if (window.addEventListener) {
            window.addEventListener('resize', this.warningPosition, false);
        }
        else {
            window.attachEvent('onresize', this.warningPosition);
        }
        var allVisibleInputs = $("select:visible");
        $(allVisibleInputs).each(function() {
            $(this).attr("ThisWasVisible", "true");
            $(this).hide();
        });
    },
    warningPosition: function() {
        var warning = document.getElementById('browsercheck_warning');
        warning.style["top"] = ((window.innerHeight || document.body.parentNode.offsetHeight) - 400) / 2 + "px";
        warning.style["left"] = ((window.innerWidth || document.body.parentNode.offsetWidth) - 600) / 2 + "px";
    },
    allowCancelAndHide: true,
    dontShowAgain: function() {
        var inpDontShowAgain;
        var browsercheck_dontShowAgain = document.getElementById('browsercheck_dontShowAgain');
        if (browsercheck_dontShowAgain) {
            inpDontShowAgain = browsercheck_dontShowAgain.checked;
        }
        else {
            inpDontShowAgain = BrowserCompatible.allowCancelAndHide;
        }
        var dontShowAgain = this.readCookie('browsercheck_dontShowAgain');
        if (inpDontShowAgain) {
            this.createCookie('browsercheck_dontShowAgain', 'on', this.cookiesExpire);
        }
        else {
            this.eraseCookie('browsercheck_dontShowAgain');
        }
    },
    cancel: function() {
        var bg = document.getElementById('browsercheck_bg');
        var warning = document.getElementById('browsercheck_warning');
        bg.parentNode.removeChild(bg);
        warning.parentNode.removeChild(warning);
        document.body.parentNode.style["overflow"] = this.old_overflow_style;
        if (BrowserDetect.browser != "IExplorer")
            document.body.style["overflow"] = this.old_overflow_style;
        document.onresize = this.resize_function;
        if (BrowserCompatible.allowCancelAndHide) {
            BrowserCompatible.dontShowAgain();
        }
        $("[ThisWasVisible=true]").show();
        if (window.removeEventListener) {
            window.removeEventListener('resize', this.warningPosition, false);
        }
        else {
            window.detachEvent('onresize', this.warningPosition);
        }
    },
    old_overflow_style: "",
    resize_function: null,
    allowCancel: true,
    allowToHide: false,
    cookiesExpire: 1,
    images: {
        'background': "/investe/site_images/BrowserCompatibility/background_browser.gif",
        'cancel': "/investe/site_images/BrowserCompatibility/close-button.png"
    },
    useBlackList: true,
    compatibleBrowsers: {
        "Opera": 9.25,
        "Firefox": 2,
        "IExplorer": 7,
        "Safari": 525.17,
        "Flock": 1.1,
        "Chrome": 1
    },
    unCompatibleBrowsers: {
        "IExplorer": 6
    },
    offeredBrowsers: ["IExplorer", "Firefox", "Chrome", "Safari", "Opera", "Flock"],
    browsersList: {
        "Chrome": {
            "image": "/investe/site_images/BrowserCompatibility/chrome.gif",
            "link": "http://www.google.com/chrome/"
        },
        "Opera": {
            "image": "/investe/site_images/BrowserCompatibility/opera.gif",
            "link": "http://www.opera.com/products/desktop/"
        },
        "Firefox": {
            "image": "/investe/site_images/BrowserCompatibility/firefox.gif",
            "link": "http://www.mozilla-europe.org/"
        },
        "IExplorer": {
            "image": "/investe/site_images/BrowserCompatibility/iexplorer.gif",
            "link": "http://www.microsoft.com/windows/internet-explorer/download-ie.aspx"
        },
        "Safari": {
            "image": "/investe/site_images/BrowserCompatibility/safari.gif",
            "link": "http://www.apple.com/safari/"
        },
        "Flock": {
            "image": "/investe/site_images/BrowserCompatibility/flock.gif",
            "link": "http://www.flock.com/"
        }
    },
    lang: "",
    langTranslations: {
        "en": {
            "title": "Obsolete browser",
            "description": "Your browser is obsolete, which means it does not contain all of the necessary functions for the correct working of many current web sites. Modern web sites are created to be convenient and effective for you and, together with improvement of web sites themselves, browsers continue to improve. In addition, older browsers have many security glitches which can be maliciously abused to steal personal and financial information; therefore by upgrading your web browser you not only benefit from an enhanced web experience, but ensure that your private data is better protected.",
            "recomendation": "We recommend using the latest version of one of the following browsers. All are free, quick to install and won't cost you anything.",
            "cancel": "Close this warning",
            "dontShowAgain": "Don't show this warning again",
            "remindMeLater": "Remind me later"
        },
        "fr": {
            "title": "Votre navigateur est obsolète",
            "description": "Nous nous excusons immédiatement pour ce language ferme mais le navigateur que vous utilisez a neuf ans, ce qui représente une éternité sur internet ! Avec cette version d’Internet Explorer votre visite sur notre nouveau site risque d'être désagréable.",
            "recomendation": "Nous vous proposons dès lors de télécharger une nouvelle version d'un navigateur repris dans la liste ci-dessous. Cela ne prend que quelques minutes et en plus, c’est gratuit ! Vous pouvez exiger de nous que nous optimalisons notre site pour les versions récentes de tous les navigateurs de la liste. Des petits défauts restent cependant possible au début.",
            "cancel": "Fermer cet avertissement",
            "dontShowAgain": "Ne plus montrer cet avertissement",
            "remindMeLater": "Rappelez moi plus tard"
        },
        "nl": {
            "title": "Uw browser is verouderd",
            "description": "Wij excuseren ons onmiddellijk voor dit ferme taalgebruik maar de browser die u gebruikt om op het internet te surfen is negen jaar oud. Een eeuwigheid op het net ! Met deze versie van Internet Explorer zult u weinig plezier beleven aan onze nieuwe website. ",
            "recomendation": "Wij stellen u daarom voor om een nieuwe browser te downloaden uit het lijstje hieronder. Een kleine moeite en bovendien gratis. Van ons mag u verwachten dat wij onze website optimaliseren voor de recentste versies van alle genoemde browsers. Schoonheidsfoutjes zijn in het begin wel mogelijk.",
            "cancel": "Sluit deze waarschuwing",
            "dontShowAgain": "Toon deze waarschuwing niet opnieuw",
            "remindMeLater": "Herinner er mij later nog eens aan"
        },
		"po": {
            "title": "Browser obsoleto",
            "description": "O seu browser está obsoleto, o que significa que não contem todas as funcionalidades necessárias à visualização correcta de muitos sites. Os sites modernos são criados de forma a serem convenientes e efectivos para o utilizador e, conjuntamente com as melhorias nos sites, os browsers estão em melhoria continua. Para alem disso os browsers mais antigos tem vários problemas de segurança que podem permitir a utilizadores maliciosos obter informações pessoais e financeiras; Portanto ao actualizar o seu browser não só benificiará de uma melhor experiência na web como ainda assegurará que os seus dados pessoais estarão melhor protegidos.",
            "recomendation": "Recomendamos a utilização da última versão de um dos seguintes browsers. São todos gratuítos e rápidos de instalar.",
            "cancel": "Fechar este aviso",
            "dontShowAgain": "Não mostrar este aviso de novo",
            "remindMeLater": "Lembrar-me mais tarde"
        }
    }
}
