// JavaScript Document

// Browser Detect
function BrowserDetect() {
	var ua = navigator.userAgent.toLowerCase(); 

   // browser engine name
   this.browserName = 'Unsupported';
   
   if (ua.indexOf('gecko') != -1 && ua.indexOf('safari') == -1) this.browserName = 'Gecko';
   if (ua.indexOf('konqueror') != -1) this.browserName = 'Konqueror';
   if (ua.indexOf('safari') != - 1) this.browserName = 'Safari';
   if (ua.indexOf('omniweb') != - 1) this.browserName = 'OmniWeb';
   if (ua.indexOf('opera') != -1) this.browserName = 'Opera';
   if (ua.indexOf('icab') != -1) this.browserName = 'Icab';
   if (ua.indexOf('aol') != -1) this.browserName = 'AOL';
   if (ua.indexOf('msie') != -1 && !this.isOpera && (ua.indexOf('webtv') == -1)) this.browserName = 'Microsoft Internet Explorer';
   if (this.browserName == 'Gecko' && ua.indexOf('gecko/') + 14 == ua.length) this.browserName = 'Mozilla';
   if (ua.indexOf('firebird/') != -1) this.browserName = 'FireBird';
   if ((this.browserName == 'Gecko') ? (ua.indexOf('netscape') != -1) : ( (ua.indexOf('mozilla') != -1) && this.browserName != 'Opera' && this.browserName != 'Safari' && (ua.indexOf('spoofer') == -1) && (ua.indexOf('compatible') == -1) && (ua.indexOf('webtv') == -1) && (ua.indexOf('hotjava') == -1))) this.browserName = 'Netscape Communicator';

   // rendering engine versions
   this.isAppleWebKit = (ua.indexOf('applewebkit') != -1);
   this.appleWebKitVersion = ( (this.isAppleWebKit) ? parseFloat( ua.substring( ua.indexOf('applewebkit/') + 12) ) : -1 );
   
   // browser version
   // correct version number
   if (this.browserName == 'Gecko' && this.browserName != 'Mozilla') {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('/', ua.indexOf('gecko/') + 6) + 1 ) );
   }
   else if (this.browserName == 'Mozilla') {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) );
   }
   else if (this.browserName == 'Microsoft Internet Explorer' && parseFloat(navigator.appVersion) >= 4) {
      this.versionMinor = parseFloat(ua.substring(ua.indexOf("msie") + 5,(ua.indexOf(";", ua.indexOf("msie") + 5))));
   }
   else if (this.browserName == 'Konqueror') {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('konqueror/') + 10 ) );
   }
   else if (this.browserName == 'Safari') {
      // safari versioning not straight forward so we will translate
      var safariVersion = parseFloat( ua.substring( ua.lastIndexOf('safari/') + 7 ) );
      if (safariVersion >= 412)
	     this.versionMinor = 2.0;
	  else if (safariVersion >= 312)
	  	this.versionMinor = 1.3;
      else if (safariVersion >= 125)
         this.versionMinor = 1.2;
      else
         this.versionMinor = 1.0;
   }
   else if (this.browserName == 'Netscape Communicator') {
      this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('netscape/') + 9 ) );
   }
   else if (this.browserName == 'Omniweb') {
      this.versionMinor = parseFloat( ua.substring( ua.lastIndexOf('omniweb/') + 8 ) );
   }
   else if (this.browserName == 'Opera') {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('opera') + 6 ) );
   }
   else if (this.browserName == 'Icab') {
      this.versionMinor = parseFloat( ua.substring( ua.indexOf('icab') + 5 ) );
   }
   else
      this.versionMinor = parseFloat(navigator.appVersion);
   
   this.versionMajor = parseInt(this.versionMinor); 
   
   // platform check
   this.platformName = 'Unsupported';
   
    if ((ua.indexOf("win")!=-1) || (ua.indexOf("16bit")!=-1)) this.platformName = 'Windows';
    // NOTE: On Opera 3.0, the userAgent string includes "Windows 95/NT4" on all
    //        Win32, so you can't distinguish between Win95 and WinNT.
    if((ua.indexOf("win95")!=-1) || (ua.indexOf("windows 95")!=-1)) this.platformName = 'Windows 95';

    // is this a 16 bit compiled version?
    if ((ua.indexOf("win16")!=-1) ||
               (ua.indexOf("16bit")!=-1) || (ua.indexOf("windows 3.1")!=-1) ||
               (ua.indexOf("windows 16-bit")!=-1)) this.platformName = 'Windows 16';

    if ((ua.indexOf("windows 3.1")!=-1) || (ua.indexOf("win16")!=-1) ||
                    (ua.indexOf("windows 16-bit")!=-1)) this.platformName = 'Windows 3.1';
	
	if ((ua.indexOf("win 9x 4.90")!=-1)) this.platformName = 'Windows ME';
    if ((ua.indexOf("windows nt 5.0")!=-1) || (ua.indexOf("windows 2000")!=-1)) this.platformName = 'Windows 2000';
    if ((ua.indexOf("windows nt 5.1")!=-1) || (ua.indexOf("windows xp")!=-1)) this.platformName = 'Windows XP';
    if ((ua.indexOf("windows nt 5.2")!=-1) || (ua.indexOf("windows xp")!=-1)) this.platformName = 'Windows 2003';

    // 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".
    if ((ua.indexOf("win98")!=-1) || (ua.indexOf("windows 98")!=-1)) this.platformName = 'Windows 98';
    if ((ua.indexOf("winnt")!=-1) || (ua.indexOf("windows nt;")!=-1)) this.platformName = 'Windows NT';
    if (this.is_win95 || this.is_winnt || this.is_win98 ||
                    ((this.is_major >= 4) && (navigator.platform == "Win32")) ||
                    (ua.indexOf("win32")!=-1) || (ua.indexOf("32bit")!=-1)) this.platformName = 'Windows32';

    if ((ua.indexOf("os/2")!=-1) ||
                    (navigator.appVersion.indexOf("OS/2")!=-1) ||
                    (ua.indexOf("ibm-webexplorer")!=-1)) this.platformName = 'OS/2';

    if (ua.indexOf("mac")!=-1) this.platformName = 'Macintosh';
    if (ua.indexOf("mac")!=-1 && ((ua.indexOf("ppc")!=-1) ||
                                (ua.indexOf("powerpc")!=-1))) this.platformName = 'Macintosh PowerPC';
    if (ua.indexOf("mac")!=-1 && ua.indexOf("os x")!=-1) this.platformName = 'Macintosh OS X';
    
    this.cookies = (document.cookie) ? "On" : "Off";
}

function CheckRequirements()
{
	var checkedOut = true;
	var browser = new BrowserDetect();

	// check minimum requirements
	if (browser.platformName.toLowerCase().indexOf("windows")!=-1)
	{
		switch (browser.browserName.toUpperCase())
		{
			case 'MICROSOFT INTERNET EXPLORER':
			{
				if (browser.versionMinor < 6)
					checkedOut = false;
				break;
			}
			case 'NETSCAPE COMMUNICATOR':
			{
				if (browser.versionMinor < 7)
					checkedOut = false;
				break;
			}
			default:
			{
				checkedOut = false;
				break;
			}
		}
	}
	else if (browser.platformName.toLowerCase().indexOf("macintosh")!=-1)
	{
		if (browser.browserName.toUpperCase() == 'SAFARI')
		{
			if (browser.versionMinor < 1)
				checkedOut = false;
		}
		else
			checkedOut = false;
	}
	
	// alert if not checked out ok
	if (checkedOut == false)
		alert("Your browser is not supported for use on this site.  If you proceed, the site may not be fully functional.  \r\n\r\nUse the 'Check My Browser' link for a list of supported browsers.");
}
