var passedColour = "#008000";
var failedColour = "#800000";
var detectableWithVB = false;

var agt = navigator.userAgent.toLowerCase();
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);

var is_firefox = (agt.indexOf('firefox') != -1);
var is_firefox2 = (is_firefox && (agt.indexOf("firefox/2.") != -1 ));
var is_firefox3 = (is_firefox && (agt.indexOf("firefox/3.") != -1 ));
var is_firefox4 = (is_firefox && (agt.indexOf("firefox/4.") != -1 ));

var is_safari = (agt.indexOf('safari') != -1);
var is_safari3_0 = ( is_safari && ( agt.indexOf("version/3.0") != -1 ) );
var is_safari31up = ( is_safari && !is_safari3_0 && ( agt.indexOf("version/3") != -1 ) );
var is_safari4 = ( is_safari && agt.indexOf("version/4") != -1 );
var is_safari5 = ( is_safari && agt.indexOf("version/5") != -1 );

var is_ie = ( ( agt.indexOf("msie") != -1 ) && ( agt.indexOf("opera") == -1 ) );
var is_ie6 = ( is_ie && ( is_major == 4 ) && ( agt.indexOf("msie 6.") != -1 ) );
var is_ie7 = ( is_ie && ( is_major == 4 ) && ( agt.indexOf("msie 7.") != -1 ) );
var is_ie8 = ( is_ie && ( is_major == 4 ) && ( agt.indexOf("msie 8.") != -1 ) );
var is_ie9 = ( is_ie && ( is_major == 5 ) && ( agt.indexOf("msie 9.") != -1 ) );

var is_win = ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) );
var is_win95 = ((agt.indexOf("win95")!=-1) || (agt.indexOf("windows 95")!=-1));
var is_win16 = ((agt.indexOf("win16")!=-1) ||
         (agt.indexOf("16bit")!=-1) || (agt.indexOf("windows 3.1")!=-1) ||
         (agt.indexOf("windows 16-bit")!=-1) );
var is_win31 = ((agt.indexOf("windows 3.1")!=-1) || (agt.indexOf("win16")!=-1) ||
              (agt.indexOf("windows 16-bit")!=-1));
var is_winme = ((agt.indexOf("win 9x 4.90")!=-1));
var is_win2k = ((agt.indexOf("windows nt 5.0")!=-1));
var is_win98 = ((agt.indexOf("win98")!=-1) || (agt.indexOf("windows 98")!=-1));
var is_winnt = ((agt.indexOf("winnt")!=-1) || (agt.indexOf("windows nt")!=-1));
var is_win32 = (is_win95 || is_winnt || is_win98 ||
              ((is_major >= 4) && (navigator.platform == "Win32")) ||
              (agt.indexOf("win32")!=-1) || (agt.indexOf("32bit")!=-1));
var is_win2k = is_winnt && (agt.indexOf("5.0") != -1);
var is_winxp = is_winnt && (agt.indexOf("5.1") != -1);
var is_os2 = ((agt.indexOf("os/2")!=-1) ||
              (navigator.appVersion.indexOf("OS/2")!=-1) ||
              (agt.indexOf("ibm-webexplorer")!=-1));

var is_mac = (agt.indexOf("mac")!=-1);
var is_mac68k = (is_mac && ((agt.indexOf("68k")!=-1) ||
                         (agt.indexOf("68000")!=-1)));
var is_macppc = (is_mac && ((agt.indexOf("ppc")!=-1) ||
                          (agt.indexOf("powerpc")!=-1)));
                          

// These terms are overridden
var JTHelp = "Help";

var BTDescription = "A current browser such as the latest version of Microsoft Internet Explorer is recommended to ensure full functionality of all components.";
var BTRecommendationMac = "";
var BTRecommendationWindows = "";
var BTRecommendationLinux = "";

var BTResultPass = "Your browser is sufficient.";
var BTResultFail_1 = "Your browser is not a sufficient browser, please <a href='upgrade_browser.asp?ou=";
var BTResultFail_2 = "'>upgrade</a> your browser.";
var BTName = "Browser";

var BTFullyCompatible = "FC";
var BTCurrentlyTesting = "CT";
var BTOldBrowser = "OB";
var BTFailed = "Failed";

var BTHelp = "Help";

function browsertest() {

	var pass = false;
	result_text = BTFailed;
	
	// IE
	if( is_ie && ( is_ie7 || is_ie8 || is_ie9 ) ) {
		pass = true;
		result_text = BTFullyCompatible;
	}
	
	// Firefox
	if( is_firefox && ( is_firefox3 || is_firefox4 ) ) {
		result_text = BTFullyCompatible;
		pass = true;
	}

	// Safari
	if( is_safari && ( is_safari31up || is_safari4 || is_safari5 ) ) {
		result_text = BTFullyCompatible;
		pass = true;
	}

	drawCheck( BTName, '', pass, result_text, '' );
	
}

var CTDescription = "The use of cookies is to allow for an increased level of security and are not being used to track your movements.";
var CTResultPass = "Your cookies are enabled.";
var CTResultFail_1 = "You do not have cookies enabled.&nbsp";
var CTResultFail_2 = "Click here for instructions";
var CTResultFail = "Fail";
var CTName = "Cookies";

var CTHelp = "Help";

function cookietest() {
	var description = '';
	var pass;
	var result_text = "";
	document.cookie = "test=cookietest";
	var theCookie=""+document.cookie;
	var ind=theCookie.indexOf("test=");
	if(ind==-1) {
		pass = false;
		result_text = CTResultFail;

		result_text +="</a>";
	}
	else {
		pass = true;
		result_text = CTResultPass;
	}
	drawCheck(CTName, description, pass, result_text, CTHelp);
}

var DTDescription = "To view our pages properly, this test ensures your computer is running the proper screen resolution and color depth.";
var DTResultPass = "You are running a sufficient screen resolution. You are also running a sufficient colour level.";
var DTResultFail_1 = "You are running a 640 X 480 screen resolution. We recommend that you run at least an 800 X 600 screen resolution.";
var DTResultFail_2 = " You are also only running at a 2-bit colour level. We recommend that you use at least a 16-bit colour level.";
var DTResultFail_3 = " You are also only running a 4-bit colour level. We recommend that you use at least a 16-bit colour level.";
var DTResultFail_4 = " You are also only running at an 8-bit colour level.  We recommend that you use at least a 16-bit colour level.";
var DTResultFail_5 = " However, you are running a sufficient colour level.";
var DTResultFail_6 = "Follow these instruction to change your display settings.";
var DTResultFail_7 = "You are running a sufficient screen resolution.";
var DTResultFail_8 = " However you are also only running a 2-bit colour level. We recommend that you use at least a 16-bit colour level.";
var DTResultFail_9 = " However, you are only running a 4-bit colour level. We recommend that you use at least a 16-bit colour level.";
var DTResultFail_10 = " However, you are only running a 4-bit colour level. We recommend that you use at least a 16-bit colour level.";
var DTResultFail_11 = "Follow these instruction to change your display settings.";


var DTName = "Display";
var DTResPass = "";
var DTPixDepPass = "";
var DTResFailed = "";
var DTPixDepFailed = "";
var DTMoreInfo = "";

function displaytest() {
	var passRes = true;
	var passPD = true;
	var result_text = "";
	if ( screen.height == 480 ) {
		passRes = false;

	}

	if ( screen.pixelDepth<16 || screen.colorDepth<16  ) {
		passPD = false;
	}
	
	
	document.write("<tr><td>&nbsp;</td><td colspan=2><b>" + DTName + "</b></td></tr>");
	
	if ( passRes || passPD ) {
		document.write("<tr><td>&nbsp;</td><td valign=top><img src='/d2l/tools/img/check.gif' width=25 height=25 alt='" + DTPass + "' title='" + DTPass + "'>");
		document.write("</td><td>");
		document.write("<font color='" + passedColour + "'><b>" + DTPassed + "</b></font><br>");
		
		if ( passRes ) {
			document.write("<br>" + DTResPass );
		}
		if ( passPD ) {
			document.write("<br>" + DTPixDepPass );		
		}
		
		document.write("</td></tr>");	

	}

	
	if(passRes == false || passPD == false ) {
		document.write("<tr><td>&nbsp;</td><td valign=top><img src='/d2l/tools/img/error.gif' width=16 height=16 alt='" + DTFailed + "' title='" + DTFailed + "'>");
		document.write("</td><td>");
		document.write("<font color='" + failedColour + "'><b>" + DTFailed + "</b></font><br>");
		
		if ( passRes == false ) {
			document.write("<br>" + DTResFailed + "<br>" );
		}
		if ( passPD == false ) {
			document.write("<br>" + DTPixDepFailed + "<br>" );		
		}
		
		document.write("<br>" + DTMoreInfo + "<br>" );				
		
		document.write("</td></tr>");	
	}
		
}

function detectPlugin() {
	var daPlugins = detectPlugin.arguments;
	var pluginFound = false;
	if (navigator.plugins && navigator.plugins.length > 0) {
		var pluginsArrayLength = navigator.plugins.length;
		for (pluginsArrayCounter=0; pluginsArrayCounter < pluginsArrayLength; pluginsArrayCounter++ ) {
			var numFound = 0;
			for(namesCounter=0; namesCounter < daPlugins.length; namesCounter++) {
				if( (navigator.plugins[pluginsArrayCounter].name.indexOf(daPlugins[namesCounter]) >= 0) ||
	    			(navigator.plugins[pluginsArrayCounter].description.indexOf(daPlugins[namesCounter]) >= 0) ) {
	    			numFound++;
				}
			}
			if(numFound == daPlugins.length) {
				pluginFound = true;
				break;
			}
		}
	}
	return pluginFound;
}

var DTPass = "Pass";
var DTPassed = "Passed";
var DTFailed = "Failed";

function drawCheck(name, description, pass, result_text, help_text) {
	document.write("<tr><td>&nbsp;</td><td colspan=2><b>" + name + "</b></td></tr><tr><td>&nbsp;</td><td valign=top>");
	if(pass) {
		document.write("<img src='/d2l/tools/img/check.gif' width=25 height=25 alt='" + DTPass + "' title='" + DTPass + "'>");
	}
	else {
		document.write("<img src='/d2l/tools/img/error.gif' width=16 height=16 alt='" + DTFailed + "' title='" + DTFailed + "'>");
	}
	document.write("</td><td>");
	if(pass) {
		document.write("<font color='" + passedColour + "'><b>" + DTPassed + "</b></font>");
	}
	else {
		document.write("<font color='" + failedColour + "'><b>" + DTFailed + "</b></font>");
	}
	document.write("<br>" + description + "<br>" + result_text );
		
	document.write("</td></tr>");
}

// Here we write out the VBScript block for MSIE Windows
if ((navigator.userAgent.indexOf('MSIE') != -1) && (navigator.userAgent.indexOf('Win') != -1)) {
    document.writeln('<script language="VBscript">');

    document.writeln('detectableWithVB = False');
    document.writeln('If ScriptEngineMajorVersion >= 2 then');
    document.writeln('  detectableWithVB = True');
    document.writeln('End If');

    document.writeln('\'this next function will detect most plugins');
    document.writeln('Function detectActiveXControl(activeXControlName)');
    document.writeln('  on error resume next');
    document.writeln('  detectActiveXControl = False');
    document.writeln('  If detectableWithVB Then');
    document.writeln('     detectActiveXControl = IsObject(CreateObject(activeXControlName))');
    document.writeln('  End If');
    document.writeln('End Function');

    document.writeln('\'and the following function handles QuickTime');
    document.writeln('Function detectQuickTimeActiveXControl()');
    document.writeln('  on error resume next');
    document.writeln('  detectQuickTimeActiveXControl = False');
    document.writeln('  If detectableWithVB Then');
    document.writeln('    detectQuickTimeActiveXControl = False');
    document.writeln('    hasQuickTimeChecker = false');
    document.writeln('    Set hasQuickTimeChecker = CreateObject("QuickTimeCheckObject.QuickTimeCheck.1")');
    document.writeln('    If IsObject(hasQuickTimeChecker) Then');
    document.writeln('      If hasQuickTimeChecker.IsQuickTimeAvailable(0) Then ');
    document.writeln('        detectQuickTimeActiveXControl = True');
    document.writeln('      End If');
    document.writeln('    End If');
    document.writeln('  End If');
    document.writeln('End Function');

    document.writeln('</scr' + 'ipt>');
}
