[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}" />
<div class="clr"></div>
<h2 class="section_name">{{ lang.theme.addcomment }}</h2>
<div class="full_content" style="margin-bottom: 0px;">
	<div id="addcomment" class="addcomment">
		<div class="box_in">
			<ul class="ui-form">
				[not-logged]
					<li class="form-group combo">
						<div class="combo_field"><input placeholder="{{ lang.theme.your_name }}" type="text" name="name" value="{savedname}" class="wide" required></div>
						<div class="combo_field"><input placeholder="{{ lang.theme.your_email }}" type="email" name="mail" value="{savedmail}" class="wide"></div>
					</li>
				[/not-logged]
				<li style="margin-bottom: 30px;">
					<div class="bb-editor">{bbcodes}<textarea onkeypress="if(event.keyCode==10 || (event.ctrlKey && event.keyCode==13)) {add_comment();}" name="content" rows="5" id="content"></textarea></div>
				</li>
				[captcha]
					<li class="c-captcha" style="margin-bottom: 30px;">
						<span><img id="img_captcha" onclick="reload_captcha();" src="{captcha_url}?rand={rand}" alt="captcha" style="background: #fff; border: 1px solid #dde4ea;" /></span>
						<input placeholder="{{ lang.theme.code }}" title="{{ lang.theme.code_info }}" type="text" name="vcode" required>
					</li>
				[/captcha]
			</ul>
			<div class="form_submit">
				<button class="btn btn-big" type="submit" title="{{ lang.theme.comments_btn }}"><b>{{ lang.theme.comments_btn }}</b></button>
			</div>
		</div>
	</div>
</div>
</form>
[/TWIG]