/*********************************************************************************************************
* Name       : systemDetection.js
*
* Department : IT DEV/MCDI/ELDI
*
* History    : 1.1 : initial version
*                    (Alex Peelman, 02.02.2006)
*			   1.8 : Message that must be shown when browser is not compatible moved from language page to here.
*					 (Alex Peelman, 12.04.2006)
*
* Purpose    : Determine information about the system such as the operating system, browser 
*			   and version, ...
*
* Functions : 
*
*		Operating Systems :
*
*		- isLinux() 	: Returns true if the OS is a Linux variant
*	    - isUnix()  	: Returns true if the OS is a Unix variant				
*       - isWindows()   : Returns true if the OS is a Windows variant different than NT or CE				
*		- isWindowsNT() : Returns true if the OS is a Windows NT variant (eg XP,2000, NT4.x)
*		- isWindowsCE() : Returns true if the OS is a Windows CE variant 
*       - isMac()		: Returns true if the OS is a Mac OS variant
*
*		Browsers :
*
*		- isOpera()		: Returns true if the Browser is an Opera variant		
*		- isSafari()	: Returns true if the Browser is a Safari variant		
*		- isKonquerer() : Returns true if the Browser is a Konquerer variant		
*		- isNetscape()  : Returns true if the Browser is a Netscape variant
*		- isMozilla()   : Returns true if the Browser is a Mozilla variant
*		- isInternetExplorer() : Returns true if the Browser is an IE variant
*       - isBrowserSupported() : Checks wether the combination of OS and Browser is supported to run DDN
*		- hasPopUpBlocker()    : Checks if the used browser blocks pop-ups
*
*		
*
*
* Variables :
*
*		- browser 		: Contains the browser's name
*       - versionNumber : Contains the browser's version number
*	    - windowWidth   : Contains the UI width
*	    - windowHeight  : Contains the UI height
*	    - colorDepth    : Contains the UI color depth
**********************************************************************************************************/

/////////////////////////////
// Definition of variables //
/////////////////////////////

var moz, moz_rv_sub, release_date='', moz_brow, moz_brow_nu='', moz_brow_nu_sub='', rv_full='',d 
var windowHeight, windowWidth, operatingSystem, versionNumber='',browser='';
n=navigator;
nav=n.appVersion;
nan=n.appName;
nua=n.userAgent;
var machineIdentifier;
var acrobat=new Object();
acrobat.installed=false;
acrobat.version='0.0';

/////////////////////////////////
// End definition of variables //
/////////////////////////////////


///////////////////////////
// Function declarations //
///////////////////////////

function initMachineIdentifier(_machineIdentifier) {
	machineIdentifier = _machineIdentifier;
}

function showMacCompatibleBrowsers() {
	document.write('<br /><a href="http://www.apple.com/support/downloads/safari.html" >Safari</a>');											
	document.write('<br /><a href="http://ftp.mozilla.org/pub/mozilla.org/mozilla/releases/mozilla1.2.1/mozilla-macos9-1.2.1-full.bin">Mozilla Suite</a>');
	document.write('<br /><a href="http://ftp.netscape.com/pub/netscape7/english/7.02/mac/macos8/sea/Netscape-mac-full.bin">Netscape</a>');
}
								
function showWindowsCompatibleBrowsers() {
	document.write('<br /><a href="http://www.windowsupdate.com">Internet Explorer</a>');	
	document.write('<br /><a href="http://www.mozilla.org/products/mozilla1.x/">Mozilla Suite</a>');
	document.write('<br /><a href="http://browser.netscape.com/ns8/download/default.jsp">Netscape</a>');								
}
								
function showCompatibleBrowsers() {
	document.write('<br /><a href="http://www.mozilla.com/firefox/">Firefox</a>');			
}
								
function showRemarkNl() {
	document.write('<br/><br />');
	document.write('Opmerking voor de Mac OS 8 / 9 gebruikers: Netscape 7 is de enige compatibele browser voor Dexia Direct Net.');
}
								
function showRemarkFr() {
	document.write('<br /><br />');
	document.write('Remarque pour les utilisateurs Mac OS 8 / 9: Netscape 7 est le seul navigateur compatible avec Dexia Direct Net.');
}

function showBrowserSupportNl() {
	if(!isBrowserSupported()) {
		if (isOpera()) {	
			document.write('<div style="width:100%;margin-left:0%;margin-right:0%;padding-bottom:0%" id="_window">');
			document.write('<div style=";background-color:#E3F1F1;border:1px solid #006699;" class="window">');
			document.write('Het is niet mogelijk om Dexia Direct Net met de Opera browser te gebruiken.');
			document.write('<br /><br />U kan gebruik maken van een <b>andere browser</b> om uw Dexia Direct Net op te starten:');
			document.write('<center>');
			showCompatibleBrowsers();
			if (isMac()) {
				showMacCompatibleBrowsers();
				document.write('</center>');
				showRemarkNl();
			} else {
				showWindowsCompatibleBrowsers();									
				document.write('</center>');
			}
			document.write('</div>');		
			document.write('</div>');
		} else if (isNetscape()) {
			if (versionNumber >= 6) {
				document.write('<div style="width:100%;margin-left:0%;margin-right:0%;padding-bottom:0%" id="_window">');
				document.write('<div style=";background-color:#E3F1F1;border:1px solid #006699;" class="window">');												
				document.write('U gebruikt een <b>verouderde versie van Netscape<\/b>. Dexia Direct Net vereist ');
				document.write('<b>minimum versie 7.0</b>. U kan Netscape en andere veiligheidupdates downloaden ');
				document.write('via de <a href="http://browser.netscape.com/ns8/download/default.jsp">site van Netscape</a>.');
				document.write('<br /><br />U kan gebruik maken van een <b>andere browser</b> om uw Dexia Direct Net op te starten:');
				document.write('<center>');
				showCompatibleBrowsers();
				if (isMac()) {
					showMacCompatibleBrowsers();
					document.write('</center>');
					showRemarkNl();
				} else {
					showWindowsCompatibleBrowsers();									
					document.write('</center>');
				} 
				document.write('</div>');
				document.write('</div>');		
			} else {
				var msg = 'U gebruikt een verouderde versie van Netscape. Dexia Direct Net vereist ';
				msg += 'minimum versie 7.0. U kan Netscape en andere veiligheidupdates downloaden ';
				msg += 'via de site van Netscape. ';
				msg += 'U kan gebruik maken van een andere browser om uw Dexia Direct Net op te starten.';
				alert(msg);
			}
		} else if (isInternetExplorer() && isMac()) {
			document.write('<br /><br /><br /><br />');
			document.write('<div style="position:relative;top:20%;background-color:#E3F1F1;border:1px solid #006699;" class="window">');
			document.write('Om Dexia Direct Net te gebruiken via Internet Explorer heeft u <b>minimum versie 6.0</b> ');
			document.write('nodig. Voor Mac OS gebruikers is deze versie echter <b>niet beschikbaar.</b> ');
			document.write('<br /><br />U kan gebruik maken van een <b>andere browser</b> om uw Dexia Direct Net op te starten:');
			document.write('<center>');
			showCompatibleBrowsers();
			showMacCompatibleBrowsers();
			document.write('</center>');
			showRemarkNl();
			document.write('</div>');		
		} else {
			document.write('<div style="width:100%;margin-left:0%;margin-right:0%;padding-bottom:0%" id="_window">');
			document.write('<div style=";background-color:#E3F1F1;border:1px solid #006699;" class="window">');
			document.write('U gebruikt een <b>verouderde versie van Internet Explorer</b>. Dexia Direct Net vereist ');
			document.write('<b>minimum versie 6.0</b>. U kan Internet Explorer en andere veiligheidupdates downloaden ');
			document.write('via de <a href="http://www.windowsupdate.com">site van Microsoft</a>.');
			document.write('<br /><br />U kan gebruik maken van een <b>andere browser</b> om uw Dexia Direct Net op te starten:');
			document.write('<center>');
			showWindowsCompatibleBrowsers();
			document.write('</center>');
			document.write('</div>');
			document.write('</div>');	
		}
	}
}

function showBrowserSupportFr() {
	if(!isBrowserSupported()) {
		if (isOpera()) {	
			document.write('<div style="width:100%;margin-left:0%;margin-right:0%;padding-bottom:0%" id="_window">');
			document.write('<div style=";background-color:#E3F1F1;border:1px solid #006699;" class="window">');
			document.write('Il n\'est pas possible d\'utiliser l\'application Dexia Direct Net à partir du browser Opera.');
			document.write('<br /><br />Vous pouvez utiliser un <b>autre navigateur</b> pour démarrer votre Dexia Direct Net: ');
			document.write('<center>');
			showCompatibleBrowsers();
			if (isMac()) {
				showMacCompatibleBrowsers();
				document.write('</center>');
				showRemarkFr();
			} else {
				showWindowsCompatibleBrowsers();									
				document.write('</center>');
			}
			document.write('</div>');		
			document.write('</div>');
		} else if (isNetscape()) {
			if (versionNumber >= 6) {
				document.write('<div style="width:100%;margin-left:0%;margin-right:0%;padding-bottom:0%" id="_window">');
				document.write('<div style=";background-color:#E3F1F1;border:1px solid #006699;" class="window">');												
				document.write('Vous utilisez une <b> vieille version de Netscape</b>. Dexia Direct Net requiert ');
				document.write('<b>au minimum la version 7.0</b>. Vous pouvez télécharger Netscape et d\'autres mises à jour de sécurité ');
				document.write('via le <a href="http://browser.netscape.com/ns8/download/default.jsp">site de Netscape</a>.');
				document.write('<br /><br />Vous pouvez utiliser un <b>autre navigateur</b> pour démarrer votre Dexia Direct Net: ');
				document.write('<center>');
				showCompatibleBrowsers();
				if (isMac()) {
					showMacCompatibleBrowsers();
					document.write('</center>');
					showRemarkFr();
				} else {
					showWindowsCompatibleBrowsers();		
					document.write('</center>');							
				} 
				document.write('</div>');
				document.write('</div>');		
			} else {
				var msg = 'Vous utilisez une vieille version de Netscape. Dexia Direct Net requiert ';
				msg += 'au minimum la version 7.0. Vous pouvez télécharger Netscape et d\'autres mises à jour de sécurité ';
				msg += 'via le site de Netscape. Vous pouvez utiliser un autre navigateur pour démarrer votre Dexia Direct Net.';
				alert(msg);
			}
		} else if (isInternetExplorer() && isMac()) {
			document.write('<br /><br /><br /><br />');
			document.write('<div style="position:relative;top:20%;background-color:#E3F1F1;border:1px solid #006699;" class="window">');
			document.write('Pour utiliser Dexia Direct Net via Internet Explorer vous avez besoin <b>au minimum de la version 6.0</b>. ');
			document.write('Cette version <b>n\'est pas disponible</b> pour les utilisateurs de Mac OS.</b>');
			document.write('<br /><br />Vous pouvez utiliser un <b>autre navigateur</b> pour démarrer votre Dexia Direct Net: ');
			document.write('<center>');
			showCompatibleBrowsers();
			showMacCompatibleBrowsers();
			document.write('</center>');
			showRemarkFr();
			document.write('</div>');		
		} else {
			document.write('<div style="width:100%;margin-left:0%;margin-right:0%;padding-bottom:0%" id="_window">');
			document.write('<div style=";background-color:#E3F1F1;border:1px solid #006699;" class="window">');
			document.write('Vous utilisez une <b>ancienne version d\'Internet Explorer</b>. Dexia Direct Net nécessite ');
			document.write('<b>au minimum la version 6.0</b>. Vous pouvez télécharger Internet Explorer et les ');
			document.write('mises à jour de sécurité à partir du <a href="http://www.windowsupdate.com">site de Microsoft</a>.');
			document.write('<br /><br />Vous pouvez utiliser un <b>autre navigateur</b> pour démarrer votre Dexia Direct Net:');
			document.write('<center>');
			showWindowsCompatibleBrowsers();
			document.write('</center>');
			document.write('</div>');
			document.write('</div>');	
		}
	}
}

function isLinux() {
	return nua.indexOf('Linux') != -1;
}

function isUnix() {
	return !isLinux() && (nua.indexOf('Unix') !=-1 || nua.indexOf('X11') != -1);
}

function isWindows() {
	return nua.indexOf('Win') != -1
}

function isWindowsNT() {
	return nua.indexOf('Windows') != -1 && nua.indexOf('NT') != -1;
}

function isWindowsCE() {
	return nua.indexOf('Windows CE') != -1;
}

function isMac() {
	var result = (nua.indexOf('Mac') != -1) || (n.platform.indexOf('Mac') != -1);
	return result;
}

function hasPopUpBlocker() {
	var	refWindow = window.open("", "_blank", "width=50,height=50,top=10,left=10,screenX=0,screenY=10,toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no,status=no",false);

	if (refWindow != null) {
		refWindow.close();
		return false;
	} else 	{
		return true;
	}
}

//functions that determine the browser
function isOpera() {
	return (nua.indexOf('Opera')!=-1);
}

// detect browser that not supports inserting of karakter in input-fields
function isInsertSupported() {
	return !(isKonquerer()); // Safari removed --> cursorpositioning in older versions Safari
}

function isSafari() {
	return (nua.indexOf('Safari')!=-1);
}

function isKonquerer() {
	return (!isSafari() && (nua.indexOf('Konqueror')!=-1) )
}

function isMozilla(){
	return (!isSafari() && !isKonquerer() && nua.indexOf('Gecko')!=-1 ); 
}

function isInternetExplorer(){
	return (nua.indexOf('MSIE')!=-1 && !isOpera() );
}

function isNetscape(){
	return (browser.indexOf('Netscape')!=-1); 
}

//see if the browser is supported for this type of system
function isBrowserSupported() {	

	if (isWindowsCE()) 	{
		if(isInternetExplorer() && parseFloat(versionNumber) < 4){
			return false;
		} else {
			return true;
		}
	} 
	
	if (isInternetExplorer() && parseFloat(versionNumber) < 6){
		return false;
	}
	
	if (isOpera()) {
		return false;
	}
	
	if (isNetscape() && parseFloat(versionNumber) < 7){
		return false;
	}
	
	return true;
}

function getPlatform()
{
	if (isLinux()) return "Linux";
	if (isUnix()) return "Unix";
	if (isWindows() || isWindowsNT() || isWindowsCE()) return "Windows";
	if (isMac()) return "Mac";
}

function getBrowser()
{
	if (isOpera()) return "Opera";
	if (isSafari()) return "Safari";
	if (isKonquerer()) return "Konquerer";
	if (isMozilla()) return "Mozilla";
	if (isInternetExplorer()) return "InternetExplorer";
	if (isNetscape()) return "Netscape";	
}

///////////////////////////////
// End Function declarations //
///////////////////////////////


//////////////////////////////////////////////////////
// What follows is the detection and definitions of //
// global variables which are used in Support.jspx  //
//////////////////////////////////////////////////////

if (isOpera()){
	str_pos=nua.indexOf('Opera');
	versionNumber=nua.substr((str_pos+6),4);
	browser = 'Opera';
}
else if (isSafari()){
	str_pos=nua.indexOf('Safari');
	versionNumber=nua.substr((str_pos+7),5);
	browser = 'Safari';
}
else if (isKonquerer()){
	str_pos=nua.indexOf('Konqueror');
	versionNumber=nua.substr((str_pos+10),3);
	browser = 'Konqueror';
}

// this part is complicated a bit, don't mess with it unless you understand regular expressions
// note, for most comparisons that are practical, compare the 3 digit rv nubmer, that is the output
// placed into 'versionNumber'.
else if (isMozilla()){
	
	pattern = /[(); \n]/;																						// regular expression pattern that will be used to extract main version/rv numbers	
	moz_types = new Array( 'Firebird', 																			// moz type array, add to this if you need to
						   'Phoenix', 
						   'Firefox', 
						   'Galeon', 
						   'K-Meleon', 
						   'Camino', 
						   'Epiphany',
						   'Netscape6', 
						   'Netscape', 
						   'MultiZilla', 
						   'Gecko Debian', 
						   'rv' );
						   
	rv_pos = nua.indexOf( 'rv' );// find 'rv' position in nua string
	rv_full = nua.substr( rv_pos + 3, 6 );// cut out maximum size it can be, eg: 1.8a2, 1.0.0 etc
	rv_slice = ( rv_full.search( pattern ) != -1 ) ? rv_full.search( pattern ) : '';			    			// search for occurance of any of characters in pattern, if found get position of that character
																												// otherwise slice out the part that you want if there is a slice position
	( rv_slice ) ? rv_full = rv_full.substr( 0, rv_slice ) : '';												// this is the working id number, 3 digits, you'd use this for 

	versionNumber = rv_full.substr( 0, 3 );																		// number comparison, like if versionNumber >= 1.3 do something
	for (i=0; i < moz_types.length; i++){	
		if ( nua.indexOf( moz_types[i]) !=-1 ){
			moz_brow = moz_types[i];
			break;
		}
	}
	if ( moz_brow ) { 																							// if it was found in the array
		str_pos=nua.indexOf(moz_brow);																			// extract string position
		moz_brow_nu = nua.substr( (str_pos + moz_brow.length + 1 ) ,3);											// slice out working number, 3 digit
		moz_brow_nu = ( isNaN( moz_brow_nu ) ) ? moz_brow_nu = versionNumber: moz_brow_nu;   					// if you got it, use it, else use versionNumber
		moz_brow_nu_sub = nua.substr( (str_pos + moz_brow.length + 1 ), 8);										// this makes sure that it's only the id number		
		sub_nu_slice = ( moz_brow_nu_sub.search( pattern ) != -1 ) ? moz_brow_nu_sub.search( pattern ) : '';
		( sub_nu_slice ) ? moz_brow_nu_sub = moz_brow_nu_sub.substr( 0, sub_nu_slice ) : '';                    //check to make sure there was a result, if not do  nothing
	}
	if ( moz_brow == 'Netscape6' ) {
		moz_brow = 'Netscape';
	}
	else if ( moz_brow == 'rv' || moz_brow == '' ) {															// default value if no other gecko name fit
		moz_brow = 'Mozilla';
	} 		
	if ( moz_brow_nu ) {																						// use rv number if nothing else is available
		versionNumber = moz_brow_nu;	
	}
	if (n.productSub) {
		release_date = n.productSub;
	}
	browser = moz_brow;
}

else if (isInternetExplorer()) {
	str_pos=nua.indexOf('MSIE');
	versionNumber=nua.substr((str_pos+5),3);
	browser = 'Microsoft Internet Explorer';
}

else {
	browser = nan;
}

if(!versionNumber) {
	versionNumber = nav.substring(0,1);
}

//determine operating system
if (isLinux()) {
	operatingSystem = "Linux";
} else if (isUnix()) {
	operatingSystem = "Unix";
} else if (isWindowsNT()) {		
	if (nua.indexOf("NT 5.0") != -1) 	{
		operatingSystem = "Windows 2000";
	} else if (nua.indexOf("NT 5.1") != -1)	{
		operatingSystem = "Windows XP"; 
	} else	{
		operatingSystem = "Windows NT";
	}	
} else if (isWindowsCE()) {
	operatingSystem = "Windows CE"
} else if (isWindows()) {
	if (nua.indexOf("95") != -1) {
		operatingSystem = "Windows 95";
	} else if (nua.indexOf("98") != -1)	{
		operatingSystem = "Windows 98";
	} else {
		operatingSystem = "Windows";
	}
} else if (isMac()) {	
	var os = "Mac OS"
	if (nua.indexOf('Mac OS') != -1) {
		os = nua.substr(nua.indexOf('Mac OS'),8);
	}
	operatingSystem = os;
} else {
	operatingSystem = "Unknown operating system"
}

windowWidth = screen.width;
windowHeight = screen.height;
colorDepth = screen.colorDepth;

//////////////////////
// End of detection //																			
//////////////////////

// Detection of acrobat reader plugin
function acrobatDetection() {
	if (navigator.platform == "Win 32" || navigator.platform == "Win32") {
		if (navigator.appName == "Microsoft Internet Explorer") {
			for (x=1; x<10; x++) {
				try {
					oAcro=eval("new ActiveXObject('AcroPDF.PDF."+x+"');");
					if (oAcro) {
						acrobat.installed=true;
						break;
					}
				}
				catch(e) {}
				}
			for (x=1; x<10; x++) {
				try {
					oAcro=eval("new ActiveXObject('PDF.PdfCtrl."+x+"');");
					if (oAcro) {
						acrobat.installed=true;
						break;
					}
				}
				catch(e) {}
			}
		} else {
			for (x=0; x<navigator.plugins.length; x++) {
				if (navigator.plugins[x].description.indexOf('Adobe PDF Plug-In For Firefox and Netscape') != -1) {
					acrobat.installed = true;
					break;
				}
			}
		}			
	} else if (navigator.platform.indexOf("MacPPC") != -1) {
		for (x=0; x<navigator.plugins.length; x++) {
			if (navigator.plugins[x].description.indexOf('Adobe Acrobat') != -1) {
				acrobat.installed = true;
				break;
			}
		}
	} 
}



