
var ff_start = new Array(
['','<br /><br />NEW VISITORS'],
['','<br /><br /><br /><br /><br /><br /><br /><br /><br />INVESTORS'],
['','<br /<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />ACTIVE TRADERS']
);

var ff_streetools = new Array(
['','CONTENTS'],
['/streetools/stock_quotes.aspx?click=menu','Stock Tools'],
['/streetools/options/option_montage.aspx?click=menu','Option Tools'],
['/streetools/charts.aspx?click=menu','Charts'],
['/streetools/symbol_news.aspx?click=menu','Ticker News'],
['/streetools/indicators/equity_oipcratio.aspx?click=menu','Indicators'],
['/streetools/market_tools/52week_hi_low.aspx?click=menu','Market Tools'],
['/streetools/centers/etf/etf.aspx?click=menu','ETF Center'],
['/streetools/centers/atc/atc.aspx?click=menu','Advanced Trading Center'],
['/personalfinance/calculators/index.aspx?click=menu','Personal Finance Calculators'],
['/personalfinance/brokers/index.aspx?click=menu','Broker Center']
);

var ff_markets = new Array(
['','CONTENTS'],
['/markets/stocks.aspx?click=menu','Stocks'],
['/markets/options.aspx?click=menu','Options'],
['/markets/commodities.aspx?click=menu','Commodities'],
['/markets/bonds.aspx?click=menu','Bonds'],
['/markets/etfs.aspx?click=menu','ETFs'],
['/markets/mutualfunds.aspx?click=menu','Mutual Funds'],
['/markets/currency.aspx?click=menu','Currency'],
['/markets/economy.aspx?click=menu','Economy']
);

var ff_marketbeat = new Array(
['','CONTENTS'],
['/commentary/index.aspx?click=menu#schaeffer','Schaeffer on Charts'],
['/commentary/index.aspx?click=menu#schaeffer','Schaeffer Commentary'],
['/commentary/index.aspx?click=menu#obs','Market Observations'],
['/commentary/dailycontrarian.aspx?click=menu','Daily Contrarian'],
['/commentary/optionbytes.aspx?click=menu','Schaeffer\'s Daily Market Blog'],
['/commentary/news.aspx?click=menu','Market News'],
['/commentary/market_recap.aspx?click=menu','Market Recap'],
['/commentary/discussionboard.aspx?click=menu','Discussion Board'],
['/commentary/rss.aspx?click=menu','RSS Feeds'],
['/commentary/podcasts/?click=menu','Audio &amp; Video']
);

var ff_pfinance = new Array(
['','CONTENTS'],
['/personalfinance/?click=menu','Main Index'],
['/personalfinance/taxes/?click=menu','Taxes'],
['/personalfinance/loans/?click=menu','Loans'],
['/personalfinance/insurance/?click=menu','Insurance'],
//['/personalfinance/autos/?click=menu','Autos'],
['/personalfinance/law/?click=menu','Law'],
//['/personalfinance/travel/?click=menu','Travel'],
['/personalfinance/careers/?click=menu','Careers'],
['/personalfinance/retirement/?click=menu','Retirement'],
['/personalfinance/brokers/index.aspx?click=menu','Brokers'],
['/personalfinance/calculators/?click=menu','Calculators']
);

var ff_sedge = new Array(
['','CONTENTS'],
['/edge/why_sir.aspx?click=menu','The Schaeffer Edge'],
['/edge/best_trades.aspx?click=menu','Best Trades'],
['/edge/testimonials.aspx?click=menu','Testimonials'],
['/edge/mediakit/bernie_bio.aspx?click=menu','About Bernie Schaeffer'],
['/edge/media_spotlight.aspx?click=jumpto','Media Spotlight']
);

var ff_su = new Array(
['','CONTENTS'],
['/schaeffersu/index.aspx?click=menu','Introduction'],
['/schaeffersu/basics/stocks/?click=menu','Investing Basics'],
['/schaeffersu/advanced/inflation/?click=menu','Advanced Investing Topics'],
['/schaeffersu/options/general/why_options.aspx?click=menu','Options Trading'],
['/schaeffersu/general/glossary.aspx?click=menu','Glossary']
);

var ff_shop = new Array(
['','CONTENTS'],
['/signup/signupform.aspx?click=menu&nav=yes&form=enews','Free Services'],
['/shop/productlist.aspx?view=education', 'Educational Services', 'shop', 'products(\'education\');return false;'],
['/shop/productlist.aspx?view=bulletins', 'Bulletin Services', 'shop', 'products(\'bulletins\');return false;'],
['/shop/productlist.aspx?view=alert', 'Alert Services', 'shop', 'products(\'alert\');return false;']
);

//The news items are in a separate JS file called navbar.js
//navbar.js content is updated via the XMLMarketObsUnion SQL job -MCT

var tt = new Array(
['Start Here!','start','start'],
['Quotes &amp; Tools Highlights','streetools','streetools'],
//['Market Highlights','markets','markets'],
['','markets','markets'],
['Commentary Highlights','marketbeat','marketbeat'],
['Personal Finance Highlights','pfinance','pfinance'],
['Schaeffer\'s Edge Highlights','sedge','sedge'],
['Education Highlights','su','su'],
['Premium Services','shop','shop']
);

var dd_ns4 = (document.layers) ? 1 : 0;
var dd_ie4 = (document.all) ? 1 : 0;
var dd_dom = ((document.getElementById) && (!dd_ie4)) ? 1 : 0; // ns6
var isOver = false;
var timer = null;
var cmTop = 0;
var cmLeft = 0;

if (dd_ns4) {
        origWidth = innerWidth;
        origHeight = innerHeight;
}

function reDo() {
        if (innerWidth != origWidth || innerHeight != origHeight) {location.reload();}
}

if (dd_ns4) onresize = reDo;
if (dd_dom) onload = InitObj;

document.write("<div id=\"gnddhome\"></div>");
	
//build dropdowns
for ( i = 0 ; i < tt.length ; i++ ) {
	var ff = eval("ff_" + tt[i][1]);
	var news = eval("news_" + tt[i][1]);
	var divNum = "gndd" + tt[i][2];
	var strDiv = "<div class=\"cm\" id=\"" + divNum + "\" onMouseOver=\"OverLayer();\" onMouseOut=\"OutLayer('"+ divNum + "');\">";
	
	//IF added to shorten the products/services box since it's at the end -MCT
	if (tt[i][2] == "shop") {
		strDiv = strDiv + "<table cellspacing=\"0\" cellpadding=\"2\" width=\"240\" border=\"0\"><tr valign=\"top\"><td class=\"cmLff\" width=\"80\"><table width=\"80\" cellpadding=\"2\" cellspacing=\"0\">";
	}
	else if (tt[i][2] == "markets") {
		strDiv = strDiv + "<table cellspacing=\"0\" cellpadding=\"2\" width=\"240\" border=\"0\"><tr valign=\"top\"><td class=\"cmL\" width=\"240\"><table width=\"240\" cellpadding=\"2\" cellspacing=\"0\" border=\"1\">";
	}
	else {
	strDiv = strDiv + "<table cellspacing=\"0\" cellpadding=\"2\" width=\"240\" border=\"0\"><tr valign=\"top\"><td nowrap class=\"cmLff\" width=\"80\"><table width=\"50\" cellpadding=\"2\" cellspacing=\"0\">";
	}
	for ( j = 0 ; j < ff.length ; j++ ) {
		var linkString = new String(ff[j][0]);

		var linkTarget="";
		var onclickVar="";
		if (ff[j][0] != '')
		{
			//markets tab
			if (tt[i][2] == "markets") {
				strDiv = strDiv;
			}
			else {//all other tabs, do the following
			//The following two lines are for links to javascript pop-ups
			//in the ff_ array, make the HREF equal to page URL, 
			//then add link text, then add onclick event, then add target
			//to degrade pop-ups if they encounter a pop-up blocker. -MCT
			
			if (ff[j][2]) linkTarget=(" target=\"" +ff[j][2] +"\"");
			if (ff[j][3]) onclickVar=(" onclick=\"" +ff[j][3] +"\"");
	
			if (linkString.indexOf('http:') == -1) ff[j][0] = ff[j][0];
			//"contents" list
			strDiv = strDiv + "<tr><td valign=\"top\" class=\"cmLff\"><b>&#187;</b></td><td class=\"cmLff\"><a class=\"black\" href=\"" + ff[j][0] + "\"" +linkTarget + onclickVar + ">" + ff[j][1] + "</a></td></tr>";
			}
		}
		
		else {
			//"contents" line
			strDiv = strDiv + "<tr><td colspan=\"2\" class=\"cmLff\"><b>" + ff[j][1] + ":</b></td></tr>";
		}
	}
		//If/else added to shorten the products/services box since it's at the end -MCT
		if (tt[i][0] == "Products &amp; Services") {
			strDiv = strDiv + "</table></td><td class=\"cmL\" width=\"100\" nowrap>";
		}
		else if (tt[i][2] == "markets") {
		strDiv = strDiv;
		}
		
		else {
			strDiv = strDiv + "</table></td><td class=\"cmL\" width=\"150\" nowrap>";
		}
	strDiv = strDiv + "<table width=\"100%\" cellpadding=\"2\" cellspacing=\"0\"><tr><td class=\"cmTitle\" colspan=\"2\">" + tt[i][0] + "</td></tr>";
	for ( j = 0 ; j < news.length ; j++ ) {
		var linkString = new String(news[j][0]);
		if (linkString.indexOf('http:') == -1) news[j][0] = news[j][0];	
		//this limits the number of news items in the right-hand side of pop-up. -MCT
		if (j < 27 && news[j][0] == "" && news[j][1] == "")
			strDiv = strDiv + "<tr><td align=\"center\" colspan=\"2\"><hr width=\"200\" align=\"center\"></td></tr>"
		else
			if (j < 27) strDiv = strDiv + "<tr><td valign=\"top\" width=\"5\">&#149;</td><td width=\"100%\"><a href=\"" + news[j][0] + "\"  class=\"cmH\">" + news[j][1] + "</a></td></tr>";
	}
	strDiv = strDiv + "</table></td></tr></table></div>\n";
	document.write(strDiv);
}

function InitObj() {
	for (i = 0; i < tt.length; i++) { 
		whichEl = "gndd" + tt[i][2];
		if (dd_dom) {
			whichEl = document.getElementById(whichEl);
		}
		else {	
			whichEl = (dd_ns4) ? document.layers[whichEl] : document.all[whichEl].style;
		} 
		whichEl.onmouseover = OverLayer;
		whichEl.onmouseout = OutLayer;
	}

}

InitObj();

function ChangeCSSBorder(id, action, activetab) {
	//change tab colors, images
	//maintopnav.ascx is also handling the determination of tab color
	//by detecting what section the user is on. -MCT
	
	if (document.getElementById) {
		if (action == 1)
		{
			if (activetab)
			{
				//if it's an active tab specify the active classes/images.
				document.getElementById(id + "Img").src = "/images/htdocs/downarrow.gif";
				document.getElementById(id + "Btn").className = "navButtonArrowDown";
			}
			else
			{
				document.getElementById(id + "Btn").className = "navButtonArrowDown";
			}
		}
		else
		{
			if (activetab)
			{
				document.getElementById(id + "Img").src = "/images/htdocs/downarrowblk.gif";
				document.getElementById(id + "Btn").className = "navButtonArrowActive";
			}
			else
			{
				//Check for start button tab.
				if (id == "start")
				{
					document.getElementById(id +"Btn").className = "navButtonStartArrow";
				}
				else
				{
					document.getElementById(id + "Btn").className = "navButtonArrow";
				}
			}
		}
	}
}

function ShowLayer(showEl, event) {
	clearTimeout(timer);
	if (dd_dom) {
		var whichEl = document.getElementById(showEl);
	}
	else {	
		var whichEl = (dd_ns4) ? document.layers[showEl] : document.all[showEl].style;
	}
	whichAnchor = showEl + "A";
	//check to see if it's already open.  If it is, then user
	//wants to close it.  Set blnNoShow to true. -MCT
	var blnNoShow = false;
	if (dd_dom) {
		if (whichEl.style.visibility == "visible")
			blnNoShow = true;
	}
	else if (whichEl.visibility == "visible")
	{
		blnNoShow = true;
	}
	HideAllLayers();
	
	//document.anchors[whichAnchor].style.backgroundColor = '880000';	
	if (dd_ie4) {
		if (document.all[whichAnchor]){ 
			//if this is the last tab, offset it to the left so it doesn't run off the page
			if (showEl == "gnddshop")
			{
				cmTop = findy(document.all[whichAnchor]) + 19;
				cmLeft = findx(document.all[whichAnchor]) + -116;
			}
			else
			{
				cmTop = findy(document.all[whichAnchor]) + 19;
				cmLeft = findx(document.all[whichAnchor]) + 1;
			}
		}
	}
	if (dd_ns4) {
		if (document.anchors[whichAnchor]) {
			cmTop = document.anchors[whichAnchor].y + 21;
			cmLeft = document.anchors[whichAnchor].x + 1;
		}
	}
	if (dd_dom){
		if (document.anchors[whichAnchor]){
			var myObject = document.anchors[whichAnchor];
			while (myObject.offsetParent) {
				//alert("made it");
				cmTop  = cmTop  + myObject.offsetTop;
				cmLeft = cmLeft + myObject.offsetLeft;
				myObject = myObject.offsetParent;
			}
		}
	}
	if (dd_dom) {

		//add "px" at end of x/y coordinates for XHTML -MCT
		//if this is the last tab, offset it to the left so it doesn't run off the page
		if (showEl == "gnddshop")
		{
			whichEl.style.top = cmTop + 19 + 'px';
			whichEl.style.left = cmLeft + -115 + 'px';
		}
		else
		{
			whichEl.style.top = cmTop + 19 + 'px';
			whichEl.style.left = cmLeft + 1 + 'px';
		}
		if (document.getElementById("jumpToMenu")==null)
		{
			//do nothing
		}
		else
		{
		//uncomment this if we need to hide the jumptomenu later.
		document.getElementById("jumpToMenu").style.visibility = "hidden";
		}
		
		//alert("dd_dom");
		if (!blnNoShow)
			whichEl.style.visibility = "visible";
		else
			document.getElementById("jumpToMenu").style.visibility = "visible";
	}
	else {
		if (document.all("jumpToMenu")==null)
		{
			//do nothing
		}
		else
		{
		//uncomment this if we need to hide the jumptomenu later.
		document.all("jumpToMenu").style.visibility = "hidden";
		}
		
		//alert("ie_dom" + whichEl.visibility);
		
		if (!blnNoShow)
			whichEl.visibility = "visible";
		else
			document.getElementById("jumpToMenu").style.visibility = "visible";
			
		whichEl.top = cmTop;
		whichEl.left = cmLeft;
	} 	
	cmTop = 0; cmLeft = 0;
}

function findy(item) {
	if (item.offsetParent) {
		return item.offsetTop + findy(item.offsetParent);
	}
	else {
		return item.offsetTop;
	}
}

function findx(item) {
	if (item.offsetParent) {
		return item.offsetLeft + findx(item.offsetParent);
	}
	else {
		return item.offsetLeft;
	}
}

function findPosition(item) {
  if( item.offsetParent ) {
    for( var posX = 0, posY = 0; item.offsetParent; item = item.offsetParent ) {
      posX += item.offsetLeft;
      posY += item.offsetTop;
    }
    return [ posX, posY ];
  } else {
    return [ item.x, item.y ];
  }
}

function HideAllLayers() {
	if (dd_dom) {
		
		if (document.getElementById("jumpToMenu")==null)
		{
			//do nothing
		}
		else
		{
			document.getElementById("jumpToMenu").style.visibility = "visible";
		}

		var divTemp = document.getElementsByTagName('div');
		for (i = 0; i < divTemp.length; i++) {
			var divString = new String(divTemp[i].id);
			if (divString.indexOf('gndd') != -1) divTemp[i].style.visibility = "hidden";
		}
	}	
	if (dd_ie4) {
		if (document.all("jumpToMenu")==null)
		{
			//do nothing
		}
		else
		{
			document.all("jumpToMenu").style.visibility = "visible";
		}

		var divTemp = document.all.tags("div");
		for (i = 0; i < divTemp.length; i++) { 
			var divString = new String(divTemp[i].id);
			if (divString.indexOf('gndd') != -1) divTemp[i].style.visibility = "hidden";
		}
	}
	if (dd_ns4) {
		for (i = 0; i < document.layers.length; i++) { 
			var divString = new String(document.layers[i].name);
			if (divString.indexOf('gndd') != -1) document.layers[i].visibility = "hidden";
		}
	}
}

function OverLayer() { clearTimeout(timer); isOver = true; }

function OutLayer() { 
	clearTimeout(timer);
	isOver = false; 
	timer = setTimeout("HideAllLayers()",300);
}