<script language="javascript" type="text/javascript">

	//
	// Global variable: ID of current active input area
		{% if (flags.edit_split) %}var currentInputAreaID = 'ng_news_content_short';
		{% else %}var currentInputAreaID = 'ng_news_content';{% endif %}

	function preview() {
		var form = document.getElementById("postForm");
		if (form.ng_news_content{% if (flags.edit_split) %}_short{% endif %}.value == '' || form.title.value == '') {
			alert('{{ lang.nsm['err.preview'] }}');
			return false;
		}

		form['mod'].value = "preview";
		form.target = "_blank";
		form.submit();

		form['mod'].value = "news";
		form.target = "_self";
		return true;
	}

	function changeActive(name) {
		if (name == 'full') {
			document.getElementById('container.content.full').className = 'contentActive';
			document.getElementById('container.content.short').className = 'contentInactive';
			currentInputAreaID = 'ng_news_content_full';
		} else {
			document.getElementById('container.content.short').className = 'contentActive';
			document.getElementById('container.content.full').className = 'contentInactive';
			currentInputAreaID = 'ng_news_content_short';
		}
	}
</script>


<form name="DATA_tmp_storage" action="" id="DATA_tmp_storage">
	<input type=hidden name="area" value=""/>
</form>
<div class="post">
	<form name="form" ENCTYPE="multipart/form-data" method="post" class="newtopic" action="{{ php_self }}" id="postForm">
		<input type="hidden" name="token" value="{{ token }}"/>
		<input type="hidden" name="mod" value="news"/>
		<input type="hidden" name="action" value="edit"/>
		<input type="hidden" name="subaction" value="submit"/>
		<div class="postinfotop">
			<h2>{{ lang.nsm['editnews_title'] }}: [ <a role="button" href="{{ listURL }}">{{ lang.nsm['news.list'] }}</a> ]</h2>
		</div>
		<div class="accsection">
			<div class="topwrap">
				<div class="card">
					<div>
						<label>{{ lang.nsm['newstitle'] }}</label>
						<input type="text" name="title" value="{{ title }}" class="form-control" />
					</div>
					<div>
						<label>{{ lang.nsm['alt_name'] }}</label>
						<input type="text" name="alt_name" value="{{ alt_name }}" {% if flags['altname.disabled'] %}disabled="disabled" {% endif %} class="form-control" />
					</div>
					<div>
						<label>{{ lang.nsm['category'] }}</label>
						<div>{{ mastercat }}</div>
					</div>
					{% if flags['multicat.show'] %}
						<div>
							<label>{{ lang.nsm['dop.categories'] }}</label>
							<div style="overflow:auto;max-height:100px;margin-bottom:10px">{{ extcat }}</div>
						</div>
					{% endif %}
					{% if (flags.edit_split) %}
						<div>
							<label>{{ lang.nsm['news.anons'] }}</label>
							<div class="bb-editor">
								{{ quicktags }}
								<textarea onclick="changeActive('short');" onfocus="changeActive('short');" name="ng_news_content_short" id="ng_news_content_short" rows="5" class="form-control">{{ content.short }}</textarea>
							</div>
						</div>
						{% if (flags.extended_more) %}
							<div>
								<label>{{ lang.nsm['news.more'] }}</label>
								<input type="text" name="content_delimiter" value="{{ content.delimiter }}" class="form-control" />
							</div>
						{% endif %}
						<div>
							<label>{{ lang.nsm['full.news'] }}</label>
							<div class="bb-editor">
								{{ quicktags }}
								<textarea onclick="changeActive('full');" onfocus="changeActive('full');" name="ng_news_content_full" id="ng_news_content_full" rows="5" class="form-control">{{ content.full }}</textarea>
							</div>
						</div>
					{% else %}
						<div>
							<div class="bb-editor">
								{{ quicktags }}
								<textarea name="ng_news_content" id="ng_news_content" rows="10" class="form-control">{{ content.short }}</textarea>
							</div>
						</div>
					{% endif %}
					<div>
						{% if not flags['mainpage.disabled'] %}
							<div><input type="checkbox" name="mainpage" value="1" id="mainpage" {% if (flags.mainpage) %}checked="checked" {% endif %}{% if flags['mainpage.disabled'] %}disabled {% endif %}  /> {{ lang.nsm['mainpage'] }}</div>
						{% endif %}
						{% if not flags['pinned.disabled'] %}
							<div><input type="checkbox" name="pinned" value="1" id="pinned" {% if (flags.pinned) %}checked="checked" {% endif %}{% if flags['pinned.disabled'] %}disabled {% endif %}  /> {{ lang.nsm['add_pinned'] }}</div>
						{% endif %}
						{% if not flags['catpinned.disabled'] %}
							<div><input type="checkbox" name="catpinned" value="1" id="catpinned" {% if (flags.catpinned) %}checked="checked" {% endif %}{% if flags['catpinned.disabled'] %}disabled {% endif %}  /> {{ lang.nsm['add_catpinned'] }}</div>
						{% endif %}
						{% if not flags['favorite.disabled'] %}
							<div><input type="checkbox" name="favorite" value="1" id="favorite" {% if (flags.favorite) %}checked="checked" {% endif %}{% if flags['favorite.disabled'] %}disabled {% endif %}  /> {{ lang.nsm['add_favorite'] }}</div>
						{% endif %}
						{% if not flags['html.disabled'] %}
							<div><input name="flag_HTML" type="checkbox" id="flag_HTML" value="1" {% if (flags['html.disabled']) %}disabled {% endif %}{% if flags['html'] %}checked="checked"{% endif %} /> {{ lang.nsm['flag_html'] }}</div>
							<div><input type="checkbox" name="flag_RAW" value="1" id="flag_RAW" {% if (flags['html.disabled']) %}disabled {% endif %}{% if flags['html'] %}checked="checked"{% endif %}  /> {{ lang.nsm['flag_raw'] }}</div>
						{% endif %}
					</div>
					{% if flags['params.lost'] %}
						<div class="alert alert-warning">
							<div>{{ lang.nsm['msge_perm_no'] }}.<br/>{{ lang.nsm['msge_rand'] }}:</div>
							{% if flags['publish.lost'] %}<div>&#8594;{{ lang.nsm['news.no_pub'] }}</div>{% endif %}
							{% if flags['html.lost'] %}<div>&#8594;{{ lang.nsm['news.no_tag'] }}</div>{% endif %}
							{% if flags['mainpage.lost'] %}<div>&#8594;{{ lang.nsm['news.no_main'] }}</div>{% endif %}
							{% if flags['pinned.lost'] %}<div>&#8594;{{ lang.nsm['news.no_home'] }}</div>{% endif %}
							{% if flags['catpinned.lost'] %}<div>&#8594;{{ lang.nsm['news.no_cat'] }}</div>{% endif %}
							{% if flags['favorite.lost'] %}<div>&#8594;{{ lang.nsm['news.no_bookmarks'] }}</div>{% endif %}
							{% if flags['multicat.lost'] %}<div>&#8594;{{ lang.nsm['news.no_dopcat'] }}</div>{% endif %}
						</div>
					{% endif %}
					<div class="row">
						<div class="col-lg-4 col-md-4 alert alert-info">
							{% if (approve == -1) %}
								{{ lang.nsm['state.draft'] }}
							{% elseif (approve == 0) %}
								{{ lang.nsm['state.unpublished'] }}
							{% else %}
								{{ lang.nsm['state.published'] }}
							{% endif %}
						</div>
						<div class="col-lg-4 col-md-4">
							<select size="1" name="approve" id="approve" class="form-control">
								{% if flags.can_draft %}<option value="-1" {% if (approve == -1) %}selected="selected"{% endif %}>{{ lang.nsm['state.draft'] }}</option>{% endif %}
								{% if flags.can_unpublish %}<option value="0" {% if (approve == 0) %}selected="selected"{% endif %}>{{ lang.nsm['state.unpublished'] }}</option>{% endif %}
								{% if flags.can_publish %}<option value="1" {% if (approve == 1) %}selected="selected"{% endif %}>{{ lang.nsm['state.published'] }}</option>{% endif %}
							</select>
						</div>
					</div>
					<div class="postinfobot">
						<input type="hidden" name="id" value="{{ id }}" />
						{% if flags.editable %}
							<button class="btn btn-success" onclick="return approveMode(-1);" type="submit">{{ lang.nsm['news.edit.save'] }}</button>
						{% endif %}
						<button class="btn btn-primary" onclick="preview();" type="button">{{ lang.nsm['preview'] }}</button>
						{% if flags.deleteable %}
							<button class="btn btn-danger" type="button" onClick="confirmit('{{ deleteURL }}', '{{ lang.nsm['sure_del'] }}')">{{ lang.nsm['news.del'] }}</button>
						{% endif %}
					</div>
				</div>
				<div class="clearfix"></div>
			</div>
		</div>
	</form>
</div>
<script language="javascript" type="text/javascript">
	// Restore variables if needed
	var jev = {{ JEV }};
	var form = document.getElementById('postForm');
	for (i in jev) {
		//try { alert(i+' ('+form[i].type+')'); } catch (err) {;}
		if (typeof(jev[i]) == 'object') {
			for (j in jev[i]) {
				//alert(i+'['+j+'] = '+ jev[i][j]);
				try {
					form[i + '[' + j + ']'].value = jev[i][j];
				} catch (err) {
					;
				}
			}
		} else {
			try {
				if ((form[i].type == 'text') || (form[i].type == 'textarea') || (form[i].type == 'select-one')) {
					form[i].value = jev[i];
				} else if (form[i].type == 'checkbox') {
					form[i].checked = (jev[i] ? true : false);
				}
			} catch (err) {
				;
			}
		}
	}
</script>