function submit_comment(owner_id,owner_type) {
	if ($('#comment').val() == '') {
		$('#comment').addClass('error_form');
		$('#comment_error').show();
		return false;
	} else {
		$('#comment').removeClass('error_form');
		$('#comment_error').hide();
	}
	
	$('#comment').hide();
	$('#button_div_submit_comment').hide();
	$('#ajax').show();
		
	params = new Object();
	params.owner_type = owner_type;
	params.comment = $('#comment').val();
	params.owner_id = owner_id;
	params.user_id = user_id;
	action('modules_comments_actions_add', params);
}

var comment_add_count = 0;

function modules_comments_actions_add_complete(response){
	comment_add_count++;
	
	var html='';
	html +=	'<div style="position:relative;padding:10px;';
	if (comment_add_count % 2==1) {
		html += 'background-color:#f5f5f5;';
	}
	html += '">';
	html +=	'<a href="/profil/'+$('#login_owner').html()+'/"><img src="'+$('#img_owner')[0].src+'" style="position:absolute;border:0;"/></a>';
	html +=	'<a href="/profil/'+$('#login_owner').html()+'/" style="text-decoration:none;font-size:18px;font-weight:bold;padding-left:80px;">'+$('#login_owner').html()+'</a><span style="margin-left:10px;font-weight:bold;">(Dodano teraz)</span><br/>';
	html +=	'<div name="comment" style="position:relative;margin-top:5px;padding-left:80px" class="html">'+response.data+'</div>';
	html +=	'<br clear="all"/>';
	html +=	'</div>';
	var comment_count = parseInt($('#count_comment').html());
	$('#count_comment').html(comment_count+1);
	$('#comment_form').hide();
	$('#comment_add').show();
	$('#comments').html(html+$('#comments').html()).show();
	$('#comment').show();
	$('#button_div_submit_comment').show();
	$('#ajax').hide();
}

function modules_comments_actions_add_error(response) {
	$('#comment').addClass('error_form');
	if (response.data.no) {
		if (response.data.no==102) {
		var text = 'Twój komentarz nie może być pusty.';
		} else {
		var text = 'Twoja sesja utraciła wżność, zaloguj się ponownie.';
		}
	} else {
		var text = response.data.comment.info;
	}
	$('#comment_error').html(text);
	$('#comment_error').show();
	$('#comment').show();
	$('#button_div_submit_comment').show();
	$('#ajax').hide();
}

function comment_box_show() {
	$('#comment_form').show();
	$('#f_comments_limit').html("1000");
	$('#comment_add').hide();
	$('#comment').val('');
}

function count_letters() {
	var ile = 1000-$('#comment').val().length;
	if(0>ile) {
		$('#comment').html($('#comment').val().substring(0,1000));
		ile=1000-$('#comment').val().length;
		alert('Wprowadzony tekst jest za długi');
	}
	$('#f_comments_limit').html(ile);
	return true;
};

function over_comment(id) {
	$('#comment_'+id).removeClass('b75');
	$('#comment_'+id).removeClass('b99');	
	$('#comment_'+id).addClass('comments_over');
}

function out_comment(id,typ) {
	$('#comment_'+id).removeClass('comments_over');
	$('#comment_'+id).addClass('b99');
}

function delete_comment(numer,owner_id,owner_type) {
	params = new Object();
	params.numer = numer;
	params.owner_id = owner_id;
	params.owner_type = owner_type;
	if (confirm('Czy napewno chesz usunąć ten komentarz?')) {
		action('modules_comments_actions_del', params);
	}
}

function modules_comments_actions_del_complete(response){
	$('#comment_'+response.data.numer).slideUp();
	$('#count_comment').html($('#count_comment').html()-1);
}

function modules_comments_actions_del_error(response){
	if (response.data.no==1) {
		window.alert('Nie możesz usunąć tego komentarza, ponieważ mineło ponad 15 minut od jego napisania.');
	} else {

	}
}