﻿
// ------------------------------------------------
// Jump between Languages
// ------------------------------------------------

// Generic Language Jump

function jumpToMyFrench(source,arguments)
{
document.getElementById("hidden1").value='sp10038be6';

document.getElementById("ctl00_frButton").click();

}
function jumpToMyEnglish(source,arguments)
{

document.getElementById("hidden1").value='sp100387e7';

document.getElementById("ctl00_enButton").click();

}


function jumpToMyFrench_NewsRelease() 
{
			// Distinct function required as the URL structure
			// for news releases differs from other pages

            var myUrl = document.location.pathname;
            myUrl = myUrl.toLowerCase();

            // remove the first occurance of / in the URL

            // the Javascript replace function
            // only replaces the first instance of 
            // the search criteria.

            var newUrl = myUrl;
            newUrl = myUrl.replace( "/", "/fr/" );
            newUrl = newUrl.replace( "/nr_", "/fr_nr_" );

            window.location = newUrl;


}
			
function jumpToMyEnglish_NewsRelease() 
{

			// Distinct function required as the URL structure
			// for news releases differs from other pages
			
            var myUrl = document.location.pathname;            
            myUrl = myUrl.toLowerCase();

            // remove the first occurance of /fr in the URL

            var newUrl = myUrl;
            newUrl = myUrl.replace( "/fr/", "/" );
            newUrl = newUrl.replace( "/fr_nr_", "/nr_" );

            window.location = newUrl;
        

}

function jumpToMyFrench_InTheNews()
{

            var myUrl = document.location.pathname;
            myUrl = myUrl.toLowerCase();

            // remove the first occurance of / in the URL

            // the Javascript replace function
            // only replaces the first instance of 
            // the search criteria.

            var newUrl = myUrl;
            newUrl = myUrl.replace( "/", "/fr/" );
            newUrl = newUrl.replace( "news/news", "news/fr_news" );

            window.location = newUrl;


}
			
function jumpToMyEnglish_InTheNews() 
{

            var myUrl = document.location.pathname;
            myUrl = myUrl.toLowerCase();

            // remove the first occurance of /fr in the URL

            var newUrl = myUrl;
            newUrl = myUrl.replace( "/fr/", "/" );
            newUrl = newUrl.replace( "news/fr_news", "news/news"  );

            window.location = newUrl;
        

}

function jumpToMyFrench_JobPosting()
{

            var myUrl = document.location.pathname;
            myUrl = myUrl.toLowerCase();

            // remove the first occurance of / in the URL

            // the Javascript replace function
            // only replaces the first instance of 
            // the search criteria.

            var newUrl = myUrl;
            newUrl = myUrl.replace( "/", "/fr/" );
            newUrl = newUrl.replace( "postings/jp_", "postings/fr_jp_" );

            window.location = newUrl;


}
			
function jumpToMyEnglish_JobPosting()
{

            var myUrl = document.location.pathname;            
            myUrl = myUrl.toLowerCase();

            // remove the first occurance of /fr in the URL

            var newUrl = myUrl;
            newUrl = myUrl.replace( "/fr/", "/" );
            newUrl = newUrl.replace( "postings/fr_jp_", "postings/jp_" );

            window.location = newUrl;
        

}
	

// ------------------------------------------------
// Breadcrumb Pathway code
// ------------------------------------------------

/*

This code is embedded at the root of the page to allow
for correct code generation

var pathway = new Array(7);
pathway[0] = "<a href='/'>Home</a>";
pathway[1] = "<WXGET NAME="AA1" RunCode="WxMenuLink" RunOption="1"></WXGET>";
pathway[2] = "<WXGET NAME="AA1" RunCode="WxMenuLink" RunOption="2"></WXGET>";
pathway[3] = "<WXGET NAME="AA1" RunCode="WxMenuLink" RunOption="3"></WXGET>";
pathway[4] = "<WXGET NAME="AA1" RunCode="WxMenuLink" RunOption="4"></WXGET>";
pathway[5] = "<WXGET NAME="AA1" RunCode="WxMenuLink" RunOption="5"></WXGET>";
pathway[6] = "<WXGET NAME="AA1" RunCode="WxMenuLink" RunOption="6"></WXGET>";
pathway[7] = "<WXGET NAME="AA1" RunCode="WxMenuLink" RunOption="7"></WXGET>";
*/

var i;
var max = 7;

function makepathway()
{
	MakePathway();
}

function MakePathway() 
{
	// alert('MakePathway() has been called.');
	
	for (i = 0; i < max; i++) 
	{
		if (pathway[i].indexOf("><")==-1) 
		{
			// write link
			if (!((i==1) && (pathway[i].indexOf("Home")!=-1))) 
			{
				document.write(pathway[i]);
			}
			
			// write character or image
			var currentPathway = pathway[i+1].toUpperCase();
			if( (currentPathway!='') && (currentPathway.indexOf("DEFAULT")==-1) && (currentPathway.indexOf("><")==-1) && (currentPathway.indexOf("Home")==-1) ) 
			{
				document.write(' > '); 
			} 
		} 
	}
}


// ------------------------------------------------
// Send to a Friend
// ------------------------------------------------

function jobid()
{
var jobid= "1234";
 }




function mailpage( Language )
{

    var LangArg = Language.toUpperCase();
    
    // Attach the title
    // Title could be set here if only the page Title

    if( LangArg == "FRANCAIS" )
    {
        // Place the French content here.
        // F R E N C H
        mail_str = "mailto:?subject=" + document.title;
        mail_str += "&body=Voici des renseignements intéressants que j’ai trouvés dans le site Web de CPPIB." + location.href+document.getElementById("ctl00_myHiddenVar").value;
    }
    else
    {  
        // Place the English content here.
        // E N G L I S H
        mail_str = "mailto:?subject=Please have a look at " + document.title;        
        mail_str += "&body=I thought you might be interested in the following information from the CPPIB website: " + location.href+document.getElementById("ctl00_myHiddenVar").value;    
    }
       
    // Send the Mail To
    location.href = mail_str;
}


// ------------------------------------------------
// Stylesheet Change Functions
// ------------------------------------------------

function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return "default";
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

window.onload = function(e) 
{
  var cookie = readCookie("style");
  if( cookie != "null" && cookie != null )
  {
	  title = cookie;
  }
  else
  {
	  title = getActiveStyleSheet();
  }

  setActiveStyleSheet(title);
  
}

window.onunload = function(e) 
{ 
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}


  var cookie = readCookie("style");
  
  if( cookie != "null" && cookie != null )
  {
	  title = cookie;
  }
  else
  {
	  title = getActiveStyleSheet();
  }

  setActiveStyleSheet(title);
  
  
// ------------------------------------------------
// Output French Dates
// ------------------------------------------------
  
function ConvertDateToFrench( strDate )
{
	var saDate = strDate.split( " " );
	
	var Day = saDate[1];
	var Month = saDate[0];
	var Year = saDate[2];
	
	var Day = Day.substr( 0, Day.length - 1 );
	
	return Day + " " + FrenchMonth(Month) + " " + Year;
}

function WriteFrenchDate( strDate )
{
	document.write( ConvertDateToFrench( strDate ) );
}


function FrenchMonth( Month )
{
	Month = Month.toUpperCase();

	switch( Month )
	{
		case "JANUARY":
			return "janvier";
		case "FEBRUARY":
			return "fevrier";
		case "MARCH":
			return "mars";
		case "APRIL":
			return "avril";
		case "MAY":
			return "mai";
		case "JUNE":
			return "juin";
		case "JULY":
			return "juillet";
		case "AUGUST":
			return "août";
		case "SEPTEMBER":
			return "septembre";
		case "OCTOBER":
			return "octobre";
		case "NOVEMBER":
			return "novembre";
		case "DECEMBER":
			return "décembre";
	}
	
	return "-- ERROR --";	
}
