/*
FAR client side scripts
*/

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) {
		//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
}

function showDownloadsPopup(){
	if(intTimerId3)window.clearTimeout(intTimerId3);
	bolDelay=false;
	var strHtml='';
	var strNotePopupContentId="far-popup_content";
	var objDownloadsContentLayer=MM_findObj("far-foldoutdownloads");
	var objClicked=MM_findObj("far-downloadscell");
	
	var objFarPopup=MM_findObj(strFarPopupId);
	//generate the table with the content
	strHtml+='<table cellspacing="0" class="far-popup_content-caption">';
	strHtml+='<tr valign="top">';
	strHtml+='<td>';
	strHtml+=objDownloadsContentLayer.innerHTML;
	strHtml+='</td>';
	strHtml+='</tr>';
	strHtml+='</table>';
	//fill the popup with content	
	MM_setTextOfLayer(strNotePopupContentId,'',strHtml);		
	//set the background color
	MM_findObj(strNotePopupContentId).style.background="#ececec";
	//position
	var intDivPosX=findPosX(objClicked);
	var intDivPosY=findPosY(objClicked);	
	intDivPosX=intDivPosX-8;
	intDivPosY=intDivPosY+17;			
	objFarPopup.style.top = intDivPosY+'px';
	objFarPopup.style.left = intDivPosX+'px';
	//show
	objFarPopup.style.visibility='visible';
}

/*
Notes popups
*/
function showNotePopup(objClicked){
	if(intTimerId3)window.clearTimeout(intTimerId3);
	bolDelay=false;
	var strClickedHtml=objClicked.innerHTML;
	strClickedHtml=strClickedHtml.replace(/,/,'');
	var strNoteContentId="far-note_content-"+strClickedHtml, strHtml='';
	
	//the content of the note
	var arrCurrentNoteData=arrNotesData[strClickedHtml].split('|');
	var strNotesCategory=arrCurrentNoteData[0];
	var strNoteNr=strClickedHtml;
	var strNoteTitle="Note "+strNoteNr+": "+arrCurrentNoteData[2];
	var strNoteUrl=arrCurrentNoteData[1]+"?origin=notepopup";
	
	var strNotePopupContentId="far-popup_content";
	var objFarPopup=MM_findObj(strFarPopupId), objNoteContent=MM_findObj(strNoteContentId);
	//generate the table with the content
	strHtml+='<table cellspacing="0" class="far-popup_content-notes">';
	strHtml+='<tr valign="top">';
	strHtml+='<td>';
	//strHtml+=objNoteContent.innerHTML;
	strHtml+='<h3>'+strNoteTitle+'</h3>';
	//strHtml+='<b>'+strNotesCategory+'</b>';
	strHtml+='</td>';
	strHtml+='<td><img src="/imgs/syst/t.gif" width="1" height="40" alt="" /></td>';
	strHtml+='</tr>';
	strHtml+='<tr valign="top">';
	//strHtml+='<td><a href="'+objNoteContent.getAttribute("url")+'" style="color: white">Click here to read the full note</a></td>';
	strHtml+='<td><a href="'+strNoteUrl+'" style="color: white">Click here to read the full note</a></td>';
	strHtml+='<td><img src="/imgs/syst/t.gif" width="1" height="20" alt="" /></td>';
	strHtml+='</tr>';
	strHtml+='</table>';
	//fill the popup with content	
	MM_setTextOfLayer(strNotePopupContentId,'',strHtml);
	//set the background color
	MM_findObj(strNotePopupContentId).style.background=strColorHex;

	//position the popup
	var strClickedObjectX=findPosX(objClicked)+1+'px';
	var strClickedObjectY=findPosY(objClicked)-objFarPopup.offsetHeight+4+'px';
	objFarPopup.style.top=strClickedObjectY;
	objFarPopup.style.left=strClickedObjectX;
	
	if(strObjClickedId==strNoteContentId){
		if(objFarPopup.style.visibility=='visible'){
			objFarPopup.style.visibility='hidden';
		}else{		
			objFarPopup.style.visibility='visible';
		}
	}else{
		objFarPopup.style.visibility='visible';
	}		
	
	strObjClickedId=strNoteContentId;
}

//iframe hack
function iframeHackVisible(bolShow, objMasterDiv){
	var objIframe = document.getElementById('far-iframehack'); 
	if(bolShow)	{ 
		objMasterDiv.style.display = "block"; 
		objIframe.style.width = objMasterDiv.offsetWidth; 
		objIframe.style.height = objMasterDiv.offsetHeight; 
		objIframe.style.top = objMasterDiv.style.top; 
		objIframe.style.left = objMasterDiv.style.left; 
		objIframe.style.zIndex = objMasterDiv.style.zIndex - 1; 
		objIframe.style.display = "block"; 
	}else{ 
		objIframe.style.display = "none";
		objMasterDiv.style.display = "none"; 
	} 
}

/*
FAR popup
*/
function hideFarPopup(){
	intTimerId3=setTimeout("hideFarPopupExecute()",50);
}

function hideFarPopupExecute(){
	objClicked=MM_findObj(strFarPopupId);
	objClicked.style.visibility='hidden';
	bolDelay=false;
}

function cancelHideFarPopup(){
	if(intTimerId3)window.clearTimeout(intTimerId3);
	bolDelay=false;
	objClicked=MM_findObj(strFarPopupId);
	objClicked.parentNode.style.visibility='visible';
}

function hideFarPopupDelayed(){
	//alert(bolDelay);
	if(!bolDelay){
		intTimerId3=setTimeout("hideFarPopupExecute()",800);	
		bolDelay=true;
	}
}

function debugText(str){MM_setTextOfLayer("debuglayer",'',str);}

/*
Layer positioning
*/
function setLyr(obj,lyr)
{
  var newX = findPosX(obj);
  var newY = findPosY(obj);
  var x;
  if(isString(lyr)){
	  x = new getObj(lyr);
	}else{
		x = lyr;
	}
  x.style.top = newY;
  x.style.left = newX;
}

function findPosX(obj)
{
  var curleft = 0;
  if (obj.offsetParent)
  {
    while (obj.offsetParent)
    {
      curleft += obj.offsetLeft
      obj = obj.offsetParent;
    }
  }
  else if (obj.x)
    curleft += obj.x;
  return curleft;
}

function findPosY(obj)
{
  var curtop = 0;
  var printstring = '';
  if (obj.offsetParent)
  {
    while (obj.offsetParent)
    {
      printstring += ' element ' + obj.tagName + ' has ' + obj.offsetTop;
      curtop += obj.offsetTop
      obj = obj.offsetParent;
    }
  }
  else if (obj.y)
    curtop += obj.y;
  //window.status = printstring;
  return curtop;
}


function getObj(name)
{
 if (document.getElementById)
 {
     this.obj = document.getElementById(name);
     this.style = document.getElementById(name).style;
 }
 else if (document.all)
 {
     this.obj = document.all[name];
     this.style = document.all[name].style;
 }
 else if (document.layers)
 {
     if (document.layers[name])
     {
      this.obj = document.layers[name];
      this.style = document.layers[name];
     }
     else
     {
      this.obj = document.layers.testP.layers[name];
      this.style = document.layers.testP.layers[name];
     }
 }
}

/*
Financial
*/
function graphEnterEnlargedModeGridD(strId){
	//this function will reload this page in enlarged mode (using grid-d)
	var strUrl=_page.leftNav[strPageId+'_1'].link;
	strUrl=replaceQuerystringParameter(strUrl, 'graphid', strId);
	strUrl=replaceQuerystringParameter(strUrl, 'parentid', strPageId);
	strUrl=replaceQuerystringParameter(strUrl, 'refferersystemid', strPageIdSystem);
	location.href=strUrl;
}

function graphShow(strId){
	//async request to get the graph content
	var strUrl=location.href;
	strUrl=removeQuerystringParameter(strUrl, "origin")
	strUrl=replaceQuerystringParameter(strUrl, 'graphid', strId);
	location.href=strUrl;
}

function graphOverview(){
	//go back to the overview page (the page without parameters)
	location.href=_page.leftNav[strPageId].link;
}

/*
Used in navigation
*/
function navigateToParentPage(){
	var strParentPageId=strPageId.replace(/(.*)_.*/,"$1");
	if(location.href.indexOf('notes')>0){
		//alert('ww');
		//strParentPageId=strParentPageId.replace(/(.*)_.*/,"$1");
	}
	var strParentUrl=_page.leftNav[strParentPageId].link;
	location.href=strParentUrl;	
}

/*
Image captions
*/
function showCaptionPopup(objClicked){
	if(intTimerId3)window.clearTimeout(intTimerId3);
	bolDelay=false;
	var strHtml='';
	var strNotePopupContentId="far-popup_content";
	var strPopupCustomAlignment="", strImageId;
	var arrTemp;
	
	var strClickedObjectId=objClicked.id;
	arrTemp=strClickedObjectId.split("_");
	if(arrTemp.length>0){
		strImageId="img_"+arrTemp[1];
		var strImageCaptionObjectId="far-imagecaption_"+arrTemp[1];
		var objImageCaption=MM_findObj(strImageCaptionObjectId);
		
		var objFarPopup=MM_findObj(strFarPopupId);
		//generate the table with the content
		strHtml+='<table cellspacing="0" class="far-popup_content-caption">';
		strHtml+='<tr valign="top">';
		strHtml+='<td>';
		strHtml+=objImageCaption.innerHTML;
		strHtml+='</td>';
		strHtml+='</tr>';
		strHtml+='</table>';
		//fill the popup with content	
		MM_setTextOfLayer(strNotePopupContentId,'',strHtml);		
		//set the background color
		MM_findObj(strNotePopupContentId).style.background="#ececec";
		
		//find out alignment of image
		strImageAlignment="right";
		if(objImageCaption.parentNode.className=="p-image-left")strImageAlignment="left";
		
		if(!isUndefined(arrCustomImageHotspots[strPageIdSystem])){
			arrImageDeltaInfo=arrCustomImageHotspots[strPageIdSystem].split('|');
			strImageDeltaId=arrImageDeltaInfo[0];
			if(strImageDeltaId==strImageId){
				if(arrImageDeltaInfo.length>3){
					strPopupCustomAlignment=arrImageDeltaInfo[3];
					//alert(strPopupCustomAlignment)
				}
			}
		}
		
		//alert(strImageAlignment);
		var intDivPosX=findPosX(objClicked);
		var intDivPosY=findPosY(objClicked);
		
		if(strPopupCustomAlignment==""){	
			if(strImageAlignment=="right"){
				intDivPosX=intDivPosX-objFarPopup.offsetWidth-0;
				intDivPosY=intDivPosY-objFarPopup.offsetHeight+10;
			}else{
				intDivPosX=intDivPosX+15;
				intDivPosY=intDivPosY-objFarPopup.offsetHeight+10;
			}
		}else{
			switch(strPopupCustomAlignment){
				case "lefttop":
					intDivPosX=intDivPosX-objFarPopup.offsetWidth-0;
					intDivPosY=intDivPosY-objFarPopup.offsetHeight+10;					
					break;
				case "righttop":
					intDivPosX=intDivPosX+15;
					intDivPosY=intDivPosY-objFarPopup.offsetHeight+10;	
					break;
				case "leftbottom":
					intDivPosX=intDivPosX-objFarPopup.offsetWidth-0;
					intDivPosY=intDivPosY+15;					
					break;
				case "rightbottom":
					intDivPosX=intDivPosX+15;
					intDivPosY=intDivPosY+15;					
					break;			
			}
		}
		
		objFarPopup.style.top = intDivPosY+'px';
		objFarPopup.style.left = intDivPosX+'px';	
		objFarPopup.style.visibility='visible';	
	}
}



function setImageHotspots(){
	/*
	This function creates small div hotspots that will show or hide the image captions
	*/
	//1
	var arrImages=document.getElementsByTagName("img"), arrTemp;
	var objImage, strDebug="", intImageWidth, intImageHeight, intImagePosX, intImagePosY, intDivPosX, intDivPosY, objHotspotCloned
	var strImageId, strImageDeltaId, arrImageDeltaInfo, strImageCaptionId;
	var strImageAlignment, strHotspotPreValue="far-image-hotspot_";
	var intCounter=0, intDeltaX=0, intDeltaY=0;
	var bolPageWithHotspots=false;

	var objHotspot=MM_findObj("far-image-hotspot_"+intCounter);
	
	for (var i=0;i<arrImages.length;i++){
		objImage=arrImages[i];
		//alert(strImageId);
		//strDebug+=", "+objImage.id+" - "+objImage.id.indexOf("img_");
		if(objImage.id.indexOf(strContentImageIdPrefix)>-1){
			arrTemp=objImage.id.split("_");
			intCounter=arrTemp[1];			
			//test if this image has a caption
			if(isObject(MM_findObj("far-imagecaption_"+intCounter))){			
				bolExecuteClientDimensionCheck=true;
				
				//clone the hotspot div
				if(!isObject(MM_findObj("far-image-hotspot_"+intCounter))){
					objHotspotCloned=objHotspot.cloneNode(true);
					objHotspotCloned.id="far-image-hotspot_"+intCounter;
					objBodyNode.appendChild(objHotspotCloned);	
				}else{
					objHotspotCloned=MM_findObj("far-image-hotspot_"+intCounter);
				}
				
				if(!isUndefined(arrCustomImageHotspots[strPageIdSystem])){
					arrImageDeltaInfo=arrCustomImageHotspots[strPageIdSystem].split('|');
					strImageDeltaId=arrImageDeltaInfo[0];
					if(strImageDeltaId==objImage.id){
						intDeltaX=parseFloat(arrImageDeltaInfo[1]);
						intDeltaY=parseFloat(arrImageDeltaInfo[2]);
					}else{
						intDeltaX=0;
						intDeltaY=0;
					}
					//alert(intDeltaX+" - "+intDeltaY);
				}
				
				//strDebug+=", "+objImage.id+" width:"+objImage.offsetWidth;
				
				//information about the image
				intImageWidth=objImage.offsetWidth;
				intImageHeight=objImage.offsetHeight;
				intImagePosX=findPosX(objImage);
				intImagePosY=findPosY(objImage);
				
				intDivPosX=intImagePosX+intImageWidth+intDeltaX-35;
				intDivPosY=intImagePosY+intImageHeight+intDeltaY-24;
				objHotspotCloned.style.top=intDivPosY+'px';
	  		objHotspotCloned.style.left=intDivPosX+'px';
	  		objHotspotCloned.style.display='inline';
	  	}
		}		
	}
	//debugText(strDebug)
	

}

/*
Print script
*/
_page.printVersionFar = function(print_type) {
	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(); }
	
	// Create privacy footer
	var crs = _page.crsc_server;
  
	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}", "");
	
	var printarea = document.getElementById("p-printarea");
	var strPageContent=printarea.innerHTML;
	var strPageContentNew='', strPageFlashJavascriptParams;
	var strOnLoadScript='window.print();setTimeout(\'window.close()\', 5000);';
	//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, "");
	
	if (printarea == null) {
		alert("no print area defined");
	} 
	else {
		w.document.open();
		w.document.write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"\n');
		w.document.write('"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n');
		w.document.write('<html xmlns="http://www.w3.org/1999/xhtml">\n');
		w.document.write('<head>\n');
		w.document.write('<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=\"http://www.crsc.philips.com/crsc/styles/external_extranet.css\" />\n";
			w.document.write(stylesheet_externalextranet);
		} else {
			w.document.write('  <link href="http://www.crsc.philips.com/crsc/styles/global.css" type="text/css" rel="stylesheet" />\n');
		}
		w.document.write('  <link href="http://www.crsc.philips.com/crsc/styles/components.css" type="text/css" rel="stylesheet" />\n');
		w.document.write('  <link href="http://www.crsc.philips.com/crsc/styles/print.css" type="text/css" rel="stylesheet" />\n');
		w.document.write('  <link href="/styles/far_styles.css" media="screen" rel="stylesheet" type="text/css" />\n');
		w.document.write('  <link href="/styles/table_style.css" media="screen" rel="stylesheet" type="text/css" />\n');
		w.document.write('  <link rel="stylesheet" href="/styles/sIFR-print.css" type="text/css" media="all" />\n');
		w.document.write('  <link rel="stylesheet" href="/styles/sIFR_styles.css" type="text/css" media="all" />\n');
		w.document.write('  <link href="/styles/far_crsc-overwrite.css" media="screen" rel="stylesheet" type="text/css"/>\n');
		
		if(_page.direction=="rtl"){
			w.document.write('  <link href="http://www.crsc.philips.com/crsc/styles/rtl.css" type="text/css" rel="stylesheet" />\n');
		}
		w.document.write('	<title>'+document.title+'</title>');
		w.document.write('</head>\n');
		w.document.write('<body style="direction:'+_page.direction+'" onload="'+strOnLoadScript+'">\n');
		w.document.write('	<div class="p-printcontainer">\n');
		w.document.write('  	<div class="p-print-logo"><img alt="Philips" src="http://www.crsc.philips.com/crsc/images/mainlogo.gif" /></div>\n');
		if(print_type=='press'){
			w.document.write('  	<div class="p-print-press"><img alt="Press information" src="http://www.crsc.philips.com/crsc/images/pressrelease_header.gif" /></div>\n');
		} else {
			w.document.write('  	<div class="p-line"><img alt="" src="'+_page.crsc_server + '/crsc/images/solidline.gif" /></div>\n');
		}
		w.document.write('  	<div id="p-grid-c">'+strPageContentNew+'</div>\n');
		w.document.write('  	<div class="p-line"><img alt="" src="http://www.crsc.philips.com/crsc/images/solidline.gif" /></div>\n');
		w.document.write('  	<div class="p-print-footer">\n');
		w.document.write('  	  ' + privacy_footer +'\n');
		w.document.write('		</div>\n');
		w.document.write('	</div>\n');
		w.document.write('</body></html>\n');
		w.document.close();
	} 	
};


/*
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});
	
	//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);
}

/*
Statistics
*/
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 trackLeadershipFlash(strPerson, strFlashId){
	var strFakeUrl="/leadership/"+strFlashId+"?person="+escape(strPerson);
	//alert("sending following fake url to the sage statistics server:\n"+strFakeUrl);
	hitStatisticsServer(strFakeUrl)
}

function hitStatisticsServer(strUrl){
	sage_ev(1,strUrl);
}

/*
Toolbar
*/
function fontEnlarge(){
	hitStatisticsServer('/toolbar/font_enlarge');
	_page.font_resize(1.2);
}
function fontReduce(){
	hitStatisticsServer('/toolbar/font_reduce');
	_page.font_resize(0.8);
}
function printPage(){
	hitStatisticsServer('/toolbar/page_print');
	_page.printVersionFar();
}
function sentPage(){
	hitStatisticsServer('/toolbar/page_email');
	_page.email();
}



/*
Check width and height of client
*/
function checkClientSize(){
	var intBrowserWidthCurrent, intBrowserHeightCurrent;
	var bolSizeChanged=false;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    intBrowserWidthCurrent = window.innerWidth;
    intBrowserHeightCurrent = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    intBrowserWidthCurrent = document.documentElement.clientWidth;
    intBrowserHeightCurrent = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    intBrowserWidthCurrent = document.body.clientWidth;
    intBrowserHeightCurrent = document.body.clientHeight;
  }
  
  if(intBrowserWidth!=intBrowserWidthCurrent){
  	bolSizeChanged=true;
  	intBrowserWidth=intBrowserWidthCurrent;
  }
  	
  if(intBrowserHeight!=intBrowserHeightCurrent){
  	bolSizeChanged=true;
  	intBrowserHeight=intBrowserHeightCurrent;
  }
  
  if(bolSizeChanged){
  	setImageHotspots();
  	centerLargeTableDiv();
  }
  
  //clear the timeouts that check the width of the page and reset the hotspots
	if(!bolExecuteClientDimensionCheck){
		if(intTimerId1)window.clearTimeout(intTimerId1);
		if(intTimerId2)window.clearTimeout(intTimerId2);
	}
}

function getClientSize() {
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    intBrowserWidth = window.innerWidth;
    intBrowserHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    intBrowserWidth = document.documentElement.clientWidth;
    intBrowserHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    intBrowserWidth = document.body.clientWidth;
    intBrowserHeight = document.body.clientHeight;
  }
}

/*
Anchor links
*/
function gotoAnchor(strAnchorName){
	//moves to an anchor link, but leave some space at the top
	if(strAnchorName.indexOf('#')>-1){
		//alert(location.hash);
		//location.hash="";
		var strUrl=location.href;
		if(strUrl.indexOf('#')>-1){
			strUrl=strUrl.split('#')[0];
		}
		strUrl+=strAnchorName;
		//alert(strUrl);
		location.href=strUrl;
		intTimerIdAnchor=setTimeout("scrollAnchorDown()",10);		
	}
}

function scrollTop(){
	location.hash="";
	window.scroll(0,0);
}

function scrollAnchorDown(){
	if(intTimerIdAnchor)window.clearTimeout(intTimerIdAnchor);
	window.scrollBy(0,-10);
}

function clickItem(){
	//a dummy funcion	
}

function setDisclaimerWidth(){
	//enlarge disclaimer text and the color table bar to full width of content area (hack for IE)	
	var objContent=MM_findObj('far-maincontent');
	if(isObject(objContent)){
		//alert(objContent.offsetWidth);
		if(objContent.offsetWidth>600){
			//alert("in");
			var objDisclaimer=MM_findObj('far-disclaimer');
			objDisclaimer.style.width=objContent.offsetWidth+'px';
			var objColorTableCell=MM_findObj('far-colortable');
			if(isObject(objColorTableCell))objColorTableCell.style.width=objContent.offsetWidth+'px';
		}
	}
}

function setAnimationCookie(){
	var now = new Date();
	fixDate(now);
	//expiry date 20 minutes from now
	now.setTime(now.getTime() + 20 * 60 * 1000);
	setCookie("playhomeanimation", "false", now);	
}

function hideLeadershipTables(){
	var intStart=1, intEnd=9;
	var strPageId="1153430", strTableId;
	var objTable;
	for (var i=intStart;i<(intEnd+1);i++){
		strTableId=strPageId+"_"+i;
		objTable=MM_findObj(strTableId);
		if(isObject(objTable))objTable.style.display = "none";
	}
	//hide all h4 nodes
	var arrHeaders=document.getElementsByTagName("h4");
	for (var i=0;i<arrHeaders.length;i++){
		arrHeaders[i].style.display = "none";		
	}
	//hide all h5 nodes
	var arrHeaders=document.getElementsByTagName("h5");
	for (var i=0;i<arrHeaders.length;i++){
		arrHeaders[i].style.display = "none";		
	}
}


function handleLargeTables(){
	//finds if a table is too large to fit in the main column
	//if so it will dump the content of that table in a centered div so that the page is not distorted
	var objDiv, strIdDiv, objTable, strIdTable, strTableWidth, strTableHeight, strTableHtml, strId;
	var strDivPosY;
	
	objDivLargeTableSource=MM_findObj("far-centered_table");
	
	var arrDivs=document.getElementsByTagName("div");
	for (var i=0;i<arrDivs.length;i++){
		objDiv=arrDivs[i];
		strIdDiv=objDiv.id;
		if(strIdDiv.indexOf("bigdiv_")>-1){
			//alert('deal with large div');
			strId=strIdDiv.split('_')[1];
			//retrieve the width of the large table
			strIdTable="bigtable_"+strId;
			//alert(strIdTable);
			objTable=MM_findObj(strIdTable);
			intLargeTableWidth=objTable.offsetWidth;
			//alert(intLargeTableWidth);
			if(intLargeTableWidth>744){
				bolExecuteClientDimensionCheck=true;
				
				//clone the source div
				if(!isObject(MM_findObj("far-centered_table_"+strId))){
					objDivLargeTable=objDivLargeTableSource.cloneNode(true);
					objDivLargeTable.id="far-centered_table_"+strId;
					objBodyNode.appendChild(objDivLargeTable);	
				}else{
					objDivLargeTable=MM_findObj("far-centered_table_"+strId);
				}				
				
				arrObjLargeTableDivs.push(objDivLargeTable)
				arrObjLargeTableDivsWidth.push(intLargeTableWidth)
				strTableWidth=intLargeTableWidth+"px";
				strTableHeight=objTable.offsetHeight+"px";
	
				//grab the content
				strTableHtml=objDiv.innerHTML;
				//set the height of the original div
				objDiv.style.height=strTableHeight;
				//clear the content of the div
				objDiv.innerHTML="";
				//put the content in the new floating div
				objDivLargeTable.style.width=strTableWidth;
				objDivLargeTable.style.height=strTableHeight;
				objDivLargeTable.innerHTML=strTableHtml;
				//position the div
				strDivPosY=findPosY(objDiv)+'px';
				objDivLargeTable.style.top=strDivPosY;
				centerLargeTableDiv();
				objDivLargeTable.style.display="inline";
			}
		}
		

	}		
}

function centerLargeTableDiv(){
	if(arrObjLargeTableDivs.length>0){
		var intPosLeft, intLargeTableWidth, objDivLargeTable;
		for (var i=0;i<arrObjLargeTableDivs.length;i++){
			objDivLargeTable=arrObjLargeTableDivs[i];
			intLargeTableWidth=arrObjLargeTableDivsWidth[i];
			if(intBrowserWidth>intLargeTableWidth){
				intPosLeft=(intBrowserWidth-intLargeTableWidth)/2;
				if(browser.isFirefox)intPosLeft=intPosLeft-8;
			}else{
				intPosLeft=0;
			}
			objDivLargeTable.style.left=intPosLeft+"px";
		}
	}
}

function getBodyNode(){
	objBodyNode=document.getElementsByTagName("body")[0];
}

function hideTableLinks(){
	//alert("ooo");
	var objP, objChildNode;
	var arrPs=document.getElementsByTagName("p");
	for (var i=0;i<arrPs.length;i++){
		objP=arrPs[i];
		objChildNode=objP.firstChild;
		if(isObject(objChildNode)){
			//alert(objChildNode.nodeName)
			if(objChildNode.nodeName.toLowerCase()=="a"){
				if(objChildNode.getAttribute("href").indexOf("tables/table")){
					//alert("hide")
					objP.style.display='none';
				}
						
				
			}
		}

	}
	
}

/*
After page has loaded
*/
function initPage(){
	//debugText('loaded...');
	if(strPageIdSystem=="1153430"){
		//leadership page - hide tables
		hideLeadershipTables();
	}	
	
	getBodyNode();
	getClientSize();
	handleLargeTables();
	intTimerId3=setTimeout("setDisclaimerWidth()",100);
	//intTimerId5=setTimeout("handleLargeTables()",50);
	intTimerId1=setTimeout("setImageHotspots()",500);
	intTimerId2=setInterval("checkClientSize()", 500); 

	//execute page specific client side code
	if(strPageIdSystem=='95363870893' || strPageIdSystem=='u62149144447'){
		//test if enlaged mode is entered
		//graphShow(retrieveQuerystringParameterValue(location.href, 'initialgraphid'));
		//MM_findObj("far-select_chart").focus();
	}
	if(strPageIdSystem=="0"){
		if(!isString(getCookie("playhomeanimation"))){
			setAnimationCookie();
		}
	}

	if(strPageIdSystem=="search-results"){
		//search page - use ajax to retrieve results
		searchExecute();
	}
	if(bolShowChildLinkObject){
		//Reconciliation non-US GAAP page
		hideTableLinks();
	}	
	
	if(strPageIdSystem=="ulogin_page"){
		//login page
		document.loginform.username.focus();
	}			
	//initiate SIFR replacements (work on this....)
	if(arrQuoteClass.length>0){
		executeSifrReplacements();
		//intTimerId5=setTimeout("executeSifrReplacements()",900);
	}
	
	//_page.printBrowserInfo();
	//alert(browser.isFirefox)
}

/*
Runtime Code
*/
//global variables
var bolDebug=false, bolDownloadsHideInProgress=true, bolDelay=false, bolUseSifr=false, bolExecuteClientDimensionCheck=false;
var intTimerId1, intTimerId2, intTimerId3, intTimerId4, intTimerId5, intTimerIdAnchor;
var intBrowserWidth, intBrowserHeight;
var strContentImageIdPrefix="img_", strLookupDebug, strObjClickedId, strFarPopupId="far-popup";
var objDivLargeTable;
var objBodyNode;
var arrCustomImageHotspots=new Array(), arrObjLargeTableDivs=new Array(), arrObjLargeTableDivsWidth=new Array(), arrQuoteClass=new Array();
//sector pages (<<img id>>|<<deviation default x coordinate>>|<<deviation default y coordinate>>|<<optional popup position:  lefttop, righttop, leftbottom, rightbottom >>)
arrCustomImageHotspots['1156524']='img_100|-210|-120|leftbottom';
arrCustomImageHotspots['1156706']='img_100|-395|-97|righttop';
arrCustomImageHotspots['1156888']='img_100|-210|-122|leftbottom';
arrCustomImageHotspots['1157070']='img_100|-115|-150|leftbottom';
arrCustomImageHotspots['1157252']='img_100|-215|-200|leftbottom';


//additional crsc parameters
//_page.link["owner"]="http://www.philips.com/siteowner";
if(location.protocol=='http:' && window.location.hostname!="130.139.83.200")_page.showStockQuotes = true;
_page.hideFlashSectionBanner = true;
_page.sectionSpecial = ["Annual Report 2006","/index.asp"]; /* Enter title and url special section */
_page.sectionMain = ["Investor Relations","http://www.philips.com/about/investor/index.html?origin=far"]; /* Optional: Enter title and url main section */
_page.leftNavOnload = false; /* set when the menu data will load */
if(window.location.hostname=="130.139.83.200"){
	_page.loadOmniture = false;
}else{
	_page.loadOmniture = true;
}
_page.crsc_nav_server = '';
_page.crsc_server = '';

//debug modus
if(document.location.search.indexOf('debug')>0 && document.location.search.indexOf('cachedebug')<1)bolDebug=true;

//get the current page id
var strPageId=linkLookup();
//alert(strPageId);

//page specific code
if(strPageIdSystem=="ulogin_page"){
	//hide all navigation items on the login page
	for (id in _page.leftNav) {
		_page.leftNav[id]=new _Item("Login","#","hidelink=yes");		
	}
	_page.leftNav["1"] = new _Item("Login","#","");
	strPageId="1";
}

if(bolDebug)openDebugWindow(strLookupDebug+"<br/>strPageId="+strPageId, false);
