/**
 *	Handle comments
**/
var commentId 			= 0;
var inputNode				=	$('newCommentField');
var parentNode			= inputNode.parentNode;
sajax_request_type 	= "POST";


function addComment () {
	if (!inputNode.value)
		return;
		
	x_Comments__newComment(inputNode.value, commentId, commentResult);
}

function commentResult (reply) {
	if (!reply)
		return window.location ="/";
	
	commentId   = reply;
	var comment = inputNode.value;
	
	if (!parentNode)
		return;
	
	clearElement(parentNode);
	parentNode.innerHTML = nl2br(comment, false);
	parentNode.onclick   = editComment;
}


function editComment (event) {
	clearElement(parentNode);
	parentNode.appendChild(inputNode);
}