﻿
// -------------------------
function GetBrowserWindowSize() {
    var winW = 630, winH = 460;

    if (parseInt(navigator.appVersion) > 3) {

        if (navigator.appName == "Netscape") {
            winW = window.innerWidth;
            winH = window.innerHeight;
        }

        if (navigator.appName.indexOf("Microsoft") != -1) {
            try {
                winW = document.body.offsetWidth;
                winH = document.body.offsetHeight;
            } catch (e) {
            }
        }
    }


    return ("Window width = " + $(window).width() + " Window height = " + $(window).height())
}

// -----------------------------   
function GetScreenSize() {
    var screenW = 640, screenH = 480;

    if (parseInt(navigator.appVersion) > 3) {
        screenW = screen.width;
        screenH = screen.height;
    }

    return ("Screen width = " + screenW + " Screen height = " + screenH);
}

// -------------------------------
function GetOperationSystem() {
    var OSName = "Unknown OS";
    if (navigator.appVersion.indexOf("Win") != -1) OSName = "Windows";
    if (navigator.appVersion.indexOf("Mac") != -1) OSName = "MacOS";
    if (navigator.appVersion.indexOf("X11") != -1) OSName = "UNIX";
    if (navigator.appVersion.indexOf("Linux") != -1) OSName = "Linux";

    return (OSName);
}

//------------------------------------------

function GetBrowserName() {
    var nVer = navigator.appVersion;
    var nAgt = navigator.userAgent;
    var browserName = navigator.appName;
    var fullVersion = '' + parseFloat(navigator.appVersion);
    var majorVersion = parseInt(navigator.appVersion, 10);
    var nameOffset, verOffset, ix;

    // In Opera, the true version is after "Opera" or after "Version"
    if ((verOffset = nAgt.indexOf("Opera")) != -1) {
        browserName = "Opera";
        fullVersion = nAgt.substring(verOffset + 6);
        if ((verOffset = nAgt.indexOf("Version")) != -1)
            fullVersion = nAgt.substring(verOffset + 8);
    }
    // In MSIE, the true version is after "MSIE" in userAgent
    else if ((verOffset = nAgt.indexOf("MSIE")) != -1) {
        browserName = "Microsoft Internet Explorer";
        fullVersion = nAgt.substring(verOffset + 5);
    }
    // In Chrome, the true version is after "Chrome" 
    else if ((verOffset = nAgt.indexOf("Chrome")) != -1) {
        browserName = "Chrome";
        fullVersion = nAgt.substring(verOffset + 7);
    }
    // In Safari, the true version is after "Safari" or after "Version" 
    else if ((verOffset = nAgt.indexOf("Safari")) != -1) {
        browserName = "Safari";
        fullVersion = nAgt.substring(verOffset + 7);
        if ((verOffset = nAgt.indexOf("Version")) != -1)
            fullVersion = nAgt.substring(verOffset + 8);
    }
    // In Firefox, the true version is after "Firefox" 
    else if ((verOffset = nAgt.indexOf("Firefox")) != -1) {
        browserName = "Firefox";
        fullVersion = nAgt.substring(verOffset + 8);
    }
    // In most other browsers, "name/version" is at the end of userAgent 
    else if ((nameOffset = nAgt.lastIndexOf(' ') + 1) < (verOffset = nAgt.lastIndexOf('/'))) {
        browserName = nAgt.substring(nameOffset, verOffset);
        fullVersion = nAgt.substring(verOffset + 1);
        if (browserName.toLowerCase() == browserName.toUpperCase()) {
            browserName = navigator.appName;
        }
    }
    // trim the fullVersion string at semicolon/space if present
    if ((ix = fullVersion.indexOf(";")) != -1) fullVersion = fullVersion.substring(0, ix);
    if ((ix = fullVersion.indexOf(" ")) != -1) fullVersion = fullVersion.substring(0, ix);

    majorVersion = parseInt('' + fullVersion, 10);
    if (isNaN(majorVersion)) {
        fullVersion = '' + parseFloat(navigator.appVersion);
        majorVersion = parseInt(navigator.appVersion, 10);
    }
    return browserName + " " + fullVersion;
}

function GetPath() {
    return document.location;
}

function GetDate() {
    return new Date();
}

function GetBrowserInfo() {
    return GetBrowserWindowSize() + "---" + GetScreenSize() + "---" + GetOperationSystem() +
               "---" + GetBrowserName() + "---" + GetPath() + "---" + GetDate();
}


// alert(GetBrowserInfo());

// --------------------------
var SilverlightVersion = "";

function GetPluginInfo() {
    var parts = Array("ver-major", "ver-minor", "ver-build", "ver-revision");

    //try firefox/non-IE version.
    var nav = navigator.plugins["Silverlight Plug-In"];
    if (nav) {
        for (var i = 0; i < 4; i++) {
            SilverlightVersion += parseInt(nav.description.split(".")[i]).toString() + ".";
        }

        return SilverlightVersion.substr(0, SilverlightVersion.length - 1);
    } else {
        //try the IE one now.
        try {
            var control = new ActiveXObject('AgControl.AgControl');
            //the following would be faster with a binary search, but this is "fast enough" for now. 
            var vers = Array(1, 0, 0, 0);
            loopMatch(control, vers, 0, 1);
            loopMatch(control, vers, 1, 1);
            loopMatch(control, vers, 2, 10000);
            loopMatch(control, vers, 2, 1000);
            loopMatch(control, vers, 2, 100);
            loopMatch(control, vers, 2, 10);
            loopMatch(control, vers, 2, 1);
            loopMatch(control, vers, 3, 1);
            for (var i = 0; i < 4; i++) {
                SilverlightVersion += vers[i].toString() + ".";
            }

            return SilverlightVersion.substr(0, SilverlightVersion.length - 1);
        } catch (e) {
            return "Silverlight not installed.";
        }
    }
}

function loopMatch(control, vers, idx, inc) {
    while (IsSupported(control, vers)) {
        vers[idx] += inc;
    }
    vers[idx] -= inc;
}

function IsSupported(control, ver) {
    return control.isVersionSupported(ver[0] + "." + ver[1] + "." + ver[2] + "." + ver[3]);
}

function GetFlashPlayerInfo() {
    var playerVersion = swfobject.getFlashPlayerVersion();

    return playerVersion.major + "." + playerVersion.minor + "." + playerVersion.release;
}


