// DM - 7/29/05 **** This file contains functions mainly used by designers (open windows, manipulate GUI elements, etc.)  
// Ref this file only on pages that need one of these functions.

// Global Variables
//***************************************************************
var session = GetSessionID() ;
//***************************************************************

// begin bubble terms functions - call init(numBubbles); and objectiveLink(); onLoad
// If bubble extends beyond top of browser - set top='1' in function call

function setBubble(val,top){ 

if(document.getElementById("bubble"+val)){
	document.getElementById("bubble"+val).style.zIndex = '999';
	document.getElementById("bubble"+val).style.display = "block";
	document.getElementById("bubble"+val).style.position = "relative";
	document.getElementById("bubble"+val).style.margin = '0';
	document.getElementById("bubble"+val).style.padding = '0';

	if(document.getElementById('dgAlertsIndex')){
		document.getElementById("bubble_content"+val).style.width = '400px';
	}
	else{
		if(top=='1'){
			document.getElementById("bubble_content"+val).style.width = '250px';
		}
		else if(top=='2'){
			document.getElementById("bubble_content"+val).style.width = '150px';
		}
		else{
			document.getElementById("bubble_content"+val).style.width = '175px';
		}
	}

    var h = document.getElementById("bubble_content"+val).offsetHeight; 
    var w = document.getElementById("bubble_content"+val).offsetWidth;

	var tlh = 5;
	var tlw = 26;

	document.getElementById("bubble"+val).style.top = findPosX("link" + val) - (h + 44) + "px";
	document.getElementById("bubble"+val).style.left = findPosY("link" + val) + 90 + "px";

	document.getElementById("bubble_content"+val).style.top = tlh + 'px';
	document.getElementById("bubble_content"+val).style.left = tlw + 'px';
	document.getElementById("bubble_content"+val).style.backgroundColor = '#fff';	
	document.getElementById("bubble_content"+val).style.fontFamily = 'arial';
	document.getElementById("bubble_content"+val).style.fontSize = '11px';

	document.getElementById("bubble_tl"+val).style.backgroundImage = 'url(/images/styles/bubble/tl.gif)';
	document.getElementById("bubble_tl"+val).style.top = '0';
	document.getElementById("bubble_tl"+val).style.left = '0';
	document.getElementById("bubble_tl"+val).style.backgroundRepeat = 'no-repeat';
	document.getElementById("bubble_tl"+val).style.width = '26px';
	document.getElementById("bubble_tl"+val).style.height = '5px';

	document.getElementById("bubble_t"+val).style.backgroundImage = 'url(/images/styles/bubble/t.gif)';
	document.getElementById("bubble_t"+val).style.top = '0';
	document.getElementById("bubble_t"+val).style.height = '5px';
	document.getElementById("bubble_t"+val).style.width = w + 'px';
	document.getElementById("bubble_t"+val).style.left = tlw + 'px';

	document.getElementById("bubble_tr"+val).style.backgroundImage = 'url(/images/styles/bubble/tr.gif)';
	document.getElementById("bubble_tr"+val).style.top = '0';
	document.getElementById("bubble_tr"+val).style.backgroundRepeat = 'no-repeat';
	document.getElementById("bubble_tr"+val).style.width = '10px';
	document.getElementById("bubble_tr"+val).style.height = '5px';
	document.getElementById("bubble_tr"+val).style.left = (w + tlw) + 'px';

	document.getElementById("bubble_l"+val).style.backgroundImage = 'url(/images/styles/bubble/l.gif)';
	document.getElementById("bubble_l"+val).style.left = '0';
	document.getElementById("bubble_l"+val).style.width = '26px';
	document.getElementById("bubble_l"+val).style.height = h + 'px';
	document.getElementById("bubble_l"+val).style.top =  tlh + 'px';

	document.getElementById("bubble_r"+val).style.backgroundImage = 'url(/images/styles/bubble/r.gif)';
	document.getElementById("bubble_r"+val).style.width = '10px';
	document.getElementById("bubble_r"+val).style.top = tlh + 'px';
	document.getElementById("bubble_r"+val).style.left = (tlw + w) + 'px';
	document.getElementById("bubble_r"+val).style.height = h + 'px';

	document.getElementById("bubble_bl"+val).style.backgroundImage = 'url(/images/styles/bubble/bl.gif)';
	document.getElementById("bubble_bl"+val).style.left = '0';
	document.getElementById("bubble_bl"+val).style.backgroundRepeat = 'no-repeat';
	document.getElementById("bubble_bl"+val).style.width = '26px';
	document.getElementById("bubble_bl"+val).style.height = '26px';
	document.getElementById("bubble_bl"+val).style.top = (tlh + h) + 'px';

	document.getElementById("bubble_b"+val).style.backgroundImage = 'url(/images/styles/bubble/b.gif)';
	document.getElementById("bubble_b"+val).style.height = '26px';
	document.getElementById("bubble_b"+val).style.width = w + 'px';
	document.getElementById("bubble_b"+val).style.top = (tlh + h) + 'px';
	document.getElementById("bubble_b"+val).style.left = tlw + 'px';

	document.getElementById("bubble_br"+val).style.backgroundImage = 'url(/images/styles/bubble/br.gif)';
	document.getElementById("bubble_br"+val).style.backgroundRepeat = 'no-repeat';
	document.getElementById("bubble_br"+val).style.width = '10px';
	document.getElementById("bubble_br"+val).style.height = '26px'
	document.getElementById("bubble_br"+val).style.left = (tlw + w) + 'px';
	document.getElementById("bubble_br"+val).style.top = (tlh + h) + 'px';

	val = "";
	}
} 

function init(numBubbles){
	if(document.getElementById("bubble1")){
	//need to initiate first or it doesn't build proper the first time fired.
		for (var i=1; i<=numBubbles; i++) {
			setBubble(i);
			resetBubble(i);
		}
	}
}

function resetBubble(bubbleNum){
	if(document.getElementById("bubble"+bubbleNum)){
		document.getElementById("bubble"+bubbleNum).style.display = "none";
	}
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

//show bubble links for review page objectives
function objectiveLink(){
  for (var i=0;i < document.links.length;i++) {
	var x = document.links[i].href
		if(x.indexOf('speculation')!=-1){
			document.getElementById('speculation').style.display = "inline";
		} else if(x.indexOf('aggressive')!=-1){
			document.getElementById('aggressive').style.display = "inline";
		} else if(x.indexOf('growth')!=-1){
			document.getElementById('growth').style.display = "inline";
		} else if(x.indexOf('income')!=-1){
			document.getElementById('income').style.display = "inline";
		}
	}
}

//hide bubbles in popup faqs
function disablePopupBubble(){

  for (var i=0;i < document.links.length;i++) {
	var x = document.links[i].href
		if(x.substring(x.length-1,x.length)=='#' && i > 2){
    	document.links[i].style.position = "static"; 
    	document.links[i].style.color = "#000";   
    	document.links[i].style.textDecoration = "none"; 
		}
	}
}

//do this check if bubble terms will show/hide based on code.
function countBubbles(total){
  for (var i=1;i <= total;i++) {
	if(!document.getElementById('link'+i)){
		var x = i-1;
		init(x);
	} else if(i==total) {
			init(i);
		}
	}
}

//hide and show any drop-downs that appear in the same location the bubble will appear.
//put a span around the drop-downs with the same name and number them ascendingly.  pass highest number to function
function hideDrop(name,num){
	for(j=1;j<=num;j++){
		document.getElementById(name+j).style.display="none";
	}
}

function showDrop(name,num){
	for(j=1;j<=num;j++){
		document.getElementById(name+j).style.display="inline";
	}
}
// End bubble terms functions ***************


// daily recap mail
function recapEmail() {
	var s;
	var s1;
	var s2;
	s=document.forms[0].txtEmail.value;
	var at=s.indexOf('@');
	if(at!=-1){
		s1=StripIllegalChars(s.substring(0,at));
		s2=StripIllegalChars(s.substring(at+1,9999));
	}
	var checkEmail = ValidEmailEmpty(s1+'@'+s2);
	if(checkEmail==false){
		alert('Please enter a valid email address');
		return false;
	}
	else{
		s=s1+'@'+s2;
		OpenChildWindow('https://'+location.hostname+'/welcome.asp?PageID=WelcomeHome&Email='+s,'','480','600');
	}
}

//hide account objectives on application overview pages - call from bottom of overview pages, body tag is dynamic
function hideObjLink(){
  for (var i=0;i < document.links.length;i++) {
	var x = document.links[i].href
		if(x.indexOf('speculation')!=-1){
			document.links[i].style.textDecoration = "none";
			document.links[i].style.color = "#000";
			document.links[i].href = "javascript:void(0);";
		} else if(x.indexOf('aggressive')!=-1){
			document.links[i].style.textDecoration = "none";
			document.links[i].style.color = "#000";
			document.links[i].href = "javascript:void(0);";
		} else if(x.indexOf('growth')!=-1){
			document.links[i].style.textDecoration = "none";
			document.links[i].style.color = "#000";
			document.links[i].href = "javascript:void(0);";
		} else if(x.indexOf('income')!=-1){
			document.links[i].style.textDecoration = "none";
			document.links[i].style.color = "#000";
			document.links[i].href = "javascript:void(0);";
		}
	}
}

function SubmitFormStrategy(sPage,sChainType) {
	if (!ValidateData(document.frmTryStrat.txtSymbol.value,document.frmTryStrat.txtSymbol)) {
		return false;
	} else {
	    document.frmTryStrat.action = sPage + '?sessionid=' + session + '&symbol=' + document.frmTryStrat.txtSymbol.value + '&page=' + sChainType + '&issubmited=true';
		return true;
	}
}

//Quickies code
/***********************************************
* AnyLink Drop Down Menu- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

var menuwidth='80px'; //default menu width
var menubgcolor='lightyellow';  //menu bgcolor
var disappeardelay=500;  //menu disappear speed onMouseout (in miliseconds)
var hidemenu_onclick=1; //hide menu when user clicks within menu?
var enableanchorlink=0; //Enable or disable the anchor link when clicked on? (1=e, 0=d)

var ie5=document.all;
var ns6=document.getElementById&&!document.all;

if (ie5||ns6){
	document.write('<span id="dropmenudiv" style="visibility:hidden;width:'+menuwidth+';background-color:'+menubgcolor+' onMouseover="clearhidemenu()" onMouseout="dynamichide(event)"></span>');
}

function getposOffset(what, offsettype){
	var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
	
	var parentEl=what.offsetParent;
	while (parentEl){
		totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
		parentEl=parentEl.offsetParent;
	}
	return totaloffset;
}

function showhide(obj, e, visible, hidden, menuwidth){
	if (ie5||ns6){
		dropmenuobj.style.left=dropmenuobj.style.top=-500;
	}
	if (menuwidth!=""){
		dropmenuobj.widthobj=dropmenuobj.style;
		dropmenuobj.widthobj.width=menuwidth;
	}
	if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover"){
		obj.visibility=visible;
	}
	else if (e.type=="click"){
		obj.visibility=hidden;
	}
}

function subshowhide(obj, e, visible, hidden){
	if (ie5||ns6){
		subdropmenuobj.style.left=subdropmenuobj.style.top=-500;
	}
	if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover"){
		obj.visibility=visible;
	}
	else if (e.type=="click"){
		obj.visibility=hidden;
	}
}

function iecompattest(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}

function clearbrowseredge(obj, whichedge, edgeoffset){
	if (whichedge=="rightedge"){
		var windowedge=ie5 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15;
		dropmenuobj.contentmeasure=dropmenuobj.offsetWidth;
		if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure){
			edgeoffset=dropmenuobj.contentmeasure-obj.offsetWidth;
		}
	}
	else{
		var windowedge=ie5 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18;
		dropmenuobj.contentmeasure=dropmenuobj.offsetHeight;
		if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure){ //move up?
			edgeoffset=dropmenuobj.contentmeasure+obj.offsetHeight;
		}
	}
	return edgeoffset;
}

var bHideArca = '';// aleks
function dropdownmenudelayed(delayed, obj, e, rowName, symbol, s, page, isfuture, noteid, spreadid, secondsymbol, foreignmarketid, AddToPosition, isbuyorsell, isdetach, isNote, url, NotesRowID) {
	if (delayed == 'false'){ 
		bHideArca = 'false';
	} else {
		bHideArca = 'true';
	}
	return dropdownmenu(obj, e, rowName, symbol, s, page, isfuture, noteid, spreadid, secondsymbol, foreignmarketid, AddToPosition, isbuyorsell, isdetach, isNote, url, NotesRowID);
}
function dropdownmenu(obj, e, rowName, symbol, s, page, isfuture, noteid, spreadid, secondsymbol, foreignmarketid, AddToPosition, isbuyorsell, isdetach, isNote, url, NotesRowID ){	

	s = session;
	if(top.frames.right){
		fTarget='right';
	}
	else{
		fTarget='main';
	}

	links=new Array();
	links[0]='<a href="javascript:AppendSessionID(' + "'" + '/quote_option_chain.asp?SYMBOL=' + symbol + "'" + ');" target="'+fTarget+'">Chain</a>';
	links[1]='<a href="#" onClick="return clickreturnvalue()" onMouseover="rightmenu(this, event, ' + "'" + 'subdrop1' + "'" + ')" target="'+fTarget+'"><img src="/images/styles/quickies/right.gif" width="7" height="7" style="float:right;margin-top:4px;margin-right:4px;">Charts</a><div id="subdrop1" style="visibility:hidden;position:absolute;"><a href="/OXNetTools/Charts/charts.aspx?SESSIONID=' + s + '&SYMBOL=' + symbol + '&SnapJava=stream" target="'+fTarget+'">Streaming</a><a href="/oxnettools/charts/snapcharts.aspx?SESSIONID=' + s + '&SYMBOL=' + symbol + '&SnapJava=snap" class="last" target="'+fTarget+'">Basic</a></div>';
	links[2]='<a href="/OXNetTools/Charts/charts.aspx?SESSIONID=' + s + '&SYMBOL=' + symbol + '&SnapJava=stream" target="'+fTarget+'">Streaming</a>';	
	links[3]='<a href="/oxnettools/charts/snapcharts.aspx?SESSIONID=' + s + '&SYMBOL=' + symbol + '&SnapJava=snap" target="'+fTarget+'">Basic</a></div>';			
	links[4]='<a href="javascript:AddtoWatch(' + "'" + symbol + "'" + ',' + "''" + ',' + "''"+ ',' + "'"  + foreignmarketid + "'" + ',' + "''"+ ');">Watch</a>';	
	links[5]='<a href="javascript:OpenAlertManager(' + "'MAIN'" + ',' + "'" + symbol + "'" + ',' + "''" + ',' + "''" + ');">Alert</a>';	
	links[6]='<a href="Javascript:NewArcaPop();">ARCA</a>';
	links[7]='<a href="javascript:islandPopUpBook()">INET</a>';
	links[8]='<a href="javascript:OpenJavaOptionBook(' + "'" + symbol + "'" + ');">Quote Box</a>';	
	links[9]='<a href="javascript:AppendSessionID(' + "'" + '/quote_detail.asp?SYMBOL=' + symbol + '&page_id=news' + "'" + ');" target="'+fTarget+'">News</a>';
	links[10]='<a href="/OXNetAccnt/welcome/risks/margin_guidelines.aspx?SESSIONID=' + s + '&ticker=' + symbol + '" target="'+fTarget+'">Margin</a>';
	links[11]='<a href="javascript:Notes(' + "'" + noteid + "'" + ',' + "'" + NotesRowID+ "'" +',' + "'" + symbol + "'" + ');">Notes</a>';
	links[12]='<a href="javascript:OpenAlertManager(' + "'WATCH_LIST'" + ',' + "'" + symbol + "'" + ',' + "''" + ',' + 'document.forms[0].lstWatch.value);">Alert</a>';
	links[13]='<a href="javascript:OpenAlertManager(' + "'WATCH_LIST'" + ',' + "'" + rowName + "'" + ',' + "'" + secondsymbol +"'" + ',' + 'document.forms[0].lstWatch.value);">Alert</a>';
	links[14]='<a href="javascript:AppendSessionID(' + "'" + '/quote_option_chain.asp?page=ssf&SYMBOL=' + symbol + '&MARKET_ID=' + foreignmarketid + "'" + ');">Chain</a>';
	links[15]='<a href="javascript:NotesSpread(' + "'" + noteid + "'" + ',' + "'" + spreadid + "'" + ',' + "'" + rowName + "'" + ',' + "'" + secondsymbol + "'" + ');">Notes</a>';
	links[16]='<a href="javascript:AppendSessionID(' + "'" + '/quote_option_chain.asp?SYMBOL=' + symbol + '&MARKET_ID=' + foreignmarketid + "'" + ');" target="'+fTarget+'">Chain</a>';
	links[17]='<a href="javascript:OpenAlertManager(' + "'POSITIONS'" + ',' + "'" + symbol + "'" + ',' + "''" + ',' + "''" + ');">Alert</a>';
	
	links[18]='<a href="javascript:AppendSessionID(' + "'" + '/quote_option_chain.asp?SYMBOL=' + symbol + "'" + ');">Chain</a>';
	links[19]='<a href="#" onClick="return clickreturnvalue()" onMouseover="rightmenu(this, event, ' + "'" + 'subdrop1' + "'" + ')"><img src="/images/styles/quickies/right.gif" width="7" height="7" style="float:right;margin-top:4px;margin-right:4px;">Charts</a><div id="subdrop1" style="visibility:hidden;position:absolute;"><a href="/OXNetTools/Charts/charts.aspx?SESSIONID=' + s + '&SYMBOL=' + symbol + '&SnapJava=stream">Streaming</a><a href="/oxnettools/charts/snapcharts.aspx?SESSIONID=' + s + '&SYMBOL=' + symbol + '&SnapJava=snap" class="last">Basic</a></div>';
	links[20]='<a href="/OXNetTools/Charts/charts.aspx?SESSIONID=' + s + '&SYMBOL=' + symbol + '&SnapJava=stream">Streaming</a>';
	links[21]='<a href="/oxnettools/charts/snapcharts.aspx.asp?SESSIONID=' + s + '&SYMBOL=' + symbol + '&SnapJava=snap">Basic</a></div>';
	links[22]='<a href="javascript:AppendSessionID(' + "'" + '/quote_detail.asp?SYMBOL=' + symbol + '&page_id=news' + "'" + ');">News</a>';
	links[23]='<a href="/OXNetAccnt/welcome/risks/margin_guidelines.aspx?SESSIONID=' + s + '&ticker=' + symbol + '">Margin</a>';
	
	links[24]='<a href="javascript:AppendSessionID(' + "'" + '/quote_option_chain.asp?SYMBOL=' + rowName + "'" + ');" target="'+fTarget+'">Chain</a>';
	links[25]='<a href="javascript:AppendSessionID(' + "'" + '/quote_option_chain.asp?SYMBOL=' + symbol + '&Page=' + noteid + "'" + ');" target="'+fTarget+'">Chain</a>';
	links[26]='<a href="' + AddToPosition + '" target="'+fTarget+'">Trade More</a>';
	//links[27]='<a href="javascript:toggle(' + "'" + 'notetxt' + noteid + "'" + ');javascript:toggle(' + "'" + 'noteimage' + noteid + "'" + ');">Notes</a>';
	links[27]='<a href="javascript:ShowWatchNote(' + "'" + rowName  + "','" + NotesRowID + "'" + ');">Notes</a>'; //rowName = Index of row, NotesRowID = AlertManagerID
	links[28]='<a href="' + url + '" target="'+fTarget+'">Trade Calc</a>';	
	links[29]='<a href="javascript:OpenAlertManager(' + "'WATCH_LIST'" + ',' + "'" + symbol + "'" + ',' + "'" + secondsymbol +"'" + ',' + 'document.forms[0].lstWatch.value);">Alert</a>';
	links[30]='<a href="javascript:OpenAlertManager(' + "'WATCH_LIST'" + ',' + "'" + symbol + "'" + ',' + "''" + ',' + 'document.forms[0].lstWatch.value);">Alert</a>';
	links[31]='<a href="javascript:OpenAlertManager(' + "'MAIN'" + ',' + "'" + symbol + "'" + ',' + "''" + ',' + "''" + ');">Alert</a>';
	links[32]='<a href="javascript:OpenAlertManager(' + "'POSITIONS'" + ',' + "'" + symbol + "'" + ',' + "''" + ',' + "''" + ');">Alert</a>';
	links[33]='<a href="javascript:OpenAlertManager(' + "'WATCH_LIST'" + ',' + "'" + symbol + "'" + ',' + "''" + ',' + 'document.forms[0].lstWatch.value);">Alert</a>';

	links[36]='<a href="javascript:AppendSessionID(' + "'/" + url + "'" + ');" target="'+fTarget+'">Trade Calc</a>';

	// watch for quote frame
	//links[38]='<a href="javascript:AddtoWatch(' + "'" + symbol + "'" + ',' + "''" + ',' + "''"+ ',' + "'"  + foreignmarketid + "'" + ',' + "''"+ ');" target="'+fTarget+'">Watch</a>';	
	//SB 28085 Modified to override the check for calculate parameter, 
	//specific to alert manager only for now. Also pointing to dotnet trade calculator directly
	//needs to be changed to point to VB in case of a problem with dotnet trade calculator

	if(page=='AlertManager'){
		links[34]='<a href="javascript:AppendSessionID('+"'"+'/OXNetTools/toolbox/trade_calculator.aspx?override=true&txtSymbol1='+symbol+"'"+');">Trade Calc</a>';
	}
	else{
		links[34]='<a href="javascript:AppendSessionID('+"'"+'/position_chart.asp?pageid=trade_calculator&txtSymbol1='+symbol+"'"+');">Trade Calc</a>';
	}
	links[35]='<a href="javascript:LoadFutureOptionChainBySymbol(' + "'" + symbol + "'" + ');">Chain</a>';
	
	
	if(page=='watchlist' || page=='watchlistspread'){
		if (isNote == '0'){
			links[27]='<a href="javascript:toggle(' + "'" + 'notetxt' + noteid + "'" + ');">Notes</a>';
		}
	}

	if(page=='aOverview' || page=='aOverviewList' || page=='aPositions' || page=='aPositionsAlerts' || page=='aPositionsCostbasis'){
		// For Position Pages additional Link
		if(isbuyorsell=='SELL'){
			links[26]='<a href="' + AddToPosition + '" target="'+fTarget+'">Sell More</a>';
		}
		else if(isbuyorsell=='BUY'){
			links[26]='<a href="' + AddToPosition + '" target="'+fTarget+'">Buy More</a>';
		}
	}
	
	if(page=='watchlist' || page=='watchlistspread' || page=='aPositions' || page=='aPositionsAlerts' || page=='aPositionsCostbasis'){
		if(isdetach=='1'){
			// For Detach Pages in order to focus on the main page;
			links[0]='<a href="javascript: Detach(' + "'" + '/quote_option_chain.asp?SESSIONID=' + s + '&SYMBOL=' + symbol + "'" + ');">Chain</a>';
			links[1]='<a href="#" onClick="return clickreturnvalue()" onMouseover="rightmenu(this, event, ' + "'" + 'subdrop1' + "'" + ')"><img src="/images/styles/quickies/right.gif" width="7" height="7" style="float:right;margin-top:4px;margin-right:4px;">Charts</a><div id="subdrop1" style="visibility:hidden;position:absolute;"><a href="javascript: Detach(' + "'" + '/OXNetTools/Charts/charts.aspx?SESSIONID=' + s + '&SYMBOL=' + symbol + '&SnapJava=stream' + "'" + ');">Streaming</a><a href="javascript: Detach(' + "'" + '/oxnettools/charts/snapcharts.aspx?SESSIONID=' + s + '&SYMBOL=' + symbol + '&SnapJava=snap' + "'" + ');" class="last">Basic</a></div>';
			links[9]='<a href="javascript: Detach(' + "'" + '/quote_detail.asp?SESSIONID=' + s + '&SYMBOL=' + symbol + '&page_id=news' + "'" + ');">News</a>';
			links[14]='<a href="javascript: Detach(' + "'" + '/quote_option_chain.asp?SESSIONID=' + s + '&PAGE=SSF&SYMBOL=' + symbol + '&MARKET_ID=' + foreignmarketid + "'" + ');">Chain</a>';
			links[16]='<a href="javascript: Detach(' + "'" + '/quote_option_chain.asp?SESSIONID=' + s + '&SYMBOL=' + symbol + '&MARKET_ID=' + foreignmarketid + "'" + ');">Chain</a>';
			if(page=='aOverview' || page=='aOverviewList' || page=='aPositions' || page=='aPositionsAlerts' || page=='aPositionsCostbasis'){
				// For Position and Overview pages additional Link
				if(isbuyorsell=='SELL'){
					links[26]='<a href="javascript: Detach(' + "'" + AddToPosition + "'" + ');">Sell More</a>';
				}
				else if(isbuyorsell=='BUY'){
					links[26]='<a href="javascript: Detach(' + "'" + AddToPosition + "'" + ');">Buy More</a>';
				}
			}
		}
	}

	links[37]=null;
	var lstType = document.getElementById('lstViewType');
	if(lstType != null){
		if((page=='aPositions' && lstType.value != 4) || page=='aPositionsAlerts' || page=='aPositionsCostbasis')
			if(IsValidOption(symbol))
				links[37]='<a href="#" onclick="javascript: showCalc(' + "'on'" + ',this,' + "'" + symbol + "'" + ');return false;">Mini Pricer</a>';		

	}else{
		if(page=='aPositions' || page=='aPositionsAlerts' || page=='aPositionsCostbasis')
			if(IsValidOption(symbol))
				links[37]='<a href="#" onclick="javascript: showCalc(' + "'on'" + ',this,' + "'" + symbol + "'" + ');return false;">Mini Pricer</a>';		
	}

	
//-------------------------------------
// 0 = Chain - with targetting main
// 1 = Chart link w/Submenu - with targetting main
// 2 = FleXCharts - with targetting main
// 3 = Charts - with targetting main
// 4 = Watch (add to watchlist)
// 5 = Alert
// 6 = ARCA - This has been removed.
// 7 = INET
// 8 = Quote Box
// 9 = News - with targetting main
// 10 = Margin - with targetting main
// 11 = Notes
// 12 = Alert for watchlist singles
// 13 = Alert for watchlist Spread and stock combo
// 14 = Chain for futures with marketid
// 15 = Notes for watchlist Spread and stock combo
// 16 = Chain with marketid for foreignmarkets
// 17 = Alert for Account Positions ( opens Alert Manager )
// ------------------
// below is dublicate of some links without targetting main
// 18 = Chain - 0
// 19 = Chart link w/Submenu - 1
// 20 = FleXCharts with targetting main - 2
// 21 = Charts - 3
// 22 = News - 9
// 23 = Margin - 10
// ------------------
// below is needed for screener pages
// 24 = Chain for RowName ( for ScreenerOption ) - 
// 25 = Chain with parsing page ( for ScreenerSpreads )
// -----------------------
// below is for new links Sell More and Buy More
// 26 = (Sell More) or (Buy More) for Overview and positions Pages 
// -----------------------
// 27 = Adding Notes on the existing page
// -----------------------
// 28 is Trade Calc link for VB6 Strategy Scan Page
// -----------------------
// 29 through 33 are new alertmanager links for each page
// -----------------------
// 36 is Trade Calc Link on DotNet StrategyScan Page
// -----------------------


//-------------------
//-------------------
// isfuture ;
// 0 = is not future
// 1 = is future
// 2 = is not spread
// 3 = is spread
// 4 = FUTURES OPTIONS SEC TYPES
//-------------------
// foreignmarketid ;
// 0 = is USMarket
//-------------------
// rowName is used as first symbol for the spreads
// rowName is used as symbol for the account overview page
// rowName is used as StockSymbol for the ScreenerOption Page
//-------------------
// spreadid is used as a flag for alertmanager on account positions pages , its value is coming from the registry
// 0 = do not add the alert manager link
// 1 = add the alert manager link
//-------------------
// secondsymbol is used as a security type id mfund or bond
// 0 = is not a ( mutual fund or bond )
// 1 = is a mutual fund or bond
//-------------------
// noteid ( for ScreenerStock page)
// is used as a flag for optionability
// 0 = Not Optional
// 1 = Optional
//-------------------
// noteid ( for ScreenerSpreads ) is used as the page for the parsing
//-------------------
// spreadid ( for screenerSpreads ) is used to diversify spread and the individual options
// 0 = individual stock
// 1 = spread
//-------------------
// isbuyorsell is used for sell more and buy more links
// "BUY" = for Buy More
// "SELL" = for Sell More
//-------------------
// isdetach is used on pages that have detach option
// 0 = is Not Detached page
// 1 = is a Detached page
//-------------------
// isNote is used on watchlist pages as a flag for existance of notes
// 0 = there is no note
// 1 = note exists
//---------------------------

	if(page=='1'){ //1 = quote frame
		menuwidth = '170px';
		edgeoffset='0';		
		rowName=new Array();
			rowName[0]='<div id="quoteFrameMoreMenu">'+links[8];
			//rowName[1]=links[38];
			rowName[1]='<a href="/OXNetTools/Charts/charts.aspx?SESSIONID=' + s + '&SYMBOL=' + symbol + '&SnapJava=stream" target="'+fTarget+'">Streaming Charts</a>';
			rowName[2]=links[9];
			rowName[3]='<a href="javascript:AddtoWatch(' + "'" + symbol + "'" + ',' + "''" + ',' + "''"+ ',' + "'"  + 0 + "'" + ',' + "''"+ ');">Watch</a></div>';
		/*if(isfuture=='0' && bHideArca == 'false' || isfuture=='0' && bHideArca == ''){		
			rowName[4]=links[6];
		}*/
			//rowName[5]='</li><li style="float:left;padding:0;margin-left:-1px;"><a href="javascript:AddtoWatch(' + "'" + symbol + "'" + ',' + "''" + ',' + "''"+ ',' + "'"  + 0 + "'" + ',' + "''"+ ');" style="' + 'border-bottom:1px solid black;height:15px;"'+'>Watch</a></li></ul>';
	} else if(page=='2') { // 2 = futures iframe
		menuwidth = '0px';
		edgeoffset='0';		
		rowName=new Array();
		rowName[0]=links[0];
		rowName[1]=links[2];
		rowName[2]=links[4];
		rowName[3]=links[5]; //rowName[3]=links[31]; KP (Disable AM)
	} else if(page=='charts') { // java and snap pages - no chart link
		menuwidth = '0px';
		edgeoffset='0';		
		rowName=new Array();
		rowName[0]=links[0];
		rowName[2]=links[4];
		rowName[3]=links[9];
		rowName[4]=links[5]; //rowName[4]=links[31];  KP (Disable AM)
	} else if(page=='news') { // news - no news link
		menuwidth = '0px';
		edgeoffset='0';		
		rowName=new Array();
		rowName[0]=links[0];
		rowName[2]=links[4];
		rowName[4]=links[5]; //rowName[4]=links[31];  KP (Disable AM)
		rowName[5]=links[1];
	} else if(page=='watchlist') { // watchlist for single stocks and options	
		menuwidth = '0px';
		edgeoffset='0';		
		rowName=new Array();
		if(foreignmarketid=='0'){
			if(isfuture=='0'){
				rowName[2]=links[27];
				rowName[3]=links[12]; //rowName[3]=links[30];  KP (Disable AM)
				rowName[4]=links[9];
				rowName[5]=links[1];
			} else if(isfuture=='1' || isfuture=='4'){
				rowName[2]=links[27];
				rowName[3]=links[12]; //rowName[3]=links[30];  KP (Disable AM)
				rowName[4]=links[9];
				rowName[5]=links[1];
			}
		} else {	// no charts link for foreign markets
			if(isfuture=='0'){
				rowName[2]=links[27];
				rowName[3]=links[12]; //rowName[3]=links[30];  KP (Disable AM)
			} else if(isfuture=='1' || isfuture=='4'){
				rowName[1]=links[27];
				rowName[2]=links[12]; //rowName[2]=links[30];  KP (Disable AM)
			}
		}
		
	} else if(page=='watchlistspread'){ // watchlist for spreads
		menuwidth = '0px';
		edgeoffset='0';		
		rowName=new Array();
		if(foreignmarketid=='0'){
			rowName[2]=links[27];
			rowName[3]=links[13]; //rowName[3]=links[29];  KP (Disable AM)
			rowName[4]=links[9];
			rowName[5]=links[1];
		} else {
			rowName[2]=links[27];
			rowName[3]=links[13]; //rowName[3]=links[29];  KP (Disable AM)
		}
	} else if(page=='aOverview'){ // Account Overview Positions
		menuwidth = '0px';
		edgeoffset='0';		
		rowName=new Array();
		if(isfuture=='1' || isfuture=='4'){
			rowName[0]=links[26];
			rowName[2]=links[4];
			rowName[3]=links[9];
			rowName[4]=links[5]; //rowName[4]=links[32];  KP (Disable AM)
			rowName[6]=links[1];
		}
		else if(isfuture=='0'){
			if(foreignmarketid=='0'){
				rowName[0]=links[26];
				rowName[2]=links[4];
				rowName[3]=links[9];
				rowName[4]=links[5]; //rowName[4]=links[32];  KP (Disable AM)
				rowName[5]=links[1];
			}
			else {
				rowName[0]=links[16];
				rowName[2]=links[4];
			}
		}
	} else if(page=='aOverviewList'){ // Account Overview WatchList
		menuwidth = '0px';
		edgeoffset='0';		
		rowName=new Array();
		if(foreignmarketid=='0'){
			rowName[2]=links[5]; //rowName[2]=links[33];  KP (Disable AM)
			rowName[3]=links[9];
			rowName[4]=links[1];
		}
		else {
			rowName[0]=links[16];
		}
	} else if(page=='aPositions'){ // Account Positions and Account Positions Daily P&L
		menuwidth = '0px';
		edgeoffset='0';		
		rowName=new Array();
		if(foreignmarketid=='0'){
			if(secondsymbol=='0' && isbuyorsell!='')
			{
			rowName[0]=links[26];
			}
			rowName[2]=links[4];
			if (noteid!='0')
			{
				rowName[3]=links[11];
			}
			if(spreadid=='1'){
			rowName[4]=links[17];
			}	
			if(isfuture!='4'){ // hide for future options
				rowName[5]=links[9];
			}	
			if(links[37]==null){			
				if(isfuture!='4'){
					rowName[6]=links[1];
				}
			}else{
				if(isfuture!='4'){
					rowName[6]=links[37];
				}
				rowName[7]=links[1];
			}	
	
		
		} else {
			if(secondsymbol=='0'){
			rowName[0]=links[26];}
			rowName[2]=links[11];
			if(spreadid=='1'){
			rowName[3]=links[17];}
			rowName[4]=links[4];
			
		}
	} else if(page=='aPositionsBonds'){ // Account Positions for Bonds
		menuwidth = '0px';
		edgeoffset='0';		
		rowName=new Array();
		if(foreignmarketid=='0'){
			if (noteid!='0')
			{
				rowName[0]=links[11];
			}
			
		} else {			
			rowName[0]=links[11];			
		}
	} else if(page=='aPositionsAlerts'){ // Account Positions Alerts
		menuwidth = '0px';
		edgeoffset='0';		
		rowName=new Array();
		rowName[0]=links[26];
		rowName[2]=links[4];
		if(foreignmarketid=='0'){
			if (noteid!='0')
			{
				rowName[3]=links[11];
			}
			
		} else {			
			rowName[3]=links[11];			
		}

		rowName[4]=links[9];
		if(links[37]==null){
			rowName[5]=links[1];
		}else{
			rowName[5]=links[37];
			rowName[6]=links[1];
		}
	} else if(page=='aPositionsCostbasis'){ // Account Positions Cost Basis and Account Positions Greeks
		menuwidth = '0px';
		edgeoffset='0';		
		rowName=new Array();
		rowName[0]=links[26];
		rowName[2]=links[4];
		if(foreignmarketid=='0'){
			if (noteid!='0')
			{
				rowName[3]=links[11];
			}
			
		} else {			
			rowName[3]=links[11];			
		}
		if(spreadid=='1'){
			rowName[4]=links[17];
		}
		rowName[5]=links[9];
		if(links[37]==null){
			rowName[6]=links[1];
		}else{
			rowName[6]=links[37];
			rowName[7]=links[1];
		}
	}else if(page=='aPositionsVT'){ // Account Positions Virtual Trade
		menuwidth = '0px';
		edgeoffset='0';		
		rowName=new Array();
		if (noteid!='0')
		{
			rowName[0]=links[11];
		}
	}else if(page=='ScreenerETF' || page=='ScreenerMF'){
		menuwidth = '0px';
		edgeoffset='0';		
		rowName=new Array();
		rowName[1]=links[4];
		rowName[2]=links[9];
		rowName[3]=links[1];
	} else if(page=='ScreenerStock'){
		menuwidth = '0px';
		edgeoffset='0';		
		rowName=new Array();
		rowName[1]=links[4];
		rowName[2]=links[9];
		rowName[3]=links[1];
	} else if(page=='ScreenerOption'){
		menuwidth = '0px';
		edgeoffset='0';		
		rowName=new Array();
		rowName[1]=links[4];
		rowName[2]=links[9];
		rowName[3]=links[1];
	} else if(page=='ScreenerCoveredCall' || page=='ScreenerPutSell'){
		menuwidth = '0px';
		edgeoffset='0';		
		rowName=new Array();
		rowName[1]=links[4];
		rowName[2]=links[9];
		rowName[3]=links[1];
	} else if(page=='ScreenerSpreads'){
		menuwidth = '0px';
		edgeoffset='0';		
		rowName=new Array();
		rowName[1]=links[4];
		rowName[2]=links[9];
		rowName[3]=links[1];
		if(spreadid=='1'){
			rowName[4]=links[3];}
	} else if(page=='ETF'){ //for non-optionable ETFs; optionable ETFs use the default list
		menuwidth = '0px';
		edgeoffset='0';		
		rowName=new Array();
		rowName[0]=links[4];
		rowName[1]=links[9];
		rowName[2]=links[5]; //rowName[2]=links[31];  KP (Disable AM)
		rowName[3]=links[1];
	} else if(page=='StrategyScan'){
		menuwidth = '0px';
		edgeoffset='0';		
		rowName=new Array();
		menuwidth = '0px';
		edgeoffset='0';		
		rowName=new Array();
		rowName[2]=links[4];
		rowName[3]=links[9];
		rowName[4]=links[5]; //rowName[4]=links[31];  KP (Disable AM)
		rowName[5]=links[28];
		rowName[6]=links[1];
	} else if(page=='StrategyScanDotNet'){
		menuwidth = '0px';
		edgeoffset='0';		
		rowName=new Array();
		menuwidth = '0px';
		edgeoffset='0';		
		rowName=new Array();
		rowName[2]=links[4];
		rowName[3]=links[9];
		rowName[4]=links[5]; //rowName[4]=links[31];  KP (Disable AM)
		rowName[5]=links[36];
		rowName[6]=links[1];
	}else if(page=='AlertManager'){
		menuwidth = '0px';
		edgeoffset='0';		
		rowName=new Array();
		menuwidth = '0px';
		edgeoffset='0';		
		rowName=new Array();
		rowName[1]=links[27]; //Notes
		//rowName[2]=links[4];
		rowName[3]=links[9];
		rowName[5]=links[34];
		rowName[6]=links[1];
	}else if(page=='AlertHistory'){
		menuwidth = '0px';
		edgeoffset='0';		
		rowName=new Array();
		menuwidth = '0px';
		edgeoffset='0';		
		rowName=new Array();
		//rowName[2]=links[4];
		rowName[3]=links[9];
		rowName[5]=links[34];
		rowName[6]=links[1];
	} else if(page=='AlertManagerSpread'){
		menuwidth = '0px';
		edgeoffset='0';		
		rowName=new Array();
		menuwidth = '0px';
		edgeoffset='0';		
		rowName=new Array();		
		rowName[1]=links[27]; //Notes
		//rowName[2]=links[4];
		rowName[3]=links[9];
		rowName[5]=links[34];
		rowName[6]=links[1];
	} else if(page=='qDetailFutures'){
		menuwidth = '0px';
		edgeoffset='0';		
		rowName=new Array();
		menuwidth = '0px';
		edgeoffset='0';		
		rowName=new Array();
		rowName[0]=links[14];
		rowName[1]=links[4];
		rowName[5]=links[5]; //rowName[4]=links[31];  KP (Disable AM)	
		rowName[6]=links[1];
	} else if(page=='DividendsCalendar'){ 
		menuwidth = '0px';
		edgeoffset='0';		
		rowName=new Array();
		rowName[0]=links[4];
		rowName[1]=links[9];
		rowName[2]=links[5]; 
		rowName[3]=links[1];
	
	} else {
		menuwidth = '0px';
		edgeoffset='0';		
		rowName=new Array();
		if(isfuture=='1' || isfuture=='4'){
			if(isfuture=='4')
			{
				rowName[0]=links[35];
			}
			else
			{
				rowName[0]=links[14];
			}
		}
		else{
			rowName[0]=links[0];
		}
		rowName[2]=links[4];
		rowName[3]=links[9];
		if(isfuture=='1'){
			rowName[4]=links[31];

		} else {
			if(page=='qDetail'){ //quote detail has extra margin link
				rowName[4]=links[5]; //rowName[4]=links[31];  KP (Disable AM)
				rowName[5]=links[10];
			} else {
				rowName[4]=links[5]; //rowName[4]=links[31];  KP (Disable AM)
			}
		}
		rowName[6]=links[1];
	}	
	
	aLength = rowName.length - 1; //get bottom menu item
	rowName[aLength] = rowName[aLength].replace('">','" class="last">'); //class adds bottom border 	

	if (window.event){
		event.cancelBubble=true;
	}
	else if (e.stopPropagation){
		e.stopPropagation();
	}
	
	if(typeof dropmenuobj!='undefined'){
		dropmenuobj.style.visibility='hidden';
	}
	
	clearhidemenu();	
	dropmenuobj=document.getElementById? document.getElementById("dropmenudiv") : dropmenudiv;		
	dropmenuobj.innerHTML=rowName.join("");
	//alert(rowName);
	if (ie5||ns6){
		if(hidemenu_onclick){
			dropmenuobj.onclick=function(){dropmenuobj.style.visibility='hidden'}
			dropmenuobj.onmouseover=clearhidemenu;
			dropmenuobj.onmouseout=ie5?function(){dynamichide(event)}:function(event){dynamichide(event)}
		}
		showhide(dropmenuobj.style, e, "visible", "hidden", menuwidth);
		dropmenuobj.x=getposOffset(obj, "left");
		dropmenuobj.y=getposOffset(obj, "top");
		
		if(document.getElementById('mainTable')){
			var mainW = document.getElementById('mainTable').scrollWidth;
		}
		else if(document.getElementById('content') && document.getElementById('nav')){
			var mainW = document.getElementById('content').scrollWidth + document.getElementById('nav').scrollWidth;			
		}
		else if(document.getElementById('content')){
			var mainW = document.getElementById('content').scrollWidth;	
		}
		var fixPos = (document.body.scrollWidth - mainW)/2; 

		if(page=='1'){
			if(BrowserDetect.browser=='Safari'){
				dropmenuobj.style.left=dropmenuobj.x+fixPos-140+"px";
				dropmenuobj.style.top="0px";				
			}
			else{			
				dropmenuobj.style.left=dropmenuobj.x-60+"px";
				dropmenuobj.style.top="0px";		
			}
		}else{
			if(BrowserDetect.browser=='Safari'){
				dropmenuobj.style.left=dropmenuobj.x+fixPos-30+"px";
				dropmenuobj.style.top=dropmenuobj.y+obj.offsetHeight+90+"px";				
			}
			else{
				dropmenuobj.style.left=dropmenuobj.x-50+"px";
				dropmenuobj.style.top=dropmenuobj.y+obj.offsetHeight+"px";
			}
		}		
	}
	return clickreturnvalue();
}

function clickreturnvalue(){
	if (ie5||ns6 && !enableanchorlink){
		return false;
	}
	else {
		return true;
	}
}

function contains_ns6(a, b) {
	while (b.parentNode){
		if ((b = b.parentNode) == a){
			return true;
		}
	}
	return false;
}

function dynamichide(e){
	if (ie5&&!dropmenuobj.contains(e.toElement)){
		delayhidemenu();
	}
	else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget)){
		delayhidemenu();
	}
}

function subdynamichide(e){
	if (ie5&&!subdropmenuobj.contains(e.toElement)){
		subdelayhidemenu();
	}
	else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget)){
		subdelayhidemenu();
	}
}

function delayhidemenu(){
	if (ie5||ns6){
		if (typeof dropmenuobj!="undefined"){
			delayhide=setTimeout("dropmenuobj.style.visibility='hidden'",disappeardelay);
		}
	}
}

function subdelayhidemenu(){
	if (ie5||ns6){
		if (typeof dropmenuobj!="undefined"){
			subdelayhide=setTimeout("subdropmenuobj.style.visibility='hidden'",disappeardelay);
		}
	}
}

function clearhidemenu(){
	if (typeof delayhide!="undefined"){
		clearTimeout(delayhide);
	}
}

function subclearhidemenu(){
	if (typeof subdelayhide!="undefined"){
		clearTimeout(subdelayhide);
	}
}

function rightmenu(obj, e, dropmenuID){
	if (document.all&&!window.opera){
		var subObjB='', ieStyle=document.all.tags('style')[0].innerHTML;
		ieStyle=ieStyle.substr(ieStyle.indexOf('dropmenudiv a'));
		ieStyle=ieStyle.substr(ieStyle.indexOf('border-bottom'));
		ieStyle=ieStyle.substr(0, ieStyle.indexOf(';'));
		for (var i_tem = 0; i_tem < ieStyle.length; i_tem++){
			subObjB+=ieStyle.charAt(i_tem).replace(/[^0-9]/,'');
			subObjB=parseInt(subObjB);
		}
	}
	else if (!window.opera){
		var subObjB=1;
	}
	else{
		var subObjB=-6;
	}
	if (window.event){
		event.cancelBubble=true;
	}
	else if (e.stopPropagation){
		 e.stopPropagation();
	}
	if (typeof subdropmenuobj!="undefined"){ //hide previous menu
		subdropmenuobj.style.visibility="hidden";
		subclearhidemenu();
	}
	if (ie5||ns6){
		obj.onmouseout=subdelayhidemenu;	
		subdropmenuobj=document.getElementById(dropmenuID);
		//subdropmenuobj.innerHTML=dropmenuID.join("");
		if (hidemenu_onclick){
			subdropmenuobj.onclick=function(){subdropmenuobj.style.visibility='hidden'};
			subdropmenuobj.onmouseover=subclearhidemenu;
			subdropmenuobj.onmouseout=ie5? function(){ subdynamichide(event)} : function(event){ subdynamichide(event)};
			subshowhide(subdropmenuobj.style, e, "visible", "hidden");
			subdropmenuobj.style.left=obj.offsetWidth-75+"px";
			if(BrowserDetect.browser=='Safari'){
				subdropmenuobj.style.top=getposOffset(obj, "top")-(dropmenuobj.y)-(obj.offsetHeight) - 72 +"px";
				subdropmenuobj.style.zIndex="999";	
			}
			else{					
				subdropmenuobj.style.top=getposOffset(obj, "top")-(dropmenuobj.y)-(obj.offsetHeight) + 17 +"px";
				subdropmenuobj.style.zIndex="999";
			}
		}
	}
	return clickreturnvalue()
}
//***End quickies code**//

//code for profile page sub-sub-menu
//set oldID to tab that will be selected on page load
var oldID='first';
function subMenu2(newID){
	if(newID!=oldID){
		document.getElementById(oldID).style.display="none";
		document.getElementById(newID).style.display="inline";
		document.getElementById(oldID+"Tab").className="resetTab";
		document.getElementById(newID+"Tab").className="setTab";
	}
	oldID=newID;
}

/* Expand/Collapse - block */
function RowsShowHideBlock(sType,sImgID,objHid) {
	var current;	
	var browserName=navigator.appName;
	
	current = (document.getElementById(sType).style.display == 'block') ? 'none' : 'block';
	document.getElementById(sType).style.display = current;

	if (current=='block') {
		s="document." + sImgID + ".src='images/icons/minus.gif'";
		if (objHid!=null) {
			objHid.value='block';			
		}
	}
	else {
		s="document." + sImgID + ".src='images/icons/plus.gif'"
		if (objHid!=null) {			
			objHid.value='none';
		}
	}
	eval(s);
}

function loadExpandCollapseStates(sType,sDivID,sImgID){
	var img;	
	var currentValue = document.getElementById(sType).value;
	if(document.getElementById(sDivID) != null)
	{
		if (currentValue != "")
		{
			if (currentValue=="block")
			{
				document.getElementById(sDivID).style.display = "block";
				img="document." + sImgID + ".src='images/icons/minus.gif'";
			}
			else
			{
				document.getElementById(sDivID).style.display = "none";
				img="document." + sImgID + ".src='images/icons/plus.gif'";
			}
		}
	}
	eval(img);
}

function sidebarShow(menu){
	var sideTitle=new Array();
	sideTitle[0]='Account';
	sideTitle[1]='Quotes';
	sideTitle[2]='Trade';
	sideTitle[3]='Tools';
	
	var path = location.pathname;
	
	for(var i=0;i<sideTitle.length;i++){
		if(menu != sideTitle[i]){
			if(path.indexOf('xguides')!=-1){
				var title = 'xguide' + sideTitle[i];
				var row = 'tr' + sideTitle[i];
				RowsShowHide(title,row,'1');
			}
			else if(path.indexOf('tour')!=-1){
				var title = 'tour' + sideTitle[i];
				var row = 'tr' + sideTitle[i];
				if(document.getElementById(row + '0')){
					RowsShowHide(title,row,'1');
				}
			}
		}
	}
}
	
function setMenuItem(){	
	var path = location.pathname; 
	var pageName = path.split("/").pop().split(".")[0];
	if(path.indexOf('careers/index')!=-1){
		if(document.getElementById('careers')){
			document.getElementById('careers').className = 'active';	
		}
	}
	if(path.indexOf('media/index')!=-1){
		if(document.getElementById('media')){
			document.getElementById('media').className = 'active';	
		}
	}
	if(path.indexOf('investing101/why')!=-1){
		if(document.getElementById('whyOptions')){
			document.getElementById('whyOptions').className = 'active';	
		}
	}
	if(path.indexOf('futures/why')!=-1){
		if(document.getElementById('whyFutures')){
			document.getElementById('whyFutures').className = 'active';	
		}
	}
	if(path.indexOf('calendarspread_short')!=-1){
		if(document.getElementById('calendarspread')){
			document.getElementById('calendarspread').className = 'active';	
		}
	}
	if(path.indexOf('condor_short')!=-1){
		if(document.getElementById('condor')){
			document.getElementById('condor').className = 'active';	
		}
	}
	if(path.indexOf('straddle_short')!=-1){
		if(document.getElementById('straddle')){
			document.getElementById('straddle').className = 'active';	
		}
	}
	if(path.indexOf('strangle_short')!=-1){
		if(document.getElementById('strangle')){
			document.getElementById('strangle').className = 'active';	
		}
	}
	if(document.getElementById(pageName)){
		document.getElementById(pageName).className = 'active';
	}
	if(location.search){ 
		var vals = (unescape((location.search.substring(1).replace(/\+/g," "))).split("&")) 
		for(i=0;i<vals.length;i++){ 
			vals[i]=vals[i].split("=") 
			if(vals[i][0]=='SubPageID'){
				var subPageID = eval("'"+vals[i][1]+"'");
			}
			else if(vals[i][0]=='lstList'){
				var subPageID = eval("'"+vals[i][1]+"'");
			}
			else if(vals[i][0]=='PageID'){
				var subPageID = eval("'"+vals[i][1]+"'");
			}
		}
		if(document.getElementById(subPageID)){
			document.getElementById(subPageID).className = 'active';
		}
	}
}	


//-----------------------------------------------------------------------------
// sortTable(id, col, rev)
//This function works with the ID of the TBODY element to be sorted.
//  col - Index of the column to sort, 0 = first column, 1 = second column,
//        etc.
//  rev - If true, the column is sorted in reverse (descending) order
//        initially.
//
// Note: the team name column (index 1) is used as a secondary sort column and
// always sorted in ascending order.
//-----------------------------------------------------------------------------

function sortTable(id, col, rev, format) {

  // Get the table or table section to sort.
  var tblEl = document.getElementById(id);

  // The first time this function is called for a given table, set up an
  // array of reverse sort flags.
  if (tblEl.reverseSort == null) {
    tblEl.reverseSort = new Array();
    tblEl.lastColumn = 1;
  }

  // If this column has not been sorted before, set the initial sort direction.
  if (tblEl.reverseSort[col] == null)
    tblEl.reverseSort[col] = rev;

  // If this column was the last one sorted, reverse its sort direction.
  if (col == tblEl.lastColumn)
    tblEl.reverseSort[col] = !tblEl.reverseSort[col];

  // Remember this column as the last one sorted.
  tblEl.lastColumn = col;

  // Set the table display style to "none" - necessary for Netscape 6 
  // browsers.
  var oldDsply = tblEl.style.display;
  tblEl.style.display = "none";

  // Sort the rows based on the content of the specified column using a
  // selection sort.

  var tmpEl;
  var i, j;
  var minVal, minIdx;
  var testVal;
  var cmp;

  for (i = 0; i < tblEl.rows.length - 1; i++) {

    // Assume the current row has the minimum value.
    minIdx = i;
    minVal = getTextValue(tblEl.rows[i].cells[col]);

    // Search the rows that follow the current one for a smaller value.
    for (j = i + 1; j < tblEl.rows.length; j++) {
      testVal = getTextValue(tblEl.rows[j].cells[col]);
      cmp = compareValues(minVal, testVal);
      // Negate the comparison result if the reverse sort flag is set.
      if (tblEl.reverseSort[col])
        cmp = -cmp;
      // Sort by the second column (team name) if those values are equal.
      if (cmp == 0 && col != 1)
        cmp = compareValues(getTextValue(tblEl.rows[minIdx].cells[1]),
                            getTextValue(tblEl.rows[j].cells[1]));
      // If this row has a smaller value than the current minimum, remember its
      // position and update the current minimum value.
      if (cmp > 0) {
        minIdx = j;
        minVal = testVal;
      }
    }

    // By now, we have the row with the smallest value. Remove it from the
    // table and insert it before the current row.
    if (minIdx > i) {
      tmpEl = tblEl.removeChild(tblEl.rows[minIdx]);
      tblEl.insertBefore(tmpEl, tblEl.rows[i]);
    }
  }

  // Make it look pretty.
  if(format==null || format==''){
	  makePretty(tblEl, col);
  }

  // Restore the table's display style.
  tblEl.style.display = oldDsply;

  return false;
}

//-----------------------------------------------------------------------------
// Functions to get and compare values during a sort.
//-----------------------------------------------------------------------------

// This code is necessary for browsers that don't reflect the DOM constants
// (like IE).
if (document.ELEMENT_NODE == null) {
  document.ELEMENT_NODE = 1;
  document.TEXT_NODE = 3;
}

function getTextValue(el) {

  var i;
  var s;

  // Find and concatenate the values of all text nodes contained within the
  // element.
  s = "";
  if(el!=null){
  for (i = 0; i < el.childNodes.length; i++)
    if (el.childNodes[i].nodeType == document.TEXT_NODE)
      s += el.childNodes[i].nodeValue;
    else if (el.childNodes[i].nodeType == document.ELEMENT_NODE &&
             el.childNodes[i].tagName == "BR")
      s += " ";
    else
      // Use recursion to get text within sub-elements.
      s += getTextValue(el.childNodes[i]);

  return normalizeString(s);
  }
}

function compareValues(v1, v2) {

  var f1, f2;

  // If the values are numeric, convert them to floats.

  f1 = parseFloat(v1);
  f2 = parseFloat(v2);
  if (!isNaN(f1) && !isNaN(f2)) {
    v1 = f1;
    v2 = f2;
  }

  // Compare the two values.
  if (v1 == v2)
    return 0;
  if (v1 > v2)
    return 1
  return -1;
}

// Regular expressions for normalizing white space.
var whtSpEnds = new RegExp("^\\s*|\\s*$", "g");
var whtSpMult = new RegExp("\\s\\s+", "g");

//modify or replace comparison strings here.
function normalizeString(s) {
  s = s.replace(whtSpMult, " ");  // Collapse any multiple whites space.
  s = s.replace(whtSpEnds, "");   // Remove leading or trailing white space.
  if(s.indexOf(',')!=-1){
  	s = s.replace(/,/g, '');   // Remove commas.
  }
  if(s.indexOf('-') > 0){
  	s = s.replace(/-/g, '');   // Remove dashes (-).
  }
  if(s.indexOf('$')!=-1){
  	s = s.replace(/\$/g, '');   // Remove $.
  }
  if(s.indexOf('(')!=-1){
  	s = s.replace(/\(/g, '-');   // Remove (.
  }
  s = s.toLowerCase();  // Convert to lower case

return s;
}

//-----------------------------------------------------------------------------
// Functions to update the table appearance after a sort.
//-----------------------------------------------------------------------------

// Style class names.
var rowClsNm = "datarow2_sm";
var colClsNm = "datarow_sm";

// Regular expressions for setting class names.
var rowTest = new RegExp(rowClsNm, "gi");
var colTest = new RegExp(colClsNm, "gi");

function makePretty(tblEl, col) {

  var i, j;
  var rowEl, cellEl;

  // Set style classes on each row to alternate their appearance.
  for (i = 0; i < tblEl.rows.length; i++) {
   rowEl = tblEl.rows[i];
   rowEl.className = rowEl.className.replace(rowTest, "");
    if (i % 2 != 0)
      rowEl.className += " " + rowClsNm;
    rowEl.className += " " + colClsNm;
    // Set style classes on each column (other than the name column) to
    // highlight the one that was sorted.
    for (j = 2; j < tblEl.rows[i].cells.length; j++) {
      cellEl = rowEl.cells[j];
      cellEl.className = cellEl.className.replace(colTest, "");
      if (j == col)
        cellEl.className += " " + colClsNm;
      cellEl.className = normalizeString(cellEl.className);
    }
  }

  // Find the table header and highlight the column that was sorted.
//  var el = tblEl.parentNode.tHead;
//  rowEl = el.rows[el.rows.length - 1];
  // Set style classes for each column as above.
//  for (i = 2; i < rowEl.cells.length; i++) {
 //   cellEl = rowEl.cells[i];
 //   cellEl.className = cellEl.className.replace(colTest, "");
    // Highlight the header of the sorted column.
  //  if (i == col)
  //    cellEl.className += " " + colClsNm;
  //    cellEl.className = normalizeString(cellEl.className);
 // }
}

//Set subTab on profile pages w/URL parameter.  Pass subTab=... in url.
function setSubTab(){
	var path = window.location.search.substring(1);
	var Parameters = new Object(); 
	var sNameValuePairs = path.split('&'); 
	var sNameValuePair; 
	for (var i = 0; i < sNameValuePairs.length; i++) { 
 	   sNameValuePair = sNameValuePairs[i].split('='); 
	   Parameters[sNameValuePair[0]] = sNameValuePair[1];
	} 

	switch (Parameters['subTab']) { 
	   case "account" : 
	      subMenu2('first'); 
	      break; 
	   case "home" : 
	      subMenu2('second'); 
	      break; 
	   case "mail" : 
	      subMenu2('third'); 
	      break; 
	   case "contact" : 
	      subMenu2('fourth'); 
	      break; 
	   case "income" : 
	      subMenu2('fifth'); 
	      break; 
	   case "employment" : 
	      subMenu2('sixth'); 
	      break; 
	   case "email" : 
	      subMenu2('first'); 
	      break; 
	   case "messages" : 
	      subMenu2('second'); 
	      break; 
	   case "format" : 
	      subMenu2('third'); 
	      break; 
	   case "paper" : 
	      subMenu2('fourth'); 
	      break; 
	   case "trading" : 
	      subMenu2('first'); 
	      break; 
	   case "status" : 
	      subMenu2('second'); 
	      break; 
	   case "chains" : 
	      subMenu2('third'); 
	      break; 
	   case "layout" : 
	      subMenu2('fourth'); 
	      break; 		  
	   default : 
	      break;
	} 
}

var x=0;
//DM 4/21/05 - disable buttons. test for scroll to bottom of iframe agreement. enable buttons. different scroll detect for different browsers.
function checkScrollEnd(){
	if(document.getElementById("lblMsg")){
		document.getElementById("lblMsg").style.display = 'block';
	}
	// Disable controls - specify controls and actions to be disabled until scroll on page
    DisableControls();
 
	var yScroll;
	if (window.frames[0]== null) return;
	if (window.frames[0].pageYOffset)	{  // all except Explorer
		yScroll = window.frames[0].pageYOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop != 'undefined'){// Explorer 6 Strict
	
		var agt = navigator.userAgent.toLowerCase(); 
		if(agt.indexOf("mac")!=-1 && agt.indexOf('msie') != -1){
			yScroll = document.frames[0].document.body.scrollTop;  
		} 
		else {
			yScroll = frames[0].document.documentElement.scrollTop;
		}
	}
	else if (document.body) {// all other Explorers	
		yScroll = frames[0].document.body.scrollTop;
	}	 
	var yHeight
	var test1 = top.frames[0].document.body.scrollHeight;
	var test2 = top.frames[0].document.body.offsetHeight
	if (test1 > test2){ // all but Explorer Mac	
		yHeight = top.frames[0].document.body.scrollHeight;
	}
	else {// Explorer Mac;
		//would also work in Explorer 6 Strict, Mozilla and Safari	
		yHeight = frames[0].document.body.offsetHeight;
	}
		 
	var frameHeight = fHeight(); //set fHeight function on page - return frame height + 10 (typically 260 or 210)

	if(yScroll > (yHeight - frameHeight)){
		//Enable controls - specify controls and actions to be enabled when scroll completes - put function on page
		EnableControls();

		if (x == 0) { //in case back is pressed, we should not display message
			document.getElementById("lblMsg").style.display = 'none';
		}
		else {
			scrollFade();
		}
	} 
	else {
	    x = x + 1;
		setTimeout("checkScrollEnd();", 500);
	}
}
hex=0; // Initial color value.

function scrollFade(){ 
  if(hex<255) { //If color is not white yet
    hex+=11; // increase color darkness
    document.getElementById("lblMsg").style.color= "rgb(255,"+hex+","+hex+")";
    setTimeout("scrollFade()",75); 
  }
  else	
    hex=0; //reset hex value
}

// SV 8/22/06 Functions to swap out screenshots in site tour. 
function largeImg(imgNum){
	document.getElementById("small" + imgNum).style.display = "none";
	document.getElementById("large" + imgNum).style.display = "block";
}
	
function smallImg(imgNum){
	document.getElementById("large" + imgNum).style.display = "none";
	document.getElementById("small" + imgNum).style.display = "block";
}

//SV 3/16/07 JS to run rebate rollover on stock preview page

var AccountTradeRebateHTML;
function hideTradeRebate(){
	document.getElementById("divRebate").style.display = 'none';
}

function displayTradeRebate(el,onOff)
{
	//AccountTradeRebateHTML=document.getElementById("divRebate").innerHTML;
	//document.getElementById("divRebate").innerHTML = '<img id="loading" hspace="5" width="16" height="16" align="left" src="/images/icons/loading.gif" />';
	var curleft = curtop = 0;
	if (el.offsetParent) {
		curleft = el.offsetLeft;
        	curtop = el.offsetTop;
       		while (el = el.offsetParent) {
        		curleft += el.offsetLeft;
            		curtop += el.offsetTop;
        	}
	}
	if(onOff=='on'){
		document.getElementById("divRebate").style.display = '';
		var divWidth = document.getElementById("divRebate").offsetWidth;
		var divHeight = document.getElementById("divRebate").offsetHeight;
		curleft = curleft - divWidth;
		curtop = curtop - divHeight;
		document.getElementById("divRebate").style.left = curleft+'px';
		document.getElementById("divRebate").style.top = curtop+'px';
	}
	else{
		document.getElementById("divRebate").style.display = 'none';
	}
		
	//Add an ajax call to get the data about trade rebate
	var s =GetSessionID();
	if (s == '0')
	{
		s = document.getElementById("txtSessionID").value;

	}
	OXNetAccnt.TradePreview.ShowTradeRebateAccountData(s,"1",callback_ProcessTradeRebateData);
	//setTimeout('hideTradeRebate()',10000);
}


function callback_ProcessTradeRebateData(result)
{
	
	if (result.value.Initialized ==1)
	{
		document.getElementById("displayname").innerHTML=result.value.DisplayName;
		document.getElementById("CurrentSavings").innerHTML=result.value.CurrentSavings;
		document.getElementById("PendingSavings").innerHTML=result.value.PendingSavings;
		document.getElementById("LifeTimeSavings").innerHTML=result.value.LifeTimeSavings;
	}
	else
	{
		//alert('rebate data not returned');
		//var c=document.getElementById("divRebate");
		document.getElementById("divRebate").style.display = 'none';
	}
}

