var g_axResourcesXml;
var strUserLocale;

function loadResources()
{
	g_axResourcesXml = new ActiveXObject("Msxml2.DOMDocument.3.0");
	g_axResourcesXml.async = false;
	g_axResourcesXml.resolveExternals = false;

	if (ChooseLocalMode == 0)
	{
		g_axResourcesXml.load(getResourceFileName());
	}
	else
	{
		g_axResourcesXml.load(LocalPicked + "\\resources.xml");

		strUserLocale = LocalPicked;
	}
}

function getResourceFileName()
{
	var strRetVal = undefined;
	var axFso = new ActiveXObject("Scripting.FileSystemObject");
	var UserLocale = navigator.userLanguage.toLowerCase();
	var strDefaultLocale = getDefaultLocaleFromConfig();
	var arrFileNames = new Array(4);

	arrFileNames[0] = UserLocale + "\\resources.xml";
	arrFileNames[1] = UserLocale.substring(0,2) + "\\resources.xml";
	arrFileNames[2] = strDefaultLocale + "\\resources.xml";
	arrFileNames[3] = strDefaultLocale.substring(0,2) + "\\resources.xml";

	for(var i=0; i<arrFileNames.length; i++)
	{
		if(axFso.FileExists(arrFileNames[i]))
		{
			strRetVal = arrFileNames[i];
			break;
		}
	}

	strUserLocale = strRetVal.replace("\\resources.xml", "");

	switch(UserLocale)
	{
		case "fil-ph":
			strUserLocale = "fil";
			strRetVal = "fil\\resources.xml";
			break;

		case "nb-no":
		case "nn-no":
			strUserLocale = "no";
			strRetVal = "no\\resources.xml";
			break;

		case "zh-hk":
		case "zh-tw":
		case "zh-cht":
			strUserLocale = "cht";
			strRetVal = "cht\\resources.xml";
			break;

		case "zh-mo":
		case "zh-cn":
		case "zh-sg":
		case "zh-chs":
			strUserLocale = "chs";
			strRetVal = "chs\\resources.xml";
			break;
	}

	return strRetVal;
}

function getDefaultLocaleFromConfig()
{
	var axConfigurationXml;
	axConfigurationXml = new ActiveXObject("Msxml2.DOMDocument.3.0");
	axConfigurationXml.async = false;
	axConfigurationXml.resolveExternals = false;
	axConfigurationXml.load("ota.config");
	var objNode = axConfigurationXml.selectSingleNode("/configuration/localization/defaultLocale/@code");
	return objNode ? objNode.text : undefined;
}

function getChooseLocalModeFromConfig()
{
	var axConfigurationXml;
	axConfigurationXml = new ActiveXObject("Msxml2.DOMDocument.3.0");
	axConfigurationXml.async = false;
	axConfigurationXml.resolveExternals = false;
	axConfigurationXml.load("ota.config");
	var objNode = axConfigurationXml.selectSingleNode("/configuration/programMode/mode[@name = \"ChooseLocal\"]/@value");
	return objNode ? objNode.text : undefined;
}

function applyResources()
{
    var objResourceElements = document.all.tags("js:resource");
	for(var i=objResourceElements.length - 1; i>=0; i--)
	{
		var outerHTML = getResource(objResourceElements.item(i).getAttribute("name"));
		objResourceElements.item(i).outerHTML = outerHTML;
	}
}
function getResource(_name)
{
	var strXPath = "/resources/data[@name = \"" + _name + "\"]/value";
	var objNode = g_axResourcesXml.selectSingleNode(strXPath);
	return objNode ? objNode.text : undefined;
}

function changeTitle()
{
    var strXPath = "/resources/data[@name = \"MainTitle\"]/value";
	var objNode = g_axResourcesXml.selectSingleNode(strXPath);

	if (objNode)
	{
	    document.title = objNode.text;
	}
	else
	{
	    document.title = "Activation Assistant for the 2007 Microsoft Office suites";
	}
}