/*
Global settings
*/

//debug modus
var bolDebug = false;
if(document.location.search.indexOf('debug')>0 && document.location.search.indexOf('cachedebug')<1)bolDebug=true;
var strCurrentPath = document.location.pathname;


//crsc settings
if(location.protocol=='http:' && window.location.hostname!="130.139.83.200")_page.showStockQuotes = true;
if(window.location.hostname=="130.139.83.200"){
	_page.loadOmniture = false;
}else{
	_page.loadOmniture = true;
}
_page.hideFlashSectionBanner = true;
_page.sectionSpecial = ["Annual Report 2007","/index.asp"]; /* Enter title and url special section */
_page.sectionMain = ["Investor Relations","http://www.philips.com/about/investor/index.page?origin=far"]; /* Optional: Enter title and url main section */
_page.leftNavOnload = false;
_page.loadSIFR = false;
_page.loadSIFRScript = false;
_page.loadSIFRConfig = false;
_page.crsc_nav_server = '';
_page.crsc_server = '';

/*
Global variables
*/
var objPageAttributes=new Object();
var bolStoreFontSizeInCookie=false;
var intFontSize=100; //default to 100%
var arrQuoteClass=[], arrBomLinks=[];
arrBomLinks.push('http://www.philips.com/about/company/management/boardofmanagement/gerardkleisterlee/index.page');
arrBomLinks.push('http://www.philips.com/about/company/management/boardofmanagement/pierre-jeansivignon/index.page');
arrBomLinks.push('http://www.philips.com/about/company/management/boardofmanagement/gottfrieddutin/index.page');
arrBomLinks.push('http://www.philips.com/about/company/management/boardofmanagement/rudyprovoost/index.page');
arrBomLinks.push('http://www.philips.com/about/company/management/boardofmanagement/theovandeursen/index.page');
arrBomLinks.push('http://www.philips.com/about/company/management/boardofmanagement/andrearagnetti/index.page');
arrBomLinks.push('http://www.philips.com/about/company/management/boardofmanagement/steverusckowski/index.page');

/*
On the login page - only show a link to the home page
*/
if(strPageIdSystem=="ulogin_page"){
	//remember first value
	var objFirstItem=_page.leftNav["0"];
	//reset the array
	_page.leftNav=new Array();
	//restore the first item
	_page.leftNav["0"]=objFirstItem;
}

/*
Calculate hierarchical position
*/
var strPageId = linkLookup();

/*
Initiate page
*/
window.addEvent('domready', initPageDomReady);
window.addEvent('load', initPage);


/*
FUNCTIONS AND CLASSES
*/
function initPageDomReady(){
	/*
	Triggered on the dom ready event
	*/
	var objImage, objSpan;
	
	
	//execute default sifr replacements
	executeDefaultSifrReplacements();	

	//url specific functionality
	switch(strPageIdSystem){
		case "79288332467":
			//sectors landing page
			executeAdditionalSifrReplacements();
			break;
		case "94817191792":
			//philips group landing page
			executeAdditionalSifrReplacements();
			break;				
		case "93168837303":	
			//financial highlights
			executeAdditionalSifrReplacements();				
			break;
		case "4533956689":
			//ten year overview
			executeAdditionalSifrReplacements();
			break;
		case "1153430":
			//leadership landing page
			executeAdditionalSifrReplacements();
			objImage=$('img_11534302');
			objSpan=objImage.getParent();
			objSpan.setProperty('class', 'far-img-right-2col')
			break;
		case "1153794":
			//presidents message
			objImage=$('img_46678932');
			objSpan=objImage.getParent();
			objSpan.setProperty('class', 'far-img-left-1col')
			break;
		case "1156433":
			//sectors landing page
			objImage=$('img_11564331');
			if($defined(objImage)){
				objSpan=objImage.getParent();
				objSpan.setProperty('class', 'far-img-right-3col')
			}
			objImage=$('img_11564334');
			if($defined(objImage)){
				objSpan=objImage.getParent();
				objSpan.setProperty('class', 'far-img-right-3col')
			}		
			break;			
		case "10752385458":
			//ifrs landing page
			retrieveIfrsInfo();
			break;
		case "1154340":
			//philips way page - hide a bold item in
			var elDiv=$('anchor11');
			if($defined(elDiv)){
				var elBold=elDiv.getElement('b');
				if($defined(elBold)){
					var elP=elBold.getParent();
					elP.setStyle('display', 'none');
				}				
			}
			break;
		case "55986043686":
			//10 year table correction 1
			$('far-maincontent').setStyle('height', '520px');
			break;
		case "23358651642":
			//10 year table correction 1
			$('far-maincontent').setStyle('height', '510px');
			break;			
	}

	//stick the search menu in the navigation
	if(!window.ie){
		placeFarSearch();
	}
	
	//set the font size used in the page
	var intFontSizeCookie=Cookie.get("fontsize");
	if(intFontSizeCookie!=false && bolStoreFontSizeInCookie){
		//reset the fontsize in the page based on the factor stored
		intFontSizeCookie=intFontSizeCookie.toFloat();
		var intFontSizeFactor=intFontSizeCookie/100;
		//alert(intFontSizeFactorCookie);
		_page.font_resize(intFontSizeFactor);
	}

  //position the usgaap logo
  if(window.ie6){
	  var elTdBar=$('far-bar');
	  if($defined(elTdBar)){
	  	var elDivLogo=elTdBar.getElement('div.far-usgaap-logo');
	  	//alert(elDivLogo.getStyle('display'));
	  	if(elDivLogo.getStyle('display')!='none'){
		  	var objTdPosition=elTdBar.getPosition();
		  	var intTop=objTdPosition.y+5;
		  	var intLeft=objTdPosition.x+660;
		  	elDivLogo.setStyle('left', intLeft);
		  	elDivLogo.setStyle('top', intTop);
		  	elDivLogo.setStyle('display', 'inline');
		  }
	  }
	}
}

function initPage(){
	/*
	Triggered on the onload event
	*/	
	
	//setup the pagination component
  if($defined(objPageAttributes.usepagination) && $defined($('far-sub-navigation'))){
  	paginationSetup();
  }

	//IE only: stick the search menu in the navigation
	if(window.ie){
		placeFarSearch();
	}
	
	//setup the tool tips (print, email, etc)
	setToolTips.delay(4500);
	
	//perform the default sifr replacements that are present on each page
	executeSifrReplacements();		

  /*
  Page specific client side scripting
  Uses global objPageAttributes object to trigger functions
  */
  if($defined(objPageAttributes.usenotepopups)){
  	setupFinancialPopups.delay(1500);
  }
  
  if($defined(objPageAttributes.usebom)){
		setupBoardOfManagement();
  }  
                         
	if($defined(objPageAttributes.usesidebargraphs)){
		setupDivisionPopups.delay(1500);
	}
	
	//ten year overview tables
	if(strPageIdSystem=="4533956689" || strPageIdSystem=="55986043686" || strPageIdSystem=="23358651642" || strPageIdSystem=="13874572099" || strPageIdSystem=="96903724863" || strPageIdSystem=="83491981930"){
		initTenYearOverview.delay(2000);
	}

	
	//url specific functionality
	switch(strPageIdSystem){
		case "0":
			//homepage
			if(window.ie){
				initHomePage.delay(500);
			}else{
				initHomePage()
			}	
			break;
		case "93168837303":	
			//financial highlights		
			setSwapper(); // Set image-swapper events
			break;
		case "1154067":
			//supervisory board page
			setupSupervisoryBoardNoteLinks();
			break;
		case "search-results":
			searchExecute();
			break;
		case "1156433":
			//sectors landing page
			objImage=$('img_11564331');
			if($defined(objImage)){
				objSpan=objImage.getParent();
				objSpan.setProperty('class', 'far-img-right-3col')
			}
			objImage=$('img_11564334');
			if($defined(objImage)){
				objSpan=objImage.getParent();
				objSpan.setProperty('class', 'far-img-right-3col')
			}		
			break;			
	}
}

/*
For the pagination object
*/
function paginationGotoSection(strSectionId){
	/*
	This function executes the navigation to a section
	*/
	var strNr=strSectionId.replace(/anchor/,"");
	
	//add a history element to the history manager and let the historymanager set the anchor link
	HistoryManager.setValue("section", 0, strNr);
	//show-hide layers to paginate to the specific section
	paginationNavigateToSection(strNr);
}

function paginationNavigateToSection(strSectionNr){
	//Show and hide the layers to simulate pagination
	//alert("paginationNavigateToSection-"+strSectionNr+" - "+$defined(strSectionNr)+" + "+$type(strSectionNr));
	if($type(strSectionNr)=="number")strSectionNr=0;
	var strId="anchor"+strSectionNr;
	var objDiv=$(strId);
	var objLink=$('far-link_'+strId);
	if(($defined(objDiv)==false || $defined(objLink)==false) && strSectionNr==0){
		strId="anchor1";
		objDiv=$(strId);
		objLink=$('far-link_'+strId);
	}

	//hide right column content
	if($defined(objPageAttributes.usesidebargraphs)){
		//alert('yo'+);
		if(strId==objPageAttributes.firstkey){
			$("far-right-col").setStyle('display', 'none');
		}else{
			$("far-right-col").setStyle('display', 'inline');
		}		
	}
	
	//hide all sections
	var objArticles=$$('#far-maincontent div.far-wrapper-text');
	objArticles.each(function(item){
			if(item.getStyle('display')!='none')item.setStyle('display', 'none');
		}
	)
	
	//show the one that we are lookng for
	if($defined(objDiv))objDiv.setStyle('display', 'block');
	//alert(objDiv.getProperty("style"));
	
	//hide main visual
	var objMainVisual=$("far-mainvisual"), objMainCaption=$("far-imagecaption_100");
	
	if($defined(objMainVisual)){
		var bolOurApproach=false;
		if(location.pathname=='/pages/risk_management/our_approach.asp')bolOurApproach=true;
		if(strId==objPageAttributes.firstkey || bolOurApproach){
			objMainVisual.setStyle('display', 'inline');
			if(objMainCaption)objMainCaption.setStyle('display', 'inline');
			if(bolOurApproach){
				//insert the flash html in the page
				var strStateId="state_2"
				if(strId=="anchor1")strStateId="state_3"
				if(strId=="anchor2")strStateId="state_4"
				if(strId=="anchor3")strStateId="state_5"
				
				var objFlashParams={src: '/imgs/user/risk_management/riskmanagement.swf?stateid='+strStateId, width: 750, height: 207, version: 8};
				insertFlashHtml('far-mainvisual', objFlashParams);
				
				
			}
		}else{
			objMainVisual.setStyle('display', 'none');
			if(objMainCaption)objMainCaption.setStyle('display', 'none');
		}
	}
	
	//set the link colors in th pagination component
	var objLinks=$$('.far-sub-navigation a.far-active-link');
	objLinks.each(function(item){
			item.removeClass('far-active-link'); 
		}
	)	
	//alert('far-link_'+strId);
	objLink.addClass('far-active-link'); 
	
	//sifr the correct components
	executeDefaultSifrReplacementsPagination();
	
	//scroll up
	window.scrollTo(0, 0);	
}


function paginationSetup(){
	/*
	Sets up the pagination component by initializing the history manager
	*/
	//alert(objPageAttributes.firstkey);
	var strHashKey="section"
	HistoryManager.initialize();
	
	var intFirstAnchor=objPageAttributes.firstkey.replace(/anchor(.*)/,"$1").toInt();
	
	HistoryManager.register(
		//unique key for this history
		strHashKey,
		//the value it should default to when the page is hit without the correct hash applied
		[intFirstAnchor],
		//defines the logic that will be executed if the hash matches the regular expression below
		function(values){
			//values[0] determine the match that is made in the regular expression
			paginationNavigateToSection(values[0]);
		}.bind(this),
		//the new value for the hash
		function(values){			
			var strKey=strHashKey+"("+values[0]+")";
			//alert(strKey);
			return strKey;
		}.bind(this),
		//the regular expression that the hash key should adhere to
		strHashKey + '\\((\\d+)\\)');

	HistoryManager.start();
}


/*
Open new window
*/
function openNewWindow(url){
	window.open(url);
}


/*
Place the far search panel inside the menu
*/
function placeFarSearch() {
	var elLeftNav=$('p-leftnav');
	if($defined(elLeftNav)){
		var elRef, elTR, elTD, elSep;
	
		elRef = elLeftNav.getElement(".p-left-bottom"); // Select reffering element for injection
		elTR = new Element('tr'); // new TR
		elTD = new Element('td'); // new TD
		elSep = new Element('div', { 'class': 'p-solidsep' });
	
		//if(window.ie7 != true) { elSep.injectInside(elTD); } //insert seperatorline inside TD
		elSep.injectInside(elTD);
		$('far-search').injectInside(elTD); // insert search content inside TD
		elTD.injectInside(elTR); 
		if($defined(elTR) && $defined(elRef))elTR.injectBefore(elRef.getParent());  // Inject the new row in the table
	}
}


/*
Calculate thie hierarchical position in the navigation array
*/
function linkLookup(){
	/*
	this function will find the correct number in the crsc array based on the url of the page
	*/
	var arrArguments=linkLookup.arguments;
	var intArguments=arrArguments.length;
	var arrTemp;
	//if(bolSpeedTest)createSplitTimeMessage("in lookup");	
	if(retrieveQuerystringParameterValue(location.href, 'parentid')!='')return retrieveQuerystringParameterValue(location.href, 'parentid');
	
	var bolCheckNext=false, bolReturnValue=false;
	var strCurrentPath=document.location.pathname;
	if(intArguments>0)strCurrentPath=arrArguments[0];
	var strSearchString=document.location.search;
	var strTempId="";
	var strLeftNavPath;
	
	//rework the path so that it will match the string pattern in the site_structure.xml 
	var re = new RegExp("(/|^\.asp|^\.html|^\.htm)$");
	if (strCurrentPath.match(re)) {
		//alert("Need to add the default document");
		strCurrentPath+="index.asp";
	}
	
	//strCurrentPath=strCurrentPath.replace(/&/gi, "------");
	
	//build a string that will match the data in the array
	var strUniqueIdentifier=strCurrentPath;
	//overrule for cms
	if(strCurrentPath=="/system/xopus_prepare.asp"){
		strUniqueIdentifier=strSearchString;
	}

	if(bolDebug)strLookupDebug="<b>Searching: strUniqueIdentifier="+strUniqueIdentifier+"</b><br/>";
	
	for(id in _page.leftNav){
		if(!isFunction(_page.leftNav[id])){
			//alert(id);
			//alert(_page.leftNav[id].link)
			strLeftNavPath=_page.leftNav[id].link;
			arrTemp=strLeftNavPath.split('?');
			if(arrTemp.length>0)strLeftNavPath=arrTemp[0]
			//strLeftNavPath=strLeftNavPath.replace(/&/gi, "------");
			
			if(bolDebug)strLookupDebug+="-"+strLeftNavPath+"<br/>";
			
			if (strUniqueIdentifier == strLeftNavPath){
				strTempId=id;
				break;
			}
		}
	}
	//if(bolSpeedTest)createSplitTimeMessage("uit lookup (id="+strTempId+")");
	return strTempId
}

/*
Toolbar
*/
function pageFontEnlarge(){
	hitStatisticsServer('/toolbar/font_enlarge');
	_page.font_resize(1.2);
	if(bolStoreFontSizeInCookie){
		Cookie.set("fontsize", _page.articleCSSFontsizeCurrent);
	}
}
function pageFontReduce(){
	hitStatisticsServer('/toolbar/font_reduce');
	_page.font_resize(0.8);
	if(bolStoreFontSizeInCookie){
		Cookie.set("fontsize", _page.articleCSSFontsizeCurrent);
	}
}
function pagePrint(){
	hitStatisticsServer('/toolbar/page_print');
	_page.printVersionFar();
}
function pageSent(){
	hitStatisticsServer('/toolbar/page_email');
	_page.email();
}
function pageDownloadFoldout(){
	hitStatisticsServer('/toolbar/download');
}

/*
For tracking statistics
*/
function hitStatisticsServer(strUrl){
	//sage_ev(1,strUrl);
}

/*
Popup setup
*/
function setupFinancialPopups(){
	/*
	This function sets up the popups used in the financial tables (that link to the notes)
	*/
	var objPopupDimensions={'width': 290, 'height': 113};
	var offset={};
	offset['x']=0-objPopupDimensions['width']/2;
	offset['y']=-15;	
	if (window.ie6)offset['y']=-15;
	if(window.webkit){
		offset['x']=offset['x']+6;
		offset['y']=offset['y']+5;
	}
	offset['y']= offset['y'] - objPopupDimensions['height'];
	
	$('far-maincontent').getElements('.far-financial-statement .number').each(function(el) {		
		var id = el.id;
		var nr = id.substring(11);
		var divSource=$('popup-'+nr);
		//alert(nr);
		if(!$defined(divSource)){
			alert("WARNING: Div with id popup-"+nr+" is not defined.\nPlease contact the administrator.");
		}else{
			var popup = $('popup-'+nr).setStyles({
				'position': 'absolute',	        
				'z-index': '999',
				'visibility': 'hidden'
			}).injectInside(document.body);			
			
			setPopup(el, popup, offset, 'click');	
		}
	
										
	});
}

function setupDivisionPopups(){
	/*
	This function sets up the popups to the graphs in the sectors pages
	*/
	var intWidthEl=244, intOffsetY=3, intOffsetX=0;
	
	if(window.ie7)intOffsetX=0;
	
	$$('.far-keydata-link').each(function(el) {	
		var id = el.id;
		//var objPos=el.getPosition();
		var nr = id.substring(11);
		var popup = new Element('div').setStyles({
			'position': 'absolute',	        
			'z-index': '999',
			'visibility': 'hidden'
		}).injectInside(document.body);	

		$('popup-'+nr).injectInside(popup);
		
		var x=0-(popup.getElement('.far-p-keyd-content').getSize()['size']['x'])+intWidthEl+1+intOffsetX;
		var offset = {'x': x, 'y': intOffsetY};

		setPopup(el, popup, offset, 'click');								
	});
}

/* BOM */
function setupBoardOfManagement(){
	$$('.far-block-wrapper').each(function(el, index) { 
		new Accordeon(el); 
		//alert(index);
		//set the links to the cv's 
		var elLink=el.getElement('div[class=far-block-link] a');
		elLink.setProperty('href', arrBomLinks[index]);
		
		
	});
	
}

function siblingNavigatorNavigate(variant){
	if(isString(variant)){
		//alert(variant);
		if(variant!="#")location.replace(variant);
	}else{
		//alert(variant.value);
		location.replace(variant.value);
	}
}

var intAuditorsMarkTimerId;

function auditorsMarkPopupShow(){
	var objButton=$('far-auditors-mark-logo');
	var objPopup=$('far-auditors-mark-popup');
	
	objPopup.removeEvents('mouseleave')
	objPopup.removeEvents('mouseenter')
	objButton.removeEvents('mouseleave')
	
	objPopup.setStyle("display", "inline");
	bolPopupOpen=true;
	
	//calculate the position of the popup
	var objButtonPosition=objButton.getPosition();
	var intTop=objButtonPosition.y+27;
	var intLeft=objButtonPosition.x-10;
	objPopup.setStyles({
	   left: intLeft,
	   top: intTop
	});
	
	objPopup.addEvent('mouseleave', auditorsMarkPopupClose);
	objPopup.addEvent('mouseenter', function(){
		if($defined(intAuditorsMarkTimerId)){
			$clear(intAuditorsMarkTimerId); 
		}
	});
	objButton.addEvent('mouseleave', function(){
		intAuditorsMarkTimerId=auditorsMarkPopupClose.delay(500)
	});
}

function downloadFile(strUrl){
	//alert('in download file script '+strUrl);
	var strDownloadUrl="/tools/stream.asp?file=";
	hitStatisticsServer(strUrl);
	strDownloadUrl+=strUrl.split('?')[0];
	location.href=strDownloadUrl;
}

function auditorsMarkPopupClose(){
	$('far-auditors-mark-popup').setStyle("display", "none");
}

function retrieveIfrsInfo(){
	/*
	Retrieves the content of the ifrs landing page by an ajax request to the child page
	*/
	var strChildPageUrl="/pages/notes_to_the_ifrs_financial_statements.asp";
	var strHtmlIfrs=serverSideRequest({url: strChildPageUrl, method: 'get'});
	//alert(strHtmlIfrs);
	
	//retrieve the body copy text
	var elDivTemp=$("far-contentbucket");
	elDivTemp.setHTML(strHtmlIfrs);
	var elIfrsBodyTextTable=elDivTemp.getElement('table[id=far-single-col]');
	var elMainImageTable=elIfrsBodyTextTable.getElement('table');
	elMainImageTable.setStyle('display', 'none');
	
	var arrLinks=elIfrsBodyTextTable.getElements('a');
	arrLinks[0].setText('The Philips Group');
	arrLinks[3].setProperty('href', '/pages/supervisory_board_report.asp?origin=leftnav#section(1)');
	
	
	
	//alert(elIfrsBodyTextTable.innerHTML);
	
	//inject in the page
	elIfrsBodyTextTable.injectInside('far-maincontent');
	
}


/* SEARCH */
/*
Search Form
*/
function processSearchForm(){
	if (document.finderForm.searchKey.value == null || document.finderForm.searchKey.value == "" || document.finderForm.searchKey.value == "Enter name or keyword"){
		alert ("Please enter name or keyword.");			
	}else{
		//fill the values from this form in the search form and submit this form
		document.searchForm.q.value=document.finderForm.searchKey.value;
		//document.searchForm.chapter.value=getFormFieldValue(MM_findObj('far-searchselectchapter'));
		//alert(getFormFieldValue(MM_findObj('far-searchselectchapter')));
		document.searchForm.submit();
	}
	return false;
}

function setFieldValue(fieldRef, str) {
	// clears field when user clicks in, 
	// and resets to default str when user clicks out 
	// with no value in the field.
	obj = eval(fieldRef);
	if (obj.value == str) {
		obj.value = "";
	}
	else if (obj.value == "") {
		obj.value = str;
	}
}

/*
Search scripts
*/
function searchExecute(){
	//executes the search by performing an ajax request to a .NET module
	var arrFormData=new Array();
	var strHtml, strUrl="/tools/search_results.aspx";
	var strQueryString=Right(location.search, location.search.length-1);
	strQueryString=strQueryString.replace(/chapter/,"c");
	//strQueryString=strQueryString.replace(/\+/gi, " ");
	//strQueryString=encodeUrl(strQueryString)
	arrFormData['strQueryString']=strQueryString;
	//alert(strQueryString);
	strHtml=serverSideRequest({url: strUrl, callback: 'searchDisplayResults()', arrdata: arrFormData, method: 'post'});
	
	//setFieldValue('document.finderForm.searchKey','yoooo')
	
	document.finderForm.searchKey.value=retrieveQuerystringParameterValue(location.search, "q").replace(/\+/gi, " ");
	//setFormFieldValueById('far-searchselectchapter', retrieveQuerystringParameterValue(location.search, "chapter").replace(/\+/gi, " "));
}

function submitCorrected(strQuery){
	strUrl=replaceQuerystringParameter(location.href, "q", strQuery);
	location.replace(strUrl);
}


function searchDisplayResults(strHtml){
	//alert(strHtml)
	MM_setTextOfLayer('div_search_result','',strHtml);
}

/*
Print script
*/
_page.printVersionFar = function(print_type) {
	var printarea = document.getElementById("p-printarea");
	if (printarea == null) {
		alert("no print area defined");
		return;
	}	
	
	/*
	FAR UNIQUE
	*/
	var printarea = document.getElementById("p-printarea");
	var strPageContent=printarea.innerHTML;
	//openDebugWindow(strPageContent);
	var strPageContentNew='', strPageFlashJavascriptParams;
	//alert('in');
	var strOnLoadScript='setTimeout(\'printThisPage()\', 2000);';
	//strOnLoadScript='';
	
	//rework the page content
	//1) flash elements - remove the inline script nodes that generate the flash files
	strPageContentNew=strPageContent.replace(/<script type="?text.javascript"?>writeFlashHtml.*?<\/script>/gim, "");
	//openDebugWindow(strPageContentNew);
	
	//2) back to top links
	strPageContentNew=strPageContentNew.replace(/<span.*?<a href="?javascript:scrollTop\(\);"?>Back to top<\/a>&nbsp;<\/span>/gim, "");
	
	//3) hidden pagination divs (IE only)
	strPageContentNew=strPageContentNew.replace(/<DIV class=far-wrapper-text .*?style="DISPLAY: none"/gim, "<DIV class=far-wrapper-text style='width:100%'");
	strPageContentNew=strPageContentNew.replace(/<div.*?class="far-wrapper-text"/gim, "<div class=\"far-wrapper-text\" style=\"width:100%\"");
	
	//4) pagination component
	strPageContentNew=strPageContentNew.replace(/<!-- begin pagination -->/gim, "<!--");
	strPageContentNew=strPageContentNew.replace(/<!-- end pagination -->/gim, "-->");
	
	//5) sifr alternate
	strPageContentNew=strPageContentNew.replace(/<span.*?sIFR-alternate.*?<\/span>/gim, "");
	
	
	// Create privacy footer
	var crsc = _page.crsc_server;
	var privacy_footer = _page.text["footer"];
	privacy_footer = privacy_footer.replace("{BR}", "<br />");
	privacy_footer = privacy_footer.replace("{COPYRIGHT}", _page.text["copyright"]);
	privacy_footer = privacy_footer.replace("{PRIVACY}", "<a href=\""+_page.link["privacy"]+"\">"+_page.text["privacy"]+"</a>");
	privacy_footer = privacy_footer.replace("{OWNER}", "<a href=\""+_page.link["owner"]+"\">"+_page.text["owner"]+"</a>");
	privacy_footer = privacy_footer.replace("{TERMS}", "<a href=\""+_page.link["terms"]+"\">"+_page.text["terms"]+"</a>");
	privacy_footer = privacy_footer.replace("| {SITEMAP}", "");
	privacy_footer = privacy_footer.replace("{CAREERS} | ","");
	var print_body = '';
	print_body += '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"\n';
	print_body += '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n';
	print_body += '<html xmlns="http://www.w3.org/1999/xhtml">\n';
	print_body += '<head>\n';
	print_body += '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />\n';
	if(_page.headerType == "external_extranet") {
		// No global stylesheet when using external extranet
		var stylesheet_externalextranet = "	<link rel=\"stylesheet\" type=\"text/css\" href=\""+_page.crsc_server+"/crsc/styles/external_extranet.css\" />\n";
		print_body += stylesheet_externalextranet;
	} else {
		print_body += '  <link href="'+_page.crsc_server + '/crsc/styles/global.css" type="text/css" rel="stylesheet" />\n';
	}
	print_body += '  <link href="'+_page.crsc_server + '/crsc/styles/components.css" type="text/css" rel="stylesheet" />\n';
	print_body += '  <link href="'+_page.crsc_server + '/crsc/styles/print.css" type="text/css" rel="stylesheet" />\n';
	if(_page.direction=="rtl"){
		print_body += '  <link href="'+_page.crsc_server + '/crsc/styles/rtl.css" type="text/css" rel="stylesheet" />\n';
	}
	print_body += '  <link media="print" href="'+_page.crsc_server + '/crsc/styles/printbrowser.css" type="text/css" rel="stylesheet" />\n';
	// Adjust styles of some locales
	if(_page.locale) {
		if(_page.locale.substring(3,5)=="zh" || _page.locale.substring(3,5)=="ja" || _page.locale.substring(3,5)=="ko"){
			// Add extra stylesheet for Chinese and Japanese and Korean locales
			print_body += "<link rel=\"stylesheet\" type=\"text/css\" href=\""+_page.crsc_server+"/crsc/styles/zh_ja.css\" />\n";
		}
		else if(_page.locale.substring(3,5)=="th"){
			// Add extra stylesheet for Thai locales
			print_body += "<link rel=\"stylesheet\" type=\"text/css\" href=\""+_page.crsc_server+"/crsc/styles/th.css\" />\n";
		}
		else if(_page.locale.substring(3,5)=="ru"){
			// Add extra stylesheet for russian locales
			print_body += "<link rel=\"stylesheet\" type=\"text/css\" href=\""+_page.crsc_server+"/crsc/styles/ru.css\" />\n";
		}
	}	
	
	/*
	FAR UNIQUE
	*/
	print_body += '  <link href="/styles/far_styles.css" media="screen" rel="stylesheet" type="text/css" />';
	print_body += '  <link href="/styles/far_styles-print.css" media="screen" rel="stylesheet" type="text/css" />';
	print_body += '  <link rel="stylesheet" href="/styles/sIFR_styles.css" type="text/css" media="all" />';
	print_body += '  <link href="/styles/far_crsc-overwrite.css" media="screen" rel="stylesheet" type="text/css"/>';
	print_body += '<script type="text/javascript" language="javascript">var arrQuoteClass=[];</script>';
	print_body += '<script type="text/javascript" language="javascript" src="/scripts/mootools_full_compressed.js">//</script>';
	print_body += '<script type="text/javascript" language="javascript" src="/scripts/far_scripts-printpage.js">//</script>';
	
	
	print_body += '	<title>'+document.title+'</title>';
	print_body += '</head>\n';
	print_body += '<body style="direction:'+_page.direction+'" onload="'+strOnLoadScript+'">\n';
	print_body += '	<div class="p-printcontainer">\n';
	print_body += '  	<div class="p-print-logo"><img alt="Philips" src="'+_page.crsc_server + '/crsc/images/mainlogo.gif" /></div>\n';
	if(print_type=='press'){
		print_body += '  	<div class="p-print-press"><img alt="Press information" src="'+_page.crsc_server + '/crsc/images/pressrelease_header.gif" /></div>\n';
	} else {
		print_body += '  	<div class="p-line"><img alt="" src="'+_page.crsc_server + '/crsc/images/solidline.gif" /></div>\n';
	}
	
	
	
	print_body += '  	<div id="p-grid-c">'+strPageContentNew+'</div>\n';
	
	
	
	print_body += '  	<div class="p-line"><img alt="" src="'+_page.crsc_server + '/crsc/images/solidline.gif" /></div>\n';
	print_body += '  	<div class="p-print-footer">\n';
	print_body += '  	  ' + privacy_footer +'\n';
	print_body += '		</div>\n';
	print_body += '	</div>\n';
	print_body += '</body></html>\n';
	// Create popup window
	var wHeight=500;
	var wWidth=700;
	var w=window.open('','','height='+wHeight+',width='+wWidth+',toolbar=yes,scrollbars=yes')
	// Center popup window
	var sWidth = parseInt(gsW());
	var sHeight = parseInt(gsH());
	if( sWidth>0&&sHeight>0 ){w.moveTo(Math.round((sWidth-wWidth)/2),Math.round((sHeight-wHeight)/2))};
	if( w.focus ) { w.focus(); }
	w.document.open();
	w.document.write(print_body);
	w.document.close();
};

function setupSupervisoryBoardNoteLinks(){
	/*
	Generates links from the asterixes to the descriptions
	*/
	var arrNodes=$$('h6.far-block-h5-sub');
	arrNodes.each(function(el){ 
		//alert(el.getText());
		var strNodeText=el.getText();
		if(strNodeText.indexOf("*")>0){
			var strDivText="";

			if(strNodeText.indexOf("** ***")>0)strDivText="** ***";
			if(strDivText==""){
				if(strNodeText.indexOf("***")>0)strDivText="***";
			}
			if(strDivText==""){
				if(strNodeText.indexOf("**")>0)strDivText="**";
			}
			if(strDivText==""){
				if(strNodeText.indexOf("*")>0)strDivText="*";
			}
			
			var arrTemp=strNodeText.split("*");
			strNodeText=arrTemp[0];					
			
			//set the text
			el.setText(strNodeText);
			
			//create the div element
			var elSpan=new Element('span', {
				'styles': {
					'cursor': 'pointer'
				},
				'events': {
					'click': function(){
						scrollTo(0,10000000);
					}
				}
			});
			
			elSpan.setText(strDivText);
			
			elSpan.injectInside(el);

		}
		
	}); 
}

/**
 * PopUp
 * - Needs an element to be connected with the PopUp
 * - Based on Mootools.v1.1 
 *
 */

var currPopup; 
var currPopupMouseOver = false;
var currPopupOpen = false;
var currPopupHandle;


function setPopup(handle, popup, offset, showEvent) {			
	
	// Set events
	handle.addEvent(showEvent, function(){ 	

		if (currPopupOpen){
			hidePopup(); 
			currPopupOpen = false;
		} else {
			// Retrieve positions
			var pos = {'x': handle.getPosition()['x'] + offset['x'], 'y': handle.getPosition()['y'] + offset['y']};
			//var pos = {'x': handle.getPosition()['x'] + offset['x'], 'y': handle.getPosition()['y'] - popup.getSize()['size']['y'] + offset['y']};
			
			//debugObject({obj: pos})

			// Set positions
			popup.setStyles({'top': pos['y'] + 'px','left': pos['x'] + 'px'}); // Assign the positions
			
			//alert(currPopup);
			if (currPopup != null) currPopup.setStyle('visibility', 'hidden');
			currPopup = popup;
			currPopupHandle = this.getElement('li');
			showPopup(); // Show the popup	
			currPopupOpen = true;

			handle.addEvent('mouseleave', function(){ hidePopup.delay(500, this); });
		}
	});	

	popup.addEvent('mouseenter', function() {
		currPopupMouseOver = true;
		popup.addEvent('mouseleave', function() {	
			currPopupMouseOver = false;
			handle.removeEvents('mouseleave');
			hidePopup();
		});
	});
}

function showPopup() {
	if (currPopup != null) currPopup.setStyle('visibility', 'hidden');
	if (currPopupHandle != null) currPopupHandle.addClass('open');

	currPopup.setStyle('visibility','visible');
}

function hidePopup() {
	if (!currPopupMouseOver) {
		if (currPopupHandle != null) currPopupHandle.removeClass('open');
		currPopup.setStyle('visibility','hidden');
		currPopupOpen = false;
	}
}

/**
 * ToolTip - static tooltip
 * - Needs an element to be connected with the tip
 * - Based on Mootools.v1.1 
 *
 */

var currTooltip;
var currTooltipHandle;
var currTooltipMouseOver = false;

function setToolTips() {	
	var el = $('far-toolbar');
	
	if (el)	{
		var arr = el.getElements('a');

		if (arr.length > 0) {
			//var htmlStart = '<div class="far-popup-small-wrapper"><div class="far-top-shadow-small"></div><table cellspacing="0" class="far-p-small-content" ><tr><td class="p-center" align="center" style="vertical-align:middle;"><p class="far-p-h5">';
			var html, strId;
			var htmlEnd = '</p></td></table><div class="far-bottom-shadow-small"></div></div>';
			var bPopup = false;
			
			var offset = {'x': -67, 'y': -1};
			if (window.ie) offset = {'x': -67, 'y': 30};
			if (window.webkit) offset = {'x': -67, 'y': 10};
			
			arr.each(function(item){
				strId=item.id;
				switch(strId){
					case "toolbar_fontenlarge":
						html = '<div class="far-popup-small-larger"></div>';
						break;
					case "toolbar_fontreduce":
						html = '<div class="far-popup-small-smaller"></div>';
						break;
					case "toolbar_print":
						html = '<div class="far-popup-small-print"></div>';
						break;
					case "toolbar_email":
						html = '<div class="far-popup-small-mail"></div>'
						break;
					case "toolbar_download":
						var downloadsHtml = $('far-toolbar-downloads').innerHTML;
						var html = '<div class="far-popup-large-wrapper"><div class="far-top-shadow-large"></div><table cellspacing="0" class="far-p-large-content" ><tr><td class="far-download-content"><p class="far-p-h-dl">Download</p>' + downloadsHtml + '</td></tr></table><div class="far-bottom-shadow-large"></div></div>';	
						
						bPopup = true;
						offset =  {'x': -183, 'y': 1};
						if (window.ie) offset = {'x': -183, 'y': 24};
						if (window.webkit) offset = {'x': -183, 'y': 12};
						break;
					
				}
				setTooltip(item, html, offset, 'mouseenter', bPopup);

			});
			

		}
	}

	//var years = $('far-overview-table');
	var years = $('far-overview-container');
	if(years){
		years.getElements('.first-row').each(function(el){
			setFarToolTip(el);
		});

		years.getElements('.far-numeric-data').each(function(el){
			setFarToolTip(el);
		});
	}

	

	var tdInfo = $('far-overview-info');
	if(tdInfo){
		tdInfo.getElements('.info').each(function(el){
			setFarToolTip(el);
		});
	}
}

function setFarToolTip(el) {
	var innerHtml, html, strId, strNewCopy, elHandle, arrSups;
	var bPopup = false;

	strNewCopy = "";
	
	arrSups = el.getElements('sup.far-note');
	arrSups.each(function(el){
		strNewCopy = strNewCopy + '<span>' + el.getProperty('title') + '</span>';
		el.setProperty('title', '');
	});
	
	if(strNewCopy != "") {
		var popup = $('popup-10y'); 
		popup.getElement('.far-content-copy-10y').setHTML(strNewCopy);
		html = popup.innerHTML;

		bPopup = false;
		var offset = {'x': -60, 'y': el.getSize()["size"]["y"]};
		if(window.ie){
			offset = {'x': -60, 'y': el.getSize()["size"]["y"] - 1};
		} else if (window.gecko)
		{
			offset = {'x': -60, 'y': el.getSize()["size"]["y"]};
		}

		setTooltip(el, html, offset, 'mouseenter', bPopup);
	}
	strNewCopy = "";
}

function setTooltip(handle, html, offset, showEvent, popup) {
	// Set the html
	var tooltip = new Element('div').setStyles({
		'position': 'absolute',
		'z-index': '999',
		'visibility': 'hidden'
	}).setHTML(html).injectInside(document.body);


	if (popup) {	
		// Set events
		handle.addEvent(showEvent, function(){ 	
			// Retrieve positions
			var pos = {'x': handle.getPosition()['x'] + offset['x'], 'y': handle.getPosition()['y'] + offset['y']};

			// Set positions
			tooltip.setStyles({'top': pos['y'] + 'px','left': pos['x'] + 'px'}); // Assign the positions

			if (currTooltip != null) currTooltip.setStyle('visibility', 'hidden');
			currTooltip = tooltip;
			currTooltipHandle = this;

			showTooltip(); // Show the popup	
			
			handle.addEvent('mouseleave', function(){
				hideTooltip.delay(600, this);
			});
		});	

		tooltip.addEvent('mouseenter', function() {
			currTooltipMouseOver = true;
			tooltip.addEvent('mouseleave', function() {	
				currTooltipMouseOver = false;
				handle.removeEvents('mouseleave');
				hideTooltip();
			});
		});
	} else {
		// Set events
		handle.addEvent(showEvent, function(){ 				
			// Retrieve positions
			var pos = {'x': handle.getPosition()['x'] + offset['x'], 'y': handle.getPosition()['y'] + offset['y']};

			// Set positions
			tooltip.setStyles({'top': pos['y'] + 'px','left': pos['x'] + 'px'}); // Assign the positions

			if (currTooltip != null) currTooltip.setStyle('visibility', 'hidden');
			currTooltip = tooltip;
			currTooltipHandle = this;
			showTooltip(); // Show the popup				
		});	

		handle.addEvent('mouseleave', function() {
			hideTooltip();
		});
	}
}

function showTooltip() {
	if (currTooltip != null) currTooltip.setStyle('visibility', 'hidden');
	if (currTooltipHandle != null) currTooltipHandle.addClass('open');

	currTooltip.setStyle('visibility','visible');
}

function hideTooltip() {
	if (!currTooltipMouseOver) {
		if (currTooltipHandle != null) currTooltipHandle.removeClass('open');
		if (currTooltip != null) currTooltip.setStyle('visibility','hidden');
	}
}
