// IDs for Javascript-manipulated DOM elements:
var commentspanprefix = '#comment'; // 'add comment' ids


var commententry_origcontent;
var commententry_currentid = -1;  // -1 if nothing currently being commented on.

function CancelCommentEntry()
{
	if (commententry_currentid != -1) {
    	$(commentspanprefix + commententry_currentid).html(commententry_origcontent);
        commententry_currentid = -1;
    }
    return false;
}

// Add an adviser comment to the specified entry.
function AddComment(entryid)
{ 
	// Already commenting on this entry? Nothing to do.
	if (commententry_currentid == entryid)	
		return false;
	
	CancelCommentEntry();

    var commentspan = commentspanprefix + entryid;
    var oldcontent = $(commentspan).html()

    commententry_origcontent = oldcontent;
    commententry_currentid = entryid;
   
 	// Create our 'add comment' form.
    newcontent =  '<div>Your comment:</div>'
				 +   '<textarea id="ta' + entryid + '" name="content" rows="3" style="width: 98%"></textarea>'
				 +   '<br><input type="submit" value="Add" disabled>'
				 +   '<input type="submit" value="Cancel" onclick="return CancelCommentEntry();">'
		        ;
	// Add the form.
    $(commentspan).html(newcontent);
	$('#ta' + entryid).focus();
    return false;
}

