/* navigation script */
if ( typeof(navigation) == "undefined") 
	navigation=new Object();
  
 
navigation.getRequestURLForNonCMSPage=function() {
	var a =document.getElementsByTagName('script');
	for(var i=0;i<a.length;i++){
		if ( a[i].src.indexOf("requrl") > 0 && a[i].src.indexOf("cmsid") > 0 )		{
			var requrlarr =  a[i].src.split("&");
			var requrlarr2 = requrlarr[1].split("=");
			return  requrlarr2[1] + "?cmsid=dummy";
		}
	}
	if (cmsrequri) return "" + cmsrequri ;
	else return "";
}


navigation.initializeSafari=function() {
	navigation.actualpath = navigation.getRequestURLForNonCMSPage();	
	
	navigation.hideMenuDelayTime=1200;
	navigation.showMenuDelayTime = 150;
	if ( !navigation.dynamicChanpageHeader)
		navigation.dynamicChanpageHeader=document.getElementById('dynamicChanpageHeader');
	navigation.oNav2=document.getElementById('nav2');
	if ( !navigation.oNav2 )
		return;
	navigation.cMenus=navigation.oNav2.getElementsByTagName('ul');
	navigation.oNav2.onmouseover=navigation.cancelHideMenu;
	navigation.oNav2.onmouseout=navigation.hideMenu;
	oNav1=document.getElementById('nav1');
	cTabs=oNav1.getElementsByTagName('li');

	navigation.footerLine1 = "";
	navigation.footerLine2 = "";	
	
	navigation.html1 = "<div  >" 
		+ "<table   cellspacing=\"0\" cellpadding=\"0\" border=\"0\" > "
		+ "<tr >";
	navigation.html2 = "";	
	for(var k=0;k<cTabs.length;k++){
		var oLI =cTabs[k];
		var href1 = oLI.getElementsByTagName('a')[0].href;
		var firstLevSelected = false;
		if (  navigation.compareLevel(navigation.actualpath,href1,1)) {
		 	firstLevSelected = true;
		}
		 
		var target = oLI.getElementsByTagName('a')[0].target;
		if ( target == "nothing" ) {
			navigation.lastOLi = oLI ;
		}
		else {
			//Deal with secondary nav 

			if ( navigation.cMenus[k] )
				{
				var menuListItems = navigation.cMenus[k].getElementsByTagName('li');
				var selectedIndex = 5000;
				for(var j=0;j<menuListItems.length;j++){
					if (  navigation.compareLevel(navigation.actualpath,menuListItems[j].getElementsByTagName('a')[0].href,2) ) {
						firstLevSelected = true; 
						selectedIndex = j;
					}
				}
				if ( firstLevSelected ) {
					navigation.html2 = "<div style='width:100%' class='safariSecondNavBackgroundColor'><table><tr >";
					for(var j=0;j<menuListItems.length - 1;j++){
						var atag = menuListItems[j].getElementsByTagName('a')[0];
						var href =  atag.href;
						var target = atag.target; 

						var tabname = (menuListItems[j].getElementsByTagName('span')[0]).innerHTML;
						if ( j > 0 )
							navigation.footerLine2 = navigation.footerLine2 + " | ";

						navigation.footerLine2 = navigation.footerLine2 + "<a href=\"" + href 
						+ "\" target = \"" + target	  +  "\" >"  + tabname + "</a>";

						navigation.html2 = navigation.html2 + "<td class='safariSecondNavTD'>";
						navigation.html2 = navigation.html2 + "<a class='safariFirstA' href=\"" 
						+ href 
						+ "\" target = \"" + target	  +  "\" >";
						
						if  ( selectedIndex == j )
							navigation.html2 = navigation.html2 + "<span class='safariSpanSecondLevSpanSelected'>"  ;
						else
							navigation.html2 = navigation.html2 + "<span class='safariSpanSecondLevSpan'>"  ;
						navigation.html2 = navigation.html2 + tabname + "</span>" + "</a>";
					}
					navigation.html2 = navigation.html2 + "</tr></table></div>";		
				}
		}
			
			//Start first Nav again
		
			navigation.sometxtfull = (oLI.getElementsByTagName("span")[0]).innerHTML;
			navigation.sometxt = navigation.sometxtfull.charAt(0);
			if ( k != 0 ) 
				navigation.footerLine1 =  navigation.footerLine1 + " | " ;
			navigation.footerLine1 = navigation.footerLine1 + "<a href=\"" + href1 
			+ "\" target = \"" + target	  +  "\" >"  + navigation.sometxtfull + "</a>";
			
			if ( firstLevSelected )
				navigation.html1 =  navigation.html1 + "<td class='safariFirstNavTDSelected'>"
					+ "<a chanTabHighlighted = 'yes' ";
			else
				navigation.html1 =  navigation.html1 + "<td class='safariFirstNavTD'>" 
							+ "<a ";
			navigation.html1 =  navigation.html1 
				+ " target='"
				+ target + "' href='"
				+ href1+ "'  class='safariFirstA' >" 
			      	+ navigation.safariSplitFirstLevelNav(  navigation.sometxtfull,"safariSpanFirstLev" )
				+" </a></td> ";
		}
	}
	navigation.html1 = navigation.html1 + "	</tr> </table> </div> ";
	navigation.dynamicChanpageHeader.innerHTML = navigation.html1 +  navigation.html2;
}

navigation.newsafarifontsize=function() {
	navigation.safarimode="true";
	var oNav1=document.getElementById('nav1');
	var cTabs=oNav1.getElementsByTagName('span');
	for(var i=0;i<cTabs.length;i++){
		var oSpan = cTabs[i];
		oSpan.setAttribute("style","font-size:1.2em") ;
	}
}

navigation.checkSafariBrowser=function() {
    if(navigator.appVersion.indexOf("Safari")!=-1)
    {
         version = parseFloat(navigator.appVersion.split("Safari/")[1]);
         if(version < 312.5)
         {
              navigation.supportSafariDynchan = false;
         }
         else
         {
              navigation.supportSafariDynchan = true;
         }
    }
}

navigation.safariSplitFirstLevelNav=function( name, classname) {
		if ( (name.length) > 42 && name.indexOf("<br/>") == -1 ) {
			var mylastindex = name.lastIndexOf(" ") ;
			var mystring =   "<br style='line-height:3px' /><span class='" + classname + "''> "
			   		 + name.substring(0,mylastindex) 
			   		 + "</span><br/> "
			        	 + "<span class='" + classname + "''> "
			   		 + name.substring(mylastindex + 1)
			   		 +"</span>";
			return mystring;
		}
 	     	return "<span class='" + classname + "''> "
			        +  "</span><br/> "
			        + "<span class='" + classname + "''> "
			        + name
			        + "</span>";
}

navigation.initialize=function() {
	if(!document.getElementById){
		return;
	}
	navigation.actualpath = navigation.getRequestURLForNonCMSPage();	
	
	navigation.hideMenuDelayTime=1200;
	navigation.showMenuDelayTime = 150;
	navigation.dynamicChanpageHeader=document.getElementById('dynamicChanpageHeader');
	if ( typeof(navigationFooterObject) == "undefined") {
		navigation.dynamicChanpageHeader.style.display = "block";		
	}
	navigation.oNav2=document.getElementById('nav2');
	if ( !navigation.oNav2 )
		return;
	navigation.cMenus=navigation.oNav2.getElementsByTagName('ul');
	navigation.oNav2.onmouseover=navigation.cancelHideMenu;
	navigation.oNav2.onmouseout=navigation.hideMenu;
	oNav1=document.getElementById('nav1');
	cTabs=oNav1.getElementsByTagName('li');
	navigation.defaultMenuHighlighted = 0 ;
	navigation.lastOLi = null	
	navigation.clickhappened = "false";
	navigation.tabWidth = 113 ;
	navigation.tabCount = cTabs.length ;
	navigation.tabHeight = 	31 ;
	navigation.chinesemode = "false";
	navigation.footerLine1 = "";
	navigation.footerLine2 = "";
	
	if ( navigator.userAgent.indexOf("Safari") != -1 ) {
		navigation.checkSafariBrowser()
	      if ( !navigation.supportSafariDynchan ) {
			navigation.initializeSafari();
			return;
		}
		navigation.safarimode="true";
		navigation.newsafarifontsize();
	}
	
	if ( navigator.appName =="Opera" ) {   //adjust margin for opera bowser
		navigation.oNav2.setAttribute("style","margin-top:-7px") ;
	}

        //Do the empty bar
	for(var k=0;k<cTabs.length;k++){
		var oLI =cTabs[k];
		if (  navigation.chinesemode == "false" && (oLI.getElementsByTagName('a')[0].href).indexOf("-zh/") > 0 ) {
			navigation.chinesemode  = "true";
		}
		var href = oLI.getElementsByTagName('a')[0].href;
		var target = oLI.getElementsByTagName('a')[0].target;
		if ( target == "nothing" ) {
			navigation.lastOLi = oLI ;
		}
		else {
			navigation.sometxtfull = (oLI.getElementsByTagName("span")[0]).innerHTML;
			navigation.sometxt = navigation.sometxtfull.charAt(0);
			if ( k != 0 ) 
				navigation.footerLine1 =  navigation.footerLine1 + " | " ;
			navigation.footerLine1 = navigation.footerLine1 + "<a href=\"" + href 
			// + "\" target = \"" + target	  +  "\" >"  + navigation.sometxtfull + "</a>";
			+  "\" >"  + navigation.sometxtfull + "</a>";
			if ( typeof(navigationFooterObject) != "undefined") {
			}
		}
	}
	
	for(var i=0;i<cTabs.length;i++){
		var oLI=cTabs[i];
		navigation.lastOLi = oLI ;
		oLI.nPosition=i;
		oLI.bAuthenticationRequired=false;
		if ( oLI.getElementsByTagName('a')[0].target != "nothing" ) {
			oLI.onmouseover=function(){
				navigation.startShowMenuTimer(this);			
			}
			oLI.onclick=function(){
				navigation.clickhappened = "true";	
			}
			oLI.onmouseout=function(){
				navigation.cancelshowMenuTimeout();
				navigation.hideMenu();
			}
			oLI.bAuthenticationRequired=false;
		} 
		if (  navigation.compareLevel(navigation.actualpath,oLI.getElementsByTagName('a')[0].href,1 )){ 
		        // if usl matches, set it as current tab
			oLI.className ='currentTab1';
			(cTabs[i].getElementsByTagName('a')[0]).setAttribute("chanTabHighlighted","yes");
			navigation.cMenus[i].className = "currentMenu1";
		} 
		if ( navigation.cMenus[i] ) {
			var menuListItems = navigation.cMenus[i].getElementsByTagName('li');
			for(var j=0;j<menuListItems.length;j++) {
				menuListItems[j	].onclick=function() {
					navigation.clickhappened = "true";	
					this.getElementsByTagName('a')[0].className="current";
				}
				if (  navigation.compareLevel(navigation.actualpath,menuListItems[j].getElementsByTagName('a')[0].href,2) ) {
					oLI.className ='currentTab1';
					(cTabs[i].getElementsByTagName('a')[0]).setAttribute("chanTabHighlighted","yes");
					navigation.cMenus[i].className = "currentMenu1";
					menuListItems[j].getElementsByTagName('a')[0].className="current";
				}
			}
			if ( navigation.cMenus[i].className == "currentMenu1" ) 
			for(var j=0;j<menuListItems.length - 1;j++){
				var atag = menuListItems[j].getElementsByTagName('a')[0];
				var href =  atag.href;
				var target = atag.target; 
				var tabname = (menuListItems[j].getElementsByTagName('span')[0]).innerHTML;
				if ( j > 0 )
					navigation.footerLine2 = navigation.footerLine2 + " | ";
				navigation.footerLine2 = navigation.footerLine2 + "<a href=\"" + href 
				+ "\" target = \"" + target	  +  "\" >"  + tabname + "</a>";
			}
		}
		if(oLI.className && oLI.className=='currentTab1'){
			navigation.currentTab1=oLI;
			navigation.activeTab=oLI;
		}
		
		//Add line breaks
		if (  ( navigation.actualpath,oLI.getElementsByTagName('a')[0]).firstChild && ( navigation.actualpath,oLI.getElementsByTagName('a')[0]).firstChild.innerHTML ) {
			var name = (navigation.actualpath,oLI.getElementsByTagName('a')[0]).firstChild.innerHTML;	
			
			if ( (name.length) > 42 && name.indexOf("<br/>") == -1 ) {
				var mylastindex = name.lastIndexOf(" ") ;
				var mystring = name.substring(0,mylastindex) + "<br/>" + name.substring(mylastindex + 1);
			if (navigation.safarimode == "true" )
				(navigation.actualpath,oLI.getElementsByTagName('a')[0]).innerHTML = "<span style=\"font-size:1.2em;padding-top:0px\">"
				  + mystring + "</span>";
			else
			(navigation.actualpath,oLI.getElementsByTagName('a')[0]).innerHTML = "<span style=\"padding-top:0px\">"
			+ mystring + "</span>" ;
			}
		}
	}
	if(!navigation.currentTab1){
		navigation.cMenus[i-1].className = "currentMenu1";
		navigation.defaultMenuHighlighted = i - 1 ;
	}
}

navigation.compareLevel = function(url,fullurl, level) {
	var stringToProcess1 = url;

	index = fullurl.indexOf("https://");
	var stringToProcess2 = "";
	
	if ( index != -1 ) {
		stringToProcess2 = fullurl.substring(index + 7);
			
	} else {
	 	return false;
	}
	
	var firstSplit = stringToProcess1.split("?")[0].split(".htm")[0];
	var temp = firstSplit.split("/");
	var urlToCompare ="";
	if ( level == 1  &&  temp[0] )
		urlToCompare = temp[0] ;
	if ( level == 1  &&  temp[1] )
		urlToCompare = urlToCompare  + temp[1] ;
	if ( level == 1  &&  temp[2] )
		urlToCompare =  urlToCompare + temp[2] ;
	if ( level == 1  &&  temp[3] )
		urlToCompare =  urlToCompare + temp[3] ;
	
	if ( level == 2  &&  temp[0] )
		urlToCompare =   temp[0] ;
	if ( level == 2  &&  temp[1] )
		urlToCompare =  urlToCompare + temp[1] ;
	if ( level == 2  &&  urlToCompare + temp[2] )
		urlToCompare =  urlToCompare + temp[2] ;
	if ( level == 2  &&  temp[3] )
		urlToCompare =  urlToCompare + temp[3] ;
	if ( level == 2  &&  temp[4] )
		urlToCompare =  urlToCompare + temp[4] ;

	firstSplit = stringToProcess2.split("?")[0].split(".htm")[0];
	temp = firstSplit.split("/");
	var fullurlToCompare = "";
	if ( level == 1  &&  temp[2] )
		fullurlToCompare =  fullurlToCompare + temp[2] ;
	if ( level == 1  &&  temp[3] )
		fullurlToCompare =  fullurlToCompare + temp[3] ;
	if ( level == 1  &&  temp[4] )
		fullurlToCompare =  fullurlToCompare + temp[4] ;

	if ( level == 2  &&  fullurlToCompare +  temp[2] )
		fullurlToCompare  = fullurlToCompare + temp[2] ;
	if ( level == 2  &&  temp[3] )
		fullurlToCompare =  fullurlToCompare + temp[3] ;
	if ( level == 2  &&  temp[4] )
		fullurlToCompare =  fullurlToCompare + temp[4] ;
	if ( level == 2  &&  temp[5] )
		fullurlToCompare =  fullurlToCompare + temp[5] ;
	return ( fullurlToCompare ==  urlToCompare );
	
}


//Following function removes the query string of the url
navigation.compare = function(url,fullurl) {
	var temp = ("" + url).split("?");
	var urlstripped = temp[0];
	if ( urlstripped.indexOf(".html") > 0 ) {
		urlstripped = navigation.cut(urlstripped);
	}
	
	temp = (""  + fullurl).split("?");
	fullurlstripped = temp[0];
	
	if ( fullurlstripped == urlstripped )
		return true;
	return false;
}


navigation.cut = function(url) {
	var  lastIndexofslasjh = url.lastIndexOf("/");
	if ( lastIndexofslasjh > 0 ) {
		var myrul = url.substring(0,lastIndexofslasjh);
		return myrul;
	}
}


navigation.startShowMenuTimer=function(oLI){
	navigation.showMenuFor = oLI;
	navigation.cancelHideMenu();	
	navigation.showMenuTimeout= setTimeout(navigation.showMenuOnTimer,navigation.showMenuDelayTime);	
}


navigation.showMenuOnTimer =function(){
	navigation.showMenu(navigation.showMenuFor);
}


navigation.showMenu=function(oLI){
	if ( !oLI)
		return;
	navigation.cancelHideMenu();		
	navigation.oNav2.className='';
	if (navigation.activeTab!=navigation.currentTab1) {
		navigation.activeTab.className='';
		navigation.cMenus[navigation.activeTab.nPosition].className='';
	}
		
	if(oLI==navigation.currentTab1) {
		navigation.dynamicChanpageHeader.className='';
	} else  {
		if ( oLI != navigation.lastOLi ) {
			navigation.dynamicChanpageHeader.className='activeNav';
			oLI.className='activeTab';
		}
		navigation.cMenus[oLI.nPosition].className='activeMenu';
	}
	navigation.activeTab=oLI;
}


navigation.hideMenu=function(){
	function navigation_snapback(){
		if (  navigation.clickhappened == "true") {
			return ;
		}
		if ( navigation.defaultMenuHighlighted== 0 ) {
			navigation.showMenu(navigation.currentTab1);
		}else {
			navigation.showMenu(navigation.lastOLi );
		}
		navigation.showMenu(navigation.currentTab1);
	}
	if ( navigation )	
		navigation.hideMenuTimeOut=setTimeout(navigation_snapback,navigation.hideMenuDelayTime);
}


navigation.cancelshowMenuTimeout=function(){
	if(navigation.showMenuTimeout){
		clearTimeout(navigation.showMenuTimeout);
		navigation.showMenuTimeout=null;
	}
}


navigation.cancelHideMenu=function(){
	navigation.dynamicChanpageHeader=document.getElementById('dynamicChanpageHeader');
	if(navigation.hideMenuTimeOut){
		clearTimeout(navigation.hideMenuTimeOut);
		navigation.hideMenuTimeOut=null;
	}
}


navigation.setFooter=function(){
	var k = document.getElementById('dyn-chan-footer');
	k.innerHTML= navigation.footerLine1  + "<BR/>"  + navigation.footerLine2; 
}


if (typeof ( navigation.firsttime ) == "undefined" )  {
	navigation.initialize();
	navigation.firsttime = "false";
} 

/* For options kinds of pages that call javascript only once*/
if ( typeof(navigationFooterObjectAux) != "undefined") {
	navigation.setFooter();
}

