
// OS TYPES
var cWIN32 = 0;
var cMAC_OS9 = 1;
var cMAC_OSX = 2;
var cLINUX = 3;

// BROWSER TYPES
var cIE = 0;
var cFIREFOX = 1;
var cMOZILLA = 2;
var cNETSCAPE = 3;
var cSAFARI = 4;

	function getClientTimeZoneOffset()
	{
		return - (new Date()).getTimezoneOffset();
	}

// Browser identification CONSTANT OBJECT

	function BrowserIdentificationObj()
	{
		var b = navigator.appName;

		if (b=='Netscape')
			this.b = 'ns';
		else
		if (b=='Microsoft Internet Explorer')
			this.b = 'ie';
		else
			this.b = b;

		this.v    = parseInt(navigator.appVersion, 10);
		this.ns   = (this.b == "ns" && this.v >= 4);
		this.ns4  = (this.b == "ns" && this.v == 4);
		this.ns5  = (this.b == "ns" && this.v == 5);
		this.ie   = (this.b == "ie" && this.v >= 4);
		this.ie40 = (getIEVersionNumber() == 4.0);
		this.ie4  = (getIEVersionNumber() >= 4.0);
		this.ie5  = (getIEVersionNumber() >= 5.0);
		this.ie50 = (getIEVersionNumber() >= 5.0 && getIEVersionNumber() < 5.5);
		this.ie55 = (getIEVersionNumber() >= 5.5);
		this.mac = (navigator.userAgent.toLowerCase().indexOf('mac') != -1);
		this.win = (navigator.userAgent.toLowerCase().indexOf('windows') != -1);
		this.ie_mac = (this.ie5 && this.mac);
		this.ie_win = (this.ie && this.win);
		
		if (this.ie5)
			this.v = 5;

		this.browserOK = (this.ie5);

		this.toString = BrowserIdentificationObj_toString;
		this.pluginsToString = BrowserIdentificationObj_pluginsToString;
		this.detectPlugins = BrowserIdentificationObj_detectPlugins;

		var userAgent = navigator.userAgent;

		// VARIOUS CONVENIENT BOOLEANS.
		this.ie = userAgent.indexOf('MSIE') != -1;
		this.firefox = userAgent.indexOf('Firefox') != -1;
		this.netscape = userAgent.indexOf('Netscape') != -1;
		this.safari = userAgent.indexOf('Safari') != -1;
		this.mozilla = (userAgent.indexOf('Mozilla') != -1) && !this.ie && !this.firefox && !this.netscape && !this.safari;

		this.win = navigator.platform.indexOf('Win32') != -1;
		this.mac = navigator.platform.indexOf('MacPPC') != -1;
		this.linux = navigator.platform.indexOf('Linux') != -1;

		this.macOSX = this.mac && navigator.userAgent.indexOf('Mac OS X') != -1;
		this.macOS9 = this.mac && navigator.userAgent.indexOf('Mac OS') == -1;

		this.geckoBased = ((userAgent.indexOf('like Gecko') == -1) && (userAgent.indexOf('Gecko') != -1));

		// OS.
		this.os = null;
		if (this.win)
			this.os = cWIN32;
		else
		if (this.macOS9)
			this.os = cMAC_OS9;
		else
		if (this.macOSX)
			this.os = cMAC_OSX;
		else
		if (this.linux)
			this.os = cLINUX;


		// BROWSER TYPE.
		this.browserType = null;
		if (this.ie)
			this.browserType = cIE;
		else
		if (this.firefox)
			this.browserType = cFIREFOX;
		else
		if (this.mozilla)
			this.browserType = cMOZILLA;
		else
		if (this.netscape)
			this.browserType = cNETSCAPE;
		else
		if (this.safari)
			this.browserType = cSAFARI;

		this.pluginsDetected = false;
	}


	function BrowserIdentificationObj_pluginsToString()
	{
		var s = '';
		s+='is.flash ->' + is.flash + '\n';
		s+='is.shockwave ->' + is.shockwave + '\n';
		s+='is.realPlayer ->' + is.realPlayer + '\n';
		s+='is.quickTime ->' + is.quickTime + '\n';
		s+='is.acrobatReader ->' + is.acrobatReader + '\n';
		s+='is.windowsMediaPlayer ->' + is.windowsMediaPlayer + '\n';

		return s;
	}

	function BrowserIdentificationObj_toString()
	{
		var s = '';

		s+='appCodeName -> ' + navigator.appCodeName + '\n';
		s+='appMinorVersion -> ' + navigator.appMinorVersion + '\n';
		s+='appName -> ' + navigator.appName + '\n';
		s+='appVersion -> ' + navigator.appVersion + '\n';
		s+='cookieEnabled -> ' + navigator.cookieEnabled + '\n';
		s+='cpuClass -> ' + navigator.cpuClass + '\n';
		s+='mimeTypes -> ' + navigator.mimeTypes + '\n';
		s+='onLine -> ' + navigator.onLine + '\n';
		s+='opsProfile -> ' + navigator.opsProfile + '\n';
		s+='platform -> ' + navigator.platform + '\n';
		s+='plugins -> ' + navigator.plugins + '\n';
		s+='systemLanguage -> ' + navigator.systemLanguage + '\n';
		s+='userAgent -> ' + navigator.userAgent + '\n';
		s+='userLanguage -> ' + navigator.userLanguage + '\n';
		s+='userProfile -> ' + navigator.userProfile + '\n';

		s+=this.pluginsToString();

		return s;
	}


	function BrowserIdentificationObj_detectPlugins()
	{
		this.java = navigator.javaEnabled();


		if (this.ie && is.win) {

			pluginlist = detectIE("SWCtl.SWCtl.1","Shockwave Director") +
			detectIE("ShockwaveFlash.ShockwaveFlash.1","Shockwave Flash") +
			detectIE("rmocx.RealPlayer G2 Control.1","RealPlayer") +
			detectIE("RealPlayer.RealPlayer(tm) ActiveX Control (32-bit)","RealPlayer") +
			detectIE("RealVideo.RealVideo(tm) ActiveX Control (32-bit)","RealPlayer") +
			detectIE("QuickTimeCheckObject.QuickTimeCheck.1","QuickTime") +
			detectIE("MediaPlayer.MediaPlayer.1","Windows Media Player") +
			detectIE("WMPlayer.OCX","Windows Media Player") +
			detectIE("PDF.PdfCtrl.5","Acrobat Reader");
		}
		else {
			nse = "";

			for (var i = 0; i < navigator.mimeTypes.length; i++)
				nse += navigator.mimeTypes[i].type.toLowerCase();

			pluginlist = detectNS("image/svg-xml","SVG Viewer") +
			detectNS("application/x-director","Shockwave Director") +
			detectNS("application/x-shockwave-flash","Shockwave Flash") +
			detectNS("audio/x-pn-realaudio-plugin","RealPlayer") +
			detectNS("video/quicktime","QuickTime") +
			detectNS("application/x-mplayer2","Windows Media Player") +
			detectNS("application/pdf","Acrobat Reader");
		}

		if (pluginlist.length > 0)
			pluginlist = pluginlist.substring(0, pluginlist.length-1);

		this.flash = (pluginlist.indexOf("Flash") >= 0);
		this.shockwave = (pluginlist.indexOf("Shockwave Director") >= 0);
		this.realPlayer = (pluginlist.indexOf("RealPlayer") >= 0);
		this.quickTime = (pluginlist.indexOf("QuickTime") >= 0);
		this.acrobatReader = (pluginlist.indexOf("Acrobat Reader") >= 0);


		if (pluginlist.indexOf("Windows Media Player") >= 0) {

			this.windowsMediaPlayer = true;

				var windowsmedia = {};

				// Set some base values
				windowsmedia.installed = false;
				windowsmedia.version = '0.0'; // Internet Explorer-only

				// Check for GeckoActiveXObject and co-inciding Plug-In
				var gkoaxwma = false;
				if (navigator.plugins && navigator.plugins.length) {
					for (x = 0; x < navigator.plugins.length; x++) {
						if (navigator.plugins[x].name.indexOf('ActiveX') != -1 && window.GeckoActiveXObject) {
							gkoaxwma = true;
							break;
						}
					}
				}

				if (window.ActiveXObject || gkoaxwma) {
					try {
						oWMP = new AXO('WMPlayer.OCX.7', gkoaxwma);
						if (oWMP) {
							windowsmedia.installed = true;

							// A wierd bug in the Gecko ActiveX plug-in will return
							// undefined at the first call, but the correct value on the second.
							// This "fix" doesn't seem to hurt IE at all.
							parseFloat(oWMP.versionInfo);

							windowsmedia.version = parseFloat(oWMP.versionInfo);

							if (windowsmedia.version.toString().length == 1)
								windowsmedia.version+= '.0';
						}
					}
					catch(e) {
					}
				}
				else
				if (navigator.plugins && navigator.plugins.length) {
					for (x = 0; x < navigator.plugins.length; x++) {
						if (navigator.plugins[x].name.indexOf('Windows Media') != -1) {
							windowsmedia.installed = true;
							break;
						}
					}
				}

				// Internet Explorer or GeckoActiveXObject-compatible browsers only.
				windowsmedia.ver7 = (windowsmedia.installed && parseInt(windowsmedia.version, 10) >= 7);
				windowsmedia.ver8 = (windowsmedia.installed && parseInt(windowsmedia.version, 10) >= 8);
				windowsmedia.ver9 = (windowsmedia.installed && parseInt(windowsmedia.version, 10) >= 9);
		}
		else {
			this.windowsMediaPlayer = false;
		}

		this.installedMediaPlayers = [];

		if (this.windowsMediaPlayer !== false)
			this.installedMediaPlayers[this.installedMediaPlayers.length] = cWINDOWS_MEDIA_PLAYER;
		if (this.realPlayer)
			this.installedMediaPlayers[this.installedMediaPlayers.length] = cREAL_PLAYER;
		if (this.quickTime)
			this.installedMediaPlayers[this.installedMediaPlayers.length] = cQUICKTIME;

		this.pluginsDetected = true;

	}


	// UTILITY FUNCTIONS OF THE BrowserIdentificationObj OBJECT.

	function getIEVersionNumber()
	{
		var str = navigator.userAgent.substr(navigator.userAgent.indexOf('MSIE ') + 'MSIE '.length);
		str = str.substr(0, str.indexOf(';'));

		if (isNaN(str))
			return -1;
		else
			return parseFloat(str);
	}


	function detectIE(ClassID, name)
	{
		result = false;

		document.write('<SCR'+'IPT LANGUAGE=VBScript>\n on error resume next \n result = IsObject(CreateObject("');
		document.write(ClassID);
		document.write('"))</SCR'+'IPT>\n');

		if (result)
			return name + ',';
		else
			return '';
	}


	function detectNS(ClassID, name)
	{
		n = '';

		if (nse.indexOf(ClassID) != -1)
			if (navigator.mimeTypes[ClassID].enabledPlugin !== null)
				n = name + ',';

		return n;
	}



	// Create an ActiveX/GeckoActiveX constructor
	function AXO(id, gkoaxwma)
	{
		var control = null;
		
		try {
			if (window.ActiveXObject && navigator.userAgent.indexOf('Win') != -1)
				control = new ActiveXObject(id);
			else
			if (gkoaxwma)
				control = new GeckoActiveXObject(id);
		}
		catch (ex) {
		}

		return control;
	}


var disablePluginDetection = true;

var is = null;

// OTHERWISE, CREATE INSTANCE OF IS OBJECT.
is = new BrowserIdentificationObj();

if (!disablePluginDetection)
	is.detectPlugins();


