

/*
	***************************************************************
	* Description:    This is the JavaScript file for the Kyocera *
	*                 Mita exhibeo site that displays Flash files *
	*                 from exhibeo(TM) pages.                     *
	*                                                             *
	* Author:         Hyro Technologies (16/04/2004).             *
	*                                                             *
	***************************************************************
*/


var m_intWidth;
var m_intHeight;

var m_strSource;
var m_strQuality;

var m_strBgColour;
var m_strAlignment;

var m_strBackupImage;


// The following variables are used by the flash detection function.
var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.indexOf("Windows") != -1) ? true : false;
var isMac = (navigator.appVersion.indexOf("Mac") != -1) ? true : false;


function flashWriter()
{
    /*
    ----------------------------------------------------
    Comments Block
    ----------------------------------------------------
    @name           :   flashWriter.
    @description    :   "object" constructor.

    @prerequisites  :   none.
    @argument(s)    :   none.
    @return         :   nothing.
    ----------------------------------------------------
    */

    // Properties.
    m_intWidth = null;
    m_intHeight = null;

    m_strSource = null;
    m_strQuality = null;

    m_strBgColour = null;    
    m_strAlignment = null;

    m_strBackupImage = null;


    // Methods.
    this.width = setWidth;
    this.height = setHeight;

    this.source = setSource;
    this.quality = setQuality;

    this.bgcolor = setBgColour;
    this.align = setAlignment;

    this.noFlashImage = setBackupImage;
    this.write = write;
}


function setWidth(intWidth)
{
    /*
    ----------------------------------------------------
    Comments Block
    ----------------------------------------------------
    @name           :   setWidth.
    @description    :   sets the width value
                        for the Flash code.

    @prerequisites  :   none.
    @argument(s)    :   strWidth        - string.
    @return         :   nothing.
    ----------------------------------------------------
    */

    if (!isNaN(parseInt(intWidth)))
    {
        if (parseInt(intWidth) > 0)
            m_intWidth = intWidth;
    }
}


function setHeight(intHeight)
{
    /*
    ----------------------------------------------------
    Comments Block
    ----------------------------------------------------
    @name           :   setHeight.
    @description    :   sets the height value
                        for the Flash code.

    @prerequisites  :   none.
    @argument(s)    :   strHeight       - string.
    @return         :   nothing.
    ----------------------------------------------------
    */

    if (!isNaN(parseInt(intHeight)))
    {
        if (parseInt(intHeight) > 0)
            m_intHeight = intHeight;
    }
}


function setSource(strSource)
{
    /*
    ----------------------------------------------------
    Comments Block
    ----------------------------------------------------
    @name           :   setSource.
    @description    :   sets the source value
                        for the Flash code.

    @prerequisites  :   none.
    @argument(s)    :   strSource       - string.
    @return         :   nothing.
    ----------------------------------------------------
    */

    if (strSource == null)
        return;

    strSource = trim(strSource.toString());

    if (strSource.toLowerCase().indexOf(".swf") == -1)
        return;

    if (strSource.length > 0)
        m_strSource = strSource;
}


function setQuality(strQuality)
{
    /*
    ----------------------------------------------------
    Comments Block
    ----------------------------------------------------
    @name           :   setQuality.
    @description    :   sets the quality value
                        for the Flash code.

    @prerequisites  :   none.
    @argument(s)    :   strQuality      - string.
    @return         :   nothing.
    ----------------------------------------------------
    */

    if (strQuality == null)
        return;

    strQuality = trim(strQuality.toString().toLowerCase());

    if (((strQuality == "low") || (strQuality == "medium") || (strQuality == "high")) && (strQuality.length > 0))
        m_strQuality = strQuality;
    else
        m_strQuality = "high";          // Default to high.
}


function setBgColour(strColour)
{
    /*
    ----------------------------------------------------
    Comments Block
    ----------------------------------------------------
    @name           :   setBgColour.
    @description    :   sets the background colour
                        value for the Flash code.

    @prerequisites  :   none.
    @argument(s)    :   strColour       - string.
    @return         :   nothing.
    ----------------------------------------------------
    */

    if (strColour == null)
        return;

    m_strBgColour = trim(strColour.toString());
}


function setAlignment(strAlignment)
{
    /*
    ----------------------------------------------------
    Comments Block
    ----------------------------------------------------
    @name           :   setAlignment.
    @description    :   sets the alignment
                        value for the Flash code.

    @prerequisites  :   none.
    @argument(s)    :   strAlignment    - string.
    @return         :   nothing.
    ----------------------------------------------------
    */

    if (strAlignment == null)
        return;

    strAlignment = trim(strAlignment.toString().toLowerCase());

    var arrAlignmentValues = new Array("absbottom",
                                       "absmiddle",
                                       "baseline",
                                       "bottom",
                                       "left",
                                       "middle",
                                       "right",
                                       "texttop",
                                       "top");

    var intIndex = 0;
    var intCollectionLength = arrAlignmentValues.length;

    var blnFoundMatching = false;


    for (; intIndex < intCollectionLength; intIndex++)
    {
        if (strAlignment == arrAlignmentValues[intIndex])
        {
            blnFoundMatching = true;
            break;
        }
    }


    if (blnFoundMatching)
        m_strAlignment = trim(strAlignment.toString());
    else
        m_strAlignment = "left";        // Default to left.


    // Free variables.
    arrAlignmentValues = null;

    intIndex = null;
    intCollectionLength = null;
    blnFoundMatching = null;
}


function setBackupImage(strImage)
{
    /*
    ----------------------------------------------------
    Comments Block
    ----------------------------------------------------
    @name           :   setBackupImage.
    @description    :   sets the backup image
                        value for the Flash code.

    @prerequisites  :   none.
    @argument(s)    :   strImage        - string.
    @return         :   nothing.
    ----------------------------------------------------
    */

    if (strImage == null)
        return;

    m_strBackupImage = trim(strImage.toString());
}


function write()
{
    /*
    ----------------------------------------------------
    Comments Block
    ----------------------------------------------------
    @name           :   write.
    @description    :   "writes" out the Flash code to 
                        the current document.

    @prerequisites  :   none.
    @argument(s)    :   none.
    @return         :   nothing.
    ----------------------------------------------------
    */


    /*
     *  Required values:
     *      - width.
     *      - height.
     *      - source.
     *
     *  Optional values:
     *      - quality       (defaults to "high").
     *      - bgColor       (defaults to "white").  
     *      - align         (defaults to "left").
     */


    var strTemp = "";

    if (getFlashVersion() > 5)
    {
        if ((m_strSource != null) && (m_intWidth != null) && (m_intHeight != null))
        {
            var strSourceName = m_strSource.substr(0, m_strSource.lastIndexOf("."));
            m_strSource = "files/1/" + m_strSource;


            if (m_strQuality == null)
                m_strQuality = "high";

            if (m_strBgColour == null)
                m_strBgColour = "white";

            if (m_strAlignment == null)
                m_strAlignment = "left";


            strTemp += "\n    <object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\"";
            strTemp += "\n     codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\"";
            strTemp += "\n     width=\"" + m_intWidth + "\" height=\"" + m_intHeight + "\" id=\"" + strSourceName + "\" align=\"" + m_strAlignment + "\">";
            strTemp += "\n        <param name=\"movie\" value=\"" + m_strSource + "\"/>";
            strTemp += "\n        <param name=\"quality\" value=\"" + m_strQuality + "\"/>";
            strTemp += "\n        <param name=\"bgcolor\" value=\"" + m_strBgColour + "\"/>";
            strTemp += "\n        <embed src=\"" + m_strSource + "\" quality=\"" + m_strQuality + "\" bgcolor=\"" + m_strBgColour + "\" width=\"" + m_intWidth + "\" height=\"" + m_intHeight + "\" name=\"" + strSourceName + "\" align=\"" + m_strAlignment + "\"";
            strTemp += "\n         type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\">";
            strTemp += "\n        </embed>";
            strTemp += "\n    </object>";

            document.write(strTemp);


            // Free variable.
            strSourceName = null;
        }
        else
        {
            if (m_intWidth == null)
                strTemp += "\n\t- Width.";

            if (m_intHeight == null)
                strTemp += "\n\t- Height."

            if (m_strSource == null)
                strTemp += "\n\t- Source.";

            alert("The following Flash attribute(s) have not been supplied or set      \nproperly in the flashWriter code placed in a content area:\n" + strTemp + "\n\ntherefore, the Flash file will not be displayed.\nPlease supply or correct the listed attribute(s).\n\n");
        }
    }
    else
    {
        if ((m_strBackupImage != null) && (m_strBackupImage.length > 0))
        {
            strTemp = m_strBackupImage.toLowerCase();

            if ((strTemp.indexOf(".jpg") == -1) && (strTemp.indexOf(".gif") == -1) && (strTemp.indexOf(".jpeg") == -1) && (strTemp.indexOf(".png") == -1) && (strTemp.indexOf(".bmp") == -1))
                alert("The supplied backup image is not an image format       \nsupported by exhibeo.\n\nThe supplied backup image will not be displayed.");
            else
            {
                m_strBackupImage = "images/1/" + m_strBackupImage;
                strTemp = "\n    <img src=\"" + m_strBackupImage + "\">";

                document.write(strTemp);
            }
        }
    }


    // Free variables.
    strTemp = null;

    m_intWidth = null;
    m_intHeight = null;

    m_strSource = null;
    m_strQuality = null;

    m_strBgColour = null;
    m_strAlignment = null;

    m_strBackupImage = null;
}


function trim(s)
{
    /*
    ----------------------------------------------------
    Comments Block
    ----------------------------------------------------
    @name           :   trim.
    @description    :   trims a string of leading and
                        trailing white space.

    @prerequisites  :   none.
    @argument(s)    :   s               - string.
    @return         :   string.
    ----------------------------------------------------
    */

	return ltrim(rtrim(s));
}


function ltrim(s)
{
    /*
    ----------------------------------------------------
    Comments Block
    ----------------------------------------------------
    @name           :   ltrim.
    @description    :   trims a string of leading
                        white space.

    @prerequisites  :   none.
    @argument(s)    :   s               - string.
    @return         :   string.
    ----------------------------------------------------
    */

    return s.replace(/^\s+/g, "");
}


function rtrim(s)
{
    /*
    ----------------------------------------------------
    Comments Block
    ----------------------------------------------------
    @name           :   rtrim.
    @description    :   trims a string of trailing
                        white space.

    @prerequisites  :   none.
    @argument(s)    :   s	            - string.
    @return         :   string.
    ----------------------------------------------------
    */

    return s.replace(/\s+$/g, "");
}


function getFlashVersion()
{
    /*
    ----------------------------------------------------
    Comments Block
    ----------------------------------------------------
    @name           :   getFlashVersion.
    @description    :   returns the Flash version
                        installed on the end machine.

    @prerequisites  :   none.
    @argument(s)    :   none.
    @return         :   integer.

        Flash Version Detector  v1.1.5
        http://www.dithered.com/javascript/flash_detect/index.html
        code by Chris Nott (chris@NOSPAMdithered.com - remove NOSPAM)
        with VBScript code from Alastair Hamilton.

        Modified for specific usage (Hyro Technologies).
        20/02/2004.

    ----------------------------------------------------
    */


    var flashVersion_DONTKNOW = -1;
    var agent = navigator.userAgent.toLowerCase(); 


    // NS3 needs flashVersion to be a local variable.
    if (agent.indexOf("mozilla/3") != -1 && agent.indexOf("msie") == -1)
        flashVersion = 0;


    // NS3+, Opera3+, IE5+ Mac (support plugin array):  check for Flash plugin in plugin array.
    if ((navigator.plugins != null) && (navigator.plugins.length > 0))
    {
        var flashPlugin = navigator.plugins['Shockwave Flash'];

    	if (typeof flashPlugin == 'object')
    	{ 
    	    if (flashPlugin.description.indexOf('7.') != -1)
       	    	flashVersion = 7;
    	    else if (flashPlugin.description.indexOf('6.') != -1)
            	flashVersion = 6;
    	    else if (flashPlugin.description.indexOf('5.') != -1)
    	       	flashVersion = 5;
    	    else if (flashPlugin.description.indexOf('4.') != -1)
    	        flashVersion = 4;
    	    else if (flashPlugin.description.indexOf('3.') != -1)
    	        flashVersion = 3;
    	}
    }

    // IE4+ Win32:  attempt to create an ActiveX object using VBScript.
    else if (agent.indexOf("msie") != -1 && parseInt(navigator.appVersion) >= 4 && agent.indexOf("win")!=-1 && agent.indexOf("16bit")==-1)
    {
        document.write('<script language="VBScript"\> \n');
        document.write('on error resume next \n');
        document.write('dim obFlash \n');
        document.write('set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.7") \n');
        document.write('if IsObject(obFlash) then \n');
        document.write('flashVersion = 7 \n');
        document.write('else set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.6") end if \n');
        document.write('if flashVersion < 7 and IsObject(obFlash) then \n');
        document.write('flashVersion = 6 \n');
        document.write('else set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.5") end if \n');
        document.write('if flashVersion < 6 and IsObject(obFlash) then \n');
        document.write('flashVersion = 5 \n');
        document.write('else set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.4") end if \n');
        document.write('if flashVersion < 5 and IsObject(obFlash) then \n');
        document.write('flashVersion = 4 \n');
        document.write('else set obFlash = CreateObject("ShockwaveFlash.ShockwaveFlash.3") end if \n');
        document.write('if flashVersion < 4 and IsObject(obFlash) then \n');
        document.write('flashVersion = 3 \n');
        document.write('end if');
        document.write('</script\> \n');
    }

    // WebTV 2.5 supports flash 3.
    else if (agent.indexOf("webtv/2.5") != -1)
        flashVersion = 3;

    // Older WebTV supports flash 2.
    else if (agent.indexOf("webtv") != -1)
        flashVersion = 2;

    // Can't detect in all other cases.
    else
        flashVersion = flashVersion_DONTKNOW;

    return flashVersion;
}
