// Copyright © 2002 Microsoft Corporation.  All rights reserved.
function hasRuntimeDependencies()
{
	var bIsCompatible = true;

	// Check for compatible OS (Win98+ or NT4+)
	if (!IsCompatibleOS())
	{
		window.alert(ERR_UNSUPPORTED_OS_VERSION);
		bIsCompatible = false;
	}

	// Check for IE5.01+
	var sUA = navigator.userAgent.toLowerCase();
	var iPosMSIE = sUA.indexOf("msie ");
	var fIEVer = parseFloat( sUA.substring(iPosMSIE+5) );
	if ( !((iPosMSIE>-1) && (fIEVer>=5.01)) ) 
	{
		window.alert(ERR_UNSUPPORTED_BROWSER_VERSION);
		bIsCompatible = false;
	}

	// Check for min resolution of 800x600; Disabled per Functional Spec.
	if ( !((screen.width >= 800)&&(screen.height >= 600)) )
	{
		window.alert(ERR_UNSUPPORTED_SCREEN_RESOLUTION);
		bIsCompatible = false;
	}

	// Check for min color depth less than 16 bits per pixel (65536 colors); Disabled per Functional Spec.
	if (screen.colorDepth < 16)
	{
		window.alert(ERR_UNSUPPORTED_COLOR_DEPTH);
		bIsCompatible = false;
	}			
		
	// Check for MSXML parser 3.0 or greater
	if (getMSXMLParserVer() < 3.0)
	{
		window.alert(ERR_UNSUPPORTED_XMLPARSER);
		bIsCompatible = false;
	}

	// Check for Macromedia Flash version
	if (flashVersion() < 5)
	{
		window.alert(ERR_WRONG_FLASH_VERSION);
		bIsCompatible = false;
	}
	
	// Check for Shockwave version
	if (shockwaveVersion() < 8.5)
	{
		window.alert(ERR_WRONG_SHOCKWAVE_VERSION);
		bIsCompatible = false;
	}
			
	return bIsCompatible;
}

function IsCompatibleOS()
{
	var bIsCompatible = true;

	// convert to lowercase to simplify testing
    	var sUA = navigator.userAgent.toLowerCase();
	
	// Non-Microsoft OS?
	if (sUA.indexOf("win")==-1)
	{
		bIsCompatible = false;
		return bIsCompatible;
	}

    	// 16 bit Windows?
    	if (	(sUA.indexOf("win16")!=-1) 	 || (sUA.indexOf("16bit")!=-1) 		|| 
		(sUA.indexOf("windows 3.1")!=-1) || (sUA.indexOf("windows 16-bit")!=-1)  )
	{
		bIsCompatible = false;
		return bIsCompatible;
	}
 
    	// Win95?
    	if ((sUA.indexOf("win95")!=-1) || (sUA.indexOf("windows 95")!=-1))
	{
		bIsCompatible = false;
		return bIsCompatible;
	}

	// NT version less than 4?
	var ipos = sUA.indexOf("windows nt")
	if ((ipos != -1) && (sUA.length >= ipos+11))
	{
		var sVersion = sUA.substr(ipos+11,1);
		if (!isNaN(sVersion))
		{
			if (parseInt(sVersion) < 4)
				bIsCompatible = false;
		}
		//else
		//	NT version cannot be determined
	}
	else
	{
		ipos = sUA.indexOf("winnt")
		if ((ipos != -1) && (sUA.length >= ipos+6))
		{
			var sVersion = sUA.substr(ipos+6,1);
			if (!isNaN(sVersion))
			{
				if (parseInt(sVersion) < 4)
					bIsCompatible = false;
			}
		}
		//else
		//	NT version cannot be determined
	}

	return bIsCompatible;
}

function getMSXMLParserVer()
{
	var xml = "<?xml version=\"1.0\" encoding=\"UTF-16\"?><cjb></cjb>";
	var x = null;
	var fParserVer = 0;
	    
	try
	{ 
	    	x = new ActiveXObject("Msxml.DOMDocument"); 
	    	x.async = false;
	    	if (x.loadXML(xml))
	   		fParserVer = 1.0;
	}
	catch(e)
	{
	}

	try
	{ 
	    	x = new ActiveXObject("Msxml2.DOMDocument"); 
	    	x.async = false;
	    	if (x.loadXML(xml))
	   		fParserVer = 2.0;
	}
	catch(e)
	{
	}
	 
	try
	{ 
	    	x = new ActiveXObject("Msxml2.DOMDocument.2.6"); 
	    	x.async = false;
	    	if (x.loadXML(xml)) 
	    	  	fParserVer = 2.6;
	}
	catch(e)
	{
	}

	try{ 
	    	x = new ActiveXObject("Msxml2.DOMDocument.3.0"); 
	    	x.async = false;
	    	if (x.loadXML(xml)) 
	    	  	fParserVer = 3.0;
	}
	catch(e)
	{
	}

	try
	{ 
	    	x = new ActiveXObject("Msxml2.DOMDocument.4.0"); 
	    	x.async = false;
	    	if (x.loadXML(xml)) 
	    	  	fParserVer = 4.0;
	}
	catch(e)
	{
	}

	return fParserVer;
}


function shockwaveVersion()
{
	var MAX_SHOCKWAVE_VERSION = 15;		//  start with version 15 just in case
						//  the viewer has a long lifespan
	var oControl = null;
	var sClassName = "";
	var fVersion = 0.0;
	var sVersion = "0.0";

	// Step down through possible versions
  	for (var i = MAX_SHOCKWAVE_VERSION; i > 0; i--)
	{
		// Set up the classname for the version that we're trying to instantiate
    		sClassName = "SWCtl.SWCtl." + i.toString();

		try
		{
    			// create a control of the specified version
    			oControl = new ActiveXObject(sClassName);
		
			// get the version; returns a string of the form "8.5r352"
			sVersion = oControl.ShockwaveVersion("");

			// convert to a floating point value; ignores the revision number
			fVersion = parseFloat(sVersion);
			break;
		}
		catch(e)
		{
		}
	}

	oControl = null;

  	// The class name for Shockwave 6 actually has the version number 1
  	if (fVersion == 1.0) 
		fVersion = 6.0;

  	return fVersion;
}


function flashVersion()
{
	var MAX_FLASH_VERSION = 10;		//  start with version 10 just in case
						//  the viewer has a long lifespan
	var oControl = null;
	var sClassName = "";
	var iVersion = 0;
	
	// Step down through possible versions
  	for (var i = MAX_FLASH_VERSION; i >= 0; i--)
	{
		// Set up the classname for the version that we're trying to instantiate
		sClassName = "ShockwaveFlash.ShockwaveFlash";

		// The class name for Flash version 1 is "ShockwaveFlash.ShockwaveFlash"
		if (i > 0)
			sClassName += "." + i.toString();

		try
		{
    			// create a control of the specified version
    			oControl = new ActiveXObject(sClassName);
		
			iVersion = i;
			break;
		}
		catch(e)
		{
		}
	}

	oControl = null;
  	
  	return iVersion;
}