1(function ($) { 2 _.mixin(_.str.exports()); 3 4 // $(document).ready fires too early in IE10 5 //document.addEventListener('DOMContentLoaded', function () { 6 $(document).ready(function () { 7 /* Navigation menu */ 8 var currentSubMenu = $('#nav li ul:visible'); 9 var subMenus = $('#nav li ul'); 10 var timeoutId; 11 $('#nav li div').mouseover(function () { 12 if (timeoutId) 13 clearTimeout(timeoutId); 14 var obj = this; 15 timeoutId = setTimeout(function () { 16 subMenus.hide(); 17 $(obj).parent().find("ul").show(); 18 }, 200); 19 20 }); 21 22 $('#nav li div').mouseleave(function () { 23 if (timeoutId) 24 clearTimeout(timeoutId); 25 }); 26 27 $('#nav').mouseleave(function () { 28 subMenus.hide(); 29 currentSubMenu.show(); 30 }); 31 32 /* User preferences */ 33 34 var userPrefsCode = $('#user_prefs'); 35 if (userPrefsCode.length > 0) { 36 $.params.userPrefs = $.parseJSON(userPrefsCode.text()); 37 userPrefsCode.remove(); 38 } 39 40 // TODO: Refactor this mess 41 42 if($.params.userPrefs.is_logged_in) { 43 44 /* Tab indexes */ 45 46 if($.params.userPrefs.is_demo) { 47 $.params.tabIndexes = { 48 balance: 0, 49 stock: 1, 50 option: 2, 51 basket: 3 52 } 53 } else { 54 $.params.tabIndexes = { 55 balance: 0, 56 stock: 1, 57 option: 2, 58 funds: 3, 59 basket: 4 60 } 61 } 62 63 /* Widgets Initialization */ 64 65 $.params.messageDom = $("#ajax-msg"); 66 $.params.messageDom.loading(); 67 68 $.params.ticket = $("#trade_ticket_tabs"); 69 $.params.ticket.tabs({ 70 select:function (e, ui) { 71 return !$(ui.tab).hasClass("disabled"); 72 } 73 }); 74 75 $.params.tradingDescription = $('.trading-description'); 76 $.params.tradingDescription.tradingDescription({ 77 getStatus: function(tab_id) { 78 var selected_tab = tab_id != null ? tab_id : $.params.ticket.tabs("option", "active"); 79 for(var i in $.params.tabIndexes) { 80 if($.params.tabIndexes[i] == selected_tab) { 81 return i; 82 } 83 } 84 return null; 85 } 86 }); 87 88 $.params.toggleBar = $("#ui-toggle-ticket"); 89 $.params.toggleBar.toggle_ticket(); 90 91 $.params.balanceTable = $("#ui-balance-table"); 92 $.params.balanceTable.balance_table(); 93 94 $.params.ticket.on('click','.balance-tab, .refresh-balance-btn', function(){ 95 $('#buying-power').hide(); 96 $('#trade-option-buying-power').hide(); 97 $.params.balanceTable.balance_table('refresh'); 98 }); 99 100 101 $.params.quoteForm = $("#ui-quote"); 102 $.params.opForm = $("#ui-op-form"); 103 104 $.params.streamer = null; 105 106 $.params.quoteForm 107 .quote_loader({ 108 container: $.params.quoteForm.next("div") 109 }) 110 .oc_loader({ 111 container: $("#ui-options-chain"), 112 set_data: function(action, leg) { 113 $.params.opForm.option_manipulate("setData", action, leg); 114 }, 115 bind_legs_refresh: function(syncronizer) { 116 $.params.opForm.on("option_manipulatemodification", function(evt, data) { 117 syncronizer($.params.opForm.option_manipulate("getOptionLegs")); 118 }); 119 } 120 }); 121 122 $("#ui-account-switch").account_switch({ 123 // Which dom holds the account no text 124 account_no:$(".account .account_no") 125 }); 126 127 $.params.opForm.option_manipulate({ 128 option_quantity: parseInt($.params.userPrefs.option_quantity, 10), 129 stock_quantity: parseInt($.params.userPrefs.stock_quantity, 10), 130 option_chain: $.params.quoteForm.data("oc_loader"), 131 qfs: $.params.qfs 132 }).option_trade(); 133 134 $.params.stForm = $("#ui-st-form"); 135 $.params.stForm.stock_manipulate().stock_trade({ 136 quote: $.params.quoteForm.data("quote_loader") 137 }); 138 139 $.params.mfForm = $("#ui-mf-form"); 140 $.params.mfForm.mutual_funds(); 141 142 $.params.queueTable = $(".ui-queue"); 143 $.params.queueTable.queues(); 144 145 $.params.orderTable = $("#ui-orders-container"); 146 $.params.orderTable.orders(); 147 148 $.params.orderTableNew = $("#ui-orders-new-container"); 149 $.params.orderTableNew.ordersNew(); 150 151 $.params.transactionsTable = $("#ui-transactions-container"); 152 $.params.transactionsTable.transactions(); 153 154 $.params.positionTable = $(".ui-position"); 155 $.params.positionTable.positions({ 156 addPrice: function(data) { 157 $.params.quoteForm.data("oc_loader").addPrice(data); 158 }, 159 getPrices: function() { 160 return $.params.quoteForm.data("oc_loader").prices; 161 } 162 }); 163 164 165 $.params.qpw = $('.ui-push-quote-widget'); 166 $.params.qpw.push_quote(); 167 168 $.params.accountPrefs = $('.account-prefs'); 169 $.params.accountPrefs.accountPrefs(); 170 171 $(".transfer_index #content").transferMoney(); 172 173 $(".btn_messages").messageCenter(); 174 175 } 176 177 // Initialization of overlay element
178 $.params.overlay = $("#overlay"); 179 $.ram.overlay = $.params.overlay.overlay({ 180 closeOnClick:true, 181 top: '5%', 182 fixed:true, 183 mask:{ 184 color:'#fff', 185 loadSpeed:200, 186 opacity:0.2 187 }, 188 onClose:function () { 189 $.params.overlay.find("#overlay-content").html(""); 190 }, 191 onBeforeLoad: function () { 192 193 } 194 }); 195 196 // Initialization of stand-alone elements 197 198 $("#stock_translation_trigger").click(function () { 199 $.params.overlay.width(700); 200 var url = $(this).attr("href"); 201 $.params.overlay.find("#overlay-content").load(url, function () { 202 $.params.overlay.data("overlay").load(); 203 $("div#stock_translation_container").tabs(); 204 $.params.overlay.find("#overlay-content iframe").load(function(){ 205 $(this).siblings(".load-bar").remove(); 206 }); 207 }); 208 209 return false; 210 }); 211 212 $("a[title].tooltip").tooltip({ 213 effect:"fade", 214 offset:[-5, 0] 215 }); 216 217 buildJQueryDialog($("a[title].dialog")); 218 219 $("input[title]").tooltip({ 220 effect:"fade", 221 offset:[-10, 0] 222 }); 223 224 $("a.youtube").click(function (evt) { 225 evt.preventDefault(); 226 var data = $.parseJSON($(this).next("code").html()); 227 228 var frame = $("<iframe />").attr(data); 229 230 $.params.overlay.find("#overlay-content").empty().append(frame); 231 $.params.overlay.data("overlay").load(); 232 }); 233 234 $("#header #nav .transfer_money a").click(function(evt) { 235 evt.preventDefault(); 236 var url = $(this).attr("href"); 237 var el = $.params.overlay; 238 var widget = el.data("overlay"); 239 el.find("#overlay-content").load(url, function () { 240 var prev_width = el.css("width"); 241 el 242 .css("width", "1000px") 243 .addClass("transfer"); 244 245 widget.load(); 246 247 el.on("onClose.transfer", function() { 248 el 249 .css("width", prev_width) 250 .removeClass("transfer") 251 .off("onClose.transfer"); 252 }); 253 }); 254 }); 255 256 var InvestViewOpener = function(link) { 257 this._link = $(link); 258 }; 259 260 InvestViewOpener.prototype = (new EventDispatcher()).extend({ 261 _link: null, 262 _link_parent: null, 263 _countdown_window: null, 264 _timer: 0, 265 _url: "/platforms/investview_params", 266 execute: function() { 267 var that = this; 268 269 this._link_parent = $(this._link).parent("li"); 270 this._link_parent.addClass("loading"); 271 272 this.addEventListener("dialog_stopped", $.proxy(this.stopLoading, this)); 273 274 $.post(this._url, $.proxy(this._processResponse, this)); 275 }, 276 _processResponse: function(response) { 277 var type = "error"; 278 279 if (response.status != "error") { 280 type = "success"; 281 } else { 282 $.params.messageDom.msg("show", type, response.message); 283 } 284 285 if(response.form) { 286 this._showIVMessage(this._getDisplayIVCallback(response.form)); 287 } else { 288 $.dialog(type, "<p>" + response.message + "</p>"); 289 this.dispatchEvent("dialog_stopped"); 290 } 291 }, 292 stopLoading: function() { 293 this._link_parent.removeClass("loading"); 294 295 if(this._countdown_window) { 296 this._countdown_window.dialog("close"); 297 } 298 299 clearTimeout(this._timer); 300 }, 301 _getDisplayIVCallback: function(form_text) { 302 var that = this; 303 304 return function() { 305 that._displayForm(form_text); 306 }; 307 }, 308 _showIVMessage: function(callback) { 309 var that = this; 310 311 this._countdown_window = $.dialog("Redirection", ""); 312 this._runCountdown(); 313 314 this.addEventListener("iv_before_open", function() { 315 callback(); 316 }); 317 318 $(".investview_now").live("click", function(e) { 319 e.preventDefault(); 320 321 that.dispatchEvent("dialog_stopped"); 322 that.dispatchEvent("iv_before_open"); 323 }); 324 325 var close_button = this._countdown_window 326 .siblings(".ui-dialog-titlebar") 327 .find(".ui-dialog-titlebar-close"); 328 329 close_button.click(function() { 330 that.dispatchEvent("dialog_stopped"); 331 }); 332 333 return false; 334 }, 335 _runCountdown: function() { 336 var message = this._link.siblings(":input[name*=IV_message]").val(); 337 var url = this._link.attr("href"); 338 var that = this; 339 340 var counter = 5; 341 342 (function countdown() { 343 if(counter > 0) 344 { 345 that._countdown_window.html(_.sprintf(message, counter, url)); 346 counter--; 347 that._timer = setTimeout(countdown, 1000); 348 } else { 349 that.dispatchEvent("iv_before_open"); 350 } 351 })(); 352 }, 353 _displayForm: function (form_text) { 354 var form = createHiddenForm(form_text).attr("target", "_newtab"); 355 356 $(document.body).append(form); 357 this._executeForm(form); 358 }, 359 _executeForm: function(form) { 360 var that = this; 361 form.submit(function(e) { 362 e.preventDefault(); 363 this.submit(); 364 form.remove(); 365 366 that.dispatchEvent("dialog_stopped"); 367 }).submit(); 368 } 369 }); 370 371 $("#header #nav .platforms_investview a").click(function(e) { 372 e.preventDefault(); 373 374 var ivo = new InvestViewOpener(this).init(); 375 ivo.execute(); 376 }); 377 378 $("#to-strategy-intro a").click(function () { 379 var a = $(this); 380 var url = a.attr("href"); 381 var strat = url.replace(/^.*?#/, ""); 382 url = url.replace(/#.*?$/, ""); 383 384 var section; 385 $.get(url, function (responseText) { 386 $(responseText).find("#lo_tab3 h3").each(function () { 387 var h3 = $(this); 388 if (h3.text().indexOf(strat) != -1) { 389 section = h3.add(h3.nextUntil("h3")); 390 return false; 391 } 392 }); 393 394 var html = "<div class='strat_section'>"; 395 $.each(section, function () { 396 html += $(this).outerHTML(); 397 }); 398 html += "</div>"; 399 400 $.params.overlay.find("#overlay-content").html(html); 401 $.params.overlay.data("overlay").load(); 402 }); 403 404 return false; 405 }); 406 407 $("#accounting-in-nav").click(function () { 408 var url = $(this).attr("href"); 409 $.params.overlay.width(960); 410 $.params.overlay.find("#overlay-content").load(url, function () { 411 $.params.overlay.data("overlay").load(); 412 }); 413 414 return false; 415 }); 416 417 418 $("#vstatements-in-nav").click(function () { 419 var url = $(this).attr("href"); 420 421 if($.browser.msie) { 422 var popup = window.open(url, "_blank", "height=1000,width=960,top=200,location=no,menubar=no,resizable=no"); 423 popup.focus(); 424 425 return false; 426 } 427 428 $.params.overlay.find("#overlay-content").load(url, function () { 429 $.params.overlay.data("overlay").load(); 430 }); 431 432 return false; 433 }); 434 435 436 $(".ajax").show(); 437 438 $("a.alien").click(function () { 439 var url = $(this).attr("href"); 440 var title = "Outbound link"; 441 var message = "You are about to leave ChoiceTrade's site and navigate to a site managed by Trade Accountant. Trade Accountant is a third-party business provider that operates separately from ChoiceTrade. The Trade Accountant site will launch in a separate window on your browser."; 442 $("<div />").attr('title', title).html(message).dialog({ 443 resizable:false, 444 modal:true, 445 buttons:{ 446 "Proceed":function () { 447 $(this).dialog("close"); 448 window.location.href = url; 449 }, 450 "Cancel":function () { 451 $(this).dialog("close"); 452 } 453 } 454 }); 455 return false; 456 }); 457 458 $("#liveHelp,.liveHelp").click(function () { 459 //window.open("https://wwws.choicetrade.com/livehelp.html", "hlp","location=0,status=0,scrollbars=0,width=300,height=100"). 460 //moveTo(200,200);
461 //return false; 462 463 464 window.open(encodeURI('https://oggchat2.icoa.com/cp?font=Verdana&fontsize=10pt&bgcolor=FFFFFF&cid=c08f011235beb8ca0135c51322040232&website=www.choicetrade.com&text=_oggchat-img1-on.png&height=450&width=380&r=' + document.referrer), 'OggChat', 'toolbar=0,scrollbars=1,location=0,status=0,menubar=0,resizable=1,width=380,height=450'); 465 return false; 466 467 468 var page = { 469 'host':'oggchat2.icoa.com', 470 'cid':'c08f011235beb8ca0135c51322040232', 471 'act':'c08f011235beb8ca0135c513210e0230', 472 'font':'Verdana', 473 'fs':'10pt', 474 //'popup_margin_top':'60px', /*The top margin of proactive chat window*/ 475 //'popup_margin_left':'40px', /*The left margin of proactive chat window*/ 476 //'img':'http://yourwebsite.com/yourproactivechatimage.jpg', /*Url of a custom image to use on proactive chats*/ 477 'p':'0' 478 }; 479 480 function mon() { 481 var base = (("https:" == document.location.protocol) ? "https://oggchat2.icoa.com" : "http://oggchat2.icoa.com"); 482 var url = base + "/js/monitor.js"; 483 var e = document.createElement('script'); 484 e.src = url; 485 e.type = 'text/javascript'; 486 document.getElementsByTagName('head')[0].appendChild(e); 487 } 488 489 if (window.addEventListener) { 490 window.addEventListener('load', mon, false); 491 } else if (window.attachEvent) { 492 window.attachEvent('onload', mon); 493 } 494 495 496 }); 497 498 $(".accordion").accordion({ 499 collapsible:true, 500 autoHeight:false, 501 active:false 502 }); 503 504 505 $("select[name*=AccountPreferences]").change(function () { 506 var nameAttr = $(this).attr('name'); 507 var patt = /autotrade/i; 508 var nameResult = nameAttr.match(patt); 509 var value = $(this).val(); 510 var prefSlug = nameAttr.split('][')[1]; 511 512 if(nameResult){ 513 return false; 514 } 515 516 // Use closure to keep id inside it immutable 517 (function(value, prefSlug) { 518 getDynamicMessageForNoAutotrade(value, prefSlug, $.noop, function() {}); 519 })(value, prefSlug); 520 }); 521 522 /*Picks already selected options values and makes an ajax request in order to check if the checked values have at_risk field*/ 523 var prevAutotradeValues = $("select[name*=autotrade]").val(); 524 var commPlansStocks = $('#AccountPreferencesCommPlanStocks').parent('div').outerHTML(); 525 var commPlansOptions = $('#AccountPreferencesCommPlanOptions').parent('div').outerHTML(); 526 var multiple = $("select[name*=autotrade]").attr('multiple'); 527 /*Hide/show `Stocks commission plan`, `Options commission plan` fields*/ 528 529 function checkCommissionFieldsexistence(){ 530 531 var selectPricesParent = $("#select_pricesSlug").parent('div'); 532 var accountPreferencesOrderTypeParent = $('#AccountPreferencesOrderType').parent('div'); 533 534 if($('#AccountPreferencesCommPlanStocks_').length == 0){ 535 $(commPlansStocks).insertAfter(selectPricesParent); 536 } 537 if($('#AccountPreferencesCommPlanOptions_').length == 0){ 538 $(commPlansOptions).insertBefore(accountPreferencesOrderTypeParent); 539 } 540 } 541 542 function removeCommissionFields(){ 543 $('#AccountPreferencesCommPlanStocks_').parent('div').remove(); 544 $('#AccountPreferencesCommPlanOptions_').parent('div').remove(); 545 } 546 547 if(prevAutotradeValues != 0 && prevAutotradeValues !== null){ 548 var multiple = $("select[name*=autotrade]").attr('multiple'); 549 if(multiple == 'multiple'){ 550 var checkCommPlanOptions = prevAutotradeValues.indexOf('1'); 551 var checkCommPlanStocks = prevAutotradeValues.indexOf('2'); 552 if(checkCommPlanOptions !== -1 || checkCommPlanStocks !== -1){ 553 removeCommissionFields(); 554 } 555 }else{ 556 if(prevAutotradeValues == 1 || prevAutotradeValues == 2){ 557 removeCommissionFields(); 558 } 559 } 560 561 } 562 563 /*End*/ 564 565 $("select[name*=autotrade]").change(function () { 566 var value = $(this).val(); 567 var nameAttr = $(this).attr('name'); 568 var prefSlug = nameAttr.split('][')[1]; 569 var checkedAccounts = $('.accounts input:checked').last().attr('name'); 570 var accountValue = checkedAccounts.split('][')[1].split(']')[0]; 571 572 /*Hide/show `Stocks commission plan`, `Options commission plan` fields*/ 573 574 if(value){ 575 if(multiple){ 576 var checkCommPlanOptions = value.indexOf('1'); 577 var checkCommPlanStocks = value.indexOf('2'); 578 579 if(checkCommPlanOptions !== -1 || checkCommPlanStocks !== -1){ 580 removeCommissionFields(); 581 }else{ 582 checkCommissionFieldsexistence(); 583 } 584 }else{ 585 if(value == 1 || value == 2){
586 removeCommissionFields(); 587 }else{ 588 checkCommissionFieldsexistence(); 589 } 590 } 591 }else{ 592 checkCommissionFieldsexistence(); 593 } 594 595 /*End*/ 596 597 if(multiple == 'multiple'){ 598 function diff(previousValues, currentValues){ 599 if(!currentValues){ 600 prevAutotradeValues = currentValues; 601 return {prev: true, value: previousValues[0]}; 602 } 603 604 if(!previousValues){ 605 prevAutotradeValues = currentValues; 606 return {prev: false, value: currentValues[0], values: currentValues}; 607 } 608 609 if(previousValues.length > currentValues.length){ 610 for(var i = 0; i < previousValues.length; i++){ 611 if(!currentValues.includes(previousValues[i])){ 612 prevAutotradeValues = currentValues; 613 /*The prev property true value indicates that this value has been cut from the previous values */ 614 return {prev: true, value: previousValues[i]}; 615 } 616 } 617 }else if(previousValues.length < currentValues.length){ 618 for(var i = 0; i < currentValues.length; i++){ 619 if(!previousValues.includes(currentValues[i])){ 620 prevAutotradeValues = currentValues; 621 /*The prev property false value indicates that this value has been added to the previous values */ 622 return {prev: false, value: currentValues[i], values: currentValues}; 623 } 624 } 625 } 626 } 627 628 var prevCurrentValuesDifference = diff(prevAutotradeValues, value); 629 630 var atRiskValues = {}; 631 if(!prevCurrentValuesDifference.prev){ 632 var values = prevCurrentValuesDifference.values; 633 for(var i = 0; i < values.length; i++){ 634 var atRiskVal = $('.at-risk-input-change[data-val="'+values[i]+'"]'); 635 if(atRiskVal.length){ 636 atRiskValues[values[i]] = atRiskVal.val(); 637 } 638 } 639 } 640 641 if(prevCurrentValuesDifference){ 642 if(prevCurrentValuesDifference['prev'] === true) { 643 var value = prevCurrentValuesDifference['value']; 644 $('.account-preferences-at-risk-item-' + value).remove(); 645 }else if(prevCurrentValuesDifference['prev'] === false){ 646 647 var value = prevCurrentValuesDifference['value']; 648 var currentValues = prevCurrentValuesDifference['values']; 649 // Use closure to keep id inside it immutable 650 (function(value, currentValues, atRiskValues) { 651 getDynamicMessage_(value, currentValues, prefSlug, accountValue, atRiskValues, $.noop, function() {}); 652 })(value, currentValues, atRiskValues); 653 654 } 655 } 656 }else{ 657 (function(value, currentValues) { 658 getDynamicMessage_(value, currentValues, prefSlug, accountValue, {}, $.noop, function() {}); 659 })(value, 0); 660 } 661 }); 662 663 $("a[href=#balances]").click(function () { 664 $.params.toggleBar.toggle_ticket("slideDown"); 665 $.params.ticket.tabs("select", $.params.tabIndexes.balance); 666 return false; 667 }); 668 669 if(accountNumber = $("#AccountNumber option:selected").val()) { 670 // if (accountNumber.substr(0, 6) > '013530' && accountNumber.substr(0, 6) < '013668' || (accountNumber.substr(0, 1) === 'T' || accountNumber ==='010281EDBU') ) { 671 $("#private_tool").attr('class', ''); 672 //} 673 } 674 675 $(".robo_analyst").click(function(){ 676 $(".robo_analyst").css('background-color',' #c0bdc8'); 677 $(".daily_picks").css('background-color','#C1E1EC'); 678 $(".robo_analyst_intraday").css('background-color','#C1E1EC'); 679 }); 680 $(".robo_analyst_intraday").click(function(){ 681 $(".robo_iframe").css("display","none"); 682 var necesaryIframes = $(".robo_iframe").attr('src','https://buysellorhold.com/analysis2/eod/?symbol=AMZN&opinion=short'); 683 // console.log(necesaryIframes.length); return false; 684 necesaryIframes[necesaryIframes.length - 1].setAttribute("style", "display: block;"); 685 $(".robo_analyst_intraday").css('background-color',' #c0bdc8'); 686 $(".daily_picks").css('background-color','#C1E1EC'); 687 $(".robo_analyst").css('background-color','#C1E1EC'); 688 }); 689 690 $(".daily_picks").click(function () { 691 $(".robo_iframe").css("display","none").hasClass('robo_iframe_1'); 692 $(".robo_iframe").not(".robo_iframe_1").css("display","block").attr('src','https://buysellorhold.com/analysis2/delayed/?symbol=AMZN&opinion=short'); 693 $(".daily_picks").css('background-color',' #c0bdc8'); 694 $(".robo_analyst").css('background-color','#C1E1EC'); 695 $(".robo_analyst_intraday").css('background-color','#C1E1EC'); 696 }); 697 698 $(".reboot").click(function () { 699 // if (confirm("This will reload the current page. Are you sure?")) { 700 window.location.reload(); 701 // } 702 return false; 703 }); 704 705 706 var productStatus = $('.product-active-time'); 707 var popUp = $('.pop-up'); 708 var popUpSubscription = $(".pop-up-subscription"); 709 var roboAnalystPage = $('.robo-analyst-page'); 710 var cancelProduct = $('.cancel-product').val(); 711 var activeDaysRoboProduct; 712 var cancelButtonValue; 713 var productValue; 714function ajax_setup (type, url, data) { 715 $.ajax({
716 type:type, 717 url: url, 718 data: data, 719 success:function (result) { 720 if(result.message === 'Success') { 721 productStatus.text('Thank you for your subscription.' ).show().css('color','red'); 722 roboAnalystPage.hide(); 723 if(productValue === '320') { 724 $(".robo_analyst_intraday").show(); 725 $(".daily_picks").show(); 726 $('.text').show(); 727 location.reload(); 728 } else if(productValue === '321') { 729 $(".robo_analyst").show(); 730 $('.text').show(); 731 location.reload(); 732 } 733 $(".robo_iframe").css("display","block").attr('src','https://buysellorhold.com/analysis2/delayed/?symbol=AMZN&opinion=short'); 734 setTimeout(function(){ 735 productStatus.hide(); 736 }, 3000); 737 738 739 if(productValue === '322' || activeDaysRoboProduct === true) { 740 Date.prototype.addDays = function(days) { 741 var date = new Date(this.valueOf()); 742 date.setDate(date.getDate() + days); 743 return date; 744 }; 745 var dateForActiveDay = new Date(); 746 var activeData = dateForActiveDay.addDays(30); 747 var productActiveDays = ((activeData.getMonth()+ 1) + '/' + activeData.getDate() + '/' + activeData.getFullYear());
748 productStatus.text('Thank you. Your subscription will end on' + ' ' + productActiveDays).show().css('color','red'); 749 roboAnalystPage.hide(); 750 $(".robo_analyst_intraday").show(); 751 $(".daily_picks").show(); 752 $('.robo_iframe').show(); 753 location.reload(); 754 } 755 else if( activeDaysRoboProduct === false) { 756 var dateForLastActiveDay = new Date(), year = dateForLastActiveDay.getFullYear(), month = dateForLastActiveDay.getMonth(); 757 var lastDay = new Date(year, month + 1, 0); 758 var lastDayThisMonth = (lastDay.getMonth() + 1) + '/' + lastDay.getDate() + '/' + lastDay.getFullYear(); 759 productStatus.text('Thank you. Your subscription will end on' + ' ' + lastDayThisMonth).show().css('color','red'); 760 } 761 } 762 }, 763 error: function(error) { 764 if(error) { 765 productStatus.text('You are not subscribed to any products').show(); 766 setTimeout(function(){ 767 productStatus.hide(); 768 }, 3000); 769 } 770 }, 771 }); 772} 773 774function ajax_save_user_billing () { 775 $.ajax({
776 type: "POST", 777 url: "save_user_billing", 778 }) 779} 780 781$('.select-product').click(function () { 782 popUpSubscription.toggle(500); 783 productValue = $(this).next().val(); 784 $(".yes-subscription").click(function () { 785 popUpSubscription.hide(); 786 ajax_setup("POST",'save_billing_robo_product',{data_to_be_pass: productValue}); 787 ajax_save_user_billing(); 788 }); 789}); 790 791$('.upgrade-robo-product').click(function () { 792 cancelButtonValue = this.textContent; 793 if(cancelButtonValue === 'Upgrade') { 794 $('.cancel-or-upgrade').text('upgrade'); 795 } 796 popUp.toggle(500); 797}); 798 799$('.cancel-robo-product').click(function () { 800 cancelButtonValue = this.textContent; 801 if(cancelButtonValue === 'Cancel subscription') { 802 $('.cancel-or-upgrade').text('cancel'); 803 } 804 popUp.toggle(500); 805}); 806 807 $('.no').click(function () { 808 popUp.hide(500); 809 }); 810 811 $(".no-subscription").click(function () { 812 popUpSubscription.hide(500); 813 }); 814 815$('.yes').click(function () { 816 if(cancelButtonValue === 'Cancel subscription') { 817 activeDaysRoboProduct = false; 818 popUp.hide(500); 819 ajax_setup("POST",'remove_billing_robo_product',{data_to_be_pass: cancelProduct,value_to_be_pass: cancelButtonValue}) 820 } 821 else { 822 popUp.hide(500); 823 $.ajax({
824 type: "POST", 825 url: "remove_billing_robo_product", 826 data: {data_to_be_pass: cancelProduct}, 827 success:function (result) { 828 if(result.message === 'Success') { 829 setTimeout(function(){ 830 location.reload(); 831 }, 2000); 832 } 833 } 834 }) 835 } 836}); 837 838$('.data-trade-stock').click(function () { 839 $('#trade-option-buying-power').hide(); 840 $.ajax({ 841 type: "POST", 842 url: "/api/account_info", 843 data: {data_to_passing: 'ajax_request'}, 844 success:function (result) { 845 $('.non-marginable').html('Non-marginable stocks: '+result.currentcashbuyingpower); 846 if(result.daytradingallowed == 1) { 847 $('.marginable').html('Marginable stocks: ' + result.currentdaytradingbuyingpower); 848 } else if(result.acctstate == 2) { 849 $('.marginable').html('Marginable stocks: ' + result.currentovernightbuyingpower); 850 } else { 851 $('.marginable').html('Marginable stocks: ' + result.currentcashbuyingpower); 852 } 853 854 $('#buying-power').show(); 855 $('#trade-option-buying-power').hide(); 856 } 857 }) 858}); 859 860$('.data-trade-option').click(function () { 861 $('#buying-power').hide(); 862 $.ajax({
863 type: "POST", 864 url: "/api/account_info", 865 data: {data_to_passing: 'ajax_request'}, 866 success: function (result) { 867 $('.options').html('Options: ' + result.currentcashbuyingpower); 868 $('#trade-option-buying-power').show(); 869 $('#buying-power').hide(); 870 } 871 }) 872}); 873 874 875 var openedWindow = null; 876 $("#detach-now").live("click", function () { 877 var a = $(this); 878 var url = a.attr("href"); 879 openedWindow = window.open(url, "detached-window", "width=1024,height=800,scrollbars=yes"); 880 881 a.siblings(".ui-queue,.ui-queue-filter,#ui-orders-container,.ui-orders-filter,#ui-positions-container,.ui-positions-filter,.delete-all, .orders-table-container").hide(); 882 a.siblings(".after-detached").show(); 883 a.hide(); 884 885 return false; 886 }); 887 $("#attach-now").live("click", function () { 888 var a = $(this); 889 var container = a.parents(".after-detached"); 890 container.siblings(".ui-queue,.ui-queue-filter,#ui-orders-container,.ui-orders-filter,#ui-positions-container,.ui-positions-filter,.delete-all, .orders-table-container").show(); 891 container.hide(); 892 $("#detach-now").show(); 893 894 openedWindow.close(); 895 896 return false; 897 }); 898 899 var subscriptionTrigger_clickHandler = function () { 900 var url = $(this).attr("href"); 901 $.params.overlay.find("#overlay-content").load(url, function () { 902 $.params.overlay.data("overlay").load(); 903 }); 904 905 return false; 906 }; 907 908 $("#subscription-trigger").click(subscriptionTrigger_clickHandler); 909 $("#manage-subscription-trigger").click(subscriptionTrigger_clickHandler); 910 911 $.extend($.validator.messages, { 912 remote:"Already taken." 913 }); 914 915 /* 916 $("#ui-change-password").submit(function() { 917 var form = $(this); 918 919 if (!form.valid()) { 920 return false; 921 } 922 923 form.ajaxSubmit({ 924 dataType: "html", 925 success: function(html) { 926 form.find(".result").html(html); 927 } 928 }).validate(); 929 930 return false; 931 }); 932 */ 933 934 $("#flashMessage").delay(8000).slideUp(); 935 $("a.false,a[href=#]").click(function () { 936 return false; 937 }); 938 $("form.prompt").submit(function () { 939 if (!$(this).valid) { 940 return false; 941 } 942 var msg = $(this).attr("rel"); 943 if (!confirm(msg)) { 944 return false; 945 } 946 }); 947 $("#learning_option_tabs").tabs(); 948 949 // Below is Matt's code 950 951 var platform_data = function (obj) { 952 var out = { 953 platform_code:$(obj).attr('platform_code') 954 }; 955 if (typeof(platform_options_autoconfirm) != 'undefined' && platform_options_autoconfirm) { 956 var res = confirm('Do you wish to autoconfirm this operation? Click OK to autoconfirm, cancel to allow normal confirmation. (Autoconfirmation will only take effect if confirmation would normally be performed via email.)'); 957 if (res) 958 out.autoconfirm = true; 959 } 960 return out; 961 }; 962 var showDialog = function (title, message, close) { 963 $('<div />').attr('title', title).html(message).dialog({ 964 bgiframe:true, 965 modal:true, 966 buttons:{ 967 OK:function () { 968 $(this).dialog('close'); 969 } 970 }, 971 close:close 972 }); 973 }; 974 var dataError = function (data) { 975 var close = null; 976 if (data.field) 977 close = function () { 978 $('#' + data.field).focus(); 979 }; 980 showDialog('Error', data.error, close); 981 }; 982 $('.platform_selection').click(function () { 983 $.getJSON('/api/request_platform', platform_data(this), function (data, textStatus) { 984 if (data.error) 985 return dataError(data); 986 showDialog('Activation Request', data.message + '<div style="text-align: center; margin-top: 15px"><a href="/active_trader/my_platform.php" title="Go to the My Platform page, where you can view the trading weapons at your disposal and their status">Proceed to My Platform</a></div>'); 987 }); 988 }); 989 $('.pause').click(function () { 990 if (!confirm('Are you sure you want to pause this platform option?')) 991 return; 992 $.getJSON('/api/pause_platform', platform_data(this), function (data, textStatus) { 993 if (data.error) 994 return dataError(data); 995 showDialog('Pause Request', data.message); 996 }); 997 }); 998 $('.resume').click(function () { 999 if (!confirm('Are you sure you want to resume this platform option?')) 1000 return; 1001 $.getJSON('/api/resume_platform', platform_data(this), function (data, textStatus) { 1002 if (data.error) 1003 return dataError(data); 1004 showDialog('Resume Request', data.message); 1005 }); 1006 }); 1007 $('.cancel').click(function () { 1008 if (!confirm('Are you sure you want to cancel this platform option?')) 1009 return; 1010 $.getJSON('/api/cancel_platform', platform_data(this), function (data, textStatus) { 1011 if (data.error) 1012 return dataError(data); 1013 showDialog('Cancel Request', data.message); 1014 }); 1015 }); 1016 $('.reinstate').click(function () { 1017 if (!confirm('Are you sure you want to reinstate this platform option?')) 1018 return; 1019 $.getJSON('/api/reinstate_platform', platform_data(this), function (data, textStatus) { 1020 if (data.error) 1021 return dataError(data); 1022 showDialog('Reinstatement Request', data.message); 1023 }); 1024 }); 1025 1026 $('.choicestreamer').click(function () { 1027 window.open('/platforms/choicestreamer', 'QuoteStream', 'menubar=no,toolbar=no,width=740,height=400'); 1028 return false; 1029 }); 1030 });
1031 1032 var div; 1033 1034 $.fn.outerHTML = function () { 1035 var elem = this[0], 1036 tmp; 1037 1038 return !elem ? null : 1039 typeof ( tmp = elem.outerHTML ) === 'string' ? tmp : 1040 (div = div || $('<div/>') ).html(this.eq(0).clone()).html(); 1041 }; 1042 1043})(jQuery); 1044 1045function buildJQueryDialog(obj, dialogWidth) { 1046 var dWidth = !dialogWidth ? 300 : dialogWidth; 1047 var dialogA = obj; 1048 var dialogATitle = dialogA.attr("title"); 1049 if (dialogATitle) { 1050 var dialogASplit = dialogATitle.split("|"); 1051 var dialogAHeader = ""; 1052 if (dialogASplit.length > 1) { 1053 dialogAHeader = dialogASplit[0]; 1054 dialogATitle = dialogASplit[1]; 1055 } 1056 var dialogAPosition = dialogA.position(); 1057 1058 var toolTipADialog = $('<p>' + dialogATitle + '</p>').dialog({ 1059 autoOpen:false, 1060 hide:"fade", 1061 modal:true, 1062 position:["center", dialogAPosition[1] / 2], 1063 resizable:false, 1064 show:"fade", 1065 title:dialogAHeader, 1066 width:dWidth 1067 }); 1068 1069 dialogA.click(function () { 1070 toolTipADialog.dialog('open'); 1071 }); 1072 1073 dialogA.removeAttr("title"); 1074 } 1075 1076} 1077 1078function showSimpleModalWithOkButton(title, content) { 1079 $('<div />').html(content).dialog({ 1080 modal:true, 1081 title:title.charAt(0).toUpperCase() + title.slice(1), 1082 open:function (event, ui) { 1083 $('.ui-dialog :button').focus(); 1084 }, 1085 buttons:[ 1086 { 1087 text:"Close", 1088 click:function () { 1089 $(this).dialog("close"); 1090 } 1091 } 1092 ] 1093 }) 1094} 1095 1096function getDynamicMessage(message_id, func, cancel_func) { 1097 /* Get Message */ 1098 $.ajax({
1099 type:"POST", 1100 url:"../api/get_warning", 1101 dataType:"json", 1102 data:{ id:message_id }, 1103 success:function (data) { 1104 showDynamicMessage(data, func, cancel_func); 1105 } 1106 }); 1107} 1108 1109function getDynamicMessage_(value, currentValues, prefSlug, accountValue, atRiskValues, func, cancel_func) { 1110 /* Get Message */ 1111 let clickedCheckbox = value; 1112 $.ajax({ 1113 type:"POST", 1114 url:"../api/get_warning", 1115 dataType:"json", 1116 data:{ value:value, prefSlug:prefSlug, values: currentValues, accountValue: accountValue, atRiskValues: atRiskValues}, 1117 success:function (data) { 1118 var multiple = $("select[name*=autotrade]").attr('multiple'); 1119 var accountPreferences = $('.account-preferences-at-risk'); 1120 1121 $('#AccountPreferencesLandingPage').val('5') 1122 getDynamicMessageForNoAutotrade('5', 'landing_page') 1123 1124 if(data['success'] === false){ 1125 if(!multiple){ 1126 accountPreferences.html(''); 1127 } 1128 return false; 1129 } 1130 if(data['at_risk'] === false){ 1131 if(!multiple){ 1132 accountPreferences.html(''); 1133 } 1134 showDynamicMessage(data['api'], func, cancel_func, clickedCheckbox); 1135 return false; 1136 } 1137 if(data['at_risk']){ 1138 var options = data['options']; 1139 if($('.account-preferences-at-risk').length){ 1140 var atRiskContainer = $('.account-preferences-at-risk').html(''); 1141 }else{ 1142 var atRiskContainer = $(`<div class="input text account-preferences-at-risk"></div>`); 1143 } 1144 1145 for(var i = 0; i < options.length; i++){ 1146 if(options[i]['secondary'] === 'at_risk'){ 1147 var atRiskDefault = options[i]['at_risk_default'] ? options[i]['at_risk_default'] : ''; 1148 var atRisk = options[i]['at_risk'] ? options[i]['at_risk'] : ''; 1149 var atRiskFinal = options[i]['at_risk'] ? options[i]['at_risk'] : atRiskDefault; 1150 var value = options[i]['value']; 1151 var slug = options[i]['pref_slug']; 1152 var title = options[i]['title']; 1153 var item = `<div class="input text account-preferences-at-risk-item account-preferences-at-risk-item-${value}"> 1154 <label data-val="${value}" class="${(atRisk && (atRisk != atRiskDefault)) ? 'changed' : ''}" for="AccountPreferencesAtRisk${value}" id="labelAccountPreferencesAtRisk${value}" ><span class='label-arrow'></span> At-risk dollar quantity for (${title})</label> 1155 <input class="at-risk-input-change" data-val="${value}" name="data[AccountPreferences][at_risk][${value}]" type="text" value="${atRiskFinal}" maxlength="10" id="AccountPreferencesAtRisk${value}"> 1156 </div>`; 1157 atRiskContainer.append(item); 1158 } 1159 } 1160 1161 atRiskContainer.insertBefore('.account-prefs .right #select_pricesSlug'); 1162 1163 var riskInput = $('.at-risk-input-change'); 1164 var riskInputPrevVal = riskInput.val(); 1165 1166 if(data['api']){ 1167 showDynamicMessage(data['api'], func, cancel_func, clickedCheckbox); 1168 } 1169 } 1170 } 1171 }); 1172} 1173 1174function getDynamicMessageForNoAutotrade(value, prefSlug, func, cancel_func) { 1175 $.ajax({
1176 url: '/api/get_warning_for_no_autotrades', 1177 type: 'POST', 1178 data:{value: value, prefSlug: prefSlug}, 1179 success: function(data){ 1180 if(data['success']){ 1181 showDynamicMessage(data['api'], func, cancel_func); 1182 } 1183 } 1184 }); 1185} 1186 1187function urlify(text,label) { 1188 1189 text = text.replace(/(<([^>]+)>)/ig," "); 1190 1191 text = text.replace(/http:\/\//i, 'https://'); 1192 1193 var urlRegex = /(https?:\/\/[^\s]+)/g; 1194 1195 var i = 0; 1196 return text.replace(urlRegex, function(url, c, o, s) { 1197 var name; 1198 if(Array.isArray(label)) { 1199 name = label[i]; 1200 i++; 1201 } else { 1202 name = (label) ? label : url 1203 } 1204 1205 return '<p><a href="' + url + '" target="_blank" style="color:#0000ff;">' + name + '</a></p>'; 1206 }) 1207} 1208 1209function showDynamicMessage(data, func, cancel_func, clickedCheckbox = null) { 1210 var func = typeof func != "function" ? function() { } : func; 1211 var cancel_func = typeof func != "function" ? function () { } : cancel_func; 1212 1213 if(data!=undefined){ 1214 1215 1216 if (data.DoNotRemind == 'no') { 1217 1218 /* Accept function */ 1219 var accept = function () { 1220 var suppress = false; 1221 if (data.Suppress == 'automatic') 1222 suppress = true; 1223 if (data.Suppress == 'checkbox') 1224 suppress = $("#m-checkbox").is(':checked'); 1225 $.ajax({
1226 type:"POST", 1227 url:"../api/save_answer", 1228 dataType:"json", 1229 data:{ id:data.MessageID, answer:data.AcceptanceType, suppress:suppress }, 1230 success:function () { 1231 if ($.isFunction(func)) 1232 func(); 1233 $.fallr('hide'); 1234 } 1235 }); 1236 }; 1237 1238 /* Cancel function */ 1239 var cancel = function () { 1240 if (data.DisagreeAction == 'block content') { 1241 let disagreeBtn = document.getElementById('fallr-button-button2'); 1242 if(disagreeBtn) { 1243 const dropdownContainer = document.getElementById('ddcl-AccountPreferencesAutotrade-ddw'); 1244 if (dropdownContainer) { 1245 const checkbox = document.querySelector(`input[type="checkbox"][value="${clickedCheckbox}"]`); 1246 if (checkbox.checked) { 1247 checkbox.click(); 1248 } 1249 } 1250 } 1251 if ($.isFunction(cancel_func)) 1252 cancel_func(); 1253 } else if (data.DisagreeAction == 'block log-in') { 1254 //TODO Implement Block Log-In logic. 1255 } 1256 $.fallr('hide'); 1257 }; 1258 1259 var urls = [''+data.MessageName+' »', 'AutoTrading Agreement »']; 1260 1261 var message = '<h4>' + data.MessageName + '</h4>' + '<p style="width: 356px;">' + urlify(data.Message, urls) + '</p>'; 1262 if (data.Modal == 'yes') { 1263 if (data.Suppress == 'checkbox') 1264 message += '<input id="m-checkbox" type="checkbox"><label style="margin-left: 5px;" for="m-checkbox">Don\'t show me this again.</label>'; 1265 1266 var btns; 1267 1268 switch (data.AcceptanceType) { 1269 case 'I agree': 1270 btns = { 1271 button1:{text:'I Agree', onclick:accept}, 1272 button2:{text:'I Disagree', onclick:cancel} 1273 }; 1274 break; 1275 case 'ok': 1276 btns = { 1277 button1:{text:'OK', onclick:accept} 1278 }; 1279 break; 1280 case 'continue': 1281 btns = { 1282 button1:{text:'Continue', onclick:accept}, 1283 button2:{text:'Cancel', onclick:cancel} 1284 }; 1285 break; 1286 case 'place trade': 1287 btns = { 1288 button1:{text:'Place trade', onclick:accept}, 1289 button2:{text:'Do not place trade', onclick:cancel} 1290 }; 1291 break; 1292 } 1293 1294 $.fallr('show', { 1295 buttons:btns, 1296 content:message, 1297 icon:'warning', 1298 width:'500px' 1299 }); 1300 } 1301 else { 1302 $.fallr('show', { 1303 content:message, 1304 icon:'warning', 1305 width:'500px', 1306 autoclose:3000 1307 }); 1308 if ($.isFunction(func)) 1309 func(); 1310 } 1311 } 1312 else func(); 1313 } 1314} 1315 1316function calcImpVol(C, S, K, P, T, R) { 1317 var PREVIOUStrialP = 0.0; 1318 var result; 1319 var trialP; 1320 var V; // for guesses 1321 var error = 1.0; // arbitrary large number 1322 var limit = 0; 1323 1324 var Vmin = 0.0; 1325 var Vmax = 10.0; 1326 V = 0.5; // first guess 1327
1328 var SHRINK = true; 1329 1330 while ((error > 0.001) && (limit < 100)) { 1331 trialP = calcPremium(C, S, K, V, T, R); 1332 error = Math.abs(trialP - P); 1333 1334 if (PREVIOUStrialP == trialP) // this latest Vchange has NO affect on premium, CHANGE direction 1335 { 1336 if (SHRINK) { 1337 Vmax = 10.0; // bring back to original since prev change already shrank it to V 1338 Vmin = V; 1339 V = (Vmax + V) / 2.0; 1340 SHRINK = false; 1341 } 1342 else { 1343 Vmin = 0.0; // bring back to original since prev change already upped it to V 1344 Vmax = V; 1345 V = (V + Vmin) / 2.0; 1346 SHRINK = true; 1347 } 1348 trialP = calcPremium(C, S, K, V, T, R); 1349 error = Math.abs(trialP - P); 1350 } 1351 1352 if (error > 0.001) { 1353 if (trialP > P) // guess trialP was too big, shrink trial V 1354 { 1355 Vmax = V; 1356 V = (V + Vmin) / 2.0; 1357 1358 SHRINK = true; 1359 } 1360 else // guess trial P was too small, increase trial V 1361 { 1362 Vmin = V; 1363 V = (Vmax + V) / 2.0; 1364 1365 SHRINK = false; 1366 } 1367 } 1368 limit++; 1369 1370 PREVIOUStrialP = trialP; 1371 } 1372 result = V; 1373 return(result); 1374} 1375 1376function calcPremium(C, S, K, V, T, R) { 1377 var retValue; 1378 var d1, d2; 1379 1380 if (T <= 0.0) // expired 1381 { 1382 retValue = ( C ? ((S > K) ? (S - K) : 0.0) : ((S < K) ? (K - S) : 0.0) ); 1383 } 1384 else { 1385 d1 = (Math.log(S / K) + (R + 0.5 * V * V) * T) / (V * Math.pow(T, 0.5)); 1386 d2 = d1 - V * Math.pow(T, 0.5); 1387 if (C) // call 1388 { 1389 retValue = S * N(d1) - Math.exp(-R * T) * K * N(d2); 1390 } 1391 else // put 1392 retValue = -S * N(-d1) + Math.exp(-R * T) * K * N(-d2); 1393 } 1394 1395 return(retValue); 1396} 1397 1398function N(x) { 1399 var result, poly; 1400 if (x < 0.0) { 1401 result = 1.0 - N((-1.0) * x); 1402 } 1403 else { 1404 poly = 1.0 + 0.049867347 * x + 0.0211410061 * x * x + 0.0032776263 * x * x * x + 0.0000380036 * x * x * x * x + 0.0000488906 * x * x * x * x * x + 0.000005383 * x * x * x * x * x * x; 1405 result = 1.0 - 0.5 * Math.pow(poly, -16.0); 1406 } 1407 return(result); 1408} 1409 1410function midFunc(bid, ask) { 1411 return Math.min(bid, ask) + Math.abs((Math.max(bid, ask) - Math.min(bid, ask)) / 2.0); 1412} 1413 1414function calcLegBidAsk(name, type, q, contracts) { 1415 if (name == 'bid') { 1416 if (type == 'S') 1417 return Math.min(q.bid(), q.ask()) * (-1 * contracts); 1418 else return Math.max(q.bid(), q.ask()) * contracts; 1419 } 1420 else { 1421 if (type == 'S') 1422 return Math.max(q.bid(), q.ask()) * (-1 * contracts); 1423 else return Math.min(q.bid(), q.ask()) * contracts; 1424 } 1425} 1426 1427/* 1428 * gets greatest common divisor among 1429 * an array of numbers 1430 */ 1431function gcd_array(array, a) { 1432 if (a == undefined) 1433 a = 0; 1434 var b = array.pop(); 1435 return (b === undefined) ? parseInt(a) : gcd_array(array, gcd(a, b)); 1436} 1437 1438function sformat(string) { 1439 var args = arguments; 1440 return string.replace(/{(\d+)}/g, function(match, number) { 1441 return typeof args[parseInt(number, 10) + 1] != 'undefined' 1442 ? args[parseInt(number, 10) + 1] 1443 : match 1444 ; 1445 }); 1446}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.