/***************************************************************************************************
*
*    Author: Copyright (C) 2007-2010 Marek Sienczak
*     Email: support@imarqs.com
*  Homepage: http://imarqs.com
*  Released: 2/25/2007
*   Updated: 8/3/2010
*/

var userAgent = navigator.userAgent.toLowerCase();
var appName = navigator.appName;
var appVersion = navigator.appVersion;
var userLanguage = navigator.userLanguage;
var platform = navigator.platform;

var userSystem = "";
var appCodeName = "";
var appVersionNumber = 0;
var navigatorInfo = "";

var navigatorWarning = lang == "pl" ?
                           "Zainstaluj nowszą wersję przeglądarki ze względu na większy poziom \
                            bezpieczeństwa oraz lepszą wydajność." :
                           "Install a newer web browser. This version is too old. You should to do \
                            this for more security and better performance.";

var strNav = lang == "pl" ? "Przeglądarka" : "Web browser";
var strVer = lang == "pl" ? "Wersja" : "Version";
var strLang = lang == "pl" ? "Język" : "Language";
var strSys = lang == "pl" ? "System" : "System";
var strUnknown = lang == "pl" ? "Nieznany" : "Unknown";
var strPL = lang == "pl" ? "polski" : "Polish";
var strEN = lang == "pl" ? "angielski" : "English";

var navigators = new Array("msie", 8.0,
                           "Firefox", 3.6,
                           "opera", 9.80,
                           "konqueror", 3.5,
                           "Epiphany", 2.16,
                           "SeaMonkey", 1.1,
                           "netscape", 8.1,
                           "K-Meleon", 1.02,
                           "Chrome", 4.0,
                           "Safari", 528.16,
                           "Camino", 1.0);

function SetNavigatorWarning() {
    navigatorInfo = "<p style='color:red;line-height:1.3em;'>" + navigatorWarning + "</p>";
}

function CheckUserNavigator() {
    var index;
    for (var i = 0; i < navigators.length; i += 2)
        if ((index = userAgent.indexOf(navigators[i].toLowerCase())) != -1) {
        appVersionNumber = userAgent.substr(index + navigators[i].length + 1).match(/\d+\.\d+/);
        if (appVersionNumber < navigators[i + 1])
            SetNavigatorWarning();
        if ((navigators[i].charCodeAt(0) & 0x20) == 0)
            appName = navigators[i];
        appCodeName = navigators[i].toLowerCase();
        return true;
    }
    return false;
}

function GetUserSystem() {
    if (platform.toLowerCase().indexOf("win") != -1) {
        /* http://msdn.microsoft.com/workshop/author/dhtml/overview/aboutuseragent.asp */
        var windows = new Array("nt 6.1", "7", "nt 6.0", "Vista", "nt 5.2", "2003 Server",
                                "nt 5.1", "XP", "nt 5.01", "2000 SP1", "nt 5.0", "2000",
                                "nt 4.0", "4.0", "98; win 9x 4.90", "Millennium", "98",
                                "98", "95", "95");
        for (var i = 0; i < windows.length; i += 2)
            if (userAgent.indexOf("windows " + windows[i]) != -1) {
            userSystem = " " + windows[i + 1];
            break;
        }
        userSystem = "Windows" + userSystem;
    }
    else if (platform.toLowerCase().indexOf("linux") != -1) {
        var linux = new Array("SUSE", "Fedora", "Ubuntu", "Mandriva",
                              "Debian", "Gentoo", "Slackware");
        for (var type in linux)
            if (userAgent.indexOf(linux[type].toLowerCase()) != -1) {
            userSystem = linux[type] + " ";
            break;
        }
        userSystem += "Linux";
    }
    else if (platform.toLowerCase().indexOf("mac") != -1) {
        userSystem = "Mac OS";
        if (userAgent.toLowerCase().indexOf("mac os x") != -1) {
            var macosx = new Array("10_6", "Snow Leopard", "10_5", "Leopard", "10_4", "Tiger",
                                "10_3", "Panther", "10_2", "Jaguar", "10_1", "Puma",
                                "10_0", "Cheetah");
            for (var i = 0; i < macosx.length; i += 2)
                if (userAgent.indexOf("mac os x " + macosx[i]) != -1) {
                    systemVersion = userAgent.match(/mac os x\s+([\d_]+)?/i).slice(1);
                    codeName = macosx[i + 1];
                    break;
                }
                userSystem += " X " + systemVersion.toString().replace(/_/g, ".") + " (" + codeName + ")";
        }
    }
    }
    else if (platform.toLowerCase().indexOf("iphone") != -1) {
        var systemVersionRegEx = /iphone\s+os\s+([\d_]+)?/i;
        var systemVersion = userAgent.match(systemVersionRegEx).slice(1);
        userSystem = "iPhone OS " + systemVersion.toString().replace(/_/g, ".");
    }
    else if (platform.toLowerCase().indexOf("unix") != -1) {
        userSystem = "Unix";
    }
    else
        userSystem = strUnknown;
}

function CheckUserLanguage() {
    var userLanguages = new Array("pl", strPL, "en", strEN);
    var userLanguageRegEx = /(?=;\s*([a-z]{2})(?:-[A-Z,a-z]{2})?\s*(?:\)|;){1})/;
    if (typeof (userLanguage) == "undefined")
        if (typeof (language) != "undefined")
        userLanguage = navigator.language.substr(0, 2);
    else
        userLanguage = appVersion.match(userLanguageRegEx).slice(1);
    for (var i = 0; i < userLanguages.length; i += 2)
        if (userLanguage.toString().substr(0, 2) == userLanguages[i])
        userLanguage = userLanguages[i + 1];
}

function CheckUserEnvironment() {
    CheckUserNavigator();
    CheckUserLanguage();
    GetUserSystem();
}

CheckUserEnvironment();

function GetNavigatorInfo() {
    navigatorInfo +=
        "<table cellpadding='0' cellspacing='2' border='0'>\
          <tr>\
            <td align='right'><strong>" + strNav + ": </strong></td>\
            <td align='left' style='color:#0066cc;'>" + appName + "</td>\
          </tr>\
          <tr>\
            <td align='right'><strong>" + strVer + ": </strong></td>\
            <td align='left' style='color:#0066cc;'>" + appVersionNumber + "</td>\
          </tr>\
          <tr>\
            <td align='right'><strong>" + strLang + ": </strong></td>\
            <td align='left' style='color:#0066cc;'>" + userLanguage + "</td>\
          </tr>\
          <tr>\
            <td align='right'><strong>" + strSys + ": </strong></td>\
            <td align='left' style='color:#0066cc;'>" + userSystem + "</td>\
          </tr>\
        </table>";
    document.getElementById("navinfo").innerHTML = navigatorInfo;
}