/**
 * @ 回复
 * @param authorId		评论者 ID
 * @param commentId		评论 ID
 * @param commentBox	评论输入框 ID
 */
function reply(authorId, commentId, commentBox) {
	// 评论者名字
	var author = document.getElementById(authorId).innerHTML;
	// 拼接成 '@评论者名字' 链接
	var insertStr = '<a href="#' + commentId + '">@' + author.replace(/\t|\n/g, "") + '</a> \n';
 
	// 追加到评论输入框
	appendReply(insertStr, commentBox);
}

/**
 * 追加到输入框
 * @param insertStr		追加字符串
 * @param commentBox	评论输入框 ID
 */
function appendReply(insertStr, commentBox) {
	if(document.getElementById(commentBox) && document.getElementById(commentBox).type == 'textarea') {
		field = document.getElementById(commentBox);

	} else {
		alert("The comment box does not exist!");
		return false;
	}

	if (field.value.indexOf(insertStr) > -1) {
		alert("You've already appended this reply!");
		return false;
	}

	if (field.value.replace(/\s|\t|\n/g, "") == '') {
		field.value = insertStr;
	} else {
		field.value = field.value.replace(/[\n]*$/g, "") + '\n\n' + insertStr;
	}
	field.focus();
}