var assets = 'images/';
var ie = document.all;
var agt = navigator.userAgent.toLowerCase();
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);
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_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_ie6up = (is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_5);
var browserName = navigator.appName;
var browserVersion = "0.0";
var supportedWidth = 1024;
var supportedHeight = 768;

setBrowserVersion('7.0');
setBrowserVersion('7.1');
setBrowserVersion('6.0');
setBrowserVersion('6.2');
setBrowserVersion('4.7');
setBrowserVersion('4.9');


function setBrowserVersion(ver)
    {
    if(agt.indexOf(ver) != -1)
        browserVersion = ver;
    }

function generateLine(iconId, html)
    {
    icon = '';
    bold = false;

    switch(iconId)
        {
        case 1:
            icon = 'tick.gif';
            bold = false;
            break;

        case 2:
            icon = 'cross.gif';
            bold = true;
            break;

        case 3:
            icon = 'question.gif';
            bold = true;
            break;
        }
/*
    output = '<tr><td valign="top"><img src="' + assets + icon + '" width=16 height=16>&nbsp;</td><td>';
    output += (bold) ? '<b>' + html + '</b>' : html ;
    output += '</td></tr>';
    */
    output = '<div style="margin-left:15px" class="clsNormal"><img src="' + assets + icon + '" width=16 height=16>&nbsp;';
    output += (bold) ? '<b>' + html + '</b>' : html ;
    output += '</div>';

    document.write(output);
    }

function checkFlashPlugin()
    {
    if(hasRightVersion)
        generateLine(1, 'Latest Flash Player Installed.');
    else
        if(actualVersion == 0)
                generateLine(2, 'You do not have the latest Flash player. Click <a href="http://www.macromedia.com/go/getflashplayer/" target="_blank">here</a> to download and install it.');
        else
            generateLine(2, 'You do not have the latest Flash player; you have version ' + actualVersion + '. It is recommended you click <a href="http://www.macromedia.com/go/getflashplayer/" target="_blank">here</a> to download and install the latest version.');
    }

function checkScreenResolution()
    {
    var height = screen.height;
    var width = screen.width;

    if(width >= supportedWidth && height >= supportedHeight)
        generateLine(1, 'Your screen resolution is ' + width + ' x ' + height + '. The Minimum supported resolution is ' + supportedWidth + ' x ' + supportedHeight +'.');
    else
        generateLine(2, 'Your screen resolution is ' + width + ' x ' + height + '. The Minimum supported resolution is ' + supportedWidth + ' x ' + supportedHeight +'. Click <a href="Support.aspx?showheader=1">here</a> to find out how to fix this.');
    }

function checkBrowserVersion()
    {
    if(browserName == "Microsoft Internet Explorer")
        {/*
        if(browserName == "Netscape")
            {
            if(browserVersion < 6.2)
                generateLine(2, 'You must upgrade your browser. Preferred versions of Netscape are 6.2 and 7. Click <a href="http://www.netscape.com/download/" target="_blank">here</a> to download a newer version of Netscape, but we recommend you use Internet Explorer.');
            else
                {
                generateLine(1, 'Your browser is ' + browserName + '. This is one of the recommended browsers.');
                generateLine(1, 'Your browser version is HTML 4.0 compatible.');
                }
            }
        else
            {*/
            if(is_ie6up)
                {
                generateLine(1, 'Your browser is ' + browserName + '. This is a supported browser.');
                generateLine(1, 'Your browser version is HTML 4.0 compatible.');
                }
            else
                generateLine(2, 'Your browser is not HTML 4.0 compatible. You must upgrade your browser to use the NCALT courses. Click <a href="http://www.microsoft.com/windows/ie/" target="_blank">here</a> to download and install Internet Explorer.');
            }
       /* }*/
    else
        generateLine(2, 'Your browser is '+ browserName + '. This is not a supported browser. Click <a href="http://www.microsoft.com/windows/ie/" target="_blank">here</a> to download and install Internet Explorer.');
    }

function checkCookies()
    {
    var cookieName = 'testCookie' + Math.round(Math.random() * 1000);
    document.cookie = cookieName + '=cookieValue';
    var cookiesEnabled = (document.cookie.indexOf(cookieName) != -1);

    if(cookiesEnabled)
        generateLine(1, 'Cookies are enabled on your browser.');
    else
        {
        if(browserName == "Netscape")
            {
            if((browserVersion >= 4.7 && browserVersion <= 4.9) || browserVersion >= 6.2)
                generateLine(2, 'Cookies are not enabled on your browser. Click <a href="Support.aspx?showheader=1" target="_blank">here</a> to find out more.');
            else
                generateLine(3, 'Unable to detect if Cookies are enabled on your browser. Click <a href="Support.aspx?showheader=1" target="_blank">here</a> to find out more.');
            }
        if(browserName == "Microsoft Internet Explorer")
            {
            if(is_ie6up || is_ie5up)
                generateLine(2, 'Cookies are not enabled on your browser. Click <a href="Support.aspx?showheader=1" target="_blank">here</a> to find out more.');
            else
                generateLine(2, 'Unable to detect if Cookies are enabled on your browser. Click <a href="Support.aspx?showheader=1" target="_blank">here</a> to find out more.');
            }
        }
    }

function checkJavaPlugin()    
    {    
    var javaOK = (navigator.javaEnabled());    
   
    if(javaOK) {
        generateLine(1, 'Java is enabled on your browser.');
    }
    else {    
        if(browserName == "Netscape")    
            {    
            if((browserVersion >= 4.7 && browserVersion <= 4.9) || browserVersion >= 6.2)    
                generateLine(2, 'Java is not enabled on your browser. Click <a href="http://java.sun.com/getjava/" target="_blank">here</a> to download and install Java.');    
            else    
                generateLine(3, 'Unable to detect if Java is enabled on your browser. Click <a href="http://java.sun.com/getjava/" target="_blank">here</a> to download and install Java.');    
            }    
   
        if(browserName == "Microsoft Internet Explorer")    
            {    
            if(is_ie5up || is_ie6up)    
                generateLine(2, 'Java is not enabled on your browser. Click <a href="http://java.sun.com/getjava/" target="_blank">here</a> to download and install Java.');    
            else    
                generateLine(3, 'Unable to detect if Java is enabled on your browser. Click <a href="http://java.sun.com/getjava/" target="_blank">here</a> to download and install Java.');    
            }    
        }    
    }  
    
function detectCompatibility()
    {	
    
	/* Check Java */
	if (!navigator.javaEnabled()){return false;}

	/* Check cookies */
	 var cookieName = 'testCookie' + Math.round(Math.random() * 1000);
    document.cookie = cookieName + '=cookieValue';
    var cookiesEnabled = (document.cookie.indexOf(cookieName) != -1);
    if (!cookiesEnabled){return false;}

	/*Check Browsers version*/
	if (!is_ie6up){return false;}


	/*Check resolution*/	
	var height = screen.height;
    var width = screen.width;    
    if(width < supportedWidth || height < supportedHeight){return false;}

	/*Check Flash verison*/
	if (!hasRightVersion){return false;}

	return true;
}

function detectCompatibilityAndShowReults(){

checkFlashPlugin();
checkScreenResolution();
checkBrowserVersion();
checkCookies();
checkJavaPlugin();


}