

	
	
	document.onkeydown = function(e) {
		if (!e) var e = window.event;
		var allState = (BrowserDetect.accessKeyModifiers.length > 0) ? true : false;
		for (i=0; i<BrowserDetect.accessKeyModifiers.length; i++) {
			if (BrowserDetect.accessKeyModifiers[i].code == e.keyCode) { BrowserDetect.accessKeyModifiers[i].state = true; }
			allState = allState && BrowserDetect.accessKeyModifiers[i].state
		}
		if (allState) { underlineAccessKeys(); }
	}
	document.onkeyup = function(e) {
		if (!e) var e = window.event;
		var allState = true;
		for (i=0; i<BrowserDetect.accessKeyModifiers.length; i++) {
			if (BrowserDetect.accessKeyModifiers[i].code == e.keyCode) { BrowserDetect.accessKeyModifiers[i].state = false; }
			allState = allState && BrowserDetect.accessKeyModifiers[i].state
		}
		if (!allState) { removeAccessKeyUndeline(); }
	}
	
	function underlineAccessKeys() {
		if (!underlineSpansInserted) {
			var anchors = document.getElementsByTagName('a');
			for (var i=0; i<anchors.length; i++) {
				if (anchors[i].accessKey != '') {
					var pos = anchors[i].innerHTML.toLowerCase().indexOf(anchors[i].accessKey.toLowerCase());
					if (pos >= 0) {
						anchors[i].innerHTML = anchors[i].innerHTML.slice(0,pos) + '<span class="underlineAccessKey">' + anchors[i].innerHTML.slice(pos,pos+1) + '<'+'/span>' + anchors[i].innerHTML.slice(pos+1);
					}
				}
			}
			underAccessKeyStyleSheet = document.createElement('style');
			var def = '.underlineAccessKey { text-decoration: underline; }';
			underAccessKeyStyleSheet.setAttribute("type", "text/css");
			if (underAccessKeyStyleSheet.styleSheet) {   // IE
				underAccessKeyStyleSheet.styleSheet.cssText = def;
			} else {                // the world
				var tt1 = document.createTextNode(def);
				underAccessKeyStyleSheet.appendChild(tt1);
			}
			underlineSpansInserted = true;
		}
		document.getElementsByTagName('head')[0].appendChild(underAccessKeyStyleSheet);
		underAccessKeyStyleSheet.disabled = false;
	}
	function removeAccessKeyUndeline() {
		if (underAccessKeyStyleSheet) {
			if (underAccessKeyStyleSheet.parentNode) {
				underAccessKeyStyleSheet.disabled = true;
				document.getElementsByTagName('head')[0].removeChild(underAccessKeyStyleSheet);
			}
		}
	}
	
	
	var underlineSpansInserted = false;
	var underAccessKeyStyleSheet = null;




	var BrowserDetect = {
		init: function () {
		
			var dbIndex = this.searchString();
			this.browser = this.dataBrowser[dbIndex].identity || "An unknown browser";
			this.version = this.searchVersion(navigator.userAgent)
				|| this.searchVersion(navigator.appVersion)
				|| "an unknown version";
			this.OS = this.searchOSString() || "an unknown OS";
			
			this.accessKeyInstuctions = null;
			this.accessKeyShortCode = '';
			this.accessKeyModifiers = [];
			if (this.dataBrowser[dbIndex].accessKeys) {
				for (var i=0; i<this.dataBrowser[dbIndex].accessKeys.length; i++) {
					var accessKeys = this.dataBrowser[dbIndex].accessKeys[i];
					if (accessKeys.forOS == this.OS && this.version>=accessKeys.fromVersion && this.version<accessKeys.toVersion) {
						this.accessKeyModifiers = accessKeys.keys;
						this.accessKeyInstuctions = 'Hold down the ';
						for (var j=0; j<accessKeys.keys.length; j++) {
							this.accessKeyInstuctions += this.getKeyName(accessKeys.keys[j].code);
							this.accessKeyShortCode += this.getKeyName(accessKeys.keys[j].code);
							if (j<accessKeys.keys.length-2) { this.accessKeyInstuctions += ', '; }
							if (j==accessKeys.keys.length-2) { this.accessKeyInstuctions += ' and '; }
							if (j<accessKeys.keys.length-1) { this.accessKeyShortCode += '+'; }
							accessKeys.keys[j].state = false;
						}
						this.accessKeyInstuctions += ' key' + ((accessKeys.keys.length > 1) ? 's' : '') + ' then press the <i>Access Key</i>.';
						if (accessKeys.accessKeyNote) { this.accessKeyInstuctions = accessKeys.accessKeyNote; }
					}
				}
			}
			
		},
		searchString: function () {
			for (var i=0;i<this.dataBrowser.length;i++)	{
				var dataString = this.dataBrowser[i].string;
				var dataProp = this.dataBrowser[i].prop;
				this.versionSearchString = this.dataBrowser[i].versionSearch || this.dataBrowser[i].identity;
				if (dataString) {
					if (dataString.indexOf(this.dataBrowser[i].subString) != -1)
						return i;
				}
				else if (dataProp)
					return i;
			}
		},
		searchOSString: function () {
			for (var i=0;i<this.dataOS.length;i++)	{
				var dataString = this.dataOS[i].string;
				if (dataString) {
					if (dataString.indexOf(this.dataOS[i].subString) != -1)
						return this.dataOS[i].identity;
				}
			}
		},
		searchVersion: function (dataString) {
			var index = dataString.indexOf(this.versionSearchString);
			if (index == -1) return;
			return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
		},
		getKeyName: function (code) {
			switch (code) {
				case 16: return 'Shift';
				case 17: return 'Ctrl';
				case 18: return 'Alt';
				case 27: return 'Esc';
				default: return '';
			}
		},
		dataBrowser: [ {
				string: navigator.userAgent,
				subString: "Chrome",
				identity: "Chrome",
				accessKeys: [ {
						forOS: 'Windows',
						fromVersion: 1,
						toVersion: 2,
						keys: [ { code:18 } ]
					}
				]
			}, {
				string: navigator.userAgent,
				subString: "OmniWeb",
				versionSearch: "OmniWeb/",
				identity: "OmniWeb",
				accessKeys: [ {
						forOS: 'Mac',
						fromVersion: 5.1,
						toVersion: 999,
						keys: [ { code:17 } ]
					}
				]
			}, {
				string: navigator.vendor,
				subString: "Apple",
				identity: "Safari",
				versionSearch: "Version",
				accessKeys: [ {
						forOS: 'Mac',
						fromVersion: 1.2,
						toVersion: 999,
						keys: [ { code:17 }, { code:18 } ]
					}, {
						forOS: 'Windows',
						fromVersion: 0,
						toVersion: 999,
						keys: [ { code:18 } ]
					}
				]
			}, {
				prop: window.opera,
				identity: "Opera",
				accessKeys: [ {
						forOS: 'Mac',
						fromVersion: 7,
						toVersion: 999,
						keys: [ { code:16 }, { code:27 } ],
						accessKeyNote: 'Hold down the Shift key, press Esc and release,<br/>then press the <i>Access Key</i>'
					}, {
						forOS: 'Windows',
						fromVersion: 7,
						toVersion: 999,
						keys: [ { code:16 }, { code:27 } ],
						accessKeyNote: 'Hold down the Shift key, press Esc and release,<br/>then press the <i>Access Key</i>'
					}, {
						forOS: 'Linux',
						fromVersion: 7,
						toVersion: 999,
						keys: [ { code:16 }, { code:27 } ],
						accessKeyNote: 'Hold down the Shift key, press Esc and release,<br/>then press the <i>Access Key</i>'
					}
				]
			}, {
				string: navigator.vendor,
				subString: "iCab",
				identity: "iCab",
				accessKeys: [ {
						forOS: 'Mac',
						fromVersion: 3,
						toVersion: 999,
						keys: [ { code:17 }, { code:18 } ]
					}
				]
			}, {
				string: navigator.vendor,
				subString: "KDE",
				identity: "Konqueror",
				accessKeys: [ {
						forOS: 'Linux',
						fromVersion: 3.3,
						toVersion: 999,
						keys: [ { code:17 } ]
					}
				]
			}, {
				string: navigator.userAgent,
				subString: "Firefox",
				identity: "Firefox",
				accessKeys: [ {
						forOS: 'Mac',
						fromVersion: 0,
						toVersion: 999,
						keys: [ { code:17 } ]
					}, {
						forOS: 'Windows',
						fromVersion: 2,
						toVersion: 999,
						keys: [ { code:16 }, { code:18 } ]
					}, {
						forOS: 'Windows',
						fromVersion: 0,
						toVersion: 2,
						keys: [ { code:18 } ]
					}, {
						forOS: 'Linux',
						fromVersion: 2,
						toVersion: 999,
						keys: [ { code:16 }, { code:17 } ]
					}, {
						forOS: 'Linux',
						fromVersion: 0,
						toVersion: 2,
						keys: [ { code:17 } ]
					}
				]
			}, {
				string: navigator.vendor,
				subString: "Camino",
				identity: "Camino",
				accessKeys: [ {
						forOS: 'Mac',
						fromVersion: 1,
						toVersion: 999,
						keys: [ { code:17 } ]
					}
				]
			}, {		// for newer Netscapes (6+)
				string: navigator.userAgent,
				subString: "Netscape",
				identity: "Netscape",
				accessKeys: [ {
						forOS: 'Mac',
						fromVersion: 6,
						toVersion: 999,
						keys: [ { code:17 } ]
					}, {
						forOS: 'Windows',
						fromVersion: 6,
						toVersion: 9,
						keys: [ { code:18 } ]
					}, {
						forOS: 'Windows',
						fromVersion: 9,
						toVersion: 999,
						keys: [ { code:16 }, { code:18 } ]
					}, {
						forOS: 'Linux',
						fromVersion: 6,
						toVersion: 999,
						keys: [ { code:187 } ]
					}
				]
			}, {
				string: navigator.userAgent,
				subString: "MSIE",
				identity: "Explorer",
				versionSearch: "MSIE",
				accessKeys: [ {
						forOS: 'Mac',
						fromVersion: 5.2,
						toVersion: 999,
						keys: [ { code:17 } ]
					}, {
						forOS: 'Windows',
						fromVersion: 5,
						toVersion: 999,
						keys: [ { code:18 } ],
						accessKeyNote: 'Hold down the Alt key, press the <i>Access Key</i> and release,<br/>and then press Enter.'
					}, {
						forOS: 'Windows',
						fromVersion: 4,
						toVersion: 5,
						keys: [ { code:18 } ]
					}
				]
			}, {
				string: navigator.userAgent,
				subString: "Gecko",
				identity: "Mozilla",
				versionSearch: "rv",
				accessKeys: [ {
						forOS: 'Mac',
						fromVersion: 0,
						toVersion: 999,
						keys: [ { code:17 } ]
					}, {
						forOS: 'Windows',
						fromVersion: 0,
						toVersion: 999,
						keys: [ { code:18 } ]
					}, {
						forOS: 'Linux',
						fromVersion: 0,
						toVersion: 999,
						keys: [ { code:17 } ]
					}
				]
			}, { 		// for older Netscapes (4-)
				string: navigator.userAgent,
				subString: "Mozilla",
				identity: "Netscape",
				versionSearch: "Mozilla"
			}
		],
		dataOS : [ {
				string: navigator.platform,
				subString: "Win",
				identity: "Windows"
			}, {
				string: navigator.platform,
				subString: "Mac",
				identity: "Mac"
			}, {
				string: navigator.userAgent,
				subString: "iPhone",
				identity: "iPhone/iPod"
			}, {
				string: navigator.platform,
				subString: "Linux",
				identity: "Linux"
			}
		]
	};
	BrowserDetect.init();
	

