var _SelectedMenuTdID	=	"";
var _TotalMenuTdCount	=	0;
/**************************************************************************
	 Function to Hide all the layers on a Page
**************************************************************************/

function HideLayer(pLayer, bCascade) {
	for (var i=0; i<pLayer.length; i++) {
		pLayer[i].visibility  =  "hide";
		if (bCascade)
			HideLayer(pLayer[i].document.layers, true);
	}
}

/**************************************************************************
	 Function to Hide all the layers on a Page
**************************************************************************/

/**************************************************************************
	 Function to Hide all the divs on a Page
**************************************************************************/
		
function HideDivTags() {
	var pDivs	=	"";
	var sDivNm	=	"";
	if ( navigator.family  ==  "IE" ) 
		pDivs  = document.all.tags("div");	
	else
		pDivs  = document.getElementsByTagName("div");	

	for ( var i = 0; i < pDivs.length; i++) {
		sDivNm		=	pDivs[i].id;
		if ( sDivNm.substr(0,3)  ==  "mnu" )
			//pDivs[i].className	=	"hide";
			pDivs[i].style.display	=	"none";
	}
}

/**************************************************************************
	 Function to Hide all the divs on a Page
**************************************************************************/



function openMX20RegisterPage(passedlink)
{
	parent.location.href = passedlink
}




/**************************************************************************
	 Function to Toggle the Menus
**************************************************************************/
		
function ToggleMenu(pAnkr, pDivLyr) {
	
//alert(pAnkr);

	// This is added on 17/3/06 to hide the previous dropdown when a new dropdown is shown on a new menu
	HideDivTags();
	// This is added on 17/3/06 to hide the previous dropdown when a new dropdown is shown on a new menu
	
	if ( isUndefined(pDivLyr) ==  false )
	{									
		var nArgs	=	arguments.length;
		var pLayer	=	document.layers;
		switch (navigator.family) {
			case "IE":
				pDivLyr.style.display	=	'';
				break;
			case "nn":
				pDivLyr.style.display	=	'';
				break;
			case "gecko":
				HideDivTags();
				pDivLyr		=	document.getElementById(pDivLyr);
				break;
			default:
				break;
		}
		if (nArgs != 0) {				
			// check which browser we are
			var pDynElem = (pLayer ? pDivLyr.visibility : pDivLyr.className);
			
			// be smart about namimg display classes
			pDynElem = (pDynElem = "hide" ? "show" : "hide");
			
			// make the changes to the style or class
			switch(navigator.family) {
				case "nn":
					pDivLyr.visibility = pDynElem;
					if (pDynElem == "show") {
						pDivLyr.left = pAnkr.x;
						pDivLyr.top  = pAnkr.y + 15;
					}
				break;
				default:
					pDivLyr.className = pDynElem;
				break;
			}
		}
		
	}
	else
	{
		HideDivTags();
	}
		
	return(false);
}

/**************************************************************************
	 Function to Toggle the Menus
**************************************************************************/

/**************************************************************************
	 Function to Handle the Mouse Out Event
**************************************************************************/

function OnMouseOutCheck(pDiv)
{
	// Commented the return statement to hide the divs on mouse out	
	//return;
	switch(navigator.family) {
		case "IE":
			if (!pDiv.contains(event.toElement)) ToggleMenu();
			break;
		case "nn":
			ToggleMenu();
			break;
		case "gecko":
			//var pDivTag = document.getElementById(pDiv);
			//Toggle();			
			//if (!pDivTag.contains(event.toElement)) 
			//	pDivTag.className = "hide";
			break;
		default:
			break;
	}	
}

/**************************************************************************
	 Function to Handle the Mouse Out Event
**************************************************************************/

/**************************************************************************
	 Function written to handle the onClick event of all the submenus
**************************************************************************/

function fnClick(strUrl)
{
	var ObjIframe   =   document.getElementById("ifrContent");	
	ObjIframe.src   =   strUrl;
}

/**************************************************************************
	 Function written to handle the onClick event of all the submenus
**************************************************************************/

/**************************************************************************
	 Function to Handle the Div Mouse Out Event 
**************************************************************************/

function OnDivMouseOut(pDiv) 
{	
	
	// Commented the return statement to hide the divs on mouse out	
	//return;
	switch(navigator.family) {
		case "IE":
			if (!pDiv.contains(event.toElement)) 
				HideTags();
				break;
		case "nn":				
			if (!pDiv.contains(event.toElement))
			{
				HideTags();
			}			
			break;
		case "gecko":
			//var pDivTag = document.getElementById(pDiv);
			//Toggle();			
			//if (!pDivTag.contains(event.toElement)) 
			//	pDivTag.className = "hide";
			break;
		default:
			break;
	}	
}

/**************************************************************************
	 Function to Handle the Div Mouse Out Event 
**************************************************************************/

/**************************************************************************
	 Function to Hide all the Div tags on a page 
**************************************************************************/

function HideTags() 
{
	
	var pDivs	=	"";
	var sDivNm	=	""		;
	if ( navigator.family  ==  "IE" ) 
		pDivs	=	document.all.tags("div");	
	else
		pDivs	=	document.getElementsByTagName("div");	
		

	for ( var i = 0; i < pDivs.length; i++) {
		sDivNm	=	pDivs[i].id;
		if ( sDivNm.substr(0,3)  ==  "mnu" )				
		// Commented to make it work in Firefox
		// Also converted the layer tag to div tag in the xsl file for firefox
		//pDivs[i].className	=	"hide";
		pDivs[i].style.display	=	'none';
		
	}
}

/**************************************************************************
	 Function to Hide all the Div tags on a page 
**************************************************************************/

/**************************************************************************
	 Function to Check if the object is Undefined 
**************************************************************************/

function isUndefined(a) 
{ 
	return typeof a == 'undefined'; 
} 

/**************************************************************************
	 Function to Check if the object is Undefined 
**************************************************************************/

/**************************************************************************
	 Function to Handle the Div Mouse Out Event for Firefox
**************************************************************************/

function OnDivMouseOutFox(pDiv,evt) 
{	
	// Commented the return statement to hide the divs on mouse out	
	//return;
	switch(navigator.family) {
		case "IE":
			if (!pDiv.contains(event.toElement)) 
				HideTags();
				break;
		case "nn":				
			
			pDiv   =  evt.currentTarget.id;
			pDiv   =  document.getElementById(pDiv);
	
			if (!containsDOM(pDiv,evt.relatedTarget))
			{
				HideTags();
			} 
			
			break;
		case "gecko":
			//var pDivTag = document.getElementById(pDiv);
			//Toggle();			
			//if (!pDivTag.contains(event.toElement)) 
			//	pDivTag.className = "hide";
			break;
		default:
			break;
	}	
}

/**************************************************************************
	 Function to Handle the Div Mouse Out Event for Firefox
**************************************************************************/

/**************************************************************************
	 Function to Check whether an element is present in a Container
**************************************************************************/

function containsDOM (container, containee) 
{
  var isParent = false;
  do {
    if ((isParent = container == containee))
      break;
    containee = containee.parentNode;
  }
  while (containee != null);
  return isParent;
}

/**************************************************************************
	 Function to Check whether an element is present in a Container
**************************************************************************/

/**************************************************************************
	 Function to Set the Url and Open a new page
**************************************************************************/

function openpage(passedlink)
{
	window.location.href = passedlink
}

/**************************************************************************
	 Function to Set the Url and Open a new page
**************************************************************************/

/**************************************************************************
	 Function to Hide all the Submenus
**************************************************************************/

function HideAllSubmenus()
{
	HideDivTags();
}

/**************************************************************************
	 Function to Hide all the Submenus
**************************************************************************/

/**************************************************************************
	 Function to Check whether an element is present in a Container
**************************************************************************/

function contains(a, b)
 {
	// Return true if node a contains node b.
	while (b.parentNode)
	if ((b = b.parentNode) == a)
	return true;
	return false;
 }

/**************************************************************************
	 Function to Check whether an element is present in a Container
**************************************************************************/

/**************************************************************************
   Function to Open Pages in Iframe instead of passing numbers to the url
**************************************************************************/
function OpenPageInIframe( PageLink, _SelectedMenuID )	
{	
	// Set the Global Variable for SelectedMenuTdId with the Clicked Menu Option
	_SelectedMenuTdID	=	_SelectedMenuID;
	
	SetSelectedMenuOptionValue( _SelectedMenuTdID );
	
	if ( PageLink.length  >  0 )
	{
		// Deselect all the others
		HightLightCell(document.getElementById(_SelectedMenuID), true, _TotalMenuTdCount )
		// Highlight only the Selected and deselect all the others
		document.getElementById(_SelectedMenuID).style.background =  "#1B7CCD"
		
		var ObjIframe	=	document.getElementById("ifrContent");
		ObjIframe.src	=	PageLink;
		//alert(ObjIframe.src)		
	}		
	
	
}

/**************************************************************************
   Function to Open Pages in Iframe instead of passing numbers to the url
**************************************************************************/


/**************************************************************************
   Function to Hide the Right Menu when the Registration Pages Load
**************************************************************************/
/*
function OpenComPagesInIframe( PageLink )	
{	
	if ( PageLink.length  >  0 )
	{
		var ObjIframe			=	document.getElementById("ifrContent");		
		var ObjRightSideMenuTd	=	document.getElementById("tdRightSideMenu");
		var ObjContentTd		=	document.getElementById("tdContent");
		
		// If the Page clicked is Registration from the com site
		if ( PageLink.indexOf("Registration.aspx")  ==  19 )		
		{		
			if ( ObjRightSideMenuTd )
			{
				ObjRightSideMenuTd.style.display	=	'none';
				ObjContentTd.colSpan				=	'3';		
				ObjIframe.src						=	PageLink;
			}
		}
		// else if the Page clicked is Company Registration from the com site
		else if ( PageLink.indexOf("CompanyCustom.aspx")  ==   9 )
		{
			if ( ObjRightSideMenuTd )
			{
				ObjRightSideMenuTd.style.display	=	'none';
				ObjContentTd.colSpan				=	'3';		
				ObjIframe.src						=	PageLink;
			}			
		}
		// else if any other page is clicked from the com site
		else
		{
			if ( ObjRightSideMenuTd )
			{
				ObjRightSideMenuTd.style.display	=	'';
				ObjContentTd.colSpan				=	'2';		
				ObjIframe.src						=	PageLink;
			}
			
		}	
		
	}		
}*/
// To Undo this change just replace the function name OpenComPagesInIframe
// to OpenPageInIframe in the <ComMenu></ComMenu> section of MXMenu.xml
/**************************************************************************
   Function to Hide the Right Menu when the Registration Pages Load
**************************************************************************/


/**************************************************************************
   Function to Highlight the Cells of the Menu which are selected
**************************************************************************/

function HightLight(ObjTd, HightLightflag )
{	
	if ( HightLightflag )
	{
		ObjTd.style.background =  "#1B7CCD"		
	}
	else
	{
		ObjTd.style.background =  "#ffad4c"
	}
}	

function HightLightCell(ObjLink, HightLightflag, TotalTdCount )
{
	// Set the Global Variable for the Total No of Td available in a Particular Menu Tag
	_TotalMenuTdCount	=	TotalTdCount;
	
	if ( HightLightflag )
	{
	
		var arrTds;
		if ( isUndefined(TotalTdCount)  ==  false )
		{
			arrTds	=	TotalTdCount.split("|");
			for (i=arrTds[0];i<=arrTds[1];i++)
			{
				MunuTdID	=	'MenuTd' + i;
				if ( document.getElementById(MunuTdID))
					document.getElementById(MunuTdID).style.background =  "#ffad4c"
			}

			if ( ObjLink )
			{
				ObjLink.style.background =  "#1B7CCD"				

				/*if ( document.getElementById(_SelectedMenuTdID) )
					document.getElementById(_SelectedMenuTdID).style.background =  "#1B7CCD";*/	

				if ( document.getElementById( GetSelectedMenuOptionValue() ) )
					document.getElementById( GetSelectedMenuOptionValue() ).style.background =  "#1B7CCD";					
							
			}
			
		}		
			
	}	
	else
	{

		// if ( _SelectedMenuTdID  !=  ObjLink.id )
		if ( _SelectedMenuTdID  !=  ObjLink.id  &&  GetSelectedMenuOptionValue() !=  ObjLink.id )
		{
			ObjLink.style.background =  "#ffad4c";
		}
		else
		{
			/*if ( document.getElementById(_SelectedMenuTdID) )
				document.getElementById(_SelectedMenuTdID).style.background =  "#1B7CCD";*/
				
			if ( document.getElementById( GetSelectedMenuOptionValue() ) )
				document.getElementById( GetSelectedMenuOptionValue() ).style.background =  "#1B7CCD";				
			
		}
		
	}
	
}

/**************************************************************************
   Function to Highlight the Cells of the Menu which are selected
**************************************************************************/

/**************************************************************************
   Function to Open the Link in a New Window
**************************************************************************/

function OpenPageInNewWindow( _Url )
{
	if ( _Url.length  >  0 )
	{
		window.open( _Url );
	}
}

/**************************************************************************
   Function to Open the Link in a New Window
**************************************************************************/

/**************************************************************************
   Function to Hide the Controls to make Space for Registration Pages
**************************************************************************/

function DebugOutput(msg)
{
	//alert(msg);
}

function OpenComPagesInIframe( PageLink, _SelectedMenuID )	
{	
	DebugOutput('inside OpenComPagesInIframe');
	_SelectedMenuTdID	=	_SelectedMenuID;	
	
	SetSelectedMenuOptionValue( _SelectedMenuTdID );
	
	if ( PageLink.length  >  0 )
	{
		var ObjIframe				=	document.getElementById("ifrContent");		
		var ObjLeftSideControlTd	=	document.getElementById("tdLeftSideControl");
		var ObjContentTd			=	document.getElementById("tdContent");
		
		// Added on 22-Aug-2006 to show a blank frame before loading the actual page in it
			ObjIframe.src			=	"about:blank";		
		// Added on 22-Aug-2006 to show a blank frame before loading the actual page in it
		
		// If the Page clicked is Registration from the com site
		if ( PageLink.indexOf("Registration.aspx")  ==  19 )		
		{		
			if ( ObjLeftSideControlTd )
			{

				// Deselect all the others
				HightLightCell(document.getElementById(_SelectedMenuID), true, _TotalMenuTdCount )				
				
				document.getElementById(_SelectedMenuID).style.background =  "#1B7CCD"
				
				ObjLeftSideControlTd.style.display	=	'none';
				ObjLeftSideControlTd.colSpan		=	'3';		
				ObjIframe.src						=	PageLink;
			}
		}
		// else if the Page clicked is Company Registration from the com site
		else if ( PageLink.indexOf("CompanyCustom.aspx")  ==   9 )
		{
			if ( ObjLeftSideControlTd )
			{

				// Deselect all the others
				HightLightCell(document.getElementById(_SelectedMenuID), true, _TotalMenuTdCount )							
			
				document.getElementById(_SelectedMenuID).style.background =  "#1B7CCD"
				
				ObjLeftSideControlTd.style.display	=	'none';
				ObjLeftSideControlTd.colSpan		=	'3';		
				ObjIframe.src						=	PageLink;
			}			
		}
		else if ( PageLink.indexOf("PriceWatch.aspx")  >=   0 )
		{
			DebugOutput('going to PriceWatch');
			if ( ObjLeftSideControlTd )
			{

				// Deselect all the others
				HightLightCell(document.getElementById(_SelectedMenuID), true, _TotalMenuTdCount )							
			
				document.getElementById(_SelectedMenuID).style.background =  "#1B7CCD"
				
				ObjLeftSideControlTd.style.display	=	'none';
				ObjLeftSideControlTd.colSpan		=	'3';	
			}			
			DebugOutput('PageLink: ' + PageLink);	
			ObjIframe.src						=	PageLink;

		}		
		// else if any other page is clicked from the com site
		else
		{
			if ( ObjLeftSideControlTd )
			{
			
				// Deselect all the others
				HightLightCell(document.getElementById(_SelectedMenuID), true, _TotalMenuTdCount )							
			
				document.getElementById(_SelectedMenuID).style.background =  "#1B7CCD"
				
				ObjLeftSideControlTd.style.display	=	'';
				ObjLeftSideControlTd.colSpan		=	'1'
				//ObjContentTd.colSpan				=	'2';		
				ObjIframe.src						=	PageLink;				

			}
			
		}	
		
	}		
}
// To Undo this change just replace the function name OpenComPagesInIframe
// to OpenPageInIframe in the <ComMenu></ComMenu> section of MXMenu.xml
/**************************************************************************
   Function to Hide the Controls to make Space for Registration Pages
**************************************************************************/

/**************************************************************************
   Function to Set and Get the Value of Hidden for Selected Menu Option
**************************************************************************/

function SetSelectedMenuOptionValue( _SelectedMenuValue )
{	
	if ( location.pathname.toUpperCase().indexOf('DEFAULT.ASPX') > 0  )
	{		
		document.getElementById("_ctl2_hidSelectedMenuOption").value	=	_SelectedMenuValue;	   //[Changed ctl2 to ctl1 bcz remove Ticker Annoucement MPOAVV From Default Page]
		//document.getElementById("_ctl1_hidSelectedMenuOption").value	=	_SelectedMenuValue;	
		
	}
	else if ( location.pathname.toUpperCase().indexOf('EXCHNET.ASPX') > 0  ) 	
	{
		document.getElementById("_ctl2_hidSelectedMenuOption").value	=	_SelectedMenuValue;	   //[Changed ctl2 to ctl1 bcz remove Ticker Annoucement MPOAVV From Exchnet Login Page]
		//document.getElementById("_ctl1_hidSelectedMenuOption").value	=	_SelectedMenuValue;
	}	
	else if ( location.pathname.toUpperCase().indexOf('HOME.ASPX') > 0  ) 	
	{
		document.getElementById("_ctl2_hidSelectedMenuOption").value	=	_SelectedMenuValue;	
	}	
	else if ( location.pathname.toUpperCase().indexOf('HOMEADMIN.ASPX') > 0  ) 	
	{
		document.getElementById("_ctl1_hidSelectedMenuOption").value	=	_SelectedMenuValue;	
	}	
	else
	{
		document.getElementById("_ctl2_hidSelectedMenuOption").value	=	_SelectedMenuValue;	   //[Changed ctl2 to ctl1 bcz remove Ticker Annoucement MPOAVV From Default Page]
		//document.getElementById("_ctl1_hidSelectedMenuOption").value	=	_SelectedMenuValue;	
	}	
	// document.getElementById("_ctl1_hidSelectedMenuOption").value	=	_SelectedMenuValue;	
	
}

function GetSelectedMenuOptionValue()
{	

	if ( location.pathname.toUpperCase().indexOf('DEFAULT.ASPX') > 0  )
	{
		// Uncommented the foll. statement and commented the second statement as 
		// the ticker is now shown on the default page and thus the menu becomes no. 2 control on the page.
		return document.getElementById("_ctl2_hidSelectedMenuOption").value;    //[Changed ctl2 to ctl1 bcz remove Ticker Annoucement MPOAVV From Default Page]
		// return document.getElementById("_ctl1_hidSelectedMenuOption").value;
	}
	else if ( location.pathname.toUpperCase().indexOf('EXCHNET.ASPX') > 0  ) 	  
	{
		//return document.getElementById("_ctl2_hidSelectedMenuOption").value;	  //[Changed ctl2 to ctl1 bcz remove Ticker Annoucement MPOAVV From Exchnet Login Page]
		return document.getElementById("_ctl1_hidSelectedMenuOption").value;
	}
	else if ( location.pathname.toUpperCase().indexOf('HOME.ASPX') > 0  ) 	
	{
		return document.getElementById("_ctl2_hidSelectedMenuOption").value; //If ticker is included use ctl2
	}
	else if ( location.pathname.toUpperCase().indexOf('HOMEADMIN.ASPX') > 0  ) 	
	{
		return document.getElementById("_ctl1_hidSelectedMenuOption").value;
	}	
	else
	{
		// Uncommented the foll. statement and commented the second statement as 
		// the ticker is now shown on the default page and thus the menu becomes no. 2 control on the page.
		return document.getElementById("_ctl2_hidSelectedMenuOption").value;   //[Changed ctl2 to ctl1 bcz remove Ticker Annoucement MPOAVV From Default Page]
		// return document.getElementById("_ctl1_hidSelectedMenuOption").value;
	}	
	// return document.getElementById("_ctl1_hidSelectedMenuOption").value;
	
}

function SetSelectedMenuOptionValueOnLoad( _ControlID )
{
	
	/*************************************************************************************
	  Loop to show the Home Link Option Selected when the page loads and deselect others
	*************************************************************************************/
		
		for (i=0;i<110;i++)
		{
			// Get the Menu Option
			_MenuOption		=	"MenuTd" + i;
			_ObjMenuOption	=	parent.document.getElementById(_MenuOption)
			
			// If the Menu Option Exists
			if ( _ObjMenuOption )
			{
				// If the Home Menu Option is available then
				if ( _ObjMenuOption.innerText  ==  "Home" )
				{
					// Show the Home Link as Selected
					_ObjMenuOption.style.background =  "#1B7CCD";
					// Set the Value of Hidden Field to the Value of Selected Menu Option					
					// parent.document.getElementById("_ctl1_hidSelectedMenuOption").value  =  _MenuOption;
					parent.document.getElementById( _ControlID ).value  =  _MenuOption;
					
				}
				else
				{
					// Else even if the Home Menu Option is not available then
					// DeSelect the Previous Selected Link when this page Loads
					if ( _ObjMenuOption.style.background =  "#1B7CCD" )
					{
						_ObjMenuOption.style.background =  "#ffad4c"
					}
					
				}
				
			}
			
		}
		// End of the For Loop
		
	/*************************************************************************************
	  Loop to show the Home Link Option Selected when the page loads and deselect others
	*************************************************************************************/	


}

/**************************************************************************
   Function to Set and Get the Value of Hidden for Selected Menu Option
**************************************************************************/