if(typeof parkside == "undefined") var parkside = new Object();
if(typeof parkside.comment == "undefined") parkside.comment = new Object();

// Constructor
parkside.comment = function() {
}

// static variables
parkside.comment.comment_form = null;
parkside.comment.is_reply = false;
	
// static methods
parkside.comment.replyToComment = function (id, username) {
	document.getElementById('parent_id').value = id;
	if(id > 0)
	{
		var text = username + " antworten ";
		text += " <a href='#comment_form' onclick='parkside.comment.replyToComment(0);'>[x]</a><br /><br />";
		document.getElementById('reply_to').innerHTML = text;
	}
	else
	{
		document.getElementById('reply_to').innerHTML = "";
	}
}

parkside.comment.postComment = function(p_comment_form, p_blog_entry_id, p_comment_text, p_parent_id, p_notify_owner) {		
	parkside.comment.comment_form = p_comment_form;
	parkside.comment.is_reply = (p_parent_id != 0);

	var url = "custom/modules/comment/comment.cfc?method=postComment";
	var response_function = parkside.comment.response;
	var params = {
		blog_entry_id: p_blog_entry_id
		, comment_text: p_comment_text
		, parent_id: p_parent_id
		, notify_owner: p_notify_owner
	};
	$.post(url, params, response_function, "json");
}
	
parkside.comment.response = function(cfc_result, status) { 	
	if(cfc_result.ERROR) {
		alert(cfc_result.MESSAGE);
	} else {
		parkside.comment.comment_form.comment_text.value = "";
		parkside.comment.comment_form.parent_id.value = 0;
		
		// jQuery is cool
		if ($(".item_list_paging").length == 0) {
			document.location.reload();
		} else if (parkside.comment.is_reply) {
			$(".item_list_paging .active").trigger("click");
		} else {
			$(".item_list_paging .last").trigger("click");
		}
		//parkside.comment.comment_form.parentNode.innerHTML = cfc_result.MESSAGE;
		
		document.getElementById('reply_to').innerHTML = "";
		alert(cfc_result.MESSAGE);		
	}
}
	
/// Class members
parkside.comment.prototype = {
/// Properties

/// Methods
}

