/*********************************************************************************
*************************************************************************************
**
** File: browser.js
**
** Description: File used to perform a javascript check of the users browser.
**
** Alias name: Not Applicable
**
** Category dependencies: Not Applicable
**
** Called by templates (with alias names of): Not Applicable
**
** Authors: MJF, PL
**
*************************************************************************************
*************************************************************************************
**
**  Revision list ...
**
**  MJF 20020625 Updated to reflect supported browsers.
**  MJF 20020826 Corrected reference to browsers.
**  MJF 20020920 Included acceptible browser NS6+ and changed to IE6+ for forward
**               compatability.
**  PL  20031014 Added Browser Conditions for Release 2.3
**  PL  20040720 Change Matrix for Release 2.5
**
*************************************************************************************
*************************************************************************************
**
**  Copyright HarvestRoad Ltd, 2000, 2001, 2002, 2003
**
**  All industrial and intellectual property in this software including but not
**  limited to copyright is owned by HarvestRoad Ltd.
**
**  This source, script and any associated data may not be copied (either in part,
**  or in full), altered in any way, recompiled, disassembled, reverse engineered,
**  modified for other uses or used in anyway other than for its intended purpose,
**  without the prior written permission of HarvestRoad Ltd.
**
**  Conditions of use
**
**  Without limitation to any other licence term or condition to which the use of
**  this software may be subject, HarvestRoad shall not be liable for damage however
**  arising, including but not limited to damage to software, hardware or data, as a
**  result of the intentional or unintentional use or mis-use of the software and
**  the user of the software shall indemnify and  hold harmless HarvestRoad from all
**  claims of whatever nature that may arise in connection with such use or any
**  damage arising therefrom.
**
*************************************************************************************
********************************************************************************* -*/
function isHiveBrowser() {
  var ua = navigator.userAgent.toLowerCase(),
      appVer = navigator.appVersion.toLowerCase(),
      retval = false;
  
  // browser vendor
  var v_isNav =
  	((ua.indexOf("mozilla") != -1) &&
  	(ua.indexOf("spoofer") == -1) && (ua.indexOf("compatible") == -1) &&
  	(ua.indexOf("opera") == -1) && (ua.indexOf("webtv") == -1));
  var v_isIe        = (ua.indexOf("msie") != -1);
  var v_isMac       = (ua.indexOf("mac") != -1);
  var v_isMacOSX    = (ua.indexOf("mac os x") != -1);
  var v_isNN71MacOSX = (ua.indexOf("mac os x") != -1) && (ua.indexOf("rv:1.4") != -1);
  var v_isNN702MacOSX = (ua.indexOf("mac os x") != -1) && (ua.indexOf("rv:1.0.2") != -1);
  var v_isNT        = (ua.indexOf("nt 5.0") != -1);
  var v_isXP        = (ua.indexOf("nt 5.1") != -1);
  var v_isSafari    = ((ua.indexOf('safari/412') != -1) || (ua.indexOf('safari/416') != -1));
  var v_isNN702     = (ua.indexOf("netscape/7.0") != -1);
  var v_isNN71      = (ua.indexOf("netscape/7.1") != -1);
  var v_isIe522MacOSX102 = (ua.indexOf("msie 5.22; mac_powerpc") != -1);
  var v_isIe522MacOSX103 = (ua.indexOf("msie 5.23; mac_powerpc") != -1);
  var v_isFireFox = (ua.indexOf("firefox") != -1);
  var v_isOpera = (ua.indexOf("opera") != -1);

  v_isNav = v_isNav && !v_isSafari;

  // browser versions
  var v_major;
  var v_minor;
  if (v_isIe)
  {
    var iIe = ua.indexOf("msie");
  	v_major = parseInt(ua.charAt(iIe+5));
  	v_minor = parseFloat(ua.substring(iIe+6, iIe+9));
  }
  else
  {
  	v_minor = parseFloat(appVer);
  	v_major = parseInt(v_minor);
  }
  
  var v_isNav2 = (v_isNav && (v_major == 2));
  var v_isNav3 = (v_isNav && (v_major == 3));
  var v_isNav4 = (v_isNav && (v_major == 4));
  var v_isNav5 = (v_isNav && (v_major == 5)); // netscape 7.x
  var v_isNav5Up = (v_isNav && (v_major == 5)); // netscape 7.x
  var v_isNav4Up = (v_isNav && (v_minor >= "4.7"));
  var v_isNav4Down = (v_isNav && (v_minor <= "4.7"));
  var v_isIe2 = (v_isIe && (v_major == 2));
  var v_isIe3 = (v_isIe && (v_major == 3));
  var v_isIe4 = (v_isIe && (v_major == 4));
  var v_isIe5 = (v_isIe && (v_major == 5));
  var v_isIe6 = (v_isIe && (v_major == 6));
  var v_isIe5Up = (v_isIe && (v_major >= 5));
  var v_isIe4Down = (v_isIe && (v_major <= 4) && (v_minor <= 4));
  
  //PL - Release Bld 2.3

  var v_isMacBrowser = (!v_isNN71 && v_isSafari && !v_isFireFox && !v_isOpera);
  var v_isPCBrowser  = (!v_isMac && ((v_isNT && (v_isIe5 && (v_minor = 0.5))) || v_isIe6 || v_isNN71 || !v_isNN702) && !v_isFireFox && !v_isOpera);

  if( v_isFireFox ) {
    //firefox supported on all platforms.
    //alert('v_isFireFox ' + ua);
    retval = true;
  } else if (v_isMacBrowser){
    //alert('v_isMacBrowser ' + ua);
    retval = true;
  } else if (v_isPCBrowser){
    //alert('v_isPCBrowser ' + ua + ' ' + v_isNT + ' ' + v_isXP);
    retval = true;
  } else  {
    if (v_isMac){
      retval = confirm("Unsupported browser detected for Mac OS.\nHive supports the following browsers for Mac OS:\n" 
               + "Mac OS 10.4\n"
               + "- Safari 2.0\n"
               + "- Firefox 1.0.6\n"
               + "Some Hive functions may exhibit unexpected behaviour.\n"
               + "Do you wish to continue?");
    } else if (!v_isMac && v_isNT){
      retval = confirm("Unsupported browser detected for Windows 2000.\nHive supports the following browsers for Windows 2000:\n" 
               + "- IE5.5\n" 
               + "- IE6\n" 
               + "- NN7.1\n" 
               + "- Firefox 1.0.6\n"
               + "Some Hive functions may exhibit unexpected behaviour.\n"
               + "Do you wish to continue?");
    } else if (!v_isMac && v_isXP){
      retval = confirm("Unsupported browser detected for Windows XP.\nHive supports the following browsers for Windows XP:\n" 
               + "- IE6\n" 
               + "- NN7.1\n"
               + "- Firefox 1.0.6\n"
               + "Some Hive functions may exhibit unexpected behaviour.\n"
               + "Do you wish to continue?");
    } else {
      retval = confirm("Unsupported browser detected for unsupported OS.\nHive supports the following browsers for Mac OS 10.2, Windows 2000 and Windows XP:\n" 
               + "Mac OS 10.3\n"
               + "- Safari 1.2\n"
               + "- Firefox 1.0.6\n"
               + "Windows 2000\n"
               + "- IE5.5\n" 
               + "- IE6\n" 
               + "- NN7.1\n" 
               + "- Firefox 1.0.6\n"
               + "Windows XP\n"
               + "- IE6\n" 
               + "- NN7.1\n"
               + "- Firefox 1.0.6\n"
               + "Some Hive functions may exhibit unexpected behaviour.\n"
               + "Do you wish to continue?");
    }
  }
  return retval;
} 
  // cookies
  var v_cookieEnabled = navigator.cookieEnabled;
  
  // detects if macromedia shockwave flash is installed.
  function m_isFlashEnabled()
  {
  	if (v_isIe)
  	{
  		return vb_isFlashEnabled();
  	}
  	else
  	{
  		if (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"] &&
  			navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin &&
  			navigator.plugins && navigator.plugins["Shockwave Flash"])
  		{
  			return true;
  		}
  		else
  		{
  			return false;
  		}
  	}
  }
  
  // detects the version of shockwave flash.
  function m_getFlashVersion()
  {
  	if (v_isIe)
  	{
  		return vb_getFlashVersion();
  	}
  	else
  	{
  		if (navigator.plugins && navigator.plugins["Shockwave Flash"])
  		{
  			var plugDesc = navigator.plugins["Shockwave Flash"].description;
  			return plugDesc.substr(plugDesc.indexOf(".")-1, 3);
  		}
  	}
  }
