// For voting blocks
function sendVote(vote, commentId, isContentItem)
{
	var params = 'vote=' + vote + '&id=' + commentId + '&isci=' + isContentItem;

	$.ajax({
	   type: "POST",
	   url: "/user/vote_ajax",
	   data: params,
	   success: function(msg){

		var responseData = JSON.parse(msg);

		document.getElementById('vote' + responseData.id + '_' + responseData.isContentItem).innerHTML = responseData.innerHTML;

	   }
	 });

	return false;
}

// For submit comment block
$(function() {
$("#submitComment").click(function()
{
	var commentText = $('#comment').val();
	var contentItemId = $('#contentItemId').val();
	var loggedInUserId = $('#loggedInUserId').val();

	var whiteSpace = /^[\s]+$/;
	if ( commentText == '' || whiteSpace.test(commentText) )
	{
		alert("You're trying to add an Empty Comment. Please type something and then try again.");
	}
	else
	{
		$("#submitComment").attr("disabled", "true");

		// convert (&, +, =) to string equivs. Needed so URL encoded POST won't choke.
		commentText = commentText.replace(/&/g,"**am**");
		commentText = commentText.replace(/=/g,"**eq**");
		commentText = commentText.replace(/\+/g,"**pl**");

		var params = 'ci=' + contentItemId + '&userid=' + loggedInUserId + '&comment=' + commentText;
		
		$.ajax({
			type: "POST",
			url: "/user/postcomment_ajax",
			data: params,
			success: function(msg){

				var responseData = JSON.parse(msg);

				// Clear the text box
				$('#comment').val('');

				// enable button
				$("#submitComment").removeAttr("disabled");

				//Insert new comment
				var listDiv = document.getElementById('CommentsList');

				var newHTML = responseData + listDiv.innerHTML;

				listDiv.innerHTML = newHTML;

		   }
		 });
	}
	
	return false;
})

});
