<!-- BEGIN: MAIN -->

<link rel="stylesheet" type="text/css" href="themes/itbirja/css/fontawesome.v5.min.css">
<div class="m-hidden">
  <div class="userbanner" style="background: url(<!-- IF {PHP.usr.profile.user_photo} -->{PHP.usr.profile.user_photo}<!-- ELSE -->themes/itbirja/files/cover/header1.jpg<!-- ENDIF -->) no-repeat center center; background-size: cover;">
    <div class="centerwrap clearfix">
      <div class="contentArea mt40 sm-text-center">
        <div class="pull-left sm-pull-reset"><img class="rounded" alt="{PHP.usr.name}" src="<!-- IF {PHP.usr.profile.user_avatar} -->{PHP.usr.profile.user_avatar}<!-- ELSE -->themes/itbirja/files/avatar/big/noprofilepicture.gif<!-- ENDIF -->" width="80" height="80"/></div>
        <div class="userbannertext pull-left ml15 sm-pull-reset m-text-center m-m0">
          <div>
            <h1 class="mt0">{PHP.usr.name}</h1>
            <span class="font-OpenSans f14 ml14 is-online-block color-lightGray"><i class="icon ico-online"></i> Онлайн</span>
          </div>
          <div class="color-white2 sm-pull-reset mb10">{PHP.usr.profile.user_FNAME}</div>
          <div class="color-white">
            <div class="pull-left cusongsblock-panel__rating mti3">
              <ul class="rating-block dib v-align-m">
                <!-- IF {PHP.usr.tags.RSTAR} > 0 -->
                <li class="mr2 v-align-m">
                    <i class="fa fa-star gold" aria-hidden="true"></i>
                </li>
                <li class="rating-block__rating-item--number fw600 v-align-m">{PHP.usr.tags.RSTAR}&nbsp;</li>
                <!-- ENDIF -->
              </ul>
            </div>
            <p class="dib sm-pull-reset color-white2"><!-- IF {PHP.urr.user_maingrp} == 7 -->{PHP.usr.tags.MK_PAYER_GROUP}<!-- ELSE -->{PHP.usr.tags.MK_SELLER_GROUP}<!-- ENDIF --></p>
            <span class="ml5"></span>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
<div class="page-balance">

  <div class="centerwrap clearfix pt20 pb0 block-response">
    <h1 class="f32">Баланс</h1>
    {FILE "{PHP.cfg.themes_dir}/{PHP.cfg.defaulttheme}/warnings.tpl"}
  </div>

  <!-- BEGIN: HISTORY -->
  <div class="centerwrap clearfix pb0 block-response">
    <div class="balance-info-block">
      <div class="balance-info-block__summ">
        {BALANCE_SUMM_DODJI}&nbsp;<span class="rouble rouble-dodji">RZ</span>
      </div>
      <div class="balance-info-block__action mt20">
        Внутренняя валюта "{PHP.cfg.payments.valutadodji}", курс валюты 1 <span class="rouble">Р</span> = {PHP.cfg.payments.dodjirate} <span class="rouble rouble-dodji">RZ</span>
      </div>
    </div>
    <div class="balance-info-block">
      <div class="balance-info-block__summ">
        {BALANCE_SUMM}&nbsp;<span class="rouble">Р</span>
      </div>
      <div class="balance-info-block__action">
        <div class="btn-group btn-group-js btn-group_2 dib v-align-m page-balance_btn-group">
          <div class="green-btn balance-refill-btn-js" id="increase-balance" onclick="toggleBalanceRefillPopup();show_balance_popup('', 'balance');">Пополнить баланс</div>
          <!-- IF {PHP.cfg.payments.payouts_enabled} -->
            <a href="{BALANCE_PAYOUT_URL}" class="white-btn white-btn_no-hover white-btn_hover-white withdraw-money-btn-js">Вывести деньги</a>
          <!-- ENDIF -->
        </div>
      </div>
    </div>
  </div>

<div class="centerwrap clearfix pb0 block-response">
    <div class="filter-balance__block hide">
      <div class="filter-balance__form">
        <form action="{PHP|cot_url('payments', 'm=balance')}" method="get" name="balanceform">
          <input type="hidden" name="n" value="history" />
          <div class="fields__row">
            <div class="field__inline w100">
              <input type="text" id="from" name="from" value="{PHP.from}" max="2018-05-29" min="2018-03-01" class="input js-input__calendar w110" data-position="bottom left" placeholder="От" data-placeholder="От">
              <span class="js-input__calendar-clear">
                <svg xmlns="http://www.w3.org/2000/svg" width="10" height="10">
                  <polygon points="10,0.7 9.3,0 5,4.3 0.7,0 0,0.7 4.3,5 0,9.3 0.7,10 5,5.7 9.3,10 10,9.3 5.7,5"/>
                </svg>
              </span>
            </div>
            <div class="field__inline w100">
              <input type="text" id="to" name="to" value="{PHP.to}" class="input js-input__calendar w110" data-position="bottom left" placeholder="До" data-placeholder="До">
              <span class="js-input__calendar-clear">
                <svg xmlns="http://www.w3.org/2000/svg" width="10" height="10">
                  <polygon points="10,0.7 9.3,0 5,4.3 0.7,0 0,0.7 4.3,5 0,9.3 0.7,10 5,5.7 9.3,10 10,9.3 5.7,5"/>
                </svg>
              </span>
            </div>
            <div class="field__inline w358px js-multiselectGroup type-operation-select">
              <select multiple="multiple" class="js-select__checkbox" name="operation[]">
                <option value="all"<!-- IF {PHP.operation|count($this)} == 0 --> selected="selected"<!-- ENDIF -->>Все операции</option>
                <optgroup label="Пополнение">
                  <option value="refund"<!-- IF {PHP.operation|in_array('refund', $this)} --> selected="selected"<!-- ENDIF -->>Возврат оплаты заказа</option>
                  <option value="refill"<!-- IF {PHP.operation|in_array('refill', $this)} --> selected="selected"<!-- ENDIF -->>Пополнение баланса</option>
                  <option value="order_in"<!-- IF {PHP.operation|in_array('order_in', $this)} --> selected="selected"<!-- ENDIF -->>Начисление за сделанный заказ</option>
                </optgroup>
                <optgroup label="Списание">
                  <option value="withdraw"<!-- IF {PHP.operation|in_array('withdraw', $this)} --> selected="selected"<!-- ENDIF -->>Вывод</option>
                  <option value="order_out"<!-- IF {PHP.operation|in_array('order_out', $this)} --> selected="selected"<!-- ENDIF -->>Оплата заказа</option>
                </optgroup>
              </select>
            </div>
            <div class="field__inline w358px select__single">
              <select name="market-order" placeholder="Название {PHP|cot_sitename('padeg', 'r')}" class="js-select__single filter-prd-name mobile-css-style">
                <option selected value="">Название {PHP|cot_sitename('padeg', 'r')}</option>
                <!-- IF {PHP.user_marketitems|count($this)} > 0 -->
                  <!-- FOR {KEY}, {TITLE} IN {PHP.user_marketitems} -->
                    <option value="{KEY}"<!-- IF {KEY} == {PHP.market_order} --> selected="selected"<!-- ENDIF -->>{TITLE}</option>
                  <!-- ENDFOR -->
                <!-- ENDIF -->
              </select>
            </div>
            <div class="field__inline w50">
              <input type="submit" role="button" name="" class="input w50" value="Поиск" style="padding: 5px;">
            </div>
          </div>
        </form>
      </div>
    </div>
  </div>

  <div class="centerwrap clearfix mt0 pb20 block-response mt15 m-p0" id="operations-result">
    <table class="table-style response-table m-order-table">
      <thead>
        <tr>
          <td class="w19p">
            <div class="ml20"><span class="js-table-head__filter" data-filter="date">Дата </span></div>
          </td>
          <td class="w52p"><span class="js-table-head__filter" data-filter="description">Описание </span></td>
          <td class="w12p"><span class="js-table-head__filter" data-filter="sum">Сумма </span></td>
          <td class="pr0"><span class="js-table-head__filter" data-filter="status">Статус </span></td>
        </tr>
      </thead>
      <tbody>
        <!-- BEGIN: HIST_ROW -->
        <tr>
          <td class="pl20  m-text-right">{HIST_ROW_PDATE|cot_date('d.m.Y, в H:i', $this)}</td>
          <td class="clearfix">
            {HIST_ROW_DESC}
          </td>
          <td class="m-visible clearfix p0"></td>
          <td class="m-w50p m-pull-right  m-text-right">
            <!-- IF {HIST_ROW_AREA} != 'balance' -->-<!-- ENDIF -->
            <!-- IF {HIST_ROW_IN_DODJI} -->{HIST_ROW_SUMM_DODJI|number_format($this, 2, '.', ' ')}<!-- ELSE -->{HIST_ROW_SUMM|number_format($this, 2, '.', ' ')}<!-- ENDIF -->
            &nbsp;
            <span class="rouble<!-- IF {HIST_ROW_IN_DODJI} --> rouble-dodji<!-- ENDIF -->">Р</span>
          </td>
          <td class="pr0">
            <!-- IF {HIST_ROW_AREA} == 'payout' -->
              <div class="btn-title btn-title_green pull-right sm-pull-reset">
                <div class="tooltipster btn-title_right tooltipstered" data-tooltip-text="Статус заявки можно посмотреть во вкладке заявок на вывод.">
                  ?
                </div>
                Выполнено
              </div>
            <!-- ELSE -->
              <div class="btn-title btn-title_green pull-right sm-pull-reset">
                <div class="tooltipster btn-title_right tooltipstered" data-tooltip-text="<!-- IF {HIST_ROW_LABEL_HINT} -->{HIST_ROW_LABEL_HINT}<!-- ELSE -->Ваш баланс пополнен<!-- ENDIF -->">
                  ?
                </div>
                Выполнено
              </div>
            <!-- ENDIF -->
          </td>
        </tr>
        <!-- END: HIST_ROW -->
      </tbody>
    </table>

    <div class="pagination">
      <div align="center" class="balance-pagination">
        <div class="paging">
          <div class="p1">
            <ul>
              {PAGENAV_PREV}{PAGENAV_PAGES}{PAGENAV_NEXT}
            </ul>
          </div>
        </div>
      </div>
      <div class="button__export">
        <a role="button" class="orange-btn export-userop">
        <i class="fa fa-download"></i>
        Экспорт
        </a>
      </div>
      <div class="clear"></div>
    </div>
   </div>
  </div>
  <!-- END: HISTORY -->

  <!-- BEGIN: PAYOUTS -->
  <div class="centerwrap clearfix pt20 pb0 block-response">
    <div class="balance-info-block">
      <div class="balance-info-block__summ">{BALANCE_SUMM}&nbsp;<span class="rouble">Р</span></div>
      <div class="balance-info-block__action">
        <div class="withdraw-money-form-js withdraw-block">
          <form class="withdraw-block__form"  method="post" onsubmit="return validate_withdraw($(this))">
            <select name="payout_type" class="styled-input mr10 font-OpenSans f14 w225" id="unitpay-type">
              <option value="qiwi">QIWI</option>
              <option value="yandex">Яндекс.Деньги</option>
              <option value="card">Банковская карта</option>
              <option value="wm">WebMoney</option>
            </select>
            <input type="hidden" name="action_type" value="withdraw"/>
            <div class="js-tooltip dib v-align-t mr10 m-mb10" data-tooltip-position="center" data-tooltip-text="Укажите номер кошелька в настройках профиля">
              <input name="account_name" class="styled-input disabled-area m-w105" id="purse" style="width:170px" required disabled>
            </div>
            <br class="m-visible">
            <input id="purse-input" name="funds_sum" value="{BALANCE_SUMM}" class="styled-input mr10 m-mb10 v-align-m" style="width: 50px;margin-top: -4px;" placeholder="Сумма" required>
            <input  id="purse-submit" type="submit" class="dib v-align-t green-btn mr10 m-mb10" style="height:32px;" value="Вывести">
            <a href="{BALANCE_HISTORY_URL}" class="white-btn dib v-align-t cur hide-form-btn-js m-margin-reset ml10">Отменить</a>
          </form>
          <br class="m-visible"><br class="m-visible">
          <div class="withdraw-block__error" id="withdraw-error"></div>
          <div class="withdraw-block__comission__desc" id="comis-desc"></div>
        </div>
      </div>
    </div>
  </div>
  <div class="centerwrap clearfix mt0 pb20 block-response mt15 m-p0" id="operations-result">
    <table class="table-style response-table m-order-table">
      <thead>
        <tr>
          <td class="w19p">
            <div class="ml20"><span class="js-table-head__filter" data-filter="date">Дата </span></div>
          </td>
          <td class="w52p"><span class="js-table-head__filter" data-filter="description">Описание </span></td>
          <td class="w12p"><span class="js-table-head__filter" data-filter="sum">Сумма </span></td>
          <td class="pr0"><span class="js-table-head__filter" data-filter="status">Статус </span></td>
        </tr>
      </thead>
      <tbody>
        <!-- BEGIN: PAYOUT_ROW -->
        <tr>
          <td class="pl20  m-text-right">{PAYOUT_ROW_CDATE|cot_date('d.m.Y, в H:i', $this)}</td>
          <td class="clearfix">
            Вывод средств с кошелька
          </td>
          <td class="m-visible clearfix p0"></td>
          <td class="m-w50p m-pull-right m-text-right">
            {PAYOUT_ROW_SUMM}&nbsp;<span class="rouble">Р</span>
          </td>
          <td class="pr0">
            <!-- IF {PAYOUT_ROW_STATUS} == 'moderation' -->
            <div class="btn-title btn-title_orange pull-right sm-pull-reset">
              <div class="tooltipster btn-title_right tooltipstered" data-tooltip-text="Заявка на рассмотрении">
                ?
              </div>
              {PAYOUT_ROW_LOCALSTATUS}
            </div>
            <!-- ENDIF -->

            <!-- IF {PAYOUT_ROW_STATUS} == 'canceled' -->
            <div class="btn-title btn-title_pink pull-right sm-pull-reset">
              <div class="tooltipster btn-title_right tooltipstered" data-tooltip-text="Заявка отклонена">
                ?
              </div>
              {PAYOUT_ROW_LOCALSTATUS}
            </div>
            <!-- ENDIF -->

            <!-- IF {PAYOUT_ROW_STATUS} == 'process' -->
            <div class="btn-title btn-title_blue pull-right sm-pull-reset">
              <div class="tooltipster btn-title_right tooltipstered" data-tooltip-text="Заявка обработана, в ближайшее время деньги будут отправлены на указанные реквизиты">
                ?
              </div>
              {PAYOUT_ROW_LOCALSTATUS}
            </div>
            <!-- ENDIF -->

            <!-- IF {PAYOUT_ROW_STATUS} == 'done' -->
            <div class="btn-title btn-title_green pull-right sm-pull-reset">
              <div class="tooltipster btn-title_right tooltipstered" data-tooltip-text="Деньги отправлены на указанные реквизиты">
                ?
              </div>
              {PAYOUT_ROW_LOCALSTATUS}
            </div>
            <!-- ENDIF -->
          </td>
        </tr>
        <!-- END: PAYOUT_ROW -->
      </tbody>
    </table>

    <div class="pagination">
      <div align="center" class="balance-pagination">
        <div class="paging">
          <div class="p1">
            <ul>
              {PAGENAV_PREV}{PAGENAV_PAGES}{PAGENAV_NEXT}
            </ul>
          </div>
        </div>
      </div>
      <div class="clear"></div>
    </div>
  </div>
  <!-- END: PAYOUTS -->

</div>
<script src="themes/itbirja/js/datepicker.min.js"></script>
<link rel="stylesheet" type="text/css" href="themes/itbirja/css/datepicker.min.css">
<script src="themes/itbirja/js/bootstrap.min.js"></script>
<script src="themes/itbirja/js/bootstrap-multiselect.js"></script>
<script src="themes/itbirja/js/chosen-mobile-true.jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="themes/itbirja/css/bootstrap-multiselect.css">
<script>
  $(function() {
      var typeOptions = new Array();
      //собираем список опций типа операции для дальнейшего использования
      $("select[name=type-operation] option").each(function(){
         typeOptions.push($(this).val());
      });

      if($(".js-select__single option").length == 1){
          $(".select__single").css("visibility","hidden");
      }

      $('.filter-balance__block').removeClass('hide');
      $(".oper-amount-sum").addClass("hide");
      var selectChackbox = $('.js-select__checkbox');

      selectChackbox.multiselect({
          enableClickableOptGroups: true,
          numberDisplayed: 1,
          selectAllText: 'Все операции',
          nonSelectedText: 'Все операции',
          nSelectedText: 'выбрано',
          allSelectedText : 'Все операции',
          includeSelectAllOption: false,
          selectAllNumber: false,
          onDropdownHidden: function(event) {
              //changeBalanceFilter(true, true);
          }

      });

      var selectSelectAll = $('.multiselect-container li:first-child'),
          selectNotSelectAll= $('.multiselect-container li:not(:first-child)');

      selectSelectAll.on('click', function() {
          if($(this).hasClass('active')){
              return false
          }else{
              selectChackbox.multiselect('deselect',  typeOptions);
              selectChackbox.multiselect('select', ['all']);
              selectChackbox.find('option[value=all]').prop('selected', true);
          }

          selectChackbox.multiselect("refresh");
      });


      selectNotSelectAll.on('click', function() {
          selectSelectAll.removeClass('active');
          selectSelectAll.find('input').prop('checked', false);
          selectChackbox.find('option[value=all]').prop('selected', false);

      });

      selectChackbox.on('change', function() {
          var countSelect = $('.multiselect-container li').length,
              countSelectActive = $('.multiselect-container li.active').length;
          if(countSelect == countSelectActive + 1 || countSelectActive == null){
              selectChackbox.multiselect('deselect', typeOptions);
              selectChackbox.multiselect('select', ['all']);
              selectChackbox.find('option[value=all]').prop('selected', true);
          }

          var typesVal = selectChackbox.val();
          if(!typesVal){
              selectChackbox.multiselect('select', ['all']);
          }else{
              if(typesVal.length > 0) {
                  if($.inArray("order_in", typesVal) == -1 && typesVal[0] != "all"){
                      $(".select__single").hide();
                  }else{
                      $(".select__single").show();
                  }
              }
              selectChackbox.multiselect("refresh");
          }
      });

      $('.js-select__single').chosen({
          disable_search_threshold: 10
      });

      setTimeout(function() {
        selectChackbox.change();
      }, 100);


      var calendarInput = $('.js-input__calendar'),
          calendarClear = $('.js-input__calendar-clear');
      var minDate = new Date($("#from").attr("min"));
      var maxDate = new Date($("#from").attr("max"));

      $("#from, #to").on("change", function (e) {
          var id ="#" + $(this).attr("id");
          if($(this).val() !=""){
              var from = $(this).val().split(".");
              var date = new Date(from[2], from[1] - 1, from[0]);
              var myDatepicker =  $(id).datepicker().data('datepicker');

              if(date.getTime() <= myDatepicker.maxDate.getTime() && date.getTime() >= myDatepicker.minDate.getTime()){
                  myDatepicker.selectDate(date);
              }else{
                  $(id).val("");
                  $(id).next().removeClass("show");
                  $(id).parent().find("i").show();
              }
          }else{
              $(id).next().removeClass("show");
              $(id).parent().find("i").show();
          }
      });


      calendarInput.datepicker({
          minDate: minDate,
          maxDate: maxDate,
          navTitles: {
              days: 'MM yyyy'
          },
          onHide: function(datetime){
              //calendarClose();
          },
          onSelect: function(formattedDate, date, inst) {
              //задаем лимиты для полей"от","до"
              if(inst.el.attributes[1].nodeValue =="from"){
                  if(!date){
                      date =  minDate;
                  }
                  $("#to").datepicker({
                      minDate: new Date(date)
                  });

              }else{
                  if(!date){
                      date =  maxDate;
                  }
                  $("#from").datepicker({
                      maxDate: new Date(date)
                  });
              }
              $(inst.el).trigger('change1');

              if ($("#" + inst.el.attributes[1].nodeValue).val() =="") {
                  $(inst.el).next().removeClass('show');
                  $(inst.el).parent().find("i").show();
              }else{
                  $(inst.el).next().addClass('show');
                  $(inst.el).parent().find("i").hide();
              }
          }
      });
      calendarInput.change(function() {
          if($(this).val() !="") {
              $(this).next().addClass('show');
          }
          else
              $(this).next().removeClass('show');
      });

      calendarInput.focus(function() {
          $(this).attr('placeholder', '');
      });
      calendarInput.blur(function() {
          var calendarPlaceholder = $(this).attr('data-placeholder');
          $(this).attr('placeholder', calendarPlaceholder);
      });
      calendarClear.click(function() {

          $(this).prev().val('');
          $(this).removeClass('show');

          var calendarPlaceholder = $(this).prev().attr('data-placeholder');
          var myDp = $(this).prev().datepicker().data('datepicker');
          myDp.clear();
          $(this).prev().attr('placeholder', calendarPlaceholder);
          //changeBalanceFilter(true, true);
      });
      $('.datepicker--nav-title').on("click", function() {
          return false
      });

      $('.js-multiselectGroup').on("click", function() {
          $('.chosen-container-single').removeClass('chosen-with-drop');
      });
      $('.select__single').on("click", function() {
          if($('.btn-group').hasClass('open')){
              $('.chosen-container-active').addClass('chosen-with-drop');
          }
      });


  });
</script>
<!-- IF {PHP.n} == 'payouts' -->
<script>
  var chng_desc = function(type){
      switch (type)
      {
          case 'card':
              return '{PHP|cot_payment_cfg_info_json('card')}';
          case 'qiwi':
              return '{PHP|cot_payment_cfg_info_json('qiwi')}';
          case 'yandex':
              return '{PHP|cot_payment_cfg_info_json('yandex')}';
          case 'wm':
              return '{PHP|cot_payment_cfg_info_json('wm')}';
          default :
              return"";
      }
  };
      function validate_withdraw(target)
      {
          var sum = target.closest('.withdraw-money-form-js').find('[name=funds_sum]').val();
          var type=target.closest('.withdraw-money-form-js').find('[name=payout_type]').val();
          var isOkay = true;
          <!-- IF {PHP.cfg.payments.payout_tax.qiwi.minsum} > 0 -->
          if(type=='qiwi' && sum < {PHP.cfg.payments.payout_tax.qiwi.minsum})
          {
              $('#withdraw-error').text(t('Минимальная сумма вывода: {{0}} руб', [{PHP.cfg.payments.payout_tax.qiwi.minsum}]));
              isOkay = false;
          }
          <!-- ENDIF -->
          <!-- IF {PHP.cfg.payments.payout_tax.yandex.minsum} > 0 -->
          if(type=='yandex' && sum < {PHP.cfg.payments.payout_tax.yandex.minsum})
          {
              $('#withdraw-error').text(t('Минимальная сумма вывода: {{0}} руб', [{PHP.cfg.payments.payout_tax.yandex.minsum}]));
              isOkay = false;
          }
          <!-- ENDIF -->
          <!-- IF {PHP.cfg.payments.payout_tax.wm.minsum} > 0 -->
          if(type=='wm' && sum < {PHP.cfg.payments.payout_tax.wm.minsum})
          {
              $('#withdraw-error').text(t('Минимальная сумма вывода: {{0}} руб', [{PHP.cfg.payments.payout_tax.wm.minsum}]));
              isOkay = false;
          }
          <!-- ENDIF -->
          <!-- IF {PHP.cfg.payments.payout_tax.card.minsum} > 0 -->
          if(type=='card' && sum < {PHP.cfg.payments.payout_tax.card.minsum})
          {
              $('#withdraw-error').text(t('Минимальная сумма вывода: {{0}} руб', [{PHP.cfg.payments.payout_tax.card.minsum}]));
              isOkay = false;
          }
          <!-- ENDIF -->
          var re = new RegExp($('.withdraw-money-form-js [name=account_name]').attr('pattern'), '');
          if (re) {
              if(!re.exec(target.find('[name=account_name]').val()))
              {
                  if(type == 'wm')
                      $('#withdraw-error').text('Неправильный формат номера кошелька');
                  else if(type == 'qiwi')
                      $('#withdraw-error').text('Неправильный формат номера телефона');
                  else if(type == 'yandex')
                      $('#withdraw-error').text('Неправильный формат номера кошелька');
                  else if(type == 'card')
                      $('#withdraw-error').text('Неправильный формат номера карты');
                  else
                      $('#withdraw-error').text('Неправильный формат');
                  isOkay = false;
              }
          }
          return isOkay;
      };
  $(window).load(function(){
      var purseData = [];
      purseData['wm'] = {
          'pattern': 'R[0-9]*',
          'value': '{BALANCE_PROFILE_PAYMENT_WM_SECURE}',
          'placeholder': ''
      };
      purseData['qiwi'] = {
          'pattern': '.+',
          'value': '{BALANCE_PROFILE_PAYMENT_QIWI_SECURE}',
          'placeholder': ''
      };
      purseData['yandex'] = {
          'pattern': '.+',
          'value': '{BALANCE_PROFILE_PAYMENT_YANDEX_SECURE}',
          'placeholder': ''
      };
      purseData['card'] = {
          'pattern': '',
          'value': '{BALANCE_PROFILE_PAYMENT_CARD_NUM_SECURE}',
          'placeholder': ''
      };

      var isEmptyPurseVal = false;
      var selectedType = $('#unitpay-type option:selected').val();
      var $purse = $('#purse');

      $purse.val(purseData[selectedType]['value']);
      $purse.prop('value', purseData[selectedType]['value']);
      $purse.prop('pattern', purseData[selectedType]['pattern']);
      if(purseData[selectedType]['value'].length === 0) {
          $('#purse-submit').addClass('disabled').prop('type','button');
          $('#purse-input').prop("disabled", true);
          if(in_array(selectedType, ['wm','qiwi', 'yandex'])) {
              $('#withdraw-error').html('Для того чтобы отправить заявку на вывод, укажите номер кошелька в <a href="/profile#withdraw-block">Настройках</a>');
          } else if (selectedType === 'card') {
              $('#withdraw-error').html('Для того чтобы отправить заявку на вывод, необходимо привязать карту в <a href="/profile#withdraw-block">Настройках</a>');
          } else {
              $('#withdraw-error').html('Для того чтобы отправить заявку на вывод, укажите номер карты в <a href="/profile#withdraw-block">Настройках</a>');
          }
          isEmptyPurseVal = true;
      }
      else{
          isEmptyPurseVal = false;
      }
      set_tooltip_purse_text(isEmptyPurseVal, selectedType);

      function set_tooltip_purse_text(isEmptyPurse, type){
          var el =  $('#purse').parent('.js-tooltip');
          if(isEmptyPurse){
              if (type === 'card') {
                  el.tooltip('setContent', 'Укажите номер карты в настройках профиля');
              }else {
                  el.tooltip('setContent', 'Укажите номер кошелька в настройках профиля');
              }
          }else{
              $('#purse-input').prop("disabled", false);
              $('#purse-submit').removeClass('disabled').prop('type', 'submit');
              $('#withdraw-error').html('');
              if(type === 'card'){
                  el.tooltip('setContent', 'Сменить номер карты можно в настройках профиля');
              }else{
                  el.tooltip('setContent', 'Сменить номер кошелька можно в настройках профиля');
              }
          }
      }
      $('#unitpay-type').on('change', function () {
          var payout_type = $(this).val();
          var $purse = $('#purse');
          $('#comis-desc').html(chng_desc(payout_type));
          $purse.prop('pattern', purseData[payout_type]['pattern']);

          if(purseData[payout_type]['value'].length === 0) {
              $purse.val(purseData[payout_type]['placeholder']).removeClass('js-tooltip');
              $('#purse-submit').addClass('disabled').prop('type', 'button');
              $('#purse-input').prop("disabled", true);
              if(in_array(payout_type, ['wm','qiwi', 'yandex'])) {
                  $('#withdraw-error').html('Для того чтобы отправить заявку на вывод, укажите номер кошелька в <a href="/profile#withdraw-block">Настройках</a>');
              } else if (payout_type === 'card') {
                  $('#withdraw-error').html('Для того чтобы отправить заявку на вывод, необходимо привязать карту в <a href="/profile#withdraw-block">Настройках</a>');
              } else {
                  $('#withdraw-error').html('Для того чтобы отправить заявку на вывод, укажите номер карты в <a href="/profile#withdraw-block">Настройках</a>');
              }
              isEmptyPurseVal = true;
          }else{
              $purse.val(purseData[payout_type]['value']);
              isEmptyPurseVal = false;
          }
          set_tooltip_purse_text(isEmptyPurseVal, payout_type);
      });
      var type = $('#unitpay-type option:selected').val();
      if (isEmptyPurseVal === false) {
          $('#comis-desc').html(chng_desc(type));
      } else {
          $('#comis-desc').html(chng_desc(""));
      }
      $(document).on('click', '#increase-balance', function (e) {
          e.preventDefault();
          show_balance_popup('', 'balance');
      });
  });
</script>
<!-- ENDIF -->
<!-- END: MAIN -->