<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_if check="c_PageEditable">
				<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_else/>
				<inp2:m_RenderElement name="inp_label" prefix="c" field="Filename" title="la_fld_Filename"/> <!-- la_fld_CategoryFilename -->
			</inp2:m_if>

			<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,Type,Protected" 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_if check="m_IsDebugMode">
				<inp2:m_RenderElement name="inp_edit_radio" prefix="c" field="Type" title="la_fld_Type" onclick="reflectPageType();"/>
			<inp2:m_else/>
				<inp2:m_RenderElement name="inp_label" prefix="c" field="Type" title="la_fld_Type"/>
			</inp2:m_if>

			<inp2:m_DefineElement name="template_caption_element">
				<label for="<inp2:m_param name='NamePrefix'/><inp2:{$prefix}_InputName field='$field'/>">
					<span class="<inp2:m_if check='{$prefix}_HasError' field='$field'>error-cell</inp2:m_if>" id="template_title"><inp2:m_if check="m_Param" name="title"><inp2:m_phrase label="$title"/></inp2:m_else/><inp2:m_Param name="title_text"/></inp2:m_if></span></span><inp2:m_if check="{$prefix}_IsRequired" field="$field"><span class="field-required">&nbsp;*</span></inp2:m_if>:<inp2:m_if check="m_Param" name="hint_label"><span>&nbsp;<img src="<inp2:m_TemplatesBase/>/img/hint_icon.png" width="12" height="13" title="<inp2:m_Phrase label='$hint_label' html_escape='1'/>" alt="<inp2:m_Phrase label='$hint_label' html_escape='1'/>"/></inp2:m_if>
				</label>
			</inp2:m_DefineElement>

			<inp2:m_RenderElement design="form_row" caption_render_as="template_caption_element" prefix="c" field="Template" title="la_fld_TemplateFile">
				<td class="control-cell">
					<span id="<inp2:$prefix_InputName field='$field'/>_label">
						<inp2:{$prefix}_Field field="$field"/>
					</span>

					<input style="width: 100%; display: none;" type="text" id="<inp2:{$prefix}_InputName field='$field'/>_textbox" value="<inp2:{$prefix}_Field field='$field' db='db'/>" tabindex="<inp2:m_get param='tab_index'/>"/>

					<select style="display: none;" tabindex="<inp2:m_get param='tab_index'/>" id="<inp2:{$prefix}_InputName field='$field'/>_dropdown">
						<inp2:{$prefix}_PredefinedOptions field="$field" block="inp_option_item" selected="selected" has_empty="1"/>
					</select>

					<input type="hidden" name="<inp2:{$prefix}_InputName field='$field'/>" id="<inp2:{$prefix}_InputName field='$field'/>" value="<inp2:{$prefix}_Field field='$field'/>"/>

					<script type="text/javascript">
						$(document).ready(
							function () {
								var $field_mask = '<inp2:$prefix_InputName name="#FIELD_NAME#" js_escape="1"/>';

								$( get_control($field_mask, '<inp2:m_Param name="field"/>', 'textbox') ).keyup(
									function ($e) {
										$( get_control($field_mask, '<inp2:m_Param name="field"/>') ).val( $(this).val() );
									}
								);

								$( get_control($field_mask, '<inp2:m_Param name="field"/>', 'dropdown') ).change(
									function ($e) {
										var $value = $(this).val();

										$( get_control($field_mask, '<inp2:m_Param name="field"/>') ).val($value);
										$( get_control($field_mask, '<inp2:m_Param name="field"/>', 'textbox') ).val($value);
									}
								);
							}
						);
					</script>
				</td>
			</inp2:m_RenderElement>

			<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_if check="m_IsDebugMode">
				<inp2:m_RenderElement name="inp_edit_checkbox" prefix="c" field="Protected" title="la_fld_Protected"/>
			<inp2:m_else/>
				<inp2:m_RenderElement name="inp_label" prefix="c" field="Protected" title="la_fld_Protected"/>
			</inp2:m_if>

		<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_if check="c_PageEditable">
				<inp2:m_RenderElement name="inp_edit_radio" prefix="c" field="Status" title="la_fld_Status"/>
			<inp2:m_else/>
				<inp2:m_RenderElement name="inp_label" prefix="c" field="Status" title="la_fld_Status"/>
			</inp2:m_if>

			<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">
	var $field_mask = '<inp2:c_InputName name="#FIELD_NAME#" js_escape="1"/>';

	<inp2:m_if check="c_FieldsVisible" fields="UseMenuIconUrl,MenuIconUrl">
		function reflectMenuIcon() {
			var $use = get_control($field_mask, 'UseMenuIconUrl', undefined, '_cb').checked;
			get_control($field_mask, 'MenuIconUrl', 'row').style.display = $use ? '' : 'none';
		}

		$(document).ready(reflectMenuIcon);
	</inp2:m_if>

	<inp2:m_if check="c_FieldsVisible" fields="UseExternalUrl,ExternalUrl">
		function reflectExternalUrl() {
			var $use = get_control($field_mask, 'UseExternalUrl', undefined, '_cb').checked;
			get_control($field_mask, 'ExternalUrl', 'row').style.display = $use ? '' : 'none';
		}

		$(document).ready(reflectExternalUrl);
	</inp2:m_if>

	<inp2:m_if check="c_FieldsVisible" fields="AutomaticFilename,Filename">
		function reflectFilename() {
			if ( get_control($field_mask, 'AutomaticFilename') ) {
				var $checked = get_control($field_mask, 'AutomaticFilename', undefined, '_cb').checked;
				get_control($field_mask, 'Filename').readOnly = $checked;
			}
	    }

	    $(document).ready(reflectFilename);
    </inp2:m_if>

    <inp2:m_if check="c_FieldsVisible" fields="EnablePageCache,OverridePageCacheKey,PageCacheKey,PageExpiration">
	    function reflectCachingSettings() {
			var $override = get_control($field_mask, 'OverridePageCacheKey', undefined, '_cb');
	    	var $checked = get_control($field_mask, 'EnablePageCache', undefined, '_cb').checked;

			$override.disabled = !$checked;
			get_control($field_mask, 'PageCacheKey').disabled = !$checked || !$override.checked;
//			get_control($field_mask, 'PageExpiration').disabled = !$checked;
	    }

	    function reflectCacheKeyOverride() {
			var $checked = get_control($field_mask, 'OverridePageCacheKey', undefined, '_cb').checked;
			get_control($field_mask, 'PageCacheKey').disabled = !$checked;
	    }

	    $(document).ready(reflectCachingSettings);
	    $(document).ready(reflectCacheKeyOverride);
    </inp2:m_if>

    <inp2:m_if check="c_FieldsVisible" fields="Type,Template">
	    function reflectPageType() {
	    	// get page type
	    	<inp2:m_if check="m_IsDebugMode">
	    		var $page_type = $("input[name='" + jq($field_mask.replace('#FIELD_NAME#', 'Type')) + "']:checked").val();
			<inp2:m_else/>
				var $page_type = '<inp2:c_Field name="Type" db="db"/>';
			</inp2:m_if>

			// page type specific data (0 - title, 1 - visible control, 2 - hidden control)
			var $data = {
				'1': ['<inp2:m_Phrase name="la_fld_TemplateType" js_escape="1"/>', 'dropdown', 'textbox'],
				'2': ['<inp2:m_Phrase name="la_fld_TemplateFile" js_escape="1"/>', 'textbox', 'dropdown']
			};

			// update field title according to page type
			fields['c']['Template'] = $data[$page_type][0]; // for error message
			$('#template_title').html($data[$page_type][0]); // for form label

			<inp2:m_ifnot check="m_IsDebugMode">
				<inp2:m_if check="c_Field" name="Protected" db="db">
					return ;
				</inp2:m_if>
			</inp2:m_ifnot>

			// display control, matching page type
			$( get_control($field_mask, 'Template', 'label') ).hide();
			var $template_source = $( get_control($field_mask, 'Template', $data[$page_type][1]) );

			$( get_control($field_mask, 'Template') ).val( $template_source.show().val() );
			$( get_control($field_mask, 'Template', $data[$page_type][2]) ).hide();
	    }

	    $(document).ready(reflectPageType);
	</inp2:m_if>

    Application.setHook(
    	'c:*',
    	function () {
    		$(':input:disabled', '#' + $form_name).attr('disabled', '');
    	}
    );

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

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