
function comment(artid) {
    // envoi des données au handler
    $.ajax({
       type: "POST",
       url: "http://www.userstudio.fr/pages/blog/comment.ajax.php",
       async: true,
       data: $("#commentingForm_"+artid).serialize(),
       success: function(msg) {
         if (msg.indexOf("congrats") == -1) {
         	var n = new Date();           // Grab new copy of date
			var s = n.getTime();          // Grab current millisecond #
            $(".commentingCaptcha").attr('src', 'http://www.userstudio.fr/captcha_'+s+'.jpg'); //load new captcha
            $("#commentingForm_"+artid+" #security_code").val(""); //erase only that one
         } else {
            $("#commentingForm_"+artid).remove(); //remove the valid form
         	updateComments(artid, "false"); //reload the comments without the form
         }
         $("#commentingResult_"+artid).html(msg);
       }
    });
}

function updateComments(artid, formbool) {
	$("#comments_"+artid).html("<img src='http://www.userstudio.fr/layout/loading.gif' alt='loading...' />");
	$.ajax({
       type: "GET",
       url: "http://www.userstudio.fr/pages/blog/comments.ajax.php",
       async: false,
       data: "id="+artid+"&updateForm="+formbool,
       success: function(msg) {
			$("#comments_"+artid).html(msg);
       }
    });
}

function showComments(artid) {
	$("#showCommentsButton_"+artid).attr('onclick', '');
	$("#showCommentsButton_"+artid).unbind('click');
	$("#showCommentsButton_"+artid).bind('click', function() {hideComments(artid)});
	$("#articleFooter_"+artid).append("<div class=\"comments\" id=\"comments_"+artid+"\"></div>");
	updateComments(artid, "true");
}

function hideComments(artid) {
	$("#comments_"+artid)
		.slideUp('normal', function() {
			$(this).remove();
			$("#showCommentsButton_"+artid).unbind('click');
			$("#showCommentsButton_"+artid).bind('click', function() {showComments(artid)});
		});
}
