var g_cShowTitle = "";

var g_cDisplayItem = "NULL";
var g_cShowLoginLink = "technicaltest_v2.asp";
var g_cAPILL = "NULL";

var g_cSystemCheckHelpText = " ";

var iFlashVersionRequired = 7;
var PopupBlockerTestReturnValue = 'DefaultValue';
var PopupBlockerTestTimerHandle;
var PopupBlockerTestTimerTimeoutValue = 5000;
var flash2Installed = false; // boolean. true if flash 2 is installed
var flash3Installed = false; // boolean. true if flash 3 is installed
var flash4Installed = false; // boolean. true if flash 4 is installed
var flash5Installed = false; // boolean. true if flash 5 is installed
var flash6Installed = false; // boolean. true if flash 6 is installed
var flash7Installed = false; // boolean. true if flash 7 is installed
var flash8Installed = false; // boolean. true if flash 8 is installed
var flash9Installed = false; // boolean. true if flash 9 is installed
var flash10Installed = false; // boolean. true if flash 10 is installed
var maxVersion = 10; // highest version we can actually detect

var g_cImgCheck = "check.gif";
var g_cImgInfo = "info.gif";
var g_cImgFail = "fail.gif";

var g_iIssueCount = 0;

function window_onload() {
if (g_cSystemCheckHelpText == "NULL")
 g_cSystemCheckHelpText = " ";
g_cSystemCheckHelpText = escape(g_cSystemCheckHelpText);

document.getElementById("JavascriptEnabledResultImg").style.display = "none";
document.getElementById("JavascriptEnabledLearnMoreDiv").innerHTML = "&nbsp;";

if ("6" != "NULL" && "8".substr(0,2) != "::") 
 iFlashVersionRequired = parseInt("7");

if (iFlashVersionRequired == null || isNaN(iFlashVersionRequired))
 iFlashVersionRequired = 7;

if (g_cAPILL != "" && g_cAPILL != "NULL")
 g_cShowLoginLink = g_cAPILL;

 
RunSystemCheckOnClickFunction();
}






function ClearResults()
{
 document.getElementById("IE55LearnMoreDiv").innerHTML = '&nbsp';
 document.getElementById("IE55ResultDiv").innerHTML = '&nbsp';

 document.getElementById("AcceptCookiesLearnMoreDiv").innerHTML = '&nbsp';
 document.getElementById("AcceptCookiesResultDiv").innerHTML = '&nbsp';
 document.getElementById("FlashPlugInLearnMoreDiv").innerHTML = '&nbsp';
 document.getElementById("FlashPlugInResultDiv").innerHTML = '&nbsp';
 // document.getElementById("AcrobatPlugInLearnMoreDiv").innerHTML = '&nbsp';
 //document.getElementById("AcrobatPlugInResultDiv").innerHTML = '&nbsp';
}


function RunSystemCheckOnClickFunction() {
g_iIssueCount = 0;
ClearResults();

;

if ("NULL" == "1") // if running from "in-show", don't show login link
 document.getElementById("ShowLoginLink").style.display = "none";

document.getElementById("CheckFailedErrorMsg").innerHTML = "";
document.getElementById("CheckFailedErrorMsg").style.display = "none";
document.getElementById("ContinueToShowLink").style.display = "none";
//document.forms[0].elements["RunSystemCheck"].value = "Verificar o Sistema...";
//document.forms[0].elements["RunSystemCheck"].disabled = true;

document.getElementById("JavascriptEnabledResultImg").style.display = "";
document.getElementById("JavascriptEnabledResultImg").src = g_cImgCheck;
document.getElementById("JavascriptEnabledLearnMoreDiv").innerHTML = '&nbsp';

SetBrowserAndOSTypeFields(document.forms[0], 'BrowserHiddenInput', 'OSHiddenInput');

var ua = window.navigator.userAgent;
var iBogusBrowserVariant;

iBogusBrowserVariant = 0;
if (ua.indexOf("MSN 2.5") >= 0)
 iBogusBrowserVariant = 1;

if (ua.indexOf("MSN 2.6") >= 0)
 iBogusBrowserVariant = 2;

if (ua.indexOf("AOL 6.0") >= 0)
 iBogusBrowserVariant = 3;

if (ua.indexOf("AOL 7.0") >= 0)
 iBogusBrowserVariant = 4;

if (ua.indexOf("AOL 8.0") >= 0)
 iBogusBrowserVariant = 5;

if (ua.indexOf("AOL 8.0") >= 0)
 iBogusBrowserVariant = 6;

if (ua.indexOf("AOL 9.0") >= 0)
 iBogusBrowserVariant = 7;

if (ua.indexOf("MSN 6") >= 0)
 iBogusBrowserVariant = 8;

/*
if (ua.indexOf("Gecko") >= 0)
 iBogusBrowserVariant = 9;

if (ua.indexOf("Firefox") >= 0)
 iBogusBrowserVariant = 10;
*/

if (ua.indexOf("Google") >= 0) // google toolbar issues
 iBogusBrowserVariant = 11;


var iBrowserType = document.forms[0].elements["BrowserHiddenInput"].value*1;
//iBrowserType =8;
//alert(iBrowserType);
//alert(iBogusBrowserVariant);



//if ((iBrowserType >= 3) && (iBrowserType < 10) && (iBogusBrowserVariant == 0))
if (((iBrowserType == 3) || (iBrowserType == 4)) && (iBogusBrowserVariant == 0))
 {
 document.getElementById("IE55LearnMoreDiv").innerHTML = '&nbsp';
 document.getElementById("IE55ResultDiv").innerHTML = '<img src="' + g_cImgCheck + '">';

 CheckFlashVersion();
 
CheckAcrobatVersion()

 var CookieName = "BrowserCheck";
 var DomainName = document.location.hostname;

 var ExpirationDate = new Date();
 ExpirationDate.setFullYear(ExpirationDate.getFullYear()+1);
 DeleteCookieFunction(CookieName);

 document.cookie = CookieName + "=test; expires=" + ExpirationDate.toGMTString();

 var DocumentCookieValue = document.cookie || "";
 var CookieValue = '';
 var CookieFoundFlag = 0;
 var index1 = DocumentCookieValue.indexOf(CookieName);
 var index2 = DocumentCookieValue.indexOf(';',index1);
 if (index1 != -1)
 {
 CookieFoundFlag = 1;
 if (index2 == -1)
 index2 = DocumentCookieValue.length;

 CookieValue = unescape(DocumentCookieValue.substring(index1 + DocumentCookieValue.length + 1,index2));
 }

 DeleteCookieFunction(CookieName);

 if (CookieFoundFlag == 1)
 {
 document.getElementById("AcceptCookiesLearnMoreDiv").innerHTML = '&nbsp';
 document.getElementById("AcceptCookiesResultDiv").innerHTML = '<img src="' + g_cImgCheck + '">';
 }
 else
 {
 document.getElementById("AcceptCookiesLearnMoreDiv").innerHTML = '<a href="SystemCheck_Cookie.htm" target="_blank"><img alt="Clique para mais informação" src="' + g_cImgInfo + '" border="0"></a>';
 document.getElementById("AcceptCookiesResultDiv").innerHTML = '<img src="' + g_cImgFail + '">';
 g_iIssueCount++;
 }

 }
else
 {
 document.getElementById("IE55LearnMoreDiv").innerHTML = '<a href="SystemCheck_InternetExplorer.htm" target="_blank"><img alt="Clique para mais informação" src="' + g_cImgInfo + '" border="0"></a>';
 document.getElementById("IE55ResultDiv").innerHTML = '<img src="' + g_cImgFail + '">';
 g_iIssueCount++;

 // display results here...
 DisplayResults();

 }
}


function DisplayResults() {
if (g_iIssueCount > 0)
 {
 
 var cMsg = "<br><br>" + (g_iIssueCount > 1 ? "Foram " : "Foi ") + "detectado" + (g_iIssueCount > 1 ? "s" : "") + g_iIssueCount + " erro" + (g_iIssueCount > 1 ? "s" : "") + " que não permite" + (g_iIssueCount > 1 ? "m" : "") + " efectuar o curso.";
 cMsg += "<BR>A não resolução " + (g_iIssueCount > 1 ? "destes problemas " : "deste problema ") + "pode resultar em que certas funcionalidades do curso não funcionem correctamente.";
 cMsg += "<BR><BR>Para evitar, clique no botão Ajuda para informação de como resolver o problema.<BR>";
 document.getElementById("CheckFailedErrorMsg").innerHTML = cMsg;
 document.getElementById("CheckFailedErrorMsg").style.display = "";
 //document.forms[0].elements["RunSystemCheck"].value = "Correr Verificação Sistema";
 //document.forms[0].elements["RunSystemCheck"].disabled = false;
 if ("NULL" == "NULL" || "NULL" == "0")
 {
 document.getElementById("ShowLoginLink").style.display = "none";
 document.getElementById("CloseWindowInstructions").style.display = "";
 }
 else
 {
 document.getElementById("ShowLoginLink").href = g_cShowLoginLink;
 document.getElementById("ContinueToShowLink").style.display = "";
 }
 }

if (g_iIssueCount == 0)
 {
 // the user has passed the check or ignored the issues,
 // send them to the login page
 //document.forms[0].elements["RunSystemCheck"].style.display = "none";
 //document.getElementById("ContinueToShowLink").style.display = "";

 // If there is no ShowKey, hide the "Continue to show" link
 if ("NULL" == "NULL" || "NULL" == "0")
 {
 document.getElementById("ShowLoginLink").style.display = "none";
 document.getElementById("CloseWindowInstructions").style.display = "";
 }
 else
 {
 // set the href of the link just in case they need to click to move on
 document.getElementById("ShowLoginLink").href = g_cShowLoginLink;
 // redirect the user
 location.href = g_cShowLoginLink;
 }
 }
}


function DeleteCookieFunction(name) {
var oldDate = new Date(1970, 1, 1);
document.cookie = name + "=0; expires=" + oldDate.toGMTString();
}


function CheckFlashVersion() {
var iActualVersion = 0;

if (window.navigator.userAgent.indexOf("MSIE") < 0)
 {
 var plugin = window.navigator.mimeTypes["application/x-shockwave-flash"];
 if (plugin)
 {
 plugin = plugin.enabledPlugin;
 if (plugin)
 {
 var aVersionArray = plugin.description.match(/[\d.]+/g);
 iActualVersion = aVersionArray[0];
 } 
 }
 }
else
 {
 // Loop through all versions we're checking, and
 // set iActualVersion to highest detected version.
 for (var i = 2; i <= maxVersion; i++)
 {
 if (eval("flash" + i + "Installed") == true)
 iActualVersion = i;
 }
 }
 
 if (iActualVersion >= iFlashVersionRequired)
 {
 document.getElementById("FlashPlugInResultDiv").innerHTML = '<img src="' + g_cImgCheck + '">';
 }
else
 {
 document.getElementById("FlashPlugInLearnMoreDiv").innerHTML = '<a href="SystemCheck_FlashPlugIn.htm" target="_blank"><img alt="Clique para mais informação" src="' + g_cImgInfo + '" border="0">' + iActualVersion + '/' + iFlashVersionRequired + '</a>';
 document.getElementById("FlashPlugInResultDiv").innerHTML = '<img src="' + g_cImgFail + '">';
 g_iIssueCount++;
 }
}

function CheckAcrobatVersion() {

//Script type required to validate 
var displayString; 
g_iIssueCount = 0;

var acrobat=new Object(); 

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) 
{ 
acrobat.version=parseFloat(navigator.plugins[x].description.split('Version ')[1]); 

if (acrobat.version.toString().length == 1) acrobat.version+='.0'; 

acrobat.installed=true; 

displayString = 'Acrobat Version11: '+acrobat.version; 
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'; 
displayString = 'Acrobat Version: '+acrobat.version; 

} 
} 
catch(e) {} 
} 

try 
{ 
oAcro4=new ActiveXObject('PDF.PdfCtrl.1'); 
if (oAcro4) 
{ 
acrobat.installed=true; 
acrobat.version='4.0'; 
displayString = 'Acrobat Version: '+acrobat.version; 

} 
} 
catch(e) {} 

try 
{ 
oAcro7=new ActiveXObject('AcroPDF.PDF.1'); 
if (oAcro7) 
{ 
acrobat.installed=true; 
acrobat.version='7.0'; 
displayString = 'Acrobat Version: '+acrobat.version; 

} 
} 
catch(e) {} 

} 


//if (! displayString) { displayString = 'Acrobat Installed: Information Not Available'; } 
//alert(displayString); 

if (displayString)
 {
 document.getElementById("AcrobatPlugInResultDiv").innerHTML = '<img src="' + g_cImgCheck + '">';
 }
else
 {
 document.getElementById("AcrobatPlugInLearnMoreDiv").innerHTML = '<a href="SystemCheck_AcrobatPlugIn.htm" target="_blank"><img alt="Clique para mais informação" src="' + g_cImgInfo + '" border="0"></a>';
 document.getElementById("AcrobatPlugInResultDiv").innerHTML = '<img src="' + g_cImgFail + '">';

 }


 }