var platformGeneral = null;
var platform = null;
var browserName = null;
var browserVersion = null;
var browserMajorVersion = null;
var browserMinorVersion = null;
var browserMinorMinorVersion = null;

function canAddAppletViaDOM() {
  if (browserName == "Konqueror") {
    if (browserMajorVersion < 3) return false;
    if (browserMajorVersion == 3 && browserMinorVersion < 4) return false;
  } else if (browserName == "Internet Explorer" && browserVersion == "5.5") {
    return false;
  }
  return true;
}

function detectBrowser() {
  var ua = navigator.userAgent.toLowerCase();
  var pl = navigator.platform.toLowerCase();
// ******** detect platform

  if ((ua.indexOf("win")!=-1) || (ua.indexOf("16bit")!=-1) ) {
    platformGeneral = "Windows";
    if ((ua.indexOf("windows 3.1")!=-1) || (ua.indexOf("16bit")!=-1) ||
        (ua.indexOf("win16")!=-1) || (ua.indexOf("windows 16-bit")!=-1)) platform="Windows 3.1";
    else if ((ua.indexOf("win95")!=-1) || (ua.indexOf("windows 95")!=-1)) platform="Windows 95";
    else if ((ua.indexOf("win98")!=-1) || (ua.indexOf("windows 98")!=-1)) platform="Windows 98";
    else if (ua.indexOf("windows nt 5.0")!=-1) platform="Windows 2000";
    else if (ua.indexOf("windows nt 5.1")!=-1) platform="Windows XP";
    else if ((ua.indexOf("winnt")!=-1) || (ua.indexOf("windows nt")!=-1)) platform="Windows NT";
    else if (ua.indexOf("win 9x 4.90")!=-1) platform="Windows Me";
    else if (pl.indexOf("wince")!=-1) platform="Windows CE";
    else platform ="Windows";
  }
  else if (ua.indexOf("mac")!=-1) {
    platformGeneral = "Macintosh";
    if ((ua.indexOf("68k")!=-1) || (ua.indexOf("68000")!=-1)) platform="Macintosh 68K";
    if ((ua.indexOf("ppc")!=-1) || (ua.indexOf("powerpc")!=-1)) platform="Macintosh Power_PC";
    else platform="Macintosh";
  }
  else if (ua.indexOf("linux")!=-1) platformGeneral="Linux";
  else if (ua.indexOf("sunos")!=-1) platformGeneral="SunOS";
  else if ((ua.indexOf("unix")!=-1) || (ua.indexOf("hp-ux")!=-1) || (ua.indexOf("aix")!=-1) ||
      (ua.indexOf("sco")!=-1) || (ua.indexOf("ncr")!=-1) || (ua.indexOf("bsd")!=-1) ||
      (ua.indexOf("freebsd")!=-1) || (ua.indexOf("dec")!=-1) || (ua.indexOf("osf1")!=-1) ||
      (ua.indexOf("alpha")!=-1) || (ua.indexOf("ultrix")!=-1) || (ua.indexOf("sinix")!=-1) ||
      (ua.indexOf("x11")!=-1) || (ua.indexOf("irix")!=-1)) platformGeneral="Unix";
  else if ((ua.indexOf("os/2")!=-1) || (navigator.appVersion.indexOf("OS/2")!=-1) ||
      (ua.indexOf("ibm-webexplorer")!=-1)) platformGeneral="OS/2";
  else if ((ua.indexOf("vax")!=-1) || (ua.indexOf("openvms")!=-1)) platformGeneral="VMS";
  else if (ua.indexOf("konqueror")!=-1) platformGeneral="Linux";
  else platformGeneral="Other";

// ******** detect browser name

  if ((ua.indexOf('mozilla')!=-1) && (ua.indexOf('rv:')!=-1) && (ua.indexOf('netscape') ==-1)) browserName="Mozilla";
  else if ((ua.indexOf('mozilla')!=-1) && (ua.indexOf('spoofer')==-1) &&
      (ua.indexOf('compatible') == -1) && (ua.indexOf('opera')==-1) &&
      (ua.indexOf('webtv')==-1) && (ua.indexOf('hotjava')==-1)) browserName="Netscape";
  else if (ua.indexOf("opera") != -1) browserName="Opera";
  else if (ua.indexOf("webtv") != -1) browserName="WebTV";
  else if ((ua.indexOf("navio") != -1) || (ua.indexOf("navio_aoltv") != -1)) browserName = "TV Navigator";
  else if (ua.indexOf("aol") != -1) browserName="Aol";
  else if ((ua.indexOf("msie") != -1) && (ua.indexOf("opera")==-1) && (ua.indexOf("webtv")==-1)) browserName="Internet Explorer";
  else if (ua.indexOf("hotjava") != -1) browserName="HotJava";
  else if (ua.indexOf("konqueror") != -1) browserName="Konqueror";
  else if (ua.indexOf("icab") != -1) browserName="iCab";
  else if (ua.indexOf("avantgo") != -1) browserName="AvantGo";
  else if (ua.indexOf("omniweb") != -1) browserName="OmniWeb";
  else if (ua.indexOf("kmeleon") != -1) browserName="KMeleon";
  else if (ua.indexOf("dreampassport") != -1) browserName="Dreampassport";
  else if (ua.indexOf("planetweb") != -1) browserName="PlanetWeb";
  else if (ua.indexOf("egbrowser") != -1) browserName="Egbrowser";
  else browserName="Other";

// ******** detect browser version

  if (ua.indexOf("opera") != -1) {
    var operaIndex = ua.indexOf ( "opera/" );
    if (operaIndex == -1) {
	    operaIndex = ua.indexOf ( "opera " );
	    browserVersion = parseFloat(ua.substring (operaIndex+6));
    } else browserVersion = parseFloat(ua.substring (operaIndex+6, ua.indexOf ("(", operaIndex )));
  } else if (ua.indexOf("netscape6") != -1) {
	  browserVersion=navigator.vendorSub;
  } else if ((ua.indexOf('mozilla')!=-1) && (ua.indexOf('rv:')!=-1)&& (ua.indexOf('netscape') ==-1)) {
    var mozillaIndex = ua.indexOf ( "rv:" );
    browserVersion = parseFloat(ua.substring (mozillaIndex+3, ua.indexOf (")", mozillaIndex )))
  } else if ((browserName=="Netscape") && (ua.indexOf('netscape6')==-1) && (ua.indexOf('netscape')==-1) ) {
    browserVersion=parseFloat(navigator.appVersion);
  } else if (ua.indexOf("netscape") != -1) {
    var netscapeIndex = ua.indexOf ("netscape/");
    browserVersion = parseFloat(ua.substring (netscapeIndex+9));
  } else if (ua.indexOf("webtv") != -1) {
    var webTVIndex = ua.indexOf ( "webtv/" );
    browserVersion = parseFloat(ua.substring (webTVIndex+6, ua.indexOf ("(", webTVIndex )));
  } else if (browserName == "Internet Explorer") {
    var msieIndex = ua.indexOf ( "msie " );
    browserVersion = parseFloat(ua.substring (msieIndex+5, ua.indexOf (";", msieIndex )));
  } else if (browserName == "Konqueror") {
    var konqIndex = ua.indexOf ( "konqueror/" );
    var blank = ua.indexOf ( " ", konqIndex + 10);
    var semicolon = ua.indexOf ( ";", konqIndex + 10);
    var konqIndex2 = ua.length;
    if (blank != -1) konqIndex2 = blank;
    if (semicolon != -1 && semicolon < blank) konqIndex2 = semicolon;
    browserVersion = parseFloat(ua.substring (konqIndex+10, konqIndex2 ));
  }
  
// split version into browserMajorVersion.browserMinorVersion.browserMinorMinorVersion
  
  browserVersion = "" + browserVersion;
  var dot1 = browserVersion.indexOf(".");
  if (dot1 > 0) {
    browserMajorVersion = browserVersion.substring(0, dot1);
    var dot2 = browserVersion.indexOf(".", dot1 + 1);
    if (dot2 > 2) {
      browserMinorVersion = browserVersion.substring(dot1 + 1, dot2);
      browserMinorMinorVersion = browserVersion.substring(dot2 + 1);
    } else browserMinorVersion = browserVersion.substring(dot1 + 1);
  } else browserMajorVersion = browserVersion;
  
  canLiveConnect = navigator.platform.indexOf("Mac") == -1;
  // FIXME: ADD OTHER BROWSERS
 }

detectBrowser();
