//global variable
var	gHMgraph;
var gTimespan;
// this function gets the cookie, if it exists
function Get_Cookie( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) &&
	( name != document.cookie.substring( 0, name.length ) ) )
	{
	return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

function ClearTicker()
{
	document.getElementById("fundchartTicker").value = "";
}

function keyPressed(e){
    var keyID = (window.event) ? e.keyCode : e.which ? e.which : e.charCode;

    if (keyID==13){
        GoSearch();
    }
    return false;
}

function GetXmlHttpObject(){
  var xmlHttp=null;
  try{
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
  }catch (e){    
    // Internet Explorer
    try{
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }catch (e){
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
  return xmlHttp;
}

var ticker;
var pageNo = 0;
var cutoff = "";
var cutoffArray = new Array();
cutoffArray[0] = "";
var oTickerListOL;
var agt=navigator.userAgent.toLowerCase(); 
var is_ie = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var vOffset;
if (is_ie) vOffset = 50;
else vOffset = 100;

GoSearch = function()
{   cutoffArray = new Array();
    cutoffArray[0] = "";
    ticker = document.getElementById("fundchartTicker").value;
    if (ticker == "" || ticker == "Ticker Lookup") {
	    alert("Please Enter a Ticker.");
        return;
	}	
	
	oTickerListOL = document.getElementById("TickerListOL");	
	var temp = getPosition(document.getElementById("Layer1"));
	oTickerListOL.style.left = temp["left"] - 210;
	oTickerListOL.style.top = temp["top"] + vOffset;	
	
	pageNo = 0;		
	getList();
	oTickerListOL.style.display = "block"; 
}
	
function getList(){	
				
    var oRequest=GetXmlHttpObject();  
    if (oRequest==null){
        alert ("Your browser does not support AJAX!");
        return;
    } 
    
    var url = "/cover/TickerListOL.aspx";
    url = url + "?pattern=" + ticker;       
    url = url + "&cutoff=" + cutoffArray[pageNo];    
    url = url + "&pageNo=" + pageNo;               
    //alert(url);
    oRequest.open("GET",url,true);      
    oRequest.onreadystatechange = function(){    
      if (oRequest.readyState == 4){                      
        var txt = oRequest.responseText;                      
        oTickerListOL.innerHTML = txt;    
        //alert(txt);               
                
        if (cutoffArray.length-1<=pageNo){
          var start = txt.lastIndexOf("<a id=")+1;
          var name = txt.substr(start);
          //alert(name);
          start = name.indexOf(">")+1;
          var end = name.indexOf("</a>");
          name = name.substr(start, end-start);
          //alert(name);
          cutoffArray.push(name);         
        }                 
      }  
    }  
    oRequest.send(null);  	        
        
};

GoPrevious = function()
{   
    if (pageNo > 0)
        pageNo = pageNo - 1;           
	getList();
};

GoNext = function()
{   
	pageNo = pageNo + 1;	
	getList();
};

function FeedBackSymbol(ticker)
{
	window.opener.SetSymbol(ticker);
}

function chgFavFundsLayer(layerNum) {
	if (!document.getElementById) return false;
		
	for (var i = 1; i <= 3; i ++)
	{
		document.getElementById("TabFavFunds"+i).className = "nav1";	
		document.getElementById("sectorGraph"+i).style.display = "none";						
	}
	
	document.getElementById("TabFavFunds"+layerNum).className = "nav1on";		
	document.getElementById("sectorGraph"+layerNum).style.display = "block";
	
}

function collapseNav(leftId) 
{

	 if (!document.getElementById) return false;	
	 if (!document.getElementById(leftId + "Title")) return false;	  
	 if (!document.getElementById(leftId)) return false;
	 
	 //this part changes the navarrow when collapse left nav
	 var node;
	 var classN;
	 var idx;
	 node = document.getElementById(leftId + "Title");
	 classN = node.className;
	 idx= classN.indexOf("off");
	 if (idx >=0)
	 	classN = classN.substring(0,idx);
	 else
	 	classN = classN + "off";
	 node.className = classN;

	//this part collapses left nav
	 node = document.getElementById(leftId);	 
	 if (node.childNodes.length > 0) {
	  for (var i=0; i<node.childNodes.length; i++) {
	   var child = node.childNodes[i];
	   if (child.nodeName == "a" || child.nodeName == "A") {
		 if (child.style.display == "") {
		  child.style.display = "none";
		 } else {
		  child.style.display = "";
		 }
	   }
	  }
	 }
}

function hideLeftNav()
{
	collapseNav("LeftNews");
	collapseNav('LeftLearn');
	collapseNav('LeftDiscuss');
	collapseNav('LeftNewsLetter');
	collapseNav('LeftBooks');			
}

function FFQTRedirect() {
    var url = document.ffqtList.ffqtselect.options[document.ffqtList.ffqtselect.selectedIndex].value;
	if ((url != "^") && (url != ""))
	window.location = url;	
}

function forumRedirect() {
        var url = document.ffqtList.forumselect.options[document.ffqtList.forumselect.selectedIndex].value;
	if ((url != "^") && (url != ""))
	window.location = url;
}

getPosition=function(elem)
{
	var offsetTrail = elem;
	var offsetLeft = 0;
	var offsetTop = 0;
	while (offsetTrail) {
		offsetLeft += offsetTrail.offsetLeft;
		offsetTop += offsetTrail.offsetTop;
		offsetTrail = offsetTrail.offsetParent;
	}

	var res = {"left":offsetLeft,"top":offsetTop};

	return res;
	
};

Ticker_OverLay_Close = function()
{
	document.getElementById("TickerListOL").style.display="none";
};

	<!------ OAS SETUP begin ------>
	var l_usertype;
	l_usertype = Get_Cookie( "PSI" );
	
	if (l_usertype == "S")
		{OAS_listpos = 'Top1,Top,Bottom,Left,Left2,Left3,Right,Middle,x43,Position1,Position2,Position3,Position4,Bottom1,Bottom2,x23';}
	else
		{OAS_listpos = 'Top1,TopLeft,Bottom,Left,Left2,Left3,Right,Middle,x07,x08,x30,Position1,Position2,Position3,Position4,Bottom1,Bottom2,x23';}

	
	//configuration
	OAS_query = 'area=FUNDS';	
	OAS_sitepage = 'www.morningstar.com/funds';
	
	OAS_url ='http://ads.morningstar.com/RealMedia/ads/';
	//end of configuration
	OAS_version = 10;
	OAS_rn = '001234567890'; OAS_rns = '1234567890';
	OAS_rn = new String (Math.random()); OAS_rns = OAS_rn.substring (2, 11);
	
	function OAS_NORMAL(pos) { 
		document.write('<A HREF="' + OAS_url + 'click_nx.ads/' + OAS_sitepage + '/1' + OAS_rns + '@' + OAS_listpos + '!' + pos + '?' + OAS_query + '" TARGET=_top>');
		document.write('<IMG SRC="' + OAS_url + 'adstream_nx.ads/' + OAS_sitepage + '/1' + OAS_rns + '@' + OAS_listpos + '!' + pos + '?' + OAS_query + '" BORDER=0></A>');
	}
	
	OAS_version = 11;
	if ((navigator.userAgent.indexOf('Mozilla/3') != -1) || (navigator.userAgent.indexOf('Mozilla/4.0 WebTV') != -1))
	OAS_version = 10;
	if (OAS_version >= 11)
	document.write('<SCR'+ 'IPT LANGUAGE=JavaScript1.1 SRC="' + OAS_url + 'adstream_mjx.ads/' + OAS_sitepage + '/1' + OAS_rns + '@' + OAS_listpos + '?' + OAS_query + '"><\/SCRIPT>');
	 
	 document.write('');
	
	function OAS_AD(pos) {
		if (OAS_version >= 11)
		OAS_RICH(pos);
		else
		OAS_NORMAL(pos);
	}
	
	<!------ OAS SETUP end ------>