// JScript File
// set this to the max version of flash that you'll ever deal with.
var MAX_FLASH_VERSION = 9;

// this needs to be global to use in VBScript with IE/Win
var FlashVersionInstalled = 0;

// the Object Definition
function FlashDetector()
{

                //other variables
                this.errors = '';
                this.version = 0;

                this.LoadContainer = function(theId) {
                                if(!document.getElementById){
                                                this.containerId = '';
                                                this.container = null;
                                }else{
                                                if(theId) this.containerId = theId;
                                                this.container = document.getElementById(this.containerId);
                                }
                }

                this.HasVersion = function(sVersion)
                {
                                if(!this.DetectFlash())return false;
                                if(!sVersion)sVersion = this.requiredVersion;
                                if(!sVersion){
                                                this.errors += 'No version specified.  Set the requiredVersion property or send a version as an argument to HasVersion.\n';
                                                return false;
                                }
                                if(!this.version) {
                                                this.errors +='No version could be found.\n';
                                                return false;
                                }
                                return (this.version >= sVersion);
                }

                this.DetectFlash = function()
                {
                                if(this.Detected) return this.HasFlash;

                                this.Detected = false;

                                this.HasFlash=false;
                                var flashDescription = '';
                                if(!navigator)return false; //??

                                if(navigator.appVersion) {
                                                if(navigator.appVersion.indexOf("MSIE") != -1 && navigator.appVersion.toLowerCase().indexOf("win") != -1)this.version = FlashVersionInstalled;
                                }

                                if(navigator.mimeTypes||navigator.plugins){
                                                if(navigator.mimeTypes) {
                                                                if(navigator.mimeTypes['application/x-shockwave-flash']){
                                                                                this.HasFlash=true;
                                                                                if(navigator.mimeTypes['application/x-shockwave-flash'].enabledPlugin){
                                                                                                if(navigator.mimeTypes['application/x-shockwave-flash'].enabledPlugin.description){
                                                                                                                // A flash plugin-description (usually) looks like this: Shockwave Flash 7.0 r19
                                                                                                                // pull the first number out of it, and hope for the best!
                                                                                                                flashDescription=navigator.mimeTypes['application/x-shockwave-flash'].enabledPlugin.description;
                                                                                                }else this.errors+='no description on the flash plugin.\n'; //can't know version without description.
                                                                                }else this.errors+='the mimeType is defined, but no plugin is enabled.\n'; //? this is weird.  
                                                                }
                                                }else{
                                                                //no mimeTypes.  Try the plugins array
                                                                if(navigator.plugins['Shockwave Flash']||navigator.plugins['Shockwave Flash 2.0']){
                                                                                var isVersion2 = navigator.plugins['Shockwave Flash 2.0'] ? ' 2.0' : '';
                                                                                flashDescription = navigator.plugins['Shockwave Flash' + isVersion2].description;
                                                                }
                                                }
                                }
                                if(flashDescription != '') {
                                                //found something somewhere...
                                                var v=parseInt(flashDescription.replace(/^[^0-9]*/,''));
                                                if(!isNaN(v))this.version=v;
                                }
                                //doing this in a weird way because we might have flash, and yet not know the version.
                                if(this.version){
                                                this.HasFlash=true;
                                                //whatever the error was, we worked past it!
                                                this.errors='';
                                }
                                this.Detected = true;
                                return this.HasFlash;
                }
}
