
var undefined;


// getBrowserMake -- a quick and dirty browser detect method
var g_BrowserMake;

// browser types
var kIe			= "ie";			
var kNavigator	= "navigator";	
var kNetscape4	= kNavigator;	
var kMozilla	= "mozilla";		
var kNetscape6	= kMozilla;		
var kNetscape7	= kMozilla;
var kSafari		= "safari";		
var kUnknown	= "unsupported";

// OS versions
var kWin32		= "Win32"
var kSunOS		= "SunOS";
var kMac		= "Mac";

function getBrowserMake()
{

	if ( g_BrowserMake == undefined )
	{
		var strAgent = navigator.userAgent.toLowerCase();	
		if ( strAgent.indexOf('safari') >= 0 )
			g_BrowserMake = kSafari;
		else if ( navigator.appName == 'Netscape' )
			g_BrowserMake = document.getElementById ? kMozilla : kNavigator; 
		else		
			g_BrowserMake = document.all ? kIe : kUnknown; 		
	}
	

	return g_BrowserMake;
}



// do we think this browser uses Active X 
function isActiveXBrowser()
{
	return (getBrowserMake() == kIe);
}


function getBrowserOS()
{
	var strOs = navigator.platform;

	if (strOs == 'Win32')
		return kWin32;
		
	if (strOs.indexOf('Mac') == 0)
		return kMac;

	return kUnknown;
}

function isOSX()
{
	var isX = false;
	if (getBrowserOS() == kMac )
	{
		// http://home.dobbelaere.com:7080/tim/client_sniffer.html
		var agt = navigator.userAgent.toLowerCase();
		isX = ((agt.indexOf("os x") != -1) || (agt.indexOf("osx") != -1));
	}
	
	return isX;
}


//
// Global Utils for plugin detection
// use global properties and util to share more simply with vbscript and detectXxx files
//
var g_detectableWithVB = false;	

// plugin detection function from web article
// pass in variable number of strings for plugin names
// looks for plugs by inspecting browser plugin object.
// does NOT look at browser MIME types
// does NOT look for ActiveX controls
function detectPlugin(arrPlugins, outVersion) {
 	// allow for multiple checks in a single pass
    var daPlugins = arrPlugins;//detectPlugin.arguments;
    // consider pluginFound to be false until proven true
    var pluginFound = false;
    // if plugins array is there and not fake
    if (navigator.plugins && navigator.plugins.length > 0) {
	var pluginsArrayLength = navigator.plugins.length;
	// for each plugin...
	for (pluginsArrayCounter=0; pluginsArrayCounter < pluginsArrayLength; pluginsArrayCounter++ ) {
	    // loop through all desired names and check each against the current plugin name
	    var numFound = 0;
		var plugin;
		var pluginversion; 
	    for(namesCounter=0; namesCounter < daPlugins.length; namesCounter++) 
		{
			plugin = navigator.plugins[pluginsArrayCounter];
		
		// if desired plugin name is found in either plugin name or description
		if( (plugin.name.indexOf(daPlugins[namesCounter]) >= 0) || 
		    (plugin.description.indexOf(daPlugins[namesCounter]) >= 0) ) 
			{
				// this name was found...
				
				// add version info
				pluginversion = (plugin.description.substring(plugin.description.indexOf(".")-1));
				outVersion[numFound] = pluginversion;
			
			    // bump counter
			    numFound++;
			}   
	    }
	    // now that we have checked all the required names against this one plugin,
	    // if the number we found matches the total number provided then we were successful
	    if(numFound == daPlugins.length) {
		pluginFound = true;
		// if we've found the plugin, we can stop looking through at the rest of the plugins
		break;
	    }
	}
    }
    return pluginFound;
} // detectPlugin




// detectActiveXControl
//
// vbscript detection code ala Apple
if (isActiveXBrowser())
{
	document.writeln('<script language="VBscript">');

	document.writeln('\'do a one-time test for a version of VBScript that can handle this code');
	document.writeln('g_detectableWithVB = False');
	document.writeln('If ScriptEngineMajorVersion >= 2 then');
	document.writeln('  g_detectableWithVB = True');
	document.writeln('End If');

	document.writeln('\'this next function will detect most plugins');
	document.writeln('Function detectActiveXControl(activeXControlName)');
	document.writeln('  on error resume next');
	document.writeln('  detectActiveXControl = False');
	document.writeln('  If g_detectableWithVB Then');
	document.writeln('     detectActiveXControl = IsObject(CreateObject(activeXControlName))');
	document.writeln('  End If');
	document.writeln('End Function');
	
	document.writeln('</scr' + 'ipt>');
}



function gotFlashSixOrBetter( bStrictMac )
{
	var outVersion = new Object();
	
	var bHasPlug = false;

	if ( !isActiveXBrowser() )
	{
		bHasPlug = detectPlugin( new Array("Flash", "Shockwave"), outVersion );
		var fv = outVersion[0] ? outVersion[0] : -1;
		//alert("fv=" + fv );
		g_flashVersion = new flashVersion( fv );
		bHasPlug = g_flashVersion.major >= 6;
	}
	else if ( g_detectableWithVB )
		bHasPlug =  detectActiveXControl( "ShockwaveFlash.ShockwaveFlash.6" );
	
	// note: we can't talk to activeX on Mac and have to assume no flash.
	// more detail:
	// On later machines, we could assume it is installed, and let browser handle install experience.  
	// But on OS9 machines, this can be problematic as the flash as bundled with browser doesn't always behave well.
	// To complicate matters, on IE 5.2.2 (which is who we're after here), the browser doesn't distinguish itself as OSX
	// So for most graceful failure, we need to assume there is no flash.  Forntunately, we are talking about
	// less than 1%
	//else if (isActiveXBrowser() && getBrowserOS() == kMac && isOSX())
		//bHasPlug = true;	
	else if (isActiveXBrowser() && getBrowserOS() == kMac )
		bHasPlug = (bStrictMac != true );	
	
	return bHasPlug;
}

function flashVersion( ver )
{
	ver = new String(ver);
	
	this.major = parseInt(ver);
	var ind = ver.indexOf( "." ) + 1;
	this.minor = ver.substring( ind, ind + 1 );
	ind = ver.indexOf( "r" ) + 1;
	this.release = ver.substring( ind, ver.length );
}

