<!-- IF AJAX_TOPICS -->
<script type="text/javascript">
ajax.openedPosts = {};

ajax.view_post = function(post_id, src) {
	if (!ajax.openedPosts[post_id]) {
		ajax.exec({
			action  : 'view_post',
			post_id : post_id
		});
	}
	else {
		var $post = $('#post_'+post_id);
		if ($post.is(':visible')) {
			$post.hide();
		}	else {
			$post.css({ display: '' });
		}
	}
	$(src).toggleClass('unfolded2');
};

ajax.callback.view_post = function(data) {
	var post_id = data.post_id;
	var $tor = $('#tor_'+post_id);
	window.location.href='#tor_'+post_id;
	$('#post-row tr')
		.clone()
		.attr({ id: 'post_'+post_id })
		.find('div.post_body').html(data.post_html).end()
		.find('a.tLink').attr({ href: $('a.tLink', $tor).attr('href') }).end()
		.find('a.dLink').attr({ href: $('a.tr-dl', $tor).attr('href') }).end()
		.insertAfter($tor)
	;
	initPostBBCode('#post_'+post_id);
	var maxH   = screen.height - 290;
	var maxW   = screen.width - 60;
	var $post  = $('div.post_wrap', $('#post_'+post_id));
	var $links = $('div.post_links', $('#post_'+post_id));
	$post.css({ maxWidth: maxW, maxHeight: maxH });
	$links.css({ maxWidth: maxW });
	if ($.browser.msie) {
		if ($post.height() > maxH) { $post.height(maxH); }
		if ($post.width() > maxW)  { $post.width(maxW); $links.width(maxW); }
	}
	ajax.openedPosts[post_id] = true;
};
</script>

<style type="text/css">
.post_wrap { border: 1px #A5AFB4 solid; margin: 8px 8px 6px; overflow: auto; }
.post_links { margin: 6px; }
</style>

<table id="post-row" style="display: none;">
<tr>
	<td class="row2" colspan="{TOR_COLSPAN}">
		<div class="post_wrap row1">
			<div class="post_body pad_6"></div><!--/post_body-->
			<div class="clear"></div>
		</div><!--/post_wrap-->
		<div class="post_links med bold tCenter"><a class="tLink">{L_OPEN_TOPIC}</a> &nbsp;&#0183;&nbsp; <a class="dLink">{L_DL_TORRENT}</a></div>
	</td>
</tr>
</table>
<!-- ENDIF / AJAX_TOPICS -->

<a name="start"></a>
<div class="col-md-12">
<div class="page-header m-b-0">
    <h1><i class="page-header-icon ion-ios-search"></i>{PAGE_TITLE}</h1>
	<div class="box-cell">
	<!-- IF MATCHES -->{MATCHES} {SERACH_MAX}<!-- ENDIF -->
	</div>
</div>
<br>

<!-- IF TORHELP_TOPICS -->
	<!-- INCLUDE torhelp.tpl -->
<!-- ENDIF / TORHELP_TOPICS -->

<!-- IF SHOW_SEARCH_OPT -->
<script type="text/javascript">
var FSN = {
	fs_all      : '',
	fs_og       : [],
	fs_lb       : [],
	sel_width   : null,
	scroll      : $.browser.mozilla,
	nav_inited  : false,

	show_nav: function() {
		$('#fs>label').empty().append( $('#fs-nav-legend').contents() );
	},
	build_nav: function() {

		if (FSN.nav_inited) return;

		var $fieldset = $('div#fs');
		var $select = $('select:last', $fieldset);
		var $optgroup = $('optgroup', $select);

		$optgroup.each(function(i){
			var $og = $(this);
			$og.attr({ id: 'og-'+i });
			FSN.fs_og[i] = $(this).html();
			FSN.fs_lb[i] = $(this).attr('label');
			$('#fs-sel-cat').append('<option class="cat-title" value="'+ i +'">&nbsp;&nbsp;&middot;&nbsp;'+ FSN.fs_lb[i] +'&nbsp;</option>\n');
			$('<li><span class="b">'+ FSN.fs_lb[i] +'</span>\n<ul id="nav-c-'+ i +'"></ul>\n</li>').appendTo('#fs-nav-ul').click(function(){
				if (FSN.scroll) {
					$select.scrollTo('#og-'+i);
				}
			});
			$('option', $og).each(function(){
				var $op = $(this);
				if ($op[0].className) {
					$('<li><span class="f">'+ $op.html() +'</span>\n</li>').appendTo('#nav-c-'+ i).click(function(e){
						e.stopPropagation();
						if (FSN.scroll) {
							$select.scrollTo( '#'+$op.attr('id'), { duration:300 } ).scrollTo( '-=3px' );
						}
						$('option', $select).removeAttr('selected');
						$('#'+$op.attr('id')).attr({ selected: 1 });
						$('#fs-nav-list').fadeOut();
					});
				}
			});
		});

		$('#fs-nav-ul').treeview({ collapsed: true });

		$('#fs-sel-cat').bind('change', function(){
			var i = $(this).val();
			if (FSN.sel_width == null) {
				FSN.sel_width = $select.width() + 4;
			}
			if (i == 'all') {
				var fs_html = FSN.fs_all;
			}
			else {
				var fs_html = '<optgroup label="'+ FSN.fs_lb[i] +'">'+ FSN.fs_og[i] +'</optgroup>';
			}
			$select.html(fs_html).focus();
			if (i == 'all') {
				$('#fs-nav-menu').show();
			}
			else {
				$('#fs-nav-menu').hide();
			}
			$select.width(FSN.sel_width);
		});

		FSN.fs_all = $select.html();

		FSN.nav_inited = true;
	}
};

$(function(){
	FSN.show_nav();
	$('#fs label').one('mouseenter', FSN.build_nav);
});
</script>
<style type="text/css">
    .page-forum-topics-item,
    .page-forum-topics-item .box,
    .page-forum-topics-item .box-cell {
      overflow: visible !important;
      -webkit-mask-image: none !important;
    }

    .page-forum-topics-title {
      margin-bottom: 2px;
    }

    .page-forum-topics-title .label {
      vertical-align: text-bottom;
      font-weight: bold;
    }
  </style>
<div class="menu-sub" id="fs-nav-list">
	<div class="tRight"><span id="fs-nav-close" class="med" onclick="$('#fs-nav-list').hide();"> [ {L_HIDE} ] </span></div>
	<ul id="fs-nav-ul" class="tree-root"></ul>
</div>

<div id="fs-nav-legend" style="display: none;">
	<select id="fs-sel-cat"><option value="all">&nbsp;{L_SELECT_CAT}&nbsp;</option></select>
	<span id="fs-nav-menu">&nbsp;&middot;&nbsp;<a class="menu-root" href="#fs-nav-list">{L_GO_TO_SECTION}</a></span>
</div>

<div class="panel">
    <div class="panel-heading">
        <div class="panel-title">{L_TOR_SEARCH_TITLE}</div>
    </div>
    <div class="panel-body">
		<form method="POST" name="post" action="{TOR_SEARCH_ACTION}#results">
		{S_HIDDEN_FIELDS}

				<div class="row">
					<div class="col-xl-6 col-mg-12 form-group" id="fs">
						<label>{L_SEARCH_IN_FORUMS}</label>
						<div>
							<p class="select">{CAT_FORUM_SELECT}</p>
							<p id="fs-qs-div" class="med" style="display: none;"><input id="fs-qs-input" type="text" style="width: 200px;"> {L_FILTER_BY_NAME}</p>
							<p><img width="300" class="spacer" src="{SPACER}" alt="" /></p>
						</div>
					</div>
					<div class="col-xl-3 col-mg-12 form-group">
						<label>{L_SORT_BY}</label>
						{ORDER_SELECT}
						<label class="custom-control custom-radio radio-inline">
							<input class="custom-control-input" type="radio" name="{SORT_NAME}" value="{SORT_ASC}" {SORT_ASC_CHECKED} />
							<span class="custom-control-indicator"></span>
							{L_ASC}
						</label>
						<label class="custom-control custom-radio radio-inline">
							<input class="custom-control-input" type="radio" name="{SORT_NAME}" value="{SORT_DESC}" {SORT_DESC_CHECKED} />
							<span class="custom-control-indicator"></span>
							{L_DESC}
						</label>

						<hr class="page-wide-block m-a-1">
						<label>{L_TORRENTS_FROM}</label>
						{TIME_SELECT}

						<hr class="page-wide-block m-a-1">
						<label>{L_SEED_NOT_SEEN}</label>
						{S_NOT_SEEN_SELECT}

						<hr class="page-wide-block m-a-1">
						<label>{L_GROUPS_RELEASES}</label>
						{S_RG_SELECT}

						<hr class="page-wide-block m-a-1">
						<label>{L_AUTHOR}</label>
						<div class="input-group">
							<input class="form-control" <!-- IF POSTER_ERROR -->style="color: red"<!-- ELSE -->class="post"<!-- ENDIF --> type="text" size="16" maxlength="{POSTER_NAME_MAX}" name="{POSTER_NAME_NAME}" value="{POSTER_NAME_VAL}" />
							<div class="input-group-btn">
								<input class="btn" type="button" value="{L_FIND_USERNAME}" onclick="window.open('{U_SEARCH_USER}', '_bbsearch', IWP_US); return false;" />
							</div>
						</div>

						<hr class="page-wide-block m-a-1">
						<label><span class="a-hash bold" onclick="$(this).addClass('bold').next().removeClass('bold'); $('#title_search').attr('name','{TITLE_MATCH_NAME}').attr('maxlength','{TITLE_MATCH_MAX}');">{L_TITLE_MATCH}</span>&nbsp;&middot;&nbsp;<span class="a-hash" onclick="$(this).addClass('bold').prev().removeClass('bold'); $('#title_search').attr('name','hash').attr('maxlength',40);">{L_HASH_S}</span></label>
						<input id="title_search" class="form-control" type="text" size="50" maxlength="{TITLE_MATCH_MAX}" name="{TITLE_MATCH_NAME}" value="{TITLE_MATCH_VAL}" />
						{ALL_WORDS_CHBOX}
						&middot; <a class="med" href="#" onclick="return get_fs_link();">{L_SEL_CHAPTERS}</a>
						<!-- IF $bb_cfg['search_help_url'] --> &middot; <a class="med" href="{$bb_cfg['search_help_url']}">{L_SEARCH_HELP_URL}</a><!-- ENDIF -->
					</div>
					<div class="col-xl-3 col-mg-12 form-group">
						<label>{L_SHOW_ONLY}</label>
						{ONLY_MY_CHBOX}
						{ONLY_ACTIVE_CHBOX}
						{SEED_EXIST_CHBOX}
						{ONLY_NEW_CHBOX}
						<label class="custom-control custom-checkbox">
							<input class="custom-control-input" type="checkbox" <!-- IF HIDE_CONTENTS -->{CHECKED}<!-- ENDIF -->onclick="user.set('h_tsp', this.checked ? 1 : 0);"/>
							<span class="custom-control-indicator"></span>
							{L_HIDE_CONTENTS}
						</label>
						<!-- IF $tr_cfg['gold_silver_enabled'] -->{TOR_TYPE_CHBOX}<!-- ENDIF -->

						<hr class="page-wide-block m-a-1">
						<label>{L_MY_DOWNLOADS}</label>
						<div>
							<table class="borderless my_downloads" cellspacing="0">
								<tr>
									<td>{DL_COMPL_CHBOX}</td>
								</tr>
								<tr>
									<td>{DL_WILL_CHBOX}</td>
								</tr>
								<tr>
									<td>{DL_DOWN_CHBOX}</td>
								</tr>
								<tr>
									<td>{DL_CANCEL_CHBOX}</td>
								</tr>
							</table>
						</div>

						<hr class="page-wide-block m-a-1">
						<label>{L_SHOW_COLUMN}</label>
						{SHOW_CAT_CHBOX}
						{SHOW_FORUM_CHBOX}
						{SHOW_AUTHOR_CHBOX}
						{SHOW_SPEED_CHBOX}
					</div>
				</div>
				<hr class="page-wide-block m-a-1">
				<div class="row">
					<div class="col-sm-12 text-center">
					<input class="btn" type="submit" name="submit" value="{L_SEARCH}">
					</div>
				</div>

		</form>
	</div>
</div>

<!-- ENDIF / SHOW_SEARCH_OPT -->

<a name="results"></a>

<!-- BEGIN tor -->
<div class="page-forum-topics-item box panel p-y-2 p-x-2 m-b-1<!-- IF SHOW_CURSOR --> hl-tr<!-- ENDIF -->" id="tor_{tor.POST_ID}">
	<div class="row">
        <div class="col-md-8 col-lg-9 col-xl-10">
			<div style="display: inline-flex;">
			<div class="page-forum-topics-title font-size-14 tt">
				<span title="{tor.TOR_STATUS_TEXT}" data-toggle="tooltip">{tor.TOR_STATUS_ICON}</span>&#0183;
				<a href="{TOPIC_URL}{tor.TOPIC_ID}" class="font-weight-semibold tt-text"><!-- IF tor.POLL --><span class="topicPoll">{L_TOPIC_POLL}</span>&nbsp;<!-- ENDIF --><!-- IF tor.TOR_FROZEN -->{tor.TOPIC_TITLE}<!-- ELSE -->{tor.TOR_TYPE}<b>{tor.TOPIC_TITLE}</b><!-- ENDIF --></a>
			</div>
			</div>
			<div class="font-size-11 text-muted">
				<!-- IF SHOW_CAT --><a class="gen" href="{TR_CAT_URL}{tor.CAT_ID}">{tor.CAT_TITLE}</a>&nbsp;·<!-- ENDIF -->
				<!-- IF SHOW_FORUM -->{L_FORUM}: <a class="gen" href="{TR_FORUM_URL}{tor.FORUM_ID}">{tor.FORUM_NAME}</a>&nbsp;·<!-- ENDIF -->
				<!-- IF SHOW_AUTHOR -->
					{L_AUTHOR}: <a class="med" href="{TR_POSTER_URL}{tor.POSTER_ID}">{tor.USERNAME}<!-- IF tor.USER_AUTHOR -->&nbsp;&reg;<!-- ENDIF --></a>&nbsp;·
				<!-- ENDIF -->
				{tor.ADDED_DATE}
			</div>
        </div>

        <hr class="visible-xs visible-sm m-y-2">

        <div class="col-md-4 col-lg-3 col-xl-2 valign-middle text-center">
			<div class="pull-md-right">
				<div class="box-container width-md-auto valign-middle">

					<div class="box-cell p-l-1 p-r-1">
						<div class="font-size-14 text-primary"><span class="text-success" title="{L_SEEDERS}" data-toggle="tooltip">{tor.SEEDS}</span> | <span class="text-danger" title="{L_LEECHERS}" data-toggle="tooltip">{tor.LEECHS}</span></div>
						<div class="font-size-11 text-muted line-height-1">
							<!-- IF not tor.TOR_FROZEN --><a class="btn btn-xs tr-dl" title="{L_DOWNLOAD}" data-toggle="tooltip" href="{DOWNLOAD_URL}{tor.ATTACH_ID}">{tor.TOR_SIZE}</a><!-- ELSE -->
							{tor.TOR_SIZE}<!-- ENDIF -->
						</div>
					</div>

					<div class="box-cell p-x-1 b-l-1">
						<div class="font-size-14"><strong title="{L_REPLIES}:{tor.REPLIES}" data-toggle="tooltip">{tor.COMPLETED}</strong></div>
						<div class="font-size-11 text-muted line-height-1">{L_COMPLETED}</div>
					</div>
				</div>
			</div>
        </div>
    </div>
</div>
<!-- END tor -->

<!-- IF TOR_NOT_FOUND -->
<tbody>
<tr>
	<td class="row1 tCenter pad_8" colspan="{TOR_COLSPAN}">{NO_MATCH_MSG}</td>
</tr>
</tbody>
<!-- ENDIF / TOR_NOT_FOUND -->

<!-- IF PAGINATION -->
<nav>
    <ul class="pagination pagination-sm m-y-0">
        {PAGINATION}
    </ul>
	<p class="pull-right">{PAGE_NUMBER}</p>
</nav>
<!-- ENDIF -->
</div><!--/bottom_info-->

<script type="text/javascript">
// Скрыть содержимое {...}
if (user.opt_js.h_tsp) {
	$('a.tLink').each(function(){
		$(this).html( $(this).html().replace(/\{.+?\}/g, '{...}') );
	});
}
$.each( [{SELECTED_FORUMS}], function(i,n){ $('#fs-'+ n).attr('selected', 1) });
$('#search_opt, #search-results').show();
var fs_last_val = [];
$(function(){
	<!-- IF TITLE_MATCH_URL -->
	$('a.f, a.pg').each(function(){ this.href += '&{TITLE_MATCH_URL}'; });
	$('a.s-all').each(function(){ this.href += '?{TITLE_MATCH_URL}'; });
	<!-- ENDIF -->
	<!-- IF POSTER_MATCH_URL -->
	$('a.f, a.pg').each(function(){ this.href += '&{POSTER_MATCH_URL}'; });
	<!-- ENDIF -->
	// лимит на количество выбранных разделов
	fs_last_val = $('#fs-main').val();

	$('#fs-main').bind('change', function(){
		var fs_val = $('#fs-main').val();
		if (fs_val != null) {
			if (fs_val.length > {MAX_FS}) {
				alert('{L_MAX_FS}');
				$('#fs-main').val( fs_last_val );
			}
			else {
				fs_last_val = fs_val;
			}
		}
	});
	if ($.browser.mozilla) {
	$('#fs-qs-input').focus().quicksearch('#fs-main option', {
		delay   : 300,
		onAfter : function(){
			$('#fs-main optgroup').show();
			$('#fs-main option:hidden').parent('optgroup').not( $('#fs-main :visible').parent('optgroup') ).hide();
		}
	});
	$('#fs-main').attr( 'size', $('#fs-main').attr('size')-1 );
	$('#fs-qs-div').show();
}
});
function get_fs_link ()
{
	var fs_url = '{TRACKER_URL}';
	var fs_val = $('#fs-main').val();

	if (fs_val == null) {
		alert('{L_NOT_SEL_CHAPTERS}');
	}
	else {
		fs_url += 'f[]='+ fs_val.join('&f[]=');
		window.prompt('{L_SEL_CHAPTERS}:', fs_url);
	}
	return false;
}
</script>
