/*
 *  Copyright 2000 Quidnunc All Rights Reserved
 *
 *  /javascript/sniffer.js
 *
 *  This is the JavaScript browser sniffer.
 *
 *  Author: Quidnunc
 *  Version: d1
 *
 *
 *  Ver Date          Who                     Comments
 *  -------------------------------------------------------------------------
 *  d1  03-Jan-2001   Chris Pederick          Created.
 *  -------------------------------------------------------------------------
 */

// --------------------------------------------------------------------------
// Variables
// --------------------------------------------------------------------------

// Variables to store the browser type, browser version and platform.
var bInternetExplorerCompatible = false;
var bNetscapeCompatible         = false;
var bWindowsPlatform            = false;
var bMacintoshPlatform          = false;
var bVersion4Compatible         = false;
var bVersion5Compatible         = false;
var bVersion6Compatible         = false;
var bVersion7Compatible         = false;

// --------------------------------------------------------------------------
// Detection
// --------------------------------------------------------------------------

// This calls the code to sniff for the browser and set the variables above.
sniffBrowser();

// --------------------------------------------------------------------------
// Methods
// --------------------------------------------------------------------------

/*
 * Sniffs the current browser and sets the variables accordingly.
 */
function sniffBrowser()
/*
Ver Date          Who                     Comments
-------------------------------------------------------------------------
d1  03-Jan-2001   Chris Pederick          Created.
-------------------------------------------------------------------------
*/
{
  // Variables to define what to sniff for.
  var sIE         = "MICROSOFT INTERNET EXPLORER";
  var sNN         = "NETSCAPE";
  var sIE4        = "MSIE 4.";
  var sIE5        = "MSIE 5.";
  var sIE6        = "MSIE 6.";
  var sIE7        = "MSIE 7.";
  var sNN4        = "4.";
  var sNN6        = "5.0";
  var sWIN        = "WIN32";
  var sMAC        = "MACPPC";

  var sAppName    = navigator.appName.toUpperCase();
  var sAppVersion = navigator.appVersion.toUpperCase();
  var sPlatform   = navigator.platform.toUpperCase();

  // Sniff browser type
  if(sAppName.indexOf(sIE) != -1)
  {
    bInternetExplorerCompatible = true;
  }
  else if(sAppName.indexOf(sNN) != -1)
  {
    bNetscapeCompatible = true;
  }

  // Sniff browser version
  if(bInternetExplorerCompatible)
  {
    // Check for IE versions
    if(sAppVersion.indexOf(sIE4) != -1)
    {
      bVersion4Compatible = true;
    }
    else if(sAppVersion.indexOf(sIE5) != -1)
    {
      bVersion5Compatible = true;
    }
    else if(sAppVersion.indexOf(sIE6) != -1)
    {
      bVersion6Compatible = true;
    }
    else if(sAppVersion.indexOf(sIE7) != -1)
    {
      bVersion7Compatible = true;
    }
  }
  else if(bNetscapeCompatible)
  {
    // Check for NN versions
    if(sAppVersion.indexOf(sNN4) != -1)
    {
      bVersion4Compatible = true;
    }
    else if(sAppVersion.indexOf(sNN6) != -1)
    {
      bVersion6Compatible = true;
    }
  }

  // Sniff platform
  if(sPlatform.indexOf(sWIN) != -1)
  {
    bWindowsPlatform = true;
  }
  else if(sPlatform.indexOf(sMAC) != -1)
  {
    bMacintoshPlatform = true;
  }
}

/*
 * Displays info about the current browser.
 */
function displayBrowserInfo()
/*
Ver Date          Who                     Comments
-------------------------------------------------------------------------
d1  03-Jan-2001   Chris Pederick          Created.
-------------------------------------------------------------------------
*/
{
  // Displays info about the current browser
  alert("App name :: " + navigator.appName
    + "\nApp version :: " + navigator.appVersion
    + "\nPlatform :: " + navigator.platform
    + "\n\nBrowser :: " + getBrowserDefinition());
}

/*
 * Returns a string describing the current browser.
 */
function getBrowserDefinition()
/*
Ver Date          Who                     Comments
-------------------------------------------------------------------------
d1  03-Jan-2001   Chris Pederick          Created.
-------------------------------------------------------------------------
*/
{
  // Variables to define the browser output format.
  var sIE4               = "IE4";
  var sIE5               = "IE5";
  var sIE6               = "IE6";
  var sIE7               = "IE7";
  var sNN4               = "Netscape 4";
  var sNN6               = "Netscape 6";
  var sWIN               = "Windows";
  var sMAC               = "Macintosh";
  var sUNKNOWNBROWSER    = "Unknown browser";
  var sUNKNOWNPLATFORM   = "Unknown platform";

  var sBrowserDefinition = "";

  // Find out browser and version
  if(isInternetExplorer4())
  {
    sBrowserDefinition += sIE4;
  }
  else if(isInternetExplorer5())
  {
    sBrowserDefinition += sIE5;
  }
  else if(isInternetExplorer6())
  {
    sBrowserDefinition += sIE6;
  }
  else if(isInternetExplorer7())
  {
    sBrowserDefinition += sIE7;
  }
  else if(isNetscape4())
  {
    sBrowserDefinition += sNN4;
  }
  else if(isNetscape6())
  {
    sBrowserDefinition += sNN6;
  }
  else
  {
    sBrowserDefinition += sUNKNOWNBROWSER;
  }

  // Add formatting
  sBrowserDefinition += " on ";

  // Find out platform
  if(isWindows())
  {
    sBrowserDefinition += sWIN;
  }
  else if(isMacintosh())
  {
    sBrowserDefinition += sMAC;
  }
  else
  {
    sBrowserDefinition += sUNKNOWNPLATFORM;
  }

  return sBrowserDefinition;
}

// --------------------------------------------------------------------------
// Selectors
// --------------------------------------------------------------------------

function isInternetExplorer()
/*
Ver Date          Who                     Comments
-------------------------------------------------------------------------
d1  03-Jan-2001   Chris Pederick          Created.
-------------------------------------------------------------------------
*/
{
  if(bInternetExplorerCompatible)
  {
    return true;
  }
  else
  {
    return false;
  }
}

function isInternetExplorer4()
/*
Ver Date          Who                     Comments
-------------------------------------------------------------------------
d1  03-Jan-2001   Chris Pederick          Created.
-------------------------------------------------------------------------
*/
{
  if(bInternetExplorerCompatible && bVersion4Compatible)
  {
    return true;
  }
  else
  {
    return false;
  }
}

function isInternetExplorer5()
/*
Ver Date          Who                     Comments
-------------------------------------------------------------------------
d1  03-Jan-2001   Chris Pederick          Created.
-------------------------------------------------------------------------
*/
{
  if(bInternetExplorerCompatible && bVersion5Compatible)
  {
    return true;
  }
  else
  {
    return false;
  }
}

function isInternetExplorer6()
/*
Ver Date          Who                     Comments
-------------------------------------------------------------------------
d1  03-Jan-2001   Chris Pederick          Created.
-------------------------------------------------------------------------
*/
{
  if(bInternetExplorerCompatible && bVersion6Compatible)
  {
    return true;
  }
  else
  {
    return false;
  }
}


function isInternetExplorer7()
/*
Ver Date          Who                     Comments
-------------------------------------------------------------------------
d1  22-Mar-2007   William Seaward         Created.
-------------------------------------------------------------------------
*/
{
  if(bInternetExplorerCompatible && bVersion7Compatible)
  {
    return true;
  }
  else
  {
    return false;
  }
}

function isNetscape()
/*
Ver Date          Who                     Comments
-------------------------------------------------------------------------
d1  03-Jan-2001   Chris Pederick          Created.
-------------------------------------------------------------------------
*/
{
  if(bNetscapeCompatible)
  {
    return true;
  }
  else
  {
    return false;
  }
}

function isNetscape4()
/*
Ver Date          Who                     Comments
-------------------------------------------------------------------------
d1  03-Jan-2001   Chris Pederick          Created.
-------------------------------------------------------------------------
*/
{
  if(bNetscapeCompatible && bVersion4Compatible)
  {
    return true;
  }
  else
  {
    return false;
  }
}

function isNetscape6()
/*
Ver Date          Who                     Comments
-------------------------------------------------------------------------
d1  03-Jan-2001   Chris Pederick          Created.
-------------------------------------------------------------------------
*/
{
  if(bNetscapeCompatible && bVersion6Compatible)
  {
    return true;
  }
  else
  {
    return false;
  }
}

function isWindows()
/*
Ver Date          Who                     Comments
-------------------------------------------------------------------------
d1  03-Jan-2001   Chris Pederick          Created.
-------------------------------------------------------------------------
*/
{
  if(bWindowsPlatform)
  {
    return true;
  }
  else
  {
    return false;
  }
}

function isMacintosh()
/*
Ver Date          Who                     Comments
-------------------------------------------------------------------------
d1  03-Jan-2001   Chris Pederick          Created.
-------------------------------------------------------------------------
*/
{
  if(bMacintoshPlatform)
  {
    return true;
  }
  else
  {
    return false;
  }
}
