﻿// <copyright file="NavigationUtilities.js" company="BioCentury Publications Inc."> 
// All contents Copyright © 2005-2009 BioCentury Publications, Inc. ALL RIGHTS RESERVED
// 
// http://www.biocentury.com
// </copyright>


setTimeout('clear()',1);
function clear()
{
if (window.status!=null)
	{
	window.status="";
	setTimeout('clear()',1);
	}
}

if (navigator.userAgent.indexOf("MSIE") < 1)
	{
		//used for FF - topFrameClick
		HTMLElement.prototype.click = function() 
		{
			var evt = this.ownerDocument.createEvent('MouseEvents');
			evt.initMouseEvent('click', true, true, this.ownerDocument.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
			this.dispatchEvent(evt);
		}
	}

//-------------------------------------------------------------------------------
//used in right frame to collapse/expand top anf left frames
//-------------------------------------------------------------------------------
function collapseExpandFrames(img)
{
	if (img.title == "Show frames") {//show
	    document.body.style.backgroundImage = "url(../images/tree_bg_1.gif)"
	    document.body.style.backgroundRepeat = "repeat-y";
	   
    
		document.getElementById('topRow').style.display = '';
		document.getElementById('tdLeft').style.visibility = 'visible';
		document.getElementById('tdLeft').style.display = '';
		document.getElementById('tdMain').style.width = 'auto';
//		link = document.getElementById(linkID);
//		link.innerHTML = "&nbsp;&#171; Hide Left Navigation";
//		link.src = "../Images/collapse_lf.gif";
//		link.title = "Hide Left Navigation";

		img.src = "../Images/collapse_lftf.gif";
		img.title = "Expand this frame";
		
    }
    else {//hide
        document.body.style.backgroundImage = 'none';
    
        document.getElementById('topRow').style.display = 'none';
		document.getElementById('tdLeft').style.visibility = 'hidden';
		document.getElementById('tdLeft').style.display = 'none';
		document.getElementById('tdMain').style.width = '100%';
//		link = document.getElementById(linkID);
//		link.innerHTML = "&nbsp;&#187; Show Left Navigation";
//		link.src = "../Images/expand_lf.gif";
//		link.title = "Show Left Navigation";
		
		img.src = "../Images/expand_lftf.gif";
		img.title = "Show frames";
		
    }
}

//-------------------------------------------------------------------------------
// Edited by Marius on 10/20/2008
// used to collapse/expand left navigation panel
//-------------------------------------------------------------------------------
function toggleContents(param) 
{
	//only from statistics.aspx param will be null
	//hide collapse/expand left navigation panel
	if (param == null) 
	{
		param = document.getElementById('frame_ce');
		if (param.className == 'DivHidden') 
			param.className = 'DivVisible';
		else 
			param.className = 'DivHidden';
	}
	if (param.title == "Show Left Navigation") //parent.document.getElementById('info').cols == "0,*")
	{//show
	    document.body.style.backgroundImage = "url(../images/tree_bg_1.gif)"
	    document.body.style.backgroundRepeat = "repeat-y";
	    
        document.getElementById('tdLeft').style.visibility = 'visible';
        document.getElementById('tdLeft').style.display = '';

        document.getElementById('tdMain').style.width = 'auto';
        document.getElementById('tdMain').removeAttribute('colSpan');
        
		if (param.tagName.toLowerCase() == 'a')
		{
		    param.innerHTML = "&nbsp;&#171; Hide Left Navigation";
		    param.src = "../Images/collapse_left.gif";
		    param.title = "Hide Left Navigation";	
		}
		if (param.tagName.toLowerCase() == 'img')
		{
		    param.src = "../Images/collapse_left.gif";
			param.title = "Hide Left Navigation";
        }
	}
	else {//hide
        document.body.style.backgroundImage = 'none';

        document.getElementById('tdLeft').style.visibility = 'hidden';
        document.getElementById('tdLeft').style.display = 'none';


        document.getElementById('tdMain').style.width = '100%';
        document.getElementById('tdMain').setAttribute('colSpan', '2');        
        
		if (param.tagName.toLowerCase() == 'a')
		{
		    param.innerHTML = "&nbsp;&#187; Show Left Navigation";
		    param.src = "../Images/expand_right.gif";
		    param.title = "Show Left Navigation";
		}
		if (param.tagName.toLowerCase() == 'img')
		{
		    param.src = "../Images/expand_right.gif";
			param.title = "Show Left Navigation";
        }
	}
}

//-------------------------------------------------------------------------------
//Created by Marius 10/20/2008
//-------------------------------------------------------------------------------
function setHiddenShowHideValue(link) {
    //SaveInSession('showLeftNavigation', 'sdfsdfsd');
    SaveInSession('showLeftNavigation', escape(link.innerHTML));
}
//-------------------------------------------------------------------------------
//Created by Marius 10/21/2008
//-------------------------------------------------------------------------------
function setHiddenShowHideAllValue(img) {
    //SaveInSession('showLeftNavigation', 'sdfsdfsd');
    SaveInSession('showAllNavigation', escape(img.title));
}

//-------------------------------------------------------------------------------
// GLOBAL VARIABLES
//-------------------------------------------------------------------------------
var currentActiveLink = null;
var currentActiveLinkTitle = null;

//-------------------------------------------------------------------------------
// GetParam
// ADD by - Bela Gaspar - 11/29/2006
// Descr: return from document.location.search the asked parameter value
// Used in IsFromReport()
//-------------------------------------------------------------------------------
function GetParam(theSearchURL, theParamName)
{
	var start = theSearchURL.indexOf("?"+theParamName+"=");
	if (start < 0)
		start = theSearchURL.indexOf("&"+theParamName+"=");
	if (start < 0) 
		return '';
	start += theParamName.length + 2;
	var end = theSearchURL.indexOf("&",start) - 1;
	if (end < 0)
		end = theSearchURL.length;
	var result = theSearchURL.substring(start,end);
	var result='';
	for(var i = start; i <= end; i++)
	{
		var c = theSearchURL.charAt(i);
		result = result+(c=='+'?' ':c);
	}
	return unescape(result);
}


function GetIUProfile(theModule, theMenu)
{
	return ((theMenu.split('_')[1] == "I") ? (theMenu.split('_')[0] + ".aspx?ID=Investor") : (theModule + "\/" + theMenu.split('_')[0] + ".aspx?ID=Underwriter"));
}

function GetDatabase(theModule, theMenu)
{
	return ("../" + theModule + "/Database.aspx?ID="+theMenu.split('_')[1]);
}


//-------------------------------------------------------------------------------
function containsDOM (container, containee) {
  var isParent = false;
  do {
    if ((isParent = container == containee))
      break;
    containee = containee.parentNode;
  }
  while (containee != null);
  return isParent;
}

function checkMouseLeave (element, evt) {
  if (element.contains && evt.toElement) {
    return !element.contains(evt.toElement);
  }
  else if (evt.relatedTarget) {
    return !containsDOM(element, evt.relatedTarget);
  }
}
//-------------------------------------------------------------------------------

var currentVisibleLevel2 = null;
//-------------------------------------------------------------------------------
//used in nav_top mouseover level1 links
//-------------------------------------------------------------------------------
function showHideLevel2(aLink)
{
	if (currentVisibleLevel2 == null && currentActiveLinkTitle != null)
		currentVisibleLevel2 = document.getElementById('div'+currentActiveLinkTitle.id.split('_')[0]);
	if (currentVisibleLevel2 != null)
		currentVisibleLevel2.className = 'DivHidden';
	
	if (aLink != null && document.getElementById('div'+aLink.id.split('_')[0]) != null)
	{
		document.getElementById('div'+aLink.id.split('_')[0]).className = 'DivVisible';
		currentVisibleLevel2 = document.getElementById('div'+aLink.id.split('_')[0]);
	}
}

//-------------------------------------------------------------------------------
// ADD - Bela Gaspar - 04/05/2006
// Company -> Create List
// Left frame Show Hide
// START ...
//-------------------------------------------------------------------------------

		//global var used in menu
		var currentOpenedMenuId = "";
		var menuSlideSpeed = 10;
		var menuSlideStep = 15;
		var operationInProgress = false;

		var menuItems = new Array();
		
		function init()
		{
			var args = init.arguments;
			for (var i = 0; i < args.length; i++) 
			{
				var items = document.getElementById(args[i]).childNodes;
				for (var j=0;j<items.length;j++)
				{
					if (items[j].nodeType == 1)
						menuItems[items[j].id] = initMenuItem(items[j].id);
				}
			}
		}
		function initMenuItem(id)
		{
			var menuItem = document.getElementById(id);
			var menuHeight = menuItem.offsetHeight;
			menuItem.style.height = "1px";
			menuItem.height = "1";
			menuItem.style.display = "none";
			return menuHeight;
		}
		function OpenCloseMenu(menuId)
		{
			//menuId - "General", "Pipeline" ...
			if (operationInProgress) 
			{
				var func = "OpenCloseMenu('" + menuId + "');";
				setTimeout ( func, menuSlideSpeed );
				return;
			}
			operationInProgress = true;
			activeModule = "_" + menuId;
			if (currentOpenedMenuId == menuId)
			{
				//you have clicked the same menu, so close it;
				var items = document.getElementById(currentOpenedMenuId).childNodes;
				for (var i=0;i<items.length;i++)
				{
				    if (items[i].nodeName.toLowerCase() == "div")
						CloseMenu(items[i].id, "");
				}
				currentOpenedMenuId = "";
				activeModule = "";
				ChangeColapseExpandImage(menuId);
			}
			else
			{
				if (currentOpenedMenuId != "")
				{
					var items = document.getElementById(currentOpenedMenuId).childNodes;
					for (var i=0;i<items.length;i++)
					{
						if (items[i].nodeType == 1)
							CloseMenu(items[i].id, '');
					}
					
					var items = document.getElementById(menuId).childNodes;
					for (var i=0;i<items.length;i++)
					{
						if (items[i].nodeType == 1)
							ShowMenu(items[i].id);
					}
					ChangeColapseExpandImage(menuId);
					ChangeColapseExpandImage(currentOpenedMenuId);
					currentOpenedMenuId = menuId;
					
				}
				else
				{
					var items = document.getElementById(menuId).childNodes;
					for (var i=0;i<items.length;i++)
					{
						if (items[i].nodeType == 1)
							ShowMenu(items[i].id);
					}
					currentOpenedMenuId = menuId;
					ChangeColapseExpandImage(menuId);
				}
			}
		}
		
		function ChangeColapseExpandImage(menuId)
		{
			if (document.getElementById(menuId+"_ec")!=null)
			{
				if (document.getElementById(menuId + '_ec').title == "Collapse Summary")
				{
				document.getElementById(menuId + '_ec').src	= document.getElementById(menuId + '_ec').src.replace('collapse','expand');
				document.getElementById(menuId + '_ec').title	= 'Expand Summary';
				}
				else
				{
				document.getElementById(menuId + '_ec').src	= document.getElementById(menuId + '_ec').src.replace('expand','collapse');
				document.getElementById(menuId + '_ec').title	= 'Collapse Summary';
				}
			}
		}
		
		function ShowMenu(menuId)
		{
			var menuHeight = menuItems[menuId];
			OpenMenu(menuId,1,menuHeight);
		}
		
		function OpenMenu(menuId,height,maxHeight)
		{
			var menu = document.getElementById(menuId);
			//top.parent.frames[1].gCurrentModule = menuId;
			menu.style.display = "block";
			if (height < maxHeight)
			{
				
				menu.style.height = "" + height + "px";
				var func = "OpenMenu('" + menuId + "'," + (parseInt(height) + menuSlideStep) + "," + maxHeight + " );";
				setTimeout ( func, menuSlideSpeed );
			}
			else
			{
				menu.style.height = "";
				operationInProgress = false;
			}
			
		}
		
		function CloseMenu(closeMenuId,openMenuId)
		{
		    var filterName = closeMenuId.split('_')[1]; //Region
		    if (document.getElementById('ctl00_cphMain_lbl' + filterName + 'Summary').style.color != '' &&
                document.getElementById('ctl00_cphMain_lbl' + filterName + 'Summary').style.color != '#000000')
		        return false;
			var menu = document.getElementById(closeMenuId);
			var height = parseInt(menu.offsetHeight);
			if (height > menuSlideStep)
			{
				menu.style.height = "" + (parseInt(height) - menuSlideStep) + "px";
				var func = "CloseMenu('" + closeMenuId + "','" + openMenuId + "');";
				setTimeout ( func, menuSlideSpeed );
			}
			else
			{
				if (menu)
				{
					menu.style.height = "1px";menu.style.display = "none";
				}
				operationInProgress = false;
			}
			
		}
//-------------------------------------------------------------------------------
// END ...
//-------------------------------------------------------------------------------		


//-------------------------------------------------------------------------------
// ADD - Bela Gaspar - 3/7/2007
// HELP
// Descr: open help window in the pop-up
//-------------------------------------------------------------------------------
function createHelpPopUp(helpType) 
{
    window.open('../../BioCenturyHelp/PreparingReports.aspx');
}

//-------------------------------------------------------------------------------
// ADD - Bela Gaspar - 3/7/2007
// Descr: Hide row (tr) elements
//-------------------------------------------------------------------------------
function HideTRs(theTRName)
{
	for(var i=0; i<document.getElementsByTagName("tr").length; i++)
	{
		if (document.getElementsByTagName("tr")[i] && 
			document.getElementsByTagName("tr")[i].id.split("_")[0] == theTRName)
		{
			document.getElementsByTagName("tr")[i].style.display = 'none';
		}
	}
	// Particular case: Company-> FindCompanies.aspx
	if (document.getElementById('listArea') != null)
		document.getElementById('listArea').style.display = 'none';
}