/*
   UserAgent.js
   UserAgent Object API
   gcpeters Wed., 10/03/01
   
   Copyright (c) 2001 Grant C. Peters.
   This code is free for use, and modify 
   with the precept that this copyright information
   remains with all implementations of this source code.
   
   Thank you, and enjoy.
*/
function UserAgent() {
    //store refs to navigator props appName, and userAgent
    with (navigator) {
        this.ua = userAgent;
        this.an = appName;
        this.av = appVersion;
    }
    //initialize browser related props
    this.ie = this.an.indexOf('Microsoft')  != -1;
    this.ns = this.an.indexOf('Netscape')   != -1;
    this.n6 = this.ua.indexOf('Netscape6')  != -1;
    this.n7 = this.ua.indexOf('Netscape/7') != -1;
    this.op = this.ua.indexOf('Opera')      != -1;
    this.mz = this.ua.indexOf('Gecko')      != -1;
    //make sure there is no spoofing, Opera can spoof IE and Netscape
    if(this.op) {
        this.ie = false;
        this.ns = false;
        this.n6 = false;
        this.n7 = false;
        this.mz = false;
    }
    if(this.n6) {
        this.ns = false;
        this.mz = false;
    }
    if(this.n7) {
        this.ns = false;
        this.mz = false;
    }
    if(this.mz) {
        this.n7 = false;
        this.n6 = false;
        this.ns = false;
    }
    
    if(this.ie)
        this.version = parseFloat(this.ua.substring(this.ua.indexOf('MSIE')+('MSIE'.length + 1), this.ua.length));
    else if(this.op || this.ns || this.mz || this.n6)
        this.version = parseFloat(this.av);
    else if(this.n7)
        this.version = parseFloat(this.ua.substring(this.ua.indexOf('Netscape/') + 9));
    
    this.win = this.ua.indexOf('Win')    != -1;
    this.mac = this.ua.indexOf('Mac')    != -1;
    //this.lyn = this.ua.indexOf('Lynux')  != -1;
    
    if(this.win) {
        this.platform = 'Windows';
        if(this.ua.indexOf('Windows NT 5.0') != -1 || this.ua.indexOf('Windows 2000') != -1)
            this.osVersion = '2000';
        if(this.ua.indexOf('Windows NT 4.0') != -1 || this.ua.indexOf('WinNT4.0') != -1)
            this.osVersion = 'NT 4.0';
        else if(this.ua.indexOf('Windows 98') != -1)
            this.osVersion = '98';
        else if(this.ua.indexOf('Windows 95') != -1)
            this.osVersion = '95';
        this.os = this.platform+' '+this.osVersion;
    } else if(this.mac) {
        this.platform = 'Macintosh';
        this.osVersion = 0;
        this.os = this.platform;
    } else if(this.lyn) {
        this.platform = 'Lynux';
    } else {
        this.platform = 'Other';
        this.osVersion = 'Unknown';
        this.os = 'Other';
    }
    
    if(this.ie)
        this.browser = 'Internet Explorer';
    else if (this.ns || this.n6 || this.n7)
        this.browser = 'Netscape';
    else if (this.op)
        this.browser = 'Opera';
    else if (this.mz)
        this.browser = 'Mozilla Seamonkey';
    else
        this.browser = 'Other';
}//end UserAgent()

    UserAgent.prototype.isIE = _isIE;
    UserAgent.prototype.isNS = _isNS;
    UserAgent.prototype.isN6 = _isN6;
    UserAgent.prototype.isN7 = _isN7;
    UserAgent.prototype.isMZ = _isMZ;
    UserAgent.prototype.isOP = _isOP;
    
    UserAgent.prototype.isWIN = _isWIN;
    UserAgent.prototype.isMAC = _isMAC;
    UserAgent.prototype.isLYN = _isLYN;
    
    UserAgent.prototype.getVersion = _getVersion;
    UserAgent.prototype.getBrowser = _getBrowser;
    UserAgent.prototype.getUserAgent = _getUserAgent;
    UserAgent.prototype.getAppName = _getAppName;
    UserAgent.prototype.getAppVersion = _getAppVersion;
    UserAgent.prototype.getOS = _getOS;
    UserAgent.prototype.getOSVersion = _getOSVersion;
    UserAgent.prototype.getPlatform = _getPlatform;
    UserAgent.prototype.isOtherBrowser = _isOtherBrowser;
    UserAgent.prototype.isOtherPlatform = _isOtherPlatform;
    UserAgent.prototype.isDhtmlCompat = _isDhtmlCompat;
    UserAgent.prototype.showInternalData = _showInternalData;
    
    //function defs...
    function _isIE(){return this.ie;}
    function _isNS(){return this.ns;}
    function _isN6(){return this.n6;}
    function _isN7(){return this.n7;}
    function _isMZ(){return this.mz;}
    function _isOP(){return this.op;}
    
    function _isWIN(){return this.win;}
    function _isMAC(){return this.mac;}
    function _isLYN(){return this.lyn;}
    
    function _getVersion(){return this.version;}
    function _getBrowser(){return this.browser;}
    function _getUserAgent(){return this.ua;}
    function _getAppName(){return this.an;}
    function _getAppVersion() {return this.av;}
    function _getOS() {return this.os;}
    function _getOSVersion() {return this.osVersion;}
    function _getPlatform() {return this.platform;}
    function _isOtherBrowser(){return this.browser == 'Other';}
    function _isOtherPlatform(){return this.platform == 'Other';}
    function _isDhtmlCompat(){return this.version >= 4;}
	function _showInternalData() {
        var data = '';
        for(prop in this)
            _ops(this,prop);
        _ops('','');
    }
    // the following vars and the function _ops, are not available via the UserAgent object,
    // they are not members of this object.
    var __ms,__ps;
    __ps = __ms = 0;
    function _ops(obj,prop) {
        if(obj == '' && prop == '') {
            document.write('<p><b>'+__ps+' properties, and '+__ms+' methods</b>');
            return;
        }
        var t = ''+obj[prop];
        if(t.indexOf('function') == -1) {
            document.write('<p><span class="ident">(property)</span> <b>UserAgent.'+prop+' =</b> '+obj[prop]+'</p>');
            __ps++;
        }
        else {
            document.write('<p><span class="ident">(method)</span> <b>UserAgent.'+prop+' =</b></p><pre>'+obj[prop]+'</pre>');
            __ms++;
        }
    }