ua = navigator.userAgent.toLowerCase();
i = 0;
browser = '';
version = 0;
os = '';
msg = '';

//Detect browser and version.

if ((i = ua.indexOf('aol')) != -1) {
	browser = 'AOL';
	version = parseFloat('0' + ua.substr(i+4), 10);
}	
else if ((i = ua.indexOf('compuserve')) != -1) {
	browser = 'CompuServe';
	version = '';	
}
else if ((i = ua.indexOf('opera')) != -1) {
	browser = 'Opera';
	version = parseFloat('0' + ua.substr(i+6), 10);
}
else if ((i = ua.indexOf('icab')) != -1) {
	browser = 'iCab';
	version = '';
}
else if ((i = ua.indexOf('webtv')) != -1) {
	browser = 'WebTV';
	version = '';
}
else if ((i = ua.indexOf('safari')) != -1) {
	browser = 'Safari';
	version = '';
}
else if ((i = ua.indexOf('firefox')) != -1) {
	browser = 'Firefox';
	version = '';
}
else if (((i = ua.indexOf('gecko')) != -1) && ((i = ua.indexOf('netscape')) == -1)) {
	browser = 'Mozilla';
	i = ua.lastIndexOf(':');
	l = ua.lastIndexOf(')');
	n = l - i - 1;
	version = ua.substr((i+1),n);
}
else if ((i = ua.indexOf('msie')) != -1) {
	browser = 'Internet Explorer';
	version = parseFloat('0' + ua.substr(i+5), 10);
}
else if (navigator.appName == 'Netscape') {
	browser = 'Netscape';
	i = ua.lastIndexOf('/')
	version = parseFloat('0' + ua.substr(i+1), 10);
	if (version >= 6.2) {
		version = ua.substr((i+1),(i+7));
	}
}

//Detect operating system.

if (ua.indexOf('win') != -1 ) {
	os = 'Windows';
}
else if (ua.indexOf('mac') != -1 ) {
	os = 'Macintosh';
}
else if (ua.indexOf('unix') != -1 ) {
	os = 'Unix';
}
else if (ua.indexOf('linux') != -1 ) {
	os = 'Linux';
}
else if (ua.indexOf('sun') != -1 ) {
	os = 'Sun';
}

//Assign messages based on browser, version and os.

if (browser == 'CompuServe') {
	msg = '<img src="images/redx.gif" width="18" height="11" alt="Red X.">The CompuServe Web browser is not supported by  the Wright State online course system. But you can log onto CompuServe, then launch a supported browser. See <a href="aol.html">Using AOL with the Wright State online course system</a>.';
}
else if ((browser == 'AOL') && (version < 7)) {
	msg = '<img src="images/redx.gif" width="18" height="11" alt="Red X.">This version of the AOL Web browser is not supported by the Wright State online course system. But you can log onto AOL, then launch a supported browser. See <a href="aol.html">Using AOL with the Wright State online course system</a>.';
}
else if ((browser == 'AOL') && (version >= 7)) {
	msg = '<img src="images/greencheck.gif" width="18" height="11" alt="Green check mark.">This AOL Web browser is supported by the Wright State online course system. If you have trouble with some course features, though, see <a href="aol.html">using AOL with the Wright State online course system</a>.';
}
else if ((browser == 'Opera') || (browser == 'iCab') ||  (browser == 'Firefox')) {
	msg = '<img src="images/redx.gif" width="18" height="11" alt="Red X.">' + browser + ' is not supported by the Wright State online course system and may not work with some features in your online course. Please use one of the compatible browsers listed below.';
}
else if (browser == 'Safari') {
	msg = '<img src="images/greencheck.gif" width="18" height="11" alt="Green check.">Safari works with most of the Wright State online course system features and will be fine for most courses. If you need to use some special features that do not work in Safari, you may want to try Internet Explorer 5.1 or higher.';
}
else if (browser == 'WebTV') {
	msg = '<img src="images/redx.gif" width="18" height="11" alt="Red X.">WebTV is not supported by the Wright State online course system. You will need a computer and one of the compatible browsers listed below. <a href="hardware.html">See computer requirements.</a>';
}

//begin Mozilla section

else if (browser == 'Mozilla') {
	if (version.substr(0,3) >= 1.5) {
		if (os == 'Windows') {
		msg = '<img src="images/greencheck.gif" width="18" height="11" alt="Green check mark.">Mozilla ' + version + ' for Windows is compatible with most courses in the Wright State online course system. To get the most from your Mozilla browser, see the <a href="mozilla_win.html">Windows Mozilla tuneup</a> page.';
		}
		else if (os == 'Macintosh') {
		msg = '<img src="images/greencheck.gif" width="18" height="11" alt="Green check mark.">Mozilla ' + version + ' for Macintosh works with most of the Wright State online course system features and will be fine for most courses. If you need to use some special features that do not work in Mozilla, you may want to try Internet Explorer 5.1 or higher. For more information on using your Mozilla browser with the Wright State online course system, see the <a href="mozilla_mac.html">Mac Mozilla tuneup</a> page.';
		}
	}
	else {
	msg = '<img src="images/redx.gif" width="18" height="11" alt="Red X.">Please upgrade to a newer version of Mozilla or use one of the other compatible browsers listed below.';
	}
}

//begin Netscape section

else if (browser == 'Netscape') {
	if ((version <= 6.1) || (version == '6.2') || (version == '6.2.1')) {
		msg = '<img src="images/redx.gif" width="18" height="11" alt="Red X.">Netscape ' + version + ' is not compatible with the Wright State online course system. Please use one of the compatible browsers listed below.';
		}
	else {
		if (os == 'Windows') {
		msg = '<img src="images/greencheck.gif" width="18" height="11" alt="Green check mark.">Netscape ' + version + ' for Windows is compatible with most courses in the Wright State online course system. To get the most from your Netscape browser, see the <a href="netscape_win.html">Windows Netscape tuneup</a> page.';
		}
	else if (os == 'Macintosh') {
		msg = '<img src="images/greencheck.gif" width="18" height="11" alt="Green check mark.">Netscape ' + version + ' for Macintosh works with most of the Wright State online course system features and will be fine for most courses. If you need to use some special features that do not work in Netscape, you may want to try Internet Explorer 5.1 or higher.  For more information on using your Netscape browser with  the Wright State online course system, see the <a href="netscape_mac.html">Mac Netscape tuneup</a> page.';
		}
	}
}

//end Netscape and begin IE section

else if (browser == 'Internet Explorer') {
	if (version < 5) {
		msg = '<img src="images/redx.gif" width="18" height="11" alt="Red X.">Internet Explorer ' + version + ' is not compatible with  the Wright State online course system. You need a more current browser. Please use one of the compatible browsers listed below.';
	}
	else if (os == 'Macintosh') {
		msg = '<img src="images/greencheck.gif" width="18" height="11" alt="Green check mark.">This browser works with WebCT. See the <a href="iemac.html">IE for Macintosh tuneup</a> page.';
	}
	else if ((os == 'Unix') || (os == 'Linux') || (os == 'Sun')) {
		msg = 'Internet Explorer for ' + os + ' may work, but is not proven compatible with WebCT. We recommend you use Netscape Communicator 6.2.2 or higher.';
	}
	
//Messages for Internet Explorer for Windows
	
	else if (os == 'Windows') {
		if ((version >= 5) && (version < 5.5)) {
			msg = '<img src="images/greencheck.gif" width="18" height="11" alt="Green check mark.">This browser may work with the Wright State online course system if it has 128-bit encryption. See the <a href="ie50win.html">IE 5 for Windows tuneup</a> page.';
		}
		else if ((version >= 5.5) && (version < 6)) {
			msg = '<img src="images/greencheck.gif" width="18" height="11" alt="Green check mark.">This browser works with  the Wright State online course system, if it has Service Pack 2 installed. See the <a href="ie55win.html">IE 5.5 for Windows tuneup</a> page.';
		}
		else if (version >= 6) {
			msg = '<img src="images/greencheck.gif" width="18" height="11" alt="Green check mark.">This browser works with  the Wright State online course system. See the <a href="ie6win.html">IE 6 or higher for Windows tuneup</a> page.';
		}
	}
}

//Functions to write browser information, or a warning if browser is not detected.

function whatbrowser() {
var foros = '';
	if (os) {
		foros = ' for ' + os;
	}
	if (browser) {		
	document.write('Your browser is <b>' + browser + ' ' + version + '</b>' + foros + '.');
	
		if (msg) {
			document.write('<br>' + msg);
		}
	}
	else {
	document.write('<img src="images/redx.gif" width="18" height="11" alt="Red X.">Your browser is not supported by the Wright State online course system and may not work with some features in your online course. Please see our browser recommendations below.');
	}
}

//For pages other than the browser info page. This displays a message only if the browser is not supported.
function shortchk() {
	if (msg.indexOf('redx') != -1 ) {
		document.write('<p class="warning announcetext"><img src="images/redx.gif" width="18" height="11" alt="Red X.">Your browser is not supported by the Wright State online course system and may not work with some features in your online course. Please see our <a href="browser.html">browser recommendations</a>.</p>');
	}
}
function chatcheck() {
	if (os == 'Macintosh') {
		document.write('<p style="padding: 5px;border: 1px solid #063;color:#063;"><span class="warning" style="font-size:larger;">Mac users:</span> If you need to use the <strong style="font-size:larger;">live chat</strong> feature in your WebCT course, <a href="https://wisdom.wright.edu/login2.html">please log in here</a>.</p>');
	}
}