﻿// JScript File

/**************************************************************************
 *                                                                        *
 * JavaScript to change leftNav OnState                                   *
 * Liz Dones 7/22/2008                                                    *
 * Copy from Pike Notes to BWH                                            *
 * Modified on April 6,2011 - Liz Dones                                   *
 *                                                                        *
 * Usage:                                                                 *
 * -the script will apply the .current class to the <a> and its parent    *
 *  <li> that is contained in the element with id="leftNavList" and points*
 *  to the current URL                                                    *
 * -works in IE6, Firefox and Opera                                       *
 **************************************************************************/

//<!--new script for left menu-->
menu_status=new Array();

function showHide(_menu){
  if(document.getElementById){
  var switch_id = document.getElementById(_menu);
	if(menu_status[_menu]!='show'){
	  switch_id.className='show';
	  menu_status[_menu]='show';
	}else{
	  switch_id.className='hide';
	  menu_status[_menu]='hide';
	  }
	}
}


function topHighlight(_top){
  if(document.getElementById){
  var switch_id = document.getElementById(_top);

	if(menu_status[_top]!='highlight'){
	  switch_id.className='highlight';
	  menu_status[_top]='highlight';
	}else{
	  switch_id.className='toplevel';
	  menu_status[_top]='toplevel';
	  }
	}
}


function extractPageName(hrefString)
{
    

	var cleanLoc = hrefString.replace(/(\?.*)|(#.*)/,'');

	var dotLocation = cleanLoc.indexOf('.org') + 4;

    var arr = hrefString.substring(dotLocation,hrefString.length).toLowerCase();
	
    return arr;
	
}

function setActiveMenu(arr, crtPage)
{
	for(var i=0; i<arr.length; i++)
	{
		if(extractPageName(arr[i].href) == crtPage)
		{
			if (arr[i].parentNode.tagName != "div")
			{
				arr[i].className = "current";
				arr[i].parentNode.parentNode.className = "show";
				arr[i].parentNode.parentNode.parentNode.parentNode.className = "show";
				arr[i].parentNode.parentNode.parentNode.firstChild.className = "highlight";
				arr[i].parentNode.parentNode.parentNode.parentNode.parentNode.firstChild.className = "highlight";

			}

		}
	}
}


function setPage()
{
	hrefString = document.location.href ? document.location.href : document.location;

   
     
      var teamsite = hrefString.substring(28, 0)


	   if (teamsite=="http://teamsite.partners.org")
		{

	    var cleanLoc = hrefString.replace(/(\?.*)|(#.*)/,'');
		var dotLocation = cleanLoc.indexOf('BWHInternet') + 11;

		var link = hrefString.substring(dotLocation,hrefString.length).toLowerCase();

		
		if (document.getElementById("leftNav_content")!=null) 
		setActiveMenu(document.getElementById("menu").getElementsByTagName("a"), link);		
		

		if (document.getElementById("RightNavLinks")!=null) 
			setActiveMenu(document.getElementById("right_menu").getElementsByTagName("a"), link);

			}

		else
			
		{

			if (document.getElementById("leftNav_content")!=null) 
				setActiveMenu(document.getElementById("menu").getElementsByTagName("a"), extractPageName(hrefString));		
				

			if (document.getElementById("RightNavLinks")!=null) 
				setActiveMenu(document.getElementById("right_menu").getElementsByTagName("a"), extractPageName(hrefString));
		}
		

	 //console.log(extractPageName(hrefString))
}










