var requiredVersion = 5;
var flash5Installed = false;  // wahr wenn flash 5 installiert ist
var flash6Installed = false;  // wahr wenn flash 6 installiert ist
var flash7Installed = false;  // wahr wenn flash 7 installiert ist
var flash8Installed = false;  // wahr wenn flash 7 installiert ist
var flash9Installed = false;  // wahr wenn flash 7 installiert ist
var flash10Installed = false;  // wahr wenn flash 7 installiert ist
var maxVersion     = 10;    // die Version die momentan maximal gecheckt wird
var actualVersion   = 0;    // die version die der User hat

// ceck for IE
isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;      // TRUE wenn IE and OPERA
isNS = (navigator.appName.indexOf("Netscape") != -1) ? true : false;     // TRUE wenn NS
isWin = (navigator.appVersion.indexOf("Windows") != -1) ? true : false;  // TRUE wenn auf Windows

// VB-Script Detection beim MsIe auf Windows, da MsIe bei Windows
// regular JavaScript Plugins nicht unterstützt
if(isIE && isWin){
  document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n');
  document.write('on error resume next \n');
  document.write('flash5Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.5"))) \n');
  document.write('flash6Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6"))) \n');
  document.write('flash7Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.7"))) \n');
  document.write('flash8Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.8"))) \n');
  document.write('flash9Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.9"))) \n');
  document.write('flash10Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.10"))) \n');
  document.write('</SCR' + 'IPT\> \n');
}

function detectFlash() {
  // existiert navigator.plugins
  if (navigator.plugins) {
    // check für flash 2 oder flash 3+
    if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
      var isVersion2       = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
      var flashDescription   = navigator.plugins["Shockwave Flash" + isVersion2].description;

      // alert("Flash plugin description: " + flashDescription);

      var endPos   = flashDescription.indexOf(".");
			var startPos = flashDescription.substring(0,endPos).lastIndexOf(" ");
      var flashVersion    = parseInt(flashDescription.substring(startPos, endPos));
      
      // alert(startPos+" / "+endPos+" / "+flashDescription.substring(startPos, endPos)+" : "+flashVersion);
      
      flash5Installed     = flashVersion == 5;
      flash6Installed     = flashVersion == 6;
      flash7Installed     = flashVersion == 7;
      flash8Installed     = flashVersion == 8;
      flash9Installed     = flashVersion == 9;
      flash10Installed    = flashVersion >= 10;
    }
  }
  
  for (var i = 5; i <= maxVersion; i++) {
    if (eval("flash" + i + "Installed") == true){
      actualVersion = i;
    }
  }
  
  // alert(actualVersion);

  if(navigator.userAgent.indexOf("WebTV") != -1) {
    actualVersion = 3;
  }

  if (actualVersion >= requiredVersion) {     // user has a new enough version
     return true;
  }
  return false;
}

// Function to write HTML for Flash use
// If Flash is installed, the given "flash" will be displayed else the given "image" will
// be displayed
function writeFlash(id, flash, image, imageText, x, y) {
  if (detectFlash() == true) {
    // Flash vorhanden
    document.writeln("<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" " +
                     "codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\" " +
                     "width=\""+x+"\" height=\""+y+"\" id=\""+id+"\">\n" +
                     "  <param name=\"movie\" value=\""+flash+"\" />\n" +
                     "  <param name=\"menu\" value=\"false\" />\n" +
                     "  <param name=\"quality\" value=\"high\" />\n" +
                     "  <param name=\"bgcolor\" value=\"#f5f5f5\" />\n " +
                     "  <embed src=\""+flash+"\" menu=\"false\" quality=\"high\" " +
                     "bgcolor=\"#f5f5f5\" width=\""+x+"\" height=\""+y+"\" name=\""+id+"\" " +
                     "allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" " +
                     "pluginspage=\"http://www.macromedia.com/go/getflashplayer\" >\n" +
                     "</object>\n");
  } else {
    // Flash not present
    document.writeln("<img src=\""+image+"\" alt=\""+imageText+"\" width=\""+x+"\" height=\""+y+"\" />");
  }
}

// Function to write HTML for History Flash use
// If Flash is installed, the given "flash" will be displayed else there will be a redirect to the  given "url"
function writeFlashHistorie(id, flash_de, flash_en, url, x, y, lang) {
  if (detectFlash() == true) {
    // Flash vorhanden
    document.writeln("<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" " +
                     "codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\" " +
                     "width=\""+x+"\" height=\""+y+"\" id=\""+id+"\">\n" +
                     "  <param name=\"movie\" value=\""+(lang == "DEU"?flash_de:flash_en)+"\" />\n" +
                     "  <param name=\"menu\" value=\"false\" />\n" +
                     "  <param name=\"quality\" value=\"high\" />\n" +
                     "  <embed src=\""+(lang == "DEU"?flash_de:flash_en)+"\" menu=\"false\" quality=\"high\" " +
                     " width=\""+x+"\" height=\""+y+"\" name=\""+id+"\" " +
                     "allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" " +
                     "pluginspage=\"http://www.macromedia.com/go/getflashplayer\" >\n" +
                     "</object>\n");
  } else {
    // Flash not present
    window.location.href = url;
  }
}

// Function to write HTML for Flash use at the Homepage
// If Flash is installed, the given "flash" will be displayed else the given "image" will
// be displayed
function writeFlashHome(id, flash, XMLPath, image, x, y, language) {
  if (detectFlash() == true) {
    // Flash vorhanden
    if (language == "DEU") {
    	language = "de";
    }else if(language == "JPN"){
    	language = "jp";
    }else{
      language = "en";
    }
    document.writeln("<div id=\"div_seitenbild\">\n" +
                     "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" " +
                     "codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\" " +
                     "width=\""+x+"\" height=\""+y+"\" id=\""+id+"\">\n" +
                     "  <param name=\"movie\" value=\""+flash+"\" />\n" +
                     "  <param name=\"quality\" value=\"high\" />\n" +
                     "  <param name=\"BASE\" value=\".\" />\n" +
                     "  <param name=\"FlashVars\" value=\"lang="+language+"&xmlFile="+XMLPath+"\">\n" +
                     "  <embed src=\""+flash+"\" quality=\"high\" base=\".\" flashvars=\"lang="+language+"&xmlFile="+XMLPath+"\" " +
                     "bgcolor=\"#f5f5f5\" width=\""+x+"\" height=\""+y+"\" name=\""+id+"\" " +
                     "allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" " +
                     "pluginspage=\"http://www.macromedia.com/go/getflashplayer\" >\n" +
                     "</object>\n" +
                     "</div>\n");
  } else {
    // Flash not present
    document.writeln("<div style=\"width:1000px;height:171px;background:url("+image+") no-repeat bottom left;\"></div>");
  }
}

// Function to write HTML for Flash use at the Capability landing page
// If Flash is installed, the given "flash" will be displayed else the given "image" will
// be displayed
function writeFlashLandingPage(id, flash, XMLPath, image ,imageText, x, y, language) {
  if (detectFlash() == true) {
    if (language == "DEU") {
    	language = "de";
    }else if(language == "JPN"){
    	language = "jp";
    }else if(language == "CHN"){
    	language = "zh";
    }else{
      language = "en";
    }
    // Flash vorhanden
    document.writeln("<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" " +
                     "codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\" " +
                     "width=\""+x+"\" height=\""+y+"\" id=\""+id+"\">\n" +
                     "  <param name=\"movie\" value=\""+flash+"\" />\n" +
                     "  <param name=\"quality\" value=\"high\" />\n" +
                     "  <param name=\"BASE\" value=\".\" />\n" +
                     "  <param name=\"FlashVars\" value=\"lang="+language+"&xmlFile="+XMLPath+"\">\n" +
                     "  <embed src=\""+flash+"\" quality=\"high\" base=\".\" flashvars=\"lang="+language+"&xmlFile="+XMLPath+
                     "\"bgcolor=\"#f5f5f5\" width=\""+x+"\" height=\""+y+"\" name=\""+id+"\" " +
                     "allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" " +
                     "pluginspage=\"http://www.macromedia.com/go/getflashplayer\" >\n" +
                     "</object>\n");
  } else {
    // Flash not present
   document.writeln("<img src=\""+image+"\" alt=\""+imageText+"\" usemap=\"#capability\" width=\""+x+"\" height=\""+y+"\" />");
  }
}
// Function to write HTML for Flash use at the locationtool page
// If Flash is installed, the given "flash" will be displayed else the given "image" will
// be displayed
function writeFlashLocationTool(id, flash, XMLPath, image ,imageText, x, y, language, capability) {
  if (detectFlash() == true) {
    if (language == "DEU") {
    	language = "de";
    }else if(language == "JPN"){
    	language = "jp";
    }else if(language == "CHN"){
    	language = "zh";
    }else{
      language = "en";
    }
    // Flash vorhanden
    document.writeln("<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" " +
                     "codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\" " +
                     "width=\""+x+"\" height=\""+y+"\" id=\""+id+"\">\n" +
                     "  <param name=\"movie\" value=\""+flash+"\" />\n" +
                     "  <param name=\"quality\" value=\"high\" />\n" +
                     "  <param name=\"BASE\" value=\".\" />\n" +
                     "  <param name=\"FlashVars\" value=\"lang="+language+"&xmlFile="+XMLPath+"&capability="+capability+"\">\n" +
                     "  <embed src=\""+flash+"\" quality=\"high\" base=\".\" flashvars=\"lang="+language+"&xmlFile="+XMLPath+"&capability="+capability+
                     "\"bgcolor=\"#f5f5f5\" width=\""+x+"\" height=\""+y+"\" name=\""+id+"\" " +
                     "allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" " +
                     "pluginspage=\"http://www.macromedia.com/go/getflashplayer\" >\n" +
                     "</object>\n");
  } else {
    // Flash not present
   //document.writeln("<img src=\""+image+"\" alt=\""+imageText+"\" width=\""+x+"\" height=\""+y+"\" />");
   document.writeln("<p>"+imageText+"</p>");
  }
}
// Function to remove the Menu Divs if the Flash could be displayed
function writeFlashHomeMenu() {
  if (detectFlash() != true) {
    document.getElementById("nav").style.display = "inline";
    document.getElementById("leftnav_submenus").style.display = "inline";
  }
}

// Function to remove the Menu Divs if the Flash could be displayed
function writeFlashZeitreiseMenu(id, flash, x, y) {
  if (detectFlash() == true) {
    document.getElementById("zeitleiste").style.display = "none";
    writeFlashWorldmap(id, flash, x, y);
  }
}

// Function to write HTML for Worldmap Flash
// If Flash is installed, the given "flash" will be displayed else there will be displayed nothing
function writeFlashWorldmap(id, flash, x, y) {
 if (detectFlash() == true) {
    // Flash vorhanden
    document.writeln("<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" " +
                     "codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\" " +
                     "width=\""+x+"\" height=\""+y+"\" id=\""+id+"\">\n" +
                     "  <param name=\"movie\" value=\""+flash+"\" />\n" +
                     "  <param name=\"menu\" value=\"false\" />\n" +
                     "  <param name=\"quality\" value=\"high\" />\n" +
                     "  <param name=\"bgcolor\" value=\"#ffffff\" />\n " +
                     "  <embed src=\""+flash+"\" menu=\"false\" quality=\"high\" " +
                     "bgcolor=\"#ffffff\" width=\""+x+"\" height=\""+y+"\" name=\""+id+"\" " +
                     "allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" " +
                     "pluginspage=\"http://www.macromedia.com/go/getflashplayer\" >\n" +
                     "</object>\n");
  }
}

// Function to write HTML for Picture Viewer
// If Flash is installed, the Picture Viewer "flash" will be displayed else the non flash v
// variant (Javascript) will be deployed
function writeFlashPictureViewer(id, flash, xmlPath, lang, activeBlock, x, y, group, formpath, sourcepage ) {
  if (detectFlash() == true) {
    // Flash vorhanden

    // determine if the button is to be displayed
    var formparam = "";
    if (formpath != "") {
      formparam  = "&formpath=" + formpath;
    }

    document.writeln("<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" " +
                     "codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\" " +
                     "width=\""+x+"\" height=\""+y+"\" id=\""+id+"\">\n" +
                     "  <param name=\"BASE\" value=\".\" />\n" +
                     "  <param name=\"movie\" value=\""+flash+"?xmlFile="+xmlPath+"&group="+group+"&sourcepage="+sourcepage+
                                                        formparam+
                                                        "&lang="+lang+"\" />\n" +
                     "  <param name=\"menu\" value=\"false\" />\n" +
                     "  <param name=\"quality\" value=\"high\" />\n" +
                     "  <param name=\"bgcolor\" value=\"#ffffff\" />\n " +
                     "  <param name=\"FlashVars\" value=\"activeblock="+activeBlock+"\" />\n " +
                     "  <embed src=\""+flash+
                               "?xmlFile="+xmlPath+
                               "&group="+group+
                               "&sourcepage="+sourcepage+
                               formparam+
                               "&lang="+lang+
                               "\" menu=\"false\" quality=\"high\" " +
                     "bgcolor=\"#ffffff\" width=\""+x+"\" height=\""+y+"\" name=\""+id+"\" " + "aling=\"middle\" allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" " +
                     "pluginspage=\"http://www.macromedia.com/go/getflashplayer\" BASE=\".\" "+
                     "flashvars=\"activeblock="+activeBlock+"\" >\n" +
                     "</object>\n");
  } else {
    // Flash not present

  }
}