
/* ######################## flagging / reporting ##################### */ 
function showHideFlagged(id) {
	var which = document.getElementById("showHide-" + id);
	if (which == null)	return false;
	
	if (which.innerHTML == "Show") {
		which.innerHTML = "Hide";
		which.title = "Hide";
		document.getElementById("comment-" + id).style.display = "block";
	} else {
		which.innerHTML = "Show";
		which.title = "Show";
		document.getElementById("comment-" + id).style.display = "none";
	}
	return false;
}
	
function showHideFlagging(id,option){
	var which = document.getElementById("flagging-" + id);
	if (which == null) return false;
	
	if (option == "show"){
		which.style.visibility = "visible";
	}
	if (option == "hide") {
		which.style.visibility = "hidden";
	}
	return false;
}
function flagComment(id) {
    if (confirm('Are you sure you want to report this comment as spam?')) {
        jQuery('#flagCommentIdInput').val(id);
        jQuery('#flagCommentForm').submit();
    }
    return false;
}
function resetFlagCount(id) {
    if (confirm('Are you sure you want to reset the flags for this comment?')) {
        jQuery('#resetFlagCountIdInput').val(id);
        jQuery('#resetFlagCountForm').submit();
    }
    return false;
}

/*********************************/
function clearText(inp, txt) {
    if (inp.value == txt) {
        inp.value = '';
        inp.style.color = '#000';
    }
}
function resetText(inp, txt) {
    if (inp.value == '') {
        inp.value = txt;
        inp.style.color = '#999';
    }
}

/****** LIST PAGE FUNCTIONS ********/
function deleteComment(id) {
    if (confirm('Are you sure you want to delete this comment?')) {
        jQuery('#deleteCommentIdInput').val(id);
        jQuery('#deleteCommentForm').submit();
    }
    return false;
}
function toggleEditComment(id) {
    jQuery('#commentBody' + id).toggle();
    jQuery('#commentEdit' + id).toggle();
    return false;
}
function editComment(id) {
    jQuery('#commentBody' + id).hide();
    jQuery('#commentEdit' + id).show();
    return false;
}
function cancelEditComment(id) {
    jQuery('#commentBody' + id).show();
    jQuery('#commentEdit' + id).hide();
    jQuery('#editCommentBody' + id).val(jQuery.trim($('#commentBody' + id).html()));
    return false;
}
function replyToComment(id, name) {
    jQuery('#commentBody').val("[" + name + "]\n" + sanitizeForReply(jQuery('#commentBody' + id).html()) + "\n[/" + name + "]\n");
}
function sanitizeForReply(str) {
    str = jQuery.trim(str);
    str = str.replace(/\n/img, '');
    str = str.replace(/\[[^\/]*?\].*?\[\/.*?\]/img, '');
    str = str.replace(/<blockquote.*?>.*?<\/blockquote>/img, '');
    str = str.replace(/<link.*?>/img, '');
    str = str.replace(/<br[ ]*[\/]?>/img, '\n');
    return str;
}
