/*****************************************************************************
 *
 * File:                PlatformCheck.js
 *
 * Description:
 *  Javascript library containing methods to test client platform and 
 *  browser types and versions. Function calls can be made in VSS 
 *  templates, leaving the developer to provide feedback regarding 
 *  supportability of the web-based application on the client 
 *  configuration. 
 *
 *****************************************************************************/

/*****************************************************************************
 *  Function:           vi_getPlatformType
 *
 *  Description:
 *      Method to return name of client platform.
 *
 *  Arguments: None
 *
 *  Return value: 
 *      Windows, Macintosh or Unix, depending on platform type. Returns
 *      Unknown if the platform type is not recognized.
 *
 *  Side Effects: None
 *
 *****************************************************************************/
function vi_getPlatformType() 
{
    var platform = 'Unknown';
    if( navigator.userAgent )
    {
        var agent = navigator.userAgent.toLowerCase();
        if( agent.indexOf( 'win' ) != -1 ) 
        {
            platform = 'Windows';
        }
        else if( agent.indexOf( 'mac' ) != -1 ) 
        {
            platform = 'Macintosh';
        }
        else if( agent.indexOf( 'unix'    ) != -1 ||
                 agent.indexOf( 'solaris' ) != -1 ||
                 agent.indexOf( 'sun'   ) != -1 ||
                 agent.indexOf( 'irix'    ) != -1 ||
                 agent.indexOf( 'linux'   ) != -1 ||
                 agent.indexOf( 'bsd' ) != -1 ||
                 agent.indexOf( 'aix'     ) != -1 ||
                 agent.indexOf( 'hp'      ) != -1 ) 
        {
            platform = 'Unix';
        }
    }
    return platform;
}

/*****************************************************************************
 *  Function:           vi_getPlatformOS
 *
 *  Description:
 *      Method to return name of client operating system.
 *
 *  Arguments: None
 *
 *  Return value: 
 *      For the Windows platform:   NT/ME/XP/95/98/2000/Unknown
 *      For the Macintosh platform: Version Number or Unknown
 *      For the Unix platform:      Flavor of Unix or Unknown
 *
 *  Side Effects: None
 *
 *****************************************************************************/
function vi_getPlatformOS()
{
    var OS = 'Unknown';
    if( navigator.userAgent )
    {
        var agent = navigator.userAgent.toLowerCase();
        if( vi_getPlatformType() == 'Windows' ) 
        {
            if( agent.indexOf( 'winnt' ) != -1 )
            {
                OS = 'NT';
            }
            else if( agent.indexOf( 'win 9x 4.90' ) != -1 )
            {
                OS = 'ME';
            }
            else if( agent.indexOf( 'windows xp' ) != -1 ||
                     agent.indexOf( 'winxp'      ) != -1 )
            {
                OS = 'XP';
            }
            else if( agent.indexOf( 'windows 95' ) != -1 ||
                     agent.indexOf( 'win95'      ) != -1 )
            {
                OS = '95';
            }
            else if( agent.indexOf( 'windows 98' ) != -1 ||
                     agent.indexOf( 'win98'      ) != -1 )
            {
                OS = '98';
            }
            else if( agent.indexOf( 'windows nt' ) != -1 )
            {
                var start = agent.indexOf( 'windows nt' ) + 10;
                if( parseInt( agent.substring( start ) ) == 4 ) {
                    OS = 'NT';
                }
                else if( parseFloat( agent.substr( start+1, 3 ) ) == 5.0 ) {
                    OS = '2000';
                }
                else if( parseFloat( agent.substr( start+1, 3 ) ) == 5.1 ) {
                    OS = 'XP';
                }
				else {
                    // We knew that we are windows nt already.
					OS = 'NT';
				}
            }
            else 
            {
                OS = 'Unrecognized Windows';
            }
        }
        else if( vi_getPlatformType() == 'Macintosh' ) 
        {
            if( agent.indexOf( 'os x' ) != -1 )
            {
                OS = 'Mac OS X';
			}
			// for Mac 5.2 is only for OS X
			else if( agent.indexOf( 'msie' ) != -1 &&
					 agent.indexOf( '5.2' ) != -1)
            {
                OS = 'Mac OS X';
			}
			else
			{
                OS = 'Mac OS';
			}
        }
        else if( vi_getPlatformType() == 'Unix' ) 
        {
            if( agent.indexOf( 'solaris' ) ||
                agent.indexOf( 'sun'     ) != -1 )
            {
                OS = 'Sun Microsystems';
            }
            else if( agent.indexOf( 'irix' ) != -1 )
            {
                OS = 'Silicon Graphics IRIX';
            }
            else if( agent.indexOf( 'linux' ) != -1 )
            {
                OS = 'Linux';
            }
            if( agent.indexOf( 'bsd' ) != -1 ) 
            {
                OS = 'Free BSD';
            }
            else if( agent.indexOf( 'aix' ) != -1 ) 
            {
                OS = 'IBM AIX';
            }
            else if( agent.indexOf( 'hp' ) != -1 )
            {
                OS = 'Hewlett Packard Unix';
            }
            else
            {
                OS = 'Unrecognized Unix';
            }
        }
    }
    return OS;
}

/*****************************************************************************
 *  Function:           vi_getBrowserType
 *
 *  Description:
 *      Method to return name of client browser.
 *
 *  Arguments: None
 *
 *  Return value: 
 *      MSIE or Netscape, depending on client browser. Returns
 *      Unknown if the browser type is not recognized.
 *
 *  Side Effects: None
 *
 *****************************************************************************/
function vi_getBrowserType() 
{
    var browser = 'Unknown';
    if( navigator.appName )
    {
        var app = navigator.appName.toLowerCase();
        if( app.indexOf( 'netscape' ) != -1 ) 
        {
            browser = 'Netscape';
        } 
    } 
    if( navigator.userAgent )
    {
        var agent = navigator.userAgent.toLowerCase();
        if( agent.indexOf( 'msie' ) != -1 ) 
        {
            browser = 'MSIE';
        } 
    }
    return browser;
}

/*****************************************************************************
 *  Function:           vi_getBrowserVersion
 *
 *  Description:
 *      Method to return version number of client browser.
 *
 *  Arguments: None
 *
 *  Return value: 
 *      Version number of Netscape or IE depending on client browser. 
 *      Returns -1 if the browser type is unrecognized or the version
 *      number cannot be determined.
 *
 *  Side Effects: None
 *
 *****************************************************************************/
function vi_getBrowserVersion() 
{
    var version = -1;
    if( navigator.appName )
    {
        var app = navigator.appName.toLowerCase();
        if( app.indexOf( 'netscape' ) != -1 ) 
        {
			if( navigator.appVersion )
			{
				version = parseFloat( navigator.appVersion );

				if (version >= 5.0)
				{
					if (navigator.userAgent)
					{
						var agent = navigator.userAgent.toLowerCase();
						var len = agent.length;
						// Look for the last '/'
						var start = agent.lastIndexOf( '/');
						var verstr = agent.substr(start+1);
						if (parseInt(verstr) >= 6)
						{
							version = parseFloat(verstr);
						}
					}
				}
			}
        }
    }

    if( navigator.userAgent && navigator.appVersion )
    {
        var agent = navigator.userAgent.toLowerCase();
        if( agent.indexOf( 'msie' ) != -1 ) 
        {
            var start = agent.indexOf( 'msie' ) + 4;
            version = parseFloat( agent.substring( start ) );
        } 
    }
    return version;
}

/*****************************************************************************
 *  Function:           vi_checkWindowsPlayerPlugin
 *
 *  Description:
 *      Method to return flag indicating whether the WindowsMedia player
 *      plug-in is installed and available. This method is originally 
 *      based upon free Javascript available via www.javascriptkit.com
 *      and written by Frederic (fw4@tvd.be). This method invokes the 
 *      appropriate underlying method based upon the client browser.
 *
 *  Arguments: None
 *
 *  Return value:
 *      Returns 1 if the WindowsMedia plugin is installed and available.
 *      Returns 0 if the WindowsMedia plugin is not available.
 *      Returns -1 if the WindowsMedia plugin status could not be determined.
 *
 *  Side Effects: None
 *
 *****************************************************************************/
function vi_checkWindowsPlayerPlugin()
{
    var platform = vi_getPlatformType();
    var browser = vi_getBrowserType();
    if( platform == 'Windows' && browser == 'MSIE' ) {
        return vi_detectIEPlugin( 'MediaPlayer.MediaPlayer.1' );
    }
    else if( platform != 'Windows' || browser == 'Netscape' ) {
        return vi_detectNSPlugin( 'application/x-mplayer2',
                                  'Windows Media Player' );
    }
    else {
        return -1;
    }
}

/*****************************************************************************
 *  Function:           vi_checkRealPlayerPlugin
 *
 *  Description:
 *      Method to return flag indicating whether the RealMedia player
 *      plug-in is installed and available. This method is originally 
 *      based upon free Javascript available via www.javascriptkit.com
 *      and written by Frederic (fw4@tvd.be). This method invokes the 
 *      appropriate underlying method based upon the client browser.
 *
 *  Arguments: None
 *
 *  Return value:
 *      Returns 1 if the RealPlayer plugin is installed and available.
 *      Returns 0 if the RealPlayer plugin is not available.
 *      Returns -1 if the RealPlayer plugin status could not be determined.
 *
 *  Side Effects: None
 *
 *****************************************************************************/
function vi_checkRealPlayerPlugin()
{
    var platform = vi_getPlatformType();
    var browser = vi_getBrowserType();
    var realPluginAvailable = -1;
    if( platform == 'Windows' && browser == 'MSIE' ) {
        return vi_detectIEPlugin( 'rmocx.RealPlayer G2 Control.1' );
    }
    else if( platform != 'Windows' || browser == 'Netscape' ) {

        realPluginAvailable = vi_detectNSPlugin( 'audio/x-pn-realaudio-plugin','RealPlayer' );
        if (realPluginAvailable == -1)
        {
            // Test for the RealOne Player plugin.
            realPluginAvailable = vi_detectNSPlugin( 'application/vnd.rn-realplayer-javascript','RealOne Player' );
        }
        return realPluginAvailable;
    }
    else {
        return -1;
    }
}

/*****************************************************************************
 *  Function:           vi_checkSVGViewerPlugin
 *
 *  Description:
 *      Method to return flag indicating whether the SVG viewer 
 *      plug-in is installed and available. This method is originally 
 *      based upon free Javascript available via www.javascriptkit.com
 *      and written by Frederic (fw4@tvd.be). This method invokes the 
 *      appropriate underlying method based upon the client browser
 *      (Netscape or Internet Explorer, other browsers unsupported)
 *
 *  Arguments: None
 *
 *  Return value:
 *      Returns 1 if the SVG viewer plugin is installed and available.
 *      Returns 0 if the SVG viewer plugin is not available.
 *      Returns -1 if the SVG viewer plugin status could not be determined.
 *
 *  Side Effects: None
 *
 *****************************************************************************/
function vi_checkSVGViewerPlugin()
{
    var platform = vi_getPlatformType();
    var browser = vi_getBrowserType();
    if( platform == 'Windows' && browser == 'MSIE' ) {
        return vi_detectIEPlugin( 'Adobe.SVGCtl' );
    }
    else if( platform != 'Windows' || browser == 'Netscape' ) {
        return vi_detectNSPlugin( 'image/svg-xml', 'SVG Viewer' );
    }
    else {
        return -1;
    }
}

/*****************************************************************************
 *  Function:           vi_checkShockwaveDirectorPlugin
 *
 *  Description:
 *      Method to return flag indicating whether the Shockwave Director
 *      plug-in is installed and available. This method is originally 
 *      based upon free Javascript available via www.javascriptkit.com
 *      and written by Frederic (fw4@tvd.be). This method invokes the 
 *      appropriate underlying method based upon the client browser.
 *
 *  Arguments: None
 *
 *  Return value:
 *      Returns 1 if the Shockwave Director plugin is installed and available.
 *      Returns 0 if the Shockwave Director plugin is not available.
 *      Returns -1 if the Shockwave Director plugin status could not be
 *      determined.
 *
 *  Side Effects: None
 *
 *****************************************************************************/
function vi_checkShockwaveDirectorPlugin()
{
    var platform = vi_getPlatformType();
    var browser = vi_getBrowserType();
    if( platform == 'Windows' && browser == 'MSIE' ) {
        return vi_detectIEPlugin( 'SWCtl.SWCtl.1' );
    }
    else if( platform != 'Windows' || browser == 'Netscape' ) {
        return vi_detectNSPlugin( 'application/x-director', 
                                  'Shockwave Director' );
    }
    else {
        return -1;
    }
}

/*****************************************************************************
 *  Function:           vi_checkShockwaveFlashPlugin
 *
 *  Description:
 *      Method to return flag indicating whether the Shockwave Flash
 *      plug-in is installed and available. This method is originally 
 *      based upon free Javascript available via www.javascriptkit.com
 *      and written by Frederic (fw4@tvd.be). This method invokes the 
 *      appropriate underlying method based upon the client browser.
 *
 *  Arguments: None
 *
 *  Return value:
 *      Returns 1 if the Shockwave Flash plugin is installed and available.
 *      Returns 0 if the Shockwave Flash plugin is not available.
 *      Returns -1 if the Shockwave Flash plugin status could not be 
 *      determined.
 *
 *  Side Effects: None
 *
 *****************************************************************************/
function vi_checkShockwaveFlashPlugin()
{
    var platform = vi_getPlatformType();
    var browser = vi_getBrowserType();
    if( platform == 'Windows' && browser == 'MSIE' ) {
        return vi_detectIEPlugin( 'ShockwaveFlash.ShockwaveFlash.1' );
    }
    else if( platform != 'Windows' || browser == 'Netscape' ) {
        return vi_detectNSPlugin( 'application/x-shockwave-flash', 
                                  'Shockwave Flash' );
    }
    else {
        return -1;
    }
}

/*****************************************************************************
 *  Function:           vi_checkQuickTimePlugin
 *
 *  Description:
 *      Method to return flag indicating whether the QuickTime plug-in
 *      is installed and available. This method is originally based upon
 *      free Javascript available via www.javascriptkit.com and written by
 *      Frederic (fw4@tvd.be). This method invokes the appropriate underlying 
 *      method based upon the client browser.
 *
 *  Arguments: None
 *
 *  Return value:
 *      Returns 1 if the QuickTime plugin is installed and available.
 *      Returns 0 if the QuickTime plugin is not available.
 *      Returns -1 if the QuickTime plugin status could not be determined.
 *
 *  Side Effects: None
 *
 *****************************************************************************/
function vi_checkQuickTimePlugin()
{
    var platform = vi_getPlatformType();
    var browser = vi_getBrowserType();
    if( platform == 'Windows' && browser == 'MSIE' ) {
        return vi_detectIEPlugin( 'QuickTimeCheckObject.QuickTimeCheck.1' );
    }
    else if( platform != 'Windows' || browser == 'Netscape' ) {
        return vi_detectNSPlugin( 'video/quicktime', 'QuickTime' );
    }
    else {
        return -1;
    }
}

/*****************************************************************************
 *  Function:           vi_checkAcrobatReaderPlugin
 *
 *  Description:
 *      Method to return flag indicating whether the Adobe Acrobat Reader
 *      plug-in is installed and available. This method is originally 
 *      based upon free Javascript available via www.javascriptkit.com
 *      and written by Frederic (fw4@tvd.be). This method invokes the 
 *      appropriate underlying method based upon the client browser.
 *
 *  Arguments: None
 *
 *  Return value:
 *      Returns 1 if the Acrobat Reader plugin is installed and available.
 *      Returns 0 if the Acrobat Reader plugin is not available.
 *      Returns -1 if the Acrobat Reader plugin status could not be determined.
 *
 *  Side Effects: None
 *
 *****************************************************************************/
function vi_checkAcrobatReaderPlugin()
{
    var platform = vi_getPlatformType();
    var browser = vi_getBrowserType();
    if( platform == 'Windows' && browser == 'MSIE' ) {
        return vi_detectIEPlugin( 'PDF.PdfCtrl.5' );
    }
    else if( platform != 'Windows' || browser == 'Netscape' ) {
        return vi_detectNSPlugin( 'application/pdf', 'Acrobat Reader' );
    }
    else {
        return -1;
    }
}

/*****************************************************************************
 *  Function:           vi_checkJavaEnabled()
 *
 *  Description:
 *      Method to return flag indicating whether the browser is Java 
 *      enabled. This method is originally based upon free Javascript 
 *      available via www.javascriptkit.com and written by Frederic 
 *      (fw4@tvd.be). This method invokes the appropriate underlying 
 *      method based upon the client browser. 
 *
 *  Arguments: None
 *
 *  Return value:
 *      Returns 1 if the browser is Java-enabled 
 *      Returns 0 if the browser is not Java-enabled
 *
 *  Side Effects: None
 *
 *****************************************************************************/
function vi_checkJavaEnabled()
{
    return navigator.javaEnabled() ? 1 : 0;
}

/*****************************************************************************
 *  Function:           vi_detectIEPlugin()
 *
 *  Description:
 *      Internal method to return flag indicating whether the specified
 *      plugin is available. This method is only supported for the Internet
 *      Explorer browser on the Windows platform. This method is originally 
 *      based upon free Javascript available via www.javascriptkit.com and
 *      written by Frederic (fw4@tvd.be). 
 *
 *  Arguments:
 *      pluginName the name of the plugin for which to check availability
 *
 *  Return value:
 *      Returns 1 if the plug-in is installed and available
 *      Returns 0 if the plug-in is not installed and available
 *      Returns -1 if plug-in status could not be determined
 *
 *  Side Effects: None
 *
 *****************************************************************************/
function vi_detectIEPlugin( ClassID ) 
{ 
    res = 0; 
    var platform = vi_getPlatformType();
    var browser = vi_getBrowserType();
    if( platform != 'Windows' || browser != 'MSIE' ) 
    {
        res = -1;
    }
    else 
    {
        document.write( '<SCRIPT LANGUAGE=VBScript>\n' );
        document.write( 'on error resume next\n' );
        document.write( 'res = IsObject( CreateObject("' + ClassID + '"))\n' );
        document.write( '</SCRIPT>\n'); 
        if( res ) {
            res = 1;
        }
    }
    return res;
}

/*****************************************************************************
 *  Function:           vi_getNSPlugin()
 *
 *  Description:
 *      Internal method to return the full name of the specified 
 *      plugin. This method is only supported for the Netscape browser. This
 *      method is originally based upon free Javascript available via 
 *      www.javascriptkit.com and written by Frederic (fw4@tvd.be). 
 *
 *  Arguments:
 *      pluginName the name of the plugin for which to check availability
 *
 *  Return value:
 *      pluginName the name of the plugin for which to check availability
 *
 *  Side Effects: None
 *
 *****************************************************************************/
function vi_getNSPlugin(pluginName ) 
{
    var retVal = ""; 
    if( navigator.plugins )
    {
        for( var count = 0; count < navigator.plugins.length; count++ ) 
        {
            var curName = navigator.plugins[count].name.toLowerCase();
            if( curName.indexOf( pluginName.toLowerCase() ) != -1 ) 
            {
				retVal = navigator.plugins[count].name;
			}
        }
    }
    return retVal;
}

/*****************************************************************************
 *  Function:           vi_detectNSPlugin()
 *
 *  Description:
 *      Internal method to return flag indicating whether the specified 
 *      plugin is available and configured to support the specified MIME
 *      type. This method is only supported for the Netscape browser. This
 *      method is originally based upon free Javascript available via 
 *      www.javascriptkit.com and written by Frederic (fw4@tvd.be). 
 *
 *  Arguments:
 *      mimeType   the MIME type the plug-in is required to support 
 *      pluginName the name of the plugin for which to check availability
 *
 *  Return value:
 *      Returns 1 if the plug-in/MIME type combination is supported
 *      Returns 0 if the plug-in/MIME type combination is not supported
 *      Returns -1 if plug-in or MIME type status could not be determined.
 *
 *  Side Effects: None
 *
 *****************************************************************************/
function vi_detectNSPlugin( mimeType, pluginName ) 
{
    var retVal = -1; 
    if( navigator.plugins )
    {
        retVal = 0;
        for( var count = 0; count < navigator.plugins.length; count++ ) 
        {
            var curName = navigator.plugins[count].name.toLowerCase();
            if( curName.indexOf( pluginName.toLowerCase() ) != -1 ) 
            {
                // The plug-in has been found, so see if it supports the
                // specified MIME type.
                var mimeArr = navigator.plugins[count];
                if( mimeArr ) 
                {
                    for( var mcount = 0; mcount < mimeArr.length; mcount++ )
                    {
                        var curMime = mimeArr[mcount].type.toLowerCase();
                        if( curMime.indexOf( mimeType.toLowerCase() ) != -1 ) 
                        {
                            // The plugin supports the specified MIME type
                            retVal = 1;
                            break;
                        }
                    }
                }
                else 
                {
                    // Unable to determine which MIME types are supported
                    retVal = -1;
                }
                break;
            }
        }
    }
    return retVal;
}

/*****************************************************************************
 *  Function:           vi_getRealPlayerBuild
 *
 *  Description:
 *      Method to return the version of the Real Player (or RealOne Player)
 *      plug-in installed for the current browser, or -1 if the Real Player
 *      is not installed and available.
 *
 *  Arguments: None
 *
 *  Return value:
 *      Version number of RealPlayer installed. Returns -1 if the 
 *      RealPlayer plugin is not installed and available, or if its 
 *      status cannot be determined. Build numbers map to RealPlayer
 *      releases as follows (from http://service.real.com/help/library/
 *      guides/realonescripting/browse/realscript.htm):

 *      Release Version          Standalone Build    Embedded Player Build
 *      ---------------------    ----------------    ---------------------
 *      RealPlayer 8 Update 3    6.09.584            6.0.8.1024 
 *      RealPlayer 8 Update 2    6.0.9.450           6.0.7.881 
 *      RealPlayer 8 Gold        6.0.9.357           6.0.7.788 
 *      RealPlayer 7 Update 1    6.0.8.122           6.0.7.529 
 *      RealPlayer 7 Gold        6.0.7.380           6.0.7.407 
 *      RealPlayer G2 Update 3   6.0.6.99            6.0.6.98 
 *      RealPlayer G2 Update 2   6.0.6.33            6.0.6.33 
 *      RealPlayer G2 Update 1   6.0.5.27            6.0.5.27 
 *      RealPlayer G2 Gold       6.0.3.128           6.0.6.131 
 *
 *  Side Effects: None
 *
 *****************************************************************************/
function vi_getRealPlayerBuild()
{
    if (vi_checkRealPlayerPlugin() <= 0) 
	{
        return -1;
    }

    if (!( document.vid ))
    {
        var rp = '<object id="vid" width="1" height="1" ';
        rp += 'classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA">';
        rp += '<param name="src" value="">';
        rp += '<param name="type" value="audio/x-pn-realaudio-plugin">';
        rp += '<embed name="vid" type="audio/x-pn-realaudio-plugin" src="" ';
        rp += 'width="0" height="0" type="audio/x-pn-realaudio-plugin">';
        rp += '</embed></object>';
		if (top.players_test)
		{
			top.players_test.document.write( rp );
			top.players_test.document.close();
		}
		else
		{
			document.write( rp );
		}

    }
	
	if (top.players_test)
	{
        if (top.players_test.document.vid.GetVersionInfo() != null)
        {
	        return top.players_test.document.vid.GetVersionInfo();
        }
        else
        {
            return -1;
        }
	}
	else
	{
        if (document.vid.GetVersionInfo() != null)
        {
		    return document.vid.GetVersionInfo();
        }
        else
        {
            return -1;
        }
	}
}

/*****************************************************************************
 *  Function:           vi_getRealPlayerMajorRelease
 *
 *  Description:
 *      RealPlayer major release information. This method obtains the 
 *      RealPlayer build information and maps it to release information.
 *      as per the following map (from http://service.real.com/help/library/
 *      guides/realonescripting/browse/realscript.htm):

 *      Release Version          Standalone Build    Embedded Player Build
 *      ---------------------    ----------------    ---------------------
 *      RealPlayer 8 Update 3    6.09.584            6.0.8.1024 
 *      RealPlayer 8 Update 2    6.0.9.450           6.0.7.881 
 *      RealPlayer 8 Gold        6.0.9.357           6.0.7.788 
 *      RealPlayer 7 Update 1    6.0.8.122           6.0.7.529 
 *      RealPlayer 7 Gold        6.0.7.380           6.0.7.407 
 *      RealPlayer G2 Update 3   6.0.6.99            6.0.6.98 
 *      RealPlayer G2 Update 2   6.0.6.33            6.0.6.33 
 *      RealPlayer G2 Update 1   6.0.5.27            6.0.5.27 
 *      RealPlayer G2 Gold       6.0.3.128           6.0.6.131 
 *
 *      This method returns -1 if the RealPlayer plugin is not installed 
 *      and available, or if its status cannot be determined. 
 *
 *  Arguments: None
 *
 *  Return value:
 *      Based on examination of installed versions, the above mapping is 
 *      considered incomplete, despite being obtained from the Real site.
 *      The applied mapping is therefore devised as follows:
 *
 *      RealG2  for 6.0.5.X and 6.0.6.X builds 
 *      Real7   for 6.0.7.X builds < 6.0.7.788
 *      Real8   for 6.0.8.X, 6.0.9.X builds, and 6.0.7.X builds >= 6.0.7.788
 *      RealOne for 6.0.10.X builds
 *      Unknown for all other builds.
 *      -1      if the RealPlayer plugin is not installed and available, or 
 *              if its status cannot be determined.
 *
 *  Side Effects: None
 *
 *****************************************************************************/
function vi_getRealPlayerMajorRelease()
{
    var platform = vi_getPlatformType();
	if (platform == 'Windows')
	{
		var major = -1;
		var build = vi_getRealPlayerBuild();
		if( build != -1 )
		{
			major = 'Unknown';
			var buildStart = build.substring( 0, 3 );
			if( buildStart == '6.0' )
			{
				var buildEnd = build.substring( 4 );
				if( buildEnd.indexOf( '.' ) != -1 )
				{
					var buildSepInd = buildEnd.indexOf( '.' );
					var buildMajor = buildEnd.substring( 0, buildSepInd ); 
					var buildMinor = buildEnd.substring( buildSepInd + 1 ); 
					switch( Number( buildMajor ) )
					{
						case 5:
							major = 'RealG2';
							break;
						case 6:
							major = 'RealG2';
							break;
						case 7:
							var buildMinorNum = Number( buildMinor );
							major = ( buildMinorNum < 788 ) ? 'Real7' : 'Real8';
							break;
						case 8:
							major = 'Real8';
							break;
						case 9:
							major = 'Real8';
							break;
						case 10:
							major = 'RealOne';
							break;
						case 11:
							major = 'RealOne';
							break;
						case 12:
							major = 'RealOne';
							break;
						default:
							break;
					}
				}
			}
		}
	}
	else
	{
		var plugin = vi_getNSPlugin('RealOne');
		var pluginName = plugin.toLowerCase();

		if (pluginName.indexOf('realone') != -1)
		{
			major = 'RealOne';
		}
		else
		{
            // If we don't have realOne player, then try the real Player.
            plugin = vi_getNSPlugin('RealPlayer');
            pluginName = plugin.toLowerCase();

            if (pluginName.indexOf('g2') != -1)
            {
			    major = 'RealG2';
            }
		}
	}

    return major;
}

/*****************************************************************************
 *  Function:           vi_getWindowsPlayerVersion
 *
 *  Description:
 *      Method to return the version of the Windoes Media Player plug-in
 *      installed for the current browser, or -1 if the Windows Media Player
 *      is not installed and availablea. For IE browsers, this method uses
 *      the Client Capabilities object to obtain the version information.
 *      (Refer to http://www.allfreetech.com/ShowMain.asp?MainID=81 for
 *      additional details regarding the capability to obtain configuration
 *      information from IE browsers). For Netscape, we do not detect the
 *      exact version (e-mail sbeltz@virage.com if you know how to do this),
 *      but instead detect whether the version is 7.0 or higher based on 
 *      the list of available MIME types supported by the player. (Refer to 
 *      http://msdn.microsoft.com/library/default.asp?url=/library/en-us/
 *      dnwmt/html/clientdet.asp for additional details regarding this 
 *      technique.
 *
 *  Arguments: None
 *
 *  Return value:
 *      Version number of Windows Media Player installed. On IE, this 
 *      corresponds to the full version number string returned by the
 *      getComponentVersion method (e.g. 6,4,7,1112). On Netscape, this
 *      corresponds to either 5.2+ or 6.4+ based on MIME type detection. 
 *      (A return value of 5.2+ can be assumed to correspond to a version
 *      less than 6.4). Returns -1 if the Windows Media Player plugin is
 *      not installed and available, or if its status cannot be determined. 
 *
 *  Side Effects: None
 *
 *****************************************************************************/
function vi_getWindowsPlayerVersion( frame )
{
    if (vi_checkWindowsPlayerPlugin() <= 0) 
	{
        return -1;
    }

    var version = -1;
    if (vi_getBrowserType() == 'MSIE') 
    {
        document.write( '<span style="behavior:url(#default#clientCaps)" ' );
        document.write( 'id="objCCaps"></span>' );
        version = objCCaps.getComponentVersion(
            '{6BF52A52-394A-11d3-B153-00C04F79FAA6}', 'ComponentID' );


		// if we don't have a 7+ player check for the version of a pre 7 player
		if (version == "")
		{
			version = objCCaps.getComponentVersion(
				'{22D6F312-B0F6-11D0-94AB-0080C74C7E95}', 'ComponentID' );
		}

    }
    else
    {
        var wmp52 = navigator.mimeTypes && 
            navigator.mimeTypes["application/x-mplayer2"] &&  
            navigator.mimeTypes["application/x-mplayer2"].enabledPlugin;

        var wmp64 = navigator.mimeTypes && 
                    navigator.mimeTypes["video/x-ms-wm"] &&  
                    navigator.mimeTypes["video/x-ms-wm"].enabledPlugin && 
                    navigator.mimeTypes["video/x-ms-wmv"] && 
                    navigator.mimeTypes["video/x-ms-wmv"].enabledPlugin;

        //
        // The information is from the sample in http://www.nwlink.com/~zachd/pss/pss.html
        // Question: How can I detect what version of WMP a user has via HTML? 
        //
        // WMP7 is not truly detectable within Navigator at this time, but we can make 
        // a pretty good guess about whether it is installed because only WMP7 ships
        // the DRM v2 plug-in
        //
        var wmp70 = navigator.mimeTypes && 
                    navigator.mimeTypes["application/x-drm-v2"] &&  
                    navigator.mimeTypes["application/x-drm-v2"].enabledPlugin;
        
        if ( wmp70 ) {
            version = '7.0+';
        }             
        else if( wmp64 ) {
            version = '6.4';
        }
        else if( wmp52 ) {
            version = '5.2+';
        }
    }

	if (version == "") {
		version = -1;
	}

    return version;
}

