// JavaScript Document
var sh_ShowImg = "../images/icon_+.gif";
var sh_HideImg = "../images/icon_-.gif";

function showHide(myId) {
	myText = myId.id + 'Text';
	
	if (myId.src.indexOf("minus") < 0) showText = true;
	else showText = false;
	
	if (myId.src.indexOf("FR") < 0 ) lang = 'en';
	else lang = 'fr';
	
	if (showText) {
		(lang == 'fr')?myId.src = "../images/layout/minusFR.jpg":myId.src = "../images/layout/minus.jpg";
		document.getElementById(myText).style.display='block';
	}
	else {
		(lang == 'fr')?myId.src = "../images/layout/plusFR.jpg":myId.src = "../images/layout/plus.jpg";
		document.getElementById(myText).style.display='none'; 
	}
}

function showHideFR(myId) { // myId = myFiles_Img
	myFiles = myId.id.substring(0,myId.id.length-4);
	myPicId = myId.id;
	
	if (document.getElementById(myPicId).src.indexOf("minus") < 0) showText = true;
	else showText = false;
	
	if (showText) {
		document.getElementById(myPicId).src = "../images/layout/minus_sm.jpg";
		document.getElementById(myFiles).style.display='block';
	}
	else {
		document.getElementById(myPicId).src = "../images/layout/plus_sm.jpg";
		document.getElementById(myFiles).style.display='none'; 
	}
}

function topLang() {
//function top(lang, menuitem) {
	//document.write("<div class='top'>")
var myPage = location.href;
var pageStart = myPage.lastIndexOf("/") + 1;
var pageEnd = myPage.indexOf("php") -1;
var lang = 'FR';

//for search
var mySearchString = myPage.substring(myPage.indexOf("?"),myPage.length-1);

if (pageEnd > 0) menuitem =  myPage.substring(pageStart, pageEnd);
else menuitem =  'index';


if (menuitem.substring(menuitem.length-2,menuitem.length) != 'FR') lang = 'en';
else menuitem = menuitem.substring(0, menuitem.length-2);
	
	if (lang=="en") {
		if (menuitem == 'search')  document.write("<a class='lang' href='../sphider-plus/" + menuitem + "FR.php" + mySearchString + "' target='_self' >FRAN&Ccedil;AIS</a>")
		else document.write("<a class='lang' href='../pages/" + menuitem + "FR.php' target='_self' >FRAN&Ccedil;AIS</a>")
	} else {
		if (menuitem == 'search')  document.write("<a class='lang' href='../sphider-plus/" + menuitem + ".php" + mySearchString + "' target='_self' >ENGLISH</a>")
		else 
		document.write("<a class='lang' href='../pages/" + menuitem + ".php' target='_self' >ENGLISH</a>")
	}
	
} 



function top() {
//function top(lang, menuitem) {
	//document.write("<div class='top'>")
var myPage = location.href;
var pageStart = myPage.lastIndexOf("/") + 1;
var pageEnd = myPage.indexOf("php") -1;
var lang = 'FR';

//for search
var mySearchString = myPage.substring(myPage.indexOf("?"),myPage.length-1);

if (pageEnd > 0) menuitem =  myPage.substring(pageStart, pageEnd);
else menuitem =  'index';


if (menuitem.substring(menuitem.length-2,menuitem.length) != 'FR') lang = 'en';
else menuitem = menuitem.substring(0, menuitem.length-2);
	
	if (lang=="en") {
		if (menuitem == 'search')  document.write("<a class='lang' href='../sphider-plus/" + menuitem + "FR.php" + mySearchString + "' target='_self' >FRAN&Ccedil;AIS</a>")
		else document.write("<a class='lang' href='../pages/" + menuitem + "FR.php' target='_self' >FRAN&Ccedil;AIS</a>")
	} else {
		if (menuitem == 'search')  document.write("<a class='lang' href='../sphider-plus/" + menuitem + ".php" + mySearchString + "' target='_self' >ENGLISH</a>")
		else 
		document.write("<a class='lang' href='../pages/" + menuitem + ".php' target='_self' >ENGLISH</a>")
	}
	
} //end top

function extractURL(myA) {
	//We need href and title
	//href:
	myHrefStart = myA.indexOf('href');
	myHrefStart = myA.indexOf('"', myHrefStart+1);
	myHrefStop = myA.indexOf('"', myHrefStart+4);
	myHref = myA.substring(myHrefStart+1,myHrefStop );
	
	if (myA.substring(myHrefStart+1, myHrefStart+2) == '#') myHref = "#";
	
	//title:
	myTitleStart = myA.indexOf('title');
	myTitleStart = myA.indexOf('"', myTitleStart+1);
	myTitleStop = myA.indexOf('"', myTitleStart+2);
	myTitle = myA.substring(myTitleStart+2,myTitleStop-1 );
	//alert("myTitle : " + myTitle);
	
	if (myHref == '#') myNewA = myTitle ;
	else myNewA = "<a href='" + myHref + "'>" + myTitle + "</a>";
	//alert("myNewA : " + myNewA);
	return (myNewA);
}

function extractSubURL(myA, mySelectedId) {
//alert("myA: " + myA + ", mySelectedId: " + mySelectedId);

	//We need href and title
	//href:
	myHrefStart = myA.indexOf('href');
	myHrefStart = myA.indexOf('"', myHrefStart+1);
	myHrefStop = myA.indexOf('"', myHrefStart+4);
	myHref = myA.substring(myHrefStart+1,myHrefStop );
	//alert("myHref : " + myHref);
	
	//title:
	myTitleStart = myA.indexOf('title');
	myTitleStart = myA.indexOf('"', myTitleStart+1);
	myTitleStop = myA.indexOf('"', myTitleStart+2);
	myTitle = myA.substring(myTitleStart+1,myTitleStop );
	//alert("myTitle : " + myTitle);
	
	myNewA = "<a href='" + myHref + "'>" + myTitle + "</a>";
	return (myNewA);
}

function buildBreadCrumbs()
  {
	var myPage = location.href;
	var pageStart = myPage.lastIndexOf("/") + 1;
	var pageEnd = myPage.indexOf("php") -1;
	
	if (pageEnd > 0) myVar =  myPage.substring(pageStart, pageEnd);
	else myVar =  'index';
	
      // Get the ul object
	  var breadCrumbs = "";
      var currentPage = document.getElementById(myVar);
	  
	  var topNode = false;
	  if (currentPage.parentNode.id != 'topNode') {
		  breadCrumbs = extractURL(currentPage.innerHTML);
		  myTitleStart1 = breadCrumbs.indexOf('title');
		  myTitleStart1 = breadCrumbs.indexOf('>', 0);
		  myTitleStop1 = breadCrumbs.indexOf('<', myTitleStart1+2);
		  myTitle1 = breadCrumbs.substring(myTitleStart1+1,myTitleStop1);
	  }
	  else {
	  	topNode = true;
		}
		
	  if (!topNode) {
	  	if (currentPage.parentNode.id == 'topNode') topNode = true;	
	  }
	  
	  var x = currentPage.parentNode.parentNode;
	  if (!topNode) breadCrumbs = extractURL(x.innerHTML) + ' > ' + breadCrumbs;
	  else {
	  	topNode = true;
		}
		
	  if (!topNode) {
	  	if (x.parentNode.id == 'topNode') topNode = true;	
	  }
	  
	  var y = x.parentNode.parentNode;
	  if (!topNode) breadCrumbs = extractURL(y.innerHTML) + ' > ' + breadCrumbs;
		
       if (breadCrumbs != "") document.write('<IMG width="100%" height="3px" src="../images/layout/clear.gif" ><IMG width="5px" height="5px" src="../images/layout/clear.gif" ><a href="index.php">Groupe Aeroplan</a> > ' + breadCrumbs);   
	   
	   //extract title from breadcrumbs
	   firstTitleEnd = breadCrumbs.indexOf('>') -1;
	   myFirstTitle = breadCrumbs.substring(0, firstTitleEnd);
	   MyTempTitle = breadCrumbs.substring(firstTitleEnd + 4);
	   MySecondTitleStart =  MyTempTitle.indexOf('>');
	   MySecondTitle = MyTempTitle.substring(MySecondTitleStart+1, MyTempTitle.indexOf('<'));
	   MyThirdTitle = MyTempTitle.substring(MyTempTitle.indexOf('<'), MyTempTitle.lastIndexOf('<'));
	   MyThirdTitle = MyThirdTitle.substring(MyThirdTitle.lastIndexOf('>')+1);
	   document.write('<div class="title">');
	   document.write('<div class="mainTitle">' + myFirstTitle + '</div>');
	   document.write('<div class="subTitle">' + MySecondTitle);
	   if (MyThirdTitle.length > 1)  document.write(' > ' + MyThirdTitle);
	   document.write('</div></div>');
  }

function leftMenu() {
	var myPage = location.href;
	var pageStart = myPage.lastIndexOf("/") + 1;
	var pageEnd = myPage.indexOf("php") -1;
	var topNode = false;
	
	if (pageEnd > 0) {
		myVar =  myPage.substring(pageStart, pageEnd);
		}
	else {
		myVar =  'index';
		topNode = true;
		}
		
		//=========================
	var leftMenuId = "";	
	var levels = 0;
		
	var myParent = document.getElementById(myVar);
	//var myParent = document.getElementById('invReportsAR');
	leftMenuId = myParent.id;
	
	if ((!topNode) && (myParent.parentNode.parentNode.id.length > 1)) {
		var myParent1 = myParent.parentNode.parentNode;
		leftMenuId = myParent1.id;
		levels = 1;
		}
	else topNode = true;
	
	if ((!topNode) && (myParent1.parentNode.parentNode.id .length > 1)) {
		var myParent2 = myParent1.parentNode.parentNode;
		leftMenuId = myParent2.id;
		levels = 2;
		}
	else topNode = true;
	
	//============================================
	// Build the menu	
	document.write("<div class='leftMenu'>")
	
	var parent1 = document.getElementById(leftMenuId);
	var children = parent1.getElementsByTagName("li");
	var subChildren = "";
	var haveChildren = false;
	var mySubMenu = false;
	
	for (i = 0; i < children.length; i++) {
		//check if there are submenus
		subChildren = children[i].getElementsByTagName("li");
		
		if (subChildren.length > 0)  haveChildren = true;
		else haveChildren = false;
		
		if (children[i].parentNode.parentNode.id == leftMenuId) {
			if (children[i].id == myParent.id) {
				document.write('<img src="../images/layout/arrow.gif" width="3px" height="5px"/>' + "<div class='leftMenuSelected'>" + extractURL(children[i].innerHTML) + '</div><br>');
			}
			else 
				document.write('<img src="../images/layout/arrow.gif" width="3px" height="5px"/>' + extractURL(children[i].innerHTML) + '<br>');
		}
		
		
		if (haveChildren) {
			for (j = 0; j < subChildren.length; j++) {
				if (myParent.id == subChildren[j].id) {
					document.write("<div class='leftSubMenuSelected'>");
				}
				else {
					document.write("<div class='leftSubMenu'>");
				}
				document.write('<img src="../images/layout/sub_arrow.gif" width="17px" height="5px"/>' + extractSubURL(subChildren[j].innerHTML, myParent.id));
				document.write("</div>")
			}
		}
	}
	      
	document.write("</div>")
	
		if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
 var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
 
 if (ieversion==6)
  document.write("<div class='leftMenuTopIE6'></div>")
  else document.write("<div class='leftMenuTop'></div>");
}
else
 document.write("<div class='leftMenuTop'></div>");

	
	
} //leftMenu

function investorMenu() {
	document.write('<div class="governanceMenu">');
	document.write('<img src="../images/layout/clear.gif" width="10px" height="1px" />QUICK LINKS');
	document.write('<ul >');
	document.write('<li><a href="aboutGov.php" target="_self">Governance</a></li>');
	document.write('<li><a href="mediaReleases.php" target="_self">News Releases</a></li>');
	document.write('<li><a href="rssSignUp.php" target="_self">RSS Sign-up</a></li>');
	document.write('<li><a href="invIRcontacts.php" target="_self">Contact</a></li>');
	document.write('</ul>');
	document.write("</div>");
}

function investorMenuFR() {
	document.write('<div class="governanceMenu">');
	document.write('<img src="../images/layout/clear.gif" width="10px" height="1px" />LIENS RAPIDES');
	document.write('<ul >');
	document.write('<li><a href="aboutGovFR.php" target="_self">Gouvernance</a></li>');
	document.write('<li><a href="mediaReleasesFR.php" target="_self">Communiqu&eacute;s</a></li>');
	document.write('<li><a href="rssSignUpFR.php" target="_self">Abonnez-vous &agrave;<br>nos fils RSS</a></li>');
	document.write('<li><a href="invIRcontactsFR.php" target="_self">Pour nous joindre</a></li>');
	document.write('</ul>');
	document.write("</div>");
}

function governanceMenu() {
	document.write('<div class="investorsMenu" >');
	document.write('<img src="../images/layout/clear.gif" width="10px" height="1px" />QUICK LINKS');
	document.write('<ul >');
	document.write('<li><a href="PDF_Governance/DirectorsCharter.pdf" target="_blank">Board of Directors Charter</a></li>');
	document.write('<li><a href="PDF_Governance/Code.pdf" target="_blank">Code of Ethics</a></li>');
	document.write('<li><a href="PDF_Governance/Disclosure.pdf" target="_blank">Disclosure</a></li>');
	document.write('</ul>');
	document.write('</div>');
}

function governanceMenuFR() {
	document.write('<div class="investorsMenu">');
	document.write('<img src="../images/layout/clear.gif" width="10px" height="1px" />LIENS RAPIDES');
	document.write('<ul >');
	document.write('<li><a href="PDF_GovernanceFR/DirectorsCharter.pdf" target="_blank">Charte des Administrateurs</a></li>');
	document.write('<li><a href="PDF_GovernanceFR/Code.pdf" target="_blank">&Eacute;thique</a></li>');
	document.write('<li><a href="PDF_GovernanceFR/Disclosure.pdf" target="_blank">Divulgation</a></li>');
	document.write('</ul>');
	document.write("</div>");
}

function footerMenu() {
	var myPage = location.href;
	var pageStart = myPage.lastIndexOf("/") + 1;
	var pageEnd = myPage.indexOf("php") -1;
	var lang = 'FR';
	
	if (myPage.substring(myPage.length-6,myPage.length-4) != 'FR') lang = 'en';

	if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
 var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
 
 if (ieversion==6)
  document.write("<div id='footer' class='footerIE6'>")
  else document.write("<div id='footer' class='footer'>");
}
else
 document.write("<div id='footer' class='footer'>");

	document.write("<hr 'width=100%' align='left'/>");
	
	if (lang == 'en') {
		document.write('<a href="index.php" target="_self">HOME</a>&nbsp;|&nbsp;');
		document.write('<a href="aboutGA.php" target="_self">ABOUT</a>&nbsp;|&nbsp;');
		document.write('<a href="compAeroplan.php" target="_self">OUR COMPANIES</a>&nbsp;|&nbsp;');
		document.write('<a href="invQuarter.php" target="_self">INVESTORS</a>&nbsp;|&nbsp;');
		document.write('<a href="mediaReleases.php" target="_self">MEDIA</a>&nbsp;|&nbsp;');
		document.write('<a href="respCSR.php" target="_self">SOCIAL RESPONSIBILITY</a>&nbsp;|&nbsp;');
		document.write('<a href="careersJobs.php" target="_self">CAREERS</a>&nbsp;|&nbsp;');
		document.write('<a href="contact.php" target="_self">CONTACT</a>');
	}
	else {
		document.write('<a href="indexFR.php" target="_self">ACCUEIL</a>&nbsp;|&nbsp;');
		document.write('<a href="aboutGAFR.php" target="_self">&Agrave; PROPOS</a>&nbsp;|&nbsp;');
		document.write('<a href="compAeroplanFR.php" target="_self">NOTRE ORGANISATION</a>&nbsp;|&nbsp;');
		document.write('<a href="invQuarterFR.php" target="_self">INVESTISSEURS</a>&nbsp;|&nbsp;');
		document.write('<a href="mediaReleasesFR.php" target="_self">M&Eacute;DIAS</a>&nbsp;|&nbsp;');
		document.write('<a href="respCSRFR.php" target="_self">RESPONSABILIT&Eacute;&nbsp;SOCIALE</a>&nbsp;|&nbsp;');
		document.write('<a href="careersJobsFR.php" target="_self">CARRI&Egrave;RES</a>&nbsp;|&nbsp;');
		document.write('<a href="contactFR.php" target="_self">CONTACT</a>');
	}
	
     
	document.write("</div>");
	document.write('<img src="../images/layout/clear.gif" width="100%" height="120px">');
	
} //footerMenu

