/*
 * Copyright (c) 2003-2005, Pietra Arumaga, architexels.net, pixelblender@gmail.com
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice, this
 * list of conditions and the following disclaimer.
 *
 * Redistributions in binary form must reproduce the above copyright notice,
 * this list of conditions and the following disclaimer in the documentation
 * and/or other materials provided with the distribution.
 *
 * Neither the name of Pietra Arumaga, architexels.net nor the
 * names of its contributors may be used to endorse or promote products derived
 * from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

/*
 * detect_browser is a class to performs browsers detection based on
 * the capabilities and user agent string during HTTP_REQUEST.
 *
 * return void
 */
function detect_browser(){
	agent              = navigator.userAgent.toLowerCase();
	this.dom           = ( document.getElementById )? true : false; // DOM compliants Browser
	this.ie            = ( document.all )? true : false;
	this.ns            = ( document.layers )? true : false;
	this.major_version = parseInt( navigator.appVersion );
	this.full_version  = parseFloat( navigator.appVersion );
	
	// Windows 32 bit
	this.longhorn = ( agent.indexOf( 'windows nt 6.0' ) != -1 );
	this.win2k3   = ( agent.indexOf( 'windows nt 5.2' ) != -1 );
	this.winxp    = ( agent.indexOf( 'windows nt 5.1' ) != -1 );
	this.win2k    = ( agent.indexOf( 'windows nt 5.0' ) != -1 );
	this.winnt4   = ( agent.indexOf( 'windows nt 4' ) != -1 );
	this.winnt3   = ( agent.indexOf( 'windows nt 3' ) != -1 );
	this.winme    = ( agent.indexOf( 'windows me' ) != -1 || agent.indexOf( 'win me' ) != -1 || agent.indexOf( 'win 9x 4' ) != -1 );
	this.win98    = ( agent.indexOf( 'windows 98' ) != -1 || agent.indexOf( 'win 98' ) != -1 );
	this.win95    = ( agent.indexOf( 'windows 95' ) != -1 || agent.indexOf( 'win 95' ) != -1 );
	this.win32    = (
		this.longhorn ||
		this.win2k3 ||
		this.winxp ||
		this.win2k ||
		this.winnt4 ||
		this.winnt3 ||
		this.winme ||
		this.win98 ||
		this.win95
		);
	
	// macintosh
	this.mac    = ( agent.indexOf( 'macintosh' ) != -1 || agent.indexOf( 'mac' ) != -1 || agent.indexOf( 'apple' ) != -1 );
	this.mac68k = ( this.mac && agent.indexOf( '68k' ) != -1 || agent.indexOf( '68000' ) != -1 );
	this.macppc = ( this.mac && agent.indexOf( 'ppc' ) != -1 || agent.indexOf( 'powerpc' ) != -1 );
	
	// bsd
	this.bsd    = ( agent.indexOf( 'bsd' ) != -1 );
	
	// linux
	this.linux  = ( agent.indexOf( 'linux' ) != -1 || agent.indexOf( 'gnu' ) != -1 );
	
	// Opera
	this.opera  = ( agent.indexOf( 'opera' ) != -1 );
	this.opera4 = ( this.opera && agent.indexOf( 'opera 4' ) != -1 || agent.indexOf( 'opera/4' ) != -1 );
	this.opera5 = ( this.opera && agent.indexOf( 'opera 5' ) != -1 || agent.indexOf( 'opera/5' ) != -1 );
	this.opera6 = ( this.opera && agent.indexOf( 'opera 6' ) != -1 || agent.indexOf( 'opera/6' ) != -1 );
	this.opera7 = ( this.opera && agent.indexOf( 'opera 7' ) != -1 || agent.indexOf( 'opera/7' ) != -1 );
	this.opera8 = ( this.opera && agent.indexOf( 'opera 8' ) != -1 || agent.indexOf( 'opera/8' ) != -1 );
	
	var tempVer = 0;
	
	// detects opera's version
	if( this.opera ){ tempVer = getBrowserVersion( 'opera' ); }
	
	// Safari
	this.safari    = ( agent.indexOf( 'safari' ) != -1 && this.mac );
	this.safari1   = ( this.safari && agent.indexOf( 'safari/85' )  != -1 );
	this.safari1_2 = ( this.safari && agent.indexOf( 'safari/312' ) != -1 );
	this.safari1_3 = ( this.safari && agent.indexOf( 'safari/312' ) != -1 );
	this.safari2   = ( this.safari && agent.indexOf( 'safari/412' ) != -1 );
	
	// Konqueror
	this.konqueror  = ( agent.indexOf( 'konqueror' ) != -1 && !this.safari && agent.indexOf( 'gecko' ) == -1 );
	this.konqueror1 = ( this.konqueror && agent.indexOf( 'konqueror 1' ) != -1 || agent.indexOf( 'konqueror/1' ) != -1 );
	this.konqueror2 = ( this.konqueror && agent.indexOf( 'konqueror 2' ) != -1 || agent.indexOf( 'konqueror/2' ) != -1 );
	this.konqueror3 = ( this.konqueror && agent.indexOf( 'konqueror 3' ) != -1 || agent.indexOf( 'konqueror/3' ) != -1 );
	this.konqueror4 = ( this.konqueror && agent.indexOf( 'konqueror 4' ) != -1 || agent.indexOf( 'konqueror/4' ) != -1 );
	
	// detects konqueror's version
	if( this.konqueror ){ tempVer = getBrowserVersion( 'konqueror' ); }
	
	// Gecko Engine
	this.gecko      = ( agent.indexOf( 'mozilla' ) != -1 && agent.indexOf( 'gecko' ) != -1 && !this.konqueror );
	if( this.gecko ){		// extract gecko version number
		geck = agent.match( /gecko\s?\/?(\d+)/i );
		this.geckobuild = parseInt( geck[ 1 ] );
	}
	else this.geckobuild = false;
	
	this.geckowin = ( this.win32 && this.gecko );
	this.geckomac = ( this.mac && this.gecko );
	this.geckolin = ( this.lin && this.gecko );
	this.geckobsd = ( this.bsd && this.gecko );
	
	// gecko variants
	this.firefox  = (
		this.gecko &&
		agent.indexOf( 'firefox' ) != -1 ||
		agent.indexOf( 'firebird' ) != -1 ||
		agent.indexOf( 'phoenix' ) != -1
		);
	this.epiphany = ( this.gecko && agent.indexOf( 'epiphany' ) != -1 );
	this.mozilla  = ( this.gecko && !this.firefox && !this.epiphany && agent.indexOf( 'netscape' ) == -1 );
	
	// detects firefox's version
	if( this.firefox ){ tempVer = getBrowserVersion( 'firefox' ); }
	
	// detects epiphany's version
	if( this.epiphany ){ tempVer = getBrowserVersion( 'epiphany' ); }
	
	// Microsoft Internet Explorer
	this.msie    = ( agent.indexOf( 'msie' ) != -1 && this.ie && !this.opera && !this.gecko );
	this.msiew   = ( this.msie && this.win32 && !this.mac );
	this.msie4w  = ( this.msiew && agent.indexOf( 'msie 4' ) != -1 );
	this.msie55w = ( this.msiew && agent.indexOf( 'msie 5.5' ) != -1 );
	this.msie5w  = ( this.msiew && agent.indexOf( 'msie 5' ) != -1 && !this.msie55w );
	this.msie6w  = ( this.msiew && agent.indexOf( 'msie 6' ) != -1 );
	this.msie7w  = ( this.msiew && agent.indexOf( 'msie 7' ) != -1 );
	
	// MSIE on mac pre 5 doesn't support plugin detection properly, and have some problems with flash
	this.msiem   = ( this.msiem && this.mac && !this.win32 );
	this.msie45m = ( this.msiem && agent.indexOf( 'msie 4.5' ) != -1 );
	this.msie4m  = ( this.msiem && agent.indexOf( 'msie 4' ) != -1 && !this.msie45m );
	this.msie52m = ( this.msiem && agent.indexOf( 'msie 5.2' ) != -1 );
	this.msie5m  = ( this.msiem && agent.indexOf( 'msie 5' ) != -1 && !this.msie52m );
	
	// detects msie's version
	if( this.msie ){ tempVer = getBrowserVersion( 'msie' ); }
	
		/*
		major_version      = agent.match( /msie\s?\/?(\d+)/i );
		if( major_version && major_version.length > 1 ){
			tempVer = parseInt( major_version[ 1 ] );
			if( !isNaN( tempVer ) ){ this.major_version = tempVer; }
		}
		
		minor_version      = agent.match( /msie\s?\/?\d+\.(\d+\.?\d?\.?\d?)/i );
		if( minor_version && minor_version.length > 1 ){
			tempVer = parseFloat( minor_version[ 1 ] );
			if( !isNaN( tempVer ) ){ this.minor_version = tempVer; }
		}
		*/
	
	// Netscape
	this.mz         = (
		agent.indexOf( 'mozilla' ) != -1 &&
		agent.indexOf( 'spoofer' ) == -1 &&
		agent.indexOf( 'compatible' ) == -1 &&
		!this.opera &&
		!this.msie &&
		!this.konqueror &&
		!this.safari &&
		!this.firefox &&
		!this.epiphany &&
		!this.mozilla
		);
	this.netscape3  = ( this.mz && this.major_ver == 3 );
	this.netscape4b = ( this.mz && this.major_ver == 4 && this.full_version <= 4.03 );
	this.netscape4  = ( this.mz && this.major_ver == 4 && !this.netscape4b );
	this.netscape6  = ( this.mz && this.major_ver >= 5 && this.gecko && agent.indexOf( 'netscape/6' ) != -1 );
	this.netscape7  = ( this.mz && this.major_ver >= 5 && this.gecko && agent.indexOf( 'netscape/7' ) != -1 );
	this.netscape8  = ( this.mz && this.major_ver >= 5 && this.gecko && agent.indexOf( 'netscape/8' ) != -1 );
	
	if( parseFloat( tempVer ) != 0 ){
		this.major_version = parseInt( tempVer );
		this.full_version  = parseFloat( tempVer );
	}
	
	this.oie  = ( this.ie && !this.dom );	// old IE, non DOM
	this.ons  = ( this.ns && !this.dom );	// old Netscape, non DOM
	
	// browsers which fully support PNG
	this.supportpng  = (
		this.opera8 ||
		this.opera7 ||
		this.opera6 ||
		this.opera5 ||
		this.gecko ||
		this.konqueror3
		);
	
	// browsers which support DOM for CSS position: top, left, bottom, right
	this.sides = (
		this.msie ||
		this.gecko ||
		this.opera7 ||
		this.opera8 ||
		this.konqueror3
		);
	
	// flash detection
	this.flash            = false;
	this.flashversion     = 0;
	var gotFlash          = false;
	
	// shockwave
	this.shockwave        = false;
	this.shockwaveversion = 0;
	var gotShockwave      = false;
	
	// quicktime detection
	this.qt               = false;
	this.qtversion        = 0;
	var gotQT             = false;
	
	// java detection
	this.java             = navigator.javaEnabled();
	this.javaversion      = 0;
	var gotJava           = false;
	
	// acrobat detection
	this.pdf              = false;
	this.pdfversion       = 0;
	var gotPDF            = false;
	
	// realplayer detection
	this.real             = false;
	this.realversion      = 0;
	var gotReal           = false;
	
	// media player detection
	this.wmv              = false;
	this.wmvversion       = 0;
	var gotWMV            = false;
	
	if( navigator.plugins && navigator.plugins.length ){
		try{
			navigator.plugins.refresh( false );
		}
		catch( e ){}
		
		var plugArray  = navigator.plugins;
		var plugName   = "";
		var plugDesc   = "";
		var tempNumber = "";
		
		for( var i = 0; i < plugArray.length; i++ ){
			plugName = navigator.plugins[ i ].name.toLowerCase();
			plugDesc = navigator.plugins[ i ].description.toLowerCase();
			
			// flash detection
			if( plugName.indexOf( 'shockwave flash' ) != -1 && !gotFlash ){
				this.flash = true;
				gotFlash = true;
				this.flashversion = getVersionAsFloatFromStrings( plugDesc );
			}
			
			// shockwave detection
			if( plugName.indexOf( 'shockwave for director' ) != -1 && !gotShockwave ){
				this.shockwave = true;
				gotShockwave = true;
				this.shockwaveversion = getVersionAsFloatFromStrings( plugDesc );
			}
			
			// quicktime detection
			if( plugName.indexOf( 'quicktime' ) != -1 && !gotQT ){
				this.qt = true;
				gotQT = true;
				this.qtversion = getVersionAsFloatFromStrings( plugName );			
			}
			
			// java detection
			if( plugName.indexOf( 'java' ) != -1 && plugName.indexOf( 'platform' ) != -1 && !gotJava ){
				this.java = true;
				gotJava = true;
				this.javaversion = getVersionAsFloatFromStrings( plugDesc );
			}
			
			// acrobat detection
			if( plugName.indexOf( 'adobe acrobat' ) != -1 && !gotPDF ){
				this.pdf = true;
				gotPDF = true;
				this.pdfversion = getVersionAsFloatFromStrings( plugDesc );
			}
			
			// realplayer detection
			if( plugName.indexOf( 'realplayer version' ) != -1 && !gotReal ){
				this.real = true;
				gotReal = true;
				this.realversion = getVersionAsFloatFromStrings( plugDesc );
			}
			
			// media player detection
			if( plugName.indexOf( 'windows media player' ) != -1 && !gotWMV ){
				this.wmv = true;
				gotWMV = true;
				
				/*
				if( this.geckow ){
					try{
						mediaplayer   = new GeckoActiveXObject( "WMPlayer.OCX.7" );
						this.wmvversion = mediaplayer.versionInfo;
						
						if( mediaplayer ){
							// try to fecth 2 characters before the dot, see if it's a number
							tempNumber = playerversion.charAt( playerversion.indexOf( '.' ) - 2 );
							if( !isNaN( parseInt( tempNumber ) ) ){
								// it IS a number, then use this character as initial version number
								this.wmvversion  = tempNumber;
								this.wmvversion += playerversion.charAt( playerversion.indexOf( '.' ) - 1 );
							}
							else
								this.wmvversion = playerversion.charAt( playerversion.indexOf( '.' ) - 1 );
							
							this.wmvversion += '.' + playerversion.charAt( playerversion.indexOf( '.' ) + 1 );
							
							// now try to fecth 2 characters AFTER the dot, see if it's a number
							tempNumber = playerversion.charAt( playerversion.indexOf( '.' ) + 2 );
							if( !isNaN( parseInt( tempNumber ) ) ){
								// it IS a number, then use this character as additional versioning
								this.wmvversion += tempNumber;
							}
						}
					}
					catch( e ){
					}
				}

				// try to fecth 2 characters before the dot, see if it's a number
				tempNumber = plugDesc.charAt( plugDesc.indexOf( '.' ) - 2 );
				if( !isNaN( parseInt( tempNumber ) ) ){
					// it IS a number, then use this character as initial version number
					this.wmvversion  = tempNumber;
					this.wmvversion += plugDesc.charAt( plugDesc.indexOf( '.' ) - 1 );
				}
				else
					this.wmvversion = plugDesc.charAt( plugDesc.indexOf( '.' ) - 1 );
				
				this.wmvversion += '.' + plugDesc.charAt( plugDesc.indexOf( '.' ) + 1 );
				
				// now try to fecth 2 characters AFTER the dot, see if it's a number
				tempNumber = plugDesc.charAt( plugDesc.indexOf( '.' ) + 2 );
				if( !isNaN( parseInt( tempNumber ) ) ){
					// it IS a number, then use this character as additional versioning
					this.wmvversion += tempNumber;
				}
				
				if( isNaN( parseFloat( this.wmvversion ) ) ) this.wmvversion = 0;
				*/
			}
		}
	}
	else if( navigator.mimeTypes && navigator.mimeTypes.length ){
		var mimeArray  = navigator.mimeTypes;
		var plugName   = "";
		var plugDesc   = "";
		var tempNumber = "";
		var tempJava   = "";
		var plugMime;
		
		for( var i = 0; i < mimeArray.length; i++ ){
			plugMime = navigator.mimeTypes[ i ].type;
			plugName = navigator.mimeTypes[ i ].type.toLowerCase();
			plugDesc = navigator.mimeTypes[ i ].description.toLowerCase();
			
			// flash detection
			if( plugMime != null && plugName.indexOf( 'application/x-shockwave-flash' ) != -1 && navigator.mimeTypes[ i ].enabledPlugin && !gotFlash ){
				this.flash = true;
				gotFlash = true;
			}
			
			// shockwave detection
			if( plugMime != null && plugName.indexOf( 'application/x-director' ) != -1 && navigator.mimeTypes[ i ].enabledPlugin && !gotShockwave ){
				this.shockwave = true;
				gotShockwave = true;
			}
			
			// quicktime detection
			if( plugMime != null && plugName.indexOf( 'video/quicktime' ) != -1 && navigator.mimeTypes[ i ].enabledPlugin && !gotQT ){
				this.qt = true;
				gotQT = true;
			}
			
			// java detection
			if( plugMime != null && plugName.indexOf( 'application/x-java-applet' ) != -1 && navigator.mimeTypes[ i ].enabledPlugin && !gotJava ){
				this.java = true;
				gotJava = true;
				this.javaversion = getVersionAsFloatFromStrings( plugName );
			}
			
			if( plugMime != null && plugName.indexOf( 'application/x-java-applet' ) != -1 && navigator.mimeTypes[ i ].enabledPlugin && gotJava ){
				// check if this version number is newer than the last java version
				tempJava = getVersionAsFloatFromStrings( plugName );
				if( tempJava > this.javaversion ){
					this.javaversion = tempJava;
				}
			}
			
			// acrobat detection
			if( plugMime != null && plugName.indexOf( 'application/pdf' ) != -1 && navigator.mimeTypes[ i ].enabledPlugin && !gotPDF ){
				this.pdf = true;
				gotPDF = true;
			}
			
			// realplayer detection
			if( plugMime != null && plugName.indexOf( 'audio/x-pn-realaudio-plugin' ) != -1 && navigator.mimeTypes[ i ].enabledPlugin && !gotReal ){
				this.real = true;
				gotReal = true;
			}
			
			// windows media player detection
			if( plugMime != null && plugName.indexOf( 'application/x-mplayer2' ) != -1 && navigator.mimeTypes[ i ].enabledPlugin && !gotWMV ){
				this.wmv = true;
				gotWMV = true;
			}
		}
	}
	
	if( !gotJava && this.java && this.javaversion == 0 ){
		try{
			this.javaversion = parseFloat( java.lang.System.getProperty( "java.version" ) );
		}
		catch( e ){}
	}
	
	this.debug = debugBrowser;
	this.getMsiePlugins = getMsiePlugins;
}

function getMsiePlugins(){
	if( browser && window.ActiveXObject && !browser.msiem ){
		
		var gotFlash     = false;
		var gotShockwave = false;
		var gotQT        = false;
		var gotJava      = false;
		var gotPDF       = false;
		var gotReal      = false;
		var gotWMV       = false;
		
		// flash
		for( var i = 9; i > 0; i-- ){
			try{
				flashy = new ActiveXObject( "ShockwaveFlash.ShockwaveFlash." + i );
				if( flashy ){
					browser.flash = true;
					browser.flashversion = i;
					gotFlash = true;
					break;
				}
			}
			catch( e ){}
		}
		
		// shockwave director
		for( var i = 12; i > 0; i-- ){
			try{
				swd = new ActiveXObject( "SWCtl.SWCtl." + i );
				if( swd ){
					browser.shockwave = true;
					gotShockwave      = true;
					
					swdversion = swd.ShockwaveVersion("");
					browser.shockwaveversion = getVersionAsFloatFromStrings( swdversion );
					
					break;
				}
			}
			catch( e ){}
		}
		
		// quicktime
		try{
			quicktime = new ActiveXObject( "QuickTimeCheckObject.QuickTimeCheck.1" );
			if( quicktime ){
				browser.qt = true;
				browser.qtversion = parseInt( quicktime.QuickTimeVersion.toString( 16 ).substring( 0, 3 ) )/100;
				gotQT = true;
			}
		}
		catch( e ){}
		
		// acrobat
		try{
			pdf7 = new ActiveXObject('AcroPDF.PDF.1');
			if( pdf7 ){
				browser.pdfversion = 7;
				browser.pdf        = true;
				gotPDF             = true;
			}
		}
		catch( e ){}
		
		if( !gotPDF ){
			for( var i = 7; i > 0; i-- ){
				try{
					pdf = new ActiveXObject( "Pdf.PdfCtrl." + i );
					if( pdf ){
						browser.pdfversion = i;
						browser.pdf        = true;
						gotPDF             = true;
						break;
					}
				}
				catch( e ){}
			}
		}
		
		// media player
		try{
			mediaplayer = new ActiveXObject( "WMPlayer.OCX.7" );
			if( mediaplayer ){
				browser.wmv = true;
				gotWMV = true;
				
				mediaversion = mediaplayer.versionInfo;
				browser.wmvversion = getVersionAsFloatFromStrings( mediaversion );
			}
			else{
				mediaplayer = new ActiveXObject( "MediaPlayer.MediaPlayer.1" );
				if( mediaplayer ){
					browser.wmv        = true;
					gotWMV             = true;
					browser.wmvversion = 6.4;
				}
			}
		}
		catch( e ){}
	}
}

function browserDebugger( objArray, normalFont, allBlack ){
	if( objArray.length < 1 ){ return; }
	
	rowspan = ( (objArray.length - 1) / 2 ) + 2;
	
	tags  = '<table border="0" cellpadding="0" cellspacing="0" style="font-size:85%" align="center"';
	if( !normalFont ){ tags += ' class="grayedFont"'; }
	tags += '><tr><td colspan="5" align="center"><br><b>' + objArray[0] + '</b><br><br></td></tr>';
	tags += '<tr><td align="center"><b>items</b></td><td rowspan="' + rowspan + '"><img src="../layout/blank.gif"';
	tags += ' width="15" height="1"></td><td align="center"><b>variables</b></td><td rowspan="' + rowspan + '"><img';
	tags += ' src="../layout/blank.gif" width="15" height="1"></td><td align="center"><b>values</b></td></tr>';
	
	for( i = 1; i < objArray.length; i++ ){
		tags += '<tr';
		
		evalTrue = eval( objArray[ i + 1 ] );
		if( evalTrue === true && !allBlack ){
			tags += ' class="red"';
		}
		else if( !isNaN( evalTrue ) && parseFloat( evalTrue ) > 0 && objArray[0] === "PLUGINS LIST" ){
			tags += ' class="red"';
		}
		else if( normalFont && !allBlack ){
			tags += ' class="grayReg"';
		}
		
		tags += '><td>' + objArray[i] + '</td>';
		tags += '<td>' + objArray[ i + 1 ] + '</td>';
		if( objArray[0] !== "PLUGINS LIST" || evalTrue ){
			tags += '<td>' + eval( objArray[ i + 1 ] ) + '</td></tr>';
		}
		else if( !evalTrue ){
			tags += '<td>failed to detect</td></tr>';
		}
		
		i += 1;
	}
	
	tags += '</table><br>';
	
	document.write( tags );
}

function debugBrowser(){
	if( !browser ){ return; }
	
	if( browser.msie ){ browser.getMsiePlugins(); }
	
	document.write( '<style type="text/css">.grayedFont{color:#C9C9C9;}.red{color:#D11414;}.grayReg{color:#646464;}</style>' );
	
	var generalInfo = new Array( 'GENERAL INFORMATION', 'JavaScript User Agent', 'navigator.userAgent', 'Major Version', 'browser.major_version', 'Full Version', 'browser.full_version' );
	
	var openStandard = new Array( 'OPEN STANDARD COMPABILITY', 'DOM compliance (document.getElementById)', 'browser.dom', 'Support PNG 32', 'browser.supportpng', 'Support All Positioning', 'browser.sides' );
	
	var msiec = new Array( 'INTERNET EXPLORER COMPABILITY', 'Old Internet Explorer Compliance (document.all)', 'browser.ie', 'Browser is Internet Explorer 4 for Windows', 'browser.msie4w', 'Browser is Internet Explorer 5 for Windows', 'browser.msie5w', 'Browser is Internet Explorer 5.5 for Windows', 'browser.msie55w', 'Browser is Internet Explorer 6 for Windows', 'browser.msie6w', 'Browser is Internet Explorer 7 for Windows', 'browser.msie7w', 'Browser is Internet Explorer 4 for Mac', 'browser.msie4m', 'Browser is Internet Explorer 4.5 for Mac', 'browser.msie45m', 'Browser is Internet Explorer 5 for Mac', 'browser.msie5m', 'Browser is Internet Explorer 5.2 for Mac', 'browser.msie52m' );
	
	var nsc = new Array( 'NETSCAPE & ORIGINAL MOZILLA COMPABILITY', 'Netscape 4 Compliance (document.layers)', 'browser.ns', 'Browser is Netscape 3', 'browser.netscape3', 'Browser is Netscape 4 beta (below 4.03)', 'browser.netscape4b', 'Browser is Netscape 4', 'browser.netscape4', 'Browser is Netscape 6', 'browser.netscape6', 'Browser is Netscape 7', 'browser.netscape7', 'Browser is Netscape 8', 'browser.netscape8' );

	var safc = new Array( 'SAFARI COMPABILITY', 'Browser is Safari', 'browser.safari', 'Browser is Safari 1.0.x', 'browser.safari1', 'Browser is Safari 1.2.x', 'browser.safari1_2', 'Browser is Safari 1.3.x', 'browser.safari1_3', 'Browser is Safari 2.0.x', 'browser.safari2' );
	
	var mozc = new Array( 'MOZILLA FOUNDATION COMPABILITY (GECKO ENGINE)', 'Using Mozilla\'s Gecko Engine', 'browser.gecko', 'Browser is Mozilla', 'browser.mozilla', 'Browser is Firefox', 'browser.firefox', 'Browser is Epiphany', 'browser.epiphany' );
	
	var opc = new Array( 'OPERA COMPABILITY', 'Browser is Opera 4', 'browser.opera4', 'Browser is Opera 5', 'browser.opera5', 'Browser is Opera 6', 'browser.opera6', 'Browser is Opera 7', 'browser.opera7', 'Browser is Opera 8', 'browser.opera8' );
	
	var konc = new Array( 'KONQUEROR COMPABILITY', 'Browser is Konqueror 1', 'browser.konqueror1', 'Browser is Konqueror 2', 'browser.konqueror2', 'Browser is Konqueror 3', 'browser.konqueror3', 'Browser is Konqueror 4', 'browser.konqueror4' );
	
	var plugc = new Array( 'PLUGINS LIST', 'Macromedia Flash is enabled', 'browser.flash', 'Macromedia Flash version', 'browser.flashversion', 'Macromedia Shockwave Director is enabled', 'browser.shockwave', 'Macromedia Shockwave Director version', 'browser.shockwaveversion', 'Apple QuickTime is enabled', 'browser.qt', 'Apple QuickTime version', 'browser.qtversion', 'Java is enabled', 'browser.java', 'Java version', 'browser.javaversion', 'Adobe Acrobat Reader', 'browser.pdf', 'Adobe Acrobat Reader version', 'browser.pdfversion', 'Microsoft Windows Media Player', 'browser.wmv', 'Microsoft Windows Media Player version', 'browser.wmvversion', 'RealPlayer Plugin', 'browser.real', 'RealPlayer version', 'browser.realversion' );
	
	var w32c = new Array( 'MICROSOFT WINDOWS 32 BIT COMPABILITY', 'OS is Windows 32 bit', 'browser.win32', 'OS is Windows 95', 'browser.win95', 'OS is Windows 98', 'browser.win98', 'OS is Windows ME', 'browser.winme', 'OS is Windows NT 3.x', 'browser.winnt3', 'OS is Windows NT 4.x', 'browser.winnt4', 'OS is Windows 2000', 'browser.win2k', 'OS is Windows XP', 'browser.winxp' );
	
	var macc = new Array( 'APPLE MACINTOSH COMPABILITY', 'OS is Macintosh', 'browser.mac', 'OS is Macintosh using 68000 CPU', 'browser.mac68k', 'OS is Macintosh using PowerPC CPU', 'browser.macppc' );
	
	var othc = new Array( 'OTHER OS COMPABILITY', 'OS is BSD Unix', 'browser.bsd', 'OS is Linux', 'browser.linux' );
	
	browserDebugger( generalInfo, true, true );
	browserDebugger( openStandard, true, false );
	browserDebugger( msiec, browser.msie, false );
	browserDebugger( mozc, browser.gecko, false );
	browserDebugger( opc, browser.opera, false );
	browserDebugger( konc, browser.konqueror, false );
	browserDebugger( safc, browser.safari, false );
	browserDebugger( nsc, browser.mz, false );
	browserDebugger( plugc, true, false );
	browserDebugger( w32c, browser.win32, false );
	browserDebugger( macc, browser.mac, false );
	
	if( browser.bsd || browser.linux ){ browserDebugger( othc, true, false ); }
	else{ browserDebugger( othc, false, false ); }
}

function getVersionAsFloatFromStrings( stringVer ){
	var tempNumber;
	var tempVer;
	
	if( stringVer == null ){ return 0; }
	
	stringVer.toString();
	
	if( stringVer.indexOf( '.' ) == -1 && !isNaN( parseFloat( stringVer ) ) ){
		return parseFloat( stringVer );
	}
	else if( stringVer.indexOf( '.' ) == -1 && isNaN( parseFloat( stringVer ) ) ){
		return 0;
	}
	
	// try to fecth 2 characters before the dot, see if it's a number
	if( stringVer.indexOf( '.' ) > 1 ){
		tempNumber = stringVer.charAt( stringVer.indexOf( '.' ) - 2 );
		
		if( !isNaN( parseInt( tempNumber ) ) ){
			// it IS a number, then use this character as initial version number
			tempVer  = tempNumber;
			tempVer += stringVer.charAt( stringVer.indexOf( '.' ) - 1 );
		}
		else{
			tempVer = stringVer.charAt( stringVer.indexOf( '.' ) - 1 );
		}
	}
	else{
		tempVer = stringVer.charAt( stringVer.indexOf( '.' ) - 1 );
	}
	
	tempVer += '.' + stringVer.charAt( stringVer.indexOf( '.' ) + 1 );
	
	i = 1;
	while( ( stringVer.indexOf( '.' ) + i ) < stringVer.length ){
		i++;
		
		tempNumber = stringVer.charAt( stringVer.indexOf( '.' ) + i );
		// if( tempNumber === '' ) break;
		
		if( !isNaN( parseInt( tempNumber ) ) ){
			// it IS a number, then use this character as additional versioning
			tempVer += tempNumber;
		}
	}
	
	if( isNaN( parseFloat( tempVer ) ) ){
		tempVer = 0;
	}
	
	// document.write( 'orig: ' + tempVer + '<br>');
	// document.write( 'float: ' + parseFloat( tempVer ) + '<br>');
	
	return parseFloat( tempVer );
	
}

function getBrowserVersion( stringKey ){
	var agent = navigator.userAgent.toLowerCase();
	
	var versiontemp;
	versiontemp = agent.substr( agent.indexOf( stringKey ) + stringKey.length + 1, agent.length - agent.indexOf( stringKey ) );
	
	if( versiontemp == '' ){ return 0; }
	
	var i = 0;
	var version = '';
	var gotDot = false;
	
	while( i < versiontemp.length ){
		fetchChar = versiontemp.charAt( i );
		
		if( !isNaN( fetchChar ) ){
			version += fetchChar;
		}
		else if( fetchChar == '.' && !gotDot ){
			version += fetchChar;
			gotDot = true;
		}
		else if( fetchChar == ' ' ){
			break;
		}
		
		i++;
	}
	
	if( !isNaN( parseFloat( version ) ) ){ return version; }
	else{ return 0; }
}

var browser = new detect_browser();

// =========== begin: cross browser compability ===========
if( browser.dom ){
	doc = 'document.getElementById("';
	end = '")';
	css = '.style';
	htm = '';
}
if( browser.oie ){
	doc = 'document.all["';
	end = '"]';
	css = '.style';
	htm = '';
}
if( browser.ons ){
	doc = 'document["';
	end = '"]';
	css = '';
	htm = '.document';
}

function getObj( obj ){
	if( browser.dom ){
		return document.getElementById( obj );
	}
	else if( browser.ie ){
		return document.all[ obj ];
	}
	else{
		return false;
	}
}

function getObjCss( obj ){
	if( browser.dom ){
		return document.getElementById( obj ).style;
	}
	else if( browser.oie ){
		return document.all[ obj ].style;
	}
	else{
		return false;
	}
}

var vis = browser.ons? '"show"' : '"visible"';
var hid = browser.ons? '"hide"' : '"hidden"';

var blankImg = new Image();
blankImg.src = '../images/blank.gif';
// =========== endof: cross browser compability ===========