[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>
<div class="post">
	<form id="comment" method="post" action="{post_url}" class="form newtopic" name="form" [ajax]onsubmit="add_comment(); return false;" [/ajax]>
		<input type="hidden" name="newsid" value="{newsid}"/>
		<input type="hidden" name="referer" value="{request_uri}"/>
		<div class="topwrap">
			<div class="userinfo pull-left"></div>
			<div class="posttext pull-left">
				[not-logged]
					<div class="card">
						<label>{{ lang.theme.your_name }}:</label>
						<input type="text" name="name" value="{savedname}" class="form-control" />
						<label>{{ lang.theme.your_email }}:</label>
						<input type="text" name="mail" value="{savedmail}" class="form-control" />
					</div>
				[/not-logged]
				<div class="bb-editor">
					{bbcodes}
					<textarea onkeypress="if(event.keyCode==10 || (event.ctrlKey && event.keyCode==13)) {add_comment();}" name="content" id="content" class="form-control"></textarea>
				</div>
				[captcha]
					<div>
						<label>{{ lang.theme.code }}:</label>
						<div><span><img id="img_captcha" onclick="reload_captcha();" src="{captcha_url}?rand={rand}" style="background: #fff; cursor: pointer;" alt="Security code" width="120" height="40" /></span></div>
						<div><input type="text" name="vcode" id="captcha" style="width:120px" class="form-control"></div>
					</div>
				[/captcha]
			</div>
			<div class="clearfix"></div>
		</div>
		<div class="postinfobot">
			<div class="pull-right postreply">
				<div class="pull-left"><button type="submit" class="btn btn-primary">{{ lang.theme.comments_btn }}</button></div>
				<div class="clearfix"></div>
			</div>
			<div class="clearfix"></div>
		</div>
	</form>
</div>
[/TWIG]
