{include file="./index_top.tpl"}
<style type="text/css">
    {foreach from=$event_list item=one_event name=add_event key=event_id}
    div.c_event_layout{$event_id} {
        background: {$one_event.color};
        background-color: rgba({$one_event.color_r}, {$one_event.color_g}, {$one_event.color_b}, 0.{if $one_event.background && !$calendar.day && !$calendar.week}1{else}2{/if});
    }

    {/foreach}

    /* для видимости календаря целиком на мобильных */
    body{
      width: fit-content;
    }

    table.textpad {
        border: none;
        margin: 0px;
        border-collapse: collapse;
        width: 100%;
        height: auto;
    }

    table.textpad td {
        width: auto;
        border: none;
        padding: 3px !important;
        height: auto;
    }

    table.textpad td:hover {
        background: transparent;
    }

    .fields .hidden-input {
        max-width: 93.5%;
    }

    .preloader__block {
      width: 100vw;
    }
</style>
<style>
    .ui-timepicker-div .ui_tpicker_second_label {
        float: left;
        display: inline-block;
        margin-top: 2px;
        margin-left: 4px;
        height: 14px;
    }

    .ui-timepicker-div .ui_tpicker_time_label {
        float: left;
        margin-left: 4px;
        height: 14px;
        margin-bottom: 5px;
    }

    .ui-timepicker-div .ui_tpicker_hour_label {
        float: left;
        display: inline-block;
        margin-left: 4px;
        height: 14px;
        margin-bottom: 5px;
    }

    .ui-timepicker-div .ui_tpicker_minute_label {
        float: left;
        display: inline-block;
        margin-left: 4px;
        height: 14px;
        margin-bottom: 5px;
    }

    .ui-timepicker-div .ui_tpicker_hour {
        height: 14px;
        margin-bottom: 5px;
    }

    .ui-timepicker-div .ui_tpicker_minute {
        height: 14px;
        margin-bottom: 5px;
    }

    .ui-timepicker-div .ui_tpicker_time {
        /*float:left;*/
        margin-left: 5.5em;
        height: 14px;
        margin-bottom: 5px;
    }

    .ui-timepicker-div .ui-slider.ui-slider-horizontal {
        width: 10.5em;
        height: 12px;
        margin-left: 2.3em;
    }

    .short_input.datepicker, .short_input.datetimepicker {
        width: 140px;
    }

    .ui-datepicker-current.ui-state-default.ui-priority-secondary.ui-corner-all {
        color: #212121;
        opacity: 0.83;
        font-weight: bold;
    }

    .ui-datepicker-current.ui-state-default.ui-priority-secondary.ui-corner-all.ui-state-hover {
        opacity: 1;
    }
</style>
<script type="text/javascript">

    var back_url = '{$base64_current_url}';

    var under_mouse_object = 0;
    var last_focus = 0;
    var load_values = new Array();

    function formatItem(row) {
        {literal}
        return row[2].replace(/\r/g, "<br>\n");
        {/literal}
    }
    function formatResult(row) {
        if (row[0] == "") return "";
        return row[1];
    }
    function fix_result(event, data, formatted) {
        var hidden = $(this).next().next();
        hidden.val(data[0]);
        hidden.change();
    }

    var fast_edit_old = "";
    var ajax_update = new XMLHTTP("update_value.php");
    var ajax_view_line = new XMLHTTP("view_line2.php");
    var last_tabindex_fast_edit = 800;
    var is_shift_pressed = 0; // глобальное состояние, содежащие, нажат ли шифт
    var skip_fast_focus = 0; // не обрабатывать событие onfocus у редактируемого элемента
    var skip_fast_blur = 0;  // не обрабатывать событие onblur у редактируемого элемента

    // Массив содержащий описания полей
    var all_fields = { {foreach from=$tables_cache item=one_table}{foreach $one_table['table_fields'] as $one_field}{$one_field['id']}:
    {
        'id'
    :
        '{$one_field.id}', 'table_id'
    :
        '{$one_field.table_id}', 'name_field'
    :
        '{$one_field.name_field|replace:'\\':'\\\\'|replace:"'":"\'"}', 'type_field':'{$one_field.type_field}', 'type_value':'$one_field.type_value_js', 'default_value':'{$one_field.default_value_js}', 'main':'{$one_field.main}', 'unique':'{$one_field.unique}', 'mult_value':'{$one_field.mult_value}', 'pp':'{$one_field.pp}', 'int_name':'{$one_field.int_name}', 'view':'{$one_field.view}', 'view_tb':'{$one_field.view_tb}', 'view_edit':'{$one_field.view_edit}', 'view_add':'{$one_field.view_add}', 'read':'{$one_field.read}', 'write':'{$one_field.write}', 'child_link_field':'{$one_field.child_link_field}', 'parent_link_field':'{$one_field.parent_link_field}', 's_field_id':'{$one_field.s_field_id}', 's_table_id':'{$one_field.s_table_id}', 's_field_filter_id':'{$one_field.s_field_filter_id}', 'view_html':'{$one_field.view_html}','max_size':'{$one_field.max_size}','file_types':{ldelim}{foreach from=$one_field.file_types item=filetype name=files}{$smarty.foreach.files.index}:'{$filetype}',{/foreach}{rdelim}, 's_list_values':{ldelim}{foreach from=$one_field.s_list_values key=id item=name name=s_values}{$id}: '{$name|replace:'\\':'\\\\'|replace:"'":"\'"}'{if !$smarty.foreach.s_values.last}, {/if}{/foreach}{rdelim}},
        {/foreach}{/foreach} }
    ;

    var eventFields = new Object;

    // Объект календаря
            {if $js_calendar}var calendar = {$js_calendar};{/if}

    // Список событий
            {if $json_events}var all_calendar_events = {$json_events};{/if}

    // Свойства событий
    {foreach from=$event_list item=one_event key=event_id}
            {if $one_event.default}var defaultEventId = {$event_id};{/if}
    {/foreach}

    var js_group_values = {if $js_group_values}{$js_group_values}{else}new Object{/if};

            {if $js_events}var js_events = {$js_events};{/if}

    var max_offset = {if $max_offset}{$max_offset}{else}0{/if};

            {if $month_days}var month_days = {$js_month_days};{/if}
            {if $week_days}var week_days = {$js_week_days};{/if}

</script>


<br/>

{if $error}
    <div align="center" style="margin:30px">{$error}</div>
{else}
    <script type="text/javascript" src="include/js/calendar.js?{$revision}"></script>
    <div id="inner_block" class="fields">
        <div class="preloader__block">
            <div class="preloader">
                <div class="lds-css ng-scope">
                    <div style="width:100%;height:100%" class="lds-ellipsis">
                        <div>
                            <div></div>
                        </div>
                        <div>
                            <div></div>
                        </div>
                        <div>
                            <div></div>
                        </div>
                        <div>
                            <div></div>
                        </div>
                        <div>
                            <div></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

    <table class="table_title">
        <tr>
            <td class="tit">{$cur_title}{if ($user.group_id == 1 || $user.sub_admin_rights.calendars.{$calendar.id} == 2) and $user.developer_mode}<a
                    href="edit_tabrep.php?calendar={$calendar.id}" style="background-color:transparent;" target=_blank>
                    <img class="settings_t" border="0" style="margin:0 0 0 7px;" src="images/settings_b.gif"
                         alt="{$lang.edit_calendar}" title="{$lang.edit_calendar}"></a>{/if}</td>
            <td class="no_print" nowrap>

                <div id="hidden_add_events"
                     style="position: absolute; z-index: 450; display: none; background: #fff; border: 1px solid #bfbfbf; border-radius: 4px; margin: 32px 0px 0px 0px;">
                    {assign var=add_total value=0}
                    {foreach from=$event_list item=one_event name=add_event key=event_id}
                        {if $one_event.add_acc && !$one_event.background}
                            {assign var=add_total value=$add_total+1}
                            <a href="view_line{$config.vlm}.php?table={$one_event.table_id}&line=new&back_url={$base64_current_url}"
                               onclick="addEvent('{if $calendar.day}{$calendar.day}.{$calendar.month}.{$calendar.year}{else}{$cur_day}{/if}', event, {$event_id}); return false;"
                               class="add_event_button_hidden">
                                <span style="margin: 0px 7px 0px 5px; display: inline-block; width: 10px; height: 10px; background: {$one_event.color}; border: 1px solid #B8B8B8; vertical-align: middle"></span>
                                {$one_event.name}
                            </a>
                        {/if}
                    {/foreach}
                </div>

                {if $add_total gt 1}
                    <a href="#" onclick="viewAllEvents() ;event.cancelBubble = true; return false"
                       style="float: right; margin-left: 30px; background-image: none !important" class="button"><span
                                style="width: 12px;background: url('images/button_toogle.png') no-repeat left top"></span></a>
                {/if}
                {if $add_total gt 0}
                    <a href="#"
                       onclick="addEvent('{if $calendar.day}{$calendar.day}.{$calendar.month}.{$calendar.year}{else}{$cur_day}{/if}', event); return false;"
                       class="button add"{if $add_total gt 1} style="background-position: -500px 0px; margin-right: 30px"{/if}><span>{$lang.Add_record}</span></a>
                {/if}

                <section class="one_event__wrapper" style="display: none;">
                    {foreach from=$event_list item=one_event name=add_event key=event_id}
                        <div class="one_event_block" id="record_card_add{$event_id}" style="width: 420px;">
                            <div id="event_top_arrow{$event_id}">
                                <div style="width: 400px; text-align: center; position: absolute; margin-top: -26px; z-index: 555 !important">
                                    <span style="display: inline-block; border: 8px solid transparent; border-bottom: 8px solid #ddd"></span>
                                </div>
                                <div style="width: 400px; text-align: center; position: absolute; margin-top: -25px; z-index: 556 !important">
                                    <span style="display: inline-block; border: 8px solid transparent; border-bottom: 8px solid #fff"></span>
                                </div>
                            </div>
                            <div class="cal_event_header">
                                <img src="images/tip_window_item_close.png" alt="{$lang.Hide}" title="{$lang.Hide}"
                                />
                                <span style="margin: 0px 3px 0px 0px; display: inline-block; width: 10px; height: 10px; background: {$one_event.color}; "></span>
                                <b class="one_event_date_block">{$one_event.name}</b>
                            </div>
                            <div 
                                id="event_view_edit_add{$event_id}" 
                                class="event_view_edit"
                            >

                            </div>
                            <div class="cal_event_footer">
                                <div id="go_event_link{$event_id}" style="display: none" class="go_event_link"></div>
                                <div id="save_event_button{$event_id}" style="margin: 0px;" class="save_event_button">
                                    <span onclick="saveEvent()" class="sub_add_new_line2 small_green_save"
                                        onkeydown="if ((event.keyCode == 0xA)||(event.keyCode == 0xD)) saveEvent();"><span
                                                class="b_small_green_save"></span><span
                                                class="b_small_green">{$lang.Save}</span><span
                                                class="b_small_green_end"></span></span>
                                </div>
                            </div>
                            <div id="event_bottom_arrow{$event_id}">
                                <div style="width: 400px; text-align: center; position: absolute; margin-top: 11px; z-index: 555 !important">
                                    <span style="display: inline-block; border: 8px solid transparent; border-top: 8px solid #ddd"></span>
                                </div>
                                <div style="width: 400px; text-align: center; position: absolute; margin-top: 10px; z-index: 556 !important">
                                    <span style="display: inline-block; border: 8px solid transparent; border-top: 8px solid #fff"></span>
                                </div>
                            </div>
                        </div>
                    {/foreach}
                </section>

            </td>
            <td width="100%" align="right" style="text-transform: capitalize; vertical-align: bottom" nowrap>
                {if $month_days}
                    <span style="font-size: 23px;"><b>{$calendar.monthname}</b> {$calendar.year}&nbsp;</span>
                    <span class="calendar_pages_button"
                          onclick="calendar_transition('calendar.php?id={$calendar.id}&month={$calendar.prev_month}&year={$calendar.prev_year}');">◀</span>
                    <span class="calendar_pages_button"
                          onclick="calendar_transition('calendar.php?id={$calendar.id}&month={$calendar.next_month}&year={$calendar.next_year}');">▶</span>
                    &nbsp;&nbsp;
                {/if}
                {if $week_days}
                    <span style="font-size: 23px;"><b>{$calendar.begin_day}{if $calendar.begin_monthname neq $calendar.end_monthname} {$calendar.begin_monthname}{/if}</b>{if $calendar.begin_year neq $calendar.end_year} {$calendar.begin_year}{/if}
                        - <b>{$calendar.end_day} {$calendar.end_monthname}</b> {$calendar.end_year}&nbsp;</span>
                    <span class="calendar_pages_button"
                          onclick="calendar_transition('calendar.php?id={$calendar.id}&week={$calendar.prev_week}&month={$calendar.prev_month}&year={$calendar.prev_year}');">◀</span>
                    <span class="calendar_pages_button"
                          onclick="calendar_transition('calendar.php?id={$calendar.id}&week={$calendar.next_week}&month={$calendar.next_month}&year={$calendar.next_year}');">▶</span>
                    &nbsp;&nbsp;
                {/if}
                {if $view_day}
                    <span style="font-size: 23px;"><b>{$calendar.day_name}
                            , {$calendar.day} {$calendar.month_name}</b> {$calendar.year}&nbsp;</span>
                    <span class="calendar_pages_button"
                          onclick="calendar_transition('calendar.php?id={$calendar.id}&day={$calendar.prev_day}&month={$calendar.prev_month}&year={$calendar.prev_year}');">◀</span>
                    <span class="calendar_pages_button"
                          onclick="calendar_transition('calendar.php?id={$calendar.id}&day={$calendar.next_day}&month={$calendar.next_month}&year={$calendar.next_year}');">▶</span>
                    &nbsp;&nbsp;
                {/if}
                <span style="border-left: 1px solid #B8B8B8; border-radius: 3px 0px 0px 3px"
                      class="calendar_type_switcher{if $month_days} sw_act"{else}" onclick="calendar_transition('calendar.php?id={$calendar.id}&month={$calendar.month}&year={$calendar.year}', 'month');"{/if}
                >{$lang.Month}</span><span style="border-left: 1px solid #B8B8B8; border-right: 1px solid #B8B8B8"
                                           class="calendar_type_switcher{if $week_days} sw_act"{else}" onclick="calendar_transition('calendar.php?id={$calendar.id}&week={if $calendar.day}{$calendar.day}{elseif $calendar.month eq $calendar.cur_month and $calendar.year eq $calendar.year}{$calendar.cur_day}{else}1{/if}&month={$calendar.month}&year={$calendar.year}', 'week');"{/if}
                >{$lang.Week}</span><span style="border-right: 1px solid #B8B8B8; border-radius: 0px 3px 3px 0px"
                                          class="calendar_type_switcher{if $view_day} sw_act"{else}" onclick="calendar_transition('calendar.php?id={$calendar.id}&month={$calendar.month}&year={$calendar.year}&day={if $calendar.month eq $calendar.cur_month and $calendar.year eq $calendar.year}{$calendar.cur_day}{elseif $calendar.week}{$calendar.week}{else}1{/if}', 'day');"{/if}
                >{$lang.Day}</span>
            </td>
        </tr>
    </table>
    <table id="calendar_layout">
        <tr>
            <td id="calendar_pad">
                <div id="mini_calendar_layout"{if !$mini_calendar_view} style="display: none"{/if}>
                    <div style="height: 170px">
                        <div id="c_scroll_month">
                            <span class="calendar_pages_button" style="float: left;"
                                  onclick="getMiniCalendar('-')">◀</span>
                            <span class="calendar_pages_button" style="float: right;"
                                  onclick="getMiniCalendar('+')">▶</span>
                            <span id="mini_calendar_header">{$calendar.monthname} {$calendar.year}</span>
                        </div>
                        <table class="mini_calendar">
                            <tr>
                                <th>{$lang.Mon}</th>
                                <th>{$lang.Tue}</th>
                                <th>{$lang.Wed}</th>
                                <th>{$lang.Thu}</th>
                                <th>{$lang.Fri}</th>
                                <th>{$lang.Sat}</th>
                                <th>{$lang.Sun}</th>
                            </tr>
                            <tbody id="mini_calendar_content">
                            {foreach from=$mini_calendar item=one_str}
                                <tr{if $one_str.cur_week} class="m_cur_week"{/if}>
                                    {foreach from=$one_str item=one_day key=cell_num}
                                        {if $cell_num neq 'cur_week'}
                                            <td onclick="jumpToDay({$one_day.day}, {$one_day.month}, {$one_day.year})" {if !$one_day.cur or $one_day.today} style="{if !$one_day.cur}color:#989898;{/if}{if $one_day.today}border: 1px dotted #989898; color: #cd6b69{/if}"{/if}>
                                                {if $one_day.event}<b>{$one_day.day}</b>{else}{$one_day.day}{/if}
                                            </td>
                                        {/if}
                                    {/foreach}
                                </tr>
                            {/foreach}
                            </tbody>
                        </table>
                    </div>

                    <div id="calendar_event_list"
                         style="text-align: left !important; padding: 30px 0px 0px; margin-left: -10px; overflow: hidden; white-space: nowrap;">
                        {foreach from=$event_list item=one_event key=event_id}
                            <div style="padding: 2px 0px;" id="one_event_legend{$event_id}">
                                <span {if $fast_search[$event_id]}onclick="toogleOptions({$event_id})"{/if}
                                      class="toogle_event_arrow"
                                      id="toogle_event_option{$event_id}">{if $fast_search[$event_id]}{if $fast_search[$event_id]['view_form']}▼{else}▶{/if}{else}&nbsp;{/if}</span>
                                <span style="background: {$one_event.color};" onclick="viewHideEvents({$event_id},{if $view_day}2{elseif $week_days}1{else}0{/if});fixCalendarLayout();"
                                      class="event_legend_colors"></span>
                                <span id="calendar_legend_event{$event_id}"
                                      {if $one_event.background}style="font-style: oblique;"{/if}
                                      onclick="changeDefautEvent({$event_id})"
                                      onmouseover="viewSystemHelp({$event_id}, 1)"
                                      onmouseout="viewSystemHelp({$event_id}, 0)"
                                      class="calendar_legend_event{if $event_id eq $calendar.default_event} calendar_legend_default{/if}">{$one_event.name|truncate:16:"...":true}</span>
                                <div id="system_help_event{$event_id}" class="field_tooltip"
                                     style="white-space: normal">
                                    <b>{$lang.Event} &quot;{$one_event.name}&quot;<br/><br/></b>
                                    <b>{$lang.Table}:</b> &quot;{$one_event.name_table}&quot;<br/>
                                    <b>{$lang.Field_events}:</b> &quot;{$one_event.date_f_name}
                                    &quot;{if $one_event.period_f_name} &mdash; &quot;{$one_event.period_f_name}&quot;{/if}
                                    <br/>
                                    {if $one_event.filter_name}<b>{$lang.Filter}
                                    :</b> &quot;{$one_event.filter_name}&quot;{/if}<br/>
                                    {if $one_event.help}<b>{$lang.Help}:</b> {$one_event.help}{/if}
                                </div>
                            </div>
                            {foreach from=$fast_search item=one_search key=s_id}
                                {if $event_id eq $s_id}
                                    <div id="event_opitons{$event_id}"
                                         style="display: {if $one_search.view_form}block{assign var=view_search_form value=1}{else}none{/if};"
                                         class="event_options_block">
                                        {foreach from=$one_search.fields item=one_search_field key=field_id}
                                            <div style="text-align: center; border-top: 1px dotted #D0D0D0; padding: 3px 0px; margin: 3px 0px">{$one_search_field.name_field}
                                                :
                                            </div>
                                            <div class="textpad" id=sub_cell_{$field_id}_e{$s_id}"
                                                 style="padding: 0px; margin: 0px 0px 10px;">
                                                {$one_search_field.fast_edit_div}{$one_search_field.def_value}{$one_search_field.fast_edit_div_close}
                                            </div>
                                        {/foreach}
                                    </div>
                                {/if}
                            {/foreach}
                        {/foreach}
                    </div>
                    <div id="event_fast_search_submit"{if !$view_search_form} style="display: none"{/if}>
                        <form style="display: none" method="post" id="fast_search_submit_form"><input type="hidden"
                                                                                                      name="csrf"
                                                                                                      value="{$csrf}"/>
                        </form>
                        <a class="search_button" href="#" onclick="fastSearchSubmit(); return false;">{$lang.Apply}</a>
                    </div>
                </div>
            </td>
            <td id="calendar_act_button"><span style="cursor: pointer; color: #b8b8b8; font-size: 18px;"
                                               id="view_calendar_arrow" onmouseover="highlightMinicalendar(1)"
                                               onmouseout="highlightMinicalendar(0)"
                                               onclick="viewMiniCalendar()"/>{if $mini_calendar_view}◀{else}
                ▶{/if}</span></td>

            <td id="big_calendar">
              <div id="calendar_scrollable-content" class="mini_calendar_layout__show">
                {* Дневной вид *}
                {if $view_day}
                    <div style="position: relative; left: 8px;" class="view_overperiod_events"
                         style="border: 1px solid #DDDDDD; margin: 20px 0px; min-height: 17px;">
                        {foreach from=$overperiod_events item=one_event}
                            <div draggable="true" is_background="{$one_event.background}"
                                 style="margin-top: 0px; {if !$one_event.background}border: 1px solid {$one_event.color};{/if} z-index: 0"
                                 class="calendar_event_line calendar_event_line_{$one_event.date_field}_{$one_event.line_id}_{$one_event.event_id} calendar_offset_{$one_event.line_id}_{$one_event.event_id} calendar_event_id{$one_event.event_id}"
                                 id="calendar_event_line_{$one_event.date_field}_{$one_event.line_id}_{$one_event.event_id}"
                                data-date_field_id="{$one_event.date_field}"
                                data-period_field_id="{$one_event.period_field}"
                                data-event_id="{$one_event.event_id}"
                                data-line_id="{$one_event.line_id}"     
                            >
                                <div {if !$one_event.background}
                                    {if $config['display_calendar_events'] == '0'}onclick="viewOneEvent({$one_event.event_id}, {$one_event.line_id}, event); event.cancelBubble = true;"{/if}
                                     onmouseover="highlightEvent(true, {$one_event.event_id}, {$one_event.line_id})"
                                     onmouseout="highlightEvent(false, {$one_event.event_id}, {$one_event.line_id})"{/if}
                                     id="c_event_layout{$one_event.event_id}_{$one_event.line_id}"
                                     class="c_event_layout c_event_layout{$one_event.event_id}_{$one_event.line_id} c_event_layout{$one_event.event_id}"
                                     style="z-index: 0;{if $one_event.background} padding: 1px 4px; cursor: default{/if}">
                                    {if $one_event.data.mount_date && !$one_event.prev}{$one_event.data.mount_date}{/if}{$one_event.data.mount}
                                </div>
                                {if $config['display_calendar_events'] == '1'}
                                    <div class="hoverEventBlock">
                                        <div class="cal_event_header">
                                            <b class="one_event_date_block"></b>
                                        </div>
                                        <div class="event_hover--block">
                                            <div class="event_datefields"></div>
                                            <div class="event_fields"></div>
                                        </div>
                                        <div class="cal_event_footer">
                                            <a href="">Перейти к записи »</a>
                                        </div>
                                    </div>
                                    <script>hoverEvent({$one_event.event_id}, {$one_event.line_id}, event, {$one_event.date_field});</script>
                                {/if}
                                <div class="prev_event_arrow"
                                     style="z-index: 15; position: absolute; margin: -16px 0px 0px -1{if $one_event.background}6{else}7{/if}px; {if $one_event.prev}border: 8px solid transparent; border-right: 8px solid {if $one_event.background}rgba({$one_event.color_r}, {$one_event.color_g}, {$one_event.color_b}, 0.1){else}{$one_event.color}{/if}{/if}"></div>
                                <div class="next_event_arrow"
                                     style="z-index: 15; position: absolute; margin: -16px 0px 0px 0px; {if $one_event.next}border: 8px solid transparent; border-left: 8px solid {if $one_event.background}rgba({$one_event.color_r}, {$one_event.color_g}, {$one_event.color_b}, 0.1){else}{$one_event.color}{/if}{/if}"></div>
                            </div>
                        {/foreach}
                    </div>
                    <table class="calendar_day_type calendar_table">
                        <tr>
                            <th>&nbsp;</th>
                            {* Группировка по полю *}
                            {foreach from=$day_header key=one_header_name item=one_header name=header}
                                <th style="vertical-align: top" group_key="{$one_header}" id="day_header{$one_header}">{$one_header_name}</th>
                            {/foreach}
                        </tr>

                        {* Данные в ячейки *}
                        {foreach from=$view_day key=hour item=one_pos name=days}
                            <tr>
                                <td rowspan="2" class="day_time" id="day_time{$hour}"
                                  onclick="addDayEvent(
                                    event, 
                                    {ldelim} 
                                      date: '{$hour}:00',
                                    {rdelim}
                                  )"
                                >{if $one_pos.current}
                                    <div id="cur_time_line" offset="{$one_pos.offset_time}"><span>▶</span>
                                        </div>{/if}{$hour}:00
                                </td>
                                {foreach from=$one_pos.events key=one_group_name item=one_group_data name=day_group_data}
                                    <td 
                                      class="day_top day_cell{$day_header[$one_group_name]|default:"0"}"
                                      id="cell_{$hour}_0_{$day_header[$one_group_name]|default:"0"}"
                                      data-calendar-type="day"
                                      data-hour="{$hour}"
                                      data-minute="00"
                                      data-group-key="{$day_header[$one_group_name]|default:0}"
                                      data-group-name="{if $one_group_name|regex_replace:'/<[^>]+>/':'' == $one_group_name}{$one_group_name|escape:'html'}{else}{''}{/if}"
                                      onclick="addDayEvent(
                                        event, 
                                        {ldelim}
                                          date: '{$hour}:00', 
                                          groupKey: '{$day_header[$one_group_name]|default:0}',
                                          groupValue: '{if $one_group_name|regex_replace:'/<[^>]+>/':'' == $one_group_name}{$one_group_name|escape:'javascript'}{else}{''}{/if}'
                                        {rdelim}
                                      )"
                                    >
                                        {assign var=has_events value=0}
                                        {foreach from=$one_group_data key=min item=one_group_str}
                                            {if !$min}
                                                {assign var=has_events value=1}
                                                {foreach from=$one_group_str item=one_event key=offset}
                                                    <div draggable="true" is_background="{$one_event.background}"
                                                         event_length="{$one_event.length}"
                                                         event_width="{$one_event.width}" event_offset="{$offset}"
                                                         style="margin-top: 0px; z-index: {if $one_event.background}5{else}{$offset + 13}{/if}; {if !$one_event.background}border: 1px solid {$one_event.color}{else}opacity: 0.5{/if}"
                                                         class="calendar_event_line calendar_event_line_{$one_event.date_field}_{$one_event.line_id}_{$one_event.event_id} calendar_offset_{$one_event.line_id}_{$one_event.event_id} calendar_event_id{$one_event.event_id}"
                                                         id="calendar_event_line_{$one_event.date_field}_{$one_event.line_id}_{$one_event.event_id}"
                                                         data-date_field_id="{$one_event.date_field}"
                                                         data-period_field_id="{$one_event.period_field}"
                                                         data-event_id="{$one_event.event_id}"
                                                         data-line_id="{$one_event.line_id}"
                                                    >
                                                        <div {if !$one_event.background}
                                                            {if $config['display_calendar_events'] == '0'}onclick="viewOneEvent({$one_event.event_id}, {$one_event.line_id}, event); event.cancelBubble = true;"{/if}
                                                             onmouseover="highlightEvent(true, {$one_event.event_id}, {$one_event.line_id})"
                                                             onmouseout="highlightEvent(false, {$one_event.event_id}, {$one_event.line_id})"{/if}
                                                             id="c_event_layout{$one_event.event_id}_{$one_event.line_id}"
                                                             class="c_event_layout c_event_layout{$one_event.event_id}_{$one_event.line_id} c_event_layout{$one_event.event_id}" {if $one_event.background} style="padding: 1px 4px; cursor: default; {if $one_event.background} z-index: 5{/if}"{/if}>
                                                            {if $one_event.data.mount_date}{$one_event.data.mount_date}{/if}{$one_event.data.mount}
                                                        </div>
                                                        {if $config['display_calendar_events'] == '1'}
                                                            <div class="hoverEventBlock">
                                                                <div class="cal_event_header">
                                                                    <b class="one_event_date_block"></b>
                                                                </div>
                                                                <div class="event_hover--block">
                                                                    <div class="event_datefields"></div>
                                                                    <div class="event_fields"></div>
                                                                </div>
                                                                <div class="cal_event_footer">
                                                                    <a href="">Перейти к записи »</a>
                                                                </div>
                                                            </div>
                                                            <script>hoverEvent({$one_event.event_id}, {$one_event.line_id}, event, {$one_event.date_field});</script>
                                                        {/if}
                                                    </div>
                                                {/foreach}
                                            {/if}
                                        {/foreach}
                                        &nbsp;
                                    </td>
                                {/foreach}
                            </tr>
                            <tr>
                                {foreach from=$one_pos.events key=one_group_name item=one_group_data name=day_group_data}
                                    <td 
                                      class="day_bottom day_cell{$day_header[$one_group_name]|default:"0"}"
                                      id="cell_{$hour}_1_{$day_header[$one_group_name]|default:"0"}"
                                      data-hour="{$hour}"
                                      data-minute="30"
                                      data-group-key="{$day_header[$one_group_name]|default:0}"
                                      data-group-name="{if $one_group_name|regex_replace:'/<[^>]+>/':'' == $one_group_name}{$one_group_name|escape:'html'}{else}{''}{/if}"
                                      onclick="addDayEvent(
                                        event,
                                        {ldelim}
                                          date: '{$hour}:30', 
                                          groupKey: '{$day_header[$one_group_name]|default:0}',
                                          groupValue: '{if $one_group_name|regex_replace:'/<[^>]+>/':'' == $one_group_name}{$one_group_name|escape:'javascript'}{else}{''}{/if}'
                                        {rdelim}
                                      )"
                                    >
                                        {assign var=has_events value=0}
                                        {foreach from=$one_group_data key=min item=one_group_str}
                                            {if $min}
                                                {assign var=has_events value=1}
                                                {foreach from=$one_group_str item=one_event key=offset}
                                                    <div draggable="true" is_background="{$one_event.background}"
                                                         event_length="{$one_event.length}"
                                                         event_width="{$one_event.width}" event_offset="{$offset}"
                                                         style="margin-top: 0px; z-index: {if $one_event.background}5{else}{$offset + 13}{/if}; margin-left: {($offset-1) * 70}px; {if !$one_event.background}border: 1px solid {$one_event.color}{else}opacity: 0.5{/if}"
                                                         class="calendar_event_line calendar_event_line_{$one_event.date_field}_{$one_event.line_id}_{$one_event.event_id} calendar_offset_{$one_event.line_id}_{$one_event.event_id} calendar_event_id{$one_event.event_id}"
                                                         id="calendar_event_line_{$one_event.date_field}_{$one_event.line_id}_{$one_event.event_id}"
                                                        data-date_field_id="{$one_event.date_field}"
                                                        data-period_field_id="{$one_event.period_field}"
                                                        data-event_id="{$one_event.event_id}"
                                                        data-line_id="{$one_event.line_id}"
                                                    >
                                                        <div {if !$one_event.background}
                                                            {if $config['display_calendar_events'] == '0'}onclick="viewOneEvent({$one_event.event_id}, {$one_event.line_id}, event); event.cancelBubble = true;"{/if}
                                                             onmouseover="highlightEvent(true, {$one_event.event_id}, {$one_event.line_id})"
                                                             onmouseout="highlightEvent(false, {$one_event.event_id}, {$one_event.line_id})"{/if}
                                                             id="c_event_layout{$one_event.event_id}_{$one_event.line_id}"
                                                             class="c_event_layout c_event_layout{$one_event.event_id}_{$one_event.line_id} c_event_layout{$one_event.event_id}" {if $one_event.background} style="padding: 1px 4px; cursor: default;{if $one_event.background} z-index: 5{/if}"{/if}>
                                                            {if $one_event.data.mount_date}{$one_event.data.mount_date}{/if}{$one_event.data.mount}
                                                        </div>
                                                        {if $config['display_calendar_events'] == '1'}
                                                            <div class="hoverEventBlock">
                                                                <div class="cal_event_header">
                                                                    <b class="one_event_date_block"></b>
                                                                </div>
                                                                <div class="event_hover--block">
                                                                    <div class="event_datefields"></div>
                                                                    <div class="event_fields"></div>
                                                                </div>
                                                                <div class="cal_event_footer">
                                                                    <a href="">Перейти к записи »</a>
                                                                </div>
                                                            </div>
                                                            <script>hoverEvent({$one_event.event_id}, {$one_event.line_id}, event, {$one_event.date_field});</script>
                                                        {/if}
                                                    </div>
                                                {/foreach}
                                            {/if}
                                        {/foreach}
                                        &nbsp;
                                    </td>
                                {/foreach}
                            </tr>
                        {/foreach}
                    </table>
                {/if}

                {* Недельный вид *}
                {if $week_days}{include file="calendar/week_days.tpl"}{/if}

                {* Месячный вид *}
                {if $month_days}{include file="calendar/month_days.tpl"}{/if}
              </div>
            </td>
        </tr>
    </table>
    </div>
    <iframe name='frame_upload' style='width:1px;height:1px;display:none;' onload='onupload_file_done(event);'></iframe>
    <script type="text/javascript">
        $(function () {

            var arr_mode = ['calendar', 'events'];

            $('#link_table').addClass('leg_activ');

            var ajaxObj = new XMLHTTP("calendar.php?id={$calendar.id}");
            ajaxObj.method = "POST";

            $("#legend_short span").click(function () {
                document.getElementById('legend_short').style.display = 'none';
                document.getElementById('legend_full').style.display = 'block';
                ajaxObj.call('legend_status=1&csrf={$csrf}', function (){});
            });

            $("#leg_close").click(function () {
                document.getElementById('legend_full').style.display = 'none';
                document.getElementById('legend_short').style.display = 'block';
                ajaxObj.call('legend_status=0&csrf={$csrf}', function (){});
            });

            $("table#leg_head span[id^='link_']").click(function () {
                var sel = this.id.substr(5);
                var name_l = '';
                var name_b = '';
                for (i = 0; i < arr_mode.length; i++) {
                    name_l = '#link_' + arr_mode[i];
                    name_b = 'leg_' + arr_mode[i];
                    if (sel == arr_mode[i]) {
                        $(name_l).addClass('leg_activ');
                        document.getElementById(name_b).style.display = 'block';
                    }
                    else {
                        $(name_l).removeClass('leg_activ');
                        document.getElementById(name_b).style.display = 'none';
                    }
                }
            });
        });
    </script>
    {if $calendar.help or $help_events}
        <div class="no_print">
            <div id="legend_short" style="display: {if $legend_minimized}block{else}none{/if};">
                <p align="center"><span>{$lang.Calendar_help} &quot;{$cur_title}&quot;</span></p>
            </div>
        </div>
        <div id="legend_full"
             style="display: {if $legend_minimized}none{else}block{/if}; margin-left: 0px; margin-right: 0px">
            <table id="leg_head" width="100%" border="0" cellpadding="15" cellspacing="0">
                <tbody>
                <tr>
                    <td>
                        {if $calendar.help}<span id="link_calendar">{$lang.Calendar_desc}</span>{/if}
                        {if $help_events}<span id="link_events">{$lang.Events_calendar}</span>{/if}
                    </td>
                    <td align="right">
                        <img id="leg_close" alt="{$lang.Cancel}" src="images/bullet.png"
                             style="border-width: 0px; border-style: solid; cursor: pointer;"/>
                    </td>
                </tr>
                </tbody>
            </table>

            <div id="leg_line">
            </div>

            <div id="leg_calendar" class="leg_tab" style="display: block;">
                {if $calendar.help}
                    <div class="leg_descr">{$calendar.help}</div>
                {else}
                    <div class="leg_descr">{$lang.No_calendar_desc}</div>
                {/if}
            </div>

            <div id="leg_events" class="leg_tab" style="display: none;">
                <div class="leg_descr">
                </div>
                {if $help_events}
                    <table width="100%" border="0" cellpadding="6" cellspacing="2">
                        {foreach from=$help_events key=event_id item=one_help}
                            <tr>
                                <td class="td_1">
                                    <div>
                                        <span style="margin: 0px 7px 0px 5px; display: inline-block; width: 10px; height: 10px; background: {$one_help.color}; border: 1px solid #B8B8B8; vertical-align: middle"></span>{$one_help.name}
                                    </div>
                                </td>
                                <td class="td_2">{$one_help.help}</td>
                            </tr>
                        {/foreach}
                    </table>
                {else}
                    <div class="leg_descr">{$lang.No_events_desc}.</div>
                {/if}
            </div>

        </div>
    {/if}
{/if}

<script type="text/javascript">
  //<![CDATA[
  var isGrouped = {$is_grouped|json_encode};
  var isDay = !!{$view_day|json_encode};
  var isMonth = !!{$month_days|json_encode};
  var isWeek = !!{$week_days|json_encode};
  //]]>
</script>
