// adapted from Netscape's Ultimate client-side JavaScript client sniff. and andy's sniffer
// http://www.webreference.com/tools/browser/javascript.html
// edited bij lodewijk mullah@dds.nl
function Is () {
	var agt			=	navigator.userAgent.toLowerCase();
	this.major		=	parseInt(navigator.appVersion);
	this.minor		=	parseFloat(navigator.appVersion);
	
// browsercheck
	this.nav		=	((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1) && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1) && (agt.indexOf('webtv')==-1)) ? 1:0;
	this.nav2		=	(this.nav && (this.major == 2)) ? 1:0;
	this.nav3		=	(this.nav && (this.major == 3)) ? 1:0;
	this.nav3up		=	(this.nav && (this.major >= 3)) ? 1:0;
	this.nav4		=	(this.nav && (this.major == 4)) ? 1:0;
	this.nav4up		=	(this.nav && (this.major >= 4)) ? 1:0;
	this.navonly	=	(this.nav && ((agt.indexOf(";nav") != -1) || (agt.indexOf("; nav") != -1)) ) ? 1:0;
	this.nav5		=	(this.nav && (this.major == 5)) ? 1:0;
	this.nav5up		=	(this.nav && (this.major >= 5)) ? 1:0;
	this.nav6		=	(this.nav && (agt.indexOf('netscape6') != -1)) ? 1:0;
	this.nav6up		=	(this.nav && (this.major >= 6))? 1:0;
	
	this.ie			=	(agt.indexOf("msie") != -1) ? 1:0;
	this.ie3		=	(this.ie && (this.major < 4)) ? 1:0;
	this.ie4		=	(this.ie && (this.major == 4) && (agt.indexOf("msie 5.0")==-1) ) ? 1:0;
	this.ie4up		=	(this.ie	&& (this.major >= 4)) ? 1:0;
	this.ie5		=	(this.ie && (this.major == 4) && (agt.indexOf("msie 5.0")!=-1) ) ? 1:0;
	this.ie5up		=	(this.ie	&& !this.ie3 && !this.ie4) ? 1:0;
	
	this.aol		=	(agt.indexOf("aol") != -1) ? 1:0;
	this.aol3		=	(this.aol && this.ie3) ? 1:0;
	this.aol4		=	(this.aol && this.ie4) ? 1:0;
	
	this.icab		=	(agt.indexOf("icab") != -1) ? 1:0;
	this.opera		=	(agt.indexOf("opera") != -1) ? 1:0;
	this.webtv		=	(agt.indexOf("webtv") != -1) ? 1:0;
	
// javascript version check
	if (this.nav2 || this.ie3) this.js									=	1.0
	else if (this.nav3 || this.opera) this.js							=	1.1
	else if ((this.nav4 && (this.minor <= 4.05)) || this.ie4) this.js	=	1.2
	else if ((this.nav4 && (this.minor > 4.05)) || this.ie5) this.js	=	1.3
	else if (this.nav5) this.js											=	1.4
	else if (this.nav && (this.major > 5)) this.js						=	1.4
	else if (this.ie && (this.major > 5)) this.js						=	1.3
// this is actually impossible :)
	else this.js														=	0.0;

// platform check
	this.win			=	((agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1)) ? 1:0;
	this.win16			=	((agt.indexOf("win16")!=-1) || (agt.indexOf("16bit")!=-1) || (agt.indexOf("windows 3.1")!=-1) || (agt.indexOf("windows 16-bit")!=-1) ) ? 1:0;
	this.win32			=	(this.win95 || this.winnt || this.win98 || ((this.major >= 4) && (navigator.platform == "Win32")) || (agt.indexOf("win32")!=-1) || (agt.indexOf("32bit")!=-1) ) ? 1:0;
	this.win31			=	((agt.indexOf("windows 3.1")!=-1) || (agt.indexOf("win16")!=-1) || (agt.indexOf("windows 16-bit")!=-1)) ? 1:0;
	this.win95			=	((agt.indexOf("win95")!=-1) || (agt.indexOf("windows 95")!=-1)) ? 1:0;
	this.win98			=	((agt.indexOf("win98")!=-1) || (agt.indexOf("windows 98")!=-1)) ? 1:0;
	this.winnt			=	((agt.indexOf("winnt")!=-1) || (agt.indexOf("windows nt")!=-1)) ? 1:0;
	this.win2k			=	((agt.indexOf("winnt")!=-1) || (agt.indexOf("windows nt 5.0")!=-1)) ? 1:0;

	this.os2			=	((agt.indexOf("os/2")!=-1) || (navigator.appVersion.indexOf("OS/2")!=-1) || (agt.indexOf("ibm-webexplorer")!=-1)) ? 1:0;

	this.mac			=	(agt.indexOf("mac")!=-1) ? 1:0;
	this.mac68k			=	(this.mac && ((agt.indexOf("68k")!=-1) || (agt.indexOf("68000")!=-1))) ? 1:0;
	this.macppc			=	(this.mac && ((agt.indexOf("ppc")!=-1) || (agt.indexOf("powerpc")!=-1))) ? 1:0;

	this.sun			=	(agt.indexOf("sunos")!=-1) ? 1:0;
	this.sun4			=	(agt.indexOf("sunos 4")!=-1) ? 1:0;
	this.sun5			=	(agt.indexOf("sunos 5")!=-1) ? 1:0;
	this.suni86			=	(this.sun && (agt.indexOf("i86")!=-1)) ? 1:0;
	this.irix			=	(agt.indexOf("irix") !=-1) ? 1:0;
	this.irix5			=	(agt.indexOf("irix 5") !=-1) ? 1:0;
	this.irix6			=	((agt.indexOf("irix 6") !=-1) || (agt.indexOf("irix6") !=-1)) ? 1:0;
	this.hpux			=	(agt.indexOf("hp-ux")!=-1) ? 1:0;
	this.hpux9			=	(this.hpux && (agt.indexOf("09.")!=-1)) ? 1:0;
	this.hpux10			=	(this.hpux && (agt.indexOf("10.")!=-1)) ? 1:0;
	this.aix			=	(agt.indexOf("aix") !=-1) ? 1:0;
	this.aix1			=	(agt.indexOf("aix 1") !=-1) ? 1:0;
	this.aix2			=	(agt.indexOf("aix 2") !=-1) ? 1:0;
	this.aix3			=	(agt.indexOf("aix 3") !=-1) ? 1:0;
	this.aix4			=	(agt.indexOf("aix 4") !=-1) ? 1:0;
	this.linux			=	(agt.indexOf("inux")!=-1) ? 1:0;
	this.sco			=	(agt.indexOf("sco")!=-1) || (agt.indexOf("unix_sv")!=-1) ? 1:0;
	this.unixware		=	(agt.indexOf("unix_system_v")!=-1) ? 1:0;
	this.mpras			=	(agt.indexOf("ncr")!=-1) ? 1:0;
	this.reliant		=	(agt.indexOf("reliantunix")!=-1) ? 1:0;
	this.dec			=	((agt.indexOf("dec")!=-1) || (agt.indexOf("osf1")!=-1) || (agt.indexOf("dec_alpha")!=-1) || (agt.indexOf("alphaserver")!=-1) || (agt.indexOf("ultrix")!=-1) || (agt.indexOf("alphastation")!=-1)) ? 1:0;
	this.sinix			=	(agt.indexOf("sinix")!=-1) ? 1:0;
	this.freebsd		=	(agt.indexOf("freebsd")!=-1) ? 1:0;
	this.bsd			=	(agt.indexOf("bsd")!=-1) ? 1:0;
	this.unix			=	((agt.indexOf("x11")!=-1) || this.sun || this.irix || this.hpux || this.sco ||this.unixware || this.mpras || this.reliant || this.dec || this.sinix || this.aix || this.linux || this.bsd || this.freebsd) ? 1:0;
	
	this.vms			=	((agt.indexOf("vax")!=-1) || (agt.indexOf("openvms")!=-1)) ? 1:0;
// object en method detection
	this.images			=	(document.images) ? 1:0;
	this.anchors		=	(document.anchors) ? 1:0;
	this.layers			=	(document.layers) ? 1:0;

	this.elementid		=	(document.getElementById) ? 1 : 0;
	this.elementagname	=	(document.getElementsByTagName) ? 1 : 0;
	this.docel			=	(document.documentElement) ? 1 : 0;

	var layersexist		=	(document.layers) ? document.layers.length: 0;
	this.css			=	(layersexist || document.all) ? 1:0;
	this.all			=	(document.all) ? 1:0;

	this.regexp			=	(window.RegExp) ? 1:0;
	this.option			=	(window.Option) ? 1:0;

	this.referrer		=	document.referrer;
	this.url			=	document.URL;
	this.lastModified	=	document.lastModified;

	document.cookie		=	"cookies=true";
	this.cookie			=	(document.cookie) ? 1 : 0;

	this.forms			=	(document.forms) ? 1 : 0;
	this.links			=	(document.links) ? 1 : 0;
	this.frames			=	(window.frames) ? 1 : 0;
	this.screen			=	(window.screen) ? 1 : 0;
// java
	this.java			=	(navigator.javaEnabled());
}
var is = new Is ();

/*
Plugin Detector()
Source: Webmonkey Code Library (http://www.hotwired.com/webmonkey/javascript/code_library/)
Author: Nadav Savio Author Email: webmonkey@giantant.com
*/

// this is where we write out the VBScript for MSIE Windows
var WM_startTagFix = '</';
var msie_windows = 0;
if ((navigator.userAgent.indexOf('MSIE') != -1) && (navigator.userAgent.indexOf('Win') != -1)){
	msie_windows = 1;
	document.writeln('<script language="VBscript">');
	document.writeln('\'This will scan for plugins for all versions of Internet Explorer that have a VBscript engine version 2 or greater.');
	document.writeln('\'This includes all versions of IE4 and beyond and some versions of IE 3.');
	document.writeln('Dim WM_detect_through_vb');
	document.writeln('WM_detect_through_vb = 0');
	document.writeln('If ScriptEngineMajorVersion >= 2 then');
	document.writeln('	WM_detect_through_vb = 1');
	document.writeln('End If');
	document.writeln('Function WM_activeXDetect(activeXname)');
	document.writeln('	on error resume next');
	document.writeln('	If ScriptEngineMajorVersion >= 2 then');
	document.writeln('			WM_activeXDetect = False');
	document.writeln('			WM_activeXDetect = IsObject(CreateObject(activeXname))');
	document.writeln('			If (err) then');
	document.writeln('				WM_activeXDetect = False');
	document.writeln('			End If');
	document.writeln('		Else');
	document.writeln('			WM_activeXDetect = False');
	document.writeln('		End If');
	document.writeln('End Function');
	document.writeln(WM_startTagFix+'script>');
}

function WM_pluginDetect(plugindescription, pluginxtension, pluginmime, activeXname){
//This script block will test all user agents that have a real plug-in array
//(i.e. Netscape) and set the variables, otherwise it directs the routine
// to WM_activeXDetect to detect the activeX control.
// First define some variables
	var i,plugin_undetectable=0,detected=0, daPlugin=new Object();
// Then we check to see if it's an MSIE browser that you can actually
// check for the plugin in question. 
	if (msie_windows && WM_detect_through_vb){
		plugin_undetectable = 0;
	} else {
		plugin_undetectable = 1;
	}
// If it has a real plugins or mimetypes array, we look there for the plugin first
	if(navigator.plugins) {
		numPlugins = navigator.plugins.length;
		if (numPlugins > 1) {
		if (navigator.mimeTypes && navigator.mimeTypes[pluginmime] && navigator.mimeTypes[pluginmime].enabledPlugin && (navigator.mimeTypes[pluginmime].suffixes.indexOf(pluginxtension) != -1)) {
	// seems like we have it, let's just make sure and check the version (if specified)
			if ((navigator.appName == 'Netscape') && (navigator.appVersion.indexOf('4.0') != -1)) {
	// stupid, stupid Netscape can't handle the references to navigator.plugins by number, sooo...
			for(i in navigator.plugins) {
				if ((navigator.plugins[i].description.indexOf(plugindescription) != -1) || (i.indexOf(plugindescription) != -1)) {
	// some versions of quicktime have no description. feh!
				detected=1;
				break;
				}
			}
			} else {
			for (i = 0; i < numPlugins; i++) {
				daPlugin = navigator.plugins[i];
				if ((daPlugin.description.indexOf(plugindescription) != -1) || (daPlugin.name.indexOf(plugindescription) != -1)) {
				detected=1;
				break;
				}
			}
			}
	// Mac weirdness
		if (navigator.mimeTypes[pluginmime] == null) {
			detected = 0;
			}
		}
		return detected;
		} else if((msie_windows == 1) && !plugin_undetectable){
		return WM_activeXDetect(activeXname);
		} else { 		
		return 0;
		}
	} else {
		return 0;
	}
}

// this next function just makes it easy to detect the common plugins
	function WM_easyDetect(whichPlugin) {
	// this function just makes it easy to do basic plug-in detection without
	// knowing all the mimetypes and activeX names and such
	var isItThere = 0;
	if( (whichPlugin == 'flash') || (whichPlugin == 'Flash') ) {
		isItThere = WM_pluginDetect('Flash', 'swf', 'application/x-shockwave-flash', 'ShockwaveFlash.ShockwaveFlash');
	} else if( (whichPlugin == 'director') || (whichPlugin == 'Director') ) {
		isItThere = WM_pluginDetect('Shockwave', 'dcr', 'application/x-director', 'SWCtl.SWCtl.1');
	} else if( (whichPlugin == 'quicktime') || (whichPlugin == 'Quicktime') || (whichPlugin == 'QuickTime') ) {
		isItThere = WM_pluginDetect('QuickTime', 'mov', 'video/quicktime', '');
	} else if( (whichPlugin == 'realaudio') || (whichPlugin == 'Realaudio') || (whichPlugin == 'RealAudio') ) {
		isItThere = (WM_pluginDetect('RealPlayer', 'rpm', 'audio/x-pn-realaudio-plugin', 'RealPlayer.RealPlayer(tm) ActiveX Control (32-bit)')) || (WM_pluginDetect('RealPlayer', 'rpm', 'audio/x-pn-realaudio-plugin','rmocx.RealPlayer G2 Control')) || (WM_pluginDetect('RealPlayer', 'rpm', 'audio/x-pn-realaudio-plugin','RealPlayer.RealPlayer(tm) ActiveX Control (32-bit)')) || (WM_pluginDetect('RealPlayer', 'rpm', 'audio/x-pn-realaudio-plugin','RealVideo.RealVideo(tm) ActiveX Control (32-bit)'))
	} else {
		alert('You need to tell me which plug-in to look for, like so:\n\n' + '	WM_easyDetect(\'flash\')\n' + '	WM_easyDetect(\'director\')\n' + '	WM_easyDetect(\'quicktime\')\n' + '	WM_easyDetect(\'realaudio\')');
	}
	return isItThere;
}
