/* ***********************************************************
** DETECT.JS - JS Browser/Version/Platform Detection Library
** =========================================================
** This library contains functions to detect/return the user's
** browser, version, and platform and to jump to a URL if
** the user is using a specified browser and/or version and/or
** platform. It's yours for free; please maintain this header!
**
** To load this library in an HTML doc, put the following
** line in the doc's HEAD (before any other SCRIPT tags):
**
** <SCRIPT SRC="detect.js" LANGUAGE="JavaScript"></SCRIPT>
**
** Author      Ver  Date    Comments
** ======      ===  ====    ========
** Rick Scott  1.0  1/1/00  First release
**
** Copyright 2000, Rick Scott, all rights reserved.
*********************************************************** */

/* ***********************************************************
** Functions
** =========
** getBrowser()
**   returns browser: "netscape", "ie", "other"
** getBrowserVer()
**   returns browser version number or "n/a"
** getPlatform()
**   returns browser OS: "mac", "win", "unix", "other"
** ifBVPjump(browser, version, platform, URL);
**   jumps to URL if user's browser, version, platform all
**   match the first three arguments
**   browser - "netscape", "ie", "other", "any"
**   version - "#.x", "#.#[#]", "any"
**             "#.x" matches any version #
**               ex: "4.x" matches 4.0, 4.05, 4.5, etc.
**             "#.#[#]" matches only version #.#[#]
**               ex: "4.05" matches 4.05, not 4.0, 4.5 
**   platform - "mac", "win", "unix", "other", "any"
**   URL - relative or absolute URL
**   examples:
**     ifBVPjump("ie", "4.x", "win", "ie4winpage.html");
**       would jump to ie4winpage.html if the user's BVP
**       were IE, 4.x, Windows
**     ifBVPjump("IE", "4.x", "win", "ie4winpage.html");
**       wouldn't work because "ie" is case-sensitive
**    ifBVPjump("any", "any", "unix", "unixpage.html");
**       would jump to unixpage.html if user's P were UNIX
**     ifBVPjump("any", "any", "any", "index.html");
**       would jump to index.html regardless of user's BVP
** isNetscape()
**   returns true if Netscape, false if not
** isIE()
**   returns true if IE, false if not
** isVer3()
**   returns true if version is 3.x, false if not
** isVer4()
**   returns true if version is 4.x, false if not
** isVer4up()
**   returns true if version is 4.0+, false if not
**   this is a quick way to test for DHTML capability
** isVer5()
**   returns true if version is 5.x, false if not
** isMac()
**   returns true if OS is Mac, false if not
** isWin()
**   returns true if OS is Windows, false if not
** isUNIX()
**   returns true if OS is UNIX, false if not
*********************************************************** */

function getBrowser()  // get the browser program name
  {
  if (navigator.appName == null || navigator.appName == "")
    return "other";
  else if (navigator.appName == "Netscape")
    return "netscape";
  else if (navigator.appName == "Microsoft Internet Explorer")
    return "ie";
  else
    return "other";
  }

function isNetscape()  // is browser Netscape?
  {
  if (getBrowser() == "netscape")
    return true;
  else
    return false;
  }

function isIE()  // is browser IE?
  {
  if (getBrowser() == "ie")
    return true;
  else
    return false;
  }

function getBrowserVer()  // get the browser version
  {
  if (navigator.appVersion == null || navigator.appVersion == "")
    return "n/a";
  // fix for IE 5.x appVersion bug, which returns 4.x instead of 5.x
  if (isIE() && navigator.userAgent.indexOf("5.") != -1)
    { 
    var verNum = "";
    var str = navigator.userAgent;
    var pos = str.indexOf("IE ");  // real version num follows "IE "
    for (pos=pos+3; pos<str.length; pos++)  // build verNum string
      if (str.charAt(pos) == "." || 
         (str.charAt(pos) <= "9" && str.charAt(pos) >= "0"))
        verNum += str.charAt(pos);
      else
        break;
    return verNum;
    }
  var verArray = navigator.appVersion.split(" ");
  return verArray[0];
  }

function isVer3()  // is browser version 3.x?
  {
  if (getBrowserVer() >= 3.0 && getBrowserVer() < 4.0)
    return true;
  else
    return false;
  }

function isVer4()  // is browser version 4.x?
  {
  if (getBrowserVer() >= 4.0 && getBrowserVer() < 5.0)
    return true;
  else
    return false;
  }

function isVer4up()  // is browser version 4.0+? (for DHTML coding)
  {
  if (getBrowserVer() >= 4.0)
    return true;
  else
    return false;
  }

function isVer5()  // is browser version 5.x?
  {
  if (getBrowserVer() >= 5.0 && getBrowserVer() < 6.0)
    return true;
  else
    return false;
  }

function getPlatform()  // get the browser platform (OS)
  {
  if (navigator.platform == null || navigator.platform == "")
    return "other";
  else if (navigator.platform.indexOf("Mac") >= 0)
    return "mac";
  else if (navigator.platform.indexOf("Win") >= 0)
    return "win";
  else if (navigator.platform.indexOf("Unix") >= 0)
    return "unix";
  else
    return "other";
  }

function isMac()  // is browser OS Mac?
  {
  if (getPlatform() == "mac")
    return true;
  else
    return false;
  }

function isWin()  // is browser OS Windows?
  {
  if (getPlatform() == "win")
    return true;
  else
    return false;
  }

function isUNIX()  // is browser OS UNIX?
  {
  if (getPlatform() == "unix")
    return true;
  else
    return false;
  }

function ifBVPjump(browser, version, platform, URL)
  {
  // first make sure that version = user's browser version
  if (version.indexOf("x") != -1)  // version is in "#.x" format
    {
    if ((version.charAt(0) == "3") && (isVer3() == false))
      return;  // version's incorrect, return
    else if ((version.charAt(0) == "4") && (isVer4() == false))
      return;  // version's incorrect, return 
    else if ((version.charAt(0) == "5") && (isVer5() == false))
      return;  // version's incorrect, return 
    }
  else if (version.indexOf(".") != -1) // version is in #.#[#] format
    {
    if (version != getBrowserVer())
      return;  // version's incorrect, return to caller
    }
  // okay, version's correct, but what about browser/platform?
  if ( ((browser == getBrowser()) || (browser == "any"))
       && 
       ((platform == getPlatform()) || (platform == "any")) )
    top.document.location.href = URL;  // BVP all correct, jump!
  else
    return;  // B and/or P incorrect, return
  }

