var commentisediting = false;
var currentcomment = null;

function commenthover(obj) {
    if (commentisediting || obj.className == '')
		return; 
	
	obj.className = 'activecomment';	
	objParent = obj;
	left = document.getElementById('wrap').offsetLeft - 23;
	itop = 20;
	
	
	while (objParent.id != 'contentWrapper') {		
		left += objParent.offsetLeft;
		left -= objParent.scrollLeft;
		itop += objParent.offsetTop;
		objParent = objParent.offsetParent;
	}
	
	commentpopup.style.left = left + 'px';
	commentpopup.style.top = itop + 'px';
	commentpopup.style.display = 'block';
	comment = commentManager.getFromId(obj.id.substring(7));
	document.getElementById('commenttext').innerHTML = comment.Comment;
}

function commentmouseout(obj) {
    if (commentisediting || obj.className == '')
		return;
		
	doCommentmouseout();
	obj.className = 'comment';
}

function doCommentmouseout() {
	commentpopup.className = 'tooltip largetooltip commentpopup';
	commentpopup.style.display = 'none';
}

function commentclick(obj) {
    if (obj.className == '')
		return;
		
	currentcomment = obj;
	commentpopup.className = 'tooltip largetooltip commentpopup activecommentpopup';
	document.getElementById('commenttext').focus();
	commentisediting = true;
	try
	{
	    docomment = false;
	}
	catch(exc)
	{
	}
}

function updateComment(obj) {
	comment = commentManager.getFromId(currentcomment.id.substring(7));
	if (comment.Comment != obj.value) {
		comment.Comment = obj.value;
		comment.updateComment();
	}
	commentisediting = false;
	setTimeout("doCommentmouseout()", 200);
}

function deleteComment(obj) {
	if (confirm(translate('Are you sure you want to delete this comment?'))) {
		doCommentmouseout();
		comment = commentManager.getFromId(currentcomment.id.substring(7));
		comment.deleteComment();
		commentisediting = false;
	}
}
