﻿/*
** Put this file in C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\template\layouts\Fs_resources\Script\
*/
function HideLinkToListInBreadcrumb()
{
	var isPage = false;
	var table = document.getElementById('onetidPageTitleAreaTable');	
	if(table)
	{
		var parentSpan = table.getElementsByTagName('span');
		if(parentSpan && parentSpan.length > 0)
		{
			var span0 = parentSpan[0];
			var childSpan = span0.getElementsByTagName('span');
			if(childSpan && childSpan.length > 0)
			{
				for(var i=0; i< childSpan.length; i++)
				{					
					var a = childSpan[i].getElementsByTagName('a');
					if(a && a.length > 0)
					{						
						if(a[0].innerHTML == "Pages")
						{
							childSpan[i].style.display = 'none';
							childSpan[i+1].style.display = 'none';
							isPage = true;
							break;
						}						
					}
				}
				//Remove Homepage link on Breadcrumb
				if(childSpan[0])
				{
					childSpan[0].style.display = 'none';
				}
				if(childSpan[1])
				{
					childSpan[1].style.display = 'none';
				}
				//end
			}
		}		
		if(parentSpan.length == 6 && isPage)
		{
			var _span = parentSpan[parentSpan.length - 1];
			var className = _span.className;
			_span.className = "";
			var _spanIner = _span.innerHTML;
			_span.innerHTML = "<a class='"+ className +"'>" + _spanIner + "</a>";
		}
	}	
	FixTitlePage();
}
function FixTitlePage()
{
	var title = document.title;
	document.title = title.replace("Pages - ","").replace("Home - ","").replace("Accueil - ","");
}
function HighLightSelected()
{	
	var curURL = window.location.href.toUpperCase();
	var dv = document.getElementById("quicklaunch");
	if(dv)
	{
		var obj_tmp;
		var aArr = dv.getElementsByTagName('a');
		if(aArr && aArr.length > 0)
		{			
			
			for(var j=0;j<aArr.length;j++)
			{
				var urlA = aArr[j].href.toUpperCase();
				var isNewsLetter = curURL.indexOf("NEWSLETTER") > 0 && urlA.indexOf("NEWSLETTER") > 0;
				
				var urlA_tmp = curURL;

				if(curURL.indexOf("/PAGES/") > 0)
				{
					var _pages = curURL.split("/PAGES/")[1].split("/")[0];
					if(_pages == "FORMS")
					{
						urlA_tmp = curURL.split("/PAGES/")[0] + "/PAGES/FORMS";
					}					
				}

				if(curURL.indexOf("/LISTS/") > 0)
				{
					var tmp = curURL.split("/LISTS/");
					var tmp_listName = tmp[1].split('/')[0];					
					urlA_tmp = curURL.split("LISTS")[0] + "LISTS/" + tmp_listName;
				}
				
				var isPage = urlA.indexOf(urlA_tmp);				

				if(curURL == urlA || isNewsLetter || isPage >=0)
				{
					aArr[j].className = "leftNavItemSelected";
					obj_tmp = aArr[j];
					break;
				}				
			}
			
			if(obj_tmp)
			{	
				var parent = obj_tmp.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;				
				if(parent && parent.tagName == "DIV")
				{
					var parentNode = parent.parentNode;
					if(parentNode && parentNode.tagName == "TD")
					{
						var node = parentNode.childNodes[0];					
						if(node)
						{
							var a = node.getElementsByTagName('a');
							if(a && a.length > 0)
							{
								a[0].className = "leftNavItemSelected";
							}
						}
					}
				}			
			}
			else
			{
				for(var j=0;j<aArr.length;j++)
				{
					var urlA = aArr[j].href.toUpperCase();
					var _page = curURL.split("/PAGES/")[0] + "/DEFAULT.ASPX";
					if(urlA == _page)
					{
						aArr[j].className = "leftNavItemSelected";
						break;
					}
				}
			}
		}
	}	
} 
//chinhdv fix top menu on firefox
function FixTopMenu()
{
	var browser=navigator.appName;
	if(browser && browser == "Netscape")
	{		
		var objBar = document.getElementById('HBN100');		
		if(objBar)
		{
			var arrA = objBar.getElementsByTagName('a');
			if(arrA && arrA.length > 0)
			{
				for(var k=0;k<arrA.length;k++)
				{
					arrA[k].style.height = "22px";					
				}
			}
		}
	}
	
	//fix Site Actions
	var siteActions = document.getElementById('siteactiontd');
	if(siteActions)
	{
		var table = siteActions.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode;
		if(table)
		{			
			table.style.marginBottom = "-12px";
		}
	}
	
	//Active Blogs
	ActiveBlogs("Blogs");
	ActiveBlogs("ブログ");	
	
	//hid combox search
	HidComboxSearch();
	
}
//end
//hid combox search
function HidComboxSearch()
{
	var currentURL = window.location.href.toUpperCase();
	var textSearch = "Search";
	if(currentURL.indexOf("/SITES/FR/") > 0)
	{
		textSearch = "Chercher";
	}
	if(currentURL.indexOf("/SITES/JP/") > 0)
	{
		textSearch = "捜す";
	}

	var search = document.getElementById('idSearchScope');
	if(search)
	{ 
		//search.parentNode.innerHTML = "<font class='search_title'>"+ textSearch +"&nbsp;&nbsp;</font>";
		search.style.display='none';		
	}
	var inputSearch = document.getElementById("idSearchString");
	if(inputSearch)
	{
		inputSearch.value = textSearch;		
		inputSearch.onfocus = function()
		{
			var _value = inputSearch.value;			
			if(_value == textSearch)
			{				
				inputSearch.value = "";
			}			
		}
		inputSearch.onblur = function()
		{			
			var _value = inputSearch.value;			
			if(_value == "")
			{				
				inputSearch.value = textSearch;
			}
		}
	}
}
//Active Blog
function ActiveBlogs(blogsText)
{
	var objBar = document.getElementById('HBN100');	
	if(objBar)
	{
		var aArr = objBar.getElementsByTagName('a');
		if(aArr && aArr.length > 0)
		{
			for(var x=0;x<aArr.length;x++)
			{
				if(aArr[x].innerHTML == blogsText)
				{
					aArr[x].target = "_blank";					
					var classA = aArr[x].className;
					aArr[x].className = classA + " ms-topnavselected_blog"  + " leftNavItemSelected";
					//table
					var table = aArr[x].parentNode.parentNode.parentNode.parentNode;
					if(table)
					{
						var classTable = table.className;
						table.className = classTable + " ms-topnavselected_blog";
					}
					break;
				}
			}
		}
	}
}
 //end
function HighlightBanner()
{  
  var curURL = window.location.href.toUpperCase();
  var objBar = document.getElementById('HBN100');
  var tabTable = objBar.getElementsByTagName('table');
  
  if(tabTable && tabTable.length >0)
  {
		for(i=2; i<tabTable.length; i++)
		{
		 
	  		var tabLinksArr = tabTable[i].getElementsByTagName('a');
	  		var tabLinks  = tabLinksArr[0].href.toUpperCase();
			tabLinks = tabLinks.replace("/SITES/JP","");
			tabLinks = tabLinks.replace("/SITES/FR","");
			
	  		var arrTab = tabLinks.split('/');
	  		if(arrTab[3] == "PAGES" && curURL != tabLinksArr[0].href.toUpperCase())
	  		{
	  		 	var classTable = tabTable[1].className;
	  		 	classTable =classTable + " ms-topnavselected";
	  		 	tabTable[1].className = classTable;
	  		 	
	  		 	var classTable = tabTable[i].className;
	  		 	tabTable[i].className = classTable.replace(" ms-topnavselected", "");
	  		 	break;	  		 	
	  		}
	  		else
	  		{
		  		if(curURL.indexOf(arrTab[3]) >= 0)
		  		{
		  		
		  		 	var classLinks =  tabLinksArr[0].className;
		  		 	classLinks = classLinks + " ms-topnavselected";
		  		 	 tabLinksArr[0].className =classLinks ;
		  		 	var classTable = tabTable[i].className;
		  		 	classTable =classTable + " ms-topnavselected";
		  		 	tabTable[i].className = classTable;
		  		 	
		  		 	break;
		  		}
			}
		}
  }
  
  FixTopMenu();  
}

// Function for Links button: to show pop-up include hyperlinks
// Author: QuyNH
// Begin 1

function init() 
{
	var Popup = document.getElementById("Popup_dropdownlist"); 
 
 	Popup.onmouseout = function(e){mouseMoveOut(e);}

    document.onmousemove = getCursorXY;
    
    FixTopMenu();
}

 //var Popup = document.getElementById("Popup_dropdownlist"); 
 
 //Popup.onmouseout = function(e){mouseMoveOut(e);}
 var width;
 function showWindow(content,title,width1)
 {
 	  var Popup = document.getElementById("Popup_dropdownlist");
      width = width1;
      var  dropdownlist= document.getElementById("dropdownlist");
      x = findPosX(dropdownlist) + dropdownlist.offsetWidth + 1 - width//event.clientX + document.body.scrollLeft; // get the mouse left position
      y = findPosY(dropdownlist) + dropdownlist.offsetHeight//100event.clientY + document.body.scrollTop + 35; // get the mouse top position
      Popup.style.width = width;
      Popup.innerHTML = content;
      Popup.style.display="block"; // display the pop-up
      Popup.style.left = x; // set the pop-up's left
      Popup.style.top = y; // set the pop-up's top
      if(Popup.offsetHeight > 220)
      	Popup.style.height = 220 + "px";
 }
 var check_popup = false;
function mouseMoveOut(event)
{  
            
       check_popup = true;
       
}
    
function getCursorXY(event) 
{
	var Popup = document.getElementById("Popup_dropdownlist");
    if(check_popup)
    {
            var event = event || window.event; 
            var x = event.pageX || event.clientX  + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
                            var y = event.pageY || event.clientY  + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
                    if(Popup.offsetTop > y || (Popup.offsetTop +  Popup.offsetHeight) < y)
        {
            Popup.style.display='none';
            check_popup = false;
        }
        if(Popup.offsetLeft > x || (Popup.offsetLeft +  Popup.offsetWidth) < x)
        {
             Popup.style.display='none'; 
             check_popup = false;
        }
     }
}  
  
function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }
  function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }
  //End 1
  
// Fix Position Of Fly Menu
// Author: PhucNT
// Start
function PopOut_Position(panel, hideScrollers) {

    if (window.opera) {

        panel.parentNode.removeChild(panel);

        document.forms[0].appendChild(panel);

    }

    var rel = WebForm_GetElementById(panel.rel);

    var relTable = WebForm_GetElementByTagName(rel, "TABLE");

    var relCoordinates = WebForm_GetElementPosition(relTable ? relTable : rel);

    var panelCoordinates = WebForm_GetElementPosition(panel);

    var panelHeight = ((typeof(panel.physicalHeight) != "undefined") && (panel.physicalHeight != null)) ?

        panel.physicalHeight :

        panelCoordinates.height;

    panel.physicalHeight = panelHeight;

    var panelParentCoordinates;

    if (panel.offsetParent) {

        panelParentCoordinates = WebForm_GetElementPosition(panel.offsetParent);

    }

    else {

        panelParentCoordinates = new Object();

        panelParentCoordinates.x = 0;

        panelParentCoordinates.y = 0;

    }

    var overflowElement = WebForm_GetElementById("__overFlowElement");

    if (!overflowElement) {

        overflowElement = document.createElement("img");

        overflowElement.id="__overFlowElement";

        WebForm_SetElementWidth(overflowElement, 1);

        document.body.appendChild(overflowElement);

    }

    WebForm_SetElementHeight(overflowElement, panelHeight + relCoordinates.y + parseInt(panel.y ? panel.y : 0));

    overflowElement.style.visibility = "visible";

    overflowElement.style.display = "inline";

    var clientHeight = 0;

    var clientWidth = 0;

    if (window.innerHeight) {

        clientHeight = window.innerHeight;

        clientWidth = window.innerWidth;

    }

    else if (document.documentElement && document.documentElement.clientHeight) {

        clientHeight = document.documentElement.clientHeight;

        clientWidth = document.documentElement.clientWidth;

    }

    else if (document.body && document.body.clientHeight)	{

        clientHeight = document.body.clientHeight;

		clientWidth = document.body.clientWidth; 
		} 
		//Customize S
		clientHeight = document.body.scrollHeight;
		//Customize E
		var scrollTop = 0; var scrollLeft = 0; 
		if (typeof(window.pageYOffset) != "undefined") 
		{ 
		scrollTop = window.pageYOffset; 
		scrollLeft = window.pageXOffset; } 
		else if (document.documentElement && (typeof(document.documentElement.scrollTop) != "undefined")) 
		{ 
		scrollTop = document.documentElement.scrollTop;
		 scrollLeft = document.documentElement.scrollLeft; 
		} 
		else if (document.body && (typeof(document.body.scrollTop) != "undefined"))
		 { 
		scrollTop = document.body.scrollTop; scrollLeft = document.body.scrollLeft; 
		 }
		  overflowElement.style.visibility = "hidden"; 
		  overflowElement.style.display = "none"; 
		  var bottomWindowBorder = clientHeight + scrollTop;
		   var rightWindowBorder = clientWidth + scrollLeft; var position = panel.pos; 
		   if ((typeof(position) == "undefined") || (position == null) || (position == "")) 
		   { 
		   	position = (WebForm_GetElementDir(rel) == "rtl" ? "middleleft" : "middleright"); 
		   	} 
		   position = position.toLowerCase(); 
		   var y = relCoordinates.y + parseInt(panel.y ? panel.y : 0) - panelParentCoordinates.y; 
		   var borderParent = (rel && rel.parentNode && rel.parentNode.parentNode && rel.parentNode.parentNode.parentNode && rel.parentNode.parentNode.parentNode.tagName.toLowerCase() == "div") ? rel.parentNode.parentNode.parentNode : null; WebForm_SetElementY(panel, y); PopOut_SetPanelHeight(panel, panelHeight, true); 
		   var clip = false; 
		   var overflow; 
		   if (position.indexOf("top") != -1) { y -= panelHeight; WebForm_SetElementY(panel, y); 
		   if (y < -panelParentCoordinates.y) { y = -panelParentCoordinates.y; WebForm_SetElementY(panel, y); 
		   if (panelHeight > clientHeight - 2) { clip = true; PopOut_SetPanelHeight(panel, clientHeight - 2); } } } 
		   else { 
		   if (position.indexOf("bottom") != -1) { y += relCoordinates.height; WebForm_SetElementY(panel, y); } overflow = y + panelParentCoordinates.y + panelHeight - bottomWindowBorder; 
		   if (overflow > 0) { y -= overflow; WebForm_SetElementY(panel, y); 
		   if (y < -panelParentCoordinates.y) { y = 2 - panelParentCoordinates.y + scrollTop; WebForm_SetElementY(panel, y); clip = true; PopOut_SetPanelHeight(panel, clientHeight - 2); } } }
		   if (!clip) { PopOut_SetPanelHeight(panel, panel.clippedHeight, true); } 
		   var panelParentOffsetY = 0; 
		   if (panel.offsetParent) { panelParentOffsetY = WebForm_GetElementPosition(panel.offsetParent).y; } 
		   var panelY = ((typeof(panel.originY) != "undefined") && (panel.originY != null)) ? panel.originY : y - panelParentOffsetY; panel.originY = panelY; 
		   if (!hideScrollers) { PopOut_ShowScrollers(panel); } 
		   else { PopOut_HideScrollers(panel); } 
		   var x = relCoordinates.x + parseInt(panel.x ? panel.x : 0) - panelParentCoordinates.x; 
		   if (borderParent && borderParent.clientLeft) { x += 2 * borderParent.clientLeft; } WebForm_SetElementX(panel, x); 
		   if (position.indexOf("left") != -1) { x -= panelCoordinates.width; WebForm_SetElementX(panel, x); 
		   if (x < -panelParentCoordinates.x) { WebForm_SetElementX(panel, -panelParentCoordinates.x); } }
		   else 
		   { 
		   		if (position.indexOf("right") != -1) { x += relCoordinates.width; WebForm_SetElementX(panel, x); } 
		   		overflow = x + panelParentCoordinates.x + panelCoordinates.width - rightWindowBorder; 
			   if (overflow > 0) 
			   { 
				   	   if (position.indexOf("bottom") == -1 && relCoordinates.x > panelCoordinates.width) 
				   { x -= relCoordinates.width + panelCoordinates.width; } 
				   else { x -= overflow; } WebForm_SetElementX(panel, x); 
				   if (x < -panelParentCoordinates.x) { WebForm_SetElementX(panel, -panelParentCoordinates.x); } 
			   } 
		   }
}
//End