/* ######## Broser detection javascript #######################################*/
/*

[ checknetscape4 ]
This function checks user's browser is netscape4 or earlier.
Example:
	<script type="text/javascript">
	<!--
	if ( checknetscape4() == 1 ) {
		document.write('message in Japanese or English depends on the language of the site.');
	}
	// -->
	</script>

[ checknetscape6 ]
This function checks user's browser is netscape6 (NS6.X).
Example:
	<script type="text/javascript">
	<!--
	if ( checknetscape6() == 1 ) {
		document.write('message in Japanese or English depends on the language of the site.');
	}
	// -->
	</script>

############################################################################## */

function checknetscape4( ) {
	if ( document.layers ) {
		return(1); // only netscape 4 supports document layers
	}
	if ( document.userSystem.browserLongName == 'Netscape Navigator') {
		return(1);
	}

	return(0);
}

function checknetscape6( ) {
	if ( document.userSystem.browserLongName == "Netscape" && 
		document.userSystem.browserVersion >= "6" &&
		document.userSystem.browserVersion < "7" ) {
		return(1);
	}

	return(0);
}

/* ################## Free code from Plus Five,Inc. ########################## */
/*
  Original Script by Plus Five.
  Author : tak@
  URL    : http://plus-5.com
  Version: 1.0
	Update : 2004. 9.12
	Copyright(C) Plus Five, All rights Reserved.

  <overview>
  JavaScript have navigator.appName, navigator.appVersion etc.
  But they sometimes return incorrect value.
  To get correct values, you use navigator.userAgent
  By this script, you can extract OS name, Browser version with navigator.userAgent.
  Include this script into the head tag in your html.
  This script create document.userSystem object that holds their values.

  <Example>
  Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)
 
  document.userSystem
	document.userSystem.osLongName Windows 	XP  
  	document.userSystem.osShortName 	win  
	document.userSystem.browserLongName 	Internet Explorer  
	document.userSystem.browserShortName 	ie  
	document.userSystem.browserVersion 	6.0  

  <Detail about the return value>
  See the file under '40 KnowledgeWareHouse\..\navigator.userAgent...xls

-------------------------------------------------*/
document.userSystem = new PF_getUserSystem(navigator.userAgent);
/*
  BROWSER CHECK MAIN
-------------------------------------------------*/
function PF_getUserSystem() {

	var key, index, keyIndex, keyIndexEnd, versionKey, i, j;
	var uaString = PF_getUserSystem.arguments[0].toUpperCase();

	this.osLongName = "---";
	this.osShortName = "---";
	this.browserLongName = "---";
	this.browserShortName = "---";
	this.browserVersion = "---";

	var OSTYPE = new Object();
	OSTYPE['W95'] = new PF_setOS('Windows 95','win','WINDOWS 95,WIN95');
	OSTYPE['W98'] = new PF_setOS('Windows 98','win','WINDOWS 98,WIN98,Win 9x');
	OSTYPE['WCE'] = new PF_setOS('Windows CE','win','WINDOWS CE,WINCE');
	OSTYPE['WME'] = new PF_setOS('Windows Me','win','WINDOWS ME,WINME');
	OSTYPE['WNT'] = new PF_setOS('Windows NT','win','WINDOWS NT),WINDOWS NT 3,WINDOWS NT 4,WINDOWS NT;,WINNT');
	OSTYPE['W2K'] = new PF_setOS('Windows 2000','win','WINDOWS 2000,WINDOWS NT 5.0,WIN2000');
	OSTYPE['WXP'] = new PF_setOS('Windows XP','win','WINDOWS NT 5.1,WINDOWS NT 5.2,WINDOWS XP');
	OSTYPE['MAC'] = new PF_setOS('Macintosh','mac','MAC');
	OSTYPE['LNX'] = new PF_setOS('Linux','lnx','LINUX');
	OSTYPE['BSD'] = new PF_setOS('FreeBSD','bsd','FREEBSD');
	OSTYPE['X11'] = new PF_setOS('UNIX','x11','X11');
	OSTYPE['OSX'] = new PF_setOS('Mac OS X','osx','OS X');

	var BROWSERS = new Object();
	BROWSERS['MZ'] = new PF_setBrowser('Mozilla','mz','GECKO');
	BROWSERS['IE'] = new PF_setBrowser('Internet Explorer','ie','MSIE');
	BROWSERS['AO'] = new PF_setBrowser('AOL','ao','AOL');
	BROWSERS['SF'] = new PF_setBrowser('Safari','sf','SAFARI');
	BROWSERS['OP'] = new PF_setBrowser('Opera','op','OPERA');
	BROWSERS['OW'] = new PF_setBrowser('OmniWeb','ow','OMNIWEB');
	BROWSERS['IC'] = new PF_setBrowser('iCab','ic','ICAB');
	BROWSERS['NS'] = new PF_setBrowser('Netscape','ns','NETSCAPE,NETSCAPE6');
	BROWSERS['NN'] = new PF_setBrowser('Netscape Navigator','nn','MOZILLA');
	BROWSERS['FF'] = new PF_setBrowser('Firefox','ff','FIREFOX');
	
	var UNIXDETAIL = new Array("LNX","BSD");
	var checkVersionExp01 = new Array(' ', '/', '-', '');
	var checkVersionExp02 = new Array(';', ' ', '(', '[', ')', '+', '-', '/');

	uaString = " " + uaString + ";";
	
	index = 0;
	for (key in OSTYPE) {
		for (i=0; i<OSTYPE[key].keyword.length; i++) {
			keyIndex = uaString.indexOf(OSTYPE[key].keyword[i].toUpperCase());
			if (keyIndex > index) {
				this.osLongName = OSTYPE[key].longName;
				this.osShortName = OSTYPE[key].shortName;
				index = keyIndex;
			}
		}
	}

	// UNIX is reary?
	if (this.osShortName == "x11") {
		for (i=0; i<UNIXDETAIL.length; i++) {
			key = UNIXDETAIL[i];
			for (j=0; j<OSTYPE[key].keyword.length; j++) {
				if (uaString.indexOf(OSTYPE[key].keyword[j].toUpperCase()) > 0) {
					this.osLongName = OSTYPE[key].longName;
					this.osShortName = OSTYPE[key].shortName;
				}
			}
		}
	}

	// Mac OS is reary?
	if (this.osShortName == "mac") {
		var myPlugin = navigator.plugins;
		for (i=0; i<myPlugin.length; i++) {
			if(typeof(myPlugin[i].filename)!="undefined"){
				if (myPlugin[i].filename.indexOf(".plugin") != -1 || myPlugin[i].filename.indexOf(".app") != -1) {
					this.osLongName = OSTYPE["OSX"].longName;
					this.osShortName = OSTYPE["OSX"].shortName;
				}
			}
		}
		if (uaString.indexOf("MSIE 5.2") > 0) {
			this.osLongName = OSTYPE["OSX"].longName;
			this.osShortName = OSTYPE["OSX"].shortName;
		}
	}

	index = 0;
	for (key in BROWSERS) {
		for (i=0; i<BROWSERS[key].keyword.length; i++) {
			keyIndex = uaString.indexOf(BROWSERS[key].keyword[i].toUpperCase());
			if (keyIndex > index) {
				this.browserLongName = BROWSERS[key].longName;
				this.browserShortName = BROWSERS[key].shortName;
				versionKey = BROWSERS[key].keyword[i].toUpperCase();
				index = keyIndex;
			}
		}
	}

	// Navigator is reary?
	if (this.browserShortName == "nn" && uaString.indexOf("COMPATIBLE")>0) {
		this.browserLongName = "---";
		this.browserShortName = "---";
	}

	// Version Check
	if (this.browserLongName != "---") {
		for (i=0; i<checkVersionExp01.length; i++) {
			key = versionKey + checkVersionExp01[i];
			if ( ( keyIndex = uaString.indexOf(key) ) > 0 ) break;
		}
		// Mozilla
		if ( key == 'GECKO/' ) {
			key = 'RV:';
			keyIndex = uaString.indexOf(key);
		}
		keyIndex = keyIndex + key.length;
		index = uaString.length;
		for (i=0; i<checkVersionExp02.length; i++) {
			if ((key = uaString.indexOf(checkVersionExp02[i], keyIndex)) > 0) {
				if (key < index) {
					keyIndexEnd = key;
					index = keyIndexEnd;
				}
			}
		}
		this.browserVersion = uaString.substring(keyIndex, keyIndexEnd);
	}

}
/*
  Setting OS Object
-------------------------------------------------*/
function PF_setOS(longName,shortName,keyWord) {
	this.longName = longName;
	this.shortName = shortName;
	this.keyword = keyWord.split(",");
}
/*
  Setting BROWSER Object
-------------------------------------------------*/
function PF_setBrowser(longName,shortName,keyWord) {
	this.longName = longName;
	this.shortName = shortName;
	this.keyword = keyWord.split(",");
}
