function vote(definition_id, vote) {

	$.ajax({
		type: "GET",
		url: "/vote/",
		data: {
			definition_id: definition_id,
			vote: vote,
			format: "json"
		},
		dataType: "json",
		/*error: function (a, b, c) {
			window.alert(a.responseText);
		},*/
		success: function (result) {
			var definition_div = "#definition-" + definition_id;

			if (result.success) {
				$(definition_div + " .votes_up").html(result.ups);
				$(definition_div + " .votes_down").html(result.downs);

				var str = $(definition_div + " .thumb_up a").html();
				$(definition_div + " .thumb_up").html(str);
				str = $(definition_div + " .thumb_down a").html();
				$(definition_div + " .thumb_down").html(str);

				if (vote == "up") {
					$(definition_div + " .thumb_down img").attr("src", "/css/thumbsdown-gray.png");
				} else {
					$(definition_div + " .thumb_up img").attr("src", "/css/thumbsup-gray.png");
				}
			}

			if (result.message != "") {
				$(definition_div + " .message").html(result.message);
			}
		}
	});

	return false;
}

function addCommentForm(definition_id, parent_id, container, redirect_to) {
	var toShow = $("#" + container);

	text = '<form method="POST" class="commentform" action="/comment/post/?redirect_to=' + redirect_to + '">';
	text += '<input type="hidden" name="comment[definition_id]" value="' + definition_id + '" />';
	text += '<input type="hidden" name="comment[parent_id]" value="' + parent_id + '" />';
	text += '<table>';
	text += '<tr><td>';
	text += 'Hozzászólás:';
	text += '</td></tr>';
	text += '<tr><td><textarea name="comment[message]" class="commentbox" id="commentbox' + parent_id + '"></textarea>';
	text += '</td></tr>';
	text += '<tr><td align="right">';
	text += '<input type="submit" value="küldd" />';
	text += ' <input type="button" value="mégse" onClick="cancelComment(\'' + container + '\');" />';
	text += '</td></tr>';
	text += '</table>';
	text += '</form>';

	toShow.html(text);
}

function cancelComment(container) {
	var toHide = $("#" + container);

	toHide.html("");
}

