
var showNewComment = function(t) {
	var commentsbox = document.getElementById('commentsbox');
	eval("var decoded_data = " + t.responseText);

	document.forms.i_comment_form.elements['lastComment'].value = decoded_data.lastComment;
	//clear the "no comments yet" box.
	var nocommentsyet = document.getElementById('nocommentsyet');
	if(nocommentsyet && decoded_data.text != '') {
		nocommentsyet.innerHTML = '';
	}
	
	commentsbox.innerHTML += decoded_data.text;
	
	//HandleStartWatching from channel.js
	var wl = {responseText : 'ok'};
	HandleStartWatching(wl);
};

/*
var postComment = function() {
	var frm = document.forms['comment_form']; 
	var url = BASEURL+'insert_comments.php';
	var submitdata = "hid=" + frm.elements['hid'].value 
			+ "&cid=" + frm.elements['cid'].value
			+ "&comment=" + frm.elements['comment'].value
			+ "&submitMethod=ajax";
	new Ajax.Request(url, {method:'post', postBody:submitdata, onSuccess:showNewComment, onFailure:errFunc});
	
	return false;
};
*/

var deleteComment = function(comment_id) {
	var url = 'http://'+document.location.hostname+'/comment/delete/' + comment_id + '/';
	var submitdata = "comment_id=" + comment_id
						+ "&submitMethod=ajax&submit=true";
	
	var conf = hpConfirm('Delete this comment?');
	
	if(conf) {
		new Ajax.Request(url, {method:'post', postBody:submitdata, onSuccess:domRemoveComment, onfailure:deleteError});
	}
	return false;
};

var domRemoveComment = function(t) {
	var com = $('comment' + t.responseText);
	$('commentsbox').removeChild(com);
};

var deleteError = function() {
	alert('Failed to remove Comment');
};


