
AdjustPosition();
changeView(options);

// need to adjust these objects'absolute position
// make them relative to the graph
function AdjustPosition()
{
	var strId = "tp,scale,scale1,Layer1,tim,indicator1,indicator2,indicator3,indicator4,ddate,tip,DateLeft,DateRight,ZoomRect,lleft,rright";
	var strDx = "-276,-9,-166,224,157,-176,-176,-176,-176,-176,-176,0,0,0,0,0";
	var strDy = "-16,-32,-31,-27,-34,252,352,452,550,199,40,36,36,36,184,184";           
	var g = findObj("tdgraph"); // graph's container
	var gx = getX(g);
	var gy = getY(g);
	_gx = gx;	
	_gy = gy;
	gLeft = gx + 1; 
	
	var arrId = strId.split(",");
	var arrDx = strDx.split(",");
	var arrDy = strDy.split(",");
	var id, obj, dx, dy;
	for(var i = 0; i < arrId.length; i++)
	{
		id  = arrId[i];
		obj = findObj(id);
		dx  = parseInt(arrDx[i]);
		dy  = parseInt(arrDy[i]);
		if(obj.id == "indicator1")
			_yIndicator1 = gy + dy; // fundamental is not the same
		if(obj.id == "tip")
			_yTip = gy + dy;		// fair value is not the same
		obj.style.left = (gx + dx) + "px";
		obj.style.top  = (gy + dy) + "px";
	}
	
	// for displaying dots and zoom
	graphTop = gy + 22;		
				
	priceYBottom = graphTop + 195;							
	BaseYPos = new Array(307, 407, 507, 607);
	for(var i = 0; i < BaseYPos.length; i++)
	{
		BaseYPos[i] = BaseYPos[i] + graphTop;
	}
	
	_priceBottom = priceYBottom;
	_baseYPos0   = BaseYPos[0];
	_baseYPos1	 = BaseYPos[1];
	
	AdjustFundamentalPosition();	// fundamental is not the same
}

// fundamental is not the same as other tabs.
function AdjustFundamentalPosition()
{
	if( options == "F")
	{
		priceYBottom = _priceBottom - 20;
		BaseYPos[0] = _baseYPos0 - 20;
		BaseYPos[1] = _baseYPos1 - 20;
		findObj("indicator1").style.top = ( _yIndicator1 - 20 ) + "px";
	}
	else
	{
		priceYBottom = _priceBottom;
		BaseYPos[0]  = _baseYPos0;
		BaseYPos[1]  = _baseYPos1;
		findObj("indicator1").style.top =  _yIndicator1 + "px";
	}
}

// get position of an object on the page
function getX(obj)
{
	var x = 0;
	var o = obj;
	while (o.offsetParent)
	{
		x += o.offsetLeft;
		o = o.offsetParent;
	}
		return x;
}
function getY(obj)
{
		var y = 0;
		var o = obj;
		while (o.offsetParent)
		{
			y += o.offsetTop;
			o = o.offsetParent;
		}
		if(type == "SAF")
			y -= 145;    // !!!NOTE: this is temporary solution, only suitable for this project !!!
		return y;
}	
	
// refresh
function Refresh()
{
	InitPrimes();
	ClearIndicators();
	SetGraphWidth();
	SetHelpWidth();
	SetHorizontalLineWidth();
	SetMainTableWidth();
    SetMailLink();
	
	BuildTimeFrame();
	BuildCompareTicker();
	BuildEvent();
	BuildCloseIcons();
	BuildQuotes();
	UpdateData();
}

// initiate primes
function InitPrimes()
{
	if( options == "H" && hPrime == "" )
		hPrime = security.toUpperCase();
	else if( options == "V" && vPrime == "" )
		vPrime = security.toUpperCase();
	else if( options == "F" && fPrime == "" )
		fPrime = security.toUpperCase();
}

// set graph's width
function SetGraphWidth()
{
	// graph size
	if(size == null || size == "undefined")
		size = "460";
	var g = findObj("tdgraph");
	g.style.width = parseInt( size );
}

// set help row width
function SetHelpWidth()
{
	// help width	
	var tbHelp = findObj("tableHelp");
	if( tbHelp == null || tbHelp == undefined)
		return;
	var w = 0;
	if(size == "460")
	{
		if(options == "F")
			w = 566;
		else
			w = 565;
	}
	else if(options == "F")
		w = 868;
	else
		w = 864;
	tbHelp.style.width = w + "px";
}

// set main table width
function SetMainTableWidth()
{
	var mainTable = findObj("bMain");
	if ( parseInt(size) > 700 )
			mainTable.style.width = 820 + "px"; 
	else  if ( size.indexOf("524")>=0 )
			mainTable.style.width = 640 + "px"; 
	else 
			mainTable.style.width = 203 + "px";
}

// set tab image
function SetTabImage( )
{
	// tab image src
	var tabImg = findObj("tab");
	var arr = new Array(4);
	
	// for Mcharts.aspx
	arr[0] = new Array( "QTs_stockchart_price.gif", "QTs_stockchart_technical.gif",
				 "QTs_stockchart_fundamental.gif", "QTs_stockchart_fairvalue.gif");
				 
	// for MLEcharts.aspx
	arr[1] =  new Array( "QTs_stockchart_price_MLE.gif", "QTs_stockchart_technical_MLE.gif",
				 "QTs_stockchart_fundamental_MLE.gif", "QTs_stockchart_fairvalue_MLE.gif");
	
	// for Mcharts.aspx
	arr[2] = new Array( "MS_StockCharts_PriceTab.gif", "MS_StockCharts_TechnicalTab.gif",
				 "MS_StockCharts_FundamentalTab.gif", "MS_StockCharts_FairValueTab.gif");
		
	
	var i = 0, j=0;
	
	var currentPath = window.location.pathname.toUpperCase();
	switch( currentPath )
	{
		case "/CHARTS/MCHARTS.ASPX":
			i = 0;
			break;
		case "/CHARTS/MLECHARTS.ASPX":
			i = 1;
			break;
		case "/CHARTS/STOCK_CHARTS.ASPX":
			i = 2;
			break;
		default:
			i = 0;
			break;
	}			
	
	switch( options )
	{
		case "P":
			j = 0;
			break;
		case "H":
			j = 1;
			break;
		case "F":
			j = 2;
			break;
		case "V":
			j = 3;
			break;
		default:
			j = 0;
			break;
	}
	
	tabImg.src = "images/" + arr[i][j];
}

// set mail link
function SetMailLink()
{
	// mail link
	var link = findObj("mailLink");
	var url = geturl(5);
	url = "http://" + window.location.hostname + window.location.pathname + "?" + url;	
	url = EncodeUrl(url);
	var href = "mailto:?Subject=Morningstar Charts for " + security;
	href 	+= "&body=You've been sent a link to a Morningstar stock chart. Click on the link below to view it:%0A%0A";
	href 	+= url + " %0A%0AAlso, visit http://www.morningstar.com for all your investment-tracking needs. %0A%0ASincerely,%0A%0AMorningstar, Inc. ";
	link.href = href;
}

function EncodeUrl(str)
{
	var r = /%/g;
	str = str.replace(r,"%25" );
	r = /&/g;
	str = str.replace(r,"%26" );
	r = /\+/g;
	str = str.replace(r,"%2B" );
	r = /\//g;
	str = str.replace(r,"%2F" );
	r = /#/g;
	str = str.replace(r,"%23" );
	r = /\?/g;
	str = str.replace(r,"%3F" );
	return str;
}

// set horizontal line's width
function SetHorizontalLineWidth()
{
	var w = 420;
	if ( size.indexOf("761") >= 0 )
		w= 720;
	var obj = findObj( "scale1" );
	for(var i=0; i<obj.childNodes.length; i++)
	{
		var c = obj.childNodes[i];
		if(c.tagName == "DIV" || c.tagName == "div")
		{
			c.style.width = w + "px";
			break;
		}
	}
}

// set vertical line's height
function SetVerticalLineHeight( h )
{
	var obj = findObj( "scale" );
	for(var i=0; i<obj.childNodes.length; i++)
	{
		var c = obj.childNodes[i];
		if(c.tagName == "DIV" || c.tagName == "div")
		{
			c.style.height = h + "px";
			break;
		}
	}
}

// build menu html
function BuildMenu()
{
	var menu = findObj("Menu1_MenuContainer");
	var xmlhttp = getXMLHTTP();
	var url = "AJAX.aspx";		
	xmlhttp.open("POST", url, true);
	xmlhttp.onreadystatechange=function() 
	{
		if (xmlhttp.readyState==4)
		{
			if(xmlhttp.responseText == "")
				return;
			menu.innerHTML = xmlhttp.responseText;
		}
	}
	xmlhttp.send("<root code='menu' arg='" + options + "'/>");
}

// build time frame html
function BuildTimeFrame()
{	
	// can not set tr's innerHTML!!! so add one cell and add one cell...
	var row = findObj( "trTimeFrame" );
	while( row.hasChildNodes() )
	{
		row.removeChild( row.firstChild );
	}
	
	if (options == "F")
		row.style.backgroundColor = "#f3f3f3";
	else
		row.style.backgroundColor = "#e7e7e7";
	
	var html = "<img width='1' src='http://im.morningstar.com/im/dot_clear.gif'>";
	
	var cell = row.insertCell(0);
	cell.style.backgroundColor = "#cccccc";	
	cell.innerHTML = html;		
						
	var html = "";
	if (options == "V")
	{	
		if (timeFrame == "Y10")
			timeFrame = "Y10";			      
		html = getYearlyTimeframe(timeFrame, types, "LINEAR", size);
	}
	else if (options == "F")
	{
		if (eval(size) > 500)
			html = "<img height='1' width= 865 src='http://im.morningstar.com/im/dot_clear.gif'>";
		else
			html = "<img height='1' width= 563 src='http://im.morningstar.com/im/dot_clear.gif'>";
	}
	else if (options == "P")
	{
		html = getPTimeframe(timeFrame, types, chartScale, size);								
	}
	else
	{
		html = getPTimeframe(timeFrame, types, chartScale, size);					
	}			
	
	cell = row.insertCell(1);
	cell.className = "msSmall";
	cell.align = "left";
	cell.colSpan = 3;
	cell.vAlign = "middle";
	cell.innerHTML = html;	
					
	cell = row.insertCell(2);	
	if (options != "F" )
	{
		cell.vAlign = "middle";
		cell.backgroundColor = "#e7e7e7";
		if ( eval(size) > 500)
		{
			html = "<img border='0' height='24' width= 324 src='/charts/images/MSC_GapFill1.gif'>";
		}
		else
		{
			html = "<img border='0' height='24' width= 25 src='/charts/images/MSC_GapFill1.gif'>";
		}
		cell.innerHTML = html;
	}
	else
	{
		cell.backgroundColor = "#f3f3f3";
	}	
}

// build compare ticker html
function BuildCompareTicker()
{
	var cell = findObj("tdCompareTicker");
	var html = "";
	if (options == "P" || options == "F" )
		html = "Compare to a Ticker";
	else
		html = "Enter Ticker";
												
	cell.innerHTML =  html;
}


// build event html
function BuildEvent()
{
	var cell = findObj("tdEvent");
	if (options != "P")
	{
		cell.innerHTML = "";
		return;
	}									
	var html = "<TABLE BORDER='0' CELLSPACING='0' CELLPADDING='0' >";
	html += "<TR>"
	if (events.indexOf("S") >=0 )    
		html += "<TD class='msSmall'><INPUT id ='s' checked onclick=AddEvents('S') type=checkbox>Splits</td>";
	else
		html += "<TD class='msSmall'><INPUT id ='s' onclick=AddEvents('S') type=checkbox>Splits</td>";
	if (totals != "" )
		html += "<TD class='msSmall'><INPUT id = 'd' checked onclick=changeTotalReturn('T')  type=checkbox>Total Return</td>";
	else
		html += "<TD class='msSmall'><INPUT id = 'd' onclick=changeTotalReturn('T')  type=checkbox>Total Return</td>";
	html += "</TR>";
	html += "</TABLE>";
													
	cell.innerHTML = html;
}

// build close icons html
function BuildCloseIcons()
{
	var table = findObj("tableCloseIcons");
											
	var html = "<TR valign='top'><TD height=218></TD></TR>";
	if (options == "H" && lowindicators != "Volume|")
	{
		var INDICATORS = lowindicators.split('|'); 			
		var n=0;
		for (i=0; i< INDICATORS.length ; i++)
		{
			if ( INDICATORS[i] != "" )
				n++;
		}
		for (var i=0; i<n; i++)
		{
			html += "<TR valign=top><TD height=98 class=sSmall><a href=javascript:checkOut('"+ i +"')><img id=menu  src='images/MS_StockCharts_close_icon.gif' border=0></a></TD></TR>";
		}
	}
	if( type != "IE" )
		table.innerHTML = html;
	else
		table.outerHTML = "<TABLE id='tableCloseIcons' WIDTH='10' BORDER='0' CELLSPACING='0' CELLPADDING='0'>" + html + "</TABLE>";
}

// build quotes html
function BuildQuotes()
{
	var table = findObj("tableQuotes");
														
	var html =	"<TR>";
	html +=			"<TD colspan='4'><img height='1' src='http://im.morningstar.com/im/dot_clear.gif'></TD>";
	html +=		"</TR>"  
														
	initImages();
														
	if (options == "H")
	{
		if (movingAvg != "")
		{
			//alert("all ma:  " +movingAvg)
			allMA = movingAvg.split('|');				  
			var  temp;			
			for (i=0; i< allMA.length; i++)
			{
				var ss = allMA[i].split("^");							
				n = eval(ss[0]);
				//alert("ss[0]:  " + ss[0])
				if (ss[2].indexOf("SMA") >=0 || ss[2].indexOf("MMA") >=0  || ss[2].indexOf("EMA") >=0 || ss[2].indexOf("WMA") >=0 )	
				{			
					if (ss[1].indexOf("1") >= 0)	
						html += "<TR><TD></TD><TD><INPUT id = m" + i + " onclick='onClickMA()' checked type=checkbox></TD><TD><img id=menu  src='" + imagesMA[n] +"' border=0></TD><TD align=right > <font class='msSmall'>&nbsp;" + ss[2]  +"</font></TD><TD></TD></TR>";
					else if (ss[1].indexOf("0") >= 0)
						html += "<TR><TD></TD><TD><INPUT id = m" + i + "  onclick='onClickMA()' type=checkbox></TD><TD><img id=menu  src='" + imagesMA[n] + "' border=0></TD><TD align=right > <font class='msSmall'>&nbsp;" + ss[2]  + "</font></TD><TD></TD></TR>";
				}
				else
				{	
					if (ss[2] == "MAE")
						n= 0;
					else if (ss[2] == "BB")
						n = 1;
					else
						n = 2;								
					if (ss[1].indexOf("1") >= 0)
						html += "<TR><TD></TD><TD><INPUT id = m" + i + " onclick='onClickMA()' checked type=checkbox></TD><TD><img id=menu  src='" + imagesOP[n] +"' border=0></TD><TD align=right > <font class='msSmall'>&nbsp;" + ss[2]  +"</font></TD><TD></TD></TR>";
					else if (ss[1].indexOf("0") >= 0)	
						html += "<TR><TD></TD><TD><INPUT id = m" + i + "  onclick='onClickMA()' type=checkbox></TD><TD><img id=menu  src='" + imagesOP[n] + "' border=0></TD><TD align=right > <font class='msSmall'>&nbsp;" + ss[2]  + "</font></TD><TD></TD></TR>";
				}
			}
		}	
	}	
														
	if (options == "H" || options == "V" || (options == "F" && fundamental == "TOTR"))
	{
		if ( (hPrime == security  && options == "H") || ( vPrime == security && options == "V" ) ||
			(fPrime == security && options == "F" && fundamental == "TOTR") )
			html += "<TR><TD></TD><TD><INPUT id = "+ security + " checked  onclick='onRClick(this.id)' type=radio name = r></TD><TD><img id=menu  src='" + images[0] +"' border=0></TD><TD align=right> <font class='msSmall'>&nbsp;<a HREF=javascript:OpenHelpWindow1('" + gQuoteServer + "?ticker="+security.toUpperCase() +"')>"+security.toUpperCase()+"</a></font></TD><TD></TD></TR>";
		else 
			html += "<TR><TD></TD><TD><INPUT id = "+ security + "  onclick='onRClick(this.id)' type=radio name = r></TD><TD><img id=menu  src='" + images[0] +"' border=0></TD><TD align=right> <font class='msSmall'>&nbsp;<a HREF=OpenHelpWindow1('" + gQuoteServer + "?ticker="+security.toUpperCase() +"')>"+security.toUpperCase()+"</a></font></TD><TD></TD></TR>";
	}
	else
		html += "<TR ><TD></TD><TD  width=20>&nbsp;&nbsp;&nbsp;</TD><TD ><img id=menu  src='" + images[0] +"' border=0></TD><TD align=right> <font align=right class='msSmall'>&nbsp;<a HREF=javascript:OpenHelpWindow1('" + gQuoteServer + "?ticker="  + security.toUpperCase() +"')>"+security.toUpperCase()+"</a></font></TD><TD ></TD><TD></TD><TD></TD></TR>";
															
	var n = 1;			
	if (indexes != "" && options == "P" )
	{
		//alert("all:  " +indexes)
		allI = indexes.split("|");						
		var  temp;		
		for (i=0; i< allI.length; i++)
		{
			var ss = allI[i].split("^");							
			n = eval(ss[0]);
			//alert(allI[i] + " num: " + n)
			if (ss[1].indexOf("1") >= 0)
				html += "<TR><TD></TD><TD><INPUT id = i" + i + " onclick='onClick()' checked type=checkbox></TD><TD><img id=menu  src='" + imagesMA[n] +"' border=0></TD><TD align=right> <font class='msSmall'>&nbsp;<a HREF=javascript:OpenHelpWindow1('" + gQuoteServer + "?ticker=" + ss[2] +"')>"+ss[2]+"</a></font></TD><TD></TD></TR>";
			else if (ss[1].indexOf("0") >= 0)
				html += "<TR><TD></TD><TD><INPUT id = i" + i + "  onclick='onClick()' type=checkbox></TD><TD><img id=menu  src='" + imagesMA[n] +"' border=0></TD><TD align=right> <font class='msSmall'>&nbsp;<a HREF=javascript:OpenHelpWindow1('" + gQuoteServer + "?ticker="+ss[2] +"')>"+ss[2]+"</a></font></TD><TD></TD></TR>";
		}
	}

	//alert(stockes)
	if (stockes != "")
	{
		allT = stockes.split("|");	
		var  temp;			
		for (i=0; i< allT.length; i++)
		{
			var ss = allT[i].split("^");							
			n = eval(ss[0]);
			if (options == "H" || options == "V" || (options == "F" && fundamental == "TOTR"))
			{
				//if (ss[1].indexOf("1") >= 0)
				if ( (options == "H" && hPrime == ss[2]) || (options == "V" && vPrime == ss[2]) ||
					(fundamental == "TOTR" && fPrime == ss[2]) )
					html += "<TR><TD></TD><TD><INPUT id = " + ss[2] +" checked onclick='onRClick(this.id)'  type=radio name = r></TD><TD><img id=menu  src='" + images[n] +"' border=0></TD><TD align=right> <font class='msSmall'>&nbsp;<a HREF=javascript:OpenHelpWindow1('" + gQuoteServer + "?ticker=" + ss[2] +"')>"+ss[2]+"</a></font></TD><TD></TD></TR>";
				else 
					html += "<TR><TD></TD><TD><INPUT id = " + ss[2] +" onclick='onRClick(this.id)' type=radio name = r></TD><TD><img id=menu  src='" + images[n] +"' border=0></TD><TD align=right> <font class='msSmall'>&nbsp;<a HREF=javascript:OpenHelpWindow1('" + gQuoteServer + "?ticker=" + ss[2] +"')>"+ss[2]+"</a></font></TD><TD></TD></TR>";
																
			}
			else
			{
				if (ss[1].indexOf("1") >= 0)
					html += "<TR><TD></TD><TD><INPUT id = a" + i + " onclick='onClick()' checked type=checkbox></TD><TD><img id=menu  src='" + images[n] +"' border=0></TD><TD align=right> <font class='msSmall'>&nbsp;<a HREF=javascript:OpenHelpWindow1('" + gQuoteServer + "?ticker=" + ss[2] +"')>"+ss[2]+"</a></font></TD><TD></TD></TR>";
				else if (ss[1].indexOf("0") >= 0)
					html += "<TR><TD></TD><TD><INPUT id = a" + i + "  onclick='onClick()' type=checkbox></TD><TD><img id=menu  src='" + images[n] +"' border=0></TD><TD align=right> <font class='msSmall'>&nbsp;<a HREF=javascript:OpenHelpWindow1('" + gQuoteServer + "?ticker="+ss[2] +"')>"+ss[2]+"</a></font></TD><TD></TD></TR>";
														
			}
		}
	}
														
	//events				
	if (events != "" && options == "F")
	{
		allE = events.split("|");
		for (i=0; i< allE.length; i++)
		{
			var ss= allE[i];
			if (ss == "")
				continue;
			var sT = "Split";
			if (ss.indexOf("D") >=0)
				sT = "Dividend";
			if (ss.indexOf("1") == 0)
				html += "<TR><TD></TD><TD><INPUT id = e" + i + " onclick='onEVClick()' checked type=checkbox></TD><TD></TD><TD align=right><font class='msSmall'>"+sT +"</font></TD><TD></TD></TR>";
			else if (ss.indexOf("^0") == 0)
				html += "<TR><TD></TD><TD><INPUT id = e" + i + " onclick='onEVClick()' type=checkbox></TD><TD></TD><TD align=right><font class='msSmall'>"+sT +"</font></TD><TD></TD></TR>";
		}
	}
	if( type != "IE" )
		table.innerHTML = html;
	else
		table.outerHTML = "<TABLE id='tableQuotes' cellSpacing='0' cellPadding='0' border='0'>" + html + "</TABLE>";
}	

// process info
function UpdateData()
{	
	var g = findObj("graph");
	g.src = "/charts/images/LoadingScreenAnimation.gif";
	doItAll();
	bTips = true;
	sCompLabel  = getDisLabels();      	
	g.src = geturl(1);
	
	AdjustHeight();
}

// indication may affect the graph's height 
function AdjustHeight()
{
	var h = 0, toTop = 216, dy = 100;
	var arr = lowindicators.split('|'); 
	var len = arr.length-1;
	if (options == "H")
		h = toTop + dy * len;
	else
		h = toTop + dy;
	if (options == "V")
		h = toTop + dy * 2;
	if (timeFrame == "D1" || timeFrame == "D5")
		h = toTop + dy;
	h += 7;
	if(type == "IE") // why ???
		h += 3;
	// adujust zoom height
	var ids = new Array("ZoomRect", "lleft", "rright" );
	for(var i=0; i<ids.length; i++)
	{
     	findObj( ids[i] ).style.height = h + "px";
	}
	
	_gw = parseInt(size);
	_gh = h;
	// adjust vertical line
	SetVerticalLineHeight( h );
}

// check ticker entering
function CheckEnterTicker(e)
{
	if(e.keyCode == 13)
	{
		CheckTicker();
		if(type == "IE")
			e.returnValue = false;		// cancel event for IE
		else	
			e.preventDefault();			// cancel event for Firefox and others
	}
}

// check the ticker
function CheckTicker()
{ 
	var newTicker = findObj("CompTicker").value;
	newTicker = newTicker.replace(/^\s*|\s*$/g , "");	//trim
	if(newTicker == "")
	{
		alert("please input a ticker.");
		return;
	}
	var temp = ""
	if( stockes != "" && stockes.charAt( stockes.length - 1 ) == '|' )
		temp = "^"+ newTicker.toUpperCase() +"|";
	else
		temp = "^"+ newTicker.toUpperCase();
	if (newTicker == security 
		|| ( stockes != "" && stockes.indexOf(temp) >= 0 ) )
	{
		alert(newTicker + " is already in ticker list.")
		return;
	} 
		
	var xmlhttp = getXMLHTTP();
	var url = "AJAX.aspx";
			
	xmlhttp.open("POST", url, true);
	xmlhttp.onreadystatechange=function() 
	{
		if (xmlhttp.readyState==4)
		{
			var str = xmlhttp.responseText;
			if(str == "")
				return;
			var arr = str.split( ":" );
			var result = arr[0];
			if( result == "yes" )
			{
				stockes = arr[1];
				show(1);
			}
			else
				alert( newTicker +"  is not a valid stock ticker.");
		}
	}
	var arg = stockes + ":" + newTicker;
	xmlhttp.send("<root code='checkticker' arg='" + arg + "'/>");  
}

function changeView(o)
{ 
	if (IsVisible("tim"))
		return;
	priceYBottom = graphTop + PriceHeigth + graphYStart;
	var currentPath = window.location.pathname.toUpperCase();	
	if (o == "V" && userType != "P" && (currentPath == "/CHARTS/MCHARTS.ASPX" || currentPath == "/CHARTS/STOCK_CHARTS.ASPX") )
	{
		var url = geturl(5);
		url = "http://" + window.location.hostname + window.location.pathname + "?" + url;	
		url = EncodeUrl(url);
		if (userType != null && userType != "")
			document.location.href = "http://members.morningstar.com/memberstpages/pm_stocks.html?referid=A2723";
		else
			document.location.href = "http://members.morningstar.com/forbidden/loginrawP.html?vurl=" + url + "&referid=A2723";
		
		return;
	}
	else
	{
		hideAllZoomInImages();  /// hide all images for zoom in
		options = o;
		if (o == "F")
		{
			priceYBottom = graphTopF + PriceHeigth + graphYStart;

			if (fundamental == "")
				fundamental = "EPS"; 
		}
		if (o == "V")
		{
			if (timeFrame == "D1" || timeFrame == "D5" || timeFrame == "AL")
				timeFrame = "Y1";
		}
		var obj = findObj("tip");
		if(o == "V")
			obj.style.top = _yTip + 30;
		else
			obj.style.top = _yTip;
		SetTabImage();
		BuildMenu();
		AdjustFundamentalPosition();
		Refresh();
	}
}
