//DECLARED


document.domain = 'nasdaq.com';

//vars

var homePageAdIndex = 0;
var dummy = document.cookie;
var valButton = "fp";
var nn4= false;
var nn6= (document.getElementById && !document.all);
var ie4= (document.all && !document.getElementById);
var ie5= (document.all && document.getElementById);
var is_sumLink = 'summary';
var currentActiveW="";
var currentActiveT="";
//var adC = new Array();
	
var StockRealTimeQuotes = "http://www.nasdaq.com/aspx/nasdaqlastsale_new.aspx?";
var StockFlashQuotes = "http://www.nasdaq.com/aspx/flashquotes_new.aspx?";
var StockCharts = "http://www.nasdaq.com/aspx/dynamic_charting_new.aspx?";
var StockInfoQuotes = "http://quotes.nasdaq.com/quote.dll?mode=stock&";
var StockSummaryQuotes = "http://quotes.nasdaq.com/asp/SummaryQuote_new.asp?";
var MutualFlashQuotes = "http://www.nasdaq.com/asp/quick_mutual_new.asp?mode=fund&page=quick&";
var MutualInfoQuotes = "http://www.nasdaq.com/asp/quotes_mutual_new.asp?mode=fund&page=multi&";
var OptionFlashQuotes = "http://quotes.nasdaq.com/asp/option_quick_new.asp?mode=options&page=quick&";
var OptionInfoQuotes = "http://quotes.nasdaq.com/asp/option_multi_new.asp?mode=options&page=multi&";
var SymbolLookup = "http://www.nasdaq.com/asp/comlookup.asp?";

var baseURLQuotes = 'http://quotes.nasdaq.com';
var baseURLWWW = 'http://www.nasdaq.com';
var baseURLdynamic = 'http://dynamic.nasdaq.com';

var processing = false;

function addEvent(obj, type, fn) {
	if (obj.addEventListener)
		obj.addEventListener( type, fn, false );
	else if (obj.attachEvent) {
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
	}
}

function addLoadFunction(funcptr)
{
	addEvent(window,"load",funcptr);
}

//ie6 hacks for hover styles for tabs
$(function(){
    $(".symbol_links div").mouseover(function () {
      $(this).addClass('showit');
    });
 $(".symbol_links div").mouseout(function () {
      $(this).removeClass('showit');
    });
  });

$(function(){
    $("#slider li").mouseover(function () {
      $(this).addClass('under');
    });
 $("#slider li").mouseout(function () {
      $(this).removeClass('under');
    });
  });

$(function(){
    $("#tabbox li").mouseover(function () {
      $(this).addClass('under');
    });
 $("#tabbox li").mouseout(function () {
      $(this).removeClass('under');
    });
  });


//quote widget
function htmlGo (loc,goType) 
{	
		var re = /[\s *,\,]/;
		var sInput;
		var arStrings;
		var myfrm;
		var myquote_type;
		var mystock_type1;
		var mystock_type2;
		var mystock_type3;
		var sym;
		arStrings = new Array();
		var i=0;
			for (var t=0;t<10;t++)
			{
				sym = eval("document.MainQuotes.symbol" + t + ".value").replace(/\s/g,"");
				if(sym!="") 
				{	
					arStrings[i] = sym.toUpperCase();
					i++;
				}
			}

				if(ie4) {
					sInput = document.MainQuotes.symbol0;
					myfrm = document.MainQuotes;
					myquote_type = goType;
					mystock_type1 = document.MainQuotes.stock_type[0];
					mystock_type2 = document.MainQuotes.stock_type[1];
					mystock_type3 = document.MainQuotes.stock_type[2];
				} else {
					sInput = document.getElementById('symbol0');
					myfrm = document.getElementById('MainQuotes');
					myquote_type = document.getElementById('quote_type');
					mystock_type1 = document.getElementById('stock_type1');
					mystock_type2 = document.getElementById('stock_type2');
					mystock_type3 = document.getElementById('stock_type3');
				}
				
			if ( (arStrings.join("") == "") && (loc != 'srch') ){		
				var is_mdePage = baseURLQuotes + '/asp/MasterDataEntry.asp?page=';

				if (mystock_type1.checked)
				{
					switch (goType)
					{
					case "realtime":
						document.location.href = is_mdePage + 'NasdaqLastsale';
					break;
					case "flash":
						document.location.href = is_mdePage + 'flashQuotes';
					break;

					case "summary":
						document.location.href = is_mdePage + 'Summary%20Quote';
					break;

					case "optionchain":
						//ADD MASTER DATA ENTRY URL HERE
						document.location.href = is_mdePage + 'OptionsDisplay';
					break;

					case "info":
						document.location.href = is_mdePage + 'InfoQuotes';
					break;

					case "charts":
						document.location.href = is_mdePage + 'Charts';
					break;

					case "dyncharts":
						document.location.href = is_mdePage + 'dynamic_charting';
					break;

					case "compfin":
						document.location.href = is_mdePage + 'full';
					break;

					case "premkt":
						document.location.href = is_mdePage + 'Pre-Market';
					break;

					case "afthours":
						document.location.href = is_mdePage + 'After%20Hours%20Market';
					break;

					case "stkcon":
						document.location.href = is_mdePage + 'stockconsultant';
					break;

					case "redpage":
						document.location.href = is_mdePage + 'redpage';
					break;

					case "analyst":
						document.location.href = is_mdePage + 'analystinfo';
					break;

					case "holdings":
						document.location.href = is_mdePage + 'holdingssummary';
					break;

					case "guru":
						document.location.href = is_mdePage + 'guruanalysis';
					break;

					case "compnews":
						document.location.href = is_mdePage + 'Company%20News';
					break;

					case "reports":
						document.location.href = is_mdePage + 'stockreports';
					break;
					}												
				}
				else if(mystock_type2.checked)
				{
					switch (goType){
						case "flash": document.location.href = is_mdePage + 'quickmutual';
										break;
						case "info":  document.location.href = is_mdePage + 'multimutual';
										break;
						case is_sumLink: document.location.href = is_mdePage + 'profilemutual';
										break;
						case "premkt": document.location.href = is_mdePage + 'chartingfunds';
										break;
						}
				}
				else if(mystock_type3.checked)
				{
					switch (goType){
						case "flash": document.location.href = is_mdePage + '&pathname=/aspxcontent/OptionFlashQuotes.aspx';
										break;
						case "info":  document.location.href = is_mdePage + '&pathname=/aspxcontent/OptionInfoQuotes.aspx';
										break;
						case is_sumLink: document.location.href = is_mdePage + '&pathname=%2Faspxcontent%2FOptions.aspx';
										break;
						}
				}
			} else {
				if (loc == 'srch') {
					if (arStrings.join("") == ""){
						var optionmode;
						if (mystock_type1.checked) optionmode="stock";
						if (mystock_type2.checked) optionmode="mmf";
						if (mystock_type3.checked) optionmode="options";
						SymbolLookup = "http://www.nasdaq.com/asp/homesymlookup.asp?mode=" + optionmode;
						open_new_window(SymbolLookup, 595, 380, false,true, false);
						return;
					 } else {
						var optionmode;
						if (mystock_type1.checked) optionmode="stock";
						if (mystock_type2.checked) optionmode="mmf";
						if (mystock_type3.checked) optionmode="options";
						if (optionmode=="stock" || optionmode=="mmf"){
							SymbolLookup = "http://www.nasdaq.com/asp/homesymlookup.asp?" + "symbol=" + arStrings.join("&symbol=") + "&mode=" + optionmode;
							open_new_window(SymbolLookup, 595, 380, false,true, false);
							return;
						} else if (optionmode == "options") {
							SymbolLookup = "http://www.nasdaq.com/asp/comlookup.asp?" + "symbol=" + arStrings.join("&symbol=") + "&mode=" + optionmode;
							myfrm.action = SymbolLookup;
							return;
						}
					}

				} else if (mystock_type1.checked) {
					switch (goType){
						case "realtime":
							myfrm.action = StockRealTimeQuotes + "symbol=" + arStrings.join("&symbol=") + "&selected=" + arStrings[0];
						break;

						case "flash":
							myfrm.action = StockFlashQuotes + "symbol=" + arStrings.join("&symbol=") + "&selected=" + arStrings[0];
							//myfrm.action = StockInfoQuotes + "symbol=" + arStrings.join("&symbol=") + "&page=quick" + "&selected=" + arStrings[0];
						break;

						case "summary":
							myfrm.action = StockSummaryQuotes + "symbol=" + arStrings.join("&symbol=") + "&selected=" + arStrings[0];
						break;

						case "optionchain":
							//ADD URL STRING HERE
							myfrm.action = baseURLQuotes + 'asp/option_chain.asp?' + "symbol=" + arStrings.join("&symbol=") + "&selected=" + arStrings[0];
						break;

						case "info":
							myfrm.action = StockInfoQuotes + "symbol=" + arStrings.join("&symbol=") + "&page=multi" + "&selected=" + arStrings[0];
						break;

						case "charts":
							myfrm.action = StockCharts + "symbol=" + arStrings.join("&symbol=") + "&selected=" + arStrings[0];
						break;

						case "dyncharts":
							myfrm.action = baseURLWWW + '/asp/dynamic_charting.asp?symbol=' + arStrings.join("&symbol=") + "&selected=" + arStrings[0];
						break;

						case "compfin":
							myfrm.action = baseURLWWW + '/asp/ExtendFund.asp?' + "symbol=" + arStrings.join("&symbol=") + "&selected=" + arStrings[0];
						break;

						case "premkt":
							if(arStrings.length>1)
								myfrm.action = baseURLWWW + "/aspxcontent/ExtendedTradingTrades.aspx?symbol=" + arStrings.join("&symbol=") + "&selected=" + arStrings[0] + "&mkttype=pre";
							else
								myfrm.action = baseURLWWW + "/aspxcontent/ExtendedTradingTrades.aspx?selected=" + arStrings[0] + "&mkttype=pre";								
						break;

						case "afthours":
							if(arStrings.length>1)
								myfrm.action = baseURLWWW + "/aspxcontent/ExtendedTradingTrades.aspx?symbol=" + arStrings.join("&symbol=") + "&selected=" + arStrings[0] + "&mkttype=after";
							else
								myfrm.action = baseURLWWW + "/aspxcontent/ExtendedTradingTrades.aspx?selected=" + arStrings[0] + "&mkttype=after";								
						break;

						case "stkcon":
							myfrm.action = baseURLWWW + '/asp/stock_consultant.asp?' + "&symbol=" + arStrings.join("&symbol=") + "&selected=" + arStrings[0];
						break

						case "redpage":
							myfrm.action = baseURLWWW + '/aspx/RevenueEPSSummary.aspx?' + "&symbol=" + arStrings.join("&symbol=") + "&selected=" + arStrings[0];
						break;


						case "analyst":
							myfrm.action = baseURLWWW + '/earnings/analyst_summary.asp?' + "symbol=" + arStrings.join("&symbol=") + "&selected=" + arStrings[0];
						break;

						case "holdings":
							myfrm.action = baseURLWWW + '/asp/Holdings.asp?sel=holdingssummary' + "&symbol=" + arStrings.join("&symbol=") + "&selected=" + arStrings[0];
						break;

						case "guru":
							myfrm.action = baseURLWWW + '/asp/guruanalysis.asp?' + "symbol=" + arStrings.join("&symbol=") + "&selected=" + arStrings[0];
						break;

						case "compnews":
							myfrm.action = baseURLWWW + '/asp/quotes_news.asp?' + "symbol=" + arStrings.join("&symbol=") + "&selected=" + arStrings[0];
						break;

						case "reports":
							myfrm.action = baseURLWWW + '/asp/quotes_reports_new.asp?' + "symbol=" + arStrings.join("&symbol=") + "&selected=" + arStrings[0];
						break;
					}

				} else if (mystock_type2.checked) {
					if (goType == "flash") {
						myfrm.action = MutualFlashQuotes + "symbol=" + arStrings.join("&symbol=");
					} else if (goType == "fundprofile") {
						myfrm.action = "http://www.nasdaq.com/reference/fundprofile.stm?&mode=funds" + "&symbol=" + arStrings.join("&symbol=") + "&selected=" + arStrings[0];
					} else if(goType == "info"){
						myfrm.action = MutualInfoQuotes + "symbol=" + arStrings.join("&symbol=");
					}
					  else //must be comparison charts
						myfrm.action = "http://www.nasdaq.com/asp/charting_mutual.asp?mode=funds" + "&symbol=" + arStrings.join("&symbol=") + "&selected=" + arStrings[0];

				} else {
					if (goType == "flash") {
						myfrm.action = OptionFlashQuotes + "symbol=" + arStrings.join("&symbol=");
					} else if(goType=="info") {
						myfrm.action = OptionInfoQuotes + "symbol=" + arStrings.join("&symbol=");
					} else {
						myfrm.action = baseURLQuotes + '/asp/option_chain.asp?' + "symbol=" + arStrings.join("&symbol=") + "&selected=" + arStrings[0] + "&homepage=y"; 
				}
			}
			document.location.href = myfrm.action ;
		}
}

function openwin(windowName,width,height)
{
		newWindow = window.open(windowName, 'newWindow','toolbar=no,menubar=no,width='+width+',height='+height+',scrollbars=yes,resizable=yes');
}

function open_new_window(url, width, height, statusbar, scrollbar, menubar)
{
		window.name = "ParentWin";
		window.open(url, "newWin", "menubar="+(menubar?"yes":"no")+",toolbar=0,location=0,directories=0,copyhistory=0,scrollbars="+(scrollbar?"yes":"no")+",resizable=yes,status="+(statusbar?"yes":"no")+",width="+width+",height="+height);
}
	
function GetElement (name) 
{
		return document.getElementById(name);
}

function AddSymbol(symbol,mode) 
{
		var Userinputs;
		Userinputs = new Array(10);
		for (var t=0;t<10;t++)
		Userinputs[t] = eval("document.MainQuotes.symbol" + t + ".value").replace(/\s/g,"");
		var SymbolsElement = new Array(10);
		for (var t=0;t<10; t++)
			SymbolsElement[t] = GetElement('symbol'+ t);
                var addsymbol;
                var i;
                addsymbol= 1;
                i = 0;
                while (i < 10 && addsymbol==1)
                {
		   if (Userinputs[i] =='')
		   {
			SymbolsElement[i].value = symbol;
			alert(symbol + " has been added to your symbol list");
				addsymbol=0;
			}
			i = i + 1;
		}
}

function ShowELSSymbol(symbol)
{
	document.location.href = "http://www.nasdaq.com/aspx/els.aspx?selected="+symbol;
}

function checkButtons(selectedRadio)
{	
		if (selectedRadio == 'options'){
			document.getElementById("btn3").innerHTML = "OPTIONS CHAIN";
			document.getElementById("btn4").style.display = "none";
			document.getElementById("btn5").style.display = "none";
			document.getElementById("stockctrls").style.display = "none";
			return is_sumLink = 'optionchain';
			
		}

		else if (selectedRadio == 'funds'){
			document.getElementById("btn3").innerHTML = "FUND PROFILE";	
			valButton = "fp"
			document.getElementById("btn4").className = "wide_qb";
			document.getElementById("btn4").innerHTML = "COMPARISON CHARTS";
			document.getElementById("btn4").style.display = "block";
			document.getElementById("btn5").style.display = "none";
			document.getElementById("stockctrls").style.display = "none";
			return is_sumLink = 'fundprofile';
				
			
		} else {
			document.getElementById("btn3").innerHTML = "SUMMARY QUOTES";
			document.getElementById("btn4").innerHTML = "PRE- MARKET";
			document.getElementById("btn4").className = "";
			document.getElementById("btn4").style.display = "block";
			document.getElementById("btn5").style.display = "block";
			document.getElementById("stockctrls").style.display = "block";
			return is_sumLink = 'summary';
		}		
}
//index table
function reload_chart(img_source,newselected,displayValue)
{
				if(!processing)
				{
					processing = true;
					document.getElementById(selected).className = "mywidgetnosel";
					document.getElementById(newselected).className = "mywidgetsel";
					document.getElementById("selectedCompanyName").innerHTML = displayValue;
					//document.getElementById(selected).getElementsByTagName('td')[0].innerHTML = '&nbsp;';
					//document.getElementById(newselected).getElementsByTagName('td')[0].innerHTML = '<img src="http://content.nasdaq.com/images/homeWidgetArrow.gif" style="height: 8px; width:2px" alt="" />';
					selected = newselected;
					displayValue = displayValue.replace("&","amp");//& switched to 'amp' to use this string as a querystring parameter
				    document.getElementById("indexdataframeholder").removeChild(document.getElementById("indexdataframe"));
					document.getElementById("indexdataframeholder").innerHTML = '<iframe name="indexdataframe" id="indexdataframe" frameborder="0" width="0" height="0" scrolling="no" src="../includes/indexdata.aspx?selected='+displayValue+'"></iframe>';
				    //document.getElementById("indexdataframe").src="../includes/indexdata.aspx?selected="+displayValue;
				}
}	

function setIndexData(newvalue,newchange,newpctchange,imgurl,volume)
{
				
				if(parseFloat(newchange)>0)
				{
					color="green";
					arrow="greenarrowsmall-index.gif";
				}
				else if(parseFloat(newchange)<0)
				{
					color="red";
					arrow="redarrowsmall-index.gif";
				}
				else
				{
					color="";
					arrow="spacer.gif";
				}
				td = document.getElementById(selected).getElementsByTagName('td');
				td[1].innerHTML = newvalue;
				td[2].getElementsByTagName('span')[0].className = color;
				td[2].getElementsByTagName('span')[0].innerHTML = newchange+'&nbsp;<img src="http://www.nasdaq.com/images/'+arrow+'" border="0" style="" alt=""/>&nbsp;';
				td[3].getElementsByTagName('span')[0].className = color;
				td[3].getElementsByTagName('span')[0].innerHTML = newpctchange+"%";
				document.getElementById("homeindexchartholder").removeChild(document.getElementById("homeindexchart"));
				document.getElementById("homeindexchartholder").innerHTML = '<img src="'+imgurl+'" name="homeindexchart" id="homeindexchart" border="0" style="height: 100px; width: 230px;" alt="" />';
				//document.getElementById("homeindexchart").src = imgurl;//chart image
				document.getElementById("nasdaqVolume").innerHTML = volume; //nasdaq volume
				processing = false;
			
}	
//most active
function showcontent(tab)
{
	if(tab!=currentActiveT)
	{
		if(currentActiveW!='' && currentActiveT!='')
		{
			document.getElementById(currentActiveW).style.display = "none";
		    document.getElementById(currentActiveT).className="off";
		}
		else
		{
			document.getElementById('Mostactive').style.display = "none";
			document.getElementById('Advancers').style.display = "none";
            document.getElementById('Decliners').style.display = "none";
            document.getElementById('DollarVolume').style.display = "none";
            document.getElementById('UnusualVolume').style.display = "none";
            document.getElementById('MyList').style.display = "none";
		}
    
    switch (tab)
    {
        case "most-active":
			document.getElementById('Mostactive').style.display = "block";
            currentActiveW = 'Mostactive';
            break;
        case "most-advanced":
			document.getElementById('Advancers').style.display = "block";
            currentActiveW = 'Advancers';
            break;
        case "most-declined":
			document.getElementById('Decliners').style.display = "block";
            currentActiveW = 'Decliners';
            break;
		case "dollar-volume":
			document.getElementById('DollarVolume').style.display = "block";
            currentActiveW = 'DollarVolume';
            break;
		case "unusual-volume":
			document.getElementById('UnusualVolume').style.display = "block";
            currentActiveW = 'UnusualVolume';
            break;
		case "my-list":
            document.getElementById('MyList').style.display = "block";
            currentActiveW = 'MyList';
		getMyListData();
            break;
		default:
			document.getElementById('Mostactive').style.display = "block";
            currentActiveW = 'Mostactive';
            break;
        
    }
    document.getElementById(tab).className="on";
	currentActiveT = tab;
	}
}

function getDisplayActive()
{
	var showAdvancerType = get_querystring_value("show");
	if(showAdvancerType==false)
		showcontent('most-advanced');
	else
	{
	switch(showAdvancerType.toLowerCase())
	{
		case  'mostactive': showcontent('most-active')
							break;
        case  'advancers':	showcontent('most-advanced');
							break;
        case  'decliners':	showcontent('most-declined');
							break;
        case  'dollarvolume':showcontent('dollar-volume');
							break;
        case  'unusualvolume':	showcontent('unusual-volume');
							break;
        case  'mylist':		showcontent('my-list');
							break;
		
     	default:		showcontent('most-advanced');
						break;
	}
	}
}


//adslider
function current(sl_tab)
{    
   
    document.getElementById("sl_tab1").className="off"; 
    document.getElementById("sl_tab2").className="off";
    document.getElementById("sl_tab3").className="off";
    document.getElementById("sl_tab4").className="off";
    document.getElementById(sl_tab).className="on";    
}

function checkTipSymbol()
{
	tipSym = document.getElementById('tipSymbol').value;
	if(tipSym =="Enter Symbol" || tipSym == "")
		alert("Please enter a symbol for Guru Analysis");
	else
	window.location.href = "http://www.nasdaq.com/asp/guruanalysis.asp?symbol="+tipSym+"&selected="+tipSym;
}