// by Johnson Cheung (http://www.wahon.net/~johnson/)
// Last update : April 26, 2007
// checked on
//	IE		: 5.0, 6.0
//	Mozilla	: 1.7
//	Netscape	: 4.78, 7.01
//	Opera	: 7.53, 9.20
//	Avant	: 9.02
//	Firefox	: 2.0.0.1

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

// Browser detection, following variable will be defined
//	String sBrowserName : Browser Name
//	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
//	String sOS : OS Name

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;
}