var browserOK = false;
var browserOS = "Other";
var pluginRequired = false;
var pluginOK = false;
var hasSVGSupport = false;
var useObjectTag = false;
var SVGimplementation = 'plugin';

if (navigator.platform.indexOf("Win") > -1) {
  browserOS = "Windows";
}
else if (navigator.platform.indexOf("Mac") > -1) {
  browserOS = "Macintosh";
}

//detect IE6+
if (navigator.appVersion.indexOf("MSIE")!=-1){
  temp=navigator.appVersion.split("MSIE");
  version=parseFloat(temp[1]);
  if (version == 5.5) { //warn 5.5
    alert("You are running IE 5.5. Some features of\nWebTrak may not work correctly with this browser.");
  }
  if (version >=5.5) { //allow 5.5
    browserOK = true;
    pluginRequired = true;
  }
}

//detect Safari+
if (navigator.appVersion.indexOf("Safari")!=-1){
  var versionindex=navigator.userAgent.indexOf("Safari")+7;
  if (Number(navigator.userAgent.substr(versionindex,3))>=2) {
    //alert("Note: Some features of WebTrak may not work correctly with this browser.");
    browserOK = true;
    pluginRequired = true;
  }
}

//detect opera 9+
if (navigator.userAgent.indexOf("Opera")!=-1) {
  var versionindex=navigator.userAgent.indexOf("Opera")+6;
  if (parseInt(navigator.userAgent.charAt(versionindex))>=9) {
    browserOK = true;
    useObjectTag = true;
    hasSVGSupport = true;
    SVGimplementation = 'native';
  }
}

//detect FF 1.5+
if (navigator.userAgent.indexOf("Firefox")!=-1) {
  var versionindex=navigator.userAgent.indexOf("Firefox")+8;
  if (Number(navigator.userAgent.substr(versionindex,3))>=1.5) {
    browserOK = true;
    SVGimplementation = 'native';
    hasSVGSupport = true;
    if (navigator.platform.indexOf("Mac") > -1) {
      //alert("Problems exist with Firefox and SVG on the Macintosh.\nPlease consider using Opera version 9 instead");
    }
  }
}

if ("ActiveXObject" in window) { // IE windows
  try { 
    var svg=new Object();
    // Set some base values
    svg.installed=false;
    svg.version='0';
    for (x=1; x<10; x++) {
      try {
        oSVG=eval("new ActiveXObject('Adobe.SVGCtl."+x+"');");
        if (oSVG) {
          svg.installed=true;
          svg.version=x;
        }
      }
      catch(e) {}
    }
    if ((svg.installed) && (svg.version >= 3)) {
      hasSVGSupport = true;
      pluginOK = true;
    }
    else if ((svg.installed) && (svg.version < 3)) {
      hasSVGSupport = true;
      pluginOK = false;
    }
  }
  catch (e) { 
    hasSVGSupport = false;
  }
}
else if (navigator.mimeTypes != null && navigator.mimeTypes.length > 0) {
  if (navigator.mimeTypes["image/svg-xml"] != null) {
    hasSVGSupport = true;
    pluginOK = true; // no way to really know
  }
}

if (!top.userAlertedAlready) {
  if (!browserOK) {
    top.location.href = "/template/upgrade.html";
  }
  else if (browserOK && pluginRequired && !hasSVGSupport)  {
  //install the plugin
    top.location.href = "/template/install.html";
  }
  else if (browserOK && pluginRequired && hasSVGSupport && !pluginOK) {
  //old plugin
    top.location.href = "/template/update.html";
  }
}
