// by Johnson Cheung (come.to/luckystar)
// Last update : October 5, 2004
// checked on IE 5.0, 6.0, Mozilla 1.7, Netscape 4.78, 7.01, Opera 7.53, Avant Browser 9.02

// Mozilla 1.7 is Netscape 5.0
// Netscape 7.01 is Netscape 5.0
// Avant Browser 9.02 is IE 6.0

// just need to link this file to perform the following effect
// - Browser detection, following variable will be defined
//	Boolean bisIE : is IE
//	Boolean bisNS : is Netscape
//	Boolean bisOP : is Opera
//	Boolean bisUnknown : no idea what browser it is
//	float fVersion : the browser version

var sUserAgent = navigator.userAgent.toLowerCase();

var bisIE = false;
var bisNS = false;
var bisOP = false;
var bisUnknown = true;

var sBrowserName = "";
var fVersion = 0.0;

var sOS;

var thestring;

if (UserAgentHasThis('konqueror')) {
	sBrowserName = "Konqueror";
	sOS = "Linux";
} else if (UserAgentHasThis('safari')) sBrowserName = "Safari"
else if (UserAgentHasThis('omniweb')) sBrowserName = "OmniWeb"
else if (UserAgentHasThis('opera')) {
	sBrowserName = "Opera"
	bisOP = true; bisUnknown = false;
} else if (UserAgentHasThis('webtv')) sBrowserName = "WebTV";
else if (UserAgentHasThis('icab')) sBrowserName = "iCab"
else if (UserAgentHasThis('msie')) {
	sBrowserName = "Internet Explorer"
	bisIE = true; bisUnknown = false;
} else if (!UserAgentHasThis('compatible')) {
	sBrowserName = "Netscape Navigator"
	fVersion = parseFloat(sUserAgent.substring(8, sUserAgent.indexOf(" ")));
	bisNS = true; bisUnknown = false;
} else sBrowserName = "An unknown browser";

if (!fVersion) {
	iStartPos = place + thestring.length;
	iLastPos = sUserAgent.indexOf(" ", iStartPos);
	fVersion = parseFloat(sUserAgent.substring(iStartPos, iLastPos));
}

if (!sOS) {
	if (UserAgentHasThis('linux')) sOS = "Linux";
	else if (UserAgentHasThis('x11')) sOS = "Unix";
	else if (UserAgentHasThis('mac')) sOS = "Mac"
	else if (UserAgentHasThis('win')) sOS = "Windows"
	else sOS = "an unknown operating system";
}

function UserAgentHasThis(string) {
	place = sUserAgent.indexOf(string) + 1;
	thestring = string;
	return place;
}
