// RTN# | Open Window Project | Kunal Sinha
// Code Change Starts
var xmlDoc;
var dom;
var parser;
var leftNavTree="";
//var moduleChangeStatus = 0;
var parentNodeClass="";
var leftNavElementArray = new Array();
var leftNavElementUrlArray = new Array();
var topNavParentElementArray = new Array();
var topNavMenuItemParentArray = new Array();
var leftNavElementLevelArray = new Array();

var topNavBar = "";	
var menubarString = "";
var menuString = "";

var activeParentID = "";
var activeCurrentLinkId = "";

var lastSelectedTopNav = "";
var lastSelectedTopNavImg = "";
var highlightedTopNavImg = "";

var menuItemEvenClass = "menuItemEven";
var menuItemOddClass = "menuItemOdd";

var brickLevel = 0;

var leftNavIdCounter = 0;
var parentNodeIdLeftNav;
var newLocationForLeftNav = "";
var parentPageUrl = "";
var parentPageUpdateNavUrl = "";
var newwindow = '';

// This function is called when user navigates to some other module
// from current module (for eg. from library to marketing toolkit)
// This function keeps track of last page visited by user before going to 
// other module.	
function setHistoryForCrossModuleNavigation(newLocation,oldLocation,oldNavLocation)
{
	dhtmlHistory.add(oldLocation,'');
	setCookie("oldLocation",oldLocation);
	setCookie("oldNavLocation",oldNavLocation);
	setCookie("moduleChangeStatus","1");
	window.location.href = newLocation;
}

// This function is called when user jumps from one module to 
// some other module.
function crossModuleJump(newLocation)
{
	window.location.href = newLocation;
}

function updateNavs(newLocation,backButtonFlag)
{
	var firstIndex = "";
	var secondIndex = "";
	/*if(newLocation.indexOf("|") > -1)
	{
		firstIndex = newLocation.indexOf("|");
		secondIndex = newLocation.indexOf("|",firstIndex + 1);
		parentPageUrl = newLocation.substring(firstIndex + 1,secondIndex);
		newLocationForLeftNav = newLocation.substring(secondIndex+1);
		setCookie("newLocationForUpdateNavOnPageRefresh",newLocationForLeftNav);
		newLocation = newLocation.substring(0,firstIndex);		
	}
	
	if(backButtonFlag==true)
	{
		if(newLocationForLeftNav !="")
		{
			newLocation = newLocationForLeftNav;
			//alert("newLocationForLeftNav is not null and newLocation--->" + newLocation);
			newLocationForLeftNav = "";
		}
		backButtonFlag=false;
	}*/
			
	if(newLocation!="")
	{
		for(leftNavElementUrlArrayCnt = 0 ; leftNavElementUrlArrayCnt < leftNavElementUrlArray.length; leftNavElementUrlArrayCnt++)
		{
			if(leftNavElementUrlArray[leftNavElementUrlArrayCnt] == newLocation)
			{
				updateLeftNav(leftNavElementArray[leftNavElementUrlArrayCnt],leftNavElementLevelArray[leftNavElementUrlArrayCnt]);
			}
		}
	}
	
	if(activeParentID != "")
	{
		updateTopNav(activeParentID.substring(0,activeParentID.indexOf("TopNav")),"1");
	}	
	
	// Add History Event
	if(parentPageUrl=="")
	{
		if (backButtonFlag != false){
			dhtmlHistory.add(newLocation, '');
		}	
	}
	else
	{
		if (backButtonFlag != false) {			
			dhtmlHistory.add(parentPageUrl, '');
		}
		parentPageUrl = "";
	}
}


function updateLeftNavTreeImages()
{
	for(i=1;i<leftNavElementArray.length;i++)
	{
		document.getElementById(leftNavElementArray[i] + "LeftNavImg").height = document.getElementById(leftNavElementArray[i] + "LeftNav").offsetHeight;
	}
}

function updateTopNavMenuWidth()
{
	var currentMenuWidth;
	var parentMenuWidth;
		
	for(i=1;i<topNavParentElementArray.length;i++)
	{
		currentMenuWidth = document.getElementById(topNavParentElementArray[i]).offsetWidth;
		parentMenuWidth = document.getElementById(leftNavElementArray[i] + "TopNav").offsetWidth;
		////////alert("before width = " + document.getElementById(topNavParentElementArray[i]).width);

		if(currentMenuWidth < parentMenuWidth)
			document.getElementById(topNavParentElementArray[i]).width = parentMenuWidth;
		
		////////alert("after  width = " + document.getElementById(topNavParentElementArray[i]).width);
	}
}

/*********ADDED BY GAURAV********************/
// This function checks whether the url passed is 4+ level url
// If yes, it fetches its parent i.e. 3 level url to reflect left
// and top nav accordingly
function getActiveNavUrl(tree,url){
	var	urlItem = tree.getAttribute("url");
	if(urlItem == url){
		if(tree.getAttribute("showInNavs") == "false"){
			// get the parent url
			parentUrl = getActiveParentNavUrl(tree.parentNode);
			return parentUrl;
		}		
		return url;
	} 
	
	// if node does not have any child, return empty string
	if(tree.childNodes.length == 0){
		return "";
	}
	
	// traverse all the child nodes
	for(var i=0; i<tree.childNodes.length; i++){
		urlItem = getActiveNavUrl(tree.childNodes[i],url);
		// if URL found, no need to traverse more child nodes
		if(urlItem != ""){
			break;
		}
	}
	
	return urlItem;
}
/*********ADDED BY GAURAV********************/

function getActiveParentNavUrl(node){
	if(node.parentNode == null){
		return node.getAttribute("url");
	}
	
	if(node.getAttribute("showInNavs") == "false"){
		// traverse the parent node
		return getActiveParentNavUrl(node.parentNode);
	}
	return node.getAttribute("url");
}
/*********ADDED BY GAURAV********************/

function traverse(tree)
{
	//This variable is needed to fetch the current level of node in the left navigation heirarchy.
	//This is required to calculate the "colspan" for the current level 
	var nodeLevel = tree.getAttribute("class").charAt((tree.getAttribute("class").indexOf("_") + 1));
	
	
	var brickColor;
	/*******	CODE ADDED BY GAURAV **********/
	var level3Status = false;
	/*******	CODE ADDED BY GAURAV **********/
	switch(brickLevel%2)
	{
		case 0:	brickColor = "brickDark";
				break;
		case 1:	brickColor = "brickLight";
				break;
	}
	brickLevel = brickLevel + 1;
	
	nodeID = "m" + leftNavIdCounter + "_" + tree.getAttribute("id");
	//Store the current nodeId in an array
	leftNavElementArray[leftNavIdCounter] = nodeID;
	//Store the corresponding URL in an array
	leftNavElementUrlArray[leftNavIdCounter] = tree.getAttribute("url");
	//Store the corresponding node level in an array
	leftNavElementLevelArray[leftNavIdCounter] = nodeLevel;
	
	////////alert(nodeID);
	leftNavIdCounter = leftNavIdCounter + 1;
	
	if((tree.getAttribute("itemType") == "menuBarItem") || (nodeLevel == 0))
	{
		leftNavTree +="<tr id=\"" + nodeID + "LeftNav_Container\" class=\"" + tree.getAttribute("containerPropertyClass") + "\">";
			leftNavTree +="<td>";
				leftNavTree +="<table cellspacing=\"0\" cellpadding=\"0\" width=\"100%\">";
	}		
	
	leftNavTree +="<tr id=\""+ nodeID +"LeftNav_row\" class=\"" + tree.getAttribute("class") + "\">";
	//alert("text-->" + tree.getAttribute("text"));
	if(tree.hasChildNodes())
    {
		if(nodeLevel != 0)
		{
			/*******	CODE ADDED BY GAURAV **********/
			for(var i=0; i<tree.childNodes.length; i++){
				if(tree.childNodes[i].getAttribute("showInNavs")=="false"){
					level3Status = "true";
					break;
				}
			}			
			parentNodeIdLeftNav = nodeID;
			if(level3Status == "true"){
				//alert("In if");
				leftNavTree +="<td width=\"10\">&nbsp;</td>";
				leftNavTree +="<td width=\"10\">";				
			}
			else{
				//alert("In else");
				leftNavTree +="<td colspan=\"" + nodeLevel +"\">";
			}
			if((tree.nextSibling!=null) && (nodeLevel != 1)){
				leftNavTree +="<img id=\""+ nodeID +"LeftNavImg\" src=\"/staticcontentassets/images/cnamsheader/both.gif\" style=\"width:10;\"/>";
			}
			else{
				leftNavTree +="<img id=\""+ nodeID +"LeftNavImg\" src=\"/staticcontentassets/images/cnamsheader/up.gif\" style=\"width:10;\"/>";
			}	
			leftNavTree +="</td>";
			
			/*******	CODE ADDED BY GAURAV **********/
		}
	}
    else
    {
			leftNavTree +="<td width=\"10\">&nbsp;</td>";
			leftNavTree +="<td width=\"10\">";

			if((tree.nextSibling!=null) && (nodeLevel != 1)){
				leftNavTree +="<img id=\""+ nodeID +"LeftNavImg\" src=\"/cnams/resource/lcms/cnams_site/english/generic_site_areas/staticcontentassets/images/cnamsheader/both.gif\" style=\"width:10;\"/>";
			}else{
				leftNavTree +="<img id=\""+ nodeID +"LeftNavImg\" src=\"/cnams/resource/lcms/cnams_site/english/generic_site_areas/staticcontentassets/images/cnamsheader/up.gif\" style=\"width:10;\"/>";			
			}
			
			leftNavTree +="</td>";
	}
	if(nodeLevel == 0)
		{
			////////alert("going to call updatenav 1 time--->" + tree.getAttribute("url"));
			leftNavTree +="<td id=\""+ nodeID +"LeftNav\" colspan=\"3\" class=\"level_0_brick " + "selectedItem" + "\" onclick=\"updateNavs('"+ tree.getAttribute("url") + "');getContent('"+ tree.getAttribute("url") + "');\">";
			//leftNavTree +="<td id=\""+ nodeID +"LeftNav\" colspan=\"3\" class=\"level_0_brick " + "selectedItem" + "\" onclick=\"updateLeftNav('" + nodeID + "','" + nodeLevel + "');updateTopNav('" + parentNodeIdLeftNav + "','1');getContent('"+ tree.getAttribute("url") + "');\">";
		}else{
			
			leftNavTree +="<td id=\""+ nodeID +"LeftNav\" colspan=\"" + (3 - nodeLevel) +"\" class=\"level_" + nodeLevel + "_brick " + brickColor + "\" onclick=\"updateLeftNav('" + nodeID + "','" + nodeLevel + "');updateTopNav('" + parentNodeIdLeftNav + "','1');updateNavs('"+ tree.getAttribute("url") + "');getContent('"+ tree.getAttribute("url") + "');\">";
			//leftNavTree +="<td id=\""+ nodeID +"LeftNav\" colspan=\"" + (3 - nodeLevel) +"\" class=\"level_" + nodeLevel + "_brick " + brickColor + "\" onclick=\"updateNavs('"+ tree.getAttribute("url") + "');getContent('"+ tree.getAttribute("url") + "');\">";
			
		}
	//leftNavTree +="<a onclick=\"updateLeftNav('" + nodeID + "','" + nodeLevel + "');updateTopNav('" + parentNodeIdLeftNav + "','1');getContent('"+ tree.getAttribute("url") + "');\">" + tree.getAttribute("text") + "</a>";
	////////alert("going to call updatenav 2 time--->" + tree.getAttribute("url"));
	leftNavTree +="<a onclick=\"updateNavs('"+ tree.getAttribute("url") + "');getContent('"+ tree.getAttribute("url") + "');\">" + tree.getAttribute("text") + "</a>";
		leftNavTree +="</td>";
  	leftNavTree +="</tr>";	
    
    
    /*******	CODE ADDED BY GAURAV **********/    
	for(var i=0; i<tree.childNodes.length; i++){
		if(tree.childNodes[i].getAttribute("showInNavs")!="false"){
		traverse(tree.childNodes[i]);
		}
	}
	/*******	CODE ADDED BY GAURAV **********/
		
	if((tree.getAttribute("itemType") == "menuBarItem") || (nodeLevel == 0))
	{
				leftNavTree +="</table>";
			leftNavTree +="</td>";
		leftNavTree +="</tr>";
	}
}

// This function is used to generate the Top Nav fly-out menu also 
// from the XML which is used for generating the Left Nav

// Initializing the counter to "1" to skip the Root node corresponding to the Module Name
var topNavIdCounter = 1;
var topNavParentElementArrayCnt = 0;
var topNavMenuItemParentArrayCnt = 0;


function traverseForTopNav(tree) 
{
	if(tree.hasChildNodes() || (tree.getAttribute("itemType") == "menuBarItem"))
    {
    	if((tree.getAttribute("class") != parentNodeClass) && (tree.getAttribute("itemType") == "menuBarItem"))
       	{
   			var nodeLevel = tree.getAttribute("class").charAt((tree.getAttribute("class").indexOf("_") + 1));
       		var parentNodeId = "m" + topNavIdCounter + "_" + tree.getAttribute("id");
       		topNavParentElementArray[topNavParentElementArrayCnt] = parentNodeId;
       		topNavParentElementArrayCnt = topNavParentElementArrayCnt + 1;
       		topNavIdCounter = topNavIdCounter + 1;
       		
       		var onmouseoverStr = "ddHideAll();actuatorMouseover(event, '" + parentNodeId + "','s', -4, -65);return true;";
			var onmouseoutStr = "actuatorMouseout(event, '" + parentNodeId + "');";//updateTopNav('" + parentNodeId + "','0');return true;";       		
			//var onclickStr = "updateLeftNav('" + parentNodeId + "','0');getContent('" + tree.getAttribute("url") + "');";
			////////alert("in navigation.js, traverseForTopNav---going to call updateNavs with url -->" + tree.getAttribute("url"));
			////////alert("going to call updatenav 3 time--->" + tree.getAttribute("url"));
			var onclickStr = "updateNavs('" + tree.getAttribute("url") + "');getContent('" + tree.getAttribute("url") + "');";
			
       		menubarString += "<td height=\"26\" " +
	       						" align=\"left\" " +
	       						" id=\"" + parentNodeId + "TopNav\" " + 
	       						" class=\"nav\" " + 
	       						" onclick=\"" + onclickStr + "\" " +
	       						" onmouseover=\"" + onmouseoverStr + "\" " + 
	       						" onmouseout=\"" + onmouseoutStr  + "\">" +
	       							"<a rel=\"exit\" name=\"&amp;lpos=N4\">" + tree.getAttribute("text") + "</a>" + 
	       					"</td>"; 
			
			// This if block is for main menus in a particular module.
			// For eg, Program, Course catalog menus in Library module			
			if(tree.hasChildNodes())
			{
				//alert("onclickStr->" + onclickStr);
				menubarString += "<td id=\"" + parentNodeId + "TopNavImg\" width=\"23\" " + 
									" class=\"navImg\" " + 
									" onclick=\"" + onclickStr + "\"" +
									" onmouseover=\"" + onmouseoverStr + "\" " + 
									" onmouseout=\"" + onmouseoutStr + "\">" +
								"</td>";
			}
			else
			{
				menubarString += "<td width=\"1px\" " + 
									" class=\"topNavMenuSeparator\">" +
									"<img src=\"/cnams/resource/lcms/cnams_site/english/generic_site_areas/staticcontentassets/images/flyouts/separator.gif\"/ width=\"1px\">" + 
								"</td>";
			}
       		
			// This if block is for sub menus under main menus in a particular module.
			// For eg, Academy Overview, under Program menu in Library module
			if(tree.hasChildNodes())
       		{
       			
	       		menuString += "<div onmouseover=\"changeArrowMouseOver('" + parentNodeId + "TopNavImg')\" " +
	       						" class=\"menuFrame\" " +
	       						" id=\"" + parentNodeId + "Frame\">" +
	       							"<div class=\"menu\" id=\""+ parentNodeId+"\">" +
	       								"<ul>";
	            
	            var nodeId;
	            for(var i=0; i<tree.childNodes.length; i++)
	            {
	            	nodeId = "m" + topNavIdCounter + "_" + tree.childNodes[i].getAttribute("id");
	            	topNavIdCounter = topNavIdCounter + 1;
	            	
	            	nodeLevel = tree.childNodes[i].getAttribute("class").charAt((tree.getAttribute("class").indexOf("_") + 1));
					
	            	var className = "";
	        	 	if(i%2 == 0)
		            	className = menuItemEvenClass; 
		            else
						className = menuItemOddClass; 		            		

				/*	menuString += "<li id='" + nodeId + "TopNav' " + 
									" class=\"" + className + "\" " + 
									" onclick=\"updateLeftNav('"+ nodeId + "','" + nodeLevel + "');getContent('" + tree.childNodes[i].getAttribute("url") + "');\">" +
										"<a rel=\"exit\" name=\"&amp;lpos=N1\">" + tree.childNodes[i].getAttribute("text") + "</a>" +
								"</li>"; */
						//alert("going to call updatenav 2nd time --->" + tree.childNodes[i].getAttribute("url"));
						menuString += "<li id='" + nodeId + "TopNav' " + 
									" class=\"" + className + "\" " + 
									" onclick=\"updateNavs('" + tree.childNodes[i].getAttribute("url") + "');getContent('" + tree.childNodes[i].getAttribute("url") + "');\">" +
										"<a rel=\"exit\" name=\"&amp;lpos=N1\">" + tree.childNodes[i].getAttribute("text") + "</a>" +
								"</li>";
	            }

	            menuString += 			"</ul>" +
	            					"</div>" +
	            				"</div>";            
        	}
        }
        else
        {
        	for(var i=0; i<tree.childNodes.length; i++)
            	traverseForTopNav(tree.childNodes[i]);
        }
    }
}


function updateLeftNav(id,nodeLevel)
{
	////////alert("in updateLeftNav");
	//Create ID for the Left Nav Menu Item that will be highlighted
	var leftNavId = id + "LeftNav";
	//Create ID for the Container that will be visible in Left Nav
	var containerLeftNavId = id + "LeftNav_Container";
	//Create ID for the corresponding Top Nav Menu Item whose parent menu will be highlighted in Top Nav
	var topNavId = id + "TopNav";
	//Create ID for the Container that will be visible in Left Nav
	var containerTopNavId = topNavId;
	
	
	//Reset any selected items to unselected status in the left nav
	leftNavTree = leftNavTree.replace(/selectedItem/g,"unSelectedItem");
	//Reset all Menus to hidden in the left nav
	leftNavTree = leftNavTree.replace(/visibleMenu/g,"hiddenMenu");

	//Check if we have reached here on the click of a 'Top Menubar' item
	if(nodeLevel == "2")
	{
		var parentId = document.getElementById(topNavId).parentNode.parentNode.id;
		////////alert("parentId-->" + parentId);
		containerLeftNavId = parentId + "LeftNav_Container";
		containerTopNavId = parentId + "TopNav";		
	}
	
	//Set this new tree structure in the left Nav  
	if (document.getElementById("leftNav")) {		
		document.getElementById("leftNav").innerHTML = leftNavTree;		
	}

	////////alert("leftNavId::" + leftNavId + "--nodeLevel::" + nodeLevel);
	//make suitable menu visible and highlight the suitable item
	//if(nodeLevel != "0")
	//{
	//	//////alert("here");
		if(document.getElementById(containerLeftNavId))
		document.getElementById(containerLeftNavId).className = document.getElementById(containerLeftNavId).className.replace(/hiddenMenu/g,"visibleMenu");
	//}
	if(document.getElementById(leftNavId))
	document.getElementById(leftNavId).className += " selectedItem";
		
		
	activeParentID = containerTopNavId;
	activeCurrentLinkId = id;
	
	////////alert("Img - " + document.getElementById("m10_attendingFairLeftNavImg").height);
	updateLeftNavTreeImages();
}

function updateTopNav(menuId,eventType)
{	

	topNavArrowImg = document.getElementById(lastSelectedTopNavImg);

	//Handle the case when Root Node in Left Nav is clicked
	if(menuId == "undefined")
	{
		if((document.getElementById(lastSelectedTopNav) != null) && (document.getElementById(lastSelectedTopNav) != ""))
			document.getElementById(lastSelectedTopNav).className = "nav";
	
		if(topNavArrowImg != null)
	  		document.getElementById(lastSelectedTopNavImg).className = "navImg";
		return;
	}	
	
	var topMenuId = menuId + "TopNav";
	var topMenuImgId = topMenuId + "Img";

	if(document.getElementById(topMenuId) != null)
	{
		if(topMenuId == activeParentID)
		{
			var currentClass = document.getElementById(topMenuId).className;
			
			//Reset the Top Menu highlight to plain color
		  	if((lastSelectedTopNav != "") && (lastSelectedTopNav != activeParentID))
		  	{
		  		document.getElementById(lastSelectedTopNav).className = "nav";
				if(topNavArrowImg != null)
			  		document.getElementById(lastSelectedTopNavImg).className = "navImg";
		  		
		  	}
					  	
			//Reset any selected items to unselected status in the left nav
			if(currentClass.indexOf(" selectedTopnav") == -1)
			{
				document.getElementById(topMenuId).className += " selectedTopnav";
				if(document.getElementById(topMenuImgId) != null)
		  			document.getElementById(topMenuImgId).className = "selectedTopnavImg";
			}
	
			lastSelectedTopNav = topMenuId;
			if(document.getElementById(topMenuId + "Img") != null)
				lastSelectedTopNavImg = topMenuId + "Img";
		}
		else
		{
			// 0 : OFF (i.e. not higlighted) -- onmouseout event 
			// 1 : ON  (i.e. higlighted) 	 -- onmouseover / onmouseclick event
			switch(eventType)
			{
				case "0":	document.getElementById(topMenuId).className = "nav";
							if(document.getElementById(topMenuImgId) != null)
								changeArrowMouseOut(topMenuImgId);
							break;
				case "1":	if(document.getElementById(topMenuId).className.indexOf(" hover") == -1)
								document.getElementById(topMenuId).className += " hover";
							if(document.getElementById(topMenuImgId) != null)
								changeArrowMouseOver(topMenuImgId);
							break;
			}
			
		}
	}		
}

// This method changes the arrow image from light to dark and vice-versa
function changeArrowMouseOver(arrowImgId)
{
	var currentClass = document.getElementById(arrowImgId).className;
	
	if(currentClass.indexOf(" selectedTopnav") == -1)
	{
		document.getElementById(arrowImgId).className += " selectedTopnavImg";
	}
}
function changeArrowMouseOut(arrowImgId)
{
	//alert("in changeArrowMouseOut");
	document.getElementById(arrowImgId).className = "navImg";
}

// This function switches the onmouseover color between white and normal
// 0 : Change to white
// 1 : Change to previous color
var oldClassName = "";
function changeBgColor(menuItemID,mode)
{
	switch(mode)
	{
		case 0:	oldClassName = document.getElementById(menuItemID).className;
				document.getElementById(menuItemID).className = "highlightMenuItem";
				break;
		case 1:	document.getElementById(menuItemID).className = oldClassName;
				break;
	}	
}

// This function checks is needed because "window.location.href" is not supported across all browsers
// If it is supported, we simply execute window.location.href, 
// else we click the link programmatically 
var isClicked = "false";
function linkCheck(url,linkID)
{

	if(isClicked == "false")
	{
		// This is done to prevent click event from being called twice
		// once for the <td> tag and one for the actual <a href> simulated/real click
		isClicked = "true";
		
		theLink = document.getElementById(linkID);
		if ((theLink) && (theLink.click)) 
			theLink.click();
		else 
			window.location.href = url;
	}
}

function mlIncreaseHeight(ob)
{
	var current = parseInt(ob.style.height);
	var newh = current + 1;
	ob.style.height = newh+'px';
}

function mlDecreaseHeight(ob)
{
	var current = parseInt(ob.style.height);
	var newh = current - 1;
	ob.style.height = newh+'px';	
}


var originalHomeOffsetHeight = 0; // This variable is needed to capture the height of a fully opened menu and restore it onmouseout
var isOriginalHomeOffHeightInit = "false";
var originalSearchOffsetHeight = 0; // This variable is needed to capture the height of a fully opened menu and restore it onmouseout
var isOriginalSearchOffHeightInit = "false";

var timerVar;
var isHomeMenuOpen;
var isResourceMenuOpen;
var isSearchMenuOpen;

timerVar = setInterval("checkAndCloseTopMenu()",100);

function showHeaderMenu(src, element)
{
	hideAllMenu();
		
	var elementObj = document.getElementById(element);
	//originalOffsetHeight = elementObj.offsetHeight;
	
	elementObj.style.display = '';
	
	var srcElementObj = src;
	for(var zx=zy=0; srcElementObj!=null; zx+=srcElementObj.offsetLeft, zy+=srcElementObj.offsetTop, srcElementObj=srcElementObj.offsetParent);
		pos={x:zx,y:zy};

	var height;
	
	// This part of code is necessary to prevent the drop-down menu from increasing in size in Mozilla
	// because mozilla measures offsetHeight including borderwidth. So every time the height keeps on increasing
	switch(element)
	{
		case "HomeMenu":	if(isOriginalHomeOffHeightInit == "false")
							{
								originalHomeOffsetHeight = parseInt(elementObj.offsetHeight);
								isOriginalHomeOffHeightInit = "true";
							}	
				
							if(originalHomeOffsetHeight < elementObj.offsetHeight)
								height = originalHomeOffsetHeight;
							else
								height = parseInt(elementObj.offsetHeight);

							break;
		case "ResourceMenu":	if(isOriginalHomeOffHeightInit == "false")
							{
								originalHomeOffsetHeight = parseInt(elementObj.offsetHeight);
								isOriginalHomeOffHeightInit = "true";
							}	
				
							if(originalHomeOffsetHeight < elementObj.offsetHeight)
								height = originalHomeOffsetHeight;
							else
								height = parseInt(elementObj.offsetHeight);

							break;					
		case "SearchMenu":	if(isOriginalSearchOffHeightInit == "false")
							{
								originalSearchOffsetHeight = parseInt(elementObj.offsetHeight);
								isOriginalSearchOffHeightInit = "true";
							}	
	
							if(originalSearchOffsetHeight < elementObj.offsetHeight)
								height = originalSearchOffsetHeight;
							else
								height = parseInt(elementObj.offsetHeight);

							break;
		}
										
	elementObj.style.height = '0px';
	elementObj.style.overflow = 'hidden';
	elementObj.style.left = pos.x;
	elementObj.style.top = pos.y + src.offsetHeight - 1;
	elementObj.style.width = src.offsetWidth;
	
	for(var i=0;i<height;i++){
		
		setTimeout(function(){mlIncreaseHeight(elementObj)},i*3);
	}
	setTimeout(function(){elementObj.style.visibility='visible';},height*1);

	switch(element)
	{
		case "HomeMenu": isHomeMenuOpen = "true";
							break;
		case "ResourceMenu": isResourceMenuOpen = "true";
							break;					
		case "SearchMenu": isSearchMenuOpen = "true";
							break;
														
	}
	
}


/*function hideHeaderMenu(element)
{
	var elementObj = document.getElementById(element);
	if(elementObj.offsetHeight)
	{
	////////alert(elementObj.style.height);
		var height = parseInt(elementObj.style.height);
		elementObj.style.overflow = 'hidden';

		for(var i=1;i<height;i++){
			setTimeout(function(){mlDecreaseHeight(elementObj)},i*5);
			////////alert(elementObj.style.height);
		}
		
		setTimeout(function(){elementObj.style.visibility='hidden';},height*5);
		elementObj.style.height=height;
		elementObj.style.offsetHeight=height;		
	}
}*/

function showActiveMenu(element)
{

	var elementObj = document.getElementById(element);
	elementObj.style.visibility='visible';
	
	switch(element)
	{
		case "HomeMenu": isHomeMenuOpen = "true";
							break;
		case "ResourceMenu": isResourceMenuOpen = "true";
							break;					
		case "SearchMenu": isSearchMenuOpen = "true";
							break;							
	}
}

function hideHeaderMenu(element)
{
	////////alert("Hiding");
	////////alert("originalOffsetHeight inside hideHeaderMenu = " + originalOffsetHeight);
	//document.getElementById(element).style.offsetHeight = originalOffsetHeight;
	////////alert("height in hide is - " + document.getElementById(element).style.height);
	document.getElementById(element).style.visibility = 'hidden'; 
	switch(element)
	{
		case "HomeMenu": isHomeMenuOpen = "false";
							break;
		case "ResourceMenu": isResourceMenuOpen = "false";
							break;					
		case "SearchMenu": isSearchMenuOpen = "false";
							break;							
	}
}
function hideAllMenu()
{
	var divElements=document.getElementsByTagName("div");
	for(i=0; i<divElements.length;i++ )
	{
		////////alert(divElements[i].Id);
		if(divElements[i].id.search(/.*Menu.*/)>-1)
		{
			////////alert("ID is : " + divElements[i].id);
			hideHeaderMenu(divElements[i].id);
			
		}
	}
	//document.getElementById(element).style.visibility = 'hidden'; 
}	
	
function checkAndCloseTopMenu(event)
{
	if(isHomeMenuOpen == "false")
		hideHeaderMenu("HomeMenu");
	if(isResourceMenuOpen == "false")
		hideHeaderMenu("ResourceMenu");
	if(isSearchMenuOpen == "false")
		hideHeaderMenu("SearchMenu");		
}
	
// Code Change Ends

function popitup(url)
{
	if (newwindow.location && !newwindow.closed)
	{
		newwindow.location.href = url;
	    newwindow.focus();
	}
	else
	{
		newwindow=window.open(url,'htmlname','width=350,height=250,resizable=1');
	}
}

// This method takes as parameter url of fourth level and returns url at the
// third level so that left navigation gets updated for fourth level as well.
function updateLeftNavForFourthLevel(element)
{
	var leftNavUrl;
	switch(element)
	{
		case "/resource/lcms/cnams_site/english/generic_site_areas/library/course_catalog/CCNA_servers.html": 
			leftNavUrl = "/resource/lcms/cnams_site/english/generic_site_areas/library/course_catalog/ccnaDiscovery_role.html";
			break;	
		case "/resource/lcms/cnams_site/english/generic_site_areas/library/course_catalog/CCAIIT.html": 
			leftNavUrl = "/resource/lcms/cnams_site/english/generic_site_areas/library/course_catalog/FundIT1.html";
			break;	
		default:leftNavUrl=null;
			break;												
	}
	return leftNavUrl;
}