/*  ##########################################################################
'	##########################################################################

' 	browserManager.js

'	Author(s)
' 	Ian Causton, IC, ian.causton@akqa.com

' 	Copyright 2004 AKQA.  All rights reserved.

'	Version 1.00
'	Created: 27/05/2004
'	Last modified: 27/05/2004

'	Versions:
' 	1.00 - Initial version - IC

	##########################################################################
	##########################################################################
*/

var flash2Installed = false;
var flash3Installed = false;
var flash4Installed = false;
var flash5Installed = false;
var flash6Installed = false;
var flash7Installed = false;

var isIE 	= (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin 	= (navigator.appVersion.indexOf("Windows") != -1) ? true : false;

if(isIE && isWin){
  document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n');
  document.write('on error resume next \n');
  document.write('flash2Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.2"))) \n');
  document.write('flash3Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.3"))) \n');
  document.write('flash4Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.4"))) \n');
  document.write('flash5Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.5"))) \n');  
  document.write('flash6Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6"))) \n');  
  document.write('flash7Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.7"))) \n'); 
  document.write('</SCR' + 'IPT\> \n');
}

// Constructor
function BrowserManager()
{
 
 	// create public functions
	this.detectFlash = function (iRequiredVers,iCurrentMaxFlashAvailable) {
 	
		var bValidFlash = false;
		var iActualVers = 0;
	 
	  	if (navigator.plugins) {
	    	if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]) {
			
	     	var isVersion2 		= navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
	      	var flashDescription 	= navigator.plugins["Shockwave Flash" + isVersion2].description;
		  	var flashVersion 		= parseInt(flashDescription.charAt(flashDescription.indexOf(".") - 1));
	
	      	flash2Installed = flashVersion == 2;    
	      	flash3Installed = flashVersion == 3;
	      	flash4Installed = flashVersion == 4;
	      	flash5Installed = flashVersion == 5;
	      	flash6Installed = flashVersion == 6;
			flash7Installed = flashVersion >= 7;
	    	}
	  	}
	  	for (var i = 2; i <= iCurrentMaxFlashAvailable; i++) {  
	    	if (eval("flash" + i + "Installed") == true) iActualVers = i;
	  	}
	  
	  	if(navigator.userAgent.indexOf("WebTV") != -1) iActualVers = 3;
	  
	  	if (iActualVers < iRequiredVers) {
			bValidFlash = false;        
	  	} else {
			bValidFlash = true;
	  	}
	  	
		return bValidFlash;
	}

	this.detectBrowser = function (iRequiredBrowserVers)
	{
		var bVaildBrowser	= true;
	
		if(this.getInfo().majVer < iRequiredBrowserVers || (this.getInfo().OS == "MAC" && this.getInfo().browser == "IE" && this.getInfo().majVer < iRequiredBrowserVers))
		{	
			bVaildBrowser	= false;
		}
	
		return bVaildBrowser;	
	}
	
	this.getInfo = function () {
		function Info () {this.browser="";this.majVer=0;this.minVersion=0;this.OS="";}
		var info 	= new Info();
		appVer		= navigator.appVersion;
		appName		= navigator.appName;
		plat		= navigator.platform;
		
		if (plat=="MacPPC") info.OS="MAC";
		else if (plat=="Win32") info.OS="WIN";
		else info.OS=plat.toUpperCase();
		if (appName.indexOf("Internet Explorer")!=-1) info.browser="IE";
		else if (appName=="Netscape") info.browser="NS";
		else info.browser="Other=" + appName;
		if (info.browser=="IE") {
			start=appVer.indexOf("MSIE") + 5; 
			end=appVer.indexOf(";",start);
			num=appVer.substring(start,end);
		} else {
			end=appVer.indexOf(" ");
			num=appVer.substring(0,end);
		}
		info.majVer=parseInt(num.split(".")[0]);
		info.minVer=parseInt(num.split(".")[1]);
		if (info.minVer<10) info.minVer=info.minVer*10;
		return info;
	}
	
	this.detectPopUpBlocker = function ()
	{
		// this does not work at present
		
		var bPopUpsBlocked	= true;
		var tP	= 0; 
		var eF	= 0;
		var popWin 	= null;
		var popWin2	= null;
		
		
		function failed() {eF=1}
		
		// attempt to open a pop up
		popWin = window.open("","ptest","width=1,height=1,left=5000,top=5000",true);
		popWin2 = window.open("","ptest","width=1,height=1");
		
		if(popWin == null && popWin2 == null)
		{
			alert("pop ups not allowed");
		}
		
		window.onerror	= failed;
		
		if(popWin != null)
		{
			popWin.blur(); 
			popWin.close();
			bPopUpsBlocked	= false;
		}
				
		return bPopUpsBlocked;
	}
}

// private functions

