/* Real Player detection on a Web page.
* Version 1.0
* March 09, 2004
* Paul Davis <pdavis@real.com>, Real Networks Inc.
* This example illustrates how to detect an installed copy of Real Player to ensure proper playback of Real Media files embedded in a web page.
* If the user has IE5+, the code will attempt to instantiate the Real Player active X control and query it. If the user doesn't have IE5+, the code will 1st attempt to look for Real Player in the plug-ins array and then the mime-Type array.
* The code won't detect the presence Real Player if Netscape Browser 6+ is installed after installing Real Player. This is a known issue in Netscape browser.
* The code will return a "true" value if Real Player version G2 or above is installed, but it may not be able to detect the correct Real Player version number in all cases.
* The recommended next step, when the detection fails to find Real Player, is to redirect the user to a landing page, and allow the user to choose to either download Real Player or to play the embedded contents anyway. In the example, http://guide.real.com is used as the landing page.
* The URL to download the latest release of RealPlayer is http://www.real.com/player.
* Finally, the Real Player detection logic should be intended to enhance web user experience, and not to be used as a mean to restrict access to contents.
*/

/*
* The version variable will be set when we are able
* to detect the version. Note, we do not do comprehensive
* version detection, because of the time overhead in
* instantiating a plugin. This invloves creating an instance of
* the plugin (on non Windows IE5+ platforms), setting up a
* background thread to check when it is ready and querying
* the plugin for its version.
*/

var version = 0;

function isObject(type){
return ( "undefined" != typeof(type) );
}


function winIE5upPlyrDetect(){
var player;
var iectl;

// attempt to instantiate the IE control to see if activeX is enabled.
iectl = new ActiveXObject("Shell.Explorer");


player = new ActiveXObject("rmocx.RealPlayer G2 Control.1");
version = (player.GetVersionInfo());

if(!isObject(iectl)){
return "unknown"; //ActiveX disabled
}
return new String(isObject(player));

}

function checkPlugin(name){
plugin = navigator.plugins[name];
if(isObject(plugin)){
version = plugin.description;
return true;
}
return false;
}

function pluginDetect(){
return (
(checkPlugin("RealPlayer Version Plugin"))
||
(checkPlugin("RealOne Player Version Plugin"))
);
}

function mimeTypeDetect(){
return (
isObject(navigator.mimeTypes)
&&
isObject(navigator.mimeTypes["audio/x-pn-realaudio-plugin"])
);
}

function isWinIE5plus(){
var result = false;
var uaLower = navigator.userAgent.toLowerCase();
if(uaLower.indexOf("windows") >=0 && uaLower.indexOf("msie")>=0){
var versRX = /msie\s+[5-9]/;
result = versRX.test(uaLower);
}
return result;
}

/*
* Returns a string, "true", "false", "unknown" based on the results
* of player detection.
* "false" will only be returned if the user has IE5+, activeX is
* enabled, and we can not instantiate the player control.
* That is the only case where we are sure the user does not have
* the player installed. All other cases where the player can not
* be detected will return "unknown".
*/
function hasRealPlayer(){
if( isWinIE5plus() ){
return winIE5upPlyrDetect();
}else{
return ((pluginDetect() || mimeTypeDetect()
)?"true":"unknown");
}
}

function RealPlayer_detection(){
switch( hasRealPlayer()+"" ){
case "true":
/* Successful player detection
*/
/*document.write("Real Player successfully detected.");*/
if( version != 0 ){ return version;
}
else{ return 1; }
break;
case "unknown":
/* Unable to determine if the user has a player
* If using for media ensure resulting page offers link to the media. */
/*document.location.href = "http://guide.real.com";*/
return 0;
break;
case "false":
/* Player is definitely not installed
*/
/*document.location.href = "http://guide.real.com";*/
return -1;
break;
}
}