// JavaScript Document
/*******************************************************************************
	Filename		: swf_embed.js
	Created			: 25-02-2008
	Created by		: Markus Sommerfeld
	Company		    : Charamel GmbH

	Comments		: JavaScript Class to embed a Flash file into the HTML content.
	                  Includes the Flash Player Version Detection - Rev 1.6
                      By Adobe Macromedia 
                      
    Modify #1
    Modified by     :   Markus Sommerfeld
    Modify Date     :   19-03-2008
    Modify Type     :   add ";" to each end of function (){};
                        necessary for JS compression
    
    Modify #2
    Modified by     :   Markus Sommerfeld
    Modify Date     :   25-03-2008
    Modify Type     :   The default _BGCOLOR is now NULL to use the 
                        bgColor which is defined in the Flash-File 
                        
    Modify #3
    Modified by     :   Markus Sommerfeld
    Modify Date     :   18-04-2008
    Modify Type     :   DEBUG of no flashplayer installed.
                        Is no FlashPlayer installed the script returns an error
                        
    Modify #4
    Modified by     :   Markus Sommerfeld
    Modify Date     :   05-05-2008
    Modify Type     :   change of WMODE opage in opaque                                                 
                                                 
*******************************************************************************/

function SWFembed(_ID, _ID_SWF, _SOURCE, _PARAMETERS)
{
    if (_ID == undefined || _ID==null){
        alert ("ERROR: you have to specify a Layer ID !!!");
        return false;
    };

    if (_ID_SWF == undefined || _ID_SWF==null){
        alert ("ERROR: you have to specify a Layer ID !!!");
        return false;
    };

    if (_SOURCE == undefined || _SOURCE==null){
        alert ("ERROR: the Source URL is not defined !!!");
        return false;
    };    
       
        
    //--- DEFAULT VALUES FOR SWF EMBADED
    var _DEFAULTS = new Object
    ({
        /***************************************
         *  Default Path to the SWF JS.
         *  This is the value where the swf_embed
         *  file is saved.                        
         ***************************************/ 
        _JS_PATH                : "js/swf_embed",

        /***************************************
         *  Default SWF ICON which will be shown
         *  when the client dosne't have the require
         *  SFW Version                  
         ***************************************/ 
        _SFW_ICO_SHOW           : true,
        _SFW_ICO                : "icon/swf_ico.jpg",

        /***************************************
         *  The default error message.
         *  Will be showed when the JS detect
         *  that's the client doesn't have the
         *  requre SWF Version                           
         ***************************************/ 
        _ERROR_MSG              : "This content requires<br />"
                                 +"the Adobe Flash Player<br />Version: ",
        
        /***************************************
         *  Default value for the PluginPage.
         *  This is the site where you can
         *  download the latest version of
         *  Flash Player                  
         ***************************************/ 
        _PLUGIN_PAGE            : "http://www.adobe.com/go/getflashplayer",

        /***************************************
         *  Default value for the size
         *  value could be in px or % 
         *  (100px or 100%)           
         ***************************************/ 
        _WIDTH                  : "100%",
        _HEIGHT                 : "100%",
        
        /***************************************
         *  Default value for the quality
         *  provided values are:
         *  high, autohigh, best Low, autolow                            
         ***************************************/ 
        _QUALITY                : "high",
        
        /***************************************
         *  Default value for the align
         *  provided values are:
         *  left, right, middle                            
         ***************************************/ 
        _ALIGN                  : "top",        

        /***************************************
         *  Default value for the background
         *  HEX value for the backgroundColor
         *  WITHE   = #FFFFFF;
         *  BLACK   = #000000;
         *  RED     = #FF0000;
         *  Visit http://www.colorschemer.com/
         *  for more colors                                                     
         ***************************************/ 
        _BGCOLOR                : "",

        /***************************************
         *  Default value of the window mode
         *  provided values are:
         *  window, opaque, transparent                            
         ***************************************/ 
        _WMODE                  : "opaque",

        /***************************************
         *  Default value of the Flash scale
         *  Animation's resizing definition.  
         *  provided values are:
         *  showall, noborder, exactfit                            
         ***************************************/       
        _SCALE                  : "exactfit",
        
        /***************************************
         *  Default value of autoplay
         *  Automatic Start of animation, 
         *  or not, when page is loaded.         
         *  true or false                            
         ***************************************/
         _AUTOPLAY               : true,   
         
        /***************************************
         *  Default value for LOOP
         *  Repeat Flash-Object or only once.  
         *  true or false                            
         ***************************************/
         _LOOP                   : true,   
        
        /***************************************
         *  Default value for menu
         *  Shows the context menu over the
         *  Flash-Object  
         *  true or false                            
         ***************************************/                      
        _MENU                   : true,
        
        /***************************************
         *  Aks to install the require Version
         *  true or false           
         ***************************************/               
        _EXPRESS_INSTALL        : false,
        _EXPRESS_INSTALL_FILE   : "expressinstall.swf",        

        /***************************************
         *  Default value of require Flash Version
         ***************************************/          
        _REQUIRED_MAJOR_VER     : 9,
        _REQUIRED_MINOR_VER     : 0,
        _REQUIRED_VER           : 0,        
        
        _TYPE                   : "application/x-shockwave-flash",
        _SCRIPT_ACCESS          : "sameDomain",
        
        _BASE                   : ""
    });

    /***************************
    *  VARS
    ***************************/
    this.swfDIV     = _ID;
    this.swfID     = _ID_SWF;
    this.source     = _SOURCE;
    this.parameters = _PARAMETERS;
    this.swfEmbed = "";
    this.swfObject = "";
    this.flashVar   = "";
    this.swfVersion;

    /***************************
    *  METHODS
    ***************************/
    this.getFlashVersion        = getFlashVersion;
    this.getDefaultValue        = getDefaultValue;
    this.isFlashInstalled       = isFlashInstalled;
    this.isRequestedVersion     = isRequestedVersion;
    this.generateSWFembed       = generateSWFembed;
    this.getGenerateSWFembed    = getGenerateSWFembed;
    this.getGenerateSWFobject   = getGenerateSWFobject;
    this.getSWFembedObject      = getSWFembedObject;
    this.generateSWFobject      = generateSWFobject;
    this.getAlternateContent    = getAlternateContent;
    this.setParameter           = setParameter;
    this.getParameter           = getParameter;
    this.getTags                = getTags;
    this.addVariable            = addVariable;
    this.init                   = init;

    
    /************************************
    *  Method to get the default
    *  values of the Object (_DEFAULT)    
    *************************************/    
    function getDefaultValue(_DEF)
    {
        var returnValue = _DEFAULTS[_DEF];
        return returnValue;
    };
    
    /*************************************************
    *  Check is parameters is given on false 
    *  set the parameter Object to Null    
    ************************************************/     
    if (this.parameters == undefined){
        this.parameters = new Object();
    };
    
    /*************************************************
    *  If one parameter is not given, then the default
    *  value will be used.    
    ************************************************/     
    if (this.parameters["jsPath"]       == undefined){
        this.parameters["jsPath"]       = this.getDefaultValue("_JS_PATH");};
    if (this.parameters["iconShow"]     == undefined){
        this.parameters["iconShow"]     = this.getDefaultValue("_SFW_ICO_SHOW");};
    if (this.parameters["icon"]         == undefined){
        this.parameters["icon"]         = this.getDefaultValue("_SFW_ICO");};
    if (this.parameters["errorMsg"]     == undefined){
        this.parameters["errorMsg"]     = this.getDefaultValue("_ERROR_MSG");};
    if (this.parameters["pluginPage"]   == undefined){
        this.parameters["pluginPage"]   = this.getDefaultValue("_PLUGIN_PAGE");}; 
    if (this.parameters["type"]         == undefined){
        this.parameters["type"]         = this.getDefaultValue("_TYPE");}; 
    if (this.parameters["width"]        == undefined){
        this.parameters["width"]        = this.getDefaultValue("_WIDTH");}; 
    if (this.parameters["height"]       == undefined){
        this.parameters["height"]       = this.getDefaultValue("_HEIGHT");}; 
    if (this.parameters["quality"]      == undefined){
        this.parameters["quality"]      = this.getDefaultValue("_QUALITY");};
    if (this.parameters["align"]        == undefined){
        this.parameters["align"]        = this.getDefaultValue("_ALIGN");};
    if (this.parameters["bgColor"]      == undefined){
        this.parameters["bgColor"]      = this.getDefaultValue("_BGCOLOR");};  
    if (this.parameters["wMode"]        == undefined){
        this.parameters["wMode"]        = this.getDefaultValue("_WMODE");};
    if (this.parameters["scale"]        == undefined){
        this.parameters["scale"]        = this.getDefaultValue("_SCALE");};
    if (this.parameters["autoplay"]     == undefined){
        this.parameters["autoplay"]     = this.getDefaultValue("_AUTOPLAY");};
    if (this.parameters["loop"]         == undefined){
        this.parameters["loop"]         = this.getDefaultValue("_LOOP");};
    if (this.parameters["menu"]         == undefined){
        this.parameters["menu"]         = this.getDefaultValue("_MENU");};
    if (this.parameters["expressInst"]   == undefined){
        this.parameters["expressInst"]   = this.getDefaultValue("_EXPRESS_INSTALL");};
    if (this.parameters["expressInstF"]  == undefined){
        this.parameters["expressInstF"]  = this.getDefaultValue("_EXPRESS_INSTALL_FILE");};        
    if (this.parameters["scriptAccess"] == undefined){
        this.parameters["scriptAccess"] = this.getDefaultValue("_SCRIPT_ACCESS");};
    if (this.parameters["requireVer"]   == undefined){
        this.parameters["requireVer"]   = this.getDefaultValue("_REQUIRED_MAJOR_VER");};
    if (this.parameters["base"]         == undefined){
        this.parameters["base"]         = this.getDefaultValue("_BASE");};        
    
    /*************************************************
    *  set / get the parameter value 
    ************************************************/     
    function setParameter(_NAME, _VALUE){ this.parameters[_NAME] = _VALUE;};
    function getParameter(_NAME){ return this.parameters[_NAME];};
    
    /*************************************************
    *  Version check for the Flash Player 
    *  that has the ability to start Player 
    *  Product Install (6.0r65)
    *
    *  return true or false       
    ************************************************/              
    function isFlashInstalled()
    {
        var isInstalled = DetectFlashVer(6, 0, 65);
        return isInstalled;
    };
    
    /*************************************************
    *  Version check 
    *  based upon the values defined in globals 
    *
    *  return true or false       
    ************************************************/              
    function isRequestedVersion()
    {
        var hasVersion = DetectFlashVer(   
                                        this.getParameter("requireVer"),
                                        this.getDefaultValue("_REQUIRED_MINOR_VER"), 
                                        this.getDefaultValue("_REQUIRED_VER")
                                        );
        return hasVersion;
    };
    
    
    /*************************************************
    *  return the Flash Version    
    ************************************************/      
    function getFlashVersion()
    {
        return GetSwfVer();
    };
    
    /*************************************************
    *  returns the Generated SWF <embed>           
    ************************************************/      
    function generateSWFembed()
    {
        var embedObject = "<EMBED name='"+_ID_SWF+"'";
        for (var tag in this.embTag)
            embedObject += tag + "='"+ this.embTag[tag] +"' ";
        for (var tag in this.optionalTag)
            embedObject += tag + "='"+ this.optionalTag[tag] +"' ";
        
        if (this.flashVar!="")
          embedObject += "FlashVars='" + this.flashVar + "'";
        
        embedObject += "\/>";
        
        this.swfEmbed = embedObject;
        return embedObject;
    };
    function getGenerateSWFembed(){ return this.swfEmbed;};
    
    /*************************************************
    *  returns the Generated SWF <object>                
    *************************************************/      
    function generateSWFobject()
    {
        var swfObject = "<OBJECT id='"+_ID_SWF+"' ";
        for (var tag in this.objTag)
        {
            if (tag != "asParams"){
                swfObject += tag + "='"+ this.objTag[tag] +"' ";
            }
            else
            {
                swfObject += ">";
                asParams = this.objTag["asParams"];
                for (var para in asParams)
                    swfObject += "<PARAM NAME='"+ para +"' VALUE='"+ asParams[para] +"'>"
            };
        };
        for (var tag in this.optionalTag){
            swfObject += "<PARAM NAME='"+ tag +"' VALUE='"+ this.optionalTag[tag] +"'>"
        };
            
        if (this.flashVar!=""){
            swfObject += "<PARAM NAME='FlashVars' VALUE='"+ this.flashVar +"'>"
        };
        
        this.swfObject = swfObject;
        return swfObject;
    }
    function getGenerateSWFobject(){ return this.swfObject;};
    
    /*************************************************
    *  returns the Generated SWF <object>                
    *************************************************/      
    function getSWFembedObject()
    {
        this.getTags();
        var swf  = this.generateSWFobject();
        swf     += this.generateSWFembed();
        swf     += "<\/OBJECT>";
        return swf;
    };
    
    /*************************************************
    *  add FlashVars                
    *************************************************/      
    function addVariable(varName,varValue)
    {
        if (varName!=""){ var andS = "="; }
        else{ var andS = "";};
        
        if (this.flashVar==""){this.flashVar += varName + andS + varValue;}
        else{this.flashVar += "&"+ varName + andS + varValue;};
    };    
    
    /*************************************************
    *  Alternative Content if the FlashPlayer Version
    *  to low or to old                    
    *************************************************/     
    function getAlternateContent()
    {
        var swf_ICON    = this.getParameter("jsPath") + "/" + this.getParameter("icon");
        var alt_TEXT    = this.getParameter("errorMsg");
        var plugInPage  = this.getParameter("pluginPage");
        var requireVer  = this.getParameter("requireVer");
        
        var alternateContent = ""
        + "<div align=center style='margin:30px'>"
        +   "<table>"
        +       "<tr>";

        if (this.getParameter("iconShow")==true)
        {
            alternateContent +=""
            +           "<td style='border:none'>"
            +               "<a href='"+ plugInPage +"' target='_blank'>"
            +                   "<img src='"+ swf_ICON +"' alt='"+ alt_TEXT +"'" 
            +                   "title='Adobe Flash Player nedded' style='border:none'>"
            +               "<\/a>"
            +           "<\/td>";
        };

        alternateContent +=""
        +           "<td style='border:none'>"
        +               "<span style='font-family:verdana;font-size:8pt;vertical-align:middle'>"
        +                   "<a href='"+ plugInPage +"' style='text-decoration:none;color:#571519' target='_blank'>"
        +                       alt_TEXT + requireVer
        +                   "<\/a>"
        +               "<\/span>"
        +               "<br />"
        +           "<\/td>"
        +       "<\/tr>"
        +       "<tr>"
        +           "<td colspan=2 align=center style='font-family:verdana;font-size:8pt;vertical-align:middle;font-weight:bold;border:none'>"        
        +               "Your Version is: " + this.swfVersion
        +           "<\/td>"
        +       "<\/tr>"
        +   "<\/table>"
        + "<\/div>";  
        return alternateContent;
    };
    
    /*************************************************
    *  Get the require <OBJECT> and <EMBED>
    *  also the optional TAGS     
    *************************************************/     
    function getTags()
    {
        this.embTag = new Object({
            src             : this.source,
            pluginspage     : this.getParameter("pluginPage"),
            width           : this.getParameter("width"),
            height          : this.getParameter("height")
        });
        this.objTag = new Object({
            classid         : "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000",
            codebase        : "https://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab#version=6,0,65,0",
            width           : this.getParameter("width"),
            height          : this.getParameter("height"),
            asParams        : new Object({
                                          movie:  this.source
                                        })
        });    
        this.optionalTag = new Object({
            play            	: this.getParameter("autoplay"),
            loop            	: this.getParameter("loop"),
            menu            	: this.getParameter("menu"),
            quality         	: this.getParameter("quality"),
            scale           	: this.getParameter("scale"),
            align           	: this.getParameter("align"),
            wmode           	: this.getParameter("wMode"), 
            bgcolor         	: this.getParameter("bgColor"),
            allowScriptAccess	: this.getParameter("allowScriptAccess"),
            base                : this.getParameter("base")
        });         
    };  

    /*************************************************
     * Initial the SWFembaded
     * check for the Flash Player
     * used method: isFlashInstalled()
     *      
     * Version check               
     * used method: isRequestedVersion()     
     *      
     * Is FLASH Player OK the FLASH will be
     * write in the given DIV Layer with 
     ************************************************/ 
    function init(additionalHTML)
    {
    	if ( (additionalHTML == undefined) || (! additionalHTML))
    		additionalHTML = "";
        if ( this.isFlashInstalled() && !this.isRequestedVersion() )
        {
            this.swfVersion = GetSwfVer();
            if(this.swfVersion.indexOf("WIN")!=-1){
                this.swfVersion = this.swfVersion.replace("WIN", "");
            };
        
            /*************************************************************
            *  MMdoctitle is the stored document.title value used by the 
            *  installation process to close the window that started the process
            *  This is necessary in order to close browser windows that 
            *  are still utilizing the older version of the 
            *  player after installation has completed
            *  DO NOT MODIFY THE FOLLOWING FOUR LINES
            *  Location visited after installation is complete if installation is required         
            **************************************************************/ 
        	var MMPlayerType = (isIE == true) ? "ActiveX" : "PlugIn";
        	var MMredirectURL = window.location;
            document.title = document.title.slice(0, 47) + " - Flash Player Installation";
            var MMdoctitle = document.title;
            
            if (this.getParameter("expressInst")==true)
            {
                this.getTags();
                this.source = this.getParameter("jsPath") + "/" + this.getParameter("expressInstF");
                this.embTag["src"]   = this.source;
                this.objTag["asParams"]["movie"] = this.source;
                var swfObjEmb = this.getSWFembedObject();
                document.getElementById(this.swfDIV).innerHTML = swfObjEmb;
            }
            else
            {
                document.getElementById(this.swfDIV).innerHTML = this.getAlternateContent();
            };
        }
        else if (this.isRequestedVersion()) 
        {
            /*************************************************************
            * The installed FLASH Player is OK
            *************************************************************/
            var swfObjEmb = this.getSWFembedObject();
            document.getElementById(this.swfDIV).innerHTML = swfObjEmb + additionalHTML;
        }    
        else 
        {  
            /*************************************************************
            * The installed FLASH Player is too old or the JS could not
            * detect the plugin         
            *************************************************************/                                            
            document.getElementById(this.swfDIV).innerHTML = this.getAlternateContent();
        };
    };
};
