//|
//| Copyright (C) Architecte du Logiciel
//| All rights reserved. Duplication and distribution prohibited.
//| http://www.architectedulogiciel.fr
//|

// see callable functions at the end

//ADL
//[GLOBALVARS]
var requiredVersion;
var useRedirect=false;
var flash2Installed=false;
var flash3Installed=false;
var flash4Installed=false;
var flash5Installed=false;
var flash6Installed=false;
var flash7Installed=false;
var flash8Installed=false;
var flash9Installed=false;
var maxVersion=9;
var actualVersion=0;
var hasRightVersion=false;
var jsVersion=1.0;
var isIE=(navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin=(navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
jsVersion = 1.1;
var label_txt="";
var button_txt="";
var flashplug_url="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash";
var flashicon="";

//ADL
function write_flash_obj(idname,swfmovie,swfwidth,swfheight,swfvars,bgcolor,is_transparent)
{
  var oetags = '';
  oetags += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ';
  oetags += 'width="'+swfwidth+'" height="'+swfheight+'" id="'+idname+'" align="middle">';
  oetags += '<param name="allowScriptAccess" value="sameDomain" />';
  oetags += '<param name="movie" value="'+swfmovie+'?'+swfvars+'"/>';
  oetags += '<param name="quality" value="high"/>';
  oetags += '<param name="bgcolor" value="' + bgcolor + '" />';  
  if (is_transparent) oetags += '<param name="wmode" value="transparent" />';  
  oetags += '<embed src="'+swfmovie+'" bgcolor="'+ bgcolor + '" quality="high" ';
  oetags += 'id="'+idname+'_embed" ';
  oetags += 'width="'+swfwidth+'" height="'+swfheight+'" name="'+idname+'" align="middle" ';
  oetags += 'allowScriptAccess="sameDomain"  type="application/x-shockwave-flash" ';
  oetags += 'pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" ';
  oetags += 'FlashVars="'+swfvars+'"';  
  if (is_transparent) oetags += ' wmode="transparent" ';  
  oetags += '/></object>';
  document.write(oetags);
}

//ADL
function detectFlash()
{
  if (navigator.plugins)
  {
    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;
      var flashVersion = parseInt(flashDescription.substring(16));
      flash2Installed = flashVersion == 2;    
      flash3Installed = flashVersion == 3;
      flash4Installed = flashVersion == 4;
      flash5Installed = flashVersion == 5;
      flash6Installed = flashVersion == 6;
      flash7Installed = flashVersion == 7;
      flash8Installed = flashVersion == 8;
      flash9Installed = flashVersion >= 9;
    }
  }
  for (var i = 2; i <= maxVersion; i++)
  {  
    if (eval("flash" + i + "Installed") == true) 
      actualVersion = i;
  }
  if (navigator.userAgent.indexOf("WebTV") != -1)
    actualVersion = 4;  
  if (actualVersion >= requiredVersion)
  {
    if (useRedirect) 
    {
      if (jsVersion > 1.0) 
      {
        window.location.replace(flashPage);  
      }
      else
      {
        window.location = flashPage;
      }
    }//if redirect
    hasRightVersion = true;
  }
  else 
  {  
    if (useRedirect) 
    {
      if (jsVersion > 1.0) 
      {
        window.location.replace((actualVersion >= 2) ? upgradePage : noFlashPage);
      }
      else
      {
        window.location = (actualVersion >= 2) ? upgradePage : noFlashPage;
      }
    }//if redirect
  }
}


////////////////////////////////////////////
// CALLABLE FUNCTIONS //////////////////////
////////////////////////////////////////////

//ADL
function detectFlashVers(VERSION_MIN,label_text,button_text,aflashicon)
{
  // redefine global vars;
  requiredVersion=VERSION_MIN;
  label_txt=label_text;
  button_txt=button_text;
  flashicon=aflashicon;
  //
  if (isIE && isWin)
  {
    document.write('<SCRIPT LANGUAGE=VBScript\> \n');
    document.write('on error resume next \n');
    document.write('flash2Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.2"))) \n');
    document.write('flash3Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.3"))) \n');
    document.write('flash4Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.4"))) \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('<\/SCRIPT\> \n');
  }
  detectFlash(); // will setup variable hasRightVersion
}

//ADL
function flash_obj(idname,swfmovie,swfwidth,swfheight,swfvars,bgcolor,is_transparent)
{
  if (!useRedirect)
  {
    if (hasRightVersion)    
      write_flash_obj(idname,swfmovie,swfwidth,swfheight,swfvars,bgcolor,is_transparent);      
    else
    {
      document.write('<div style="text-align:center;"><img src="'+flashicon+'" valign="middle"/> '+label_txt+' '
      +'<input type="button" value="'+button_txt+'" '
      +'onclick="window.open(\''+flashplug_url+'\',\'DownloadFlashPlugin\');" />'
      +'</div>');
    }
  }
}

//ADL
function resize_flash_obj(idname,width,height)
{
  document.getElementById(idname).width=""+width+"px";
  document.getElementById(idname).height=""+height+"px";
  document.getElementById(idname+"_embed").width=""+width+"px";
  document.getElementById(idname+"_embed").height=""+height+"px";
}

//ADL
// Return a string, dot-separated, with charCode for each characters of str_to_encode.
// last char is . (to have at least one dot in string)
function charcode_encode(str_to_encode)
{
  var str=new String();
  for (idx=0;idx<str_to_encode.length;idx++)
  {
    str+=str_to_encode.charCodeAt(idx)+".";
  }
  return str;
}

//ADL
// Return a string decoded from a dot-separated, with charCode for each characters of str_to_encode.
function charcode_decode(charcodelist_string)
{
  var str_arr = charcodelist_string.split(".");
  var fstring = new String();
  for (idx=0; idx<str_arr.length; idx++)
  {
    if (str_arr[idx].length>0)
      fstring += String.fromCharCode(str_arr[idx]);
  }
  delete str_arr;
  return fstring;
}

//ADL
function get_flashobject(flashid)
{
  if (window.document[flashid])
  {
    return window.document[flashid];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1)
  {
    if (document.embeds && document.embeds[flashid])
      return document.embeds[flashid];
    //else
      //alert("no flash object found");
  }
  else
  {
    return document.getElementById(flashid);
  }
}
