calvez
7/19/2017 - 7:16 PM

frontend_listview.js

    //  uncomment if listview needs the game closed message
    // $(document).ready(function(){
    //     $("#closed").modal('show');
    // });
var needcheck = 0; // kapcsolok a submittrade-hez
//var server_base_url = 'http://tozsdejatek.penziskola.hu';
//var server_base_url = 'http://178.22.69.131';
//var server_base_url = 'http://bet.hu';
var server_base_url = 'https://' + window.location.hostname;
var indexphp_base_url = '/index.php';

function closetrader() {
  $('#MNBTradeLineTr').css('display', 'none');
  //NL
  //$('#MNBTradeLineTr').removeClass(instr+'_tradeline').addClass('trader');
  //NL
  $('#MNBTradeLine_qty').val('');
  $('#MNBTradeLine_trans').val('');
  $('#MNBTradeLine_instr').val('');
  $('#MNBTradeLine_limitvalue').val('');
  $('#MNBTradeLine_stopvalue').val('');
  $('#MNBTradeLine_gfx').attr('src', '');
  $('#MNBTradeTextTrE').hide();
  $('#MNBTradeTextTrN').hide();
}

function cancelorder2(orderid) {
  if (cancelorder(orderid)) {
    closetrader();
    //	$('#action').val('listview');
    $('#action').val('cancelorder2');
    $('#MNBForm').submit();
  }
}

function currentorder(instr) {
  var coxmlurl = server_base_url + indexphp_base_url + '?module=backend&action=currentorder&instr=' + instr + '&user=' + $('#MNBTopHtmlUserId').html();
  $.ajax({
    type: "GET",
    dataType: "xml",
    url: coxmlurl + '&rand=' + Math.random(),
    success: function(xml) {
      if ($(xml).find('stockname').text() == instr) {
        var orderid = $(xml).find('orderid').text()
        var trans = $(xml).find('trans').text()
        var otype = $(xml).find('otype').text()
        var qty = $(xml).find('qty').text()
        var limit = $(xml).find('limit').text()
        var stop = $(xml).find('stop').text()
        var otype_name=(otype=='market' ? 'Piaci' : (otype=='limitstop' ? 'Limit Stop' : (otype=='marketstop' ? 'Stop piaci' : (otype=='limit' ? 'Limit' : ''))));        
        $('#MNBTradeLine_currentorder').show();
        $("#myModal").modal();
        $('#MNBTradeLineBtnCancel_li').show();
        $('#MNBTradeLineBtnCancel').attr('href', "javascript:cancelorder2('" + orderid + "')");
        $('#MNBTradeInfo_coid').text('#' + orderid);
        $('#MNBTradeInfo_cotype').text(otype_name);
        //alert('['+trans+'] ['+$('#MNBTradeLine_trans').val()+']');
        if (trans == $('#MNBTradeLine_trans').val()) {
          $('#MNBTradeLine_ordertype').val(otype);
          ordertype(otype);
          $('#MNBTradeLine_limitvalue').val(limit);
          $('#MNBTradeLine_stopvalue').val(stop);
          $('#MNBTradeLine_qty').val(qty);
          //					alert($(xml).find('expdate').text() );
          if ($(xml).find('expdate').text() == 2030) {
            $('#MNBTradeLine_expire').val('gtc');
          } else {
            $('#MNBTradeLine_expire').val('mo');
          }
        }
        $('#MNBTradeInfo_coqty').text(qty);
        if ($(xml).find('trans').text() == 'buy') {
          $('#MNBTradeInfo_cotrans').text('vétel');
        } else if ($(xml).find('trans').text() == 'sell') {
          $('#MNBTradeInfo_cotrans').text('eladás');
        }
        if ($(xml).find('limit').text() == '0') {
          $('#MNBTradeInfo_colimit').text('-');
        } else {
          $('#MNBTradeInfo_colimit').text($(xml).find('limit').text());
        }
        if ($(xml).find('stop').text() == '0') {
          $('#MNBTradeInfo_costop').text('-');
        } else {
          $('#MNBTradeInfo_costop').text($(xml).find('stop').text());
        }
      } else {
        $('#MNBTradeLine_currentorder').hide();
        $('#MNBTradeLineBtnCancel_li').hide();
      }
    }
  }); //close $.ajax(
}

function opentrader(trade, instr) {
  $(".trade_stockname").val(instr);
  var url = $('#MNBTradeLineTr').insertAfter($('#INSTR_' + instr)); //megy
  $('#MNBTradeLine_limit').hide();
  $('#MNBTradeLine_stop').hide();
  $('#MNBTradeLine_qty').removeClass("MNBInputError");
  $('#MNBTradeLine_limitvalue').removeClass("MNBInputError");
  $('#MNBTradeLine_stopvalue').removeClass("MNBInputError");
  $('#MNBTradeLineTr').show();
  //NL
  //$('#MNBTradeLineTr').removeClass('trader').addClass(instr+'_tradeline');
  //BJ
  var js = "javascript:isright($(this),'" + instr + "')";
  $('#MNBTradeLine_trans').attr('onchange', js);
  $('#MNBTradeLine_limitvalue').attr('onchange', js);
  $('#MNBTradeLine_stopvalue').attr('onchange', js);
  js = "javascript:ordertype($(this).val());isright($(this),'" + instr + "')";
  $('#MNBTradeLine_ordertype').attr('onchange', js);
  //BJ
  $('#MNBTradeLine_qty').focusout(function() {
    isright($('#MNBTradeLine_qty'), instr);
  });
  $('#MNBTradeTextTrE').hide();
  $('#MNBTradeTextTrN').hide();
  $('[value="dt"]').removeAttr('disabled');
  $('[value="dt"]').removeClass('MNBdisabled');

  $('#MNBTradeLine_ordertype').val('market');
  $('#MNBTradeLine_trans').val(trade);
  $('#MNBTradeLine_instr').val(instr);
  //$('#MNBTradeLine_gfx').attr('src', 'http://arfolyamsms.hu/charts_rt/'+instr+'_color.gif?mnbgame='+Math.random());
  $('#MNBTradeLine_gfx').attr('src', 'https://bet.hu/portal/api/game/game.html?securityId=' + $('#' + instr + '_bseid').text() + '&title=' + instr + '&width=280&height=160&isRealtime=true');

  $('#MNBTradeInfo_close').text($('#' + instr + '_close').text());
  $('#MNBTradeInfo_open').text($('#' + instr + '_open').text());
  $('#MNBTradeInfo_min').text($('#' + instr + '_min').text());
  $('#MNBTradeInfo_max').text($('#' + instr + '_max').text());
  $('#MNBTradeInfo_stamp').text($('#' + instr + '_stamp').text());
  $('#MNBTradeInfo_lastbid').text($('#' + instr + '_lastbid').text());
  $('#MNBTradeInfo_lastask').text($('#' + instr + '_lastask').text());
  if ($('#' + instr + '_dt_able').text() === '0') {
    $('[value="dt"]').attr('disabled', 'disabled');
    $('[value="dt"]').addClass('MNBdisabled');
  }
  if (trade == 'sell') {
    $('#MNBTradeLine_qty').val($('#' + instr + '_qty').text());
  } else if (trade == 'buy') {
    $('#MNBTradeLine_qty').val('');
  }
  currentorder(instr);
  // If the bottom of the tradeline is lower than the bottom of the screen, then scroll the screen a little.
  var tradelinebottom = $('#MNBTradeLineTr').offset().top + $('#MNBTradeLineTr').height();
  var screentop = $(window).scrollTop();
  var screenbottom = screentop + $(window).height();
  if (tradelinebottom > screenbottom) {
    $.scrollTo(screentop + (tradelinebottom - screenbottom), 'normal');
  }
}

function getfreemoney() { //jelenleg csak portfolio oldalon mukodik
  return parseFloat(cur2int($('#MNBAccount_money_free').html()));
}

function getlocked() {
  var locked = $.ajax({
    type: "POST",
    url: "index.php",
    data: "cmd=checkLocked"
  }).responseText;
  //alert('getlocked():'+locked);
  return locked;
}


function isright(elem, instrname) {
  locked = getlocked();
  needcheck = 1;
  //instrname = $('#MNBTradeLine_qty').parent().parent().parent().prev().attr('id').substr(6);
  money = getfreemoney();
  transobj = $('#MNBTradeLine_trans');
  orderobj = $('#MNBTradeLine_ordertype');
  qtyobj = $('#MNBTradeLine_qty');
  validuntil = $('#MNBTradeLine_expire').val();
  trans = transobj.val();
  order = orderobj.val();
  qty = parseFloat(qtyobj.val());
  have = parseFloat($('#' + instrname + '_qty').text());
  if (isNaN(have)) have = 0;
  //BJ
  //var szamok={'locked':locked,'money':money,'validuntil':validuntil,'trans':trans,'order':order,'qty':qty,'have':have};
  //alert('szamok='+JSON.stringify(szamok));
  //BJ
  showE = 0;
  showN = 0;
  slSet = 0;
  var forceHide;
  $('#MNBTradeTextTrN').insertAfter($('#MNBTradeLineTr'));
  $('#MNBTradeTextTrE').insertAfter($('#MNBTradeLineTr'));
  msgNEM1 = '<p>Figyelem! Önnek nincs elég fedezete ';
  msgNEM2 = ' darab részvény vásárlására!<br />Ezen az áron (';
  msgNEM3 = ') maximum ';
  msgNEM4 = ' darabot tud vásárolni.</p>';
  msgNotice = '<p><u>Megjegyzés:</u> a tranzakció kereskedési időben azonnal teljesülni fog az adott feltételek mellett.</p>';
  msgNoticeLocked = '<p><u>Megjegyzés:</u> a tranzakció aktív megbízásokat veszélyeztet.</p>';
  buyLSratio = '<p><u>Megjegyzés:</u> Limit-stop vételkor célszerű az aktiváló árnak kisebbnek lennie, mint a limit árnak.<br/> Ellenkező esetben amikor a piaci ár eléri az aktiváló árat, a részvény nem kerül megvételre, mivel a limit ár a piaci ár alatt lesz.</p>';
  buyLSLimit = '<p><u>Megjegyzés:</u> a tranzakció LIMIT vételként fog viselkedni.</p>';
  sellLSratio = '<p><u>Megjegyzés:</u> Limit-stop eladáskor célszerű az aktiváló árnak nagyobbnak lennie, mint a limit árnak.<br/> Ellenkező esetben amikor a piaci ár eléri az aktiváló árat, a részvény nem kerül eladásra, mivel a limit ár a piaci ár felett lesz.</p>';
  sellLSLimit = '<p><u>Megjegyzés:</u> a tranzakció LIMIT eladásként fog viselkedni.</p>';
  userwantsit = '<br /><p>Amennyiben mégis szeretné ezt a tranzakciót, most kattinthat a "Mehet" gombra.</p>';
  //	alert( order );
  if (trans == 'buy') {
    price = parseFloat(cur2int($('#' + instrname + "_lastask").html()));
    fee = getfee(price * qty, validuntil);
    if (elem.attr('id') == qtyobj.attr('id')) { //darabszam valtozas eseten
      needcheck = 1;
      switch (order) {
        case 'market':
        console.log('szabad pénz:', money);
        console.log('fee:', fee);
        console.log('quant:', qty);
        console.log('price:', price);
        feedb = price*1.0025;
        console.log('1 db:', feedb);
        maxbuy = money / (Math.floor(feedb));
        console.log('maximum megvehető:', Math.floor(maxbuy));
        console.log('tervezett vásárlás összesen', Math.floor(feedb*qty));
          if (money < Math.floor(feedb*qty)) {
            message = msgNEM1 + qty + msgNEM2 + price + msgNEM3 + Math.floor(maxbuy) + msgNEM4  + ' vásárolni kívánt össz: ' + Math.floor(feedb*qty) + '.</p>';
            $('#MNBTradeTextDivE').html(message);
            forceHide = 1;
            showE = 1;
          } else if (locked > 0 && money - fee - locked < price * qty) {
            $('#MNBTradeTextDivN').html(msgNoticeLocked + '<p>Ezen az áron (' + price + msgNEM3 + Math.floor(maxbuy) + ' darabot tud vásárolni más megbízások veszélyeztetése nélkül.</p>');
            showN = 1;
          } else {
            needcheck = 0;
          }
          break;
        case 'limit':
            limit = parseFloat($('#MNBTradeLine_limitvalue').val());
            fee_limit = getfee(limit * qty, validuntil);
            console.log('fee_limit:', fee_limit);
            console.log('szabad pénz:', money);
            console.log('quant:', qty);
            console.log('locked', locked);
            feedb = limit*1.0025;
            console.log('1 db:', feedb);
            maxbuy = money / (Math.floor(feedb));
            console.log('maximum megvehető:', Math.floor(maxbuy));
            console.log('tervezett vásárlás összesen', Math.floor(feedb*qty));
          if (limit > price && money - fee < price * qty && limit != 0) {
            message = msgNEM1 + qty + msgNEM2 + limit + msgNEM3 + Math.floor(maxbuy) + msgNEM4;
            $('#submittradebtn').addClass('disabled');
            $('#MNBTrade  TextDivE').html(message);
            showE = 1;
          } else if (limit <= price && money - fee < limit * qty && limit != 0) {
            message = msgNEM1 + qty + msgNEM2 + limit + msgNEM3 + Math.floor(maxbuy) + msgNEM4;
            $('#MNBTradeTextDivE').html(message);
            showE = 1;
          } else if (limit >= price && showE != 1) {
            if (locked > 0 && money - fee - locked < limit * qty) {
              $('#MNBTradeTextDivN').html(msgNoticeLocked + '<p>Ezen az áron (s' + limit + msgNEM3 + getqty(money - locked - fee_limit, price, validuntil) + ' darabot tud vásárolni a már beadott megbízások veszélyeztetése nélkül.</p>' + msgNotice);
            } else {
              $('#MNBTradeTextDivN').html(msgNotice);
            }
            showN = 1;
          } else if (locked > 0 && money - fee - locked < limit * qty && limit != 0) {
            $('#MNBTradeTextDivN').html(msgNoticeLocked + '<p>Ezen az áron (ss' + limit + msgNEM3 + getqty(money - locked - fee, limit, validuntil) + ' darabot tud vásárolni a már beadott megbízások veszélyeztetése nélkül.</p>');
            showN = 1;
          } else {
            needcheck = 0;
          }
          break;
        case 'marketstop':
            stop = parseFloat($('#MNBTradeLine_stopvalue').val());
            fee_stop = getfee(stop * qty, validuntil);
            //  console
            console.log('szabad pénz:', money);
            console.log('fee_stop:', fee_stop);
            console.log('quant:', qty);
            console.log('locked', locked);
            feedb = stop*1.0025;
            console.log('1 db:', feedb);
            maxbuy = money / (Math.floor(feedb));
            console.log('maximum megvehető:', Math.floor(maxbuy));
            console.log('tervezett vásárlás összesen', Math.floor(feedb*qty));
          //  /console
          if (stop <= price && money - fee_stop < price * qty) {
            message = msgNEM1 + qty + msgNEM2 + price + msgNEM3 + Math.floor(maxbuy) + msgNEM4;
            $('#MNBTradeTextDivE').html(message);
            showE = 1;
          } else if (stop > price && money - fee_stop < stop * qty) {
            message = msgNEM1 + qty + msgNEM2 + stop + msgNEM3 + Math.floor(maxbuy) + msgNEM4;
            $('#MNBTradeTextDivE').html(message);
            showE = 1;
          } else if (stop <= price && showE != 1) {
            if (locked > 0 && money - fee_stop - locked < price * qty) {
              $('#MNBTradeTextDivN').html(msgNoticeLocked + '<p>Ezen az áron (' + price + msgNEM3 + Math.floor(maxbuy) + ' darabot tud vásárolni a már beadott megbízások veszélyeztetése nélkül.</p>' + msgNotice);
            } else {
              $('#MNBTradeTextDivN').html(msgNotice);
            }
            showN = 1;
          } else if (locked > 0 && money - fee_stop - locked < stop * qty) {
            $('#MNBTradeTextDivN').html(msgNoticeLocked + '<p>Ezen az áron (' + stop + msgNEM3 + Math.floor(maxbuy) + ' darabot tud vásárolni a már beadott megbízások veszélyeztetése nélkül.</p>');
            showN = 1;
          } else {
            needcheck = 0;
          }
          break;
        case 'limitstop':
          stop = parseFloat($('#MNBTradeLine_stopvalue').val());
          limit = parseFloat($('#MNBTradeLine_limitvalue').val());
          fee_stop = getfee(stop * qty, validuntil);
          fee_limit = getfee(limit * qty, validuntil);
            //  console
            fee_limit = getfee(stop * qty, validuntil);
            console.log('fee_limit:', fee_limit);
            console.log('szabad pénz:', money);
            console.log('quant:', qty);
            console.log('locked', locked);
            feedb = limit*1.0025;
            console.log('1 db:', feedb);
            maxbuy = money / (Math.floor(feedb));
            console.log('maximum megvehető:', Math.floor(maxbuy));
            console.log('tervezett vásárlás összesen', Math.floor(feedb*qty));
            //  /console
          warning = "";
          error = "";
          if (stop <= price) {
            if (limit < price && money - fee_limit < limit * qty && stop != 0) {
              error = error + msgNEM1 + qty + msgNEM2 + limit + msgNEM3 + Math.floor(maxbuy) + msgNEM4;
            } else if (limit >= price && money - fee_limit < limit * qty && stop != 0) {
              error = error + msgNEM1 + qty + msgNEM2 + price + msgNEM3 + Math.floor(maxbuy) + msgNEM4;
            }
          } else {
            if (limit < stop && money - fee_limit < limit * qty && stop != 0 && limit != 0) {
              error = error + msgNEM1 + qty + msgNEM2 + limit + msgNEM3 + Math.floor(maxbuy) + msgNEM4;
            } else if (money - fee_stop < stop * qty && stop != 0) {
              //  passz
              error = error + msgNEM1 + qty + msgNEM2 + stop + msgNEM3 + getqty(money - fee_stop, stop, validuntil) + msgNEM4;
            }
          }
          if (error == "" && (limit < stop || stop <= price)) {
            if (limit < stop) {
              if (locked > 0 && money - fee_limit - locked < limit * qty) {
                warning = warning + msgNoticeLocked + '<p>Ezen az áron (' + limit + msgNEM3 + getqty(money - locked - fee_limit, limit, validuntil) + 'darabot tud vásárolni más megbízások veszélyeztetése nélkül.</p>' + buyLSratio;
              } else {
                warning = warning + buyLSratio;
              }
            }
            if (stop <= price) {
              if (locked > 0 && money - fee_limit - locked < limit * qty && !(limit < stop)) {
                warning = warning + msgNoticeLocked + '<p>Ezen az áron (' + limit + msgNEM3 + getqty(money - locked - fee_limit, limit, validuntil) + 'darabot tud vásárolni más megbízások veszélyeztetése nélkül.</p>' + buyLSLimit;
                if (limit >= price) {
                  warning = warning + msgNoticeLocked + '<p>Ezen az áron (' + limit + msgNEM3 + getqty(money - locked - fee_limit, limit, validuntil) + 'darabot tud vásárolni más megbízások veszélyeztetése nélkül.</p>' + msgNotice;
                }
              } else {
                warning = warning + buyLSLimit;
                if (limit >= price) {
                  warning = warning + msgNotice;
                }
              }
            }
          } else {
            needcheck = 0;
          }
          if (error != "") {
            $('#MNBTradeTextDivE').html(error);
            showE = 1;
          } else if (warning != "") { // ha elseif, akkor ha van error, nem is lesz warning, amugy mindketto lesz
            $('#MNBTradeTextDivN').html(warning);
            showN = 1;
          }
          break;
      }
    }
    if (order == 'market' && elem.attr('id') == orderobj.attr('id')) { //marketra valt az order
      needcheck = 1;
      if (money - fee < price * qty) {
        message = msgNEM1 + qty + msgNEM2 + price + msgNEM3 + getqty(money - fee, price, validuntil) + msgNEM4;
        $('#MNBTradeTextDivE').html(message);
        forceHide = 1;
        showE = 1;
      } else {
        needcheck = 0;
      }
    }
    if (order == 'limit' && elem.attr('id') == $('#MNBTradeLine_limitvalue').attr('id')) { //limit - limitváltozás eseten
      needcheck = 1;
      limit = parseFloat($('#MNBTradeLine_limitvalue').val());
      fee_limit = getfee(limit * qty, validuntil);
      if (limit >= price && money - fee < price * qty && limit != 0) {
        message = msgNEM1 + qty + msgNEM2 + price + msgNEM3 + getqty(money - fee, price, validuntil) + msgNEM4;
        $('#MNBTradeTextDivE').html(message);
        showE = 1;
      } else if (limit <= price && money - fee_limit < limit * qty && limit != 0) {
        message = msgNEM1 + qty + msgNEM2 + limit + msgNEM3 + getqty(money - fee_limit, limit, validuntil) + msgNEM4;
        $('#MNBTradeTextDivE').html(message);
        showE = 1;
      } else if (limit >= price && showE != 1) {
        if (locked > 0 && money - fee_limit - locked < limit * qty) {
          $('#MNBTradeTextDivN').html(msgNoticeLocked + '<p>Ezen az áron (' + price + msgNEM3 + getqty(money - locked - fee_limit, price, validuntil) + ' darabot tud vásárolni más megbízások veszélyeztetése nélkül.</p>' + msgNotice);
        } else {
          $('#MNBTradeTextDivN').html(msgNotice);
        }
        showN = 1;
      } else if (locked > 0 && money - fee_limit - locked < limit * qty && limit != 0) {
        $('#MNBTradeTextDivN').html(msgNoticeLocked + '<p>Ezen az áron (' + limit + msgNEM3 + getqty(money - locked - fee_limit, limit, validuntil) + ' darabot tud vásárolni más megbízások veszélyeztetése nélkül.</p>');
        showN = 1;
      } else {
        needcheck = 0;
      }
    }
    if (order == 'marketstop' && elem.attr('id') == $('#MNBTradeLine_stopvalue').attr('id')) { //stop - stopváltozás eseten
      needcheck = 1;
      stop = parseFloat($('#MNBTradeLine_stopvalue').val());
      fee_stop = getfee(stop * qty, validuntil);
      if (stop <= price && money - fee < price * qty && stop != 0) {
        message = msgNEM1 + qty + msgNEM2 + price + msgNEM3 + getqty(money - fee, price, validuntil) + msgNEM4;
        $('#MNBTradeTextDivE').html(message);
        showE = 1;
      } else if (stop > price && money - fee_stop < stop * qty && stop != 0) {
        message = msgNEM1 + qty + msgNEM2 + stop + msgNEM3 + getqty(money - fee_stop, stop, validuntil) + msgNEM4;
        $('#MNBTradeTextDivE').html(message);
        showE = 1;
      } else if (stop <= price && showE != 1) {
        if (locked > 0 && money - fee - locked < price * qty) {
          $('#MNBTradeTextDivN').html(msgNoticeLocked + '<p>Ezen az áron (' + price + msgNEM3 + getqty(money - locked - fee, price, validuntil) + ' darabot tud vásárolni más megbízások veszélyeztetése nélkül.</p>' + msgNotice);
        } else {
          $('#MNBTradeTextDivN').html(msgNotice);
        }
        showN = 1;
      } else if (locked > 0 && money - fee_stop - locked < stop * qty) {
        $('#MNBTradeTextDivN').html(msgNoticeLocked + '<p>Ezen az áron (' + stop + msgNEM3 + getqty(money - locked - fee_stop, stop, validuntil) + ' darabot tud vásárolni más megbízások veszélyeztetése nélkül.</p>');
        showN = 1;
      } else {
        needcheck = 0;
      }
    }
    if (order == 'limitstop' && (elem.attr('id') == $('#MNBTradeLine_stopvalue').attr('id') || elem.attr('id') == $('#MNBTradeLine_limitvalue').attr('id'))) {
      needcheck = 1;
      stop = parseFloat($('#MNBTradeLine_stopvalue').val());
      limit = parseFloat($('#MNBTradeLine_limitvalue').val());
      fee_limit = getfee(limit * qty, validuntil);
      fee_stop = getfee(stop * qty, validuntil);
      warning = "";
      error = "";
      if (stop <= price) {
        if (limit < price && money - fee_limit < limit * qty && stop != 0) {
          error = error + msgNEM1 + qty + msgNEM2 + limit + msgNEM3 + getqty(money - fee_limit, limit, validuntil) + msgNEM4;
        } else if (limit >= price && money - fee_limit < limit * qty && stop != 0) {
          error = error + msgNEM1 + qty + msgNEM2 + price + msgNEM3 + getqty(money - fee_limit, price, validuntil) + msgNEM4;
        }
      } else {
        if (limit < stop && money - fee_limit < limit * qty && stop != 0 && limit != 0) {
          error = error + msgNEM1 + qty + msgNEM2 + limit + msgNEM3 + getqty(money - fee_limit, limit, validuntil) + msgNEM4;
        } else if (money - fee_stop < stop * qty && stop != 0) {
          error = error + msgNEM1 + qty + msgNEM2 + stop + msgNEM3 + getqty(money - fee_stop, stop, validuntil) + msgNEM4;
        }
      }
      if (error == "" && (limit < stop || stop <= price)) {
        if (limit < stop) {
          if (locked > 0 && money - fee_limit - locked < limit * qty) {
            warning = warning + msgNoticeLocked + '<p>Ezen az áron (' + limit + msgNEM3 + getqty(money - locked - fee_limit, limit, validuntil) + 'darabot tud vásárolni más megbízások veszélyeztetése nélkül.</p>' + buyLSratio;
          } else {
            warning = warning + buyLSratio;
          }
        }
        if (stop <= price) {
          if (locked > 0 && money - fee_limit - locked < limit * qty && !(limit < stop)) {
            warning = warning + msgNoticeLocked + '<p>Ezen az áron (' + limit + msgNEM3 + getqty(money - locked - fee_limit, limit, validuntil) + 'darabot tud vásárolni más megbízások veszélyeztetése nélkül.</p>' + buyLSLimit;
            if (limit >= price) {
              warning = warning + msgNoticeLocked + '<p>Ezen az áron (' + limit + msgNEM3 + getqty(money - locked - fee_limit, limit, validuntil) + 'darabot tud vásárolni más megbízások veszélyeztetése nélkül.</p>' + msgNotice;
            }
          } else {
            warning = warning + buyLSLimit;
            if (limit >= price) {
              warning = warning + msgNotice;
            }
          }
        }
      } else {
        needcheck = 0;
      }
      if (error != "") {
        $('#MNBTradeTextDivE').html(error);
        showE = 1;
      } else if (warning != "") { // ha elseif, akkor ha van error, nem is lesz warning, amugy mindketto lesz
        $('#MNBTradeTextDivN').html(warning);
        showN = 1;
      }
    }
  }
  if (trans == 'sell') {
    price = parseFloat(cur2int($('#' + instrname + "_lastbid").html())); // XXX
    if (elem.attr('id') == qtyobj.attr('id')) { //darabszam valtozas eseten
      if (qty > have) {
        $('#MNBTradeTextDivE').html('<p>Figyelem! ' + have + ' darab részvénnyel rendelkezik, nem adhat el ' + qty + ' darabot!</p>');
        $('#MNBTradeTextTrN').hide();
        forceHide = 1;
        showE = 1;
      }
      if (forceHide != 1) {
        switch (order) {
          case 'market':
            break;
          case 'limit':
            limit = parseFloat($('#MNBTradeLine_limitvalue').val());
            //alert('limit='+limit);
            //BJ
            //if (limit <= price) {
            if (limit > 0 && limit <= price) {
              //BJ
              $('#MNBTradeTextDivN').html(msgNotice);
              showN = 1;
            }
            break;
          case 'marketstop':
            stop = parseFloat($('#MNBTradeLine_stopvalue').val());
            //BJ
            //if (stop >= price) {
            if (stop > 0 && stop >= price) {
              //BJ
              $('#MNBTradeTextDivN').html(msgNotice);
              showN = 1;
            }
            break;
          case 'limitstop':
            needcheck = 1;
            stop = parseFloat($('#MNBTradeLine_stopvalue').val());
            limit = parseFloat($('#MNBTradeLine_limitvalue').val());
            warning = "";
            error = "";
            if (qty > have) {
              error = error + '<p>Figyelem! ' + have + ' darab részvénnyel rendelkezik, nem adhat el ' + qty + ' darabot!</p>';
              $('#MNBTradeTextTrN').hide();
              $('#MNBTradeTextDivE').html(error);
              $('#MNBTradeTextTrN').hide();
              forceHide = 1;
              showE = 1;
            } else if (error == "" && !(qty > have) && limit > 0 && limit > stop || stop > 0 && stop >= price) {
              if (limit > stop) {
                warning = warning + sellLSratio;
              }
              if (stop >= price) {
                warning = warning + sellLSLimit;
                if (limit <= price) {
                  warning = warning + msgNotice;
                }
              }
            } else {
              needcheck = 0;
            }
            if (error != "") {
              $('#MNBTradeTextDivE').html(error);
              showE = 1;
            } else if (warning != "") { // ha elseif, akkor ha van error, nem is lesz warning, amugy mindketto lesz
              $('#MNBTradeTextDivN').html(warning);
              showN = 1;
            }
            break;
          default:
            needcheck = 0;
        }
      }
    }
    if (order == 'limit' && elem.attr('id') == $('#MNBTradeLine_limitvalue').attr('id')) { //limit - limitváltozás eseten
      limit = parseFloat($('#MNBTradeLine_limitvalue').val());
      if (qty > have) {
        $('#MNBTradeTextDivE').html('<p>Figyelem! ' + have + ' darab részvénnyel rendelkezik, nem adhat el ' + qty + ' darabot!</p>');
        $('#MNBTradeTextTrN').hide();
        forceHide = 1;
        showE = 1;
      } else if (limit > 0 && limit <= price && forceHide != 1) {
        $('#MNBTradeTextDivN').html(msgNotice);
        showN = 1;
      } else {
        needcheck = 0;
      }
    }
    if (order == 'marketstop' && elem.attr('id') == $('#MNBTradeLine_stopvalue').attr('id')) { //stop - stopváltozás eseten
      stop = parseFloat($('#MNBTradeLine_stopvalue').val());
      if (qty > have) {
        $('#MNBTradeTextDivE').html('<p>Figyelem! ' + have + ' darab részvénnyel rendelkezik, nem adhat el ' + qty + ' darabot!</p>');
        forceHide = 1;
        showE = 1;
      } else if (stop > 0 && stop >= price && forceHide != 1) {
        $('#MNBTradeTextDivN').html(msgNotice);
        showN = 1;
      }
    }
    if (order == 'limitstop' && (elem.attr('id') == $('#MNBTradeLine_stopvalue').attr('id') || elem.attr('id') == $('#MNBTradeLine_limitvalue').attr('id'))) {
      needcheck = 1;
      stop = parseFloat($('#MNBTradeLine_stopvalue').val());
      limit = parseFloat($('#MNBTradeLine_limitvalue').val());
      warning = "";
      error = "";
      if (qty > have) {
        error = error + '<p>Figyelem! ' + have + ' darab részvénnyel rendelkezik, nem adhat el ' + qty + ' darabot!</p>';
        $('#MNBTradeTextTrN').hide();
        $('#MNBTradeTextDivE').html(error);
        $('#MNBTradeTextTrN').hide();
        forceHide = 1;
        showE = 1;
      } else if (error == "" && !(qty > have) && limit > 0 && stop > 0 && limit > stop || stop >= price) {
        if (limit > stop) {
          warning = warning + sellLSratio;
        }
        if (stop >= price) {
          warning = warning + sellLSLimit;
          if (limit <= price) {
            warning = warning + msgNotice;
          }
        }
      } else {
        needcheck = 0;
      }
      if (error != "") {
        $('#MNBTradeTextDivE').html(error);
        showE = 1;
      } else if (warning != "") { // ha elseif, akkor ha van error, nem is lesz warning, amugy mindketto lesz
        $('#MNBTradeTextDivN').html(warning);
        showN = 1;
      }
    }
    if (elem.attr('id') == orderobj.attr('id')) { //tipus valtozas eseten
      if (qty > have) {
        $('#MNBTradeTextDivE').html('<p>Figyelem! ' + have + ' darab részvénnyel rendelkezik, nem adhat el ' + qty + ' darabot!</p>');
        $('#MNBTradeTextTrN').hide();
        forceHide = 1;
        showE = 1;
      }
    }
  }
  if (showE == 1) {
    $('#MNBTradeTextTrE').show();
    var tradenoticebottom = $('#MNBTradeTextTrE').offset().top + $('#MNBTradeTextTrE').height();
    var screentop = $(window).scrollTop();
    var screenbottom = screentop + $(window).height();
    if (tradenoticebottom > screenbottom) {
      $.scrollTo(screentop + (tradenoticebottom - screenbottom), 'normal');
    }
  } else {
    $('#MNBTradeTextTrE').hide();
  }
  if (showN == 1) {
    $('#MNBTradeTextTrN').show();
    var tradenoticebottom = $('#MNBTradeTextTrN').offset().top + $('#MNBTradeTextTrN').height();
    var screentop = $(window).scrollTop();
    var screenbottom = screentop + $(window).height();
    if (tradenoticebottom > screenbottom) {
      $.scrollTo(screentop + (tradenoticebottom - screenbottom), 'normal');
    }
    var t = setTimeout("needcheck=0;$('#MNBTradeTextDivN').html($('#MNBTradeTextDivN').html()+userwantsit )", 1000);
  } else {
    $('#MNBTradeTextTrN').hide();
  }
}

function rgbone(stock) {
  $('#' + stock + '_changept').removeClass('MNBPositive MNBNegative MNBNoChange MNBFlashUp');
  $('#' + stock + '_changepct').removeClass('MNBPositive MNBNegative MNBNoChange MNBFlashUp');
  $('#' + stock + '_profit').removeClass('MNBPositive MNBNegative MNBNoChange MNBFlashUp');
  if ($('#' + stock + '_changept').text() == 'n/a') {} else if ($('#' + stock + '_changept').text() > '0') {
    $('#' + stock + '_changept').addClass('MNBPositive');
    $('#' + stock + '_changepct').addClass('MNBPositive');
  } else if ($('#' + stock + '_changept').text() < '0') {
    $('#' + stock + '_changept').addClass('MNBNegative');
    $('#' + stock + '_changepct').addClass('MNBNegative');
  } else if ($('#' + stock + '_changept').text() == '0') {
    $('#' + stock + '_changept').addClass('MNBNoChange');
    $('#' + stock + '_changepct').addClass('MNBNoChange');
  }
  if ($('#' + stock + '_profit').text() > '0') {
    $('#' + stock + '_profit').addClass('MNBPositive');
  } else if ($('#' + stock + '_profit').text() < '0') {
    $('#' + stock + '_profit').addClass('MNBNegative');
  } else if ($('#' + stock + '_profit').text() == '0') {
    $('#' + stock + '_profit').addClass('MNBNoChange');
  }
}

function ordertype(type) {
  switch (type) {
    case 'market':
      $('#MNBTradeLine_limit').hide();
      $('#MNBTradeLine_stop').hide();
      $('#MNBTradeLine_limitvalue').val('');
      $('#MNBTradeLine_stopvalue').val('');
      break;
    case 'limit':
      $('#MNBTradeLine_limit').show();
      $('#MNBTradeLine_stop').hide();
      $('#MNBTradeLine_limitvalue').val('');
      $('#MNBTradeLine_stopvalue').val('');
      break;
    case 'marketstop':
      $('#MNBTradeLine_limit').hide();
      $('#MNBTradeLine_stop').show();
      $('#MNBTradeLine_limitvalue').val('');
      $('#MNBTradeLine_stopvalue').val('');
      break;
    case 'limitstop':
      $('#MNBTradeLine_limit').show();
      $('#MNBTradeLine_stop').show();
      $('#MNBTradeLine_limitvalue').val('');
      $('#MNBTradeLine_stopvalue').val('');
      break;
  }
}

function submittrade() {
  //	alert('Megjelent a box submitra? : ' + areusure + '\nMeg kellett volna jelennie? : ' + checkvalid + '(Ha megjelent, akkor a 0 érték jó)' );
  var invalid = 0;
  var expire = $('#MNBTradeLine_expire');
  var trans = $('#MNBTradeLine_trans');
  var qty = $('#MNBTradeLine_qty');
  var otype = $('#MNBTradeLine_ordertype');
  var limit = $('#MNBTradeLine_limitvalue');
  var stopv = $('#MNBTradeLine_stopvalue');
  var instr = $('#MNBTradeLine_instr');
  qty.removeClass("MNBInputError");
  limit.removeClass("MNBInputError");
  stopv.removeClass("MNBInputError");
  if ((1 * (qty.val())) <= 0) {
    qty.addClass("MNBInputError");
    invalid |= 1;
  }
  if ((otype.val() == "limit" || otype.val() == "limitstop") && (1 * (limit.val())) <= 0) {
    limit.addClass("MNBInputError");
    invalid |= 2;
  }
  if ((otype.val() == "marketstop" || otype.val() == "limitstop") && (1 * (stopv.val())) <= 0) {
    stopv.addClass("MNBInputError");
    invalid |= 4;
  }
  /*		if (invalid) {
  			alert("inalid expire:"+expire.val()+"\ntrans:"+trans.val()+"\nqty:"+qty.val()+"\norder:"+otype.val()+"\nlimit:"+limit.val()+"\nstop:"+stopv.val());
  		}*/
  if (needcheck == 0 && !invalid) {
    $.ajax({
      type: "GET",
      url: "index.php",
      data: "module=backend&action=orders&instr=" + instr.val() + "&expire=" + expire.val() + "&trans=" + trans.val() + "&qty=" + qty.val() + "&type=" + otype.val() + "&limit=" + limit.val() + "&stopv=" + stopv.val(),
      success: function(xml) {
        var res = xml.split(";");
        //document.write(xml);
        if ("" + res[0] == "0") {
          $('#action').val('orders');
          $('#module').val('backend');
          $('#MNBForm').submit();
          //closetrader();
          return;
        }
        //alert(res[1]);
      },
      error: function(xml, msg, xcept) {
        alert("submittrade() fail! " + msg);
      }
    });
  } else {
    needcheck = 0;
  }

}

function refreshportfolio() {
  var xmlurl = server_base_url + indexphp_base_url + '?module=backend&action=portfolio&user=' + $('#MNBTopHtmlUserId').html();
  /*
  var xml=$.ajax({
  type: "GET",
  url: xmlurl + '&rand=' + Math.random(),
  dataType: "xml"
  }).responseText;
  if ($(xml).find('exit').text() == 'true') {
  window.location.href = server_base_url + indexphp_base_url + '?logout';
  }
  if ($(xml).find('eqnews').text() == 'new') {
  $('#eqnewstab').addClass('neweqpost');
  }
  if ($.trim($('#MNBAccount_money_ininstr').text()) != int2cur($(xml).find('money_ininstr').text()) ||
  $.trim($('#MNBAccount_money_invested').text()) != int2cur($(xml).find('money_invested').text())) {
  var ininstr=int2cur($(xml).find('money_ininstr').text());
  var free=int2cur($(xml).find('money_free').text());
  var all=int2cur($(xml).find('money_all').text());
  var yield=int2cur($(xml).find('money_yield').text());
  var fee=int2cur($(xml).find('fee').text());
  $('#MNBAccount_money_ininstr').text(ininstr);
  $('.MNBAccount_money_ininstr').text(ininstr);
  $('.MNBAccount_money_ininstr').autoNumeric('update');
  $('#MNBAccount_money_free').text(free);
  $('.MNBAccount_money_free').text(free);
  $('.MNBAccount_money_free').autoNumeric('update');
  $('#MNBAccount_money_all').text(all);
  $('.MNBAccount_money_all').text(all);
  $('.MNBAccount_money_all').autoNumeric('update');
  $('#MNBAccount_money_yield').text(yield);
  $('.MNBAccount_money_yield').text(yield);
  $('.MNBAccount_money_yield').autoNumeric('update');
  $('.MNBAccount_money_fee').text(fee);
  $('.MNBAccount_money_fee').autoNumeric('update');
  }
  if ($(xml).find('bse_openclose').text() == 'close') {
  refreshtime = 60 * 1000; // percenkent, ha nincs tozsde
  $('#MNBBseOpenClose').text('BÉT: zárva');
  } else if ($(xml).find('bse_openclose').text() == 'open') {
  refreshtime = 3 * 1000; // 3 masodpercenkent ha van tozsde
  $('#MNBBseOpenClose').text('BÉT: nyitva');
  }
  // }}} 
  // {{{ portfolioinfo
  var sumfee=0;
  $(xml).find('stock').each(function() {
  var instr = $(this).attr('name');
  var newqty = $(this).find('qty').text();
  var thisqty = $('#' + instr + '_qty').html();
  var newdt_qty = $(this).find('dt_qty').text();
  var thisdt_qty = $('#' + instr + '_dt_qty').html();
  var thislast = $('#' + instr + '_last').html();
  var thisbid = $('#' + instr + '_bid').html();
  var thisask = $('#' + instr + '_ask').html();

  // If there is a priceinfo section...
  var priceinfo = $(xml).find('price[name="' + instr + '"]');
  if (priceinfo.length > 0) {
    // ... work from it...
    var newlast = $(priceinfo).find('last').text();
    var newbid = $(priceinfo).find('bid').text();
    var newask = $(priceinfo).find('ask').text();
    //console.log('used priceinfo');
  } else {
    // ... or else, use 'stock' prices.
    var newlast = $(this).find('last').text();
    var newbid = $(this).find('bid').text();
    var newask = $(this).find('ask').text();
  }

  if (0 && instr == 'ETFBUXOTP') {
    var thisprofit = $('#' + instr + '_profit').html();
    var newprofit = $(this).find('profit').text();
    alert('instr: ' + instr + ' \n' +
    'thislast: [' + cur2int(thislast) + '] \n' +
    'newlast: [' + cur2int(newlast) + ']\n' +
    'thisbid: [' + cur2int(thisbid) + ']\n' +
    'newbid: [' + cur2int(newbid) + ']\n' +
    'thisask: [' + cur2int(thisask) + ']\n' +
    'newask: [' + cur2int(newask) + ']\n' +
    'thisprofit: [' + cur2int(thisprofit) + ']\n' +
    'newprofit: [' + cur2int(newprofit) + ']\n'
    );
  }

  $('#' + instr + '_last').removeClass('MNBPositive MNBNegative MNBNoChange MNBFlashUp');
  if (cur2int(thislast) != cur2int(newlast) || cur2int(thisbid) != cur2int(newbid) || cur2int(thisask) != cur2int(newask) || thisqty != newqty || thisdt_qty != newdt_qty) {
    //console.log("newbid: " + cur2int(newbid) + " / thisbid: " + cur2int(thisbid));
    if (cur2int(thislast) > cur2int(newlast)) {
    $('#' + instr + '_last').addClass('MNBFlashUp MNBNegative');
    } else if (cur2int(thislast) < cur2int(newlast)) {
    $('#' + instr + '_last').addClass('MNBFlashUp MNBPositive');
    }
    $('#' + instr + '_last').html(int2cur(newlast));
    $('#' + instr + '_bid').html(int2cur(newbid));
    $('#' + instr + '_ask').html(int2cur(newask));
    $('#' + instr + '_qty').html(newqty);
    $('#' + instr + '_dt_qty').html(newdt_qty);
    $('#' + instr + '_changept').html($(this).find('changept').text());
    $('#' + instr + '_changepct').html($(this).find('changepct').text() + '%');
    $('#' + instr + '_price').html(int2cur($(this).find('price').text()));
    $('#' + instr + '_lastbid').html(int2cur($(this).find('lastbid').text()));
    $('#' + instr + '_lastask').html(int2cur($(this).find('lastask').text()));
    $('#' + instr + '_profit').html(int2cur($(this).find('profit').text()));
    $('#' + instr + '_stamp').html($(this).find('stamp').text());
    if (instr == ($('#MNBTradeLine_instr').val())) {
    //alert ($('#MNBTradeLine_instr').val()) ;
    $('#MNBTradeInfo_stamp').html($(this).find('stamp').text());
    $('#MNBTradeInfo_lastbid').html(int2cur($(this).find('lastbid').text()));
    $('#MNBTradeInfo_lastask').html(int2cur($(this).find('lastask').text()));
    }
    if (cur2int(thislast) != cur2int(newlast)) {
    $('#' + instr + '_gfx').attr('src', 'https://arfolyamsms.hu/charts_rt/' + instr + '_color.gif?mnbgame=' + Math.random());
    }
    if ($(this).find('orderid').text() < 1) {
    $('#MNBTradeOrder_' + instr).removeAttr('href');
    $('#MNBTradeOrderIcon_' + instr).attr('src', 'images/orderworkingnot3.gif');
    }
    if (newqty > '0') {
    $('#MNBTradeSell_' + instr).attr('href', 'javascript:opentrader("sell", "' + instr + '")');
    $('#MNBTradeSellIcon_' + instr).attr('src', 'images/minusicon.gif');
    } else {
    $('#MNBTradeSell_' + instr).removeAttr('href');
    $('#MNBTradeSellIcon_' + instr).attr('src', 'images/minusiconoff2.gif');
    }
    rgbone(instr);     
  }
  //  auction  bestbid>=bestask,
  abid = parseFloat(cur2int($('#' + instr + "_lastbid").text()));
  aask = parseFloat(cur2int($('#' + instr + "_lastask").text()));
  if (abid >= aask) {
    $('#'+ instr + '_auction').html('<span class="glyphicon glyphicon-alert danger" data-toggle="tooltip" data-placement="right" title="A részvény az aukciós szakaszban nem kereskedhető" aria-hidden="true"></span> Aukció');      
    $('#INSTR_' + instr).removeClass('info').addClass('alert-danger');
    $('#' + instr+'_tradebutton').hide();
  } else {
    $('#'+ instr + '_auction').html('');
    $('#' + instr+'_tradebutton').show();
    $('#INSTR_' + instr).removeClass('alert-danger').addClass('info');
  }
  // /auction    
  }); //close each(
  */

  $.ajax({
    type: "GET",
    url: xmlurl + '&rand=' + Math.random(),
    dataType: "xml",
    success: function(xml) {
      // {{{ accountinfo
      if ($(xml).find('exit').text() == 'true') {
        window.location.href = server_base_url + indexphp_base_url + '?logout';
      }
      if ($(xml).find('eqnews').text() == 'new') {
        $('#eqnewstab').addClass('neweqpost');
      }
      if ($.trim($('#MNBAccount_money_ininstr').text()) != int2cur($(xml).find('money_ininstr').text()) ||
        $.trim($('#MNBAccount_money_invested').text()) != int2cur($(xml).find('money_invested').text())) {
        var ininstr = int2cur($(xml).find('money_ininstr').text());
        var free = int2cur($(xml).find('money_free').text());
        var all = int2cur($(xml).find('money_all').text());
        var yield = int2cur($(xml).find('money_yield').text());        
        var fee = int2cur($(xml).find('fee').text());
        free=(free ? free : 0);
        all=(all ? all : 0);
        yield=(yield ? yield : 0);
        fee=(fee ? fee : 0);
        $('#MNBAccount_money_ininstr').text(ininstr);
        $('.MNBAccount_money_ininstr').text(ininstr);
        $('.MNBAccount_money_ininstr').autoNumeric('update');
        $('#MNBAccount_money_free').text(free);
        $('.MNBAccount_money_free').text(free);
        $('.MNBAccount_money_free').autoNumeric('update');
        $('#MNBAccount_money_all').text(all);
        $('.MNBAccount_money_all').text(all);
        $('.MNBAccount_money_all').autoNumeric('update');
        $('#MNBAccount_money_yield').text(yield);
        $('.MNBAccount_money_yield').text(yield);
        $('.MNBAccount_money_yield').autoNumeric('update');
        $('.MNBAccount_money_fee').text(fee);
        $('.MNBAccount_money_fee').autoNumeric('update');
      }
      if ($(xml).find('bse_openclose').text() == 'close') {
        refreshtime = 3 * 1000; // percenkent, ha nincs tozsde
        $('#MNBBseOpenClose').text('BÉT: zárva');
      } else if ($(xml).find('bse_openclose').text() == 'open') {
        refreshtime = 3 * 1000;
        $('#MNBBseOpenClose').text('BÉT: nyitva');
      }
      // }}} 
      // {{{ portfolioinfo
      var sumfee = 0;
      $(xml).find('stock').each(function() {
        var instr = $(this).attr('name');
        var newqty = $(this).find('qty').text();
        var thisqty = $('#' + instr + '_qty').html();
        var newdt_qty = $(this).find('dt_qty').text();
        var thisdt_qty = $('#' + instr + '_dt_qty').html();
        var thislast = $('#' + instr + '_last').html();
        var thisbid = $('#' + instr + '_bid').html();
        var thisask = $('#' + instr + '_ask').html();
        // If there is a priceinfo section...
        var priceinfo = $(xml).find('price[name="' + instr + '"]');
        if (priceinfo.length > 0) {
          // ... work from it...
          var newlast = $(priceinfo).find('last').text();
          var newbid = $(priceinfo).find('bid').text();
          var newask = $(priceinfo).find('ask').text();
          //console.log('used priceinfo');
        } else {
          // ... or else, use 'stock' prices.
          var newlast = $(this).find('last').text();
          var newbid = $(this).find('bid').text();
          var newask = $(this).find('ask').text();
        }
        if (0 && instr == 'ETFBUXOTP') {
          var thisprofit = $('#' + instr + '_profit').html();
          var newprofit = $(this).find('profit').text();
          alert('instr: ' + instr + ' \n' +
            'thislast: [' + cur2int(thislast) + '] \n' +
            'newlast: [' + cur2int(newlast) + ']\n' +
            'thisbid: [' + cur2int(thisbid) + ']\n' +
            'newbid: [' + cur2int(newbid) + ']\n' +
            'thisask: [' + cur2int(thisask) + ']\n' +
            'newask: [' + cur2int(newask) + ']\n' +
            'thisprofit: [' + cur2int(thisprofit) + ']\n' +
            'newprofit: [' + cur2int(newprofit) + ']\n'
          );
        }
        $('#' + instr + '_last').removeClass('MNBPositive MNBNegative MNBNoChange MNBFlashUp');
        if (cur2int(thislast) != cur2int(newlast) || cur2int(thisbid) != cur2int(newbid) || cur2int(thisask) != cur2int(newask) || thisqty != newqty || thisdt_qty != newdt_qty) {
          //console.log("newbid: " + cur2int(newbid) + " / thisbid: " + cur2int(thisbid));
          if (cur2int(thislast) > cur2int(newlast)) {
            $('#' + instr + '_last').addClass('MNBFlashUp MNBNegative');
          } else if (cur2int(thislast) < cur2int(newlast)) {
            $('#' + instr + '_last').addClass('MNBFlashUp MNBPositive');
          }
          $('#' + instr + '_last').html(int2cur(newlast));
          $('#' + instr + '_bid').html(int2cur(newbid));
          $('#' + instr + '_ask').html(int2cur(newask));
          $('#' + instr + '_qty').html(newqty);
          $('#' + instr + '_dt_qty').html(newdt_qty);
          $('#' + instr + '_changept').html($(this).find('changept').text());
          $('#' + instr + '_changepct').html($(this).find('changepct').text() + '%');
          $('#' + instr + '_price').html(int2cur($(this).find('price').text()));
          $('#' + instr + '_lastbid').html(int2cur($(this).find('lastbid').text()));
          $('#' + instr + '_lastask').html(int2cur($(this).find('lastask').text()));
          $('#' + instr + '_profit').html(int2cur($(this).find('profit').text()));
          $('#' + instr + '_stamp').html($(this).find('stamp').text());
          if (instr == ($('#MNBTradeLine_instr').val())) {
            //alert ($('#MNBTradeLine_instr').val()) ;
            $('#MNBTradeInfo_stamp').html($(this).find('stamp').text());
            $('#MNBTradeInfo_lastbid').html(int2cur($(this).find('lastbid').text()));
            $('#MNBTradeInfo_lastask').html(int2cur($(this).find('lastask').text()));
          }
          if (cur2int(thislast) != cur2int(newlast)) {
            $('#' + instr + '_gfx').attr('src', 'https://arfolyamsms.hu/charts_rt/' + instr + '_color.gif?mnbgame=' + Math.random());
          }
          if ($(this).find('orderid').text() < 1) {
            $('#MNBTradeOrder_' + instr).removeAttr('href');
            $('#MNBTradeOrderIcon_' + instr).attr('src', 'images/orderworkingnot3.gif');
          }
          if (newqty > '0') {
            $('#MNBTradeSell_' + instr).attr('href', 'javascript:opentrader("sell", "' + instr + '")');
            $('#MNBTradeSellIcon_' + instr).attr('src', 'images/minusicon.gif');
          } else {
            $('#MNBTradeSell_' + instr).removeAttr('href');
            $('#MNBTradeSellIcon_' + instr).attr('src', 'images/minusiconoff2.gif');
          }
          rgbone(instr);

          //  auction  bestbid>=bestask,
          abid = parseFloat(cur2int($('#' + instr + "_lastbid").text()));
          aask = parseFloat(cur2int($('#' + instr + "_lastask").text()));
          var auctionDate = new Date();
          var auctionTime = auctionDate.toTimeString().split(' ')[0].split(':');
          var currentTime = (auctionTime[0] + '' + auctionTime[1]);
          if (abid >= aask) {          
                  $('#submittradebtn').prop('disabled', true); 
                  $('#' + instr + '_auction').html('<span class="glyphicon glyphicon-alert danger" aria-hidden="true"></span> ');
                  $('#' + instr + '_trade').removeClass('info').addClass('alert-danger');
                  $('#' + instr + '_instr').removeClass('info').addClass('alert-danger');
                  $('#' + instr + '_bid').removeClass('info').addClass('alert-danger');
                  $('#' + instr + '_ask').removeClass('info').addClass('alert-danger');
                  $('.closedalert').hide();
          } else {
                  $('#' + instr + '_auction').html('');
                  $('#' + instr + '_instr').removeClass('alert-danger').addClass('info'); //alert-danger _bid _ak
                  $('#' + instr + '_trade').removeClass('alert-danger').addClass('info');
                  $('#' + instr + '_bid').removeClass('alert-danger').addClass('info');
                  $('#' + instr + '_ask').removeClass('alert-danger').addClass('info');
          }
          if (currentTime >= '1705' || currentTime <= '0855') {
                  var notradealert = '<a class="my-tool-tip" data-toggle="tooltip" data-placement="left" title="Kereskedési időn kívül nem adhat be piaci megbízást"><i class="glyphicon glyphicon-info-sign"></i></a>';
                  $('#marketdropdown').prop('disabled', true);
                  $('.prtr').prop('disabled', true);          
                  $('#' + instr + '_ask').replaceWith("<td></td>");
                  $('#' + instr + '_bid').replaceWith("<td></td>");
                  $('#notrade').replaceWith(notradealert);
                  $('#' + instr + '_instr').removeClass('alert-danger').addClass('info'); //alert-danger _bid _ak
                  $('#' + instr + '_trade').removeClass('alert-danger').addClass('info');
            } else {
	              $('#' + instr + '_instr').removeClass('alert-danger').addClass('info'); //alert-danger _bid _ak
	              $('#' + instr + '_trade').removeClass('alert-danger').addClass('info');
           }            

          // /auction     


          //$('.auto').autoNumeric('update',autoNumericSetup);
        }
      }); //close each(
      // }}} 
    }
  }); //close $.ajax(

}

function checkcash() {
  $('#MNBAccount_money_free').change(
    function() {
      $('#MNBTradeLine_notice').html('money');
    }
  )
}

function cur2int(x) {
  if (x == null) return 0;
  return parseInt(x.replace(/ /g, ''));
}

/*function int2cur(nStr) {
  nStr += '';
  x = nStr.split('.');
  x1 = x[0];
  x2 = x.length > 1 ? ',' + x[1] : '';
  var rgx = /(\d+)(\d{3})/;
  while (rgx.test(x1)) {
  x1 = x1.replace(rgx, '$1' + ' ' + '$2');
  }
  return x1 + x2;
}
*/
function int2cur(nStr) {
  return nStr;
}

function getfee(price, validuntil) {
  minFee = 150;
  perc = 0.0025;
  if (validuntil == 'dt') {
    minFee = 100;
    perc = 0.0015;
  }
  fee = Math.max(price * perc, minFee);
  return Math.floor(fee);
}

function getqty(fm, price, validuntil) {
  //fee = getfee(price, validuntil);
  return Math.floor(fm / price);
}

/*
function getqty(fm, price, validuntil) {
    perc = 1.0025;
    if (validuntil == 'dt') {
        perc = 1.0015;
    }
    return Math.floor(fm / (1 * price * perc));
}
*/

function refreshpage() {
  refreshportfolio();
  clearInterval(refreshId);
  refreshId = setInterval("refreshpage()", refreshtime);
  //$('.auto').autoNumeric('update',autoNumericSetup);
}

var refreshId;
var refreshtime = 2000;
$(document).ready(function() {
  rgb();
  //$('.auto').autoNumeric('init',autoNumericSetup);
  //BJ
  //teszthez
  // if (window.location.href.indexOf('aiee')){
  //   $('.well').show();
  // }
  $('.MNBAccount_money_yield').change(function() {
    $(this).text($(this).text().replace('.', ','));
  });
  //BJ
  /*
  //BJ
  $('#MNBTradeLine_ordertype').change(function() {
  instr=$(".trade_stockname").val();
  ordertype($('#MNBTradeLine_ordertype').val(),instr);
  }); // close change(
  */
  refreshtime = 2000;

  refreshId = setInterval(refreshpage, refreshtime);
  $('#MNBTradeLine_qty').keyup(function(e) {
    this.value = this.value.replace(/\D/g, '');
  });

  var cursorX;
  var cursorY;
  document.onmousemove = function(e) {
    cursorX = e.pageX;
    cursorY = e.pageY;
  }

  //var hiconfig = { over: chartOnHover, timeout: 3000, out: chartOffHover }
  //$('.chartpu').hoverIntent( hiconfig );
  //$('.chartpu').hoverIntent(chartOnHover, chartOffHover);

  /*
    function chartOnHover() {
    $('#chartpopup').css({
      'top': cursorY,
      'left': cursorX - 50
    });
    bse = $(this).attr('bseid');
    $(this).mousemove(function() {
      //$('#chartpopup').css({'top':event.pageY,'left':event.pageX-50});
      $('#chartpopup').css({
      'top': cursorY,
      'left': cursorX - 50
      });
    });
    $('#chartpopup').show();
    $('#chartpopup').html('<iframe src="https://bet.hu/iframe/magyar_egyeb/portlets?portalstate=tozsdejatek_chart&security=' + bse + '&width=120&height=80" frameborder="0" width="140" height="100" scrolling="no"></iframe>');
    }

    function chartOffHover() {
    $("#chartpopup").html('');
    }
  */

  $('[data-toggle="tooltip"]').tooltip();
  $("a.market-tool-tip").tooltip();
  // datatables listview
  $('#MNBTradeLineTr').css('display', 'none');



  var listview = $('table.dataTable').DataTable({
    paging: false,
    searching: false,
    responsive: true,
    ordering:true,
    decimal: ",",
    thousands: ".",
    columnDefs: [
       { type: 'numeric-comma', targets: [2,3,4,5,6,7,8,9,10]},
       { type: 'currency', targets:[ 2,3,4,5,6] }
    ]
  });



});