<!--
//***********************************************************************************************
//* Configure the Portfolio Manager Application.
//***********************************************************************************************

// The URL of the Portfolio Manager web site on this server (the D&B Wrapper)
//var str_SiteRoot = 'http://localhost/PortfolioManagerDev';	// Developers Machine
//var str_SiteRoot = 'http://test.PortfolioManager.dnb.com';	// Test Site
var str_SiteRoot = 'http://www.PortfolioManager.dnb.com';	// Live Site

// D&B style sheet for Portfolio Manager
var str_PM_App_StyleSheetID = 2		

// Display Debug (0=No, 1=Yes)
var bln_Debug = 0


// GR 07/05/2008 What code set to run
var str_PM_Code_VersionNumber;

// GR 07/05/2008 Whether we display the version number on the initial home page
var m_bDisplayVerInHomepageBanner = true;

// GR 07/05/2008 Logic to decide what code version and display version to use
var m_bUpdateDisplayVersion = false;
/*
if ((GetCookieValue('PortfolioManager','Country') == 'UK') || 
	(GetCookieValue('PortfolioManager','Country') == 'BE') ||
	(GetCookieValue('PortfolioManager','Country') == 'NL') ||
	(GetCookieValue('PortfolioManager','Country') == 'NO') ||
	(GetCookieValue('PortfolioManager','Country') == 'PT') ||
	(GetCookieValue('PortfolioManager','Country') == 'OTHERS'))
{	m_bUpdateDisplayVersion = true;
}
*/
var m_URLCountry = getCountry();
if ((m_URLCountry  == 'UK') || 
	(m_URLCountry == 'BE') ||
	(m_URLCountry == 'DK') ||
	(m_URLCountry == 'NL') ||
	(m_URLCountry == 'NO') ||
	(m_URLCountry == 'PT') ||
	(m_URLCountry == 'IT') ||
	(m_URLCountry == 'ES') ||
	(m_URLCountry == 'DE') ||
	(m_URLCountry == 'SE') ||
	(m_URLCountry == 'FR') ||
	(m_URLCountry == 'CH') ||	// GR 02/04/2009 make switzerland display as V4
	(m_URLCountry == 'OTHERS'))
{	m_bUpdateDisplayVersion = true;
}

if ((m_bUpdateDisplayVersion == true) && (str_PM_App_VirtualDir == 'RMS')) 
{	str_PM_VersionNumber = '4.0';
	str_PM_Code_VersionNumber = '4.1';
} 
else if (str_PM_App_VirtualDir == 'RMS') 
{	str_PM_VersionNumber = '3.3';
	str_PM_Code_VersionNumber = '4.1';
}
else //SPM
{	
	// GR 17/04/2009 Display version 2 for SPM in the banner for the following countries:
	if ((m_URLCountry != 'DE') && (m_URLCountry != 'FR')) {
		str_PM_VersionNumber = '2.0';
	} else {
		str_PM_VersionNumber = '1.1';
	}
	
	// Code version now always V4 for SPM
	str_PM_Code_VersionNumber = '4.1';

}

if (bln_Debug) {
	alert('str_PM_VersionNumber = ' + str_PM_VersionNumber);
	alert('str_PM_Code_VersionNumber = ' + str_PM_Code_VersionNumber);
}

// GR 03/07/2008 Work out the country from the URL
function getCountry()
{
	var sURL = window.location.href;
	var iStartPos = sURL.indexOf(".com");
	if (iStartPos == -1) {return "";}
	iStartPos += 4;
	var iSlashCount = 0;
	
	while (iSlashCount !=2)
	{
		if (sURL.substring(iStartPos, (iStartPos + 1)) == "/") {iSlashCount += 1;}
		iStartPos += 1;
	}
	var sCountryCode = sURL.substring(iStartPos, (iStartPos + 2));
	return sCountryCode.toUpperCase();
}

// GR 24/04/2009 Work out the site (i.e. RMS or SPM) from the URL
function getSite()
{
	var sURL = window.location.href;
	var iStartPos = sURL.indexOf(".com");
	if (iStartPos == -1) {return "";}
	iStartPos += 4;
	var iSlashCount = 0;
	
	while (iSlashCount !=1)
	{
		if (sURL.substring(iStartPos, (iStartPos + 1)) == "/") {iSlashCount += 1;}
		iStartPos += 1;
	}
	var sSite = sURL.substring(iStartPos, (iStartPos + 3));
	return sSite.toUpperCase();
}

//***********************************************************************************************
//* This function appends Portfolio Manager version details to the page title.
//* Called from PM_Banner.html
//* GR 17/04/2009 Also reloads with correct cookie language for URL country if necessary
//***********************************************************************************************
function setVersion() {

	// GR 17/04/2009 Where no country is present in the cookie (e.g. first visit), or the cookie country
	// does not match up with the country URL, reload and set cookie country so it does match up.
	// GR 24/04/2009 This also applies if the cookie site (i.e. RMS or SPM) does not match the URL site.
	var sCountry = getCountry();
	var sSite = getSite();
	if ((GetCookieValue('PortfolioManager','Country') != sCountry) || (GetCookieValue('PortfolioManager','Site') != sSite))
	{	// Cookie country or site does not match URL country or site
		// Build URL based on RMS/SPM and specify country code to set in cookie.
		var sURL = str_SiteRoot + '/' + str_PM_App_VirtualDir + '/default.asp?Country=' + sCountry;
		parent.location.replace(sURL);
		return;
	}

	// RMS or SMS
	document.all['PageTitle'].innerHTML = str_PM_App_Name;

	// Get version number
	version = getVersion();
	
	// GR 07/05/2008 Only display version in homepage if flag set
	if (!m_bDisplayVerInHomepageBanner) {
		if ((parent.frames.length == 3) && 
			(parent.frames[2].location.href.indexOf('PM_About.html') > -1)) {
			version = '';
		}
	}
	
	if (version.length > 0) {
		document.all['PageTitle'].innerHTML += ' v' + version;
	}

}
//***********************************************************************************************
//* This function sets the source of the PM frame to the PM application. 
//* Called from PM_Splash.html
//***********************************************************************************************
function setPMClientApp(strCulture) {
	// Set the link to the version of the PM Application required
	version = getVersion();
	var src = str_PM_App_URL + '/V' + str_PM_Code_VersionNumber + '/Logon/Logon.aspx';

	// Append the AppID parameter to define What we trying to access (PM or PMADMIN)
	src += '?AppID=' + str_PM_App_ID;	

	// Append the StyleSheet parameter to configure the look and feel of PM
	src += '&StyleSheetID=' + str_PM_App_StyleSheetID;

	// Append the cutlure parameter so that PM is displayed in the correct language
	src += '&Culture=' + strCulture;

	// Append the return parameter so that home/logout in PM return to the correct location
	src += '&Return=' + str_SiteRoot + '/' + str_PM_App_VirtualDir;

	// Update the source for the frame
	//parent.frames.PMApp.location.href = src;
	location.replace(src);
}
//***********************************************************************************************
//* This function takes the two letter country code from a pull down list.
//* It then passes the Country picked to the default page that handles site redirection.
//* Called from PM_Menu.html
//***********************************************************************************************
function countryPage(selector) {
  var s = str_SiteRoot + '/' + str_PM_App_VirtualDir + '/Default.asp?Country=' + selector.options[selector.selectedIndex].value;
  if (s) { parent.location = s  }
}
//***********************************************************************************************
//* This function populates the available countries in the pull down list.
//* Called from PM_Menu.html
//***********************************************************************************************
function countryPagePopDropDown(selector, ActiveCountry) {

	//alert("ActiveCountry=" + ActiveCountry);

        // Create an array to hold all countries to display in the drop down.
	var Country_Array = new Array();
	
	// Populate with all valid countries in all valid languages
	// Code, English, Italian, German, French, Spanish
	Country_Array[0] = new Array( "UK",	"United Kingdom",	"Gran Bretagna",	"Vereinigtes Königreich",	"Royaume-Uni",	"Reino Unido",	"Storbritannien",   "Reino Unido",	"zzz zzz zzz zzz zzz zzz zzz zzz zzz zzz Verenigd Koninkrijk"	);
	Country_Array[1] = new Array( "IT", "Italy",			"Italia",			"Italien",					"Italie",		"Italia",		"Italien",          "Itália",		"zzz zzz zzz zzz zzz Italie"				);
	Country_Array[2] = new Array( "DE", "Germany",			"Germania",			"Deutschland",				"Allemagne",	"Alemania",		"Tyskland",         "Alemanha",		"zzz zzz zzz Duitsland"				);
	Country_Array[3] = new Array( "BE", "Belgium",			"Belgio",			"Belgien",					"Belgique",		"Bélgica",		"Belgien",          "Bélgica",		"Belgie"				);
	Country_Array[4] = new Array( "CA", "Canada",			"Canada",			"Kanada",					"Canada",		"Canada",		"Kanada",           "Canada",		"zzz Canada"				);
	Country_Array[5] = new Array( "DK", "Denmark",			"Danimarca",		"Dänemark",					"Danemark",		"Dinamarca",	"Danmark",          "Dinamarca",	"zzz zzz Denemarken"			);
	Country_Array[6] = new Array( "ES", "Spain",			"Spagna",			"Spanien",					"Espagne",		"Espana",		"Spanien",          "Espanha",		"zzz zzz zzz zzz zzz zzz zzz zzz zzz Spanje"				);
	Country_Array[7] = new Array( "FR", "France", 			"Francia", 			"Frankreich",				"France",		"Francia",		"Frankrike",        "Franca",		"zzz zzz zzz zzz Frankrijk"				);
	Country_Array[8] = new Array( "NO", "Norway", 			"Norvegia", 		"Norwegen",					"Norvege",		"Noruega",		"Norge",            "Noruega",		"zzz zzz zzz zzz zzz zzz zzz Noorwegen"				);
	Country_Array[9] = new Array( "NL", "Netherlands", 		"Olanda", 			"Niederlande",				"Pays Bas",		"Países Bajos",	"Nederländerna",    "Holanda",		"zzz zzz zzz zzz zzz zzz Nederland"				);
	Country_Array[10] = new Array("PT", "Portugal", 		"Portogallo", 		"Portugal",					"Portugal",		"Portugal",		"Portugal",         "Portugal",		"zzz zzz zzz zzz zzz zzz zzz zzz Portugal"				);
	Country_Array[11] = new Array("SE", "Sweden", 			"Svezia", 			"Schweden",					"Suede",		"Suecia",		"Sverige",          "Suécia",		"zzz zzz zzz zzz zzz zzz zzz zzz zzz zzz zzz Zweden"				);
	Country_Array[12] = new Array("CH", "Switzerland", 		"Svizzera", 		"Schweiz",					"Suisse",		"Suiza",		"Schweiz",          "Suíça",		"zzz zzz zzz zzz zzz zzz zzz zzz zzz zzz zzz zzz Zwitserland"			);
	
	Country_Array[13] = new Array("OTHERS", 	"zzz Other Countries",	"zzz Altri Paesi",	"zzz Andere Länder",	"zzz Autres Pays",	"zzz Other Countries",	"Övriga länder", "Outros Países", "zzz zzz zzz zzz zzz zzz zzz zzz zzz zzz zzz zzz zzz Andere landen");

	if (ActiveCountry == "") 
	{	// Get which country this is from the URL
		var URL = parent.location + ""
		var LastIndex = URL.lastIndexOf("/", URL.length - 2);
		ActiveCountry = URL.substr(LastIndex + 1).replace("/","");	
		ActiveCountry = ActiveCountry.toUpperCase();
		//alert("URL=" + parent.location + ", LastIndex=" + LastIndex +  ", ActiveCountry=" + ActiveCountry);
	}


	// Identify the language we are displaying in
	var LanguageID;
	switch (ActiveCountry) {
		case "UK" :
			// English
			LanguageID = 1;
			break;
   		case "IT" :
			// Italian
			LanguageID = 2;
			break;
		case "DE" :
			// German
			LanguageID = 3;
			break;
		case "CH" :
			// German
			LanguageID = 3;
			break;
		case "CH-DE" :
			// Swiss German
			LanguageID = 3;
			ActiveCountry = "CH"
			break;
		case "CH-EN" :
			// Swiss English
			LanguageID = 1;
			ActiveCountry = "CH"
			break; 	 			
		case "CH-FR" :
			// Swiss French
			LanguageID = 4;
			ActiveCountry = "CH"
			break; 
		case "CH-IT" :
			// Swiss Italian
			LanguageID = 2;
			ActiveCountry = "CH"
			break; 
		case "FR" :
			// French
			LanguageID = 4;
			break;
		case "ES" :
			// Spanish
			LanguageID = 5;
			break;
		case "CA-FR" :
			// Canadian French 
			LanguageID = 4;
			ActiveCountry = "CA"
			break;
		case "SE" :
			// Sweden
			LanguageID = 6;
			break;
		case "PT":
			LanguageID = 7;
			break;						
		case "NL":
			// Netherlands
			LanguageID = 8;
			break;	
		case "EN-NL":
			// Dutch-English
			LanguageID = 1;
			ActiveCountry = "NL";
			break;
		default :
			// Default is "English"
			LanguageID = 1;
	} 


        // Grab the language that we want to display so we can sort correctly
	var Sorted_Array = new Array();
	for (i = 0; i < Country_Array.length; i++)
	{	Sorted_Array[i] = new Array(Country_Array[i][LanguageID], Country_Array[i][0]);
	}

        // Sort the array.
   	Sorted_Array = Sorted_Array.sort();

	// Loop round all countries and add them to the drop down
	for (i = 0; i < Sorted_Array.length; i++)
   	{

		// Use regular expression to remove additional chars useed to force entry to the end.
		var re = /zzz /g;

		// Add option to the drop down 
		selector.options[i] = new Option(Sorted_Array[i][0].replace(re, ""), Sorted_Array[i][1], false, false);

		// Select the active country in the list
		if (ActiveCountry == Sorted_Array[i][1])
		{	selector.selectedIndex = i;
		}

   	}
}
//***********************************************************************************************
//* This function identifes the version of Portfolio Manager to use.
//* This can be set in the cookie (if is has been selected) or the default set in PM_Sub.js.
//***********************************************************************************************
function getVersion() {

	// Get PM version to use from cookie
	var version = GetCookieValue('PortfolioManager','Version');
	DisplayDebug('Cookie version=' + version);
	
	if (version == "")
	{	// if not in cookie then use the default set in PM_Sub.js 
		version = str_PM_VersionNumber;
		DisplayDebug('Default version=' + version);
	}
	return(version);
}
//***********************************************************************************************
//* Get the value of an item set in the cookie. This reads cookies set via ASP / ASP.NET.
//***********************************************************************************************
function GetCookieValue(sCookieName, sParamName){
	// Split the cookie into its available sub parts
	var ArrayOfCookies = document.cookie.split("; ");
	
	var sDebug = 'ArrayOfCookies\n\n' + 'Count=' + ArrayOfCookies.length
	for (i=0; i < ArrayOfCookies.length; i++)
	{	ArrayOfCookies[i] = unescape(ArrayOfCookies[i]);
		sDebug = sDebug + '\n(' + i + ')=' + ArrayOfCookies[i]
	}
	DisplayDebug(sDebug);
	
	// Look for the sub part required
	for (i=0; i < ArrayOfCookies.length; i++)
	{	// If the 1st element matches the name we have found the correct sub part
		if (sCookieName == ArrayOfCookies[i].split("=")[0])
		{	DisplayDebug('Cookie Part: ' + sCookieName + '\n\n' + ArrayOfCookies[i]);
		
			// Get the Name value pairs section
			var NameValue = ArrayOfCookies[i].substring(sCookieName.length + 1,ArrayOfCookies[i].length);
			DisplayDebug(sCookieName + ' NameValue Pairs\n\n' + NameValue);

			// Loop round each Name Pair combination
			var NameValueArray = NameValue.split("&");
			for (j=0; j < NameValueArray.length; j++)
			{	// Look for a matching Param Name
				if (sParamName == NameValueArray[j].split("=")[0])
				{	// Match found so return the value
					return NameValueArray[j].split("=")[1]
				}
			}
		}
	}

	// There is no cookie value for that name
	return '';
}
//***********************************************************************************************
//* This function populates the image used in the Banner.
//* Called from PM_Banner.html
//***********************************************************************************************
function DisplayBannerImage(sPath){
	// If no path passed then use the default (in most cases we should use the deafult)
	if (sPath == null) 
	{	sPath = '../../../Shared/Graphics/'
	}
	
	// Pick a random image
	var headerImage = ["1" , "2", "3" , "4"];
	rand=Math.floor(4*Math.random())
	var sImage = sPath + 'head-image-' +  headerImage[rand] + '.jpg'
	
	//alert(sImage);
	document.write('<img width="107" height="80" border="0" src="' + sImage + '">');
}
//***********************************************************************************************
//* This function defines the correct Logon link in the menu. Done here so we can configure a
//* switch between http & https on test / live servers.
//* Called from PM_Menu.html
//***********************************************************************************************
function LogonMenuOption(sLogonText){
	// Get the page we are on (Menu), 
	// Ensure lower case as replace etc are case sensitive.
	var sLink = document.location.href.toLowerCase();

	// Replace the site root (http) with the app root (https)
	sLink = sLink.replace(str_SiteRoot.toLowerCase(), str_PM_App_URL.toLowerCase());
	
	//alert('href=' + document.location.href + '\n\nstr_SiteRoot=' + str_SiteRoot);	

	// Call the logon page
	sLink = sLink.replace('PM_Menu.html'.toLowerCase(),'PM_Login.html');
	
	//alert(sLink);
	document.write('<a class="linknav" target="_top" href="' + sLink + '">' + sLogonText + '</a>');
}

//***********************************************************************************************
//* Get the value of an item set in the cookie.
//***********************************************************************************************
function DisplayDebug(sDebug){
	if (bln_Debug == 1) 
	{	alert(sDebug);
	}
}
// -->
