function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function setWSAction(tagRef)
{
	document.cookie = "wsaction=" + tagRef + "; expires=Wed, 31 Dec 2025 00:00:00 UTC" + "; path=/" + "; domain=morningstar.com"
}

function setAdClick (tagRef)
{
	if (tagRef == "click")
	{
		document.getElementById("adcontain1").style.overflow = "visible";
		if (l_usertype == "S") {
			if (!is_ie)	document.getElementById("ad1sm").style.overflow = "visible";
			document.getElementById("adcontain2").style.zIndex = "2";			
		}
		else
			document.getElementById("adcontain2").style.zIndex = "3";
	}
	else if (tagRef == "noclick")
	{
		document.getElementById("adcontain1").style.overflow = "hidden"	;	
		document.getElementById("adcontain2").style.zIndex = "1";
		if (l_usertype == "S" && !is_ie) 
			document.getElementById("ad1sm").style.overflow = "hidden";		
	}
}

function log(tagRef)
{	
	var gifName;
	
	if(tagRef.name == "menu1")
	{
		setIfrWidth(585);
		gifName = "menu1";
		MM_showHideLayers('menu0','','show','menu2','','hide','menu3','','hide');
		
	}
	else if (tagRef.name == "menu4")
	{
		setIfrWidth(585);
		gifName = "menu2";
		MM_showHideLayers('menu0','','hide','menu2','','show','menu3','','hide')
	}
	else
	{
		setIfrWidth(585);
		gifName = "menu3";
		MM_showHideLayers('menu0','','hide','menu2','','hide','menu3','','show')
	}
	  
  setWSAction (tagRef.name);
  setAdClick("noclick");    
}

function logHide(tagRef)
{	
	var gifName;
	
	setIfrWidth(728);
	
	if(tagRef.name == "menu1")
	{
		gifName = "menu1";
		MM_showHideLayers('menu0','','hide','menu2','','hide','menu3','','hide');
	}
	else if (tagRef.name == "menu4")
	{
		gifName = "menu2";
		MM_showHideLayers('menu0','','hide','menu2','','hide','menu3','','hide')
	}
	else
	{
		gifName = "menu3";
		MM_showHideLayers('menu0','','hide','menu2','','hide','menu3','','hide')
	}
  	
  setWSAction("hide");
  setAdClick("click");   
}

function getIndexGraph(index) {

	var indexImg = document.getElementById("indexGraph");
	
  	indexImg.src = "/prodPages/include/index_" + index + ".png"
}

function setIfrWidth(ifrwidth) 
{ 
	// Set Big Banner SINGLEBIG's width , original Size 728 , reduce size  585
	if (document.getElementById('ifrBigB'))
		document.getElementById('ifrBigB').width=ifrwidth +" px";
}

function srchTerm(sSearchType)
{
	if (sSearchType == "search")
	{
		document.searchForm.SrchTerm.value = document.searchForm.sSrchTerm.value;
  		document.searchForm.action = "http://search.morningstar.com/MstarSrch/MstarSrch2.aspx";
  		document.searchForm.submit();
	}
	else
	{
		if (document.quoteForm.sSrchTerm.value == "")
		{
			document.quoteForm.action = "http://quote.morningstar.com/TickerNotFound.html";			
			document.quoteForm.submit();
		}
		else
		{
			document.quoteForm.action = "http://quote.morningstar.com/switch.html?ticker=" + document.quoteForm.sSrchTerm.value;
			document.quoteForm.submit();
		}
	}
}

function ClearSearchBox(sSearchType)
{
	if (sSearchType == "quote")
	{
		var text = document.quoteForm.sSrchTerm.value;
		if (text == "Enter ticker")
			document.quoteForm.sSrchTerm.value = "";
	}
	else
	{
		var text = document.searchForm.sSrchTerm.value;
		if (text == "Enter topic")
			document.searchForm.sSrchTerm.value = "";
	}
}

function readWSCookie(cookieName)
{
	var name = cookieName + "=";
	var arrCookies = document.cookie.split(';');
	for (var i = 0; i < arrCookies.length; i++)
	{
		var c = arrCookies[i];
		while (c.charAt(0) == ' ')
			c = c.substring(1, c.length);
		if (c.indexOf(name) == 0)
			return c.substring(name.length, c.length);
	}
	return null;
}

function footeropenwin(windowName, width, height)
{
	newWindow = window.open(windowName, 'newWindow', 'toolbar=no,location=no,menubar=no,width='+width+',height='+height+',scrollbars=yes,resizable=no');
}

function openPlayerSelection(windowURL)
{  
	playerSelectWin = window.open(windowURL, 'playerSelectWin', 'toolbar=no,titlebar=no,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=1,width=312,height=480,top=20,left=10');
}

function openEmailwin(windowName)
{
	if (browser_type == "Microsoft Internet Explorer")
	{
		newWindow = window.open(windowName, 'myWindow', 'toolbar=no,location=no,menubar=no,width=312,height=320,scrollbars=no,resizable=no');
	}
	else
	{
		newWindow = window.open(windowName, 'myWindow', 'toolbar=no,location=no,menubar=no,width=312,height=355,scrollbars=no,resizable=no');
	}
}
