

//------------------------------------------------
// bt = NS, IE 					:Browser Type
// bst = NS, IE, SF, OP, FF		:Browser Sub Type
// biec = true / false			:Browser IE Compatible
// bp = Mac, Sun, Win			:Browser Platform
//------------------------------------------------

//printResults();
//declare _g6Browser
var _g6Browser = new Object();

var _g6FormatRedirect = "";

//set default values
_g6Browser.bt='IE';
_g6Browser.bst='IE';
_g6Browser.bp='WIN';
_g6Browser.biec=true;
_g6Browser.wmpdetect=G6_DetectWMP();
_g6Browser.fmt="WMP";
_g6Browser.xpi=null;


//------------------------------------------------------------------------------------------------------------------------
// FUNCTION to parse user agent, detect browser capabilities and reload page with qs params containing browser caps
//------------------------------------------------------------------------------------------------------------------------
function G6_DetectBrowser(format, redirect){

	redirect = ((redirect) ? (redirect) : false); //if null set to false
	//alert(redirect);
	
	if(typeof(format)=="undefined" || typeof(format)=="null")
		_g6Browser.fmt="WMP";
	else
		_g6Browser.fmt=format;
		

	//declarations
	var platform	= navigator.platform.toUpperCase(); //changed to upper case for better compatibility :RJJ
	var agent		= navigator.userAgent;
	var appName		= navigator.appName;

	//determine browser platform (bp) and set iecompatible (biec)
	if(platform.indexOf('MAC')>-1)									{_g6Browser.bp	= 'MAC';}
	else if(platform.indexOf('LINUX')>-1)						{_g6Browser.bp	= 'LINUX';}
	else if(platform.indexOf('X11')>-1)							{_g6Browser.bp	= 'UNIX';}
	else if(platform.indexOf('SUN')>-1)							{_g6Browser.bp	= 'SUN';}
	else if(platform.indexOf(_g6Browser.bp.toUpperCase())<0)	{_g6Browser.bp	= 'NA';} // default - NA: Not Available

	//determine appname and set browser type and iecompatible (biec)
	if(appName.indexOf('Netscape')>-1){_g6Browser.bt='NS';}

	//--------------------------------------------------------------------------
	//determine browser subtype (bst) and version (bv)
	//--------------------------------------------------------------------------
	if(agent.indexOf('Netscape')>-1){		// netscape
		_g6Browser.bst='NS';
	}
	else if (agent.indexOf('Safari')>-1){	// safari
		_g6Browser.bst='SF';
	}
	else if(agent.indexOf('Opera')>-1){		// opera
		_g6Browser.bst='OP';
	}
	else if(agent.indexOf('Firefox')>-1){	// firefox
		_g6Browser.bst='FF';
	}
		
	_g6Browser.biec = G6_CheckBrowserIECompat(agent);
	
	
	
	//if browser subtype is NS - determine whether ie compatible version
	//if(_g6Browser.bst=='NS' && navigator.userAgent.indexOf('Netscape/7.2')>-1){_g6Browser.biec=true;}
	
	//if(redirect) G6_FormatRedirect();
	
	
	
	//         COMMENTED OUT FOR DETECTION VIA _g6SettingsPolicy OBJECT - RRY
	/*          
	//if not ie - reload page with browser information
	if(_g6Browser.bt!='IE'){
	
		_g6Browser.biec = G6_CheckBrowserIECompat(agent);
		
		var loc='';
		if(window.location.href.indexOf('bt='+_g6Browser.bt)==-1){
		    //make one last check to see if still browser ie compatible
        		
		    if(window.location.href.indexOf('?') ==-1)
		    {loc+='?';} else {loc+='&';}
    		
		    //now redirect
		    window.location = window.location+loc+'bt='+_g6Browser.bt+'&bp='+_g6Browser.bp+'&bst='+_g6Browser.bst+'&biec='+_g6Browser.biec + G6_FormatRedirect(redirect); //put this last part in sitemanager
		}
	}          
	*/
	//          END OMMISION - RRY
}


//Alter the site's default format/media type based on roo redirect rules
function G6_FormatRedirect(redirect) {;
	if(redirect) {
		_g6FormatRedirect = "&format="; // set default now that we know we're going to return something
	
		switch (_g6Browser.bp) {
			case "WIN": //platform

				switch(_g6Browser.bst) { //browser subtype
					case "IE": //this will never exec, but here for clarity
						_g6FormatRedirect += "wmp";
						break;
					default: //all other browser subtypes
						_g6FormatRedirect += "flash";
						break;
				}
				break;

			case "MAC": //platform
						_g6FormatRedirect += "flash";
				break;

			case "LINUX": //platform
						_g6FormatRedirect += "flash";
				break;

			case "UNIX": //platform
						_g6FormatRedirect += "flash";
				break;

			case "SUN": //platform
						_g6FormatRedirect += "flash";
				break;

			default: //platform other
						_g6FormatRedirect += "flash";
				break;

		}
	}
	return _g6FormatRedirect;
}

//----------------------------------------------------------------------------
// Function to determine whether browser is ie compatible with windows media
//----------------------------------------------------------------------------
function G6_CheckBrowserIECompat(agent){

    //always return false if mac
    if(_g6Browser.bp!='WIN')
    {
	    return false;
    }

    if(_g6Browser.wmpdetect.installed==true && _g6Browser.wmpdetect.scriptable==true && _g6Browser.wmpdetect.useable==true)
    {
	    return true;
    }
    else  //only if wmp then get the plugin
    {
	    if(_g6Browser.fmt=="WMP")
	    {
		    G6_GetPlugin(agent);
	    }
	    return false;
    }
	
    /*
    //set array of ie compatible strings
    var ar = new Array(4);
    ar[0]="Firefox/1.0.7";
    ar[1]="Firefox/1.0.6";
    ar[2]="Netscape/7.1";
    ar[3]="Netscape/7.2";

	    for (anItem in ar){
		    if(agent.indexOf(ar[anItem])>-1)
			    return true;
	    }
	    return false;
    */
}

//----------------------------------------------------------------------------
//  Check for the Mozilla Plugin and prompt if exists
//----------------------------------------------------------------------------
function G6_GetPlugin(agent){

	//right now, we are only doing this for firefox
	if(agent.indexOf("Firefox/1.")==-1)
		return;
		
	_g6Browser.xpi=new Object();
	
	if(agent.indexOf("Firefox/1.5")>-1)
		_g6Browser.xpi["Mozilla ActiveX Plugin"] = "http://www.iol.ie/~locka/mozilla/mozactivex-ff-15.xpi";
	else if(agent.indexOf("Firefox/1.0.7")>-1)
		_g6Browser.xpi["Mozilla ActiveX Plugin"] = "http://www.iol.ie/~locka/mozilla/mozactivex-ff-107.xpi";
	else if(agent.indexOf("Firefox/1.0.6")>-1)
		_g6Browser.xpi["Mozilla ActiveX Plugin"] = "http://www.iol.ie/~locka/mozilla/mozactivex-ff-106.xpi";
	else if(agent.indexOf("Firefox/1.0.5")>-1 || agent.indexOf("Firefox/1.0.4") > -1)
		_g6Browser.xpi["Mozilla ActiveX Plugin"] = "http://www.iol.ie/~locka/mozilla/mozactivex-ff-104.xpi";
	else if(agent.indexOf("Firefox/1.0.3")>-1)
		_g6Browser.xpi["Mozilla ActiveX Plugin"] = "http://www.iol.ie/~locka/mozilla/mozactivex-ff-103-2.xpi";
	else if(agent.indexOf("Firefox/1.0")>-1)
		_g6Browser.xpi["Mozilla ActiveX Plugin"] = "http://www.iol.ie/~locka/mozilla/mozactivex-ff-10.xpi";

	if(_g6Browser.xpi!=null)
	{
		//if(confirm("In order to view this site you need the Windows Media Player ActiveX plugin.  Ok to install?")){
		//	InstallTrigger.install(xpi,G6_PluginInstalled);
		document.write("<div id=\"divInstallPlugin\" style=\"position:absolute; top: 2px; left: 2px; width: 100%; height:40px; background-color:beige; color:black; font-size: 12px; z-index:19999\">");
		document.write("&nbsp;In order to view this site properly, you need the Mozilla ActiveX Plugin. <a href=\"\" onClick=\"G6_InstallAX();return false;\">Click here</a> to install. If you have recently installed the plugin, please be sure to restart your browser to ensure proper installation.</div>");	
	}
}

function G6_InstallAX(){
	InstallTrigger.install(_g6Browser.xpi,G6_AXInstalled);
}

function G6_AXInstalled(name, result){
	//document.location.href=document.location.href;
	if(result)
	{ 
	    alert("An error occured while attempting to install the plugin:" +result); 
	}
	else 
	{  
		try{
			document.getElementById("divInstallPlugin").innerHTML="Plugin installed successfully. Please restart your browser.";
		}
		catch (e)
		{
			//do nothing
		}
	}
}

function G6_ConfirmMime(){
        //make sure useable ie., activex properly installed
		if(navigator.mimeTypes && window.GeckoActiveXObject){
			if(typeof(navigator.mimeTypes['application/x-oleobject'])=='undefined'){
				return false;
			}
		}
		return true;
}
function G6_DetectWMP()
{
	var wmpInfo = {
		installed: false,
		scriptable: false,
		useable: false,
		type: null,
		versionInfo: null
	};
	var wmp64 = "MediaPlayer.MediaPlayer.1";
	var wmp7 = "WMPlayer.OCX.7";
	if((window.ActiveXObject && navigator.userAgent.indexOf('Windows') != -1) || window.GeckoActiveXObject)
	{
		wmpInfo.type = "ActiveX";
		var player = G6_CreateActiveXObject(wmp7);
		if(player)
		{
			wmpInfo.installed = true;
			wmpInfo.scriptable = true;
			
			wmpInfo.versionInfo = player.versionInfo;
			wmpInfo.useable=G6_ConfirmMime();
			return wmpInfo;
		}
		else
		{
			player = G6_CreateActiveXObject(wmp64);
			if(player)
			{
				wmpInfo.installed = true;
				wmpInfo.scriptable = true;
				wmpInfo.versionInfo = "6.4";
				wmpInfo.useable=G6_ConfirmMime();
				return wmpInfo;
			}
			else
			{
				wmpInfo.versionInfo = "none";
				return wmpInfo;
			}
		}
		
		
	}
	else if(navigator.mimeTypes)
	{
		wmpInfo.type = "NetscapePlugin";
		var player = navigator.mimeTypes['application/x-mplayer2'].enabledPlugin;
		if(player)
		{	
			
			wmpInfo.installed = true;
			//wmpInfo.scriptable = false;
			wmpInfo.versionInfo = "PluginVersion";
			return wmpInfo;
		}
		return wmpInfo;
	}
	
	
}
function G6_CreateActiveXObject(id)
{
  var error;
  var control = null;

  try
  {
    if (window.ActiveXObject)
    {
      control = new ActiveXObject(id);
    }
    else if (window.GeckoActiveXObject)
    {
      control = new GeckoActiveXObject(id);
    }
  }
  catch (error)
  {
    ;
  }
  return control;
}
	

function printResults()
{
	var detectionResults = G6_DetectWMP();
	document.write("Browser architecture supports: " + detectionResults.type + "\n");
	document.write("Windows Media Player Installed: " + detectionResults.installed + "\n");
	if(detectionResults.installed)
	{
		document.write("Windows Media Scriptable: " + detectionResults.scriptable + "\n");
		document.write("Windows Media Version: " + detectionResults.versionInfo + "\n");
	}
	
}





