/*
Browser detect
Parses User-Agent string into useful info.

Source: http://www.quirksmode.org/js/detect.html

Modified by: Paul Elias
Description: Added Firefox, made main code into function, added functions supportsFlashTransparentBackground and testBrowserDetector
Date: 11/19/2004
*/


function checkIt(detect, string)
{
	return detect.indexOf(string) + 1;
}

function getMajorVersion(string)
{
  version = String(parseFloat(string));
  j = version.indexOf(".");
  if (j >= 0)
  {
    majorver = version.substring(0,j);
  }
  else
  {
    majorver = version;
  }
  return majorver;
}

function getMinorVersion(string)
{
  version = String(parseFloat(string));
  j = version.indexOf(".");
  if (j >= 0)
  {
    minorver = version.substring(j+1, version.length);
  }
  return minorver;
}

function getBrowserDetectObject()
{
  this.browser = "";
  this.OS = "";
  this.majversion = "";

  var detect = navigator.userAgent.toLowerCase();
	var OS,browser,version,place;

	if (checkIt('konqueror'))
	{
		browser = "Konqueror";
		OS = "Linux";
	}
	else if ((place=checkIt(detect, 'safari')))
	{
	  browser = "Safari";
    version = getMajorVersion(detect.substring(place + 'safari'.length));
	}
	else if ((place=checkIt(detect, 'omniweb')))
	{
	  browser = "OmniWeb";
    version = getMajorVersion(detect.substring(place + 'omniweb'.length));
	}
	else if ((place=checkIt(detect, 'opera')))
	{
	  browser = "Opera";
    version = getMajorVersion(detect.substring(place + 'opera'.length));
	}
  else if ((place=checkIt(detect, 'webtv')))
	{
	  browser = "WebTV";
    version = getMajorVersion(detect.substring(place + 'webtv'.length));
	}
  else if ((place=checkIt(detect, 'firefox')))
	{
	  browser = "Firefox";
    version = getMajorVersion(detect.substring(place + 'firefox'.length));
	}
	else if ((place=checkIt(detect, 'icab')))
	{
	  browser = "iCab";
    version = getMajorVersion(detect.substring(place + 'icab'.length));
	}
	else if ((place=checkIt(detect, 'msie')))
	{
	  browser = "Internet Explorer";
    version = getMajorVersion(detect.substring(place + 'msie'.length));
	}
	else if (!(place=checkIt(detect, 'compatible')))
	{
		browser = "Netscape Navigator";
    version = getMajorVersion(detect.substring(8));
	}
	else browser = "An unknown browser";

	if (!OS)
	{
		if (checkIt(detect, 'linux')) OS = "Linux";
		else if (checkIt(detect, 'x11')) OS = "Unix";
		else if (checkIt(detect, 'mac')) OS = "Mac"
		else if (checkIt(detect, 'win')) OS = "Windows"
		else OS = "an unknown operating system";
	}
  
  this.browser = browser;
  this.OS = OS;
  this.majversion = version;
}

function supportsFlashTransparentBackground()
{
  var bto = new getBrowserDetectObject();
  if( (bto.OS == "Windows" && bto.browser == "Internet Explorer" && bto.majversion >= 5.0) ||
      (bto.OS == "Windows" && bto.browser == "Netscape Navigator" && bto.majversion >= 7) ||
      (bto.OS == "Windows" && bto.browser == "Firefox") ||
      (bto.browser == "Safari" && bto.majversion >= 312)
    )
  {
    return true;
  }
  return false;
}

// Test function to display results from BrowserCap for a given string
function testBrowserDetector()
{
  var bto = new getBrowserDetectObject();
  document.write("testing: <I>" + navigator.userAgent + "</I><BR>");
  document.write("&nbsp;&nbsp;Browser: <I>" + bto.browser + "</I><BR>");
  document.write("&nbsp;&nbsp;major version: <I>" + bto.majversion + "</I><BR>");
  document.write("&nbsp;&nbsp;OS: <I>" + bto.OS + "</I><BR>");
  document.write("&nbsp;&nbsp;Supports Flash Transparent Background: <I>" + supportsFlashTransparentBackground() + "</I><BR>");
  document.write("&nbsp;<BR>");
}

