// browserDetection.js
// Determine which browser the user is using.
// (c) 2004 Morcor Solutions Inc.
//
// ########################################################################################
//
// WARNING!  This script and associated scripts are (c) 2004 by Morcor Solutions Inc.
// You may not redistribute this script.  You may create copies of this script for
// backup and in-house testing purposes only.
//
// DO NOT MODIFY THIS FILE.  Please contact Morcor Solutions Inc. at 613-354-2912 or
// at support@morcor.com if you find a problem within this file.  DO NOT MODIFY THIS FILE.
//
// Morcor Solutions Inc. will not support ANY changes to this script.
//
// ########################################################################################

if (typeof(Browser) != "undefined") {
	alert("Unexpected predeclaration of 'Browser' object!");
}

// versionAtLeast() examines two version strings and returns
//  true, if version >= acceptable
//  false, if version < acceptable
function versionAtLeast( version, acceptable ) {
	var versionArray = version.split(".");
	var acceptableArray = acceptable.split(".");

	for(var i = 0; i < versionArray.length && i < acceptableArray.length; i++) {
		// Better than acceptable
		if (eval(versionArray[i]) >= eval(acceptableArray[i])) {
			return true;
		}

		// Unacceptable
		if (versionArray[i] < acceptableArray[i]) {
			return false;
		}
	}

	// Acceptable
	return true;
}

var Browser = {
	isExplorer : /MSIE/i.test(navigator.userAgent),
	isNetscape : /Netscape/i.test(navigator.userAgent),
	isOpera    : /Opera/i.test(navigator.userAgent),
	isSafari   : /Safari/i.test(navigator.userAgent),
	isMozilla  : /Gecko/i.test(navigator.userAgent) && !(/Safari/i.test(navigator.userAgent)) && !(/Netscape/i.test(navigator.userAgent)),
	isFirefox  : /Firefox/i.test(navigator.userAgent),

	name       : "Unknown",
	version    : 0,
	supported  : false,


	// --- Methods ---

	// Constructor
	init : function() {
		this.name = (this.isExplorer) ? "Microsoft Internet Explorer"
		          : (this.isNetscape) ? "Netscape"
		          : (this.isMozilla)  ? "Mozilla"
		          : (this.isSafari)   ? "Safari"
		          : "Unknown";

		this.version = (this.isExplorer) ? navigator.userAgent.match(/MSIE([^;;]+)/i)[1]
		             : (this.isNetscape) ? navigator.userAgent.match(/Netscape\/([^;(]+)/)[1]
		             : (this.isMozilla)  ? navigator.userAgent.match(/rv:([^;)]+)/)[1]
		             : (this.isSafari)   ? navigator.userAgent.match(/Safari\/([^;;]+)/i)[1]
		             : 0;

		this.supported = (this.isExplorer) ? versionAtLeast(this.version, "6.0")
		               : (this.isNetscape) ? versionAtLeast(this.version, "8")
		               : (this.isMozilla)  ? versionAtLeast(this.version, "1.5")
		               : (this.isSafari)   ? versionAtLeast(this.version, "419.3")	// 2.0.4
		               : (this.isFirefox)  ? versionAtLeast(this.version, "1.5")
		               : false;
	},

	// Printable format
	toString : function() {
		return this.name + " v" + this.version;
	}
}

Browser.init();
