var url = window.location + '';
if(url.indexOf('?') > -1){
	var urlParts = url.split('?');
	var path = urlParts[0];
	var qry = urlParts[1];
}else{
	var path = url;
	var qry = '';
}
if(path.indexOf('/') > -1){
	var pathParts = path.split('/');
	var pathPartsLen = pathParts.length;
	var pageOn = pathParts[pathPartsLen - 1];
	var subSection = pathParts[pathPartsLen - 2];
	var section = pathParts[pathPartsLen - 3];
  if(pageOn.indexOf('.') > -1){var pageName = pageOn.split('.')[0];}
  else{var pageName = pageOn;}
}
function req(variable) {
  var query = window.location.search.substring(1);
	var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
	  var pair = vars[i].split("=");
    if(pair[0] == variable){return pair[1];}
  }
}
function popwin(url,w,h,type){
	if(!w){w = 800;}
 	if(!h){h = 500;}
 	if(url){
  	if(type == 'nonav'){this.popWindow = window.open(url, 'pop_window', 'width='+w+',height='+h+',scrollbars=yes,menubar=0,status=no,toolbar=0,resizable=yes');}
  	else{this.popWindow = window.open(url, 'pop_window', 'width='+w+',height='+h+',scrollbars=yes,menubar=1,status=no,toolbar=1,resizable=yes');}
  	//if(this.popWindow){this.popWindow.focus();}
 	}
}
function ArrayLength(a){var ct = 0;for(var idx in a){ct++;}return ct;}
function linkTo(where,params,format) {
	// params is an arbitrary array of input variables i.e {symbol:'yhoo'}
	// Create condition for each external link
	var attb = {};
	if(where == 'quote'){
		if(params.nolink == 1){attb.href = 'javascript:void(0);';}
		else{attb.href = '/scottrade/research/common/symbolRedirect.asp?symbol=' + params.symbol;}
	}
	else if(where == 'buy_stock'){attb.href = 'https://trading.scottrade.com/myaccount/WatchLists.aspx?symbol=' + params.symbol;}
	else if(where == 'sell_stock'){attb.href = 'https://trading.scottrade.com/trade/StockOrderEntry.aspx?symbol=' + params.symbol;}
	else if(where == 'set_alert'){attb.href = 'https://trading.scottrade.com/myaccount/ManageAlerts.aspx?symbol=' + params.symbol;}
	else if(where == 'buy_fund'){attb.href = 'https://trading.scottrade.com/myaccount/WatchLists.aspx?symbol=' + params.symbol;}
	else if(where == 'sell_fund'){attb.href = 'https://trading.scottrade.com/trade/MutualFundOrderEntry.aspx?symbol=' + params.symbol;}
	if(format == 'showbubble'){
		attb.onEvent = 'onmouseover';
		attb.onEventFunc = "CreateStockBubble(this, '" + params.symbol + "', 175, 1)";
		attb.outEvent = 'onmouseout';
		attb.outEventFunc = 'CancelStockBubble()';
	}	
	return attb;
}
function linkToStr(where,params,format) {
	var href = '';
	if(where == 'quote'){
		if(params.nolink == 1){href = 'href="javascript:void(0);"';}
		else{
			if(path.indexOf("public") > -1){href = 'href="/public/common/symbolRedirect.asp?symbol='+params.symbol+'"';}
			else{href = 'href="/scottrade/research/common/symbolRedirect.asp?symbol='+params.symbol+'"';}
		}
	}
	else if(where == 'buy_stock'){href = 'href="https://trading.scottrade.com/myaccount/WatchLists.aspx?symbol='+params.symbol+'"';}
	else if(where == 'sell_stock'){href = 'href="https://trading.scottrade.com/trade/StockOrderEntry.aspx?symbol=' + params.symbol + '"';}
	else if(where == 'set_alert'){href = 'href="https://wtrading.scottrade.com/myaccount/ManageAlerts.aspx?symbol=' + params.symbol + '"';}
	if(format == 'showbubble'){href += ' onmouseover="CreateStockBubble(this, \''+ params.symbol +'\',175,1);"  onmouseout="CancelStockBubble();"';}	
	return href;
}
function GetScrollTop(){
	var scrollTop=document.body.scrollTop;
	if(scrollTop==0){if(window.pageYOffset){scrollTop=window.pageYOffset;}
  else{scrollTop=(document.body.parentElement)?document.body.parentElement.scrollTop:0;}}
  return scrollTop;
}
		if(window.pageYOffset){scrollTop=window.pageYOffset;}
overview = function(){
	this.textIn = Element.get("txtBox");
	this.advLink = Element.get("advCtrlLink");
	this.advCtrls = Element.get("advCtrl");
	this.advCaption = Element.get("advCaption");
	this.goBtn = Element.get("goBtn");
	this.ctrlsExpanded = false;
}
overview.prototype.Init = function(){
	if(this.textIn){
		Events.add({element:this.textIn,type:"focus",handler:this.Focus,context:this})
	  Events.add({element:this.textIn,type:"blur",handler:this.UnFocus,context:this})
	}
	if(this.advLink){Events.add({element:this.advLink,type:"click",handler:this.AdvControls,context:this})}
	if(this.goBtn){Events.add({element:this.goBtn,type:"click",handler:this.Validate,context:this})}
}
overview.prototype.Focus = function(evt, el){
  if(this.textIn){if(this.textIn.value == "Symbol(s) or Company Name"){this.textIn.value = '';}}
  Events.cancel(evt);
}
overview.prototype.UnFocus = function(evt, el){
	if(this.textIn){if(this.textIn.value == '' || this.textIn.value == ' '){this.textIn.value = "Symbol(s) or Company Name";}}
	Events.cancel(evt);
}
overview.prototype.Validate = function(evt, el){
  if(this.textIn){
  	var val = this.textIn.value;
    if(val != "Symbol(s) or Company Name" && val != '' && val != ' '){return true;}
  }
  return false;
}
overview.prototype.AdvControls = function(evt, el){
	if(this.ctrlsExpanded){
		this.advCtrls.style.display = "none";
		this.advCaption.style.display = "none";
		this.advLink.innerHTML = "Find Symbol";
		this.advLink.className = "advLinkExp";
		this.ctrlsExpanded = false;
	} else {
		this.advCtrls.style.display = "block";
		this.advCaption.style.display = "block";
		this.advLink.innerHTML = "Close advanced search";
		this.advLink.className = "advLinkCol";
		this.ctrlsExpanded = true;
	}
}
function InitOverviewControls(){var ovCtrls = new overview();ovCtrls.Init();}
if(subSection == "overview"){Events.add({element:window,type:"load",handler:InitOverviewControls})}
var bubbleDelay = '';
var delayTime = 1000;
var trigEl = '';
var newSymbol = '';
var newWidth = '';
var newCloseout = '';
var newScottradeSymbol = '';
function CallCreate(){StockBubble.Create(trigEl, newSymbol, newWidth, newCloseout, newScottradeSymbol);}
function CreateStockBubble(e, symbol, width, closeout, scottradeSymbol){
	if(!StockBubble.isBubbleShowing){
		trigEl = e;
		newSymbol = symbol;
		newWidth = width;
		newCloseout = closeout;
		newScottradeSymbol = scottradeSymbol;
		bubbleDelay = setTimeout('CallCreate()', delayTime);
	}
}
function CancelStockBubble(){StockBubble.Cancel();window.clearTimeout(bubbleDelay);}
function CreateOptionBubble(e, symbol, width, closeout, scottradeSymbol){
	StockBubble.isOption = true;
	CreateStockBubble(e, symbol, width, closeout, scottradeSymbol);
}
var CancelOptionBubble = CancelStockBubble;
StockBubble = function(){this.bubble;	this.isBubbleShowing = false; this.isOption = false;}
StockBubble.prototype.Cancel = function(){
	try{
		this.bubble.CancelBubble();
		this.bubble.DelayBubblePop();
		this.isBubbleShowing = false;
	} catch(e){}
}
StockBubble.prototype.Create = function(e, symbol, width, closeout, scottradeSymbol){
	var xy = Element.getXY(e);
	var size = Element.getSize(e);
	var inputs = Element.parseSelector("form input");
	if(!inputs) inputs = Element.parseSelector("input");
	var selects  = document.getElementsByTagName("select");
	this.bubble = new InfoBubble();
	this.bubble.bubbleWidth = 220;
	if(xy.y < 140) this.FlipBubble();
	if(selects || inputs){
		if(selects){for(var i = 0; i < selects.length; i++){if(this.Collision(e, selects[i], width)) this.FlipBubble();}}
		if(inputs){for(var i = 0; i < inputs.length; i++){if(inputs[i].id != "symbol"){if(this.Collision(e, inputs[i], width)) this.FlipBubble();}}}
	}
	if(typeof(width) != "undefined") this.bubble.bubbleWidth = width;
	if(!closeout){this.bubble.enableRollOutPop = false;}
	this.bubble.enablePopDelay = true;
	this.bubble.PopDelayTime = 500;
	this.bubble.Init();
	this.bubble.AttachBubble(document.getElementsByTagName("body")[0]);
	this.bubble.MoveBubble(xy.x, xy.y, size);
	this.bubble.scottradeSymbol = scottradeSymbol;
	this.bubble.BlowStockBubble(symbol, this.isOption, e.id);
	this.bubble.MoveBubble(xy.x, xy.y, size);
	this.isBubbleShowing = true;
}
StockBubble.prototype.Collision = function(trigEl, avoidEl, width){
	var aXY = Element.getXY(avoidEl);
	var aSize = Element.getSize(avoidEl);
	var tXY = Element.getXY(trigEl);
	if(width == "undefined") width = this.bubble.bubbleWidth;
	
	if((tXY.y - aXY.y) < 150){
		var startOfTrigEl = tXY.x + Math.round(this.bubble.bubbleWidth / 2);
		if(startOfTrigEl > aXY.x){
			var xDis = tXY.x - Math.round(width/2);
			var endOfAvoidEl = aXY.x + aSize.width;
			if(xDis < endOfAvoidEl) return true;
			else return false;
		}
		else return false;
	}
	else return false;
}

StockBubble.prototype.FlipBubble = function(){
	this.bubble.SetPoint("top");
	this.bubble.floatDistance = 3;
}
StockBubble = new StockBubble();

// --------------- Info Bubble --------------------
InfoBubble = function(){
	this.floatDistance = 0;
	this.driftDistance = 0;
	this.closeButton = true;
	this.bubbleWidth = 150;
	this.enableRollOutPop = true;
	this.enableRollOn = true;
	this.enablePopDelay = false;
	this.ShowDelayTime = 500;
	this.PopDelayTime = 2000;
	this.title = "";
	this.scottradeSymbol;
	
	// Private
	this._whichPoint = "center";
	this._created = false;
	this._createTimeout = 0;
	this._popTimeout = 0;

	// bubble pieces
	this._mainDiv = Element.create("div", {id:"infoBubble", className:"ibFloatContainer"});
	
	// bubble top
	this._topDiv = Element.create("div", {id:"ibTopContainer", className:"ibFloatContainer"}, "", this._mainDiv);
	this._topLftCorner = Element.create("div", {id:"ibTopLftCorner", className:"ibFloatDiv"});
	this._topCenter = Element.create("div", {className:""});
	this._topCenter2 = Element.create("div", {className:"ibTopTopCenter ibFloatDiv"});
	this._topRtCorner = Element.create("div", {id:"ibTopRtCorner", className:"ibFloatDiv"});
	
	// bubble mid
	this._midDiv = Element.create("div", {id:"ibMidContainer", className:"ibFloatContainer"}, "", this._mainDiv);
	this._contentDiv = Element.create("div", {id:"ibContentContainer"});
	this._titleDiv = Element.create("div", {id:"bubbleTitle"});
	this._closeBtn = Element.create("a", {id:"bubbleClose", href:"#"});
	
	// bubble bottom
	this._bottomDiv = Element.create("div", {id:"ibBottomContainer", className:"ibFloatContainer"}, "", this._mainDiv);
	this._bottomLftCorner = Element.create("div", {id:"ibBottomLftCorner", className:"ibFloatDiv"});
	this._bottomCenter = Element.create("div", {className:"ibBottomCenter ibFloatDiv"});
	this._bottomCenter2 = Element.create("div", {className:"ibBottomCenter ibFloatDiv"});
	this._bottomRtCorner = Element.create("div", {id:"ibBottomRtCorner", className:"ibFloatDiv"});
	this._point = Element.create("div", {id:"", className:"ibFloatDiv"});
	
	this.buffer = new ContentBuffer();
	this.serializer = new Serializer();
}

InfoBubble.prototype.Init = function(){
	this._AttachEvents();
	this._CreateBubble();
	this._mainDiv.style.visibility = "hidden";
}
InfoBubble.prototype._AttachEvents = function(){
	Events.add({element:this._closeBtn,type:"click",handler:this.PopBubble,context:this});
	if(this.enableRollOn){Events.add({element:this._mainDiv,type:"mouseover",handler:this.BlowBubble,context:this});}
	if(this.enableRollOutPop){
		if(this.enablePopDelay){Events.add({element:this._mainDiv,type:"mouseout",handler:this.DelayBubblePop,context:this});}
		else{Events.add({element:this._mainDiv,type:"mouseout",handler:this.PopBubble,context:this});}
	}
}
InfoBubble.prototype.AttachBubble = function(el){Element.addChild(el, this._mainDiv);}

InfoBubble.prototype._CreateBubble = function(){
	Element.setWidth(this._mainDiv, this.bubbleWidth);
	this._CreateBubbleTop();
	this._CreateBubbleContent();
	this._CreateBubblePoint();
	this._created = true;
	this._AdjustBubble();
}
InfoBubble.prototype._CreateBubbleTop = function(){
	Element.addChild(this._topDiv, this._topLftCorner);
	Element.addChild(this._topDiv, this._topCenter);
	if(this._whichPoint == "top"){
		this._topLftCorner.setAttribute("id", "ibTopTopLftCorner");
		this._topCenter.className = "ibTopTopCenter ibFloatDiv";
		this._topRtCorner.setAttribute("id", "ibTopTopRtCorner");
		this._point.setAttribute("id", "topCenterPoint");
		Element.addChild(this._topDiv, this._point);
		Element.addChild(this._topDiv, this._topCenter2);
	}
	else{
		this._topCenter.id = "ibTopCenter";
		this._topCenter.className="ibFloatDiv";
	}
	Element.addChild(this._topDiv, this._topRtCorner);
}
InfoBubble.prototype._CreateBubbleContent = function(){
	if(this.title == ""){
		Element.addChild(this._midDiv, this._contentDiv);
		if(this.closeButton) Element.addChild(this._midDiv, this._closeBtn);
	}
	else{
		this._titleDiv.innerHTML = this.title;
		if(this.closeButton){
			Element.addChild(this._midDiv, this._closeBtn);
			this._closeBtn.id = "bubbleCloseTitle";
		}
		Element.addChild(this._midDiv, this._titleDiv);
		Element.addChild(this._midDiv, this._contentDiv);
	}
}
InfoBubble.prototype._CreateBubblePoint = function(){
	Element.addChild(this._bottomDiv, this._bottomLftCorner);
	if(this._whichPoint == "center"){
		this._point.id = "centerPoint";
		Element.addChild(this._bottomDiv, this._bottomCenter);
		Element.addChild(this._bottomDiv, this._point);
		Element.addChild(this._bottomDiv, this._bottomCenter2);
	}
	else if(this._whichPoint == "right"){
		this._point.id = "rightPoint";
		Element.addChild(this._bottomDiv, this._bottomCenter);
		Element.addChild(this._bottomDiv, this._point);
	}
	else if(this._whichPoint == "left"){
		this._point.id = "leftPoint";
		Element.addChild(this._bottomDiv, this._point);
		Element.addChild(this._bottomDiv, this._bottomCenter);
	}
	else{Element.addChild(this._bottomDiv, this._bottomCenter);}
	Element.addChild(this._bottomDiv, this._bottomRtCorner);
}
InfoBubble.prototype._RecreateBubblePoint = function(){
	this._CreateBubblePoint();
	this._AdjustBubblePoint();
}
InfoBubble.prototype._AdjustBubble = function(){
	this._AdjustBubbleTop();
	this._AdjustBubbleContent();
	this._AdjustBubblePoint();
}
InfoBubble.prototype._AdjustBubbleTop = function(){
	Element.setWidth(this._topDiv, this.bubbleWidth);	
	if(this._whichPoint == "top"){
		centerWidth = Math.floor((this.bubbleWidth - 22) / 2);  // 22 = the top corners (4px width) and the point width
		Element.setWidth(this._topCenter, centerWidth);
		Element.setWidth(this._topCenter2, centerWidth);
	}
	else{
		var cornersWidth = 6 * 2;	
		Element.setWidth(this._topCenter, (this.bubbleWidth - cornersWidth));
	}
}
InfoBubble.prototype._AdjustBubbleContent = function(){
	Element.setWidth(this._midDiv, (this.bubbleWidth - 5));
	if(this.closeButton) Element.setWidth(this._contentDiv, (this.bubbleWidth - 20));
	else{Element.setWidth(this._contentDiv, this.bubbleWidth - 7);}
}
InfoBubble.prototype._AdjustBubblePoint = function(){
	var centerWidth;
	Element.setWidth(this._bottomDiv, this.bubbleWidth);
	if(this._whichPoint == "center"){	
		centerWidth = Math.floor((this.bubbleWidth - 28) / 2);
		Element.setWidth(this._bottomCenter, centerWidth);
		Element.setWidth(this._bottomCenter2, centerWidth);
	}
	else if(this._whichPoint == "left" || this._whichPoint == "right"){
		Element.setWidth(this._point, 20);
		centerWidth = this.bubbleWidth - 32;  // minus the corners and point
		Element.setWidth(this._bottomCenter, centerWidth);
	}
	else{ // no point
		centerWidth = this.bubbleWidth - 12;  // minus the corners
		Element.setWidth(this._bottomCenter, centerWidth);
	}
}
InfoBubble.prototype.SetContent = function(content){
	if(typeof content != "undefined"){
		if(this._contentDiv.hasChildNodes()) Element.removeChildNodes(this._contentDiv);
		Element.addChild(this._contentDiv, content);
		this._titleDiv.innerHTML = this.title;
	}
}
InfoBubble.prototype.SetPoint = function(type){
	if(typeof type != "undefined"){
		type = type.toLowerCase();
		if(type == "middle" || type == "center") this._whichPoint = "center";
		else if(type == "right") this._whichPoint = "right";
		else if(type == "left") this._whichPoint = "left";
		else if(type == "no" || type == "" || type == "none") this._whichPoint = "none";
		else if(type == "top") this._whichPoint = "top";
		else this._whichPoint = "none";	
		if(this._created) this._RecreateBubblePoint();
	}
}

InfoBubble.prototype.PopBubble = function(ev, el){
	this._mainDiv.style.visibility = "hidden";
	window.clearTimeout(this._createTimeout);
	if(ev){Events.cancel(ev);}
}
InfoBubble.prototype.DelayBubblePop = function(){
	if(this._popTimeout == 0){
  	var thisC = this;
		this._popTimeout = setTimeout(function(){thisC.PopBubble();}, this.PopDelayTime);
	}
}
InfoBubble.prototype.BlowBubble = function(){
	if(this.enablePopDelay && this._popTimeout > 0){
		window.clearTimeout(this._popTimeout);
		this._popTimeout = 0;
	}
	this._mainDiv.style.visibility = "visible";
}
InfoBubble.prototype.DelayBlowBubble = function(){
	var thisC = this;
	this._createTimeout = setTimeout(function(){thisC.BlowBubble();}, this.ShowDelayTime);
}
InfoBubble.prototype.BlowStockBubble = function(symbol, isOption, id){
	if(typeof(symbol) != "undefined"){
		if(this._contentDiv.hasChildNodes()) Element.removeChildNodes(this._contentDiv);		
		Element.create("div", {style:"text-align:center;"}, "Loading...", this._contentDiv);
		this.DelayBlowBubble();
		if(path.indexOf("public") > -1){var url = "../../common/buffer/infoBubbleBuffer.asp";}
		else if(path.indexOf("quotelist") > -1){var url = "../common/buffer/infoBubbleBuffer.asp";}
		else{var url = "../../common/buffer/infoBubbleBuffer.asp";}
		var cbObj = {
			url: url,
			data: {sym:symbol},
			contentType: "text/javascript",
			onload: this.LoadBubble,
			onerror: this.ErrorBubble,
			method: "post",
			debug: true,
			context: this
		};
		if(isOption){cbObj.data = {sym:symbol, isOption:true};this.elId = id;}
		this.buffer.load(cbObj);		
	}
}
InfoBubble.prototype.CancelBubble = function(){window.clearTimeout(this._createTimeout);}
InfoBubble.prototype.LoadBubble = function(buffer){
	var result = this.serializer.deserialize(buffer.getResult());
	if(result){
		var currentHeight = Element.getSize(this._mainDiv).height;
		if(this._contentDiv.hasChildNodes()){Element.removeChildNodes(this._contentDiv);}
		if(result.isOption){this.LoadOptionContent(result);}
		else{this.LoadStockContent(result);}
	}else{Element.addChild(div, "No Symbol Found");}
	var pos = Element.getXY(this._mainDiv);
	var newHeight = currentHeight + Element.getSize(this._mainDiv).height;
	if(!result.entitlements){pos.y = pos.y - (Math.round(newHeight / 2)) - 1;}
	else{pos.y = pos.y - (Math.round(newHeight / 2)) - 1;}
	Element.setXY(this._mainDiv, pos.x, pos.y);
}
InfoBubble.prototype.LoadStockContent = function(result){
	var div = Element.create("div", {}, "", this._contentDiv);
	if(typeof(result.exchg) != "undefined"){	
		var tickerDiv = Element.create("div", {className:"companyName"}, "", div);
		if(this.scottradeSymbol){var symbol = this.scottradeSymbol;}
		else{var symbol = result.symbol;}
		if(symbol[symbol.length - 1] == ' '){while(symbol.charAt(symbol.length-1) == " "){symbol = symbol.substring(0,symbol.length-1);}}
		Element.create("a", {href:"../../stocks/snapshot/snapshot.asp?symbol=" + symbol, style:"font-weight:bold"}, symbol, tickerDiv);
		if(typeof(result.exchg) == "undefined"){Element.addChild(tickerDiv, ": Symbol not found");}
		else{Element.addChild(tickerDiv, ':' + result.exchg);}
		Element.create("p", {className:"companyName"}, result.name, div);
		var p = Element.create("p", {id:"infoBar"}, "", div);
		Element.addChild(p, result.last);
		Element.addChild(p, "&nbsp;");
		Element.addChild(p, "&nbsp;");
		if(result.issue != "MF"){
			Element.addChild(p, result.change);
			Element.addChild(p, "&nbsp;");
			Element.addChild(p, "&nbsp;");
			Element.addChild(p, result.changePct);
		}
		if(!result.entitlements){
			if(result.exchg == "NASDAQ"){Element.create("p", {className:"companyName", style:"font-size:7pt"}, "Market data is delayed by at least 15 minutes.", div);}
			else{Element.create("p", {className:"companyName", style:"font-size:7pt"}, "Market data is delayed by at least " + result.delay + " minutes.", div);}
		}
		else{Element.create("p", {className:"asofDate", style:"font-size:7pt; margin-bottom:5px;"}, "as of " + result.lastDate, div);}
		if(result.issue != "MF"){
			if(result.issue != "ETF" && result.issue != "ETN"){Element.create("a", {href:'../../stocks/news/news.asp?symbol=' + symbol}, "Search all News for " + symbol, div);}
		  Element.create("hr", {}, "", div);
		  if(result.issue == "ETF" || result.issue == "ETN"){var href = '../../etf/summary/summary.asp';}
		  else{	var href = '../../stocks/snapshot/snapshot.asp';}
		  href += '?symbol=' + symbol;
		  Element.create("a", {href:href}, "More Research", div);
		  Element.create("br", {}, "", div);
		}
		if(result.tier != "public"){
			if(result.issue == "MF" || result.issue == "MMF"){var href = linkTo('sell_fund', {symbol:symbol})}
			else{var href = linkTo('sell_stock', {symbol:symbol})}
			Element.create("a", {href:href.href, target:"_parent"}, "Trade", div);
			Element.create("br", {}, "", div);
			var href = linkTo('set_alert', {symbol:symbol})
			Element.create("a", {href:href.href, target:"_parent"}, "Set Alert", div);
		}
	}
	else{Element.addChild(div, "No Symbol Found");}
}
InfoBubble.prototype.LoadOptionContent = function(result){
	var table = Element.create('table', {className:"mb5",width:"100%",cellspacing:0,cellpadding:0,border:0}, '', this._contentDiv);
	var tbody = Element.create('tbody',{},'',table);
	var tr = Element.create('tr',{},'',tbody);
	var td = Element.create('td',{},'',tr);
	var a = Element.create('a', {id:this.elId, href:"javascript:void(0)"}, result.displaySymbol, td);
	ops.AddLink(a);
	Element.create('td',{className:'bold'},result.strikePrice + ' ' + result.chainType,tr);
	//Element.create('td',{},result.lot,tr);
	tr = Element.create('tr',{},'',tbody);
	Element.create('td',{className:'sGryTxt'},'&nbsp;',tr);
	Element.create('td',{className:'sGryTxt'},'Strike Price',tr);
	//Element.create('td',{className:'sGryTxt'},'Multiplier',tr);
	if(result.tier != "public"){
		var tableSize = "48%";
	  table = Element.create('table', {className:'dataTable floatLft',width:tableSize,cellspacing:0,cellpadding:0,border:0}, '', this._contentDiv);
	  tbody = Element.create('tbody',{},'',table);
	  tr = Element.create('tr',{},'',tbody);
	  Element.create('td',{},'Delta',tr);
	  Element.create('td',{align:"right"},result.delta,tr);
	  tr = Element.create('tr',{},'',tbody);
	  Element.create('td',{},'Gamma',tr);
	  Element.create('td',{align:"right"},result.gamma,tr);
	  tr = Element.create('tr',{},'',tbody);
	  Element.create('td',{},'Rho',tr);
	  Element.create('td',{align:"right"},result.rho,tr);
	  table = Element.create('table', {className:'dataTable floatRt',width:tableSize,cellspacing:0,cellpadding:0,border:0}, '', this._contentDiv);
	  tbody = Element.create('tbody',{},'',table);
	  tr = Element.create('tr',{},'',tbody);
	  Element.create('td',{},'Theta',tr);
	  Element.create('td',{align:"right"},result.theta,tr);
	  tr = Element.create('tr',{},'',tbody);
	  Element.create('td',{},'Vega',tr);
	  Element.create('td',{align:"right"},result.vega,tr);
	  tr = Element.create('tr',{},'',tbody);
	  Element.create('td',{},'Impd Volatility',tr);
	  Element.create('td',{align:"right"},result.impliedVol,tr);
	  Element.create('div', {className:"clear"}, '', this._contentDiv);
	}
	if(!result.entitlements){
		if(result.exchg == "NASDAQ"){Element.create("p", {className:"companyName", style:"font-size:7pt"}, "Market data is delayed by at least 15 minutes.", this._contentDiv);}
		else{Element.create("p", {className:"companyName", style:"font-size:7pt"}, "Market data is delayed by at least " + result.delay + " minutes.", this._contentDiv);}
	}else{Element.create("p", {className:"asofDate", style:"font-size:7pt; margin-bottom:5px;"}, "as of " + result.lastDate, this._contentDiv);}
	var div = Element.create('div',{className:"floatLft"}, '', this._contentDiv);
	var text = 'Get Option Quote';if(result.tier != 'public'){text += ' &amp; Chart';}
	a = Element.create('a', {id:this.elId, href:"javascript:void(0)"}, text, div);
	ops.AddLink(a);
	if(result.tier != "public"){
		//var href = linkTo('sell_stock', {symbol:result.displaySymbol});
		var href = 'https://trading.scottrade.com/trade/OptionOrderentry.aspx?symbol=' + result.displaySymbol;
		div = Element.create('div',{className:"floatRt"},'', this._contentDiv);
		Element.create('a',{href:href, target:"_parent",className:"bold"}, "Trade", div);
	}
	Element.create('div', {className:"clear"}, '', this._contentDiv);
}
InfoBubble.prototype.MoveBubble = function(x, y, triggerSize, locked){
	var browser = navigator.appVersion;
	var ieBrowser = false;
	if(browser.indexOf("MSIE 6.0") > -1 || browser.indexOf("MSIE 5.5") > -1){ieBrowser = true;}
	if(typeof(triggerSize) != "undefined"){
		if(locked) locked = locked.toLowerCase();
		var size = Element.getSize(this._mainDiv);		
		var xPos;
		var yPos;
		if(this._whichPoint == "center" || this._whichPoint == "none" || this._whichPoint == "top"){
			xPos = (x - (Math.round(size.width / 2) + this.driftDistance)) + (Math.round(triggerSize.width / 2));	
		}else if(this._whichPoint == "left"){
			xPos = (x + 15) + this.driftDistance;
		}else{
			xPos = (x - size.width) + this.driftDistance;
		}
		if(this._whichPoint == "top"){
			if(locked == 'y') yPos = y;
			else{
				yPos = y + ((size.height + this.floatDistance) * 2);
				yPos = yPos + 8;
			}
		}
		else{
			yPos = y - (size.height + this.floatDistance);
			if(!ieBrowser){yPos = yPos - 8;}
		}
		Element.setXY(this._mainDiv, xPos, yPos);
	}
	else{Element.setXY(this._mainDiv, x, y);}
}
InfoBubble.prototype.MoveBubbleAbs = function(x, y){	Element.setXY(this._mainDiv, x, y);}
InfoBubble.prototype.IsBubbleCreated = function(){return this._created;}
InfoBubble.prototype.IsBubbleShowing = function(){
	if(this._mainDiv.style.visiablity == "visable") return true;
	else return false;
}
InfoBubble.prototype.GetBubblePosition = function(){return Element.getXY(this._mainDiv);}
InfoBubble.prototype.GetBubbleSize = function(){return Element.getSize(this._mainDiv);}
// --------------- Quick Quote --------------------
QuickQuote = function(){
	this.symbolInput = Element.get("symbol");
	this.goBtn = Element.get("qqGoBtn");
	this.symbolForm = Element.get("frmQuickQuote");
	this.dataContainer = Element.get("qqDataContainer");
	this.indexTable = Element.get("qqIndexDataContainer");
	this.symbolContainer = Element.create("div", {id:"symbolContainer"});
	this.refreshBtn = Element.get("refresh");
	this.detailedBtn  = Element.get("detailedBtn");
	this.btnContainer = Element.get("qqBtnContainer");
	this.marketMessage = Element.get("marketMessage");
	this.symbol = "";
	this.buffer = new ContentBuffer();
	this.serializer = new Serializer();
}
QuickQuote.prototype.attachEvents = function(){
	Events.add({element:this.refreshBtn,type:"click",handler:this.refreshQuote,context:this});
	Events.add({element:this.goBtn,type:"click",handler:this.getQuote,context:this});
	Events.add({element:this.symbolForm,type:"submit",handler:this.getQuote,context:this});
	Events.add({element:this.symbolInput,type:"focus",handler:this.clearField,context:this});
	Events.add({element:this.symbolInput,type:"blur",handler:this.fillField,context:this});
	Events.add({element:this.detailedBtn,type:"click",handler:this.getDetailed,context:this});
}
QuickQuote.prototype.clearField = function(){
	this.symbolInput.value = "";
}
QuickQuote.prototype.fillField = function(){
	if(this.symbolInput.value == "" || this.symbolInput.value == " "){
		this.symbolInput.value = "Symbol or Name";
	}
}
QuickQuote.prototype.refreshQuote = function(event, trigEl){
	this.buffer.load({
		url: "/scottrade/research/common/buffer/quickquoteBuffer.asp",
		data:{sym: this.symbol},
		contentType: "text/javascript",
		onload: this.redrawQuote,
		onerror: this.errorQuote,
		method: "post",
		context: this
	});	
	Events.cancel(event);
}
QuickQuote.prototype.getQuote = function(event, trigEl){
	if(this.symbolInput.value){	
		this.buffer.load({
			url: "/scottrade/research/common/buffer/quickquoteBuffer.asp",
			data:{sym:this.symbolInput.value},
			contentType: "text/javascript",
			onload: this.redrawQuote,
			onerror: this.errorQuote,
			method: "post",
			context: this
		});	
	}
	this.symbol = this.symbolInput.value;
	Events.cancel(event);
}
QuickQuote.prototype.getDetailed = function(event, el){
	if(this.symbol){
		document.location.href = "../../stocks/snapshot/snapshot.asp?symbol=" + this.symbol;
	}
	else if(this.symbolInput.value){
		if(this.symbolInput.value != "Symbol or Name"){
			document.location.href = "../../stocks/snapshot/snapshot.asp?symbol=" + this.symbolInput.value;
		}
	}
	
	Events.cancel(event);
}
QuickQuote.prototype.redrawQuote = function (buffer) {
	var result = this.serializer.deserialize(buffer.getResult());
	var showQuote;
	if(typeof result.symbolQuote != "undefined"){
		showQuote = true;
		Element.removeChildNodes(this.symbolContainer);
		var div = Element.create("div", {id:"qqSymbolName"}, result.symbolQuote.name.toUpperCase(), this.symbolContainer);
		var childern = new Array("Price: ", " ", result.symbolQuote.last, " ", result.symbolQuote.change, " ", result.symbolQuote.changePct);
		div = Element.create("div", {id:"qqSymbolPrice"}, childern, this.symbolContainer);
		var divs = Array(Element.create("div", {className:"qqSymbolFloatDivs qqValueTitles"}, "Bid"), Element.create("div", {className:"qqSymbolFloatDivs"}, result.symbolQuote.bid));
		Element.create("div", {className:"qqSymbolFloatContainer"}, divs, this.symbolContainer);
		divs = Array(Element.create("div", {className:"qqSymbolFloatDivs qqValueTitles"}, "Ask"), Element.create("div", {className:"qqSymbolFloatDivs"}, result.symbolQuote.ask));
		Element.create("div", {className:"qqSymbolFloatContainer"}, divs, this.symbolContainer);
		divs = Array(Element.create("div", {className:"qqSymbolFloatDivs qqValueTitles"}, "Open"), Element.create("div", {className:"qqSymbolFloatDivs"}, result.symbolQuote.open));
		Element.create("div", {className:"qqSymbolFloatContainer"}, divs, this.symbolContainer);
		divs = Array(Element.create("div", {className:"qqSymbolFloatDivs qqValueTitles"}, "Volume"), Element.create("div", {className:"qqSymbolFloatDivs"}, result.symbolQuote.volume));
		Element.create("div", {className:"qqSymbolFloatContainer"}, divs, this.symbolContainer);
		var a = Element.create("a", {target:'_parent', href:"https://trading.scottrade.com/trade/StockOrderEntry.aspx?symbol=" + this.symbol}, "TRADE NOW");
		div = Element.create("div", {id:"qqTradeNow"}, a, this.symbolContainer);
	}
	else if(result.error){
		showQuote = true;
		Element.removeChildNodes(this.symbolContainer);
		var span = Element.create("span", {className:"searchText"}, result.textIn);
		var p = Element.create("p", {id:"errorText"}, "", this.symbolContainer);
		Element.addChild(p, span);
		Element.addChild(p, " was not found.");
		p = Element.create("p", {id:"errorText"}, "", this.symbolContainer);
		var a = Element.create("a", {href:result.errorLink, style:'color:blue'} , "click here");
		Element.addChild(p, "To do a search for ");
		span = Element.create("span", {className:"searchText"}, result.textIn);
		Element.addChild(p, span);
		Element.addChild(p, ", ");
		Element.addChild(p, a);
	}
	else{
		showQuote = false;
		if(this.symbolContainer.hasChildNodes()) Element.removeChildNodes(this.symbolContainer);
	}
	if(result.quotes.length == 3){
		var tr = this.indexTable.getElementsByTagName("tr");
		for(var i = 0; i < tr.length; i++){
			Element.removeChildNodes(tr[i]);
			var td = Element.create("td");
			var span = Element.create("span", {className: "qqCoName"});
			Element.addChild(span, result.quotes[i].name);
			Element.addChild(td, span);
			Element.addChild(td, Element.create("br"));
			Element.addChild(td, result.quotes[i].last);
			Element.addChild(tr[i], td);
			td = Element.create("td", {align:"right", valign:"bottom", className:"changeTd"});
			Element.addChild(td, result.quotes[i].change);
			Element.addChild(tr[i], td);
		}
	}
	if(showQuote){
		Element.removeChildNodes(this.dataContainer);
		Element.addChild(this.dataContainer, this.symbolContainer);
		Element.addChild(this.dataContainer, this.btnContainer);
		Element.addChild(this.dataContainer, this.indexTable);
	}
	else{
		Element.removeChildNodes(this.dataContainer);
		Element.addChild(this.dataContainer, this.indexTable);
		Element.addChild(this.dataContainer, this.btnContainer);
	}
	
	Element.removeChildNodes(this.marketMessage);
	Element.addChild(this.marketMessage, result.marketMessage);
	Element.addChild(this.marketMessage, Element.create("br"));
	Element.addChild(this.marketMessage, result.quoteDate);
	Element.addChild(this.marketMessage, " ");
	Element.addChild(this.marketMessage, result.quoteTime);
}
QuickQuote.prototype.errorQuote = function(){
	window.status = "Sorry. Error retrieving market data.";
}
/* Initialize */
function initQuickQuoteModule(){
	try {
		var qq = new QuickQuote();
		qq.attachEvents();
	} catch(e) {}
}
Events.add({element:window,type:"load",handler:initQuickQuoteModule});
var ltBox = false;
var LightBox = function(url, width, height, title){
	var main = Element.get("main");var body = document.getElementsByTagName("body")[0];
	this.width = width;this.height = height;
	if(!url){this.url = "../../common/lib/lightbox/blank.asp";}
	else{this.url = url;}
  this.title = "Scottrade";
  if(title){this.title = title;}
  this.shade = Element.create('div',{id:"shade"}, '', body);
  this.shade.style.height = Element.getSize(Element.get("rightRail")).height + 'px';//(screen.height + GetScrollTop()) + 'px';
  this.mainPanel = Element.create('div',{id:"floatPanel"},'',main);
  this.mainPanel.style.top = GetScrollTop() + 30 + "px";
  this.mainPanel.style.left = 500 - (width / 2) + "px";
  this.titlePane = Element.create('div',{id:"titlePane", style:"border-bottom:1px solid #938D7D;"},'',this.mainPanel);this.titlePane.style.width = width + "px";
  this.closeLink = Element.create('a',{href:"javascript:void(0)"},"Close");
  Events.add({element:this.closeLink,type:"click",handler:this.Close,context:this});
  this.closeImg = Element.create('a',{href:"javascript:void(0)"},Element.create('img',{src:"../../common/img/buttons/close.gif",alt:"close", border:"0",style:"vertical-align:middle;margin-left:5px;"}));
  Events.add({element:this.closeImg,type:"click",handler:this.Close,context:this});
  this.closeBox = Element.create('div',{id:"closeBox"},'',this.titlePane);this.closeBox.style.width = "60px";this.closeBox.style.textAlign = "right";
  Element.addChild(this.closeBox, this.closeLink);
  Element.addChild(this.closeBox, this.closeImg);
  this.titleBox = Element.create('div',{id:"titleBox",className:"floatLft"}, this.title,this.titlePane);this.titleBox.style.width = (parseInt(width) - 120) + "px";
  Element.create('div', {className:"clear"}, '', this.titlePane);
  this.frame = Element.create('iframe',{src:this.url,frameborder:0,border:0,height:this.height + 10,width:this.width}, '', this.mainPanel);//this.contentPane);
  this.frame.frameBorder = 0;this.frame.scrolling = "no";this.frame.marginWidth = 0;
  
  this.shade.style.display = "block";
}
LightBox.prototype.Update = function(url, width, height, title){
	this.width = width;
	this.height = height;
	this.title = title;
	this.titleBox.innerHTML = title;
	this.url = url;
	this.frame.width = width;
	this.frame.height = height;
	this.frame.src = url;
	if(this.mainPanel.style.display == "none"){this.mainPanel.style.display = "block";}
}
LightBox.prototype.Close = function(){
	this.shade.style.display = "none";
	this.mainPanel.style.display = "none";
	this.frame.src = "../../common/charts/blank.html";
	ltBox = false;
}

function OpenLightBox(url, width, height, title){
	if(!ltBox){ltBox = new LightBox(url, width, height, title);}
	else{ltBox.Update(url, width, height, title);}
}

function CloseLightBox(){
	if(ltBox){ltBox.Close();}
	else{parent.ltBox.Close();}
}

function LBCheck(){
	var lb = req("openlb");
  if(lb){
  	if(lb == "tutorials"){
  		OpenLightBox("../../knowledgecenter/media/tutorials.asp", 930, 740, "Tutorial");
  	}
  	else if(lb == "webcast"){
  		var item = req("item");
  		OpenLightBox("../../knowledgecenter/media/media.asp?channel=Webcast&docKey=" + item, 795, 570, "Media Center");
  	}
  	else if(lb == "quiz"){
  		var item = req("item");
  		OpenLightBox("../../knowledgecenter/media/media.asp?channel=Quizzes&docKey=" + item, 795, 570, "Media Center");
  	}
  }
}
Events.add(window,"load",LBCheck);

var termBubbles = [];
function OpenKnowledgeBubble(el, term, symbol){
	for(var terms in termBubbles){
		termBubbles[terms].PopBubble();
	}
	
	if(!termBubbles[term]){
		var width = 300;
		termBubbles[term] = new InfoBubble();
		termBubbles[term].bubbleWidth = width;
		termBubbles[term].title = term;
		
		var xy = Element.getXY(el);
	  var size = Element.getSize(el);
	  var inputs = Element.parseSelector("form input");
	  if(!inputs) inputs = Element.parseSelector("input");
	  var selects  = document.getElementsByTagName("select");
	  if(xy.y < 230){Flip();}
	  if(selects || inputs){
		  if(selects){for(var i = 0; i < selects.length; i++){if(Collision(el, selects[i], width)) Flip();}}
		  if(inputs){for(var i = 0; i < inputs.length; i++){if(inputs[i].id != "symbol"){if(Collision(el, inputs[i], width)) Flip();}}}
	  }
		
		termBubbles[term].Init();
		termBubbles[term].AttachBubble(Element.get("main"));
		
		var GetData = function(buffer){
			var serializer = new Serializer();
			var results = serializer.deserialize(buffer.getResult());
			//alert(results);
			if(!results){results = "No data available";}
			termBubbles[term].title = results.title;
			termBubbles[term].SetContent(results.html);
			var xy = Element.getXY(el);
		  var size = Element.getSize(el);
		  if(termBubbles[term]._whichPoint == "top"){xy.y = xy.y - 495;}
		  termBubbles[term].MoveBubble(xy.x, (xy.y + 15), size);
		  termBubbles[term].BlowBubble();
		}
		
		var cb = new ContentBuffer();
	  cb.load({
			url: "../../common/buffer/kc_bubbleBuffer.asp",
			data:{term: term, sym: symbol},
			contentType: "text/javascript",
			method:"post",
			onload:GetData,
			onerror:Error,
		  debug:true
		});
	}
	else{
		termBubbles[term].BlowBubble();
	}
	
	function Flip(){
		termBubbles[term].SetPoint("top");
	  termBubbles[term].floatDistance = 3;
	}
	
	function Collision(trigEl, avoidEl, width){
	  var aXY = Element.getXY(avoidEl);
	  var aSize = Element.getSize(avoidEl);
	  var tXY = Element.getXY(trigEl);
	  if(width == "undefined") width = termBubbles[term].bubbleWidth;
	
	  if((tXY.y - aXY.y) < 150){
		  var startOfTrigEl = tXY.x + Math.round(termBubbles[term].bubbleWidth / 2);
		  if(startOfTrigEl > aXY.x){
			  var xDis = tXY.x - Math.round(width/2);
			  var endOfAvoidEl = aXY.x + aSize.width;
			  if(xDis < endOfAvoidEl) return true;
			  else return false;
		  }
		  else return false;
	  }
	  else return false;
	}
}
function CloseKnowledgeBubble(el, term){
	if(termBubbles[term]){
		termBubbles[term].PopBubble();
	}
}

loader_js = function() { }
loader_js.prototype.showLoading = function(container,gifPos,whichIcon) {
	var size = Element.getSize(container);
	var pos = Element.getXY(container);
	//We can position the loading gif (0=center,1=top,2=bottom)
	if(gifPos==1) {
		var topPosOfImg = 60; //show the gif near the top
	} else if(gifPos==2) {
		var topPosOfImg = (parseInt(size.height - 30)); //show the gif near the bottom
	} else {
		var topPosOfImg = (parseInt(size.height / 2 - 16)); //center loading gif
	}
	var leftPos = (parseInt(size.width / 2 - 16)); //centered
	//which icon to use
	if (whichIcon==1) {
		var iconSource = '../../common/img/loading/loading.gif';
	} else {
		var iconSource = '../../common/img/loading/purple-loading.gif';
	}
	//create new transparent div and attach to DOM
	var indicator = Element.create('div',{id:'loading_'+container,'class': 'loadingIndicator',style:'top:'+pos.y+'px;left:'+pos.x+'px;height:'+size.height+'px;width:'+size.width+'px'},'', document.body);
	//create new loading gif and attach to new div
	var graphic = Element.create('img', {src:iconSource, style:'position:absolute;top:'+topPosOfImg+'px;left:'+leftPos+'px;'}, '', indicator);
}
loader_js.prototype.hideLoading = function(container) { Element.remove('loading_'+container); }
loader = new loader_js();

function notebookAdd(type, value){
	
	alert("in");
	
	var buffer = new ContentBuffer();
	
	var cbObj = {
		url : "../common/buffer/notebookBuffer.asp"
		,data : {type: type, value: value}
		,onload : display
		,onerror : error
		,method : "post"
		};
	
	buffer.load(cbObj);
	
	function error(){
		alert("error");
	}
	function display(buffer){
		var results = buffer.getResult();
		alert(results);
	}

}