/*
   UserAgent.js
   UserAgent Object API
   gcpeters.com Wed., 11/28/04
   
   Copyright (c) 2004 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.
   
   batch updated 
   
   Thank you, and enjoy.
*/
function UserAgent() {
    // store color depth
    this.color = screen.colorDepth;
    //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;
    this.ff   = this.ua.indexOf('Firefox') != -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 = true;
        this.mz = false;
    }
    if(this.n7) {
        this.ns = true;
        this.mz = false;
    }
    if(this.mz) {
        this.n7 = false;
        this.n6 = false;
        this.ns = false;
    }
    if(this.ff) {
        this.mz = 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.n7)
        this.version = parseFloat(this.av);
    else if(this.n7)
        this.version = parseFloat(this.ua.substring(this.ua.indexOf('Netscape/') + 9));
    else if(this.ff)
        this.version = parseFloat(this.ua.substring(this.ua.indexOf('Firefox/') + 8));
    
    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.1') != -1)
            this.osVersion = 'XP';
        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 if(this.ff)
        this.browser = 'Mozilla Firefox';
    else
        this.browser = 'Other';
}//end UserAgent


// for deteriming the color depth
UserAgent.prototype.isColor256   = _isColor256;
UserAgent.prototype.isColor16bit = _isColor16bit;
UserAgent.prototype.isColor32bit = _isColor32bit;
// for deteriming the browser
UserAgent.prototype.isIE = _isIE;
UserAgent.prototype.isI5 = _isI5;
UserAgent.prototype.isI6 = _isI6;
UserAgent.prototype.isNS = _isNS;
UserAgent.prototype.isN6 = _isN6;
UserAgent.prototype.isN7 = _isN7;
UserAgent.prototype.isMZ = _isMZ;
UserAgent.prototype.isFF = _isFF;
UserAgent.prototype.isOP = _isOP;
// for deteriming the OS
UserAgent.prototype.isWIN = _isWIN;
UserAgent.prototype.isMAC = _isMAC;
UserAgent.prototype.isLYN = _isLYN;
// misc methods
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;// can't determine what broswer
UserAgent.prototype.isOtherPlatform = _isOtherPlatform;// can't determine what OS
UserAgent.prototype.isDhtmlCompat = _isDhtmlCompat; // version 4.o and up browsers
UserAgent.prototype.isDOMCompl = _isDOMCompl; // compliant with the DOM standard
UserAgent.prototype.redirNS = _redirNS;// redirect netscape browsers
UserAgent.prototype.showInternalData = _showInternalData;

//function defs...
function _isColor256()   {this.color == 8;}
function _isColor16bit() {this.color == 16;}
function _isColor32bit() {this.color == 32;}

function _isIE(){return this.ie;}
function _isI5(){return this.ie && this.version >= 5;}
function _isI6(){return this.ie && this.version >= 6;}
function _isNS(){return this.ns;}
function _isN6(){return this.n6;}
function _isN7(){return this.n7;}
function _isMZ(){return this.mz;}
function _isFF(){return this.ff;}
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 _isDOMCompl() { return ( (this.isI5() || ua.isI6()) || (this.isN6() || this.isN7()) || this.isFF()); }
function _redirNS(loc) {if(this.isNS() && this.getVersion() < 5) location.href = loc;}

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++;
    }
}