
//////////////////////////////////////////////////////////////////////////////
//	Script ID:			browser_detect.js									//
//	Main Function(s):	browserDetect()										//
//	Author:				Clifford Trout <-He rules!							//
//	Date:				03.13.2001											//
//																			//
//	Description:															//
//		This script detects the users browser type, the version of the 		//
//		browser, the version class, and the operating system. The results 	//
//		are returned in a "hash" for use as needed.							//
//																			//
//			Hash keys:														//
//				broswer	-	the name of the browser (Internet Explorer)		//
//				version	-	the version of the browser being used (5.01)	//
//				OS		-	the operating system (Windows or Mac)			//
//				class	-	the browser generation class (4 or 5)			//
//																			//
//	Revision History:														//
//		ctrout		|	03.13.2001 | Creation								//
//		eshaheen	|	05.19.2003 | Added checks for NS7 and IE6 and		//
//									 corrected browser detect for IE4		//
//									 and IE5								//
//////////////////////////////////////////////////////////////////////////////

function browserDetect() {
	var browser = "";
	var version = "";
	var verClass = "";
	var userAgent = navigator.userAgent;
	var pntr = userAgent.indexOf("MSIE ")
	var retValue = new Array();
	
	var NS4 = (document.layers) ? 1 : 0;
	var NS6 = (userAgent.indexOf("Netscape6") != -1) ? 1 : 0;
	var NS7 = (userAgent.indexOf("Netscape7") != -1) ? 1 : 0;
	var IE4 = (userAgent.indexOf("MSIE 4.") != -1) ? 1 : 0;
	var IE5 = (userAgent.indexOf("MSIE 5.") != -1) ? 1 : 0;
	var IE6 = (userAgent.indexOf("MSIE 6.") != -1) ? 1 : 0;
	var OS = (userAgent.indexOf("Win") != -1) ? "Windows" : (userAgent.indexOf("Mac") != -1) ? "Mac" : "Unknown";

	if (NS4) {
		browser = "Netscape";
		version = userAgent.substring((userAgent.indexOf("/") + 1), userAgent.indexOf(" "));
		verClass = "4";
	} else if (NS6) {
		browser = "Netscape";
		version = userAgent.substring((userAgent.lastIndexOf("/") + 1), userAgent.length);
		verClass = "5";
	} else if (NS7) {
		browser = "Netscape";
		version = userAgent.substring((userAgent.lastIndexOf("/") + 1), userAgent.length);
		verClass = "6";
	} else if (IE4) {
		browser = "Internet Explorer";
		version = userAgent.substring((pntr + 5), userAgent.indexOf(";",pntr));
		verClass = "4";
	} else if (IE5) {
		browser = "Internet Explorer";
		version = userAgent.substring((pntr + 5), userAgent.indexOf(";",pntr));
		verClass = "5";
	} else if (IE6) {
		browser = "Internet Explorer";
		version = userAgent.substring((pntr + 5), userAgent.indexOf(";",pntr));
		verClass = "6";
	} else {
		browser = "";
		version = userAgent;
		verClass = "";
	}

	retValue["browser"] = browser;
	retValue["version"] = version;
	retValue["OS"] = OS;
	retValue["class"] = verClass;
	
	return(retValue);
}

