[TWIG]
<script type="text/javascript">
var cajax = new sack();
function reload_captcha() {
	var captc = document.getElementById('img_captcha');
	if (captc != null) {
		captc.src = "{captcha_url}?rand="+Math.random();
	}
}	

function add_comment(){
	// First - delete previous error message
	var perr;
	if (perr=document.getElementById('error_message')) {
		perr.parentNode.removeChild(perr);
	}

	// Now let's call AJAX comments add
	var form = document.getElementById('comment');
	//cajax.whattodo = 'append';
	cajax.onShow("");[not-logged]
	cajax.setVar("name", form.name.value);
	cajax.setVar("mail", form.mail.value);[captcha]
	cajax.setVar("vcode", form.vcode.value); [/captcha][/not-logged]
	cajax.setVar("content", form.content.value);
	cajax.setVar("newsid", form.newsid.value);
	cajax.setVar("ajax", "1");
	cajax.setVar("json", "1");
	cajax.requestFile = "{post_url}"; //+Math.random();
	cajax.method = 'POST';
	//cajax.element = 'new_comments';
	cajax.onComplete = function() { 
		if (cajax.responseStatus[0] == 200) {
			try {
				var resRX = eval('('+cajax.response+')');
				var nc;
				if (resRX['rev'] && document.getElementById('new_comments_rev')) {
					nc = document.getElementById('new_comments_rev');
				} else {
					nc = document.getElementById('new_comments');
				}
				nc.innerHTML += resRX['data'];				
				if (resRX['status']) { 
					// Added successfully!
					form.content.value = '';
				}
  			} catch (err) { 
				alert('Error parsing JSON output. Result: '+cajax.response); 
			}
		} else {
			alert('TX.fail: HTTP code '+cajax.responseStatus[0]);
		}	
		[captcha] 
		reload_captcha();[/captcha]
	}
	cajax.runAJAX();
}
</script>
<form id="comment" method="post" action="{post_url}" name="form" [ajax]onsubmit="add_comment(); return false;"[/ajax]>
<input type="hidden" name="newsid" value="{newsid}" />
<input type="hidden" name="referer" value="{request_uri}" />
<!--noindex-->
<div class="add-comm-form clearfix add-shadow2" id="add-comm-form">
	<div class="ac-title">{{ lang.theme.comments_add_title }} <span class="fa fa-chevron-down"></span></div>
	[not-logged]
		<div class="ac-soc" data-label="{{ lang.theme.comments_soc_title }}">
			<a href="#" target="_blank"><img src="{tpl_url}/images/social/vk.png" /></a>
			<a href="#" target="_blank"><img src="{tpl_url}/images/social/ok.png" /></a>
			<a href="#" target="_blank"><img src="{tpl_url}/images/social/fb.png" /></a>
			<a href="#" target="_blank"><img src="{tpl_url}/images/social/mail.png" /></a>
			<a href="#" target="_blank"><img src="{tpl_url}/images/social/google.png" /></a>
			<a href="#" target="_blank"><img src="{tpl_url}/images/social/yandex.png" /></a>
		</div>
		<div class="ac-inputs flex-row">
			<input type="text" maxlength="35" name="name" value="{savedname}" placeholder="{{ lang.theme.comments_name }}" />
			<input type="text" maxlength="35" name="mail" value="{savedmail}" placeholder="{{ lang.theme.comments_email }}" />
		</div>
	[/not-logged]
	<div class="ac-textarea"><div class="bb-editor">{bbcodes}<textarea onkeypress="if(event.keyCode==10 || (event.ctrlKey && event.keyCode==13)) {add_comment();}" name="content" id="content"></textarea></div></div>
	[captcha]
		<div class="ac-protect">
			<div class="form-item clearfix imp">
				<label>{{ lang.theme.captcha_title }}</label>
				<div class="form-secur">
					<input type="text" name="vcode" placeholder="{{ lang.theme.captcha_text }}" maxlength="45" required /><img id="img_captcha" onclick="reload_captcha();" src="{captcha_url}?rand={rand}" alt="captcha" style="background: #fff; cursor: pointer; width:120px; height:40px;" />
				</div>
			</div>
		</div>
	[/captcha]
	<div class="ac-submit clearfix">
		<div class="ac-av img-box" id="ac-av"></div>
		<button type="submit">{{ lang.theme.comments_button }}</button>
	</div>
</div>
<!--/noindex-->
</form>
[/TWIG]