﻿
if (!VisualOn)
    var VisualOn = {};

VisualOn.Browser = {
    browserName: navigator.appName,
    fullVersion: '' + parseFloat(navigator.appVersion),
    majorVersion: parseInt(navigator.appVersion, 10),

    init: function() {
        var nVer = navigator.appVersion;
        var nAgt = navigator.userAgent;
        var nameOffset, verOffset, ix;

        // In MSIE, the true version is after "MSIE" in userAgent
        if ((verOffset = nAgt.indexOf("MSIE")) != -1) {
            this.browserName = "Microsoft Internet Explorer";
            this.fullVersion = nAgt.substring(verOffset + 5);
        }
        // In Opera, the true version is after "Opera" 
        else if ((verOffset = nAgt.indexOf("Opera")) != -1) {
            this.browserName = "Opera";
            this.fullVersion = nAgt.substring(verOffset + 6);
        }
        // In Chrome, the true version is after "Chrome" 
        else if ((verOffset = nAgt.indexOf("Chrome")) != -1) {
            this.browserName = "Chrome";
            this.fullVersion = nAgt.substring(verOffset + 7);
        }
        // In Safari, the true version is after "Safari" 
        else if ((verOffset = nAgt.indexOf("Safari")) != -1) {
            this.browserName = "Safari";
            this.fullVersion = nAgt.substring(verOffset + 7);
        }
        // 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('/'))) {
            this.browserName = nAgt.substring(nameOffset, verOffset);
            this.fullVersion = nAgt.substring(verOffset + 1);
            if (this.browserName.toLowerCase() == this.browserName.toUpperCase()) {
                this.browserName = navigator.appName;
            }
        }
        // trim the fullVersion string at semicolon/space if present
        if ((ix = this.fullVersion.indexOf(";")) != -1) this.fullVersion = this.fullVersion.substring(0, ix);
        if ((ix = this.fullVersion.indexOf(" ")) != -1) this.fullVersion = this.fullVersion.substring(0, ix);

        this.majorVersion = parseInt('' + this.fullVersion, 10);
        if (isNaN(this.majorVersion)) {
            this.fullVersion = '' + parseFloat(navigator.appVersion);
            this.majorVersion = parseInt(navigator.appVersion, 10);
        }
    },

    isIE7orOlder: function() {
        if (this.browserName == "Microsoft Internet Explorer" && this.majorVersion < 8)
            return true;
        else
            return false;
    }
};


VisualOn.Browser.init();