if (!defaultAjax) {
	var defaultAjax = 0;
}

jQuery(document).ready(function() { 
	updateCommentsFormJS();
}); 

function showResponse(response, status) {
	if (response != "FALSE") {
		jQuery("#comments-list p.no-comments").remove();
		jQuery("#comments-wrapper").prepend(response);
		updateCommentsJS();
		updateCaptcha();

	}

	window.location.hash = "comments-top";                
}

function updateCommentsFormJS() {
	var options = {
		success:			showResponse,
		resetForm:			true,
		dataType:			"http"
	} 

	jQuery("#new-comment-form input[name='ajax']").attr('value', defaultAjax);

	jQuery("#comments-form form").submit(function() { 
		if (!defaultAjax) {
			return true;
		}

		jQuery(this).ajaxSubmit(options); 

		return false; // musime vratit false, aby se formular neodeslal
	}); 

	if (jQuery("#markitup.markItUpEditor").length === 1) {
        jQuery('#markitup').markItUpRemove();
	}
	jQuery('#markitup').markItUp(mySettings);

	updateCaptcha();
}

function updateCaptcha(){
	jQuery.getJSON("/sys_files/js/noncaptcha.php?callback=?", hideCaptcha);
}

function hideCaptcha(code) {
	var code = code[0];
	if (code == 'FALSE') {
		return false;
	}
	
	jQuery("#comments-form .test").remove();
	jQuery("#comments-form form input[name='captcha']").remove();
	jQuery("#comments-form form").append('<input type="hidden" name="captcha" value="' + code + '" />');
}

