//Title:       Browsercheck
//Version:     1.0
//Copyright:   Copyright (c) 2000
//Author:      REVIE
//Company:     Rhino Productions
//Description: Checks a user's browser settings

/*
   1.00  REVIE 2000/02/05  created
 */

// example:
//    var bw = new checkBrowser();
// then, you could do:
//    if(bw.ie) { /* IE */ } 
//    if(bw.bw) { /* DHTML/CSS enabled browser */ }...

function checkBrowser() {
   // browser version
   this.ver  = navigator.appVersion;
   this.dom  = document.getElementById?1:0;
   this.ie5  = (this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0;
   this.ie4  = (document.all && !this.dom)?1:0;
   this.ns5  = (this.dom && parseInt(this.ver) >= 5) ?1:0;
   this.ns4  = (document.layers && !this.dom)?1:0;
   this.opera= (this.ver.indexOf("Opera")>0?1:0);
   this.ie   = (this.ie5 || this.ie4);
   this.ns   = (this.ns5 || this.ns4);
   this.bw   = (this.ie5 || this.ie4 || this.ns4 || this.ns5);

   // OS check
   this.agent=navigator.userAgent;
   this.os   =(this.agent.indexOf('(')<0?'Unknown':
               navigator.userAgent.substring(this.agent.indexOf('(')+1,
                                             (this.agent.indexOf(')')>0?
                                              this.agent.indexOf(')'):
                                              this.agent.length)));
   this.win =this.os.indexOf('Win');
   this.mac =(this.os.indexOf('Mac')>=0 || this.os.indexOf('PPC')>=0?1:0);
   this.unix=(this.os.indexOf('X11')>=0?this.os.indexOf('X11'):
              (this.os.indexOf('SunOS')>=0?this.os.indexOf('SunOS')>=0:
               this.os.indexOf('Linux')));
   var start=(this.win>=0?this.win:(this.mac>=0?this.mac:this.unix));
   this.os=(start<0?'Unknown':
            Trim(this.os.substring(start,(this.os.indexOf(';',start)>0?
                                          this.os.indexOf(';',start):
                                          this.os.length))));
   this.win++; this.mac++; this.unix++;
   return this;
} // checkBrowser

// checks to see if the window size is good enough.
// use like checkBrowser().  Example:
//    window.page = new checkRes(1024,768);
// then, page.ok returns 1 if good.
// can only be used when the page is loaded (onLoad?) for IE browsers
function checkRes(bestwidth, bestheight) {
   // screen width & height
   this.x = screen.width;
   this.y = screen.height;

   // browser width & height
   this.width=(document.layers?innerWidth:
               document.all?document.body.offsetWidth:this.x);
   this.height=(document.layers?innerHeight:
                document.all?document.body.offsetHeight:this.y);

   this.ok=(this.width>=bestwidth && this.height>=bestheight?1:0);
   return this;
} // checkRes

// removes beginning and trailing spaces from a string
// (used in checkBrowser()
function Trim(inString) {
  var retVal = "";
  var start = 0;
  while ((start < inString.length) && (inString.charAt(start) == ' ')) {
    ++start;
  }
  var end = inString.length;
  while ((end > 0) && (inString.charAt(end - 1) == ' ')) {
    --end;
  }
  retVal = inString.substring(start, end);
  return retVal;
} // Trim
