﻿// JScript File
var reader;
var check;
var contentClass = "health-content-hidden";
var swfversion;
var acrobat=new Object();
var shockVersion;

function CheckSpecifications()
{
    //To detect flash version
    swfversion = deconcept.SWFObjectUtil.getPlayerVersion();

    //To detect screen resolution

    if ((screen.width >= 1024) && ( screen.height>= 768))
    {
        check = 1;
    }
    else
    {        
        check = 0;
    }

    //To detect acrobat reader
    // Set some base values
    acrobat.installed=false;
    acrobat.version='0.0';

    if (navigator.plugins && navigator.plugins.length)
    {
	    for (x=0; x<navigator.plugins.length; x++)
	    {
		    if (navigator.plugins[x].description.indexOf('Adobe Acrobat') != -1 || navigator.plugins[x].description.indexOf('Adobe PDF') != -1)
		    {
			    /*acrobat.version=parseFloat(navigator.plugins[x].description.split('Version ')[1]);

			    if (acrobat.version.toString().length == 1) acrobat.version+='.0';*/
			    acrobat.installed=true;
			    
			    break;
		    }
	    }
    }
    else if (window.ActiveXObject)
    {
	    for (x=2; x<10; x++)
	    {
		    try
		    {
			    oAcro=eval("new ActiveXObject('PDF.PdfCtrl."+x+"');");
			    if (oAcro)
			    {
				    acrobat.installed=true;
				    acrobat.version=x+'.0';
			    }
		    }
		    catch(e) {}
	    }
	    try
	    {
		    oAcro4=new ActiveXObject('PDF.PdfCtrl.1');
		    if (oAcro4)
		    {
			    acrobat.installed=true;
			    acrobat.version='4.0';
		    }
	    }
	    catch(e) {}
	    
	    try
        {
            oAcro7=new ActiveXObject('AcroPDF.PDF');
            if (oAcro7)
            {
                acrobat.installed=true;
                acrobat.version='7.0';
                reader = acrobat.version;
            }
        }
        catch(e) {}
    }

    acrobat.ver4=(acrobat.installed && parseInt(acrobat.version) >= 4) ? true:false;
    acrobat.ver5=(acrobat.installed && parseInt(acrobat.version) >= 5) ? true:false;
    acrobat.ver6=(acrobat.installed && parseInt(acrobat.version) >= 6) ? true:false;
    acrobat.ver7=(acrobat.installed && parseInt(acrobat.version) >= 7) ? true:false;
    acrobat.ver8=(acrobat.installed && parseInt(acrobat.version) >= 8) ? true:false;
    acrobat.ver9=(acrobat.installed && parseInt(acrobat.version) >= 9) ? true:false; 

    // To check Shockwave player installed version
    var swObj = new SWObject(null,'d',0,0,0,0);
    
    shockVersion = swObj.getPlayerVersion();
    
    ShowContent();
    BindHeaderText();
    JavascriptEnabled();
    HasFlashPlayer();
    HasShockwavePlayer();
    CheckResolution();
    CheckReader();
}

function ShowContent()
{    
    var maindiv = document.getElementById('health-content-left');
    if(maindiv.className == contentClass)
    {
        maindiv.className = "health-content-visible";
    }
}

//To fill the <div> tags
function BindHeaderText()
{   
    if((swfversion['major'] >= 9) && parseInt(shockVersion) >= 8 && (check == 1) && (acrobat.installed))
    {
        document.getElementById('headercontent').innerHTML = "Great! Your computer has passed its health check.This means it meets the technical requirements of the site. "+
        "<br> <br> <i>"+"You can now"+'<a href="Login/Register.aspx" id=\"lnkRegister\"> register for a free trial </a>'+"or "+'<a href="Login/Default.aspx" id=\"lnkLogin\"> login</a> '+" to get instant access "+"<br>" +" to the wealth of high quality online educational resources available."+"</i>" ; 
        document.getElementById('img').className = "happy-face";
//        BindPopUp("lnkRegister");
//        BindPopUp("lnkLogin");
    }
   else if(((swfversion['major'] >= 9))&&((check != 1) ||(acrobat.installed == false) || (parseInt(shockVersion) < 8) ))
   {
         document.getElementById('headercontent').innerHTML = "Your computer has passed the critical technical requirements for the site."+
        "This means that whilst the site will work on this machine, we do recommend that you address the items listed as requiring attention."+
        "<br /><br />"+"Review the details below and click on the links to fix the problems. Then please run the heath check again. Alternatively, call our Technical HelpDesk on"+'<b>' + " 01666 843 224" +  '</b>'+" or email" +'<a href="mailto:support@sherston.co.uk"> support@sherston.co.uk </a>'+" and we will be happy to help.";
        
        document.getElementById('img').className = "happy-face";    
    }
    else if((swfversion['major'] < 9))
    {      
        document.getElementById('headercontent').innerHTML=" We’re afraid your computer has failed its health check. This means it doesn’t meet the technical requirements of the site."+
        "<br /><br />"+"Review the details below and click on the links to fix the problems. Then please run the heath check again. Alternatively, call our Technical HelpDesk on"+'<b>' + " 01666 843 224" +  '</b>'+" or email" +'<a href="mailto:support@sherston.co.uk"> support@sherston.co.uk </a>'+" and we will be happy to help.";
    }  
}


function HasFlashPlayer()
{
    if(swfversion['major'] >= 9)
    {
         document.getElementById('flash').innerHTML = "<b>"+"Flash player version 9.0 or newer is installed"+"</b>"+"<br /><i>"+"Flash Player 9 or newer is needed to run the site’s content correctly."+"</i>";
         document.getElementById('flash-player').className = "enabled";
    } 
    else if((swfversion['major'] < 9) && (swfversion['major'] != 0))
    {
         document.getElementById('flash').innerHTML ="<b><i>"+ "Flash Player version 9.0 or newer is not installed."+"</b><br/>"+" It appears that your browser is using version " + swfversion['major'] + "<br>"+
         "The website needs Flash Player 9 or newer to run the content correctly."+"</i><br>"+'<a href="TechnicalCheck/InstallFlash.aspx" target="_blank">Help me install Flash Player 9.0</a>';
         document.getElementById('flash-player').className = "disabled";  
    } 
    else if(swfversion['major'] == 0) 
    {
        document.getElementById('flash').innerHTML = "<b>"+"Flash player is not installed."+"</b>"+"<br /><i>"+ "The website needs Flash Player 9 or newer to run the content correctly. It appears that this is not installed on your system."+"</i><br />"+'<a href="TechnicalCheck/InstallFlash.aspx" target="_blank">Help me install Flash Player 9.0</a>';
        document.getElementById('flash-player').className = "disabled";
    }
}

function HasShockwavePlayer()
{
    if(parseInt(shockVersion) >= 8)
    {
        document.getElementById('swResult').innerHTML = "<b>Shockwave player is installed</b><br /><i>Shockwave Player is needed for the Rain Forest Music program only</i>";
        document.getElementById('shockwave').className = "enabled";
    }
    else
    {
        document.getElementById('swResult').innerHTML = "<b>Shockwave player is not installed</b><br /><i>Shockwave Player is needed for the Rain Forest Music program only. It appears that you do not have the correct version installed on your system.</i><br/><a href='http://www.adobe.com/shockwave/download/' target='_blank'>Help me install Shockwave Player</a>";
        document.getElementById('shockwave').className = "disabled";
    }
}

function CheckResolution()
{    
    if( check == 1)
    {
        document.getElementById('screen').innerHTML = "<b>"+"Screen resolution is at least 1024x768"+"</b>"+"<br /><i>"+"This site has been designed to run at a screen resolution of 1024x768."+"</i>";
        document.getElementById('screen-res').className = "enabled"; 
    } 
    else if(check == 0) 
    {
        document.getElementById('screen').innerHTML = "<b>"+"Your screen resolution is not set to atleast 1024x768"+"</b>"+"<br />"+"It appears to be currently set at " +'['+screen.width+']x['+screen.height+']'+  "<br /><i>"+ 
        '<a href="TechnicalCheck/ScreenResolution.aspx" target="_blank">Show me how to change my screen resolution</a>';
        
        document.getElementById('screen-res').className = "disabled";          
    }
}

function CheckReader()
{   
    if(acrobat.installed)
    {
       document.getElementById('reader').innerHTML = "<b>"+"An up-to-date version of Adobe Reader is installed"+"</b>"+"<br /><i>"+"The latest version of Adobe Reader enables you to download printable resources."+"</i>";
       document.getElementById('reader-version').className = "enabled";
    }
    else
    {
        document.getElementById('reader').innerHTML = "<b>"+"An up to date version of Adobe Reader is not installed"+"</b>"+"<br /><i>"+"The latest version of Adobe Reader enables you to download printable resources. If you have another pdf reader installed, or if you are using an Apple Mac, then you will still be able to access the printable resources."+"</i>"
        +"<br />"+'<a href="http://www.adobe.com/products/acrobat/readstep2.html" target="_blank">Help me install Adobe Reader</a>';
        document.getElementById('reader-version').className = "disabled";
    }
}

function JavascriptEnabled()
{
    document.getElementById('jscript').innerHTML = "<b>"+"JavaScript is enabled"+"</b>"+"<br /><i>"+"This is a requirement for this site."+"</i>";
    document.getElementById('java').className = "enabled";
}

function HideContent()
{      
    if(document.getElementById('health-content-left').className = "health-content-visible")
    {
        //show all elements which're currently hidden
        document.getElementById('health-content-left').className = "health-content-hidden";
    }
}  
