	$(document).ready(
  	function(){
  		$('input.postComment').bind('click', postComment);
	 	$('input.resetComment').bind('click', resetComment);

  	}
  );
  var resetComment = function (e) {
  		$('#user_comment_name').removeAttr("readonly");
  		$('#user_comment').removeAttr("readonly");
  		$('#commentButtonSubmit').show();
	   	$('#commentButtonReset').hide();
	   	$('#sendComment').hide();

  }
  var postComment = function (e) {
  	$('#messageComment').hide();
	$('#user_comment_name').attr('readonly', 'readonly');
	$('#user_comment').attr('readonly', 'readonly');
	$('#user_comment_email').attr('readonly', 'readonly');
	$('#sec_code').attr('readonly', 'readonly');
  	$("#loading_comment").show();
	$('#sendComment').hide();

	$.ajax({
	   type: "POST",
	   url: "/ajax.php",
	   data: "action=addcomment&controller=guestbook&"+$.param( $("#commentForm").formToArray() ),
	   dataType: "json",
	   success: function(msg) {
	   		var message = '';
	   		if (msg.error) {
	    		for(i=0;i<msg.error.length;i++) 
	   				message += msg.error[i] + '<br />';
	   			$('#messageComment').html(message).show();
		  		$('#user_comment_name').removeAttr("readonly");
		  		$('#user_comment').removeAttr("readonly");
		  		$('#user_comment_email').removeAttr("readonly");
		  		$('#sec_code').removeAttr("readonly");
				$('img.sec_code_img').attr('src', '/captcha.php&id='+msg.captchatry);
	   		}
	   		if (msg.saved == 1) {
	   			$('#messageComment').hide();
	   			$('#sendComment').css('color', '#688000').html('&nbsp;<b>Wpis zapisany!<\/b>').fadeIn('slow');
	   			$('#commentButtonSubmit').hide();
	   			$('#commentButtonReset').show();

	   		}
	   		if (msg.send == 0) {
	   			$('#messageComment').hide();
	   			$('#send').css('color', '#f00').html('&nbsp;<b>Błąd podczas zapisu!<\/b>').fadeIn('slow');
			 	$('#user_comment_name').removeAttr("readonly");
			 	$('#user_comment').removeAttr("readonly");
			 	$('#user_comment_email').removeAttr("readonly");
			 	$('#sec_code').removeAttr("readonly");
	   		}
	   },
	   complete: function() {
	   		$("#loading_comment").hide();
	   }
	 });
  }
  
  $(document).ready(
  	function(){
  		$('a.comment-info-more').bind('click', showComment);
		$('a.comment-info-less').bind('click', hideComment);
  	}
  );
  var showComment = function(e) {
  	comment = ($(this).parent());
  	comment.toggle();
  	$("#"+comment.attr('id')+'_long').toggle();
  }
  var hideComment = function(e) {
  	comment = ($(this).parent());
  	comment.toggle();
  	$("#"+comment.attr("id").replace("_long", "")).toggle();
  }
