//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 IE6 = false /*@cc_on || @_jscript_version < 5.7 @*/;
var is_sumLink = 'summary';
var currentActiveW="";
var currentActiveT="";
var navHidden = true;
var loadingupper = false;
var loadinglower = false;
var uselIndex = "";
var lselIndex = "";
var upperselected = "";
var lowerselected = "";
var topGraphUrl = "";
var botGraphUrl = "";
var baseURLQuotes = 'http://quotes.nasdaq.com';
var baseURLWWW = 'http://www.nasdaq.com';
var baseURLdynamic = 'http://dynamic.nasdaq.com';

var processing = false;
var ordIndexes = new Array("NASDAQ","NASDAQ-100","NASDAQ-100 PMI","NASDAQ-100 AHI","DJIA","S&P 500","Russell 1000","Russell 2000","FTSE All-World ex-US*","FTSE RAFI 1000*");
var indexObjs = new Array(10);


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);
}

function bookmark(url,title){
  if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
  window.external.AddFavorite(url,title);
  } else if (navigator.appName == "Netscape") {
    window.sidebar.addPanel(title,url,"");
  } else {
    alert("Press CTRL-D (Netscape) or CTRL-T (Opera) to bookmark");
  }
}

//$(function(){$("#symbol0").autocomplete("../aspx/autocompletesearch.aspx",{minChars:2,maxItemsToShow:9,cacheLength:1,delay:50,extraParams:{sortBy:"symbol"}});});

//hover styles for tabs
//most active widget
$(function(){
    $(".symbol_links div").mouseover(function () {
      $(this).addClass('showit');
    });
 $(".symbol_links div").mouseout(function () {
      $(this).removeClass('showit');
    });
  });
//ad slider
$(function(){
    $("#slider li").mouseover(function () {
      $(this).addClass('under');
    });
 $("#slider li").mouseout(function () {
      $(this).removeClass('under');
    });
  });
//most active tabs
$(function(){
    $("#tabbox li").mouseover(function () {
      $(this).addClass('under');
    });
 $("#tabbox li").mouseout(function () {
      $(this).removeClass('under');
    });
  });
//index table
$(function(){
$('#nasdaq_indices div').hover(function()
	{
    $(this).addClass('hover_ix');
    }, function()
	{
    $(this).removeClass('hover_ix');    
	});
$('#other_indices div').hover(function()
	{
    $(this).addClass('hover_ix');
    }, function()
	{
    $(this).removeClass('hover_ix');    
	});

});

//quote widget
function showNav()//show the quote navigation
{
	jQuery('#stocknav').slideDown("slow");
	navHidden = false;
	document.getElementById("quotenavexpand").style.display="none";
	document.getElementById("quotenavcollapse").style.display="block";
}

function hideNav()//hide the quote navigation
{
	jQuery('#stocknav').slideUp("slow");
	navHidden = true;
	document.getElementById("quotenavcollapse").style.display="none";
	document.getElementById("quotenavexpand").style.display="block";
}

function hideExp()
{
	document.getElementById("quotenavexpand").style.display="none";
    document.getElementById("quotenavcollapse").style.display="none";
}

function trim(str)
{
  return str.replace(/^\s*/, '').replace(/\s*$/, '');
}


function replaceComma(temp) 
{
	var out = ','; // replace this
	var add = ' '; // with this
	temp = '' + temp + ' '; // temporary holder

	while (temp.indexOf(out)>-1) 
	{
		pos= temp.indexOf(out);
		temp = '' + (temp.substring(0, pos) + add + temp.substring((pos + out.length), temp.length));
	}
	return temp;
}

function checkUserInput(ele, event)
{
	if(event == 'onfocus')
	{
		if(ele.value=='Enter up to 25 symbols separated by commas or spaces') ele.value='';
	}
	else if(event == 'onblur')
	{
		var str = ele.value;
		str = replaceComma(str);
		str = trim(str);
		if(str=='')
		{
		}
		//hideNav();
  	}
	else if (event == 'onkeypress')
	{

		if(navHidden==true && document.getElementById('stock_type1').checked )
		{
			showNav();
		}
	}
}

function checkButtons(selectedRadio)//radio buttons, switch to a new nav if the nav is currently visible
{

  if(selectedRadio == 'options')
  {
		hideNav();
		hideExp();
		$("#stock_controls").css("display","none");
    	$("#fund_controls").css("display","none");
    	$("#option_controls").css("display","block");
		document.getElementById("userinput").value = "";
		document.getElementById("savesymbols-hm").style.visibility = "hidden";
  }
  else if(selectedRadio == 'funds')
	{
		hideNav();
	    hideExp();
		$("#stock_controls").css("display","none");
		$("#option_controls").css("display","none");
		$("#fund_controls").css("display","block");
		document.getElementById("userinput").value = "";
		document.getElementById("savesymbols-hm").style.visibility = "hidden";
			
	} 
	else if(selectedRadio == 'stocks')
	{
		if(navHidden==true)
			$("#quotenavexpand").css("display","block");
		$("#fund_controls").css("display","none");
		$("#option_controls").css("display","none");
		$("#stock_controls").css("display","block");
		document.getElementById("userinput").value = getCookieSymbols();
		document.getElementById("savesymbols-hm").style.visibility = "visible";
	}

		
}

function toggleCookieNav()
{
	if(navigator.cookieEnabled)
	{
		if(get_cookie_value("userCookiePref")=="true")//disabling cookie nav
		{
			var confirmation=confirm("Are you sure? Choosing the OK button will clear your current symbol list for next time");
			if(confirmation==true)
			{
				var exdate=new Date();
				exdate.setDate(exdate.getDate()+14);//expires in two weeks
				document.cookie="userCookiePref=false;expires="+exdate.toGMTString()+";path=/;domain=nasdaq.com";
			}			
			else
			{
				document.getElementById("cookiepref").checked = true;
			}
		}
		else//enabling cookie nav
		{
			var exdate=new Date();
			exdate.setDate(exdate.getDate()+14);//expires in two weeks
			document.cookie="userCookiePref=true;expires="+exdate.toGMTString()+";path=/;domain=nasdaq.com";			
		}
	}
	else
	{
		alert("Browser cookies must be enabled to use this feature.")
		document.getElementById("cookiepref").checked = false;
	}
}

function updateCookieList(symbolList)
{
	if(navigator.cookieEnabled)
	{
		count=symbolList.length;
		if(count>0)
		{
			var selectedSym = symbolList[0].toUpperCase();
			var total = symbolList.length;
		
			var list="";
			var j;
			if(count>25)
				count = 25;					
			for(j=count-1;j>=0;j--)
			{
				if ( (symbolList[j]) && (symbolList[j] != ''))
				{
					sym = symbolList[j].toUpperCase();
					if(sym==selectedSym)
						sym+="+";	//add a tag for selected symbol
					if(list!="")
						list = sym.concat("&"+list);
					else
						list = sym;
				}
			}
		
			var exdate=new Date();
			exdate.setDate(exdate.getDate()+14);//expires in two weeks
			document.cookie="userSymbolList="+list+";expires="+exdate.toGMTString()+";path=/;domain=nasdaq.com";
			
		}
			
	}//cookies not enabled
}


function getCookieSymbols()
{
	var found;
	if(navigator.cookieEnabled)
	{
		if(document.cookie.indexOf("userSymbolList=")!=-1)
		{
					
			var i,j;
			i = document.cookie.indexOf("userSymbolList=")+15;
			j = document.cookie.indexOf(";",i);
						
			if(j==-1)  //symbol list string is at the end of the cookie for some reason
				j = document.cookie.length;
			var list = unescape(document.cookie.substring(i,j)).replace(/\+/g,"");
			if(list.search("&")>-1) //multiple symbols are present and split to form an array
			{
				var symbols = list.split("&");
				found = true;
			}
			else if(list!="") //only one symbol present in cookie, create an array to process
			{
				var symbols = new Array(1);
				symbols[0]=list;
				found = true;
			}
			else//empty list
				found = false;			
		}
		else //no list stored
			found = false;
	}
	else//cookies not enabled
		found = false;

	if(found && get_cookie_value("userCookiePref")=="true")
		return " "+symbols.join(" ");
	else
		return "";
}

function removeDuplicates(arr)
{
	if(arr.length>1)
	{
		var duplicated = false;
		var uniqueArray = new Array();
		uniqueArray[0] = arr[0];
		for(i=1;i<arr.length;i++)
		{
			duplicated = false;
			var test = arr[i].toUpperCase();
			for(j=i-1;j>=0;j--)
			{
				if(arr[j].toUpperCase()==test)
				{
					duplicated = true;
					break;
				}
			}
			if(!duplicated)
				uniqueArray.push(arr[i]);
		}
		return uniqueArray;
	}
	else
		return arr;
}

function check_interstitial_count(max)
{
	var cdate = new Date();
	if(navigator.cookieEnabled)
	{
		code = get_cookie_value("interstitial_code");

		if(code!=false)//interstitial cookie exists
		{
			info = code.split("_");
			
			if(info[0]==String(cdate.getDay()) && info[1]==String(cdate.getMonth()))//cookie is current
			{				
				current_count = info[2];
				if(parseInt(current_count)<max)
					return true;//havent seen max interstitials yet
				else
					return false;//already saw interstitial max times
			}
			else
				return true;//cookie is out of date
		}
		else
		{
			return true;//havent seen interstitial
		}
	}
	else
		return false;//cookies not enabled
}

function check_interstitial_count_geotarget(max)
{
	var skip;
	skip = get_cookie_value("skip_interstitial3");
	if(skip!=false)
	{
		if(skip=="false")
		{
			var cdate = new Date();
			code = get_cookie_value("interstitial_code3");
		
			if(code!=false)//interstitial cookie exists
			{
				info = code.split("_");
					
				if(info[0]==String(cdate.getDay()) && info[1]==String(cdate.getMonth()))//cookie is current
				{				
					current_count = info[2];
					if(parseInt(current_count)<max)
						return true;//havent seen max interstitials yet
					else
						return false;//already saw interstitial max times
				}
				else
					return true;//cookie is out of date
			}
			else
			{
				return true;//havent seen interstitial
			}
		}
		else
			return false;//outside of interstitial target area
		
	}
	else
		return false;//skip cookie value not set
}

var interstitialPage = "http://www.nasdaq.com/includes/interstitial.stm?dest=";
//interstitial ad components: cookie values(skip,code), max, .stm file, make ad call

function check_two_interstitial_count_geotarget(max, max2, goType)//max goes with interstitial.stm ad(acela), max2 goes with interstitial3.stm(discover) ad
{
	var irand, skip,skip2;
	skip = get_cookie_value("skip_interstitial");
	skip2 = get_cookie_value("skip_interstitial3");
	irand = Math.floor(Math.random() * 2) +1;
	
	if((skip==false && skip2==false) || (goType=="summary" && !IE6))//neither skip cookies are set or cookies are disabled, bail
		return false;
	else
	{
		if(skip2==false || IE6)//second skip cookie not set, discover ad disabled in IE6, test first
		{
			if(skip=="false")
			{
				return check_aux(max, "interstitial_code", "http://www.nasdaq.com/includes/interstitial.stm?dest=");
			}
			else
				return false;//outside of first interstitial target area
			
		}
		else if(skip==false)//first skip cookie not set, test second
		{
			if(skip2=="false")
			{
				return check_aux(max2, "interstitial_code3", "http://www.nasdaq.com/includes/interstitial3.stm?dest=");
			}				
			else
				return false;//outside of second interstitial target area
			
		}
		else//both cookies recognized
		{
			if(skip=="true" && skip2=="true")
				return false;//outside of both interstitial target areas
			else
			{
				if(skip2=="true")//skip second, check first interstitial
				{
					return check_aux(max, "interstitial_code", "http://www.nasdaq.com/includes/interstitial.stm?dest=");		
				}
				else if(skip=="true")//skip first, check second interstitial
				{
					return check_aux(max2, "interstitial_code3", "http://www.nasdaq.com/includes/interstitial3.stm?dest=");		
				}
				else//both target cookies are set, and both are "false" randomly choose 1 to test for max ads
				{
								
					var tryFirst=false;
					var trySecond=false;
					if(irand==1)//test first interstitial
					{
						var cdate = new Date();
						code = get_cookie_value("interstitial_code");
				
						if(code!=false)//interstitial cookie exists
						{
							info = code.split("_");
							
							if(info[0]==String(cdate.getDay()) && info[1]==String(cdate.getMonth()))//cookie is current
							{				
								current_count = info[2];
								if(parseInt(current_count)<max)
								{
									interstitialPage = "http://www.nasdaq.com/includes/interstitial.stm?dest=";
									return true;//havent seen max interstitials yet
								}
								else
									trySecond = true;//already saw interstitial max times, test the second one
							}
							else
							{
								interstitialPage = "http://www.nasdaq.com/includes/interstitial.stm?dest=";
								return true;//cookie is out of date
							}
						}
						else
						{
							interstitialPage = "http://www.nasdaq.com/includes/interstitial.stm?dest=";
							return true;//havent seen interstitial
						}
					}
					else if(irand==2)
					{
						var cdate = new Date();
						code = get_cookie_value("interstitial_code3");
					
						if(code!=false)//interstitial cookie exists
						{
							info = code.split("_");
							
							if(info[0]==String(cdate.getDay()) && info[1]==String(cdate.getMonth()))//cookie is current
							{				
								current_count = info[2];
								if(parseInt(current_count)<max2)
								{
									interstitialPage = "http://www.nasdaq.com/includes/interstitial3.stm?dest=";
									return true;//havent seen max interstitials yet
								}
								else
									tryFirst = true;//already saw interstitial max times, test the first one
							}
							else
							{
								interstitialPage = "http://www.nasdaq.com/includes/interstitial3.stm?dest=";
								return true;//cookie is out of date
							}
						}
						else
						{
							interstitialPage = "http://www.nasdaq.com/includes/interstitial3.stm?dest=";
							return true;//havent seen interstitial
						}					
					}

					//if we're here, the user has seen the randomly chosen ad max times already, check against the other ad
					
					if(tryFirst)
					{
						return check_aux(max, "interstitial_code", "http://www.nasdaq.com/includes/interstitial.stm?dest=");
					}
					else if(trySecond)
					{
						return check_aux(max2, "interstitial_code3", "http://www.nasdaq.com/includes/interstitial3.stm?dest=");
					}

					return false;//should never be here

				}//skip neither
					
			}//inside at least 1 target area

		}//both cookies recognized

	}//at least 1 cookie recognized
}

function check_three_interstitial_count_geotarget(max, max2, max3)
{
	var res=false;
	irand = Math.floor(Math.random() * 3) +1;
	skip3 = get_cookie_value("skip_interstitial2");
	if(irand!=3)//test for first two interstitials
	{
		res = check_two_interstitial_count_geotarget(max,max2);
	}		
	if(!res && skip3!=false)//first two interstitials either failed or not picked, interstitial 3 cookie is set
	{
		if(skip3!="true")//inside interstitial 3 geo area, check max
			res = check_aux(max3, "interstitial_code3", "http://www.nasdaq.com/includes/interstitial3.stm?dest=");
		else if(irand==3)//outside interstitial 3 geo area, check other two if they havent been checked yet
			res = check_two_interstitial_count_geotarget(max,max2);			
	}
	
	return res;
}

function check_aux(max, cookie_name, url)
{
	var cdate = new Date();
	code = get_cookie_value(cookie_name);
	if(code!=false)//interstitial cookie exists
	{
		info = code.split("_");				
		
		if(info[0]==cdate.getDay() && info[1]==cdate.getMonth())//cookie is current
		{		
			//alert("comparing: "+parseInt(current_count)+" against: "+max);
			current_count = info[2];
			if(parseInt(current_count)<max)
			{
				interstitialPage = url;
				return true;//havent seen max interstitials yet
			}
			else
				return false;//already saw interstitial max times
		}
		else
		{
			interstitialPage = url;
			return true;//cookie is out of date
		}
	}
	else
	{
		interstitialPage = url;
		return true;//havent seen interstitial
	}
}
					


function htmlGo (loc,goType)
{
	var re = /[\s *,\,]/;
	var sInput;
	var arStrings;
	var myfrm;
	var sInput= document.quotenav.userinput.value.replace("Enter up to 25 symbols","");
	list = replaceComma(sInput);
	list = trim(list).toUpperCase();

	arStrings = list.split(" ");

	mystock_type1 = document.getElementById('stock_type1');
	mystock_type2 = document.getElementById('stock_type2');
	mystock_type3 = document.getElementById('stock_type3');

		if ( (arStrings.join("") == "") && (loc != 'srch') )//no symbols entered
		{
			
			var is_mdePage = baseURLQuotes + '/asp/MasterDataEntry.asp?page=';

			if (mystock_type1.checked)
			{			
			
				switch (goType)
				{
					case "realtime":
						document.location.href = is_mdePage + 'NasdaqLastsale';
					break;

					case "tradereporting":
						document.location.href = is_mdePage + 'nlstrades';
					break;

					case "flash":
						document.location.href = is_mdePage + 'flashQuotes';
					break;

					case "summary":
						document.location.href = is_mdePage + 'Summary%20Quote';
					break;

					case "historical":
						document.location.href = is_mdePage + 'historical-quotes';
					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 "compcharts":
						document.location.href = is_mdePage + 'Charts';
					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 "holdingssummary":
						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 "release":
						document.location.href = is_mdePage + 'companypressrelease';
					break;
					
					case "full":
						document.location.href = is_mdePage + 'full';
					break;	

					case "filings":
						document.location.href = is_mdePage + 'filings';
					break;	

					case "shortint":
						document.location.href = is_mdePage + 'short';
					break;		

					case "insiderform4":
						document.location.href = is_mdePage + 'insiderform4';
					break;	

					case "competitor":
						document.location.href = is_mdePage + 'competitor';
					break;			

					case "analystsummary":
						document.location.href = is_mdePage + 'analystsummary';
					break;	

					case "holdings":
						document.location.href = is_mdePage + 'holdings';
					break;						
										
					case "stockreports":
						document.location.href = is_mdePage + 'stockreports';
					break;

					default:
						document.location.href = is_mdePage + 'flashQuotes';													
																
				}
				
			}
			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 "fundprofile": 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 "optionchain": document.location.href = is_mdePage + '&pathname=%2Faspxcontent%2FOptions.aspx';
										break;
					}
			}
		}
		else //either symbols have been entered, or we're doing a search
		{
			if (mystock_type1.checked) 
			{
					arStrings = removeDuplicates(arStrings);
					if(navigator.cookieEnabled)//either modify the cookie or add a new one
					{
						updateCookieList(arStrings); //update the user cookie
						size = arStrings.length;
						if(size>1 && goType!="compcharts" && get_cookie_value("userCookiePref")=="true") //remove everything except the first
							arStrings.splice(1,size-1);
					}
 
					switch (goType)
					{
						case "realtime":
							action = baseURLWWW + '/aspx/nasdaqlastsale.aspx?symbol=' + arStrings.join("&symbol=") + "&selected=" + arStrings[0];
						break;

						case "tradereporting":
							action = baseURLWWW + '/aspx/nlstrades.aspx?symbol=' + arStrings.join("&symbol=") + "&selected=" + arStrings[0];
						break;

						case "flash":
							action = baseURLWWW + '/aspx/flashquotes.aspx?symbol=' + arStrings.join("&symbol=") + "&selected=" + arStrings[0];
						break;

						case "summary":
							action = baseURLQuotes + '/asp/SummaryQuote.asp?' + "symbol=" + arStrings.join("&symbol=") + "&selected=" + arStrings[0];
						break;

						case "optionchain":
							//ADD URL STRING HERE
							action = baseURLWWW + '/aspxcontent/options.aspx?' + "symbol=" + arStrings.join("&symbol=") + "&selected=" + arStrings[0];
						break;

						case "info":
							action = baseURLWWW + '/aspx/infoquotes.aspx?' + 'symbol=' + arStrings.join("&symbol=") + "&selected=" + arStrings[0];
						break;

						case "charts":
							action = baseURLWWW + '/aspx/chartingbasics.aspx?' + "symbol=" + arStrings.join("&symbol=") + "&selected=" + arStrings[0];
						break;

						case "compcharts":
							action = baseURLWWW + '/aspx/chartingbasics.aspx?comparison=on&symbol=' + arStrings.join("&symbol=") + "&selected=" + arStrings[0];
						break;

						case "dyncharts":
							action = baseURLWWW + '/aspx/dynamic_charting.aspx?symbol=' + arStrings.join("&symbol=") + "&selected=" + arStrings[0];
						break;

						case "compfin":
							action = baseURLWWW + '/asp/ExtendFund.asp?' + "symbol=" + arStrings.join("&symbol=") + "&selected=" + arStrings[0];
						break;

						case "premkt":
							if(arStrings.length>1)
								action = baseURLWWW + '/aspxcontent/ExtendedTradingTrades.aspx?mkttype=pre' + "&symbol=" + arStrings.join("&symbol=") + "&selected=" + arStrings[0];
							else
								action = baseURLWWW + '/aspxcontent/ExtendedTradingTrades.aspx?selected=' + arStrings[0] + "&mkttype=pre";
						break;

						case "afthours":
							if(arStrings.length>1)
								action = baseURLWWW + '/aspxcontent/ExtendedTradingTrades.aspx?mkttype=after' + "&symbol=" + arStrings.join("&symbol=") + "&selected=" + arStrings[0];
							else
								action = baseURLWWW + '/aspxcontent/ExtendedTradingTrades.aspx?selected=' + arStrings[0] + "&mkttype=after";
						break;

						case "stkcon":
							action = baseURLWWW + '/asp/stock_consultant.asp?' + "symbol=" + arStrings.join("&symbol=") + "&selected=" + arStrings[0];
						break;

						case "redpage":
							action = baseURLWWW + '/aspx/revenueepssummary.aspx?' + "symbol=" + arStrings.join("&symbol=") + "&selected=" + arStrings[0];
						break;


						case "analystsummary":
							action = baseURLWWW + '/earnings/analyst_summary.asp?' + "symbol=" + arStrings.join("&symbol=") + "&selected=" + arStrings[0];
						break;

						case "guru":
							action = baseURLWWW + '/asp/guruanalysis.asp?' + "symbol=" + arStrings.join("&symbol=") + "&selected=" + arStrings[0];
						break;

						case "compnews":
							action = baseURLWWW + '/aspxcontent/newsHeadlines.aspx?' + "symbol=" + arStrings.join("&symbol=") + "&selected=" + arStrings[0];
						break;

						case "release":
							action = baseURLWWW + '/aspxcontent/newsHeadlines.aspx?SourceCode=PMZ' + "&symbol=" + arStrings.join("&symbol=") + "&selected=" + arStrings[0];
						break;

						case "stockreports":
							action = baseURLWWW + '/asp/quotes_reports.asp?' + "symbol=" + arStrings.join("&symbol=") + "&selected=" + arStrings[0];
						break;

						case "full":
							action = baseURLWWW + '/asp/extendfund.asp?' + "symbol=" + arStrings.join("&symbol=") + "&selected=" + arStrings[0];
						break;
						case "filings":
							action = baseURLWWW + '/asp/quotes_sec.asp?' + "symbol=" + arStrings.join("&symbol=") + "&selected=" + arStrings[0];
						break;

						case "shortint":
							action = baseURLWWW + '/aspxcontent/shortinterests.aspx?' + "symbol=" + arStrings.join("&symbol=") + "&selected=" + arStrings[0];
						break;

						case "holdingssummary":
							action = baseURLWWW + '/asp/holdings.asp?' + "symbol=" + arStrings.join("&symbol=") + "&selected=" + arStrings[0];
						break;

						case "holdings":
							action = baseURLWWW + '/asp/holdings.asp?FormType=Institutional' + "&symbol=" + arStrings.join("&symbol=") + "&selected=" + arStrings[0];
						break;

						case "insiderform4":
							action = baseURLWWW + '/asp/holdings.asp?FormType=form4' + "&symbol=" + arStrings.join("&symbol=") + "&selected=" + arStrings[0];
						break;

						case "competitor":
							action = baseURLWWW + '/screening/ViewCompetitors.asp?' + "symbol=" + arStrings.join("&symbol=") + "&selected=" + arStrings[0];
						break;

						case "historical":
							action = baseURLWWW + '/aspx/historical_quotes.aspx?' + "symbol=" + arStrings.join("&symbol=") + "&selected=" + arStrings[0];
						break;

						default:
							action = baseURLWWW + '/aspx/flashquotes.aspx?' + "symbol=" + arStrings.join("&symbol=") + "&selected=" + arStrings[0];
						
					}

					if (navigator.appVersion.indexOf("Safari")==-1 && jsUserAgent.indexOf('AOL')==-1 && check_two_interstitial_count_geotarget(2,2,goType))//show ad if browser is NOT safari or AOL
					{
						//document.location.href = "http://www.nasdaq.com/includes/interstitial3.stm?dest="+action;
						document.location.href = interstitialPage+action;
						return;
					}
					
											
					
			}
			else if (mystock_type2.checked)
			{
				if (goType == "flash")
				{
					action = baseURLWWW + "/asp/quick_mutual.asp?" + "symbol="  + arStrings.join("&symbol=") + "&selected=" + arStrings[0];;
				} 
				else if (goType == "fundprofile") 
				{
					action = baseURLWWW + "/reference/fundprofile.stm?" + "symbol=" + arStrings.join("&symbol=") + "&selected=" + arStrings[0];
				} 
				else if(goType == "info")
				{
					action = baseURLWWW + "/asp/quotes_mutual.asp?" + "symbol=" + arStrings.join("&symbol=") + "&selected=" + arStrings[0];
				}
				else //must be comparison charts
					action = baseURLWWW + "/asp/charting_mutual.asp?" + "symbol=" + arStrings.join("&symbol=") + "&selected=" + arStrings[0];

			} 
			else
			{
				if (goType == "flash")
				{
					action = baseURLWWW + "/aspxcontent/OptionFlashQuotes.aspx?" + "symbol=" + arStrings.join("&symbol=") + "&selected=" + arStrings[0];
				} 
				else if(goType=="info") 
				{
					action = baseURLWWW + "/aspxcontent/OptionInfoQuotes.aspx?" + "symbol=" + arStrings.join("&symbol=")  + "&selected=" + arStrings[0];
				}
				else
				{
					action = baseURLWWW + '/aspxcontent/options.aspx?' + "symbol=" + arStrings.join("&symbol=") + "&selected=" + arStrings[0];
				}
			}

			document.location.href = action;
		}
		
	
}

function symLookup()
{
	if(document.getElementById('stock_type1').checked)
		pushmodal('symbol_lookup_modal_box','symbolLookupModalBoxinit(\'stock\')');
	else if(document.getElementById('stock_type2').checked)
		pushmodal('symbol_lookup_modal_box','symbolLookupModalBoxinit(\'mmf\')');
	else 
		pushmodal('symbol_lookup_modal_box','symbolLookupModalBoxinit(\'options\')');
}

function symbolLookupModalBoxinit(type)
{
	var frame = document.getElementById("msymbollookupframe");
	frame.style.visibility = "visible";
	frame.src = 'http://www.nasdaq.com/asp/NasdaqSymLookup2.asp?mode='+type;
}

function AddSymbol(symbol)
{

  var Userinput = document.quotenav.userinput.value;
  if(Userinput=='Enter up to 25 symbols separated by commas or spaces')
	document.quotenav.userinput.value = symbol;
  else
	document.quotenav.userinput.value = symbol + ' ' + Userinput;
  popmodal();
}

function ShowELSSymbol(symbol)
{
	document.location.href = "http://www.nasdaq.com/aspx/els.aspx?selected="+symbol;
}



//index table
function getIndexIndex(symbol)//get the relative index
{
	switch(symbol)
	{
		case "NASDAQ": return 0;
		case "NASDAQ-100": return 1;
		case "NASDAQ-100 PMI": return 2;
		case "NASDAQ-100 AHI": return 3;
		case "DJIA": return 0;
		case "S&P 500": return 1;
		case "Russell 1000": return 2;
		case "Russell 2000": return 2;
		case "FTSE All-World ex-US*": return 4;
		case "FTSE RAFI 1000*": return 5;
	}
}

function cleanIndexName(name)//generate a name which can be used as an ID
{
	return name.replace(/\*/g,'P').replace(/\s/g,'P').replace(/&/g,'P');
}

function indexChartInit()
{
	uselIndex = getIndexIndex(upperselected);
	lselIndex = getIndexIndex(lowerselected);	
}

function getIndexClass(symbol)
{
	index = getIndexIndex(symbol);
	if(symbol == "NASDAQ" || symbol == "NASDAQ-100" || symbol == "NASDAQ-100 PMI" || symbol == "NASDAQ-100 AHI")
		compareTo = uselIndex;
	else
		compareTo = lselIndex;
	
	if(index == compareTo)
return "sel_ix";





	else if(index > compareTo)
		return "bot_ix";
	else
		return "top_ix";
}

function indexObj(symbol,value,change,pctchange,volume)
{
	this.symbol = symbol;
	this.value= value;
	this.change = change;
	this.pctchange = pctchange;
	this.volume = volume;
}

function setIndexInfo(symbol,value,change,pctchange,volume)
{
	for(i=0;i<10;i++)
	{
		if(ordIndexes[i]==symbol)
			break;
	}
	indexObjs[i] = new indexObj(symbol,value,change,pctchange,volume);
}


function displayIndex(symbol,value,change,pctchange,volume)
{
	cleanName = cleanIndexName(symbol);
	if(symbol=="DJIA")
	{
		document.write('</div><div id="other_indices">');//start bottom chart div
	}
	
	document.write('<div id="'+cleanName+'" class="'+getIndexClass(symbol)+'" onclick="reload_chart(\''+symbol+'\')">');
	document.write('<span class="container_ix">');
	document.write('<span class="index_ix">'+symbol.replace("-"," ")+'</span>');
	document.write('<span class="value_ix">'+value+'</span>');
	document.write('<span class="change_ix">');
	if(change!="N/A")
	{
		change = parseFloat(change);
		if(change>0)
		{
			color = "green";
			arrow = "greenarrowsmall-index.gif";
		}
		else if(change<0)
		{
			color = "red";
			arrow = "redarrowsmall-index.gif";
		}
		else
		{	//unch
			color = "";
			arrow = "spacer.gif";
		}
	}
	else
	{
		color = "";
		arrow = "spacer.gif";
	}

	document.write('<span class="'+color+' num_ix">'+change+'</span>&nbsp;');
	document.write('<span class="img_ix"><img src="http://content.nasdaq.com/images/'+arrow+'" alt="" /></span>&nbsp;');
    document.write('<span class="'+color+' percent_ix">'+pctchange+'%</span>');

	document.write('</span></span>');//close change and container
	
	if(symbol==upperselected)
	{
		document.write('<img class="chart_ix" src="'+topGraphUrl+'" height="100" width="230" alt="" />');
		$("#nasdaqVolume").text(volume);
	}
	else if(symbol==lowerselected)
		document.write('<img class="chart_ix" src="'+botGraphUrl+'" height="100" width="230" alt="" />');
	
	document.write('</div>');
}

function displayIndexes()
{
	document.write('<div id="nasdaq_indices">');
	index = indexObjs[0];
	displayIndex(index.symbol, index.value, index.change, index.pctchange, index.volume);//NASDAQ
	index = indexObjs[1];
	displayIndex(index.symbol, index.value, index.change, index.pctchange, index.volume);//NASDAQ-100
	index = indexObjs[2];
	displayIndex(index.symbol, index.value, index.change, index.pctchange, index.volume);//NASDAQ-100 PMI
	index = indexObjs[3];
	displayIndex(index.symbol, index.value, index.change, index.pctchange, index.volume);//NASDAQ-100 AHI
	index = indexObjs[4];
	displayIndex(index.symbol, index.value, index.change, index.pctchange, index.volume);//DJIA
	index = indexObjs[5];
	displayIndex(index.symbol, index.value, index.change, index.pctchange, index.volume);//S&P 500
	index = indexObjs[7];
	displayIndex(index.symbol, index.value, index.change, index.pctchange, index.volume);//Russell 2000
	
	//last row
	document.write('<div onclick="" class="bot_ix" id="moreindices">'
	+'<span class="container_ix">'
	+'<span class="more_ix">'
	+'<span class="more_ix_head"><a href="http://quotes.nasdaq.com/aspx/marketindices.aspx">More Indices...</a></span>'
	+'<span><a href="http://quotes.nasdaq.com/aspx/marketindices.aspx">Market</a></span>|'
	+'<span><a href="http://quotes.nasdaq.com/aspx/sectorindices.aspx">Sector</a></span>|'
	+'<span><a href="http://quotes.nasdaq.com/asp/GlobalIndices_World.asp ">Global</a></span>'
	+'</span></span></div>');

	document.write('</div>');
}

function reload_chart(selected)
{
	if(!processing)
	{
		processing = true;
		if(selected == "NASDAQ" || selected == "NASDAQ-100" || selected == "NASDAQ-100 PMI" || selected == "NASDAQ-100 AHI")
		{
			loadingupper = true;
			upperselected = selected;
			updating = cleanIndexName(upperselected);
			index = getIndexIndex(upperselected);
			holder = "nasdaq_indices";
		}						
		else
		{
			loadinglower = true;
			lowerselected = selected;
			updating = cleanIndexName(lowerselected);
			index = getIndexIndex(lowerselected);
			holder = "other_indices";
		}
				
		$("#"+holder)
			.children("div")
				.filter("#"+updating)//add loading image
					.children("img")
						.remove()
					.end()
					.append('<img src="http://www.nasdaq.com/images/ajax-loading.gif" class="chart_ix" border="0" style="position:absolute; top:35px; right:100px; height:32px;width:32px;" alt=""/>')
				.end()
				.filter("div:lt("+index+")")//change classes which are above it
					.attr("class","top_ix")
				.end()
				.filter("div:gt("+index+")")//change classes below it
					.attr("class","bot_ix")
				.end()
				.filter("div:eq("+index+")")//select it
					.attr("class","sel_ix");
		
		//$("#H2_1").text(selected);
		displayValue = selected.replace("&","amp");//& switched to 'amp' to use this string as a querystring parameter
		var dataframe = $("#indexdataframeholder");
		dataframe.children("#indexdataframe").remove();
		dataframe.append('<iframe name="indexdataframe" id="indexdataframe" frameborder="0" width="0" height="0" scrolling="no" src="../includes/indexdata.aspx?selected='+displayValue+'"></iframe>');
	}
}


function setIndexData(newvalue,newchange,newpctchange,imgurl,volume)
{
	setTimeout("writeIndexData('"+newvalue+"','"+newchange+"','"+newpctchange+"','"+imgurl+"','"+volume+"')",500);
}


function writeIndexData(newvalue,newchange,newpctchange,imgurl,volume)
{
	
	
	if(newchange!="N/A")
	{	
		newchange = parseFloat(newchange);
		if(newchange>0)
		{
			color="green";
			arrow="greenarrowsmall-index.gif";
		}
		else if(newchange<0)
		{
			color="red";
			arrow="redarrowsmall-index.gif";
		}
		else
		{
			color="";
			arrow="spacer.gif";
		}
	}
	else
	{
		color="";
		arrow="spacer.gif";
	}
	

	if(loadingupper)
	{
		loadingupper = false;
		updating = cleanIndexName(upperselected);
		index = getIndexIndex(upperselected);
		holder = "nasdaq_indices";					
	}				
	else
	{
		loadinglower = false;
		updating = cleanIndexName(lowerselected);
		index = getIndexIndex(lowerselected);
		holder = "other_indices";
	}

				
	$("#"+holder)
		.children("#"+updating)//update with new values
				.children(".container_ix")
					.children(".value_ix")
						.text(newvalue)
						.next()
							.children(".num_ix")
								.attr("class",color+" num_ix")
								.text(newchange)
								.next()
									.children("img")
										.remove()
									.end()
									.append('<img src="http://content.nasdaq.com/images/'+arrow+'" alt="" />')
									.next()
										.attr("class",color+" percent_ix")
										.text(newpctchange+"%")
									.end()
								.end()									
							.end()
						.end()
					.end()
				.end()
				.children("img")
					.remove()
				.end()
				.append('<img src="'+imgurl+'" class="chart_ix" border="0" style="height: 100px; width: 230px;" alt="" />');
			

	//$("#nasdaqVolume").text(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;
	}
	}
}

function setSelRange(inputEl, selStart, selEnd) 
{  if (inputEl.setSelectionRange) 
   {
		inputEl.focus();   
		inputEl.setSelectionRange(selStart, selEnd);  
	} 
	else if 
	(inputEl.createTextRange) 
	{   
		var range = inputEl.createTextRange();   
		range.collapse(true);   
		range.moveEnd('character', selEnd);   
		range.moveStart('character', selStart);   
		range.select();  
	} 
}


//input box cursor, called after ads are loaded
function hpPlaceCursor()
{
	//document.getElementById("userinput").focus();//place the cursor in the input box after ads
	setSelRange(document.getElementById("userinput"), 0,0) 
}


//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";    
}

//google hints
function getRandomGoogleHints()
{
	var result;
	if(typeof googlehints != 'undefined')
	{
		var hints = googlehints.split(',');
		
		//get 3 random indexes between 0 and googlehints array size
		hintmax = hints.length;
		var index1 = Math.floor(Math.random() * hintmax);
		if(hints.length>1)
		{
			do
			{
				var index2 = Math.floor(Math.random() * hintmax);
			}
			while(index2==index1)
			
			if(hints.length>2)
			{	
				do
				{
					var index3 = Math.floor(Math.random() * hintmax);
				}
				while(index3==index2 || index3==index1)
				result = hints[index1].replace(/^\s*/, '').replace(/\s*$/, '')+","+hints[index2].replace(/^\s*/, '').replace(/\s*$/, '')+","+hints[index3].replace(/^\s*/, '').replace(/\s*$/, '');
			}
			else
				result = hints[index1].replace(/^\s*/, '').replace(/\s*$/, '')+","+hints[index2].replace(/^\s*/, '').replace(/\s*$/, '');
		}
		else
			result = hints[index1].replace(/^\s*/, '').replace(/\s*$/, '');
	}
	else
		result = "";

	return result;

}

function getId_HintModifier(Id)
{
	if((Math.floor(Math.random() * 2))<1)//randomly use no hints and append 'test-no-hints' to IDs
	{
		google_hints = '';
		Id = Id+",test-no-hints";
	}
	else
	{
		Id = Id+",test-hints";
	}
	return Id;
}


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;
}


