<div id="dialog_progress" style="display:none">
    <div class="hr1"></div>
    <div id="indicator" style="vertical-align: middle; display:none; margin-left:50%;margin-top:25px;">
        <img src="images/indicator.gif"/>
    </div>
</div>

<div id="alert_div"></div>
{if $user.asterisk_server}
    <div id="asterisk_div"></div>
{/if}

{if !$this_is_modal_window}

    {if $demo_base_id}
        <div class="demo_create_acc">
            <table class="demo_create_acc_tbl">
                <tr>
                    <td width=100%>{$lang.demo_create_acc_txt} &nbsp; <a id="demo_create_acc_a" target=_blank
                                                                        href='{$lang.demo_create_acc_url}'><input
                                    id="demo_create_acc_btn_inp" type="button" value='{$lang.demo_create_acc_btn}'/></a>
                    </td>
                </tr>
            </table>
            <img id="closebut" src="images/demo_create_acc.svg"
                onclick="$('.demo_create_acc, .demo_create_acc2').hide();$.cookie('demo_create_acc','1', { expires: 1});"/>
        </div>
    {/if}

    {if !$preg_matches} {assign var=preg_matches value=0} {/if}
    {if preg_match('/^demo(\d+)/i', $smarty.server.HTTP_HOST, $preg_matches)}
        <div class="demo_create_acc">
            <table class="demo_create_acc_tbl">
                <tr>
                    <td width=100%>{$lang.demo_create_acc_txt} &nbsp; <a id="demo_create_acc_a" target=_blank
                                                                        href='https://clientbase.ru/market/index.html%3Fconfig={$preg_matches[1]}.html'><input
                                    id="demo_create_acc_btn_inp" type="button" value='{$lang.demo_create_acc_btn}'/></a>
                    </td>
                </tr>
            </table>
            <img id="closebut" src="images/demo_create_acc.svg"
                onclick="$('.demo_create_acc, .demo_create_acc2').hide();$.cookie('demo_create_acc','1', { expires: 1});"/>
        </div>
    {/if}

    {* Баннер к FREE версии, аналогичный банеру от ДЕМО *}
    {if (!$full_version and !$demo_base_id and !$client_demo_id and $script_name neq 'login.php') or ($full_version eq 1 and $tariff_id eq 1)}
        <div class="demo_create_acc">

            <table class="demo_create_acc_tbl">
                <tr>
                    <td width=100%>{if $tariff_limits.verif_require}{$lang.verificate_account_txt}{else}{$lang.free_version_used_txt}{/if}&nbsp;<b>{$days_expire}</b>&nbsp;&nbsp;&nbsp;<a id="demo_create_acc_a" target=_blank
                      href='{if $config.type=="SAAS"}edit_saas.php{else}https://clientbase.ru/buy/buy_new_licence/{/if}'>
                      <input id="demo_create_acc_btn_inp" type="button" value='{if $tariff_limits.verif_require}{$lang.Fill_profile}{else}{$lang.Buy_saas}{/if}'/></a></td>
                </tr>
            </table>
            <img id="closebut" src="images/demo_create_acc.svg" onclick="$('.demo_create_acc, .demo_create_acc2').hide();"/>

        </div>
        <script>
        $(document).ready(function() {
                    $('.demo_create_acc, .demo_create_acc2').css('display', 'block');

        });
        </script>
    {/if}

    {* Баннер к режиму "только для чтения" (для резервных аккаунтов) *}
    {if $config.read_mode}
        <div class="demo_create_acc" style="display:block">
            <table class="demo_create_acc_tbl">
                <tr>
                    <td width=100%>{$lang.read_mode_txt}</td>
                </tr>
            </table>
            <img id="closebut" src="images/demo_create_acc.svg" onclick="$('.demo_create_acc, .demo_create_acc2').hide();"/>
        </div>
    {/if}

    {* Баннер к партнерскому аккаунту *}
    {if $saas_config.login|substr:0:8 == 'partner-' || $config.not_commercial}
        <div class="demo_create_acc" style="display:block">
            <table class="demo_create_acc_tbl">
                <tr>
                    <td width=100%>{$lang.partner_account_message}</td>
                </tr>
            </table>
            <img id="closebut" src="images/demo_create_acc.svg" onclick="$('.demo_create_acc, .demo_create_acc2').hide();"/>
        </div>
    {/if}

    {* Баннер к аккаунту разработки *}
    {if $saas_config.login|substr:0:8 == 'devcopy-'}
        <div class="demo_create_acc" style="display:block">
            <table class="demo_create_acc_tbl">
                <tr>
                    <td width=100%>{$lang.develop_account_message}</td>
                </tr>
            </table>
            <img id="closebut" src="images/demo_create_acc.svg" onclick="$('.demo_create_acc, .demo_create_acc2').hide();"/>
        </div>
    {/if}

    {if $user.id > 0 and $script_name neq 'login.php'}

        {* окно календарей *}
        {if $window_calendar_data.calendars[$user.id]|is_array}
            <div id="calendar_window"
                style="display: {$b_events.calendar.view}; top: {$b_events.calendar.top}; left: {$b_events.calendar.left}; z-index: 5001; opacity: {$b_events.calendar.opacity}"
                onclick="eventWindowFocus('calendar'); event.cancelBubble = true">
                <div class="no_print" id="calendar_window_frame"
                    style="width: {$b_events.calendar.width}px; height: {$b_events.calendar.height}px; z-index: {$b_events.calendar.zindex}01">
                    <div id="calendar_window_header">
                        {$lang.Calendars}
                    </div>
                </div>

                <div id="calendar_window_space" class="no_print"
                    style="width: {$b_events.calendar.space_width}px; height: {$b_events.calendar.space_height}px; margin: -{$b_events.calendar.space_margin}px 5px 0px; z-index: {$b_events.calendar.zindex}02">
                    {if $window_calendar_data.calendars[$user.id]|count_cb>0}
                        <table>
                            <thead>
                            <tr>
                                <td class="calWindowFirstColumn"></td>
                                <td>{$lang.Today}</td>
                                <td>{$lang.Tomorrow}</td>
                                <td class="calWindowLastColumn"></td>
                            </tr>
                            </thead>
                            <tbody>
                            {foreach from=$window_calendar_data.calendars[$user.id] item=one_calendar}
                                <tr>
                                    <td class="calWindowFirstColumn"><a target="_blank"
                                                                        href="calendar.php?id={$one_calendar.id}">{$one_calendar.name}</a>
                                    </td>
                                    <td><a target="_blank"
                                        href="calendar.php?id={$one_calendar.id}&amp;month={date('m',strtotime($dayToday))}&amp;year={date('Y',strtotime($dayToday))}&amp;day={date('d',strtotime($dayToday))}">{if $one_calendar[$dayToday]}{$one_calendar[$dayToday]}{else}0{/if}</a>
                                    </td>
                                    <td><a target="_blank"
                                        href="calendar.php?id={$one_calendar.id}&amp;month={date('m',strtotime($dayTomorrow))}&amp;year={date('Y',strtotime($dayTomorrow))}&amp;day={date('d',strtotime($dayTomorrow))}">{if $one_calendar[$dayTomorrow]}{$one_calendar[$dayTomorrow]}{else}0{/if}</a>
                                    </td>
                                    <td class="calWindowLastColumn"><a target="_blank"
                                                                    href="calendar.php?id={$one_calendar.id}"><img
                                                    src="images/tip_arrow.gif"/></a></td>
                                </tr>
                            {/foreach}
                            </tbody>
                        </table>
                    {elseif $window_calendar_data.calendars[$user.id]|count_cb==0}
                        <table class="no_calendars">
                            <thead>
                            <tr>
                                <td class="calWindowFirstColumn"></td>
                                <td>&nbsp;</td>
                                <td></td>
                                <td class="calWindowLastColumn"></td>
                            </tr>
                            </thead>
                            <tbody>
                            <tr>
                                <td colspan="4">{$lang.No_calendars}. {if $user.id==1}<a target="_blank"
                                                                                        href="edit_cat.php">{$lang.Add_calendar}</a>{/if}
                                </td>
                            </tr>
                            </tbody>
                        </table>
                    {/if}
                </div>

                <img src="images/window_close.png" alt="" id="calendar_window_close"
                    onclick="eventView('calendar'); event.cancelBubble = true"
                    style="margin-top: -{$b_events.calendar.close_margin}px; z-index: {$b_events.calendar.zindex}02"
                    title="{$lang.Hide}"/>
            </div>
        {/if}
        {* конец окна календарей *}

        <!-- Begin of notification and message windows block and search-->

        <!-- Begin of search block -->
        <div id="search_window"
            style="display: {$b_events.search.view}; top: {$b_events.search.top}; left: {$b_events.search.left}; z-index: 5001; opacity: {$b_events.search.opacity}"
            onclick="eventWindowFocus('search'); event.cancelBubble = true">
            <div class="no_print" id="search_window_frame"
                style="width: {$b_events.search.width}px; height: {$b_events.search.height}px; z-index: {$b_events.search.zindex}01">
                <div id="search_window_header">
                    {$lang.Search}
                </div>
            </div>
            <div id="search_window_space" class="no_print"
                style="width: {$b_events.search.space_width}px; height: {$b_events.search.space_height}px; margin: -{$b_events.search.space_margin}px 5px 0px; z-index: {$b_events.search.zindex}02">
                <table id="search_window_content" cellpadding="0" cellspacing="0" border="0">
                    <tr>
                        <td id="search_window_info" style="width:100%;">
                            <div id="search_window_progress" style="margin-bottom: 10px;">
                                <form action="#" id="search_window_form" onsubmit="start_search();return false;" >
                                    <div id="search_window_form_block" style="margin: 0 10px 0 10px;">
                                        <table>
                                            <tr>
                                                <td width="100%">
                                                    <input autofocus id="search_input" placeholder="{$lang.Enter_search_text}" class="form-control">
                                                </td>
                                                <td>
                                                    <input id="search_submit_button" type="submit" value="{$lang.Search}" class="btn btn-default btn-sm">
                                                </td>
                                                <td>
                                                    <input style="display:none;" type='submit' id='search_window_stop_btn' onclick='reset_search();return false;' class='form-control input-sm' value='{$lang.Stop}'>
                                                </td>
                                                <td>
                                                    <span title="{$lang.Advanced_settings}" id="ext_search_open_vert" class="ext_search_open_vert"></span>
                                                </td>
                                            </tr>
                                        </table>
                                    </div>
                                </form>
                            </div>
                            <div id="search_continue" class="btn btn-default btn-sm" style="text-align:center; display:none;" onclick="$(this).css('display', 'none'); reset_search(true, true);">{$lang.Search_continue}</div>
                            <div id="search_window_field"
                                style="height: {$b_events.search.field_height}px; width: 100%;">
                            </div>
                            <div id="search_window_progress_bar" style="position:relative; display:none; margin: 0 10px 0 10px;">
                                <div class="progress" style="max-width: 100%;width:100%;margin-bottom: 0; height: 15px; text-align:center; position: relative;">
                                    <div class="progress-bar progress-bar-striped active" id="search_window_progress_bar_line" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 45%; position: absolute;">
                                    </div>
                                    <span class="sr-only" id="search_window_progress_text" style="
                                        position: relative;
                                        color: #fff;
                                        font-size: 11.5px;
                                        white-space: nowrap;
                                        vertical-align: top;"></span>
                                </div>
                            </div>
                        </td>
                        <td id="search_window_table_list" style="width:200px;display:none;">
                            <div id="search_window_tables" style="position: relative; height: {$b_events.search.table_height}px;">
                                <ul id="search_window_head_tables" style="margin-bottom: 0">
                                    <li style="margin-top: 4px; cursor: pointer;">
                                        <input type="checkbox" id="search_window_all_stat_input" data-table checked onclick="all_stat()" style="">
                                        <span style="font-weight: bold; vertical-align: text-bottom;">{$lang.All} {$lang.tables}</span>
                                    </li>
                                </ul>
                                <ul id="search_window_list_tables">

                                </ul>
                            </div>
                        </td>
                    </tr>
                </table>
            </div>
            <img src="images/window_close.png" alt="" id="search_window_close"
                onclick="eventView('search'); event.cancelBubble = true"
                style="margin-top: -{$b_events.search.close_margin}px; z-index: {$b_events.search.zindex}02" title="{$lang.Hide}"/>
        </div>
        <!-- End of search block -->

        <!-- Begin of tips block -->
        <div id="tip_window"
            style="display: {$b_events.tip.view}; top: {$b_events.tip.top}; left: {$b_events.tip.left}; z-index: 5001; opacity: {$b_events.tip.opacity}"
            onclick="eventWindowFocus('tip'); event.cancelBubble = true">
            <div class="no_print" id="tip_window_frame"
                style="width: {$b_events.tip.width}px; height: {$b_events.tip.height}px; z-index: {$b_events.tip.zindex}01">
                <div id="tip_window_header">
                    {$lang.Tips}
                </div>
            </div>

            <div id="tip_window_space" class="no_print"
                style="width: {$b_events.tip.space_width}px; height: {$b_events.tip.space_height}px; margin: -{$b_events.tip.space_margin}px 5px 0px; z-index: {$b_events.tip.zindex}02">
                <div id="tips_window_controls">
                    <img id="close_all_tips_button" src="images/tip_window_item_close.png" alt="{$lang.close_all_tips}"
                        title="{$lang.close_all_tips}"
                        onclick="jconfirm('{$lang.close_all_tips}?', function () { cbTipsDisplay.closeAll(); }, function() { })"/>
                    <table cellspacing="0">
                        <tr>
                            <td onclick="cbTipsDisplay.switchTab('all')" class="tip_sw_active" style="border-left: none"
                                id="tip_sw_tab_all">{$lang.All}</td>
                            <td onclick="cbTipsDisplay.switchTab('active')" id="tip_sw_tab_active">{$lang.Active}</td>
                            <td onclick="cbTipsDisplay.switchTab('today')" id="tip_sw_tab_today">{$lang.Today}</td>
                            <td onclick="cbTipsDisplay.switchTab('important')" id="tip_sw_tab_important">{$lang.Important}</td>
                            <td onclick="cbTipsDisplay.switchTab('archive')" id="tip_sw_tab_archive">{$lang.Archive}</td>
                            <td onclick="cbTipsDisplay.switchTab('search')" style="border-right: none;"
                                id="tip_sw_tab_search">{$lang.Search}</td>
                        </tr>
                    </table>
                    <div class="tips_sort">
                        <a href="#" class="tip_sort_button" onclick="cbTipsDisplay.sortTipsByDate()"> Сортировка: Дата

                        <svg version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 284.929 284.929" style="enable-background:new 0 0 284.929 284.929;"
                            xml:space="preserve">
                        <g>
                            <path d="M282.082,76.511l-14.274-14.273c-1.902-1.906-4.093-2.856-6.57-2.856c-2.471,0-4.661,0.95-6.563,2.856L142.466,174.441
                                L30.262,62.241c-1.903-1.906-4.093-2.856-6.567-2.856c-2.475,0-4.665,0.95-6.567,2.856L2.856,76.515C0.95,78.417,0,80.607,0,83.082
                                c0,2.473,0.953,4.663,2.856,6.565l133.043,133.046c1.902,1.903,4.093,2.854,6.567,2.854s4.661-0.951,6.562-2.854L282.082,89.647
                                c1.902-1.903,2.847-4.093,2.847-6.565C284.929,80.607,283.984,78.417,282.082,76.511z"/>
                        </g>
                        <g></g><g></g><g></g><g></g><g></g><g></g><g></g><g></g><g></g><g></g><g></g><g></g><g></g><g></g><g></g>
                        </svg>

                        </a>

                    </div>
                </div>
                <div id="tip_window_content" style="height: {$b_events.tip.list_height - 20}px;">
                    <div id="tip_window_tooltip"><h2><img src="images/process.gif" alt="" style="vertical-align: middle"/></h2>
                    </div>
                    <div id="tip_window_list" style="display: none;"></div>
                    <div id="tip_window_archive" style="display: none;"><h2><img src="images/process.gif" alt=""
                                                                                style="vertical-align: middle"/></h2></div>
                    <div id="tip_window_search" style="display: none;">
                        <form action="#" onsubmit="cbTipsDisplay.search(0); return false">
                            <div id="extended_tip_search" style="display: none;">
                                {$lang.Period} {$lang.since_from} <input type="text" name="t_date_begin" id="t_date_begin"
                                                                        size="10" class="t_search_date"/>
                                {$lang.since_to} <input type="text" name="t_date_end" id="t_date_end" size="10"
                                                        class="t_search_date"/>
                                {if $admin_tip_search}
                                    <div style="margin-top: 5px;">
                                        {$lang.User}:
                                        <select name="admin_tip_search" id="admin_tip_search">
                                            {foreach from=$admin_tip_search key=u_id item=u_name}
                                                <option value="{$u_id}"{if $u_id eq $user.id} selected{/if}>{$u_name}</option>
                                            {/foreach}
                                        </select>
                                    </div>
                                {/if}
                            </div>
                            <input type="text" name="t_search" id="t_search_text" value="{$lang.Search}" size="35"
                                style="color: gray"
                                onkeyup="if ((event.keyCode == 0xA)||(event.keyCode == 0xD)) cbTipsDisplay.search(0);"
                                onfocus="cbTipsDisplay.search_focus(this)" onblur="cbTipsDisplay.search_blur(this)"/>
                            <span title="{$lang.Start_fast_search}" class="fast_search_submit"
                                onclick="cbTipsDisplay.search(0)"></span>
                            <span title="{$lang.Advanced_search}" class="ext_search_open"
                                onclick="$('#extended_tip_search').slideToggle();{if $admin_tip_search}document.getElementById('admin_tip_search').value='{$user.id}';{/if}"></span>
                        </form>
                        <div id="tip_search_result" style="display: none"></div>
                    </div>
                </div>
            </div>

            <img src="images/window_close.png" alt="" id="tip_window_close"
                onclick="eventView('tip'); event.cancelBubble = true"
                style="margin-top: -{$b_events.tip.close_margin}px; z-index: {$b_events.tip.zindex}02" title="{$lang.Hide}"/>
        </div>
        <!-- End of tips block -->

        {if $user.acc_messages}
            <!-- Begin of message block -->
            <div id="message_window"
                style="display: {$b_events.message.view}; top: {$b_events.message.top}; left: {$b_events.message.left}; z-index: 5001; opacity: {$b_events.message.opacity}"
                onclick="eventWindowFocus('message'); event.cancelBubble = true">
                <div id="message_window_frame" class="no_print"
                    style="width: {$b_events.message.width}px; z-index: {$b_events.message.zindex}01;">
                    <div id="message_window_header">
                        <div id="menu_close_btn">
                            <img src="images/vk_delete.png" alt="КБ" id="message_window_close"
                                onclick="eventView('message'); event.cancelBubble = true; event.stopPropagation();"
                                style="z-index: {$b_events.message.zindex}02"
                                title="{$lang.Hide}"/>
                        </div>
                        <div class="message_window_menu_items">
                            <button class="message_window_menu_chat">{if $config.copyright}<img src="images/cb_logo_menu.png" alt="Кб" title="{$lang.Start_internal_chat}">{/if}</button>
                        </div>
                        {if $all_modules.social_messages['status'] == 0 }
                            {* Для разграничения доступа: если есть доступ к категории Соц. сети, то добавляем модуль вк в окно чата *}
                            {foreach from=$user_cats item=$one_cat}
                                {if $one_cat.name == 'Соц. сети'}
                                    <div class="message_window_menu_items">
                                        <button id="message_window_menu_vk_group">
                                            <img src="images/vk_logo_square.png" alt="Сообщество ВК" title="Начать ВК чат от имени сообщества">
                                            <span id="message_window_menu_items--counter"></span>
                                        </button>
                                    </div>
                                    {break}
                                {/if}
                            {/foreach}
                        {/if}
                    </div>

                    <div id="message_window_space" class="no_print"
                        style="height: {$b_events.message.space_height}px; z-index: {$b_events.message.zindex}02">

                        <!-- Чат КБ -->
                        <div id="message_window_content">
                            <div id="message_window_chat">
                                <div class="message_window_chat-title ui-draggable-handle">
                                    <div id="message_window_chat-title--name">{$lang.Internal_chat}</div>
                                </div>
                                <div class="message_window_vk-writeMessageButton">

                                </div>
                                <div id="message_window_user_list">
                                    <div id="message_window_cur_user">{$user.fio|escape}</div>

                                </div>
                                <div id="message_window_users" class="message_vk-users">
                                    <div id="message_window_users_new"></div>
                                    <div id="message_window_chates"></div>
                                    <div id="message_window_users_online"></div>
                                    <div id="message_window_users_away"></div>
                                    <div id="message_window_users_offline"></div>
                                </div>
                                <div id="message_window_history">
                                    <div class="message_history_content"
                                        id="message_history_content0">{$lang.sel_con_for_dalog}</div>
                                </div>
                                <div id="message_window_drafting" class="message_vk-sendMessage">
                                    <form id="message_chat_form" action="#" onsubmit="cbMessagesDisplay.messageQueue(); return false">
                                    <textarea id="chat_textarea"
                                            onkeyup="cbMessagesDisplay.setReadAll()"
                                            onkeydown="return cbMessagesDisplay.enterMode(event)" placeholder="{$lang.Enter_your_message}..."></textarea>
                                        <div class="chat_action_buttons">
                                            {* <input type="checkbox" name="sent_enter" id="sent_enter_msg" checked="1" /> Отправлять по Enter *}
                                            <input id="chat_from_submit" type="submit" hidden="hidden"/>
                                            <img id="chat_form_submit__img" src="images/send_button.png" alt="{$lang.Send}" title="{$lang.Send_message}">
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                        <!-- Конец чата КБ -->

                        <!-- Чат ВК -->
                        <div class="message_window_vk" style="display: none;">
                            <div class="message_window_vk-title">
                                <div id="message_window_vk-title--name">В контакте</div>
                            </div>
                            <div class="message_window_vk-writeMessageButton">
                            <button id="writeMessageButton"><img src="images/vk_search_people.png" alt="Написать сообщение" title="Начните поиск по людям"></button>
                            </div>
                            <div class="message_window_vk-chatUser">
                                <div class="message_user_info">
                                    <div class="chatUser-username">Имя собеседника</div>
                                    <div class="chatUser-userstatus">Статус</div>
                                </div>
                            <div class="message_search">
                                <input type="text" id="message_search-input" placeholder="Поиск по сообщениям" style="display:none;">
                                <button id="message_search-button">
                                    <img src="images/vk_message_search.png" alt="Поиск по сообщениям" title="Начните поиск по сообщениям диалога">
                                </button>
                                <button class="margin_right_vk_elems" id="message_search-goSearch" style="display: none;">
                                    <img src="images/ok-search_vk.png" alt="Поиск по сообщениям" title="Начать поиск по сообщениям">
                                </button>
                                <button id="message_search-button--cancel" style="display: none;">
                                    <img src="images/delete_vk.png" alt="Отмена поиска" title="Отменить поиск по сообщениям">
                                </button>
                            </div>
                            </div>
                            <div class="message_vk-users">
                                <datalist class="message_vk-users--list">

                                </datalist>
                            </div>
                            <div class="message_vk-history">
                                <div class="message_vk-history_field">
                                    <p style="margin-left: 10px; margin-top: 10px; font-style: italic; color: #a9a9a9;">Выберите пользователя</p>
                                </div>
                            </div>
                            <div class="message_vk-sendMessage">
                                <textarea id="message_vk-messageText" placeholder="Введите ваше сообщение..."></textarea>
                                <div class="message_vk-sendMessage_buttons">
                                    <form class="margin_right_vk_elems" id="attach_files_form" name="attach_files_form" action="getFileHash.php" method="post" enctype="multipart/form-data" target="_blank">
                                        <label id="message_attachLabel" for="message_vk-attachButton"><img src="images/attach_file.png" alt="Прикрепить файл" title="Прикрепить документ"></label>
                                        <input id="message_vk-attachButton" type="file" name="file">
                                        <input id="message_server_name" type="text" name="server_name" style="display: none;">
                                    </form>
                                    <div class="margin_right_vk_elems" id="attach_file_info" style="display: none;">
                                        <div id="attach_file_name">

                                        </div>
                                        <button id="delete_attachment_file"><img src="images/delete_attach.png" alt="Удалить файл" title="Удалить файл"></button>
                                    </div>
                                    <button class="margin_right_vk_elems" id="message_vk-sendButton"><img src="images/send_button.png" alt="Отправить" title="Отправить сообщение"></button>
                                    <button class="margin_right_vk_elems" id="message_vk-deleteButton"><img src="images/vk_deleteMessage.png" alt="Удалить сообщение" title="Удалить выбранные сообщения"></button>
                                    <button class="margin_right_vk_elems" id="message_vk-editOkButton" style="display: none;"><img src="images/vk_complete.png" alt="Применить изменения" title="Применить изменения"></button>
                                    <button id="message_vk-editCancelButton" style="display: none;"><img src="images/cancel_vk.png" alt="Применить изменения" title="Отменить редактирование"></button>
                                </div>
                            </div>
                            <div id="friends_search_vk" style="display: none;">
                                <div class="friends_search_header">
                                    <button id="friends_search_header_btn-close"><img src="images/vk_delete.png" alt="Закрыть окно поиска"></button>
                                    <div style="position: absolute; top: 30%; left: 29%;">Поиск подписчиков</div>
                                </div>
                                <div class="friends_search_field">
                                    <img src="images/friends_search.png" alt="Поиск людей">
                                    <input type="text" id="friends_search_field-input" placeholder="Введите имя друга">
                                    <button id="friends_search_field--cancel">
                                        <img src="images/vk_delete.png" alt="Отмена поиска">
                                    </button>
                                </div>
                                <div class="friends_search_items">

                                </div>
                            </div>
                        </div>
                        <!-- Конец чата ВК -->
                    </div>
                </div>
            </div>
            <!-- End of message block -->

            {if $all_modules.livechat.status eq 0}
            <!-- Begin of manager OK block -->
            <section id="manager_ok__window" class="hidden" style="top: {$b_events.message.top}; left: {$b_events.message.left}; z-index: 5001;"
                    onclick="event.cancelBubble = true">
                <div class="ok_draggable-wrapper">

                </div>
                <div id="manager_ok__wrapper" class="no_print"
                    style="width: 1000px; height: 710px; z-index: {$b_events.message.zindex}01;">
                    <iframe id="message_window_okFrame" src="modules/livechat/manager_side.php" frameborder="0"></iframe>
                </div>

            </section>
            <!-- End of manager OK block -->
            {/if}
        {/if}

        <div class="event-tooltip_wrap no_print">
            {if $display_notifications}
                {foreach from=$display_notifications item=one_notification}
                    {if $one_notification.type == 2 || !($table.auto_save == "1" && $total_rec <= 1)}
                        <div class="display_notification display_notification_class_by_type_{$one_notification.type}">
                            {if $one_notification.type != 3}
                                <a class="display_notification_button" href="#"
                                onclick="hide_this_notif(this)" title="Закрыть уведомление"></a>
                            {/if}
                            {*<div class="display_notification_icon"></div>*}
                            <div class="display_notification_text">{$one_notification.text}</div>
                        </div>
                    {/if}
                {/foreach}
            {/if}
            <div id="event_tooltip_asterisk"></div>
            <div class="event-tooltip__notifications-wrap">
                <div class="event-tooltip__control" title="{$lang.hide_tips}">
                    <div class="event-tooltip__tips-info">
                        <span>{$lang.new_notifications}</span>
                        <span class="event-tooltip__tips-count event-tooltip__tips-count--no-new" id="tooltip-tips-count"></span>
                    </div>
                    <button type="button" class="event-tooltip__button event-tooltip__button--close" id="event-tooltip-close-all" title="{$lang.close_tips}">
                        {if {$config.notify_style} == 0}
                            <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="Layer_1" x="0px" y="0px" viewBox="0 0 80 80" style="enable-background:new 0 0 80 80;" xml:space="preserve" width="13" height="13">
                                <g>
                                    <polygon id="first_close_svg" points="40,49.007 15.714,73.293 6.707,64.286 30.993,40 6.707,15.714 15.714,6.707 40,30.993    64.286,6.707 73.293,15.714 49.007,40 73.293,64.286 64.286,73.293"/>
                                    <path id="second_close_svg" d="M15.714,7.414l23.578,23.578L40,31.7l0.707-0.707L64.286,7.414l8.3,8.3L49.007,39.293L48.3,40   l0.707,0.707l23.578,23.579l-8.3,8.3L40.707,49.007L40,48.3l-0.707,0.707L15.714,72.586l-8.3-8.3l23.579-23.579L31.7,40   l-0.707-0.707L7.414,15.714L15.714,7.414 M64.286,6L40,30.286L15.714,6L6,15.714L30.286,40L6,64.286L15.714,74L40,49.714L64.286,74   L74,64.286L49.714,40L74,15.714L64.286,6L64.286,6z"/>
                                </g>
                            </svg>
                        {/if}
                    </button>
                </div>
                <div id="event_tooltip" class="no_print event-tooltip--hover"></div>
            </div>
        </div>

        <bgsound src="" id="event_sound">

        {if $as_tables_assigned and $user.asterisk_login and $user.browser_caller and $script_name=="phone.php"}
            <video id="remoteAudio" style="display: none" autoplay></video>
            <video id="localAudio" style="display: none" autoplay muted></video>
            <audio id="ringtone" style="display: none" loop src="ringtone.wav"></audio>
            <audio id="ringbacktone" style="display: none" loop src="ringbacktone.wav"></audio>
        {/if}


        <!-- End of notification and message windows block -->

        {if $all_bizprocs or $user.group_id==1 or $user.sub_admin_rights.addit_bizproc}
            <!-- Business_processes, dialog -->
            <div id="dialog_bizproc" class="dialog1" style="display:none;">
                <div class="hr1"></div>
                {foreach from=$all_bizprocs item=one_bizproc name=bizprocs}
                    {if !($smarty.foreach.bizprocs.iteration > 8)}
                        {if $one_bizproc.bp_type == 0}
                            <p>
                                <button class="d_button" id="true_bizproc"
                                        onclick="location.href='bizproc.php?proc={$one_bizproc.id}'">{$one_bizproc.name}</button>
                            </p>
                        {/if}
                        {if $one_bizproc.bp_type == 1}
                            <p>
                                <button class="d_button"
                                        onclick="open_dialog_my({$one_bizproc.id})">{$one_bizproc.name}</button>
                            </p>
                        {/if}
                    {/if}
                    {foreachelse}
                    <p class="add1">{$lang.No_bizproc}
                        .{if $user.group_id==1 or $user.sub_admin_rights.addit_bizproc}<br><br>
                        <a href="edit_bizproc.php?proc=-1">{$lang.Add_bizproc}</a>{/if}</p>
                {/foreach}
                {if $smarty.foreach.bizprocs.total > 8}
                    <p><a href="bizproc.php">{$lang.Additional_bizproc}</a></p>
                {/if}
            </div>
            <div id="dialog_bizproc_2" class="dialog1" style="display:none">
                <div class="hr1"></div>
                <div id="dialog_height">
                    <form method="post">
                        <table>
                            <tr>
                                <img style="margin-top:20px;margin-bottom:20px;display:none" src=""
                                    id="img_id">
                            </tr>
                            <tr>
                                <td id="desc_id"></td>
                            </tr>
                        </table>
                        <table>
                            <tr>
                                <div id="g_button"
                                    style="display:none; width:220px; height:35px; margin-left:auto; margin-right:auto;margin-top:10px"
                                    class="button save_prez"></div>
                            </tr>
                            <tr>
                                <div id="b_button"
                                    style="display:none; width:220px; height:35px; margin-left:auto; margin-right:auto;margin-top:10px"
                                    class="button addit_act default-btn"></div>
                            </tr>
                        </table>
                        <input type="hidden" name="csrf" value="{$csrf}"/>
                        <input type="hidden" id="img_width" name="img_width" value=""/>
                        <input type="hidden" id="img_height" name="img_height" value=""/>
                    </form>
                </div>
            </div>
        {/if}
    {/if}
</div>

<script>
    var my_bizproc_flag = 0;
    var click_flag = 0;
    var my_bizproc_start;
    function count(obj) {
        var count = 0;
        for (var prs in obj) {
            if (obj.hasOwnProperty(prs)) count++;
        }
        return count;
    }

    function open_dialog_my(bizproc_id, i) {
        if (!i) i = 1;
        my_param_g = 1;
        my_param_b = 1;

        $.ajax({
            url: "bizproc.php",
            dataType: "json",
            data: { bizproc_id: bizproc_id, index_top_flag: 1 },
            success: function (data) {

                data_count = count(data);
                start_count = data_count;

                if (data[i].att_file_name != '') {
                    document.getElementById('img_id').style.display = 'block';
                    document.getElementById('img_width').value = data[i].width;

                    if (data[i].description.length > 800)
                        document.getElementById('img_height').value = data[i].height + 300;
                    else
                        document.getElementById('img_height').value = data[i].height;
                }

                if (data[i].att_file_name == '') {
                    document.getElementById('img_id').style.display = 'none';
                    if (data[i].description.length > 200)
                        document.getElementById('img_width').value = 600;
                    else
                        document.getElementById('img_width').value = 500;

                    if (data[i].description.length > 800)
                        document.getElementById('img_height').value = 600;
                    else
                        document.getElementById('img_height').value = data[i].height;
                }

                //if ($(".dialog1 ui-dialog-content ui-widget-content"))

                if ($("#dialog_bizproc").css('display') == 'block') $("#dialog_bizproc").dialog('close');
                my_bizproc_start = 1;
                open_my_dialog();

                var parentElem = document.getElementById('dialog_bizproc_2');
                for (var iteration = 1; iteration < data_count + 1; iteration++) {
                    var div = document.createElement('div');
                    div.className = 'form_switcher';
                    div.id = 'my_id' + iteration;
                    if (iteration == 1)
                        div.style.backgroundPosition = 'left';
                    div.style.display = 'inline-block';
                    parentElem.appendChild(div);
                }

                //изначально скрываем кнопки
                document.getElementById('g_button').style.display = 'none';
                document.getElementById('b_button').style.display = 'none';

                if (data[i].g_button == '1') {
                    document.getElementById('g_button').style.display = 'block';
                    document.getElementById('g_button').innerHTML = data[i]['g_text'];
                }
                if (data[i].b_button == '1') {
                    document.getElementById('b_button').style.display = 'block';
                    document.getElementById('b_button').innerHTML = data[i]['b_text'];
                }


                $('#dialog_bizproc_2').click(function () {
                    if (click_flag)
                        return;
                    data_count -= 1;
                    i += 1;

                    //если все шаги прошли, закрываем диалог
                    if (i > start_count)
                        remove_page_arrows_my();

                    //изначально скрываем кнопки
                    document.getElementById('g_button').style.display = 'none';
                    document.getElementById('b_button').style.display = 'none';


                    document.getElementById('my_id' + i).style.backgroundPosition = 'left'

                    if (data_count > 0) {
                        //изначально скрываем кнопки
                        document.getElementById('g_button').style.display = 'none';
                        document.getElementById('b_button').style.display = 'none';

                        //задаем размер окна  с учетом картинкой
                        if (data[i].att_file_name != '') {
                            document.getElementById('img_id').style.display = 'block';
                            document.getElementById('img_width').value = data[i].width;

                            document.getElementById('img_height').value = data[i].height;
                            document.getElementById('dialog_height').style.height = '';
                        }

                        //пытаемся задать размеры окна без картинки
                        if (data[i].att_file_name == '') {
                            document.getElementById('img_id').style.display = 'none';

                            if (data[i].description.length > 200)
                                document.getElementById('img_height').value = 400;
                            else
                                document.getElementById('img_height').value = data[i].height;

                            if (data[i].description.length > 200)
                                document.getElementById('img_width').value = 600;
                            else
                                document.getElementById('img_width').value = 400;

                            document.getElementById('dialog_height').style.height = document.getElementById('img_height').value - 70 + 'px';
                        }


                        bp_name = data[i].name;
                        bp_desc = data[i].description;
                        bp_img = data[i].att_file;

                        open_my_dialog();

                        if (data[i].g_button == '1') {
                            document.getElementById('g_button').style.display = 'block';
                            document.getElementById('g_button').innerHTML = data[i]['g_text'];
                            my_param_g = i;
                        }
                        if (data[i].b_button == '1') {
                            document.getElementById('b_button').style.display = 'block';
                            document.getElementById('b_button').innerHTML = data[i]['b_text'];
                            my_param_b = i;
                        }

                        if (!document.getElementById('bp_header_id')) {
                          let dialog_elem = document.querySelector('[aria-describedby="dialog_bizproc_2"]')
                          dialog_elem.style.width = ''
                          dialog_elem.querySelector('.dialog1').style.height = ''


                          let dialog_inner_elem = document.querySelector('[aria-describedby="dialog_bizproc_2"] .ui-dialog-title')
                          dialog_inner_elem.innerHTML = dialog_inner_elem.innerText
                        }

                        document.getElementById('bp_header_id').innerHTML = bp_name;
                        document.getElementById('desc_id').innerHTML = bp_desc;
                        document.getElementById('img_id').setAttribute('src', bp_img);
                    }

                });

                $('#g_button').click(function () {
                    if (document.getElementById('g_button').style.display == 'block' && data[i].g_link != '') {
                        my_bizproc_start = 0;
                        click_flag = 1;
                        $("#dialog_bizproc_2").dialog('close');
                        window.location.href = data[my_param_g].g_link;
                    }
                });

                $('#b_button').click(function () {
                    if (document.getElementById('b_button').style.display == 'block' && data[i].b_link != '') {
                        my_bizproc_start = 0;
                        click_flag = 1;
                        $("#dialog_bizproc_2").dialog('close');
                        window.location.href = data[my_param_b].b_link;
                    }
                });


                bp_name = data[i].name;
                bp_desc = data[i].description;
                bp_img = data[i].att_file;

                document.getElementById('bp_header_id').innerHTML = bp_name;
                document.getElementById('desc_id').innerHTML = bp_desc;
                document.getElementById('img_id').setAttribute('src', bp_img);
            },
            error: function(data) { //Хз почему нормальный ответ идёт в error,в ответе status 200
              let response = data.responseText.split('<script>')[0]
              response = JSON.parse(response)

              data = response

                data_count = count(data);
                start_count = data_count;

                if (data[i].att_file_name != '') {
                    document.getElementById('img_id').style.display = 'block';
                    document.getElementById('img_width').value = data[i].width;

                    if (data[i].description.length > 800)
                        document.getElementById('img_height').value = data[i].height + 300;
                    else
                        document.getElementById('img_height').value = data[i].height;
                }

                if (data[i].att_file_name == '') {
                    document.getElementById('img_id').style.display = 'none';
                    if (data[i].description.length > 200)
                        document.getElementById('img_width').value = 600;
                    else
                        document.getElementById('img_width').value = 500;

                    if (data[i].description.length > 800)
                        document.getElementById('img_height').value = 600;
                    else
                        document.getElementById('img_height').value = data[i].height;
                }

                //if ($(".dialog1 ui-dialog-content ui-widget-content"))

                if ($("#dialog_bizproc").css('display') == 'block') $("#dialog_bizproc").dialog('close');
                my_bizproc_start = 1;
                open_my_dialog();

                var parentElem = document.getElementById('dialog_bizproc_2');
                for (var iteration = 1; iteration < data_count + 1; iteration++) {
                    var div = document.createElement('div');
                    div.className = 'form_switcher';
                    div.id = 'my_id' + iteration;
                    if (iteration == 1)
                        div.style.backgroundPosition = 'left';
                    div.style.display = 'inline-block';
                    parentElem.appendChild(div);
                }

                //изначально скрываем кнопки
                document.getElementById('g_button').style.display = 'none';
                document.getElementById('b_button').style.display = 'none';

                if (data[i].g_button == '1') {
                    document.getElementById('g_button').style.display = 'block';
                    document.getElementById('g_button').innerHTML = data[i]['g_text'];
                }
                if (data[i].b_button == '1') {
                    document.getElementById('b_button').style.display = 'block';
                    document.getElementById('b_button').innerHTML = data[i]['b_text'];
                }


                $('#dialog_bizproc_2').click(function () {
                    if (click_flag)
                        return;
                    data_count -= 1;
                    i += 1;

                    //если все шаги прошли, закрываем диалог
                    if (i > start_count)
                        remove_page_arrows_my();

                    //изначально скрываем кнопки
                    document.getElementById('g_button').style.display = 'none';
                    document.getElementById('b_button').style.display = 'none';


                    document.getElementById('my_id' + i).style.backgroundPosition = 'left'

                    if (data_count > 0) {
                        //изначально скрываем кнопки
                        document.getElementById('g_button').style.display = 'none';
                        document.getElementById('b_button').style.display = 'none';

                        //задаем размер окна  с учетом картинкой
                        if (data[i].att_file_name != '') {
                            document.getElementById('img_id').style.display = 'block';
                            document.getElementById('img_width').value = data[i].width;

                            document.getElementById('img_height').value = data[i].height;
                            document.getElementById('dialog_height').style.height = '';
                        }

                        //пытаемся задать размеры окна без картинки
                        if (data[i].att_file_name == '') {
                            document.getElementById('img_id').style.display = 'none';

                            if (data[i].description.length > 200)
                                document.getElementById('img_height').value = 400;
                            else
                                document.getElementById('img_height').value = data[i].height;

                            if (data[i].description.length > 200)
                                document.getElementById('img_width').value = 600;
                            else
                                document.getElementById('img_width').value = 400;

                            document.getElementById('dialog_height').style.height = document.getElementById('img_height').value - 70 + 'px';
                        }


                        bp_name = data[i].name;
                        bp_desc = data[i].description;
                        bp_img = data[i].att_file;

                        open_my_dialog();

                        if (data[i].g_button == '1') {
                            document.getElementById('g_button').style.display = 'block';
                            document.getElementById('g_button').innerHTML = data[i]['g_text'];
                            my_param_g = i;
                        }
                        if (data[i].b_button == '1') {
                            document.getElementById('b_button').style.display = 'block';
                            document.getElementById('b_button').innerHTML = data[i]['b_text'];
                            my_param_b = i;
                        }

                        if (!document.getElementById('bp_header_id')) {
                          let dialog_elem = document.querySelector('[aria-describedby="dialog_bizproc_2"]')
                          dialog_elem.style.width = ''
                          dialog_elem.querySelector('.dialog1').style.height = ''


                          let dialog_inner_elem = document.querySelector('[aria-describedby="dialog_bizproc_2"] .ui-dialog-title')
                          dialog_inner_elem.innerHTML = dialog_inner_elem.innerText
                        }

                        document.getElementById('bp_header_id').innerHTML = bp_name;
                        document.getElementById('desc_id').innerHTML = bp_desc;
                        document.getElementById('img_id').setAttribute('src', bp_img);
                    }

                });

                $('#g_button').click(function () {
                    if (document.getElementById('g_button').style.display == 'block' && data[i].g_link != '') {
                        my_bizproc_start = 0;
                        click_flag = 1;
                        $("#dialog_bizproc_2").dialog('close');
                        window.location.href = data[my_param_g].g_link;
                    }
                });

                $('#b_button').click(function () {
                    if (document.getElementById('b_button').style.display == 'block' && data[i].b_link != '') {
                        my_bizproc_start = 0;
                        click_flag = 1;
                        $("#dialog_bizproc_2").dialog('close');
                        window.location.href = data[my_param_b].b_link;
                    }
                });


                bp_name = data[i].name;
                bp_desc = data[i].description;
                bp_img = data[i].att_file;

                if (!document.getElementById('bp_header_id')) {
                  let dialog_elem = document.querySelector('[aria-describedby="dialog_bizproc_2"]')
                  dialog_elem.style.width = ''
                  dialog_elem.querySelector('.dialog1').style.height = ''

                  let dialog_inner_elem = document.querySelector('[aria-describedby="dialog_bizproc_2"] .ui-dialog-title')
                  dialog_inner_elem.innerHTML = dialog_inner_elem.innerText
                }

                document.getElementById('bp_header_id').innerHTML = bp_name;
                document.getElementById('desc_id').innerHTML = bp_desc;
                document.getElementById('img_id').setAttribute('src', bp_img);
            }

        });
    }

    function remove_page_arrows_my() {
        if ($("#dialog_bizproc").css('display') == 'block') $("#dialog_bizproc").dialog('close');
        location.reload();
    }

    function open_my_dialog() {
        var obj = {};
        obj.modal = true;
        obj.title = '<table cellpadding="0" cellspacing="0"><tr><td height="10"><p id="bp_header_id" style="font-size:16px; font-weight:normal; color:#999; margin-top:3px; padding-left:8px;"></p></td><td></td></tr></table>';
        let elem = $(obj.title)
        if (document.getElementById('img_width').value)
            obj.width = document.getElementById('img_width').value;
        obj.height = document.getElementById('img_height').value;

        //делаем точки в самом низу страницы
        obj.draggable = false;
        obj.resizable = false;
        obj.open = function (event, ui) {
            $(this).parent().find('.ui-dialog-title').html(elem);
        };
        $("#dialog_bizproc_2").dialog(obj);
        $('.ui-icon-closethick').remove();
        $('.ui-button-icon-space').remove();
        $('.ui-dialog-titlebar-close').removeClass('ui-button ui-corner-all ui-widget ui-button-icon-only');
        $('.ui-dialog-titlebar-close').text('');
        $("#dialog_bizproc_2").bind('dialogclose', remove_page_arrows_my);
        overlayHandler();
        $(window).on('resize', overlayHandler);
        $("div.ui-dialog").focus();
        return false;
    }

    function bizproc_view() {
        if (my_bizproc_start == 1)
            return;
        var obj = {};
        obj.modal = true;
        obj.title = '<table cellpadding="0" cellspacing="0"><tr><td height="10"><p style="font-size:16px; font-weight:normal; color:#999; margin-top:3px; padding-left:8px;">{$lang.Business_processes}</p></td>{if $user.group_id==1 or $user.sub_admin_rights.addit_bizproc}<td><a style="text-decoration:none; " href="edit_bizproc.php?&back_url={$base64_current_url}"><img alt="" border="0" src="images/settings_a.gif" onmouseover="this.src=\'images/settings_b.gif\';" onmouseout="this.src=\'images/settings_a.gif\';" style="margin-left:10px; margin-top:-7px;"/></a></td>{/if}</tr></table>';
        obj.width = 350;
        obj.draggable = false;
        obj.resizable = false;
        obj.open = function (event, ui) {
            $(this).parent().find('.ui-dialog-title').html(obj.title);
        };
        $("#dialog_bizproc").dialog(obj);
        $('.ui-icon-closethick').remove();
        $('.ui-button-icon-space').remove();
        $('.ui-dialog-titlebar-close').removeClass('ui-button ui-corner-all ui-widget ui-button-icon-only');
        $('.ui-dialog-titlebar-close').text('');
        overlayHandler();
        $("div.ui-dialog").focus();
        return false;
    }
</script>
<!-- End of business_processes -->
{/if}



{* Блок "Избранные записи" *}
<div id="favorite_window" style="display: none{*$b_events.search.view*}; top: {$b_events.search.top}; left: {$b_events.search.left}; z-index: 5001; opacity: {$b_events.search.opacity}" onclick="eventWindowFocus('favorite'); event.cancelBubble = true">

    <div id="favorite_window_header">
        {$lang.favorite_lines}
    </div>

    <div class="favorite_window_inner">
        <table class="favorite_window_table">
            <tbody>

            </tbody>
        </table>
    </div>

    <img src="images/window_close.png" alt="" id="favorite_window_close" onclick="eventView('favorite'); event.cancelBubble = true" title="{$lang.Hide}"/>
</div>
