//navigator.appCodeName -> js1.0
//navigator.appName -> js1.0
//navigator.appVersion -> js1.0
//navigator.userAgent -> js1.0
var USER_AGENT_OPERA = "OPERA";
var USER_AGENT_NS = "NETSCAPE";
var USER_AGENT_IE = "MSIE";

var flashEnabled = false; //Globale per "sottoscript" di explorer

function BrowserInfo() {

var ua = "";
var start = 0;
var end = 0;

  this.isOp = false;
  this.isIe = false;
  this.isNs = false;
  this.ver = 0;
  this.os = "";

  ua = navigator.userAgent.toUpperCase();
  versione = navigator.appVersion;
  appName = navigator.appName;

  if (ua.indexOf(USER_AGENT_OPERA) != -1) {
    this.isOp = true;
    this.ver = this.checkOpVer(ua, versione, appName);
    this.os = this.checkOpOs(ua, appName);
  }
  else if (ua.indexOf(USER_AGENT_IE) != -1) {
    this.isIe = true;
    this.ver = this.checkIeVer(ua);
    this.os = this.checkIeOs(ua);
  }
  else {
    this.isNs = true;
    this.ver = this.checkNsVer(versione);
    this.os = this.checkNsOs(ua);
  }
}

BrowserInfo.prototype.checkOpVer = BrowserInfo_checkOpVer; //Opera Version
BrowserInfo.prototype.checkIeVer = BrowserInfo_checkIeVer; //Internet Explorer Version
BrowserInfo.prototype.checkNsVer = BrowserInfo_checkNsVer; //Netscape Version
BrowserInfo.prototype.checkOpOs = BrowserInfo_checkOpOs; //Opera Operatin System
BrowserInfo.prototype.checkIeOs = BrowserInfo_checkIeOs; //Internet Explorer Operatin System
BrowserInfo.prototype.checkNsOs = BrowserInfo_checkNsOs; //Netscape Operatin System

BrowserInfo.prototype.isExplorer = BrowserInfo_isExplorer;
BrowserInfo.prototype.isNetscape = BrowserInfo_isNetscape;
BrowserInfo.prototype.isOpera = BrowserInfo_isOpera;

BrowserInfo.prototype.version = BrowserInfo_version;
BrowserInfo.prototype.platform = BrowserInfo_platform;
BrowserInfo.prototype.checkFlashPlugin = BrowserInfo_checkFlashPlugin;

function BrowserInfo_checkOpVer(userAgent, appVersion, appName) {
var start = 0;
var end = 0;

  if (appName.toUpperCase() == USER_AGENT_OPERA)
    return parseFloat(appVersion);
  else {
    start = userAgent.indexOf(USER_AGENT_OPERA) + USER_AGENT_OPERA.length;
    end = userAgent.length;
    return userAgent.substring(start, end);
  }
}

function BrowserInfo_checkIeVer(userAgent) {
var start = 0;
var end = 0;

  start = userAgent.indexOf(USER_AGENT_IE) + USER_AGENT_IE.length;
  end = userAgent.lastIndexOf(";");
  return userAgent.substring(start, end);
}

function BrowserInfo_checkNsVer(versione) {
  return parseFloat(versione);
}

function BrowserInfo_checkOpOs(userAgent, appName) {
  //Opera puo' essere usato per apparire come IE o Ns o come (ovviamente) Opera
  if ((appName.toUpperCase() == USER_AGENT_NS) || (appName.toUpperCase() == USER_AGENT_OPERA))
    return this.checkNsOs(userAgent);
  else
    return this.checkIeOs(userAgent);
}

function BrowserInfo_checkIeOs(userAgent) {
var start = 0;
var end = 0;

  start = userAgent.lastIndexOf(";") + 1;
  end = userAgent.lastIndexOf(")");
  return userAgent.substring(start, end);
}

function BrowserInfo_checkNsOs(userAgent) {
var start = 0;
var end = 0;

  start = userAgent.indexOf("(") + 1;
  end = userAgent.indexOf(";");
  return userAgent.substring(start, end);
}

function BrowserInfo_isExplorer() {
  return this.isIe;
}

function BrowserInfo_isNetscape() {
  return this.isNs;
}

function BrowserInfo_isOpera() {
  return this.isOp;
}

function BrowserInfo_version() {
  return this.ver;
}

function BrowserInfo_platform() {
  return this.os;
}

function BrowserInfo_checkFlashPlugin() {
var FLASH_MIMETYPE = 'application/x-shockwave-flash';
  if (this.os.indexOf('MAC') != -1) {
    /*alert('version:' + this.ver);
    alert(this.isExplorer);
    alert(this.isNetscape);
    alert(this.isOpera);
    alert(this.platform);*/

    if ((navigator.mimeTypes[FLASH_MIMETYPE] != null) && (navigator.mimeTypes[FLASH_MIMETYPE].enabledPlugin != null)) {
      flashEnabled = true;
    } else  {
      flashEnabled = false;
    }

    if (navigator.plugins && navigator.plugins['Shockwave Flash']) {
      flashEnabled = true;
    } else {
      flashEnabled = false;
    }
  } else {
    if (this.isNetscape()) {
       if (navigator.mimeTypes[FLASH_MIMETYPE] != null)
          if (navigator.mimeTypes[FLASH_MIMETYPE].enabledPlugin != null) flashEnabled = true;
    } else if (this.isExplorer()) {
      if (parseInt(this.ver) <= 4) {
        window.onerror = ErrorHandler;
        var swf = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
        flashEnabled = true;
      } else {
        flashEnabled = true;
        document.write('<scr'+'ipt language="JavaScript">\n'+
        'try {\n'+
        'var swf = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");\n'+
        '}\n'+
        'catch(e){\n'+
        'flashEnabled=false;\n'+
        '}\n'+
        '</scr'+'ipt>');
      }
    } else {
      if (navigator.mimeTypes[FLASH_MIMETYPE] != null)
        if (navigator.mimeTypes[FLASH_MIMETYPE].enabledPlugin != null) flashEnabled = true;
    }
  }
  return flashEnabled; //flashEnabled globale per il "sottoscript" di explorer
}

function ErrorHandler(msg, url, lno) {
  /*alert("Error Occurred! Handled by Generic Error Handler" + "\n" +
     "Error: " + msg + "\n" + "URL: " + url + "\n" +
     "Line Number: " + lno);*/
  return true;
}
