<inp2:m_RequireLogin permissions="in-portal:browse.view" system="1"/>
<inp2:m_DefineElement name="catalog_tab">
	<inp2:m_if check="m_ParamEquals" name="tab_init" value="" inverse="inverse">
		<inp2:m_if check="m_ParamEquals" name="tab_init" value="1">
		 	a_toolbar.AddButton(
				new ToolBarButton(
					'new_cat',
					'<inp2:m_phrase label="la_ToolTip_New_Category" escape="1"/>',
					add_item,
					true
				)
			);
		</inp2:m_if>

		<inp2:m_if check="m_Param" name="tab_init" equals_to="2">
			<div id="categories_div" prefix="<inp2:m_param name='prefix'/>" view_template="catalog_tab" edit_template="categories/categories_edit" category_id="-1" dep_buttons="new_cat" class="catalog-tab"><!-- IE minimal height problem fix --></div>
			<script type="text/javascript">$Catalog.registerTab('categories');</script>
		</inp2:m_if>

		<inp2:m_if check="m_ParamEquals" name="tab_init" value="3">
			$Catalog.setItemCount('<inp2:m_Param name="prefix"/>', '<inp2:{$prefix}_CatalogItemCount grid="$grid_name"/>');
		</inp2:m_if>
	<inp2:m_else/>
		<inp2:lang.current_Field name="Charset" result_to_var="charset"/>
		<inp2:m_Header data="Content-type: text/plain; charset=$charset"/>
		<inp2:m_include t="incs/blocks"/>
		<inp2:m_include t="incs/in-portal"/>
		<inp2:m_include t="categories/ci_blocks"/>

		<inp2:m_if check="m_Param" name="prefix" equals_to="c.showall">
			<inp2:$prefix_InitList grid="$grid_name" parent_cat_id="any"/>
		<inp2:m_else/>
			<inp2:$prefix_InitList grid="$grid_name"/>
		</inp2:m_if>

		// substiture form action, like from was created from here
		document.getElementById('categories_form').action = '<inp2:m_t pass="all" no_amp="1" js_escape="1"/>';
		$Catalog.setItemCount('<inp2:m_param name="prefix"/>', '<inp2:$prefix_CatalogItemCount/>');
		$Catalog.setCurrentCategory('<inp2:m_param name="prefix"/>', <inp2:m_get name="m_cat_id"/>);
		$Catalog.saveSearch('<inp2:m_Param name="prefix"/>', '<inp2:$prefix_SearchKeyword js_escape="1"/>', '<inp2:m_Param name="grid_name"/>');

		<inp2:m_RenderElement name="structure_reload_element"/>

		<inp2:m_DefineElement name="grid_parent_category_td" format="">
			<inp2:Field name="ParentId" result_to_var="item_category" db="db"/>

			<inp2:m_if check="m_Get" name="type" equals_to="item_selector">
				<inp2:CategoryName cat_id="$item_category"/>
			<inp2:m_else/>
				<a href="<inp2:m_Link template='catalog/catalog' m_cat_id='$item_category' no_pass_through='1'/>"><inp2:CategoryName cat_id="$item_category"/></a>
			</inp2:m_if>
		</inp2:m_DefineElement>

		<inp2:m_DefineElement name="page_browse_td" format="">
			<inp2:m_if check="m_Get" name="type" equals_to="item_selector">
				<a href="javascript:$Catalog.go_to_cat(<inp2:m_get name="c_id"/>, '<inp2:GetModulePrefix/>');" title="<inp2:m_Phrase name='la_alt_GoInside' html_escape='1'/>"><inp2:Field field="$field" grid="$grid" format="$format"/></a>
			<inp2:m_else/>
				<a href="<inp2:ItemEditLink/>" title="<inp2:m_Phrase name='la_Text_Edit' no_editing='1'/>" onclick="return direct_edit('<inp2:m_param name="PrefixSpecial"/>', this.href);"><inp2:Field field="$field" grid="$grid" format="$format"/></a>
			</inp2:m_if>

			<!--##<span class="small-statistics">(<inp2:SubCatCount/> / <inp2:ItemCount/>)</span>##-->

			<inp2:m_if check="BrowseModeAvailable" pass_params="1">
				<a href="<inp2:PageBrowseLink/>" title="<inp2:m_Phrase name='la_alt_Browse' no_editing='1'/>"><img src="<inp2:m_TemplatesBase/>/img/ic_browse_mode.gif" width="8" height="7" alt="<inp2:m_Phrase name='la_alt_Browse' html_escape='1'/>" border="0"/></a>
			</inp2:m_if>

			<inp2:m_if check="Field" field="Type" equals_to="2" db="db">
				<span class="field-required" title="<inp2:m_Phrase name='la_System' no_editing='1'/>">&nbsp;*</span>
			</inp2:m_if>
		</inp2:m_DefineElement>

		<inp2:m_RenderElement name="grid_js" PrefixSpecial="$prefix" IdField="CategoryId" grid="$grid_name"  menu_filters="yes"/>
		<inp2:m_RenderElement name="grid_search_buttons" PrefixSpecial="$prefix" grid="$grid_name" ajax="1"/>

		Grids['<inp2:m_param name="prefix"/>'].SetDependantToolbarButtons( new Array('edit','delete','approve','decline','sep3','cut','copy','move_up','move_down','sep6'));

		<inp2:m_if check="{$prefix}_ModuleRootCategory">
			a_toolbar.DisableButton('upcat');
			a_toolbar.DisableButton('homecat');
		<inp2:m_else/>
			a_toolbar.EnableButton('upcat');
			a_toolbar.EnableButton('homecat');
		</inp2:m_if>
		$Catalog.reflectPasteButton(<inp2:$prefix_HasClipboard/>);

		<inp2:m_if check="m_Recall" name="root_delete_error">
			alert('<inp2:m_Phrase name="la_error_RootCategoriesDelete"/>');
			<inp2:m_RemoveVar name="root_delete_error"/>
		</inp2:m_if>
		#separator#
		<!-- categories tab: begin -->
		<inp2:m_RenderElement name="kernel_form" form_name="categories_form"/>
		<inp2:m_RenderElement name="grid" ajax="1" PrefixSpecial="$prefix" IdField="CategoryId" grid="$grid_name" menu_filters="yes"/>
		<inp2:m_RenderElement name="kernel_form_end"/>
		<!-- categories tab: end -->
	</inp2:m_if>
</inp2:m_DefineElement>

<inp2:c_InitCatalogTab render_as="catalog_tab" default_grid="Default" radio_grid="Radio"/>