// part of the code is taken from Brian's Threaded Comments (http://meidell.dk/blog)
		
		
function moveAddCommentBelow(theId, threadId)
{
	var addComment = document.getElementById("talkback-form");
	if(!addComment)
	{
		//alert("ERROR:\nThreaded Comments can't find the 'addcomment' div.\nThis is probably because you have changed\nthe comments.php file.\nMake sure there is a tag around the form\nthat has the id 'addcomment'"); 
		return
	}

	var comment = document.getElementById(theId);

	addComment.parentNode.removeChild(addComment);

	comment.appendChild(addComment);

	var replyId = document.getElementById("replyCommentID");
	if(replyId == null)
	{
		//alert("Brians Threaded Comments Error:\nThere is no hidden form field called\n'replyCommentID'. This is probably because you\nchanged the comments.php file and forgot\nto include the field. Please take a look\nat the original comments.php and copy the\nform field over.");
	}
	replyId.value = threadId;
	var reRootElement = document.getElementById("reroot");
	if(reRootElement == null)
	{
		//alert("Brians Threaded Comments Error:\nThere is no anchor tag called 'reroot' where\nthe comment form starts.\nPlease compare your comments.php to the original\ncomments.php and copy the reroot anchor tag over.");
	}
	reRootElement.style.display = "block";

	//var aTags = comment.getElementsByTagName("A");
	//var anc = aTags.item(0).id;
	//document.location.href = "#"+anc;

	document.getElementById("talkbackList").focus();
}

function checkDocumentIntegrity()
{
	str = "";
			
	str += checkElement("reroot","div tag");
	str += checkElement("talkback-form", "div tag");
	str += checkElement("replyCommentID", "hidden form field");
	str += checkElement("talkbackList", "textfield");
			
	if(str != "")
	{
		str = "Brian's Threaded Comments are missing some of the elements that are required for it to function correctly.\nThis is probably the because you have changed the original comments.php that was included with the plugin.\n\nThese are the errors:\n" + str;
		str += "\nYou should compare your comments.php with the original comments.php and make sure the required elements have not been removed.";

		//alert(str);
	}
}
               
function checkElement(theId, elDesc)
{
	var el = document.getElementById(theId);
	if(!el)
	{
		if(elDesc == null)
			elDesc = "element";
		return "- The "+elDesc+" with the ID '" +theId + "' is missing\n"; 
	}
	else 
		return "";
}
		
function reRoot()
{
	var addComment = document.getElementById("talkback-form");			
	var reRootElement = document.getElementById("reroot");
	reRootElement.style.display = "none";
	var content = document.getElementById("talkbackList");
	addComment.parentNode.removeChild(addComment);
	content.appendChild(addComment);

	document.location.href = "#talkbackList";

	document.getElementById("talkbackList").focus();				
	document.getElementById("replyCommentID").value = "0";
}			
		
function changeCommentSize(d)
{
	var el = document.getElementById("talkbackList");
	var height = parseInt(el.style.height);
	if(!height && el.offsetHeight)
		height = el.offsetHeight;
	height += d;
	if(height < 20) 
		height = 20;
	el.style.height = height+"px";
}		
