<inp2:adm_SetPopupSize width="880" height="680"/>
<inp2:m_include t="incs/header"/>
<inp2:m_include t="categories/categories_tabs"/>

<inp2:m_RenderElement name="combined_header" prefix="c" section="in-portal:browse" title_preset="categories_edit" tab_preset="Default"/>

<!-- ToolBar -->
<table class="toolbar" height="30" cellspacing="0" cellpadding="0" width="100%" border="0">
<tbody>
	<tr>
  	<td>
  		<script type="text/javascript">
				a_toolbar = new ToolBar();
				a_toolbar.AddButton( new ToolBarButton('select', '<inp2:m_phrase label="la_ToolTip_Save" escape="1"/>', function() {
							submit_event('c','<inp2:c_SaveEvent/>');
						}
					) );
				a_toolbar.AddButton( new ToolBarButton('cancel', '<inp2:m_phrase label="la_ToolTip_Cancel" escape="1"/>', function() {
							submit_event('c','OnCancelEdit');
						}
				 ) );

				a_toolbar.AddButton( new ToolBarSeparator('sep1') );

				a_toolbar.AddButton( new ToolBarButton('prev', '<inp2:m_phrase label="la_ToolTip_Prev" escape="1"/>', function() {
							go_to_id('c', '<inp2:c_PrevId/>');
						}
				 ) );
				a_toolbar.AddButton( new ToolBarButton('next', '<inp2:m_phrase label="la_ToolTip_Next" escape="1"/>', function() {
							go_to_id('c', '<inp2:c_NextId/>');
						}
				 ) );

				a_toolbar.Render();

				<inp2:m_if check="c_IsSingle">
					a_toolbar.HideButton('prev');
					a_toolbar.HideButton('next');
					a_toolbar.HideButton('sep1');
				<inp2:m_else/>
					<inp2:m_if check="c_IsLast">
						a_toolbar.DisableButton('next');
					</inp2:m_if>
					<inp2:m_if check="c_IsFirst">
						a_toolbar.DisableButton('prev');
					</inp2:m_if>
				</inp2:m_if>
			</script>
		</td>

		<inp2:m_RenderElement name="ml_selector" prefix="c"/>
	</tr>
</tbody>
</table>

<inp2:c_SaveWarning name="grid_save_warning"/>
<inp2:c_ErrorWarning name="form_error_warning"/>
<inp2:m_RenderElement name="inp_edit_hidden" prefix="c" field="OldPriority"/>

<inp2:m_ifnot check="c_FieldVisible" field="Template">
	<inp2:m_RenderElement name="inp_edit_hidden" prefix="c" field="Template" db="db"/>
</inp2:m_ifnot>

<div id="scroll_container">
	<table class="edit-form">
		<inp2:m_RenderElement name="subsection" prefix="c" fields="CategoryId,Name,Description,CreatedById,AutomaticFilename,Filename,SymLinkCategoryId" title="!la_section_Category!"/>
			<inp2:m_RenderElement name="inp_id_label" prefix="c" field="CategoryId" title="!la_fld_CategoryId!"/>
			<inp2:m_RenderElement name="inp_edit_box_ml" prefix="c" field="Name" title="!la_fld_PageTitle!" size="70"/> <!-- la_fld_Name -->
			<inp2:m_RenderElement name="inp_edit_textarea_ml" prefix="c" field="Description" title="!la_fld_Description!" control_options="{min_height: 60}" rows="4" cols="70"/>
			<inp2:m_RenderElement name="inp_edit_user" prefix="c" field="CreatedById" title="la_fld_CreatedById" size="30" display_original="1"/>
			<inp2:m_RenderElement name="inp_edit_checkbox" prefix="c" field="AutomaticFilename" title="la_fld_AutoCreateFileName" onclick="reflectFilename()"/> <!-- la_fld_CategoryAutomaticFilename -->
			<inp2:m_RenderElement name="inp_edit_box" prefix="c" field="Filename" title="la_fld_Filename" size="70" /> <!-- la_fld_CategoryFilename -->
			<inp2:m_RenderElement name="inp_edit_category" prefix="c" field="SymLinkCategoryId" title="la_fld_SymLinkCategoryId"/>

		<inp2:m_RenderElement name="subsection" prefix="c" fields="Title,MenuTitle,FriendlyURL,ParentId,Template,FormId,FormSubmittedTemplate,IsMenu" title="la_section_Page"/>
			<inp2:m_RenderElement name="inp_edit_box_ml" prefix="c" field="Title" title="!la_fld_PageContentTitle!" size="40"/>
			<inp2:m_RenderElement name="inp_edit_box_ml" prefix="c" field="MenuTitle" title="!la_fld_PageMentTitle!" size="40"/>

			<inp2:m_RenderElement name="inp_edit_box" prefix="c" field="FriendlyURL" title="la_fld_FriendlyURL" size="63"/>
			<inp2:m_RenderElement name="inp_edit_options" prefix="c" field="ParentId" title="la_fld_ParentSection"/>

<!--			<inp2:m_RenderElement name="inp_edit_checkbox" prefix="c" field="IsSystem" title="!la_fld_IsSystemTemplate!" onchange="OnSystemClick()"/>-->

			<inp2:m_if check="c_Field" name="IsSystem" equals_to="1" db="db">
				<inp2:m_if check="m_IsDebugMode">
					<inp2:m_RenderElement name="inp_edit_box" prefix="c" field="Template" title="la_fld_TemplateFile" size="40"/>
				</inp2:m_if>
			<inp2:m_else/>
				<inp2:m_RenderElement name="inp_edit_options" prefix="c" field="Template" title="la_fld_TemplateType" size="40"/>
			</inp2:m_if>

			<inp2:m_RenderElement name="inp_edit_options" prefix="c" field="FormId" title="!la_fld_Form!"/>
			<inp2:m_RenderElement name="inp_edit_box" prefix="c" field="FormSubmittedTemplate" title="la_fld_FormSubmittedTemplate" size="60"/>
			<inp2:m_RenderElement name="inp_edit_radio" prefix="c" field="IsMenu" title="la_fld_MenuStatus"/>

		<inp2:m_RenderElement name="subsection" prefix="c" fields="Status,NewItem,EditorsPick,Priority,UseMenuIconUrl,MenuIconUrl,UseExternalUrl,ExternalUrl,CreatedOn,MetaKeywords,MetaDescription,IndexTools" title="!la_section_Properties!"/>
			<inp2:m_RenderElement name="inp_edit_radio" prefix="c" field="Status" title="!la_fld_Status!"/>
			<inp2:m_RenderElement name="inp_edit_radio" prefix="c" field="NewItem" title="!la_fld_New!"/>
			<inp2:m_RenderElement name="inp_edit_checkbox" prefix="c" field="EditorsPick" title="!la_fld_EditorsPick!"/>

			<inp2:m_RenderElement name="inp_edit_options" prefix="c" field="Priority" title="la_fld_Priority"/>

			<inp2:m_RenderElement name="inp_edit_checkbox" prefix="c" field="UseMenuIconUrl" title="!la_fld_UseMenuIcon!" onclick="reflectMenuIcon();"/>
			<inp2:m_RenderElement name="inp_edit_box" prefix="c" field="MenuIconUrl" title="!la_fld_MenuIcon!" size="60"/>
			<inp2:m_RenderElement name="inp_edit_checkbox" prefix="c" field="UseExternalUrl" title="la_fld_UseExternalUrl" onclick="reflectExternalUrl();"/>
			<inp2:m_RenderElement name="inp_edit_box" prefix="c" field="ExternalUrl" title="la_fld_ExternalUrl" size="60"/>

			<inp2:m_RenderElement name="inp_edit_date_time" prefix="c" field="CreatedOn" title="!la_fld_CreatedOn!"/>
			<inp2:m_RenderElement name="inp_edit_textarea" prefix="c" field="MetaKeywords" title="!la_fld_MetaKeywords!" allow_html="0" control_options="{min_height: 50}" rows="3" cols="70"/>
			<inp2:m_RenderElement name="inp_edit_textarea" prefix="c" field="MetaDescription" title="!la_fld_MetaDescription!" allow_html="0" control_options="{min_height: 50}" rows="4" cols="70"/>
			<inp2:m_RenderElement name="inp_edit_textarea" prefix="c" field="IndexTools" title="!la_fld_TrackingCode!" control_options="{min_height: 50}" allow_html="0"/>

		<inp2:m_RenderElement name="subsection" prefix="c" fields="EnablePageCache,OverridePageCacheKey,PageCacheKey,PageExpiration" title="la_section_PageCaching"/>
			<inp2:m_RenderElement name="inp_edit_checkbox" prefix="c" field="EnablePageCache" title="la_fld_EnablePageCache" onclick="reflectCachingSettings();"/>
			<inp2:m_RenderElement name="inp_edit_checkbox" prefix="c" field="OverridePageCacheKey" title="la_fld_OverridePageCacheKey" onclick="reflectCacheKeyOverride();"/>
			<inp2:m_RenderElement name="inp_edit_box" prefix="c" field="PageCacheKey" title="la_fld_PageCacheKey"/>
			<inp2:m_RenderElement name="inp_edit_box" prefix="c" field="PageExpiration" title="la_fld_PageExpiration" hint_label="la_hint_PageExpiration"/>

		<!-- custom fields: begin -->
		<inp2:m_include t="incs/custom_blocks"/>
		<inp2:cf.general_PrintList render_as="cv_row_block" SourcePrefix="c" value_field="Value" per_page="-1" grid="Default" />
		<!-- custom fields: end -->

		<inp2:m_RenderElement name="inp_edit_filler"/>
	</table>
</div>

<script type="text/javascript">
	function getControl ($field, $appendix, $prepend) {
		var $field_mask = '<inp2:c_InputName field="#FIELD_NAME#"/>';

		$appendix = isset($appendix) ? '_' + $appendix : '';
		$prepend = isset($prepend) ? $prepend + '_' : '';

		return document.getElementById( $prepend + $field_mask.replace('#FIELD_NAME#', $field) + $appendix );
	}

	function reflectMenuIcon() {
		var $menu_icon_url = getControl('MenuIconUrl');
		if ($menu_icon_url) {
			$menu_icon_url.parentNode.parentNode.style.display = getControl('UseMenuIconUrl', null, '_cb').checked ? '' : 'none';
		}
	}

	function reflectExternalUrl() {
		var $external_url = getControl('ExternalUrl');
		if ($external_url) {
			$external_url.parentNode.parentNode.style.display = getControl('UseExternalUrl', null, '_cb').checked ? '' : 'none';
		}
	}

	function OnSystemClick() {
		var cel = getControl('IsSystem', null, '_cb');
		var tel = getControl('Template');

		if (cel) {
			if (cel.checked) {
				cel.setAttribute('old_template', tel.value);
				tel.value='';
				tel.disabled = true;
				tel.readonly = true;
			}
			else {
				var old_template = cel.getAttribute('old_template');
				tel.disabled = false;
				tel.readonly = false;
				if (old_template) {
					tel.value = old_template;
				}
				cel.setAttribute('old_template', '');
			}
		}
	}

	function reflectFilename() {
		var $filename = getControl('Filename');
		if ($filename) {
			var $checked = getControl('AutomaticFilename', null, '_cb').checked;
			$filename.readOnly = $checked;
		}
    }

    function reflectCachingSettings() {
		var $checked = getControl('EnablePageCache', null, '_cb').checked;

		getControl('OverridePageCacheKey', null, '_cb').disabled = !$checked;
		getControl('PageCacheKey').disabled = !$checked || !getControl('OverridePageCacheKey', null, '_cb').checked;
//		getControl('PageExpiration').disabled = !$checked;
    }

    function reflectCacheKeyOverride() {
		var $checked = getControl('OverridePageCacheKey', null, '_cb').checked;
		getControl('PageCacheKey').disabled = !$checked;
    }

    Application.setHook(
    	'c:*',
    	function () {
    		getControl('OverridePageCacheKey', null, '_cb').disabled = false;
			getControl('PageCacheKey').disabled = false;
//			getControl('PageExpiration').disabled = false;
    	}
    );

	$(document).ready(
		function() {
			reflectMenuIcon();
			reflectExternalUrl();
			reflectFilename();
			// OnSystemClick();

			reflectCacheKeyOverride();
			reflectCachingSettings();
		}
	);

	disable_categories('<inp2:c_InputName name="ParentId"/>', <inp2:c_AllowedCategoriesJSON/>);
</script>

<inp2:m_include t="incs/footer"/>