// a simple script for determining the browser capabilities
// andrew harris 2005-03-08
//
// there are more efficient ways of doing this, but I want something really
// open & flexible that I can understand when I come back to it in 6 months!
//
// Part 1 is all about determining the browser version and it's compatibility
//
// make the raw data lower case to assist searching
var agt = navigator.userAgent.toLowerCase();
// now, determine the platform
var os="";
if(agt.indexOf("mac") != -1)
  {
	os="Macintosh";
  } else if(agt.indexOf("windows") != -1) {
	os="Windows";
  } else if(agt.indexOf("inux") != -1) {
	os="Linux";
  } else {
	os="Other OS";
}
// now, the browser name
if(agt.indexOf("opera") != -1)
{
	bName = "Opera";
} else if(agt.indexOf("msie") != -1) {
	bName = "Microsoft Internet Explorer";
} else if(agt.indexOf("netscape") != -1) {
	bName = "Netscape";
} else if(agt.indexOf("firefox") != -1) {
	bName = "Firefox";
} else if(agt.indexOf("camino") != -1) {
	bName = "Camino";
} else if(agt.indexOf("safari") != -1) {
	bName = "Safari";
} else if(agt.indexOf("mozilla") != -1) {
	bName = "Mozilla";
}
// now, the browser version
var bVer= "";
if(bName == "Microsoft Internet Explorer")
{
	var startPosition= "", endPosition= "", version= "";
	startPosition = agt.indexOf("msie") + 5;
	endPosition = agt.indexOf(";",startPosition);
	bVer = agt.substring(startPosition,endPosition);
} else if(bName == "Netscape") {
	if(agt.indexOf("7.0") != -1){ bVer = 7.0 };
	if(agt.indexOf("7.1") != -1){ bVer = 7.1 };
	if(agt.indexOf("7.2") != -1){ bVer = 7.2 };
} else if(bName == "Firefox") {
	if(agt.indexOf("1.0") != -1){ bVer = 1.0 };
	if(agt.indexOf("2.0") != -1){ bVer = 2.0 };
} else {
	// because netscape 4.x browsers don't identify themselves as netscape!
	if(agt.indexOf("mozilla/4.7") != -1){ bVer = "4.7x", bName = "Netscape" };
	if(agt.indexOf("mozilla/4.77") != -1){ bVer = "4.77", bName = "Netscape" };
	if(agt.indexOf("mozilla/4.78") != -1){ bVer = "4.78", bName = "Netscape" };
}
//
// bless the various browser combinations
var browsermessage="";
if((os == "Windows")&&(bName=="Microsoft Internet Explorer")&&(bVer=="5.0")){ bCheck = 1;
	} else if((os == "Windows")&&(bName=="Microsoft Internet Explorer")&&(bVer=="5.5")){ bCheck = 1;
	} else if((os == "Windows")&&(bName=="Microsoft Internet Explorer")&&(bVer=="6.0")){ bCheck = 1;
	} else if((os == "Windows")&&(bName=="Microsoft Internet Explorer")&&(bVer=="7.0")){ bCheck = 1;
	} else if((os == "Windows")&&(bName=="Microsoft Internet Explorer")){ bCheck = 2;
	} else if((os == "Windows")&&(bName=="Firefox")){ bCheck = 1;
	} else if((os == "Windows")&&(bName=="Netscape")&&(bVer>="4.76")){ bCheck = 2;
	} else if((os == "Macintosh")&&(bName=="Safari")){ bCheck = 1;
	} else if((os == "Macintosh")&&(bName=="Firefox")){ bCheck = 1;
	} else if((os == "Macintosh")&&(bName=="Microsoft Internet Explorer")){ bCheck = 3;
	} else if((os == "Macintosh")&&(bName=="Netscape")&&(bVer=="4.77")){ bCheck = 2;
	} else if((os == "Macintosh")&&(bName=="Netscape")&&(bVer>="7.0")){ bCheck = 2;
	} else { bCheck = 0; // for all non-supported browsers
};
// OK, now constuct a statement to display meaningful information to the user
if(bCheck == 1) {
	browsermessage = ("<img src=\"\/lms\/browser_test\/tick.gif\" alt=\"[OK]\" \/> Your browser, "+bName+" version "+bVer+" for "+os+", works with the LMS.");
	} else if(bCheck == 2){
	browsermessage = ("<img src=\"\/lms\/browser_test\/alert.gif\" alt=\"[Alert]\" \/> Your browser, "+bName+" version "+bVer+" for "+os+", is not a recommended browser, though it should still work with the LMS.");
	} else if(bCheck == 3){
	browsermessage = ("<img src=\"\/lms\/browser_test\/cross.gif\" alt=\"[Problem]\" \/> Your browser, "+bName+" version "+bVer+" for "+os+", does not work with the LMS.");
	} else {
	browsermessage = ("<img src=\"\/lms\/browser_test\/alert.gif\" alt=\"[Alert]\" \/> Your browser, "+bName+" "+bVer+" for "+os+", is not recommended for use with the LMS. However, most modern browsers will work with the LMS.");
}
//
// Part 2 tests whether cookies are enabled
//
var cookieEnabled=(navigator.cookieEnabled)? true : false;
//
//if not IE4+ nor NS6+
if (typeof navigator.cookieEnabled=="undefined" && !cookieEnabled){ 
document.cookie="testcookie";
cookieEnabled=(document.cookie.indexOf("testcookie")!=-1)? true : false;
}
//
if (cookieEnabled){ //if cookies are enabled on client's browser
	cookiemessage=("<img src=\"\/lms\/browser_test\/tick.gif\" alt=\"[OK]\" \/> Your browser is accepting cookies. This is good.");
} else {
	cookiemessage=("<img src=\"\/lms\/browser_test\/cross.gif\" alt=\"[Problem]\" \/> Your browser is not accepting cookies. See <a href=\"/support/browser/cookies.html\">these instructions<\/a> on how to accept cookies.");
}
//
// Part 3 tests whether Java is enabled
//
var javamessage = "";
if(window.navigator.javaEnabled()){
		javamessage=("<img src=\"\/lms\/browser_test\/tick.gif\" alt=\"[OK]\" \/> Java is enabled in your browser. This is good.");
	} else {
		javamessage=("<img src=\"\/lms\/browser_test\/alert.gif\" alt=\"[Alert]\" \/> Could not detect Java in your browser. Some features of the LMS require Java. See <a href=\"/lms/assets/downloads/browser-check.pdf\">these instructions<\/a> on how to enable Java.");
}
if((os == "Macintosh")&&(bName!="Microsoft Internet Explorer")){
	javamessage+=("<br \/>&nbsp;&nbsp;&nbsp; <small><em>Gecko-based Mac browsers (Firefox, Mozilla, Netscape, Camino) may mis-report this.<\/small><\/em>");
}
//
// Part 4 tests for VBScript and warns about ActiveX
//
var activemessage = "";
if ((navigator.userAgent.indexOf('MSIE') != -1) && (navigator.userAgent.indexOf('Win') != -1)) {
	activemessage=("<dt>ActiveX<\/dt><dd>");
	activemessage+=("<dd><img src=\"\/lms\/browser_test\/alert.gif\" alt=\"[Alert]\" \/> If you use Internet Explorer for Windows and need to use the WYSIWYG editor, you will require ActiveX to be enabled. ActiveX cannot be reliably detected by this page, but if you experience difficulty with the WYSIWYG editor, try enabling ActiveX. See <a href=\"/lms/active_x.html\">this guide<\/a> for instructions.<\/dd>");
}
//
// Part 5 writes back to the document
//
// display the statements
document.write("<dl>");
document.write("<dt>Browser<\/dt>");
document.write("<dd>"+browsermessage+"<\/dd>");
document.write("<dt>Javascript<\/dt>"); // if they've got this far it's a given!
document.write("<dd><img src=\"\/lms\/browser_test\/tick.gif\" alt=\"[OK]\" \/> JavaScript is enabled in your browser. This is good.<\/dd>");
document.write("<dt>Cookies<\/dt>");
document.write("<dd>"+cookiemessage+"<\/dd>");
document.write("<dt>Java<\/dt>");
document.write("<dd>"+javamessage+"<\/dd>");
document.write(activemessage);
document.write("<\/dl>");
// for debugging
/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
var debug="";
debug = ("<pre>os = "+os+" : bName = "+bName+" : bVer = "+bVer+" : bCheck = "+bCheck);
document.write(debug);
document.write("\r"+agt);
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
