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_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
          && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
          && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
var is_nav2 = (is_nav && (is_major == 2));
var is_nav3 = (is_nav && (is_major == 3));
var is_nav4 = (is_nav && (is_major == 4));
var is_nav4up = (is_nav && (is_major >= 4));
var is_navonly = (is_nav && ((agt.indexOf(";nav") != -1) ||
                    (agt.indexOf("; nav") != -1)) );
var is_nav6 = (is_nav && (is_major == 5));
var is_nav6up = (is_nav && (is_major >= 5));
var is_gecko = (agt.indexOf('gecko') != -1);
var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var is_ie3 = (is_ie && (is_major < 4));
var is_ie4 = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
var is_ie4up = (is_ie && (is_major >= 4));
var is_ie5 = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
var is_ie5_5 = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
var is_ie5up = (is_ie && !is_ie3 && !is_ie4);
var is_ie5_5up =(is_ie && !is_ie3 && !is_ie4 && !is_ie5);
var is_ie6 = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.")!=-1) );
var is_ie6up = (is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_5);

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);
if (is_mac && is_ie5up) is_js = 1.4;
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 BTDescription = "A current browser such as the latest version of Microsoft Internet Explorer is recommended to ensure full functionality of all components.";
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";

function browsertest() {
	var description = BTDescription;
	var pass;
	var result_text = "";
	if(is_ie5up || is_nav4up) {
		pass = true;
		result_text = BTResultPass;
	}
	else {
		pass = false;
		result_text = BTResultFail_1  + ou + BTResultFail_2;
	}
	drawCheck(BTName, description, 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 CTName = "Cookies";

function cookietest() {
	var description = CTDescription;
	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_1;
		if(is_nav4) {
			result_text += "<a href='http://www.beyondfleece.com/faq/enable_cookies/#winmoz'>";
		}
		else if(is_nav6up) {
			result_text += "<a href='http://www.beyondfleece.com/faq/enable_cookies/#winmoz'>";
		}
		else {
			result_text += "<a href='tech-tutorial-ie-ck.html'>";
		}
		result_text += CTResultFail_2 + "</a>";
	}
	else {
		pass = true;
		result_text = CTResultPass;
	}
	drawCheck(CTName, description, pass, result_text);
}

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";


function displaytest() {
	var description = DTDescription;
	var pass;
	var result_text = "";
	var link = "";
	if(is_winxp) {
		link = "adjust_res_xp.asp?ou=" + ou;
	}
	else if(is_mac) {
		link = "adjust_res_mac.asp?ou=" + ou;
	}
	else {
		link = "adjust_res_98.asp?ou=" + ou;
	}
	if ((screen.height==480) || (screen.pixelDepth==8) || (screen.pixelDepth==4) || (screen.pixelDepth==2)) {
		pass = false;
		if (screen.height == 480) {
			result_text = DTResultFail_1;
		   if (screen.pixelDepth == 2) {
				result_text += DTResultFail_2;
			}
		   else if (screen.pixelDepth == 4) {
				result_text += DTResultFail_3;
			}
		   else if (screen.pixelDepth == 8) {
				result_text += DTResultFail_4;
			}
		   else {
				result_text += DTResultFail_5;
			}
			result_text += "<br><a href='" + link + "'>" + DTResultFail_6 + "</a>.";
		}
		else {
			result_text = DTResultFail_7;
		   if (screen.pixelDepth == 2) {
				result_text += DTResultFail_8;
			}
		   else if (screen.pixelDepth == 4) {
				result_text += DTResultFail_9;
			}
		   else if (screen.pixelDepth == 8) {
				result_text +=  DTResultFail_10;
			}
			result_text += "<a href='" + link + "'>" + DTResultFail_11 + "</a>."; 
		}
	}
	else {
		pass = true;
		result_text = DTResultPass;
	}
	drawCheck(DTName, description, pass, result_text);
}

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) {
	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='../images/tech-check.gif' width=25 height=25 alt='" + DTPass + "' title='" + DTPass + "'>");
	}
	else {
		document.write("<img src='../images/tech-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 + "</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>');
}
