/* Browser detection */
function Brows ()
{ 

  // *** BROWSER VERSION ***
  // Note: On IE5, these return 4, so use brows.ie5up to detect IE5.

  this.majorBrowserVersion = parseInt(navigator.appVersion);
  var agt=navigator.userAgent.toLowerCase();

  // *** BROWSER VERSION ***
  // Note: On IE5, these return 4, so use brows.ie5up to detect IE5.

  this.majorBrowserVersion = parseInt(navigator.appVersion);
  this.minorBrowserVersion = parseFloat(navigator.appVersion);

  // Note: Opera and WebTV spoof Navigator.  We do strict client detection.
  // If you want to allow spoofing, take out the tests for opera and webtv.
  this.nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
	       && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
	       && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
  this.nav2 = (this.nav && (this.majorBrowserVersion == 2));
  this.nav3 = (this.nav && (this.majorBrowserVersion == 3));
  this.nav4 = (this.nav && (this.majorBrowserVersion == 4));
  this.nav4up = (this.nav && (this.majorBrowserVersion >= 4));
  this.navonly      = (this.nav && ((agt.indexOf(";nav") != -1) ||
				    (agt.indexOf("; nav") != -1)) );
  this.nav6 = (this.nav && (this.majorBrowserVersion == 5));
  this.nav6up = (this.nav && (this.majorBrowserVersion >= 5));
  this.gecko = (agt.indexOf('gecko') != -1);


  this.ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
  this.ie3    = (this.ie && (this.majorBrowserVersion < 4));
  this.ie4    = (this.ie && (this.majorBrowserVersion == 4) && (agt.indexOf("msie 4")!=-1) );
  this.ie4up  = (this.ie  && (this.majorBrowserVersion >= 4));
  this.ie5    = (this.ie && (this.majorBrowserVersion == 4) && (agt.indexOf("msie 5.0")!=-1) );
  this.ie5_5  = (this.ie && (this.majorBrowserVersion == 4) && (agt.indexOf("msie 5.5") !=-1));
  this.ie5up  = (this.ie  && !this.ie3 && !this.ie4);
  this.ie5_5up =(this.ie && !this.ie3 && !this.ie4 && !this.ie5);
  this.ie6    = (this.ie && (this.majorBrowserVersion == 4) && (agt.indexOf("msie 6.")!=-1) );
  this.ie6up  = (this.ie  && !this.ie3 && !this.ie4 && !this.ie5 && !this.ie5_5);

  // *** JAVASCRIPT VERSION CHECK ***
  if (this.nav2 || this.ie3) this.js = 1.0;
  else if (this.nav3) this.js = 1.1;
  else if (this.opera5up) this.js = 1.3;
  else if (this.opera) this.js = 1.1;
  else if ((this.nav4 && (this.minorBrowserVersion <= 4.05)) || this.ie4) this.js = 1.2;
  else if ((this.nav4 && (this.minorBrowserVersion > 4.05)) || this.ie5) this.js = 1.3;
  else if (this.hotjava3up) this.js = 1.4;
  else if (this.nav6 || this.gecko) this.js = 1.5;
  // NOTE: In the future, update this code when newer versions of JS
  // are released. For now, we try to provide some upward compatibility
  // so that future versions of Nav and IE will show they are at
  // *least* JS 1.x capable. Always check for JS version compatibility
  // with > or >=.
  else if (this.nav6up) this.js = 1.5;
  // note ie5up on mac is 1.4
  else if (this.ie5up) this.js = 1.3

			 // HACK: no idea for other browsers; always check for JS version with > or >=
			 else this.js = 0.0;

  // *** PLATFORM ***
  this.win   = ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) );
  // NOTE: On Opera 3.0, the userAgent string includes "Windows 95/NT4" on all
  //        Win32, so you can't distinguish between Win95 and WinNT.
  this.win95 = ((agt.indexOf("win95")!=-1) || (agt.indexOf("windows 95")!=-1));

  // NOTE: Reliable detection of Win98 may not be possible. It appears that:
  //       - On Nav 4.x and before you'll get plain "Windows" in userAgent.
  //       - On Mercury client, the 32-bit version will return "Win98", but
  //         the 16-bit version running on Win98 will still return "Win95".
  this.win98 = ((agt.indexOf("win98")!=-1) || (agt.indexOf("windows 98")!=-1));
  this.winnt = ((agt.indexOf("winnt")!=-1) || (agt.indexOf("windows nt")!=-1));
  this.win32 = (this.win95 || this.winnt || this.win98 || 
		((this.majorBrowserVersion >= 4) && (navigator.platform == "Win32")) ||
		(agt.indexOf("win32")!=-1) || (agt.indexOf("32bit")!=-1));

  this.winme = ((agt.indexOf("win 9x 4.90")!=-1));
  this.win2k = ((agt.indexOf("windows nt 5.0")!=-1));

  this.mac    = (agt.indexOf("mac")!=-1);
  // hack ie5 js version for mac
  if (this.mac && this.ie5up) this.js = 1.4;
  this.mac68k = (this.mac && ((agt.indexOf("68k")!=-1) || 
			      (agt.indexOf("68000")!=-1)));
  this.macppc = (this.mac && ((agt.indexOf("ppc")!=-1) || 
			      (agt.indexOf("powerpc")!=-1)));

  this.sun   = (agt.indexOf("sunos")!=-1);
  this.sun4  = (agt.indexOf("sunos 4")!=-1);
  this.sun5  = (agt.indexOf("sunos 5")!=-1);
  this.suni86= (this.sun && (agt.indexOf("i86")!=-1));
  this.linux = (agt.indexOf("inux")!=-1);
  this.freebsd = (agt.indexOf("freebsd")!=-1);
  this.bsd = (agt.indexOf("bsd")!=-1);
  this.unix  = ((agt.indexOf("x11")!=-1) || this.sun || this.linux || this.bsd || this.freebsd);
}

function coolButtons(classPrefix, cssFile, overrideClass) {
  brows = new Brows();
  if (brows.ie5up || brows.nav6up) {

    // IMPORT STYLESHEET FOR BUTTONS
    document.writeln('<style type="text/css">');
    document.writeln('@import url("'+cssFile+'");');
    document.writeln('</style>');

    var inputs = new Array();
    inputs = document.getElementsByTagName('input');
		
    for (i = 0; i < inputs.length; i++) {

      if (inputs[i].type == 'button' || inputs[i].type == 'submit' || inputs[i].type == 'reset') {
	var value = inputs[i].value;
	var type = inputs[i].type;
					
	inputs[i].value = (value.replace(/^\W+/,'')).replace(/\W+$/,'');

	if (inputs[i].className == '' || inputs[i].className.indexOf(classPrefix) != -1) {
					
	  // IF BUTTONS DO NOT HAVE AN ASSIGNED CLASS... 
	  if (inputs[i].className == '') {

	    if (overrideClass != '') {
	      inputs[i].className = overrideClass;
	    }
	    else {

	      // ASSIGN GENERIC CLASS TO CLASSLESS BUTTONS
	      inputs[i].className = classPrefix+'generic';

	      // ASSIGN SOME CUSTOM CLASSES TO COMONLY USED BUTTONS
	      if (value == 'submit')
		{
		  inputs[i].className = classPrefix+'go';
		}
	      if (value.search(/^add/i) != -1)
		{
		  inputs[i].className = classPrefix+'add';
		}
	      if (value.search(/spelling/i) != -1)
		{
		  inputs[i].className = classPrefix+'spellcheck';
		}
	      if (value.search(/save/i) != -1) 
		{
		  inputs[i].className = classPrefix+'save';
		}
	      if (value.search(/search/i) != -1 || value.search(/apply filters/i) != -1)
		{
		  inputs[i].className = classPrefix+'search';
		}
	      if (type == 'reset' || value.search(/clear/i) != -1 || value.search(/reset/i) != -1)
		{
		  inputs[i].className = classPrefix+'reset';
		}
	      if (value.search(/cancel/i) != -1 || value.search(/delete/i) != -1 || value.search(/remove/i) != -1) 
		{
		  inputs[i].className = classPrefix+'cancel';
		}
	      if (value.search(/continue/i) != -1 || value == 'go')
		{
		  inputs[i].className = classPrefix+'go';
		}
	      if (value.search(/back/i) != -1)
		{
		  inputs[i].className = classPrefix+'back';
		}

	    }

	  }

	  // ADD BROWSER-SPECIFIC SUFFIXES TO CLASSNAMES
	  if (brows.ie5) {
	    inputs[i].className += '_ie5';
	  }
	  else if (brows.ie5_5up) {
	    inputs[i].className += '_ie5_5up';
	  }
	  // Mozilla 5 -- CHECK NS 6+, Any issues with other geckos?
	  else if (brows.nav6up) {
	    inputs[i].className += '_nav6up';
	  }
	}
      }
    }
  }
}
