/*
* ------------------------------------------------------------------------------------------------
*
* This is an unpublished work, the copyright in which vests in Experian Limited. All rights 
* reserved.
*
* The information contained herein is confidential and the property of Experian Limited, and is 
* supplied without liability for errors or ommisions. No part may be reproduced, disclosed or 
* used except as authorised by contract or other written permission. The copyright and
* foregoing restrictions on reproduction and use extend to all media in which the information 
* may be embodied.
* ------------------------------------------------------------------------------------------------
* Title: Visualisation
*
* Filename: 	main.js
* File created:	11/03/09
*
* Description:	Implementation of the functions common to the animation, visualisation and exit
*               pages. 
*
* Written by:	Russell Ballaam, DPDG Documentation.
*
* Revision:	0.1
*
* Revision history:
*
* Revision 0.1 11/03/09
* ------------------------------------------------------------------------------------------------
*
* First release.
*/

// Define and instantiate global variables:
var bAnimmovie = false;												    // Whether the guide starts with a front-end animation movie (true) or static image (false).
var bClose = false;                                                     // Whether the visualisation should be closed when the message box is closed.
var bCustomsupport = true;				                                // Whether the guide supports custom profiles (true) or not (false).
var bDonechecks = false;												// Whether compatibilty checks have been completed (true) or not (false).
var bDonelocalisation = false;											// Whether localisation checks have been completed (true) or not (false).
var bExperianbrowser = false;	    									// Whether the guide is running in the Experian Browser (true) or not (false).
var bFlashinstalled = false;											// Whether Adobe/Macromedia Flash Player is installed (true) or not (false).
var bInternet = false;												    // Whether the visualisation is running on an Intranet/Internet (true) or behind a portable Web server (false).
var bLangsupport = false;                                               // Whether the visualisation supports multiple langauges.
var bMediasupport = false;												// Whether the guide contains any sound or video files (true) or not (false).
var bModalshown = false;                                                // Whether a modal dialog is currently displayed (true) or not (false).
var bScreenres = true;                                                  // Whether the user has the required screen resolution (true) or not (false)
var bSVGsupport = false;												// Whether SVG is supported (true) or not (false);
var bVis = false;                                                       // Whether the visualisation page is loaded (true) or not (false);
var bVMLsupport = false;												// Whether VML is installed (true) or not (false);
var bWindows = true;												    // Whether the user is using Windows (true) or not (false);
var iDefaultlang = 0;                                                   // The default language to be used on the system.
var iFlashversion = 0;													// The version of Flash Player that is installed.
var iLookupsupport = 0;												    // Whether the guide should display the postcode lookup, if available, (2 = yes, unlimited) (1 = yes, limited) or not (no, 0).
var iNumlang = 7;                                                       // The number of languages supported for the user interface.
var iPreferredlang = -1;                                                // The preferred language.
var objAjax = new Ajax();                                               // The Ajax object.
var objAnim;															// The object for the animation.
var objCustomstorage;								                    // A local storage object.
var objXMLdoc;												            // Working variable which holds each XML document before being processed.
var szBrowsername = "";													// The name of the user's browser.
var szDataversion = "Mosaic UK 2009";	                                // The version of data associated with the guide.
var szDocurl = document.URL;										    // Complete URL of this page.
var szDomain;														    // The 'domain' used for the visualisation console.
var szExitpage = "exit.htm";   										    // Name of the Exit page.
var szLocalxmldir = "../xml/localisation/";						        // Relative path to the XML directory that holds the localisation XML files for the guide.
var szMainfoldername = "mosaicuk"                                       // The main folder name for the project.
var szMainimgdir = "data/" + szMainfoldername + "/images/main/";		// Fragment of the path to the directory that holds the main image files.
var szPDFversion = "";													// The version of Adobe Acrobat PDF plug-in or ActiveX control installed on the user's PC. 
var szPortableserver = "http://127.0.0.1:8080/";					    // The 'domain' of the visualisation when it is running behind a portable Web server. 
var szProjectname = "Mosaic UK 2009"                                    // The name of the project.
var szSupport = "0";													// Adobe/Macromedia Flash Player, Adobe PDF, Microsoft Windows Media Player, VML/SVG support.
var szVisversion = "1.5";												// The overall version of the visualisation application.

// Define global arrays:
var szLanguagearr = new Array("EN", "FR", "ES", "DE", "NL", "ZH", "JA");// The languages.
var szLocalisationarr = new Array();                                    // The localisation array.

// Computate the domain and visualisation mode based on whether the domain for the portable Web server is contained
// within the current document URL:
if (szDocurl.indexOf(szPortableserver) == 0)
{
	szDomain = szPortableserver;
	bInternet = false;
}
else
{
	szDomain = szDocurl.substring(0, (szDocurl.lastIndexOf("/") - 4));
	bInternet = true;
}

// Prevent the content of the page from being selectable:
var Unselectable = {
 
	enable : function(e) 
	{
		var e = e ? e : window.event;
 
		if (e.button != 1) 
		{
			if (e.target) 
			{
				var targer = e.target;
			} else if (e.srcElement) 
			{
				var targer = e.srcElement;
			}
 			var targetTag = targer.tagName.toLowerCase();
			if ((targetTag != "input") && (targetTag != "textarea")) 
			{
				return false;
			}
		}
	},
 
	disable : function () 
	{
		return true;
	}
 
}
 
if (typeof(document.onselectstart) != "undefined") 
{
	document.onselectstart = Unselectable.enable;
} 
else 
{
	document.onmousedown = Unselectable.enable;
	document.onmouseup = Unselectable.disable;
}

/*
 * ------------------------------------------------------------------------------------------------
 * FUNCTION: calculateSupport
 * ------------------------------------------------------------------------------------------------
 * 
 * Calculates and sets the value of the 'szSupport' variable that is sent to szStartpage.
 *
 * Parameters:  None.
 *
 * Returns: None.
 * ------------------------------------------------------------------------------------------------
*/
function calculateSupport() 
{
	// Add the language:
	szSupport = iPreferredlang;
	
	// VML or SVG support:
	if (bVMLsupport)
	szSupport += "1";
	else if (bSVGsupport)
	szSupport += "0";
	
	// Screen resolution:
	if (bScreenres)
	szSupport += "1";
	else
	szSupport += "0";
	
	// Windows OS:
	if (bWindows)
	szSupport += "1";
	else
	szSupport += "0";
		
	// Macromedia (Adobe) Flash Player support:
	if (bFlashinstalled && iFlashversion >= 9)
	szSupport += "2";
	else if (bFlashinstalled && iFlashversion >= 6)
	szSupport += "1";
	else
	szSupport += "0";
		
	// Postcode lookup support:
	if (iLookupsupport == 2)
	szSupport += "2";
	else if (iLookupsupport == 1)
	szSupport += "1";
	else
	szSupport += "0";		
}

/*
 * ------------------------------------------------------------------------------------------------
 * FUNCTION: changeCSSrule
 * ------------------------------------------------------------------------------------------------
 * 
 * Changes the value of a specified CSS rule of a specified selector within a specified stylesheet.
 *
 * Parameters:  iCSSno = the number of the stylesheet in the stylesheet collection. Stylesheets are
 *                       numbered from 0 (the first one listed in the HTML document).
 *              szSelectortext = the name of the required selector as it appears in the stylesheet.
 *              szRule = the name of the required rule as it appears in the stylesheet.
 *              szNewvalue = the new value to be applied to the rule.
 *
 * Returns: None.
 * ------------------------------------------------------------------------------------------------
*/
function changeCSSrule(iCSSno, szSelectortext, szRule, szNewvalue) 
{
	var szCSSrulekw;  // The browser-specific keyword for CSS rules.
		
	if (document.all) 
	{
		szCSSrulekw = 'rules';
	}
	else if (document.getElementById) 
	{
		szCSSrulekw = 'cssRules';
	}
			
	for (var i = 0; i < document.styleSheets[iCSSno][szCSSrulekw].length; i++) 
	{				
		if (document.styleSheets[iCSSno][szCSSrulekw][i].selectorText.toLowerCase() == szSelectortext) 
		{
			document.styleSheets[iCSSno][szCSSrulekw][i].style[szRule] = szNewvalue;
		}
	}
	
}

/*
 * ------------------------------------------------------------------------------------------------
 * FUNCTION: checkCompatibility
 * ------------------------------------------------------------------------------------------------
 * 
 * Checks the compatibility of the user's browser.
 *
 * Parameters:  None.
 *
 * Returns: None.
 * ------------------------------------------------------------------------------------------------
*/
function checkCompatibility() 
{
	// Detect the name of the user's browser and check whether it can run the visualisation:  
	detectBrowser();
	
	// If using Microsoft Internet Explorer, check whether VML is installed and registered: 
	if (szBrowsername == "Internet Explorer 6+")
	checkVML();
	else	
	checkSVG();
	
	if ((szBrowsername != "Internet Explorer 6+") && (szBrowsername != "Firefox 3+") && bSVGsupport)
	alert(szLocalisationarr[3]);
	else if (!bVMLsupport && !bSVGsupport)
	{
	    alert(szLocalisationarr[4]);
	    bClose = true;
	}
	
	// Check the screen resolution:
	checkRes();
	
	// Check for Windows:
	checkWin();	
	
	// Check whether Macromedia (now Adobe) Flash Player is installed:
	if (bAnimmovie == true || bMediasupport == true || bCustomsupport)
	{
	      detectFlash();
	      checkFlash();
	}
	
	// Check whether the guide should display the postcode lookup (if available):
	checkLookup();
			
	// Calculate and store the value of the support variable:
	calculateSupport();
	
	// Flag that all compatibility checks have been completed:		
	bDonechecks = true;
	
	// Write an animation or static image into the page depending on
	// whether the Adobe Flash Player is supported on the user's browser:
	if(!bVis)
	{
	    if ((bFlashinstalled && iFlashversion >= 6) &&  bAnimmovie)
	    writeAnimationcontrol();
	    else
	    writeImage();
	}
}

/*
 * ------------------------------------------------------------------------------------------------
 * FUNCTION: checkFlash
 * ------------------------------------------------------------------------------------------------
 * 
 * Checks whether the Macromedia (now Adobe) Flash Player is installed.
 *
 * Parameters:  None.
 *
 * Returns: None.
 * ------------------------------------------------------------------------------------------------
*/
function checkFlash()
{
	// If the Flash Player version 9 or later is not installed, but version 6, 7 or 8 is installed:
	if (bFlashinstalled && iFlashversion < 9 && iFlashversion >= 6)
	{
		alert(szLocalisationarr[8]);		
		
	}
	// If the Flash Player is not installed or if the version is less than 6:
	else if (!bFlashinstalled || iFlashversion < 6)
	{
		alert(szLocalisationarr[6]);		
		
	}
	
}

/*
 * ------------------------------------------------------------------------------------------------
 * FUNCTION: checkLookup
 * ------------------------------------------------------------------------------------------------
 * 
 * Checks whether the guide should display the postcode lookup (if available) or not.
 *
 * Parameters:  None.
 *
 * Returns: None.
 * ------------------------------------------------------------------------------------------------
*/
function checkLookup() 
{
	var szLookupsupport = (location.search ? location.search.substring(1) : 1);
			
	// Strip off the hyphen if it exists:
	if (szLookupsupport.length >= 3)
	{   
        if(szLookupsupport.charAt(0) == "-")
        szLookupsupport = szLookupsupport.slice(1, szLookupsupport.length);
    }
    		
	if (szLookupsupport == "*0" || !bFlashinstalled || iFlashversion < 6)
	iLookupsupport = 0;
	else if (szLookupsupport == "*1")
	iLookupsupport = 2;
	else
	iLookupsupport = 1;	
}

/*
 * ------------------------------------------------------------------------------------------------
 * FUNCTION: checkRes
 * ------------------------------------------------------------------------------------------------
 * 
 * Checks whether the user has the required screen resolution.
 *
 * Parameters:  None.
 *
 * Returns: None.
 * ------------------------------------------------------------------------------------------------
*/
function checkRes()
{
    var viewportwidth;
    var viewportheight;
    
    if ((screen.width >= 1024) && (screen.height >= 768))
    { 
        if (typeof window.innerWidth != 'undefined')
        {
            viewportwidth = window.innerWidth,
            viewportheight = window.innerHeight
        }
        else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth !='undefined' && document.documentElement.clientWidth != 0)
        {
            viewportwidth = document.documentElement.clientWidth,
            viewportheight = document.documentElement.clientHeight
        }
        else
        {
            viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
            viewportheight = document.getElementsByTagName('body')[0].clientHeight
        }      
                
        if ((viewportwidth >= 1018) && (viewportheight >= 743))
        {
            bScreenres = true;
        }
        else
        bScreenres = false;
     }
             
     if (!bScreenres)
     {
        //$("#body").attr("scroll", "yes")
        //$("#body").css("overflow", "auto")
     }
          
}

/*
 * ------------------------------------------------------------------------------------------------
 * FUNCTION: checkSVG
 * ------------------------------------------------------------------------------------------------
 * 
 * Checks whether SVG is installed and exits if it isn't.
 *
 * Parameters:  None.
 *
 * Returns: None.
 * ------------------------------------------------------------------------------------------------
*/
function checkSVG()
{
	var szSVG
	
	if (navigator.mimeTypes != null && navigator.mimeTypes.length > 0) 
	{
        if (navigator.mimeTypes["image/svg+xml"] != null) 
        { 
            szSVG = "object"; 
        }
    }
    else if (window.ActiveXObject) 
    { 
        // Adobe plugin
        try 
        { 
            adobe = new ActiveXObject("Adobe.SVGCtl"); 
            szSVG = "embed"; 
        }
        catch (e) 
        { 
            szSVG = "MS Error"; 
        }
    }
    else szSVG = "none";
    
    if (szSVG == "none" || szSVG == "MS Error")
    {
        alert(szLocalisationarr[2]);
	    bClose = true;
	}
    else 
	bSVGsupport = true;	
}

/*
 * ------------------------------------------------------------------------------------------------
 * FUNCTION: checkVML
 * ------------------------------------------------------------------------------------------------
 * 
 * Checks whether VML is installed (Microsoft Internet Explorer only) and exits if it isn't.
 *
 * Parameters:  None.
 *
 * Returns: None.
 * ------------------------------------------------------------------------------------------------
*/
function checkVML()
{
	if (!bVMLsupport)
	{
		alert(szLocalisationarr[1]);
		bClose = true;		
	} 
}

/*
 * ------------------------------------------------------------------------------------------------
 * FUNCTION: checkWin
 * ------------------------------------------------------------------------------------------------
 * 
 * Checks whether the user is using Windows.
 *
 * Parameters:  None.
 *
 * Returns: None.
 * ------------------------------------------------------------------------------------------------
*/
function checkWin()
{
    if (navigator.appVersion.indexOf("Win") != -1) 
    bWindows = true;
    else
    bWindows = false;    
}

/*
 * ------------------------------------------------------------------------------------------------
 * FUNCTION: closeVisualisation
 * ------------------------------------------------------------------------------------------------
 * 
 * Closes the visualisation window if it is displayed in a new window, otherwise, it tries to go
 * back to the referring page, or close the main window.
 *
 * Parameters:  None.
 *
 * Returns: None.
 * ------------------------------------------------------------------------------------------------
*/
function closeVisualisation()
{
	if (bExperianbrowser == true)
	window.external.ExperianB_Close();	
	else if (opener && !opener.closed)
	window.self.close();		
	else if (history.length >= 1)
	history.back();
	else if(!bInternet)
	location.replace("http://127.0.0.1:8080/dwebpro/shutdown?file=%23%23DWEBPRO_DOCUMENTROOT%23%23%5Chtml%5Cshutdown.htm");
	else if (bInternet)
	window.self.close();	
}

/*
 * ------------------------------------------------------------------------------------------------
 * FUNCTION: detectBrowser
 * ------------------------------------------------------------------------------------------------
 * 
 * Detects the type and version of browser being used.
 *
 * Parameters:  None.
 *
 * Returns: None.
 * ------------------------------------------------------------------------------------------------
*/
function detectBrowser() 
{
 	var iVersionindex;		// The index of the version number in the 'navigator' object.
	var iVersion;			// The major version number of the browser.
			
	// Check for Firefox 3+:
	if(navigator.userAgent.indexOf("Firefox")!=-1)
	{
		iVersionindex = navigator.userAgent.indexOf("Firefox") + 8;
		
		if (parseInt(navigator.userAgent.charAt(iVersionindex)) >= 3)
		szBrowsername = "Firefox 3+";
	}
	// Check for Microsoft Internet Explorer 6+:
	else if (navigator.appVersion.indexOf("MSIE")!=-1)
	{
		var szTemp = navigator.appVersion.split("MSIE");
		iVersion = parseFloat(szTemp[1]);	
		
		// Check for non-Internet Explorer which will return 0:
	    if (iVersion >= 6) 
		szBrowsername = "Internet Explorer 6+";
	}
	// Check for Opera 8+:
	else if (navigator.userAgent.indexOf("Opera")!= -1)
	{
		iVersionindex = navigator.userAgent.indexOf("Opera") + 6;
		
		if (parseInt(navigator.userAgent.charAt(iVersionindex)) >= 8)
		szBrowsername = "Opera 8+";
	}
}

/*
 * ------------------------------------------------------------------------------------------------
 * FUNCTION: detectFlash
 * ------------------------------------------------------------------------------------------------
 * 
 * Detects whether the Macromedia (now Adobe) Flash Player or the plug-in/Active X control is  
 * installed and available on the user's PC.
 *
 * Parameters:  None.
 *
 * Returns: None.
 * ------------------------------------------------------------------------------------------------
*/
function detectFlash()
{
	var bMSdetect = false;		// Microsoft Internet Explorer is installed (true) or not (false).
		
	if (navigator.plugins && navigator.plugins.length > 0)
	{
		
		var type = 'application/x-shockwave-flash';
        var mimeTypes = navigator.mimeTypes;
        
        if(mimeTypes && mimeTypes[type] && mimeTypes[type].enabledPlugin && mimeTypes[type].enabledPlugin.description)
        {
                var version = mimeTypes[type].enabledPlugin.description;
                var descParts = version.split(/ +/);
                var majorMinor = descParts[2].split(/\./);
        
                iFlashversion = parseInt(majorMinor[0], 10);
                bFlashinstalled = true;
        }
		else
		bFlashinstalled = false;
		
		if (navigator.plugins["Shockwave Flash 2.0"])
		{
			bFlashinstalled = true;
			iFlashversion = 2;
		}
	}
	else if (navigator.mimeTypes && navigator.mimeTypes.length > 0)
	{
		x = navigator.mimeTypes['application/x-shockwave-flash'];
		
		if (x && x.enabledPlugin)
		bFlashinstalled = true;
		else
		bFlashinstalled = false;
	}
	else
	bMSdetect = true;

	if (bMSdetect == true)
	{
		for(var i = 10; i > 0; i--)
		{
			try
			{
				var flash = new ActiveXObject("ShockwaveFlash.ShockwaveFlash." + i);
				bFlashinstalled = true;
				iFlashversion = i;
				break;
			}
			catch(e)
			{
			}
		}
	}
	
}

/*
 * ------------------------------------------------------------------------------------------------
 * FUNCTION: getLang
 * ------------------------------------------------------------------------------------------------
 * 
 * Retrieves the value of the last language (if any) selected and saved by the user. If no language
 * has previously been saved, then an AJAX call is made to the server to get the user's preferred 
 * language settings for their browser (if any). 
 *
 * Parameters:  None.
 *
 * Returns: None.
 * ------------------------------------------------------------------------------------------------
*/
function getLang()
{
    var szRequest;					// The string used to request the language from the server page.
    var iStoredlanguage;            // The last saved language (if any).    
    
    
    // Get the stored language (if any):    
    iStoredlanguage = dojo.storage.get("language")    
     
    // If a language has been previously saved then save the setting    
    if (iStoredlanguage != null)
    {
        iPreferredlang = (iStoredlanguage)
        setLocalisation();
        return;
        
    }
    else
	{  
        // Create the request string:
	    szRequest = szDomain + "asp/getlang.asp";	    	
			
	    // Get the preferred langauges from the server:
	    objAjax.doGet(szRequest, langHandler);	    
	}		
}

/*
 * ------------------------------------------------------------------------------------------------
 * FUNCTION: hideMsgbox
 * ------------------------------------------------------------------------------------------------
 * 
 * Hides the message box.
 *
 * Parameters:	None. 
 *
 * Returns: None.
 * ------------------------------------------------------------------------------------------------
*/
function hideMsgbox() 
{
    if(bModalshown)
    {
        $("#modalscreen").css("display", "none");
        bModalshown = false; 
    }   
    
    $("#msgboxcontainer").fadeOut("slow");
    
    if (bClose)
    closeVisualisation();
}

/*
 * ------------------------------------------------------------------------------------------------
 * FUNCTION: langHandler
 * ------------------------------------------------------------------------------------------------
 * 
 * Processes the list of preferred lanagues from the user's browser (if any), selecting the 
 * highest one as the preferred language. If there are no preferred languages, then the user's
 * browser's language is selected (if used), their user language (if used) or the system (OS) 
 * language (if used). If none of these are available then the default language for the
 * visualisation is used.
 *
 * Parameters:  None.
 *
 * Returns: None.
 * ------------------------------------------------------------------------------------------------
*/
function langHandler(szLang)
{
	var lang = szLang.toUpperCase();
	var iIndex = 1;		
	
	for (var i = 0; i < szLanguagearr.length; i++)
	{
	    if (lang.indexOf(szLanguagearr[i]) != -1)
	    {
	        if (lang.indexOf(szLanguagearr[i]) < iIndex)
	        {        
	            iIndex = lang.indexOf(szLanguagearr[i])
	            iPreferredlang = i;
	        }
	    }
	}			
	if (iPreferredlang == -1)
	{
	    if (typeof navigator.browserLanguage != "undefined")
        lang = navigator.browserLanguage.toUpperCase();
        else if (typeof navigator.userLanguage != "undefined")
        lang = navigator.userLanguage.toUpperCase();
        else if (typeof navigator.language != "undefined")
        lang = navigator.language.toUpperCase();
        else if (typeof navigator.systemLanguage != "undefined")
        lang = navigator.systemLanguage.toUpperCase();
        else
        lang = szLanguagearr[iDefaultlang];
                    
        for (var i = 0; i < szLanguagearr.length; i++)
	    {
	        if (lang && indexOf(szLanguagearr[i]) == 0)
	        {
	            iPreferredlang = i;
	            break;
	        }
	    }   
	}	
	setLocalisation();	   
}

/*
 * ------------------------------------------------------------------------------------------------
 * FUNCTION: loadXMLfile
 * ------------------------------------------------------------------------------------------------
 * 
 * Loads a selected XML file and calls a function to load it into a selected array.
 *
 * Parameters:  szFilename = the name of the XML file to load.
 *				objArrayname = the name of the array into which the data must be loaded.
 *				iParams = the number of parameters within the file.
 *				funObject = the name of the construction funstion used to create the objects loaded
 *							into the array.												
 *
 * Returns: None.
 * ------------------------------------------------------------------------------------------------
*/
function loadXMLfile(szFilename, objArrayname, iParams, funObject)
{
    // Get the XML file using AJAX:
    $.ajax({
    async: false,
    url: szFilename,
    dataType: ($.browser.msie) ? "text" : "xml",
    success: function(data)
    {
        if (typeof data == "string") 
        {
            objXMLdoc = new ActiveXObject("Microsoft.XMLDOM");
            objXMLdoc.async = false;
            objXMLdoc.loadXML(data);
        } 
        else 
        {
            objXMLdoc = data;
        }
     
        if (bVis)
        {
            // If the array is szProfilegrouparr:
	        if (objArrayname == szProfileprimaryarr)
	        loadProfiledata();
	 
	        //If the array is szChartnamearr:
	        else if (objArrayname == szChartnamearr)
	        loadChartobject();
	
            // Process the file:
            else
            processXMLdata(objArrayname, iParams, funObject);
        }
        else
        processXMLdata(objArrayname, iParams, funObject);
      }
    });  
 } 
  
 /*
 * ------------------------------------------------------------------------------------------------
 * FUNCTION: positionBox
 * ------------------------------------------------------------------------------------------------
 * 
 * Positions the dialog or message box, before it is displayed.
 *
 * Parameters:	szID = the ID of the message box or dialog box to display.
 *              iLeft = the left position of the dialog or message box.
 *				iTop = the top position of the dialog or message box. 
 *
 * Returns: None.
 * ------------------------------------------------------------------------------------------------
*/
function positionBox(szID, iLeft, iTop) 
{
    var viewportwidth;
    var viewportheight;    
    
    var zsTemp;
    szTemp = $("#" + szID).css("width");
    var iWidth = parseInt(szTemp.substring(0, szTemp.length));
    szTemp = $("#" + szID).css("height");
    var iHeight = parseInt(szTemp.substring(0, szTemp.length));    	
	 
    if (typeof window.innerWidth != 'undefined')
    {
      viewportwidth = window.innerWidth,
      viewportheight = window.innerHeight
    }
    else if (typeof document.documentElement != 'undefined' && typeof document.documentElement.clientWidth !='undefined' && document.documentElement.clientWidth != 0)
    {
       viewportwidth = document.documentElement.clientWidth,
       viewportheight = document.documentElement.clientHeight
    }
    else
    {
       viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
       viewportheight = document.getElementsByTagName('body')[0].clientHeight
    }
    
    if (iLeft == -1) 
    iLeft = Math.round((viewportwidth - iWidth) / 2);
	if (iTop == -1) 
	iTop = Math.round((viewportheight - iHeight) / 2);
	
	$("#" + szID).css("left", iLeft + "px");
	$("#" + szID).css("top", iTop + "px");	
 }
 
 /*
 * ------------------------------------------------------------------------------------------------
 * FUNCTION: processXMLdata
 * ------------------------------------------------------------------------------------------------
 * 
 * Processes the XML file or string currently loaded into 'objXMLdoc' variable.
 *
 * Parameters:  objArrayname = the name of the array into which the data must be loaded.
 *				iParams = the number of parameters within the file.
 *				funObject = the name of the construction funstion used to create the objects loaded
 *							into the array.												
 *
 * Returns: None.
 * ------------------------------------------------------------------------------------------------
*/
function processXMLdata(objArrayname, iParams, funObject)
{ 
	var p1 = objXMLdoc.getElementsByTagName('p1');
	var p2 = objXMLdoc.getElementsByTagName('p2');
	var p3 = objXMLdoc.getElementsByTagName('p3');
	var p4 = objXMLdoc.getElementsByTagName('p4');
	var p5 = objXMLdoc.getElementsByTagName('p5');
	
	switch(iParams)
	{	
		case 1:
		for (i = 0; i < p1.length; i++)
    	{
       		objArrayname[objArrayname.length] = p1[i].childNodes[0].nodeValue;   	  		
       	}
		break;
	
		case 2:
		for (i = 0; i < p1.length; i++)
    	{
       		objArrayname[objArrayname.length] = new funObject(p1[i].childNodes[0].nodeValue, p2[i].childNodes[0].nodeValue);
		}
		break;
			
		case 3:
		for (i = 0; i < p1.length; i++)
    	{
       		if (bVis)
            {
       		    // If the Topic titles array:		
			    if (objArrayname ==	objToptitlesarr)
			    {
				    
				    if (parseInt(p1[i].childNodes[0].nodeValue) > iHighestcat)
				    iHighestcat = parseInt(p1[i].childNodes[0].nodeValue);
				    
				    if (parseInt(p2[i].childNodes[0].nodeValue) > iHighesttop)
				    iHighesttop = parseInt(p2[i].childNodes[0].nodeValue);
			    }
			 				
			objArrayname[objArrayname.length] = new funObject(p1[i].childNodes[0].nodeValue, p2[i].childNodes[0].nodeValue, p3[i].childNodes[0].nodeValue);
			}
			else
			objArrayname[objArrayname.length] = new funObject(p1[i].childNodes[0].nodeValue, p2[i].childNodes[0].nodeValue, p3[i].childNodes[0].nodeValue);
			
		}
		break;
			
		case 4:
		for (i = 0; i < p1.length; i++)
    	{
       		objArrayname[objArrayname.length] = new funObject(p1[i].childNodes[0].nodeValue, p2[i].childNodes[0].nodeValue, p3[i].childNodes[0].nodeValue, p4[i].childNodes[0].nodeValue);
		}
		break;
			
		case 5:
		for (i = 0; i < p1.length; i++)
    	{
       		if(bVis)
       		{
       		    // If the Profiles titles array:		
			    if (objArrayname ==	objProftitlesarr)
			    {
				    if (parseInt(p3[i].childNodes[0].nodeValue) > iHighestprof)
				    iHighestprof = parseInt(p3[i].childNodes[0].nodeValue);
			    }
								
			    objArrayname[objArrayname.length] = new funObject(p1[i].childNodes[0].nodeValue, p2[i].childNodes[0].nodeValue, p3[i].childNodes[0].nodeValue, p4[i].childNodes[0].nodeValue, p5[i].childNodes[0].nodeValue);
            }
            else
            objArrayname[objArrayname.length] = new funObject(p1[i].childNodes[0].nodeValue, p2[i].childNodes[0].nodeValue, p3[i].childNodes[0].nodeValue, p4[i].childNodes[0].nodeValue, p5[i].childNodes[0].nodeValue);
		
		}
		break;
	}	 
}

/*
 *------------------------------------------------------------------------------
 * FUNCTION: setLocalisation
 *------------------------------------------------------------------------------
 * 
 * Sets the localisation directorories for the currently selected language.
 *
 * Parameters: 	None.
 *
 * Returns: 	None.
 *
 *------------------------------------------------------------------------------
*/ 
function setLocalisation()
{      
    if (!bVis)
    {
        if (bLangsupport)
        {
            if (iPreferredlang != -1)
            szLocalxmldir += szLanguagearr[iPreferredlang].toLowerCase() + "/";
            else if (iPreferredlang == -1)        
            alert("A preferred language could not be acquired from your computer, so the default language will be used.");
	    }
        else
        szLocalxmldir += szLanguagearr[iDefaultlang].toLowerCase() + "/";
                  
        loadXMLfile(szLocalxmldir + "animation.xml", szLocalisationarr, 1); 
        //window.document.title = szLocalisationarr[0];
    }
            
    checkCompatibility();         
}

/*
 * ------------------------------------------------------------------------------------------------
 * FUNCTION: showModalscreen
 * ------------------------------------------------------------------------------------------------
 * 
 * Displays the modal screen behind the message or dialog box.
 *
 * Parameters:	None. 
 *
 * Returns: None.
 * ------------------------------------------------------------------------------------------------
*/
function showModalscreen() 
{
    var iWidth;
    var iHeight;
    
    if (document.documentElement && (document.documentElement.clientWidth > 0)) 
    iWidth = document.documentElement.clientWidth;
	else if (window.innerWidth) 
	iWidth = window.innerWidth;
	else 
	iWidth = document.body.clientWidth;
	
	if (window.innerHeight)
	iHeight = window.innerHeight;
	else if (document.documentElement && (document.documentElement.clientHeight > 0)) 
	iHeight = document.documentElement.clientHeight;
	else 
	iHeight = document.body.clientHeight;
    
    $("#modalscreen").css("width", iWidth);
    $("#modalscreen").css("height", iHeight);    
        
    $("#modalscreen").css("display", "block");
    bModalshown = true;    
}

/*
 * ------------------------------------------------------------------------------------------------
 * FUNCTION: showMsgbox
 * ------------------------------------------------------------------------------------------------
 * 
 * Displays the message box.
 *
 * Parameters:	szTitle = the title for the message box.
 *              szContent = the content for the message box.
 *              iLeft = -1 (for centred) or integer for left pixel position.
 *              iTop = -1 (for centred) or integer for top pixel position.
 *              iWidth = width in pixels.
 *              iHeight = height in pixels.
 *				bModal = whether a modal message box (true) or modeless (false) should be displayed.
 *              bPlain = whether the Close and OK buttons should be displayed (true) or not (false). 
 *
 * Returns: None.
 * ------------------------------------------------------------------------------------------------
*/
function showMsgbox(szTitle, szContent, iLeft, iTop, iWidth, iHeight, bModal, bPlain) 
{
    var iHght;
    
    $("#msgboxcaption").html(szTitle);
    $("#msgtxt").html(szContent);
    
    $("#msgboxcontainer").css("width", iWidth);
    $("#msgboxcontainer").css("height", iHeight);
    $("#msgboxtitle").css("width", iWidth - 2);
    $("#msgboxtitle").css("height", 20);
    $("#msgboxcontent").css("width", iWidth - 2);
    $("#msgboxcontent").css("height", iHeight - 52);
    
    // Calculate the height from the content:
    $("#msgboxcontainer").css("display", "block");
    $("#msgboxcontainer").css("visibility", "hidden");
    iHght = $("#msgboxcontent").attr("scrollHeight")
    $("#msgboxcontainer").css("display", "none");
    $("#msgboxcontainer").css("visibility", "visible");
    
    // Reset the height:
    $("#msgboxcontent").css("height", iHght);
    $("#msgboxcontainer").css("height", iHght + 54);
        
    if (bPlain)
    {
        //$("#msgboxbutton").css("top", iHeight - 30);
        $("#msgboxbutton").css("top", iHght + 22);
        $("#msgboxbutton").css("width", iWidth - 2);
        $("#msgboxbutton").css("height", 30);
        $("#msgboxbutton").css("display", "block");
        $("#msgbutton1").css("display", "block");
        $("#msgboxcloseimg").css("display", "block");
        $("#msgboxtitle").css("cursor", "move");
                
    }
    else
    {
        $("#msgboxbutton").css("display", "none");
        $("#msgbutton1").css("display", "none");
        $("#msgboxcloseimg").css("display", "none"); 
        $("#msgboxtitle").css("cursor", "default");   
    }
    
    if (iLeft == -1)    
    positionBox("msgboxcontainer", iLeft, iTop);
    else
    positionBox("msgboxcontainer", iLeft, iTop - (iHght + 64));
    
    if(bModal)
    showModalscreen();   
    
    $("#msgboxcontainer").fadeIn("slow"); 
        
    if (bPlain)     
    Drag.init(document.getElementById("msgboxtitle"), document.getElementById("msgboxcontainer"), 0, null, 0);    
    
}
