if(typeof SbWeb=="undefined"||SbWeb==null)SbWeb={};if(typeof SbWeb.UI=="undefined"||SbWeb.UI==null)SbWeb.UI={};var $wl=SbWeb.UI.WatchList=new function(){var config={dataUrl:"",addUrl:"",resultsId:"",expandMode:0,longListBreak:10,longListMax:25,isAuth:false,loginLink:"",investNowLink:"",addStocksNowLink:"",detailViewPLink:"",detailViewWLink:"",viewWatchListLink:"",transferWatchListLink:"",symbolTradeURL:"",symbolInvestURL:"",symbolOptionURL:"",symbolGetQuoteURL:"",symbolUp:"",symbolDown:"",symbolNoChange:"",imgWLIcon:"",unauthMsgWL:"Keep an eye on the stocks, ETFs and mutual funds you want with the Watch List.",unauthMsgP:"View the stocks and other holdings in your portfolio.",emptyMsgWL:"Keep an eye on the stocks, ETFs and mutual funds you want with our new Watch List.",emptyMsgWLImport:"Check out our new and improved Watch List.<div class=\"VSpace5\"></div>Want to keep the stocks from your old Watch List? ",emptyMsgP:"There are no stocks or other holdings in this account's portfolio.",genericError:"Information temporarily unavailable.",currentListId:"",WLcookieExpiration:365,WLcookieName:"sbWatchListSelectedId",ImportCookieName:"researchWatchList",dataRetrieved:false,renderOneTimeRefresh:true,data:new Array(),addSymbolListeners:new Array()};this.Initialize=function Initialize(dataUrl,resultsContainerId,isAuth,linkPath,loginLink,imagePath,symbolup,symboldown,symbolnochange){config.dataUrl=dataUrl;if(isAuth>0){config.isAuth=true}config.loginLink="<a href=\""+loginLink+"\">Log In now &gt;</a>";config.investNowLink="<a href=\""+linkPath+"Trade/\">Invest now &gt;</a>";config.detailViewPLink="<a href=\""+linkPath+"Account/Portfolio/Positions.aspx\">Detailed view &gt;</a>";config.detailViewWLink="<a href=\""+linkPath+"Research/Tools/Watchlist.aspx\">Detailed view &gt;</a>";config.viewWatchListLink="<a href=\""+linkPath+"Research/Tools/Watchlist.aspx\">View Watch List &gt;</a>";config.transferWatchListLink="<a href=\""+linkPath+"Research/Tools/Watchlist.aspx\">Transfer now &gt;</a>";config.symbolTradeURL=linkPath+"Trade/OrderStatus/TradeDecision.aspx";config.symbolInvestURL=linkPath+"Research/MarketUpdate/GetQuote.aspx";config.symbolOptionURL=linkPath+"Trade/Options/optionstradedecision.aspx";config.symbolGetQuoteURL=linkPath+"Research/MarketUpdate/GetQuote.aspx";config.symbolUp=imagePath+symbolup;config.symbolDown=imagePath+symboldown;config.symbolNoChange=imagePath+symbolnochange;config.imgWLIcon="<img src=\""+imagePath+"icons/Watchlist_16x16.gif\" width=\"16px\" height=\"16px\" alt=\"\" />";this.SwitchTabs(resultsContainerId)};this.InitializeAddSymbol=function(addUrl){config.addUrl=addUrl};this.SwitchTabs=function(tab){var divWatchList=document.getElementById("divwatchlist");var divPortfolio=document.getElementById("divportfolio");switch(tab){case"watchlist":divWatchList.style.display="block";divPortfolio.style.display="none";break;case"portfolio":divWatchList.style.display="none";divPortfolio.style.display="block";break}this.GetTabExpandMode();config.resultsId="#div"+tab;this.SetTabCookie(tab+config.expandMode);if(config.isAuth){if(config.dataRetrieved){this.Render()}else{this.GetData()}}else{this.FormatUnauthMsg()}};this.SetTabCookie=function(value){var ExpireDate="";document.cookie="wpSelectedIndex="+value+"; path=/; domain=sharebuilder.com;"};this.GetTabExpandMode=function(){var currCookie=$.cookie("wpSelectedIndex");if((currCookie==null)||(currCookie=="")){config.expandMode=0}else{config.expandMode=currCookie.substr(currCookie.length-1)}};this.CheckImportCookie=function(){var testCookie=$.cookie(config.ImportCookieName);if((testCookie==null)||(testCookie=="")){return false}else{return true}};this.GetCookieSelectedListId=function(){var varList=$.cookie(config.WLcookieName);if((varList==null)||(varList=="")){config.currentListId="";if(config.data.WLs.length>0){if(config.data.WLs[0].list.length>0){config.currentListId=config.data.WLs[0].id;this.SetCookieSelectedListId(config.currentListId)}}}else{config.currentListId=varList}};this.SetCookieSelectedListId=function(id){config.currentListId=id;$.cookie(config.WLcookieName,config.currentListId,{expires:config.WLcookieExpiration,path:"/",domain:"sharebuilder.com"})};this.RefreshData=function(){if(config.dataUrl.length>0){$.getJSON(config.dataUrl,function(json){config.data=json;if(config.data.isAuth){config.dataRetrieved=true;SbWeb.UI.WatchList.GetCookieSelectedListId();SbWeb.UI.WatchList.Render()}else{this.FormatUnauthMsg()}})}};this.ChangeList=function(listId){var i=this.GetIndexFromId(listId);if(i>=0){this.SetCookieSelectedListId(listId);this.Render()}};this.GetData=function(){config.data=SbWeb.Research.WatchListData;if(config.data.isAuth){config.dataRetrieved=true;SbWeb.UI.WatchList.GetCookieSelectedListId();SbWeb.UI.WatchList.Render()}else{this.FormatUnauthMsg()}};this.Render=function(){if((config.data["errors"]!=null)&&(config.data["errors"]!=false)){if(config.data.isAuth){$(this.FormatError()).appendTo(config.resultsId)}else{if(config.renderOneTimeRefresh){config.renderOneTimeRefresh=false;this.GetData()}else{this.FormatUnauthMsg()}}}else{if(config.resultsId.toLowerCase().indexOf("portfolio")<0){$(this.FormatData(config.currentListId,(config.expandMode==0)?config.longListBreak:config.longListMax)).appendTo(config.resultsId)}else{$(this.FormatData("p",(config.expandMode==0)?config.longListBreak:config.longListMax)).appendTo(config.resultsId)}}};this.ReRender=function(id,limit){$(this.FormatData(id,limit)).appendTo(config.resultsId)};this.FormatData=function(dataId,limit){var bAddExpandCollapse=false;var ecItemsToShow=0;var ecButtonClass="";var ecText="";var data;var count=0;var output="";if(dataId=="p"){if(config.data.p!=null){data=config.data.p;count=data.length}}else{var listIndex=this.GetIndexFromId(dataId);if(listIndex>=0){data=config.data.WLs[listIndex].list;count=data.length}else{if((config.data.WLs!=null)&&(config.data.WLs.length>0)){data=config.data.WLs[0].list;count=data.length}}}$(config.resultsId).empty();if((data!=null)&&(data.length>0)){if(limit<count){count=limit;bAddExpandCollapse=true;ecItemsToShow=data.length;ecButtonClass="ButtonExpand";config.expandMode=0;if(dataId=="p"){ecText="Expand to show more"}else{ecText="Expand to show all"}}else{if((limit>config.longListBreak)&&(count>config.longListBreak)){bAddExpandCollapse=true;ecItemsToShow=config.longListBreak;ecButtonClass="ButtonCollapse";ecText="Switch to compact view";config.expandMode=1;if(limit>config.longListMax){count=config.longListMax}}}if(config.resultsId.toLowerCase().indexOf("portfolio")<0){this.SetTabCookie("watchlist"+config.expandMode);if(config.data.WLs.length>1){output+=this.AddWLDropDown()}output+=this.AddTableHeaderFooter(config.detailViewWLink,true)}else{this.SetTabCookie("portfolio"+config.expandMode);output+=this.AddTableHeaderFooter(config.detailViewPLink,false)}output+="<tbody>";for(i=0;i<count;i++){if(data[i]!=null){output+="<tr";if((data[i+1]==null)&&(!bAddExpandCollapse)){output+=" class=\"rl\""}if(i==0){output+=" class=\"r1\""}output+=">";output+="<td class=\"PadL5\"><span>";output+="<a href=\""+config.symbolGetQuoteURL+"?Symbol="+data[i].s+"\">"+data[i].s+"</a></span>&nbsp;</td>";var tempQuote=data[i].q;var strQuote="&nbsp;";var nullQuote=false;if(tempQuote!=null){strQuote=this.FormatCurrency(tempQuote,true)}else{nullQuote=true;strQuote="N/A"}output+="<td class=\"AlignRight\"><span>"+strQuote+"</span></td>";var classUpDownText="";var strIconImgUp="<img src=\""+config.symbolUp+"\" width=\"7px\" height=\"8px\" class=\"Indicator\" alt=\"value increased\" />";var strIconImgDown="<img src=\""+config.symbolDown+"\" width=\"7px\" height=\"8px\" class=\"Indicator\" alt=\"value decreased\" />";var strIconImgNoChange="<img src=\""+config.symbolNoChange+"\" width=\"7px\" height=\"8px\" class=\"Indicator\" alt=\"no change in value\" />";var tempChange=data[i].c;var strChange="&nbsp;";if((tempChange!=null)&&(!nullQuote)){if(tempChange>0){classUpDownText="ChangeUp";}else if(tempChange<0){classUpDownText="ChangeDn";}else{classUpDownText="ChangeNC";}strChange+=this.FormatCurrency(tempChange,false)}else if(nullQuote){strChange="N/A"}output+="<td class=\"AlignRight\"><span class=\""+classUpDownText+"\">"+strChange+"</span></td>";output+="<td class=\"PadL10\">";if(data[i].lt=="1"){output+="<a href=\""+config.symbolTradeURL+"?stock="+data[i].s+"\">Trade</a>"}else if(data[i].lt=="2"){output+="<a href=\""+config.symbolTradeURL+"?Symbol="+data[i].s+"\">Invest</a>"}else if(data[i].lt=="3"){output+="<a href=\""+config.symbolOptionURL+"?Symbol="+data[i].s+"\">Trade</a>"}else{output+="&nbsp;"}output+="</td>";if((i<count-1)||(bAddExpandCollapse)){output+="</tr>\n<tr><td colspan=\"4\" class=\"rowsepModule\"><div>&nbsp;</div></td></tr>"}else{output+="</tr>\n"}}}if(bAddExpandCollapse){output+="<tr class=\"rl\">";output+="<td colspan=\"4\" class=\"PadL5\">";output+="<div class=\""+ecButtonClass+"\" onmouseover=\"this.className='"+ecButtonClass+" Hover';\" onmouseout=\"this.className='"+ecButtonClass+"';\" onclick=\"SbWeb.UI.WatchList.ReRender('"+dataId+"', "+ecItemsToShow+");return false;\"><a href=\"#\" onclick=\"SbWeb.UI.WatchList.ReRender('"+dataId+"', "+ecItemsToShow+");return false;\">"+ecText+"</a></div>";output+="</td></tr>"}}else{if(config.resultsId.toLowerCase().indexOf("portfolio")>=0){output+=this.AddTableHeaderFooter(config.investNowLink,false)}else{if(config.data.WLs.length>1){output+=this.AddWLDropDown()}output+=this.AddTableHeaderFooter(config.detailViewWLink,true)}output+=this.AddNoItemsMsg()}output+="</tbody></table>";return output};this.FormatUnauthMsg=function(){$(config.resultsId).empty();var output=this.AddTableHeaderFooter(config.loginLink,false);output+="<tr><td colspan=\"4\" class=\"MsgBlock\"><div>";if(config.resultsId.toLowerCase().indexOf("portfolio")>=0){output+=config.unauthMsgP}else{output+="<div><span class=\"Bold\">ShareBuilder Watch List</span></div>";output+="<div>"+config.unauthMsgWL+"</div>"}output+="</div></td></tr>";output+="</tbody></table>";$(output).appendTo(config.resultsId)};this.FormatError=function(){$(config.resultsId).empty();var output="";if(config.resultsId.toLowerCase().indexOf("portfolio")<0){output+=this.AddTableHeaderFooter(config.detailViewWLink,true)}else{output+=this.AddTableHeaderFooter(config.detailViewPLink,false)}output+="<tr><td colspan=\"4\" class=\"MsgBlock\"><div>";output+=config.genericError;output+="</div></td></tr>";return output};this.AddWLDropDown=function(){var output="<div class=\"WLDropDown\">";output+="<span>View</span>";output+="<select id=\"selWLs\" class=\"DropDownInput LargeDropDown\" onchange=\"SbWeb.UI.WatchList.ChangeList(this.value);\">";for(var i=0;i<config.data.WLs.length;i++){output+="<option value=\""+config.data.WLs[i].id+"\"";if(config.data.WLs[i].id==config.currentListId){output+=" selected"}output+=">"+config.data.WLs[i].name+"</option>"}output+="</select></div>";return output};this.AddTableHeaderFooter=function(tfootLink,boolAddWLIcon){var output="<div class=\"Clear\"></div>";output+="<table class=\"WLPMod\" cellpadding=\"0\" cellspacing=\"0\">";output+="<thead><tr><th class=\"PadL5\">Symbol</th><th class=\"AlignRight\">";output+="Last";output+="</th><th class=\"AlignRight\">Change</th><th class=\"PadR5\">&nbsp;</th></tr></thead>";if(boolAddWLIcon){output+="<tfoot><tr><th colspan=\"4\" class=\"AlignRight PadR5 AdjustHeight\">";output+="<div class=\"divWLIcon\">"+config.imgWLIcon+"</div>"}else{output+="<tfoot><tr><th colspan=\"4\" class=\"AlignRight PadR5\">&nbsp;"}output+=tfootLink+"</th></tr></tfoot>";return output};this.AddNoItemsMsg=function(){var output="<tr><td colspan=\"4\" class=\"MsgBlock\">";if(config.resultsId.indexOf("portfolio")>=0){output+=config.emptyMsgP}else{output+="<div><span class=\"Bold\">ShareBuilder Watch List</span></div>";if(this.CheckImportCookie()){output+="<div>"+config.emptyMsgWLImport;output+=config.transferWatchListLink+"</div>"}else{output+="<div>"+config.emptyMsgWL+"</div>"}}output+="</td></tr>";return output};this.FormatCurrency=function(inputAmt,isQuote){var valueAmt=inputAmt;var strAmt="";if((valueAmt>=1000.0)||(valueAmt<=-1000.0)){var tempValue=valueAmt.toFixed(0).toString();var tempLength=tempValue.indexOf(".");if(tempLength<0){tempLength=tempValue.length}tempValue=tempValue.substring(0,tempLength);var strNew="";while(tempLength>3){strNew=","+tempValue.substring(tempLength-3,tempLength);tempValue=tempValue.substring(0,tempLength-3);tempLength=tempValue.length}if(tempLength>0){strNew=tempValue+strNew}strAmt=strNew}else if((valueAmt<1.0)&&(isQuote)){strAmt=valueAmt.toFixed(4)}else{strAmt=valueAmt.toFixed(2)}if(isQuote){strAmt="$"+strAmt}return strAmt};this.GetIndexFromId=function(currentId){if(config.data.WLs!=null){for(var i=0;i<config.data.WLs.length;i++){if(config.data.WLs[i].id==currentId){return i}}}return-1};this.RegisterAddSymbolListener=function(listener){config.addSymbolListeners.push(listener)};this.AddSymbol=function(symbol){if((window.location.href+"").indexOf("https:")!=-1){$.getJSON(config.addUrl+"?q="+symbol,function(json){var i;for(i=0;i<config.addSymbolListeners.length;i++)config.addSymbolListeners[i](json);if(json.status==$wl.AddSymbolStatusCodes.OK)$wl.RefreshData()})}else{var i;var d={};d.symbol=symbol;d.status=$wl.AddSymbolStatusCodes.FORBIDDEN;for(i=0;i<config.addSymbolListeners.length;i++)config.addSymbolListeners[i](d)}};this.AddSymbolStatusCodes={OK:0,FORBIDDEN:1,INVALID:2,FULL:3,FAILED:99}};jQuery.cookie=function(a,b,c){if(typeof b!='undefined'){c=c||{};if(b===null){b='';c.expires=-1}var d='';if(c.expires&&(typeof c.expires=='number'||c.expires.toUTCString)){var e;if(typeof c.expires=='number'){e=new Date();e.setTime(e.getTime()+(c.expires*24*60*60*1000))}else{e=c.expires}d='; expires='+e.toUTCString()}var f=c.path?'; path='+(c.path):'';var g=c.domain?'; domain='+(c.domain):'';var h=c.secure?'; secure':'';document.cookie=[a,'=',encodeURIComponent(b),d,f,g,h].join('')}else{var j=null;if(document.cookie&&document.cookie!=''){var k=document.cookie.split(';');for(var i=0;i<k.length;i++){var l=jQuery.trim(k[i]);if(l.substring(0,a.length+1)==(a+'=')){j=decodeURIComponent(l.substring(a.length+1));break}}}return j}};