
//Determines the browser being used
    var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
    var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
    var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;

//////////////////////////////////////////////////
//Flash Version Methods///////////////////////////
//////////////////////////////////////////////////
    function controlVersion(){

        var version, activeXObject, error;

    //Attempts to initializes a new ActiveXObject for ShockwaveFlash 7
        try{

        //Initializes a new ActiveXObject
            activeXObject = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");

        //Grabs the version of the activeXObject
            version = activeXObject.GetVariable("$version");

        }

    //Error Control
        catch(error){}

    //If version wasn't initialized
        if(!version){

        //Attempts to initializes a new ActiveXObject for ShockwaveFlash 6
            try{

            //Initializes a new ActiveXObject
                activeXObject = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");

                // installed player is some revision of 6.0
                // GetVariable("$version") crashes for versions 6.0.22 through 6.0.29,
                // so we have to be careful.

            //Default the version to the first public version
                version = "WIN 6,0,21,0";

            //Throws and error if AllowScriptAccess does not exist (introduced in 6.0r47)
                activeXObject.AllowScriptAccess = "always";

            //Safe to call for 6.0r47 or greater
                version = activeXObject.GetVariable("$version");
            }

        //Error Control
            catch(error){}
        }

    //If version wasn't initialized
        if(!version){

        //Attempts to initializes a new ActiveXObject for ShockwaveFlash 4 or 5
            try{

            //Initializes a new ActiveXObject
                activeXObject = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");

            //Grabs the version of the activeXObject
                version = activeXObject.GetVariable("$version");
            }

        //Error Control
            catch(error){}
        }

    //If version wasn't initialized
        if(!version){

        //Attempts to initializes a new ActiveXObject for ShockwaveFlash 3
            try{

            //Initializes a new ActiveXObject
                activeXObject = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.3");

            //Sets the version of the activeXObject
                version = "WIN 3,0,18,0";
            }

        //Error Control
            catch(error){}
        }

    //If version wasn't initialized
        if(!version){

        //Attempts to initializes a new ActiveXObject for ShockwaveFlash 2
            try{

            //Initializes a new ActiveXObject
                activeXObject = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");

            //Sets the version of the activeXObject
                version = "WIN 2,0,0,11";
            }
            
        //Error Control--Sets the version to a null value -1
            catch(error){version = -1;}
        }

    //Returns the version
        return version;
    }

    function getSWFVersion(){

    //Initializes the flashVersion variable
        var flashVersion = -1;

    //Attempts to search for the Flash player in the plugins array if it exists--NetScape and Opera versions >= 3
        if(navigator.plugins != null && navigator.plugins.length > 0){
            if(navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]){

            //Grabs the swf version info
                var swVer2 = (navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "");
                var flashDescription = navigator.plugins["Shockwave Flash" + swVer2].description;
                var descArray = flashDescription.split(" ");
                var tempArrayMajor = descArray[2].split(".");
                var versionMajor = tempArrayMajor[0];
                var versionMinor = tempArrayMajor[1];
                var versionRevision = descArray[3];
                if(versionRevision == "")
                    versionRevision = descArray[4];

                if(versionRevision[0] == "d")
                    versionRevision = versionRevision.substring(1);

                else if(versionRevision[0] == "r"){
                    versionRevision = versionRevision.substring(1);
                    if(versionRevision.indexOf("d") > 0)
                        versionRevision = versionRevision.substring(0, versionRevision.indexOf("d"));
                }

            //Sets the flahVersion string
                flashVersion = versionMajor + "." + versionMinor + "." + versionRevision;
            }
        }

    //MSN/WebTV 2.6 supports Flash 4
        else if(navigator.userAgent.toLowerCase().indexOf("webtv/2.6") != -1)
            flashVersion = 4;
    //WebTV 2.5 supports Flash 3
        else if(navigator.userAgent.toLowerCase().indexOf("webtv/2.5") != -1)
            flashVersion = 3;

    //Older WebTV supports Flash 2
        else if(navigator.userAgent.toLowerCase().indexOf("webtv") != -1)
            flashVersion = 2;

    //If the browser is windows IE
        else if(isIE && isWin && !isOpera)
            flashVersion = controlVersion();

    //Returns the flashVersion
        return flashVersion;
    }

    function testFlashVersion(reqMajorVer, reqMinorVer, reqRevision){

    //Grabs the version of the SWF file
        versionStr = getSWFVersion();

    //Error Control
        if(versionStr == -1 )
            return false;
        
    //If version string was initialized
        if(versionStr != 0){

        //If user is running Windows IE
            if(isIE && isWin && !isOpera){

            //Given "WIN 2,0,0,11"
                tempArray         = versionStr.split(" ");     // ["WIN", "2,0,0,11"]
                tempString        = tempArray[1];            // "2,0,0,11"
                versionArray      = tempString.split(",");    // ['2', '0', '0', '11']
            }

        //Not Windows IE
            else{
                versionArray      = versionStr.split(".");
            }
            var versionMajor      = versionArray[0];
            var versionMinor      = versionArray[1];
            var versionRevision   = versionArray[2];

        //If the major version is greater than the requited major version
            if(versionMajor > parseFloat(reqMajorVer)){
                return true;
            }
            
        //If they are equal
            if(versionMajor == parseFloat(reqMajorVer)){

            //If minor version is greater than the required minor version
                if(versionMinor > parseFloat(reqMinorVer))
                    return true;

            //If they are equal
                if(versionMinor == parseFloat(reqMinorVer) && versionRevision >= parseFloat(reqRevision))
                        return true;
            }
        }

    //Returns false--not acceptable version
        return false;
    }
    

//////////////////////////////////////////////////
//Active Content Methods//////////////////////////
//////////////////////////////////////////////////
    function addExtension(src, ext){
      if(src.indexOf('?') != -1)
        return src.replace(/\?/, ext+'?');

      else
        return src + ext;
    }

    function generateObjectHTML(objAttrs, params, embedAttrs){

    //Initializes a new string variable
        var string = '';

    //If running Window IE, generates an appropriate <object> tag
        if(isIE && isWin && !isOpera){

        //Begins the <object> tag
            string += '<object ';

        //Iterates through the objAttrs Array
            for(var i in objAttrs){

            //Concatentates the next object attribute
                string += i + '="' + objAttrs[i] + '" ';
            }

        //Closes the opening <object> tag in the string
            string += '>';

        //Iterates through the params Array
            for(i in params){

            //Concatenates appropriate <param> tags
                string += '<param name="' + i + '"value="' + params[i] + '" />';
            }

        //Adds the closing </object> tag
            string += '</object>';
        }

    //Generates an appropriate <embed> tag
        else{

        //Begins the <embed> tag
            string += '<embed ';

         //Iterates through the embedAttrs Array
            for(i in embedAttrs){

            //Concatenates the embedAttrs data to the string
                string += i + '="' + embedAttrs[i] + '"';
            }

         //Ends the <embed> and add the </embed> tags
            string += '></embed>';
        }

    //Calls to write the string to the document model
        document.write(string);
    }

    function AC_FL_RunContent(){

    //Calls to generate the active content object
        var object = generateObjectArguments(arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000", "application/x-shockwave-flash");

    //Calls to output the HTML code to the document of the object's passed data
        generateObjectHTML(object.objAttrs, object.params, object.embedAttrs);
    }

    function AC_SW_RunContent(){
        
    //Calls to generate the active content object
        var object = generateObjectArguments(arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000", null);

    //Calls to output the HTML code to the document of the object's passed data
        generateObjectHTML(object.objAttrs, object.params, object.embedAttrs);
    }

    function generateObjectArguments(args, ext, srcParamName, classid, mimeType){

    //Initializes a new object Object
        var object = new Object();
            object.embedAttrs = new Object();
            object.params = new Object();
            object.objAttrs = new Object();

    //Iterates through the args Array
        for(var i=0; i < args.length; i += 2){

        //Grabs the current value in lowercase
            var value = args[i].toLowerCase();

        //Manages the value
            switch(value){
                case "classid":
                    break;
                case "pluginspage":
                        object.embedAttrs[args[i]] = args[i+1];
                    break;
                case "src":
                case "movie":
                        args[i+1] = addExtension(args[i+1], ext);
                        object.embedAttrs["src"] = args[i+1];
                        object.params[srcParamName] = args[i+1];
                    break;
                case "onafterupdate":
                case "onbeforeupdate":
                case "onblur":
                case "oncellchange":
                case "onclick":
                case "ondblClick":
                case "ondrag":
                case "ondragend":
                case "ondragenter":
                case "ondragleave":
                case "ondragover":
                case "ondrop":
                case "onfinish":
                case "onfocus":
                case "onhelp":
                case "onmousedown":
                case "onmouseup":
                case "onmouseover":
                case "onmousemove":
                case "onmouseout":
                case "onkeypress":
                case "onkeydown":
                case "onkeyup":
                case "onload":
                case "onlosecapture":
                case "onpropertychange":
                case "onreadystatechange":
                case "onrowsdelete":
                case "onrowenter":
                case "onrowexit":
                case "onrowsinserted":
                case "onstart":
                case "onscroll":
                case "onbeforeeditfocus":
                case "onactivate":
                case "onbeforedeactivate":
                case "ondeactivate":
                case "type":
                case "codebase":
                case "id":
                        object.objAttrs[args[i]] = args[i+1];
                    break;
                case "width":
                case "height":
                case "align":
                case "vspace":
                case "hspace":
                case "class":
                case "title":
                case "accesskey":
                case "name":
                case "tabindex":
                        object.embedAttrs[args[i]] = object.objAttrs[args[i]] = args[i+1];
                    break;
                default:
                        object.embedAttrs[args[i]] = object.params[args[i]] = args[i+1];
            }
        }

    //Sets the 'classid' value in the object's objAttrs Array
        object.objAttrs["classid"] = classid;

    //Sets the 'type' mimeType value in the object's embedAttrs Array
        if(mimeType)
            object.embedAttrs["type"] = mimeType;

    //Returns the object
        return object;
    }
