﻿// browser.js

function BrowserDetect() {
        var ua = navigator.userAgent.toLowerCase();

        // browser name
        this.isGecko     = (ua.indexOf('gecko') != -1);
        this.isMozilla   = (this.isGecko && ua.indexOf("gecko/") + 14 == ua.length);
        this.isNS        = ( (this.isGecko) ? (ua.indexOf('netscape') != -1) : ( (ua.indexOf('mozilla') != -1) && (ua.indexOf('spoofer') == -1) && (ua.indexOf('compatible') == -1) && (ua.indexOf('opera') == -1) && (ua.indexOf('webtv') == -1) && (ua.indexOf('hotjava') == -1) ) );
        this.isIE        = ( (ua.indexOf("msie") != -1) && (ua.indexOf("opera") == -1) && (ua.indexOf("webtv") == -1) );

        // spoofing and compatible browsers
        this.isIECompatible = ( (ua.indexOf("msie") != -1) && !this.isIE);
        this.isNSCompatible = ( (ua.indexOf("mozilla") != -1) && !this.isNS && !this.isMozilla);

        // browser version
        this.versionMinor = parseFloat(navigator.appVersion);

        // correct version number
        if (this.isNS && this.isGecko) {
                this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('/') + 1 ) );
        } else if (this.isIE && this.versionMinor >= 4) {
                this.versionMinor = parseFloat( ua.substring( ua.indexOf('msie ') + 5 ) );
        }

        this.versionMajor = parseInt(this.versionMinor);
        this.geckoVersion = ( (this.isGecko) ? ua.substring( (ua.lastIndexOf('gecko/') + 6), (ua.lastIndexOf('gecko/') + 14) ) : -1 );

        // dom support
        this.isDOM1 = (document.getElementById);
        this.isDOM2Event = (document.addEventListener && document.removeEventListener);

        // css compatibility mode
        this.mode = document.compatMode ? document.compatMode : 'BackCompat';

        // specific browser shortcuts
        this.isNS7x = (this.isNS && this.versionMajor == 7);
        this.isMozilla11x = (this.isMozilla && this.versionMinor >= 1.1);
        this.isIE6x = (this.isIE && this.versionMajor == 6);
        this.isIE6up = (this.isIE && this.versionMajor >= 6);
}