if (FlowBasis.Comments) {
}
else {
	FlowBasis.Comments = new Object();
}

if (FlowBasis.Comments.UI) {
}
else {
	FlowBasis.Comments.UI = new Object();
}

// The CommentControl class is used in conjunction with the server-side CommentControl class.
FlowBasis.Comments.UI.CommentControl = function() {
	this.commentListID = null;
	this.addCommentFormID = null;
}

//TODO: Select a javascript inheritance method.
for (var member in FlowBasis.UI.Control.prototype) {
	FlowBasis.Comments.UI.CommentControl.prototype[member] = FlowBasis.UI.Control.prototype[member];
}


FlowBasis.Comments.UI.CommentControl.prototype.submitNewComment = function() {
	var form = document.getElementById(this.addCommentFormID);			
	var content = form.comment.value;
	
	var additionalData = null;
	if (FlowBasis.user) {
	}
	else {
		additionalData = new Object();
		additionalData.commenterName = form.commenterName.value;				
		additionalData.commenterEmail = form.commenterEmail.value;
	}			

	var self = this;
	
	this.invokeAndWait(
		'addComment',
		[ content, additionalData ],
		function (response) {					
			if (response.error == null) {
				self.clearAddCommentForm();
				self.refreshCommentsList();
			}
		});			
}


FlowBasis.Comments.UI.CommentControl.prototype.clearAddCommentForm = function() {
	var form = document.getElementById(this.addCommentFormID);
	form.comment.value = '';			
	
	if (FlowBasis.user) {
	}
	else {
		additionalData = new Object();
		
		if (form.commenterName) {
			form.commenterName.value = '';
		}
		
		if (form.commenterEmail) {				
			form.commenterEmail.value = '';
		}
	}
}


FlowBasis.Comments.UI.CommentControl.prototype.refreshCommentsList = function() {
	FlowBasis.rpc.updateElement(
		this.commentListID,
		this.rpcUri,
		'getCommentListInnerHtml',
		[],
		null);
}