
function CheckInput(pageId) {
	var target = '';
	selected = '';
	arSymbols = '';
	bLookup = false;
	var urlre = /^http/;
	
	if(myPage=="companynewsstory")
		document.getElementById("quotepage").value = "companynews";//exception:news story page doesnt fit into nav, but has quotebox

	if(myPage=="companynewsstory")
		document.getElementById("quotepage").value = "companynews";//exception:news story page doesnt fit into nav, but has quotebox

	if (urlre.test(pageId)) 
	{
		var nasdaq100re = "http://www.nasdaq.com/quotedll/quote.dll?page=nasdaq100";
		var nasdaqf100re = "http://www.nasdaq.com/quotedll/quote.dll?page=nasdaqf100";
		var indure = "http://www.nasdaq.com/quotedll/quote.dll?page=indu";
	

		if(nasdaq100re == pageId)
		{
			window.location.href = pageId;
			return;
		}

		else if(nasdaqf100re == pageId)
		{
			window.location.href = pageId;
			return;
		}

		else if(indure == pageId)
		{
			window.location.href = pageId;
			return;
		}
			
	} 
	else
	{   
		if (document.getElementById("quotepage").value == 'NasdaqLastsale')
		{
			window.location.href = wwwURL + 'aspx/nasdaqlastsale.aspx?symbol=' + quoteBoxSymbolArray.join('&symbol=') + "&selected=" + quoteBoxSelectedSymbol;
			return;
		}
		else if (document.getElementById("quotepage").value == 'quick') 
		{
			window.location.href = wwwURL + 'aspx/flashquotes.aspx?symbol=' + quoteBoxSymbolArray.join('&symbol=') + "&selected=" + quoteBoxSelectedSymbol;
			//window.location.href = 'http://quotes.nasdaq.com/quotedll/quote.dll?mode=stock&page=quick&symbol=' + quoteBoxSymbolArray.join('&symbol=') + "&selected=" + quoteBoxSelectedSymbol;
			return;
		}
		else if (document.getElementById("quotepage").value == 'multi') 
		{
			window.location.href = 'http://quotes.nasdaq.com/aspx/InfoQuotes.aspx?symbol=' + quoteBoxSymbolArray.join('&symbol=') + "&selected=" + quoteBoxSelectedSymbol;
			return;
		}
		else if (document.getElementById("quotepage").value == 'summaryquote')
		{
			window.location.href = 'http://quotes.nasdaq.com/asp/SummaryQuote.asp?symbol=' + quoteBoxSymbolArray.join('&symbol=') + "&selected=" + quoteBoxSelectedSymbol;
			return;
		}
		else if (document.getElementById("quotepage").value == 'charting') 
		{
			
			if(myPage != "charting")
			{
				window.location.href = wwwURL + 'aspx/chartingbasics.aspx?symbol=' + quoteBoxSymbolArray.join('&symbol=') + "&selected=" + quoteBoxSelectedSymbol;
				return;
			}
			else
			{
				var chartingOptions="";
				//carry over user parameters
				if(document.quotenav.intraday.value!="")
					chartingOptions += "&intraday="+document.quotenav.intraday.value;

				if(document.quotenav.timeframe.value!="")
					chartingOptions += "&timeframe="+document.quotenav.timeframe.value;

				if(document.quotenav.charttype.value!="")
					chartingOptions += "&charttype="+document.quotenav.charttype.value;
	
				if(document.quotenav.splits.value!="")
					chartingOptions += "&splits="+document.quotenav.splits.value;

				if(document.quotenav.comparison.value!="")
					chartingOptions += "&comparison="+document.quotenav.comparison.value;

				if(document.quotenav.movingaverage.value!="")
					chartingOptions += "&movingaverage="+document.quotenav.movingaverage.value;

				if(document.quotenav.lowerstudy.value!="")
					chartingOptions += "&lowerstudy="+document.quotenav.lowerstudy.value

				window.location.href = wwwURL + 'aspx/chartingbasics.aspx?symbol=' + quoteBoxSymbolArray.join('&symbol=') + "&selected=" + quoteBoxSelectedSymbol + chartingOptions;
				return;
			}
		}
		else if(document.getElementById("quotepage").value == 'dynamic_charting')
		{
			window.location.href = wwwURL + 'aspx/dynamic_charting.aspx?symbol=' + quoteBoxSymbolArray.join('&symbol=') + "&selected=" + quoteBoxSelectedSymbol;
			return;
		}
		else if (document.getElementById("quotepage").value == 'redpage') 
		{
			window.location.href = wwwURL + 'aspx/revenueepssummary.aspx?symbol=' + quoteBoxSymbolArray.join('&symbol=') + "&selected=" + quoteBoxSelectedSymbol;
			return;
		}
		else if (document.getElementById("quotepage").value == 'full')
		{
			window.location.href = wwwURL + 'asp/ExtendFund.asp?symbol=' + quoteBoxSymbolArray.join('&symbol=') + "&selected=" + quoteBoxSelectedSymbol;
			return;
		}
		else if (document.getElementById("quotepage").value == 'competitor')
		{
			window.location.href = quoteURL + 'screening/viewcompetitors.asp?symbol=' + quoteBoxSymbolArray.join('&symbol=') + "&selected=" + quoteBoxSelectedSymbol;
			return;
		}
		else if (document.getElementById("quotepage").value == 'short') 
		{
			window.location.href = wwwURL + 'aspxcontent/shortinterests.aspx?symbol=' + quoteBoxSymbolArray.join('&symbol=') + "&selected=" + quoteBoxSelectedSymbol;
			return;
		}
		else if (document.getElementById("quotepage").value == 'news')
		{
			window.location.href = wwwURL + 'asp/quotes_news.asp?symbol=' + quoteBoxSymbolArray.join('&symbol=') + "&selected=" + quoteBoxSelectedSymbol;
			return;
		}
		else if (document.getElementById("quotepage").value == 'companynews')
		{
			window.location.href = wwwURL + 'aspxcontent/newsheadlines.aspx?symbol=' + quoteBoxSymbolArray.join('&symbol=') + "&selected=" + quoteBoxSelectedSymbol;
			return;
		}
		else if (document.getElementById("quotepage").value == 'companypressrelease')
		{
			window.location.href = wwwURL + 'aspxcontent/newsheadlines.aspx?symbol=' + quoteBoxSymbolArray.join('&symbol=') + "&selected=" + quoteBoxSelectedSymbol + "&SourceCode=PMZ";
			return;
		}
		else if (document.getElementById("quotepage").value == 'companynewsthestreet')
		{
			window.location.href = wwwURL + 'aspxcontent/newsheadlines.aspx?symbol=' + quoteBoxSymbolArray.join('&symbol=') + "&selected=" + quoteBoxSelectedSymbol + "&SourceCode=TSTRT";
			return;
		}else if (document.getElementById("quotepage").value == 'companynewsthefool')
		{
			window.location.href = wwwURL + 'aspxcontent/newsheadlines.aspx?symbol=' + quoteBoxSymbolArray.join('&symbol=') + "&selected=" + quoteBoxSelectedSymbol + "&SourceCode=MFOOL";
			return;
		}		
		else if (document.getElementById("quotepage").value == 'analystinfo')
		{
			window.location.href = earningsURL + 'earnings/analyst_summary.asp?symbol=' + quoteBoxSymbolArray.join('&symbol=') + "&selected=" + quoteBoxSelectedSymbol;
			return;			
		}
		else if (document.getElementById("quotepage").value == 'stockreports')
		{
			window.location.href = wwwURL + 'asp/quotes_reports.asp?symbol=' + quoteBoxSymbolArray.join('&symbol=') + "&selected=" + quoteBoxSelectedSymbol;
			return;
		}
		else if (document.getElementById("quotepage").value == 'annualrpt') 
		{
			window.location.href = wwwURL + 'asp/quotesannualreportlink.asp?symbol=' + quoteBoxSymbolArray.join('&symbol=') + "&selected=" + quoteBoxSelectedSymbol;
			return;
		}
		// filings
		else if (document.getElementById("quotepage").value == 'holdingssummary')
		{
			window.location.href = earningsURL + 'asp/holdings.asp?symbol=' + quoteBoxSymbolArray.join('&symbol=') + "&selected=" + quoteBoxSelectedSymbol;
			return;
		}
		else if (document.getElementById("quotepage").value == 'holdings') 
		{
			window.location.href = earningsURL + 'asp/holdings.asp?symbol=' + quoteBoxSymbolArray.join('&symbol=') + "&selected=" + quoteBoxSelectedSymbol + "&FormType=Institutional";
			return;
		}
		else if (document.getElementById("quotepage").value == 'insiderform4')
		{
			window.location.href = earningsURL + 'asp/holdings.asp?symbol=' + quoteBoxSymbolArray.join('&symbol=') + "&selected=" + quoteBoxSelectedSymbol + "&FormType=form4";
			return;
		}
		else if (document.getElementById("quotepage").value == 'insiderform144')
		{
			window.location.href = earningsURL + 'asp/holdings.asp?symbol=' + quoteBoxSymbolArray.join('&symbol=') + "&selected=" + quoteBoxSelectedSymbol + "&FormType=form144";
			return;
		}
		else if (document.getElementById("quotepage").value == 'companyfilings' || document.getElementById("quotepage").value == 'filings')
		{
			window.location.href = earningsURL + 'asp/quotes_sec.asp?symbol=' + quoteBoxSymbolArray.join('&symbol=') + "&selected=" + quoteBoxSelectedSymbol;
			return;
		}
		else if (document.getElementById("quotepage").value == 'options')
		{
			window.location.href = quoteURL + 'aspxcontent/options.aspx?symbol=' + quoteBoxSymbolArray.join('&symbol=') + "&selected=" + quoteBoxSelectedSymbol;
			return;
		}
		else if (document.getElementById("quotepage").value == 'stockconsultant') 
		{
			window.location.href = wwwURL + 'asp/stock_consultant.asp?symbol=' + quoteBoxSymbolArray.join('&symbol=') + "&selected=" + quoteBoxSelectedSymbol;
			return;
	    }
		else if (document.getElementById("quotepage").value == 'stockcomparison') 
		{
			window.location.href = wwwURL + "/aspx/stock-comparison.aspx?symbol="+quoteBoxSelectedSymbol+"&selected="+quoteBoxSelectedSymbol;
			return;
	    }
		else if (document.getElementById("quotepage").value == 'guruanalysis')
		{
			window.location.href = wwwURL + 'asp/guruanalysis.asp?symbol=' + quoteBoxSymbolArray.join('&symbol=') + "&selected=" + quoteBoxSelectedSymbol;
			return;
		}
	    else if (document.getElementById("quotepage").value == 'afterhours')
		{
			if(quoteBoxNumSymbols>1)
				window.location.href = quoteURL + 'aspxcontent/ExtendedTradingTrades.aspx?selected=' + quoteBoxSelectedSymbol + '&mkttype=after&symbol=' + quoteBoxSymbolArray.join('&symbol=');
			else
				window.location.href = quoteURL + 'aspxcontent/ExtendedTradingTrades.aspx?selected=' + quoteBoxSelectedSymbol + '&mkttype=after';
			return;
		}
		else if (document.getElementById("quotepage").value == 'premarket') 
		{
			if(quoteBoxNumSymbols>1)
				window.location.href = quoteURL + 'aspxcontent/ExtendedTradingTrades.aspx?selected=' + quoteBoxSelectedSymbol + '&mkttype=pre&symbol=' + quoteBoxSymbolArray.join('&symbol=');
			else
				window.location.href = quoteURL + 'aspxcontent/ExtendedTradingTrades.aspx?selected=' + quoteBoxSelectedSymbol + '&mkttype=pre';
			return;
	    } 
		else if (document.getElementById("quotepage").value == 'afterhourscharts') 
		{
			window.location.href = quoteURL + 'aspxcontent/ExtendedTradingCharts.aspx?mkttype=after&symbol=' + quoteBoxSymbolArray.join('&symbol=') + "&selected=" + quoteBoxSelectedSymbol;
			return;
	    }
	 	else if (document.getElementById("quotepage").value == 'premarketcharts') 
		{
	        window.location.href = quoteURL + 'aspxcontent/ExtendedTradingCharts.aspx?mkttype=pre&symbol=' + quoteBoxSymbolArray.join('&symbol=') + "&selected=" + quoteBoxSelectedSymbol;
			return;
        }
			// options pages
		else if (document.getElementById("quotepage").value == 'optionquick') 
		{
	        window.location.href = quoteURL + 'aspxcontent/OptionFlashQuotes.aspx?symbol=' + quoteBoxSymbolArray.join('&symbol=') + "&selected=" + quoteBoxSelectedSymbol;
			return;
        }
		else if (document.getElementById("quotepage").value == 'optionmulti') 
		{
	        window.location.href = quoteURL + 'aspxcontent/OptionInfoQuotes.aspx?symbol=' + quoteBoxSymbolArray.join('&symbol=') + "&selected=" + quoteBoxSelectedSymbol;
			return;
        }
		
			// funds pages
		else if (document.getElementById("quotepage").value == 'quickmutual') 
		{
	        window.location.href = wwwURL + 'aspx/mutual-fund-flashquote.aspx?symbol=' + quoteBoxSymbolArray.join('&symbol=') + "&selected=" + quoteBoxSelectedSymbol;
			return;
        }
		else if (document.getElementById("quotepage").value == 'multimutual') 
		{
	        window.location.href = wwwURL + 'aspx/mutual-fund-quote.aspx?symbol=' + quoteBoxSymbolArray.join('&symbol=') + "&selected=" + quoteBoxSelectedSymbol;
			return;
        }
		else if (document.getElementById("quotepage").value == 'chartingfunds') 
		{
			if(myPage != "chartingfunds")
			{
				window.location.href = wwwURL + 'aspx/mutual-fund-chart.aspx?symbol=' + quoteBoxSymbolArray.join('&symbol=') + "&selected=" + quoteBoxSelectedSymbol;
				return;
			}
			else
			{
				var chartingOptions="";
				//carry over user parameters
				if(document.quotenav.intraday.value!="")
					chartingOptions += "&intraday="+document.quotenav.intraday.value;

				if(document.quotenav.timeframe.value!="")
					chartingOptions += "&timeframe="+document.quotenav.timeframe.value;

				if(document.quotenav.charttype.value!="")
					chartingOptions += "&charttype="+document.quotenav.charttype.value;
	
				if(document.quotenav.splits.value!="")
					chartingOptions += "&splits="+document.quotenav.splits.value;

				if(document.quotenav.comparison.value!="")
					chartingOptions += "&comparison="+document.quotenav.comparison.value;

				if(document.quotenav.movingaverage.value!="")
					chartingOptions += "&movingaverage="+document.quotenav.movingaverage.value;

				if(document.quotenav.lowerstudy.value!="")
					chartingOptions += "&lowerstudy="+document.quotenav.lowerstudy.value

				window.location.href = wwwURL + 'asp/charting_mutual.asp?symbol=' + quoteBoxSymbolArray.join('&symbol=') + "&selected=" + quoteBoxSelectedSymbol + chartingOptions;
				return;
			}
	        
			return;
        }
		else if (document.getElementById("quotepage").value == 'profilemutual') 
		{
	        window.location.href = wwwURL + 'reference/fundprofile.stm?symbol=' + quoteBoxSymbolArray.join('&symbol=') + "&selected=" + quoteBoxSelectedSymbol;
			return;
        }

				
	}
}

function editSymbols()
{
		if (myPage == 'fundamentalcharts' || myPage == 'stockconsultant')
				document.quotenav.target = 'ParentWin';
			else
				document.quotenav.target = '_parent';

		for (i=0;i<quoteBoxNumSymbols;i++)
		{
			//move selected to the first entry in the array
			if(quoteBoxSymbolArray[i]==quoteBoxSelectedSymbol)
			{
				if(i==0)
					break;
				//store selected
				temp = quoteBoxSymbolArray[i];
				//swap
				quoteBoxSymbolArray[i] = quoteBoxSymbolArray[0];
				quoteBoxSymbolArray[0] = temp;
				break;
			}
		}
		page = "page="+document.getElementById("quotepage").value; //add the page parameter
		path = "&pathname="+window.location.pathname; //add the pathname parameter
		window.location.href = quoteURL + 'aspx/masterdataentry.aspx?'+page+path+'&symbol=' + quoteBoxSymbolArray.join('&symbol=') + "&selected=" + quoteBoxSelectedSymbol;
		if(myPage=='fundamentalcharts' || myPage == 'stockconsultant')window.parent.close();
}

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 readResults(){
	readStockResults();
	return;
}

function readStockResults(){
		var result = window.frames["validateSymbolForm"].document.body.innerHTML.split('|');
		// [0] - symbol
		// [1] - is valid symbol?
		// [2] - is new symbol?
		// [3] - new symbol
		// [4] - change date.
	
	if(validationIndex == -1)//doing add symbol validation
	{
		if(result[1].toLowerCase()=='true'){
				displaySymbolInfo(result[0]);
		} else if(result[2].toLowerCase()=='true'){
				alert(result[0] + ' is changed to ' + result[3] + ' on ' + result[4]);
				displaySymbolInfo(result[3]);
		} else {
				alert(result[0] + ' is Not a Valid Symbol');
				document.frmAddASymbol.symbol.value = '';
				document.frmAddASymbol.symbol.focus();
		}
	}
	else 
	{
		if(result[1].toLowerCase()=='true'){
				persistValidation(validationIndex+1);
		} else if(result[2].toLowerCase()=='true'){
				alert(result[0] + ' is changed to ' + result[3] + ' on ' + result[4]);
				persistValidation(validationIndex+1);
		} else {
				alert(result[0] + ' is Not a Valid Symbol'); //this symbol is invalid
				quoteBoxSymbolArray.splice(validationIndex,1);//remove from the array
				if(result[0] == quoteBoxSelectedSymbol) //is this the selected?
				{
					if(quoteBoxSymbolArray.length>0)
					{
						validationSelectedInvalid = true;
						if(validationIndex < quoteBoxSymbolArray.length-1) 
							quoteBoxSelectedSymbol = quoteBoxSymbolArray[validationIndex]; //set selected to the next symbol if there is one
						else
							quoteBoxSelectedSymbol = quoteBoxSymbolArray[0]; //otherwise set selected to the first valid symbol
					}
				}
				persistValidation(validationIndex); //go on with list
		}
	}
		
	 return;
}

function displaySymbolInfo(symbol)
{
		if(quoteBoxNumSymbols==25)
		{
				alert('Can not add more than 25 symbols. Please use Edit Symbol List to edit your symbol list.');
				return false;
		}
				
		//set new symbol as selected and add to symbol array new option at the end
		quoteBoxSelectedSymbol = symbol;
		quoteBoxSymbolArray.unshift(symbol); //add to first element in array
		quoteBoxNumSymbols+=1;
		CheckInput();
		//alert(symbol + " has been added to your symbol list");
}

function qbgetIndex(symbol)
{
	for (var t=0;t<quoteBoxSymbolArray.length;t++)
	{
		if (quoteBoxSymbolArray[t] == symbol)
			return t;
	
	}
	return -1;
}


function isDuplicate(newSymbol)
{
	newSymbol = newSymbol.toUpperCase();
	for (var t=0;t<quoteBoxSymbolArray.length;t++)
	{
		if (quoteBoxSymbolArray[t] == newSymbol)
			return true;
	
	}
	return false;
}


function selectSymbol(sym)
{
	quoteBoxSelectedSymbol = sym;
	CheckInput();
}


function trimSymbol(str){
    return str.replace(/^\s*/, '').replace(/\s*$/, '');
}


function validateSymbol()
{
	displaySymbolInfo(document.frmAddASymbol.symbol.value.toUpperCase());
}
/*
function validateSymbol(){
		var url;
		var newSymbol = document.frmAddASymbol.symbol.value.toUpperCase();
		var str;
		newSymbol = trimSymbol(newSymbol);
		if (newSymbol=='') 
		{
            alert('Please enter a symbol and reselect the add button');
			document.frmAddASymbol.symbol.value = '';
			document.frmAddASymbol.symbol.focus();
   		   return false;
        }
		if(isDuplicate(newSymbol)) 
		{
			selectSymbol(newSymbol)
		}
		else
		{
			url = quoteURL + 'aspx/ValidateSymbol.aspx?mode=stock';
			url += '&selected=' + newSymbol;

			document.getElementById("validateSymbolForm").src = url;//calls readResults()
		}

		return false;
}
*/

function CheckInput2(navigation) 
{
	var SymbolLookup = quoteURL + 'aspx/NasdaqSymLookup.aspx?parentLocation=window.opener.document.quotenav.userinput.value';
	
	if (navigation == 'symbollookup')	{
				//quotenav.action = SymbolLookup;
     
      open_new_window(SymbolLookup, 380, 340, false,true, false);
      
		
	}
     
}

//called from NasdaqSymLookup.asp
function AddSymbol(symbol) 
{
	var editsymbolactive = false;
	if(typeof modalexists != 'undefined')
	{
		if(modalexists == true)
			if(currentWindowHandle == "symbol_lookup_modal_box")
				popmodal();
			if(currentWindowHandle == "edit_symbol_modal_box")
				editsymbolactive = true;
				
	}

	if(!editsymbolactive)
	{	
		if(isDuplicate(symbol))
		{
			selectSymbol(symbol);
		}
		else
		{
			displaySymbolInfo(symbol);
		}
	}
	else
	{
		document.getElementById("modalinput").focus();
		document.getElementById("modalinput").value = symbol+" "+document.getElementById("modalinput").value;
		//alert(symbol + " has been added to your symbol list");
	}
}

function ShowELSSymbol(symbol)//this is for euro symbols being added
{
	document.location.href = "http://www.nasdaq.com/aspx/els.aspx?selected="+symbol;
}

function initWidget()
{
	selectPage();
	loadSymbols();
	//validateSymbols();
	initSymbolNav();
	//updateCookie();
	//updateCookieList(quoteBoxSymbolArray);
	return;
}

function selectPage()
{
	var currentPage;
	var newsIndex;
	for(var i=0;i<document.getElementById("quotepage").length;i++)
	{
		currentPage = document.getElementById("quotepage").options[i].value; 
		if(currentPage == myPage)
		{
			document.getElementById("quotepage").options[i].selected = true;
			document.getElementById(currentPage+"link").className = "qn_on";
			return;
		}
		if(currentPage == "companynews")
			newsIndex = i;
	}
	//misc. news pages
	if(myPage == 'companynewsthestreet' || myPage == 'companynewsthefool')
	{
		document.getElementById("quotepage").options[newsIndex].selected = true;
		if(myPage == 'companynewsthestreet')
			document.getElementById("companynewsthestreetlink").className = "qn_on";
		else
			document.getElementById("companynewsthethefoollink").className = "qn_on";
	}
	return;
}

var validationIndex=-1;
var validationSelectedInvalid = false;

function validateSymbols()
{
	persistValidation(0);
}

function persistValidation(index)
{
	if(quoteBoxSymbolArray.length>0)
	{
		if(index<quoteBoxSymbolArray.length)//are we still validating?
		{
			validationIndex = index;
			validateInputSymbol(quoteBoxSymbolArray[index]);
		}
		else //done
		{
			quoteBoxNumSymbols = quoteBoxSymbolArray.length; //number of valid symbols
			if(validationSelectedInvalid) //selected symbol was invalid
				validationIndex = -2
			else
				validationIndex = -1;//everything went smoothly
		}
	}
	else //no valid symbols were found
	{
		validationIndex = -3;
	}
}

function validateInputSymbol(symbol)
{
	var url;
	var str;
	newSymbol = trimSymbol(symbol);
	url = quoteURL + 'aspx/ValidateSymbol.aspx?mode=stock';
	url += '&selected=' + symbol;
	document.getElementById("validateSymbolForm").src = url;//calls readResults()
}

var validationTimerHandle;

function initSymbolNav()
{
	var selectedIndex;
	var carouselscrollamount = 1;
    var carouselstartindex = 0;

	if(validationIndex==-1)//all symbols validated, invalid ones removed, selected symbol is valid
	{
		if(quoteBoxSymbolArray.length>0)
		{
			if(quoteBoxSymbolArray.length>13)//set up carousel
			{
				selectedIndex = qbgetIndex(quoteBoxSelectedSymbol);
				if(selectedIndex>12)
					carouselstartindex = selectedIndex - 11;
				if(quoteBoxSymbolArray.length>17)
					carouselscrollamount = 3;
				jQuery(document).ready(function() {
    					jQuery('#mycarousel').jcarousel(
					{
							start:  carouselstartindex,
       						scroll: carouselscrollamount,
	       					size: quoteBoxSymbolArray.length,
						itemLoadCallback: {onBeforeAnimation: populateSymbolNav}
           				}
					);
					});
			}
			else //less than 14 - not using carousel add a modified placeholer
			{
				var build = '<div class="jcarousel-skin-tango">' +
					    '<div class="jcarousel-container jcarousel-container-horizontal">' +
						'<div style="display: block" class="jcarousel-prev jcarousel-prev-horizontal jcarousel-prev-disabled jcarousel-prev-disabled-horizontal"></div>' +
						'<div class="jcarousel-next jcarousel-next-horizontal jcarousel-next-disabled jcarousel-next-disabled-horizontal"></div>'+
					    '<div class="jcarousel-clip jcarousel-clip-horizontal">' +
					    '<ul class="jcarousel-list jcarousel-list-horizontal" id="mycarousel" style="width:800px">';
				var navSymbolString="";
				for(i=0;i<quoteBoxSymbolArray.length;i++)
				{
					if(quoteBoxSymbolArray[i]!=quoteBoxSelectedSymbol)
						navSymbolString+='<li class="jcarousel-item jcarousel-item-horizontal jcarousel-item-1 jcarousel-item-1-horizontal"><span><a href="javascript:loadselected(\''+quoteBoxSymbolArray[i]+'\');">'+quoteBoxSymbolArray[i]+'</a></span></li>';	
					else
						navSymbolString+='<li class="jcarousel-item jcarousel-item-horizontal jcarousel-item-1 jcarousel-item-1-horizontal"><span><a class="qn_ontab" href="javascript:loadselected(\''+quoteBoxSymbolArray[i]+'\');">'+quoteBoxSymbolArray[i]+'</a></span></li>';
				}
				navSymbolString+='</ul>';
				document.getElementById("quotesnav_symbols").innerHTML = build + navSymbolString;
			}
		}
				
	}
	else if(validationIndex==-2)//selected symbol was found to be invalid, reload with a valid selected symbol
	{
		CheckInput(); //reload the page
	}
	else if(validationIndex==-3)//no valid symbols were found in the list, reload with a default symbol
	{
		alert("No Valid Symbols Entered."); 
		quoteBoxSymbolArray[0] = "NDAQ";
		quoteBoxSelectedSymbol = "NDAQ";
		quoteBoxNumSymbols = 1;
		CheckInput(); //reload the page
	}		
	else //still validating symbols retry in a little while
		validationTimerHandle=setTimeout("initSymbolNav()",500);
}

function populateSymbolNav(carousel, state)
{
	for(i=0;i<quoteBoxSymbolArray.length;i++)
	{
		if(quoteBoxSymbolArray[i]!=quoteBoxSelectedSymbol)
			carousel.add(i,'<span><a href="javascript:loadselected(\''+quoteBoxSymbolArray[i]+'\');">'+quoteBoxSymbolArray[i]+'</a></span>');
		else
			carousel.add(i,'<span><a class="qn_ontab" href="javascript:loadselected(\''+quoteBoxSymbolArray[i]+'\');">'+quoteBoxSymbolArray[i]+'</a></span>');
	}
}


function loadselected(symbol)
{
	quoteBoxSelectedSymbol = symbol;
	if(myPage=="companynewsstory")
		myPage = "companynews";//exception:news story page doesnt fit into nav, but has quotebox
	loadPage(myPage);
}
		

var quoteBoxSelectedSymbol; //selected symbol
var quoteBoxSymbolArray = new Array(0); //symbol list
var quoteBoxNumSymbols;
var removedCookieSyms = new Array();//removed list

function loadSymbols()
{
		
			var symbol;
			var query = window.location.search.substring(1);
			var j = 0;
			var params = query.split('&');
			var current_num = 0;
			var bHasASymbol = false;
			var bHasASelected = false;
			var sel_sym_number = 0;

			for (var i=0;i<params.length;i++)
			{
				symbol = params[i].split('=');
				if (symbol[0].toLowerCase() == 'selected' && symbol[1] != null && symbol[1].length > 0)
				{
					bHasASelected = true;
					selected = symbol[1].toUpperCase();
					quoteBoxSelectedSymbol = trimTick(selected);
				}
				else if (symbol[0].toLowerCase() == 'symbol' && symbol[1] != null && symbol[1].length > 0 && j < 25)
				{
					if (!isDuplicate(symbol[1]))
					{
						bHasASymbol = true;
						symbol[1] = unescape(trimTick(symbol[1]));
						quoteBoxSymbolArray[j] = symbol[1].toUpperCase();
						j++;
					}
				}
				else if (symbol[0].toLowerCase() == 'formtype' && myPage == 'filings')
				{
						var holdingspage;
						if(symbol[1].toLowerCase() == 'form4')
								holdingspage = 'insiderform4';
						else if(symbol[1].toLowerCase() == 'form144')
								holdingspage = 'insiderform144';
						else if(symbol[1].toLowerCase() == 'institutional')
								holdingspage = 'holdings';
						else
								holdingspage = 'holdingssummary';

						for(var k=0;i<document.getElementById("quotepage").length;k++)
						{
							if(document.getElementById("quotepage").options[k].value == holdingspage)
							{
								document.getElementById("quotepage").options[k].selected = true;
								break;
							}
						}
				}
				else if (symbol[0].toLowerCase() =='mkttype' && myPage =='afterhours')
				{
					if (symbol[1].toLowerCase() == 'after')
					{
						document.quotenav.mkttype.value='after';
					}else
					{
						document.quotenav.mkttype.value='pre'
					}
				}
				else if (symbol[0].toLowerCase() == 'intraday' && symbol[1] != null && symbol[1].length > 0)
				{
						document.quotenav.intraday.value=symbol[1];
				}
				else if (symbol[0].toLowerCase() == 'timeframe' && symbol[1] != null && symbol[1].length > 0)
				{
						document.quotenav.timeframe.value=symbol[1];
				}
				else if (symbol[0].toLowerCase() == 'charttype' && symbol[1] != null && symbol[1].length > 0)
				{
						document.quotenav.charttype.value=symbol[1];
				}
				else if (symbol[0].toLowerCase() == 'splits' && symbol[1] != null && symbol[1].length > 0)
				{
						document.quotenav.splits.value=symbol[1];
				}
				else if (symbol[0].toLowerCase() == 'earnings' && symbol[1] != null && symbol[1].length > 0)
				{
						document.quotenav.earnings.value=symbol[1];
				}
				else if (symbol[0].toLowerCase() == 'movingaverage' && symbol[1] != null && symbol[1].length > 0)
				{
						document.quotenav.movingaverage.value=symbol[1];
				}
				else if (symbol[0].toLowerCase() == 'lowerstudy' && symbol[1] != null && symbol[1].length > 0)
				{
						document.quotenav.lowerstudy.value=symbol[1];
				}
				else if (symbol[0].toLowerCase() == 'comparison' && symbol[1] != null && symbol[1].length > 0)
				{
						document.quotenav.comparison.value=symbol[1];
				}
				else if (symbol[0].toLowerCase() == 'index' && symbol[1] != null && symbol[1].length > 0)
				{
						document.quotenav.index.value=symbol[1];
				}
				else if (symbol[0].toLowerCase() == 'sel_sym_number')
						sel_sym_number = symbol[1];
				
			}

			if (!bHasASymbol && bHasASelected)//no symbols, only a selected; add selected as a symbol
			{
				quoteBoxSymbolArray[j] = quoteBoxSelectedSymbol;
			}
			
			quoteBoxNumSymbols = quoteBoxSymbolArray.length;
			return;
}

		function trimTick(tmpSym)
		{
			var	myLen = tmpSym.length;

			if (tmpSym.indexOf('`') > 0)
				tmpSym = tmpSym.substr(0, eval(myLen - 1));

			if (tmpSym.indexOf('%60') > 0)
				tmpSym = tmpSym.substr(0, eval(myLen - 3));

			return tmpSym;
		}


//this function overrides the default page's loadPage() function
//if we're on a quote page, navigation should take us to a 
//quote page, not data entry page

function loadPage(pageId)
{
		if(pageId == "After Hours Market")
		{
			document.getElementById("quotepage").value = "afterhours";
			quotenav.mkttype.value = 'after';
		}
		else if(pageId == "Pre-Market")
		{
			quotenav.mkttype.value = 'PRE';
			document.getElementById("quotepage").value = "premarket";
		}
		else if(pageId == "companyfilings")
		{
			document.getElementById("quotepage").value = "filings";
		}
		else 
			document.getElementById("quotepage").value = pageId;
		CheckInput(pageId);//pass through the page ID in case we're going to a static page
}

//*********edit symbol list modal functions
function editSymbolListModalBoxInit()
{
	var input =	document.getElementById("modalinput");
	input.focus();
	input.value = quoteBoxSymbolArray.join(" ")+" ";
}

function clearlist()
{
	var input =	document.getElementById("modalinput");
	input.focus();
	input.value = "";
	
}

function replaceComma(temp) 
{
				//return temp.replace(/,/g, ' ');

				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 trim(str){
	    return str.replace(/^\s*/, '').replace(/\s*$/, '');
	}

function gomodal()
{
	var re = /\s */;
	var sInput= document.getElementById("modalinput").value.toUpperCase();
	sInput = replaceComma(sInput);
	sInput = trim(sInput);
	if(sInput!="")
	{
		var arStrings = sInput.split(re);
				
		if (arStrings.length>25) 
		{
				alert('You may only choose up to 25 symbols. Please edit your list in the data entry box.');
				document.getElementById("modalinput").focus();
				return true;
		}		
		quoteBoxSelectedSymbol = arStrings[0];
		quoteBoxSymbolArray.splice(0,quoteBoxSymbolArray.length); //remove symbols from array

		for(i=0; i<arStrings.length;i++)
		{
			quoteBoxSymbolArray[i] = arStrings[i]; //add new symbols to the array
		}
		//validateSymbols();
        goModalNext();				
	}
	else
		document.getElementById("modalinput").focus();
}

function goModalNext()
{
	if(validationIndex==-1 || validationIndex==-2)
		CheckInput();
	else if(validationIndex==-3)
	{
		alert("No valid symbols entered. Please edit your list in the data entry box."); 
		document.getElementById("modalinput").focus();
	}
	else //still validating symbols retry in a little while
		validationTimerHandle = setTimeout("goModalNext()",500);
//if the first symbol is invalid, the page will automatically reload once validation is finished
}

//*************symbol lookup modal functions
function symbolLookupModalBoxinit(type)
{
	var frame = document.getElementById("msymbollookupframe");
	frame.style.visibility = "visible";
	frame.src = quoteURL + 'aspx/NasdaqSymLookup.aspx?mode='+type;
}
	

function updateCookie()
{
	var page = document.getElementById("quotepage").value;

	if(page=="NasdaqLastsale" || page=="quick")
		return;// flash quotes and real time already do this so exit

	var params = document.location.search.substring(1);
	var paramsList = params.split('&');
	var is_bareSymArray = new Array();
	var current, is_selectedSymbol, index=0;
	is_selectedSymbol = get_querystring_value("selected").toUpperCase();
	

	if(navigator.cookieEnabled)
	{

		for(i=0;i<paramsList.length;i++)
		{
			current = paramsList[i].split('=');
			if(current[0]=='symbol')
			{
				if(index<25)
				{
					is_bareSymArray[index] = current[1].toUpperCase();
					index++;
				}
			}
		}

		var total = is_bareSymArray.length;
	
		if(document.cookie.indexOf("userSymbolList=")!=-1 || document.cookie.indexOf("newquick=")!=-1)
		{
					
			var i,j,unique=true,duplicates=0,first=true;
			if(document.cookie.indexOf("userSymbolList=")!=-1)//new cookie present, this is priority
			{
				i = document.cookie.indexOf("userSymbolList=")+15;
				j = document.cookie.indexOf(";",i);
			}
			else //old cookie
			{
				i = document.cookie.indexOf("newquick=")+9;
				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));
			if(list.search("&")>-1) //multiple symbols are present and split to form an array
			{
				var symbols = list.split("&");
			}
			else //only one symbol present in cookie, create an array to process
			{
				var symbols = new Array(1);
				symbols[0]=list;
			}
			var count = 0,reTest;
			for(i=0;i<symbols.length;i++)
			{
				symbols[i]=symbols[i].toUpperCase();
				for(j=0;j<is_bareSymArray.length;j++)
				{
					if ( (is_bareSymArray[j]) && (is_bareSymArray[j] != ''))
					{
						if(is_bareSymArray[j].toUpperCase()==symbols[i]) //this is already entered in querystring
						{                           //duplicated symbols are removed from the cookie symbol list      
													//since all querystring symbols are added back at the end
							unique=false;
									
						 	if(list.search("&"+symbols[i]+"&")>-1) //matched symbol is located after first and before the last
							{
								list=list.replace("&"+symbols[i]+"&","&");
								//alert("replaced1");
							}
							else  
							{
								reTest = new RegExp("^"+symbols[i]+"&");
								if(list.search(reTest)>-1) //matched symbol is first in cookie
								{
									list=list.replace(reTest,"");
								}
								else
								{
									reTest = new RegExp("&"+symbols[i]+"$");
									if(list.search(reTest)>-1) //matched symbol is last in cookie
									{
										list=list.replace(reTest,"");
									}
									else  //symbol is only on in the list, clear it
									{
										list="";
									}
								}
							}
							break;
						}
					}
				}
				if(!unique)
					duplicates++;
					
				unique=true;
							
			}
					
			j = symbols.length - duplicates; //# of unique cookie symbols
			if((total+j)>25) //truncate list if > 25 total
			{	
				if(symbols.length>1)
				{
					j = total + j - 25;//total # to be removed
					for(i=0;i<j;i++)
					{
						last = list.lastIndexOf("&");
						if(last != -1)
							list=list.slice(0,last); //remove oldest symbol from list
						else
							list = ""; //only 1 symbol left and being removed so now old list is empty
					}
				}
				else
					list="";
					
			}

			for(j=is_bareSymArray.length-1;j>=0;j--) //build new list for cookie
			{
				if ( (is_bareSymArray[j]) && (is_bareSymArray[j] != ''))
				{
					for(i=0;i<=j;i++)
					{
						if ( (is_bareSymArray[i]) && (is_bareSymArray[i] != '') && (i!=j) && (is_bareSymArray[i].toUpperCase()==is_bareSymArray[j].toUpperCase() ) )
						{ //this symbol was duplicated by the user, avoid storing duplicates in cookie
							if(i<j)
								is_bareSymArray[j]="";
							else
								is_bareSymArray[i]="";
							break;
						}
					}
					if(is_bareSymArray[j]!="")
					{
						if(list!="")
							list = is_bareSymArray[j].toUpperCase().concat("&"+list);
						else
							list = is_bareSymArray[j].toUpperCase();
			    		}
				}		
			}
			var exdate=new Date();
			exdate.setDate(exdate.getDate()+1);//expires in two weeks

			document.cookie="userSymbolList="+list+";expires="+exdate+";path=/;domain=nasdaq.com";

		}
		else //cookies are enabled but nothing stored yet
		{
			var list="";
			var j,count;
			count=is_bareSymArray.length;
			if(count>0)
			{
				for(j=count-1;j>=0;j--)
				{
					if ( (is_bareSymArray[j]) && (is_bareSymArray[j] != ''))
					{
						if(list!="")
							list = is_bareSymArray[j].toUpperCase().concat("&"+list);
						else
							list = is_bareSymArray[j].toUpperCase();
					}
				}
			
			var exdate=new Date();
			exdate.setDate(exdate.getDate()+1);//expires in two weeks

			document.cookie="userSymbolList="+list+";expires="+exdate+";path=/;domain=nasdaq.com";
			//document.cookie="newquick="+list+";expires="+exdate+";path=/;domain=www.nasdaq.com";
			//store first list
			}
		}
					
	}//cookies not enabled
				
}

function updateCookieList(symbolList)
{
	var current, is_selectedSymbol, index=0;
	is_selectedSymbol = quoteBoxSelectedSymbol;	

	if(navigator.cookieEnabled)
	{

		var total = symbolList.length;
	
		if(document.cookie.indexOf("userSymbolList=")!=-1)
		{
					
			var i,j,unique=true,duplicates=0,first=true;
			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));
			if(list.search("&")>-1) //multiple symbols are present and split to form an array
			{
				var symbols = list.split("&");
			}
			else //only one symbol present in cookie, create an array to process
			{
				var symbols = new Array(1);
				symbols[0]=list;
			}
			var count = 0,reTest;
			for(i=0;i<symbols.length;i++)
			{
				symbols[i]=symbols[i].toUpperCase();
				for(j=0;j<total;j++)
				{
					if ( (symbolList[j]) && (symbolList[j] != ''))
					{
						if(symbolList[j].toUpperCase()==symbols[i]) //this is already entered in querystring
						{                           //duplicated symbols are removed from the cookie symbol list      
													//since all querystring symbols are added back at the end
							unique=false;
									
						 	if(list.search("&"+symbols[i]+"&")>-1) //matched symbol is located after first and before the last
							{
								list=list.replace("&"+symbols[i]+"&","&");
								//alert("replaced1");
							}
							else  
							{
								reTest = new RegExp("^"+symbols[i]+"&");
								if(list.search(reTest)>-1) //matched symbol is first in cookie
								{
									list=list.replace(reTest,"");
								}
								else
								{
									reTest = new RegExp("&"+symbols[i]+"$");
									if(list.search(reTest)>-1) //matched symbol is last in cookie
									{
										list=list.replace(reTest,"");
									}
									else  //symbol is only on in the list, clear it
									{
										list="";
									}
								}
							}
							break;
						}
					}
				}
				if(!unique)
					duplicates++;
					
				unique=true;
							
			}
					
			j = symbols.length - duplicates; //# of unique cookie symbols
			if((total+j)>25) //truncate list if > 25 total
			{	
				if(symbols.length>1)
				{
					j = total + j - 25;//total # to be removed
					for(i=0;i<j;i++)
					{
						last = list.lastIndexOf("&");
						if(last != -1)
						{
							removedCookieSyms[removedCookieSyms.length] = list.substr(last+1);//save off removed cookies for recently viewed
							list=list.slice(last); //remove oldest symbol from list
						}
						else
						{
							removedCookieSyms[removedCookieSyms.length] = list;
							list = ""; //only 1 symbol left and being removed so now old list is empty
							break;
						}
					}
				}
				else
					list="";
					
			}

			for(j=symbolList.length-1;j>=0;j--) //build new list for cookie
			{
				if ( (symbolList[j]) && (symbolList[j] != ''))
				{
					for(i=0;i<=j;i++)
					{
						if ( (symbolList[i]) && (symbolList[i] != '') && (i!=j) && (symbolList[i].toUpperCase()==symbolList[j].toUpperCase() ) )
						{ //this symbol was duplicated by the user, avoid storing duplicates in cookie
							if(i<j)
								symbolList[j]="";
							else
								symbolList[i]="";
							break;
						}
					}
					if(symbolList[j]!="")
					{
						if(list!="")
							list = symbolList[j].toUpperCase().concat("&"+list);
						else
							list = symbolList[j].toUpperCase();
			    	}
				}		
			}
			var exdate=new Date();
			exdate.setDate(exdate.getDate()+14);//expires in two weeks

			document.cookie="userSymbolList="+list+";expires="+exdate+";path=/;domain=nasdaq.com";

		}
		else //cookies are enabled but nothing stored yet
		{
			var list="";
			var j,count;
			count=symbolList.length;
			if(count>0)
			{
				for(j=count-1;j>=0;j--)
				{
					if ( (symbolList[j]) && (symbolList[j] != ''))
					{
						if(list!="")
							list = symbolList[j].toUpperCase().concat("&"+list);
						else
							list = symbolList[j].toUpperCase();
					}
				}
			
			var exdate=new Date();
			exdate.setDate(exdate.getDate()+14);//expires in two weeks

			document.cookie="userSymbolList="+list+";expires="+exdate+";path=/;domain=nasdaq.com";
			
			}
		}
					
	}//cookies not enabled
}

initWidget();
$(function(){$("#AddASymbol").autocomplete("../aspx/autocompletesearch.aspx",{minChars:2,maxItemsToShow:9,cacheLength:1,delay:50,onItemSelect:validateSymbol,extraParams:{sortBy:"symbol"}});});

