Comment_viewer = {
	showTree: function(data) {
//alert('showTree:\n' + data.html);
		document.getElementById('comments-load').innerHTML = '';
		var o = document.getElementById('comment' + data.node_id);
		if (data.node_id == 0) {
			o = document.getElementById('comments-area');	
		} else {
			o = document.getElementById('comment' + data.node_id);	
		}
		if (o) {
			if (data.mode == 'replace') {
				o.innerHTML = data.html;
			} else {
				o.innerHTML += data.html;
			}
		}
	},

	changeCommentText: function (data) {
		document.getElementById('comments-load').innerHTML = '';
		var o = document.getElementById('comment-text' + data.node_id);
		if (o) {
			o.innerHTML = data.text;
		}
	}, 

	updateComment: function () {
		var o = document.comment_form;
		if (o) {
			var parent_id = o.parent_id.value;
			var node_id = o.node_id.value;
			var text = o.text.value;
			if (text == '') {
				alert('Введите текст комментария.');
			} else {
				xajax.call('Comment_updateComment', [node_id, parent_id, text]);
				o.text.value = '';
			}
		}
		var f = document.getElementById('comments-form');
		f.parentNode.removeChild(f);
		document.getElementById('comments-form-area').appendChild(f);
	},



	reply: function(id) {
		var o = document.getElementById('comment' + id);
		var f = document.getElementById('comments-form');
		if (o && f) {
			f.parentNode.removeChild(f);
			var node = o.firstChild;
			while (node && node.className != 'comment-content') {
				node = node.nextSibling;
			}
			if (node) {
				if (node.nextSibling) {
					o.insertBefore(f, node.nextSibling);
				} else {
					o.appendChild(f);
				}
			}
			document.comment_form.parent_id.value = id;
			document.comment_form.node_id.value = 0;
			f.style.marginLeft = '20px';
			document.comment_form.text.value = '';
		}
	},

	rollback: function() {
		var o = document.comment_form;
		if (o) {
			o.parent_id.value = 0;
			o.node_id.value = 0;
			o.text.value = '';
		}
		var f = document.getElementById('comments-form');
		f.parentNode.removeChild(f);
		f.style.marginLeft = '0px';
		document.getElementById('comments-form-area').appendChild(f);
	},

	editComment: function(id) {
		var o = document.getElementById('comment' + id);
		var f = document.getElementById('comments-form');
		if (o && f) {
			document.comment_form.parent_id.value = 0;
			document.comment_form.node_id.value = id;
			document.comment_form.text.value = document.getElementById('comment-text'+id).innerHTML.replace(/<br\/?>\n?/gi,"\n");

			f.parentNode.removeChild(f);
			f.style.marginLeft = '20px';
			var node = o.firstChild;
			while (node && node.className != 'comment-content') {
				node = node.nextSibling;
			}
			if (node) {
				if (node.nextSibling) {
					o.insertBefore(f, node.nextSibling);
				} else {
					o.appendChild(f);
				}
			}
		}
	}

///	deleteComment: function (id) {
//		xajax_deleteComment(id);
//	}
}

