//Update the comment length indicator.
function update_len() {
	var len = $('comment').value.length;
	var lenmax = $('lenmax').innerHTML;
	$('len').innerHTML=len;
	if (len > lenmax) {
		$('len').setStyle({color: '#a40000'});
		$('cutoff_warn').setStyle({display: ''});
	}
	if (len <= lenmax) {
		$('len').setStyle({color: ''});
		$('cutoff_warn').setStyle({display: 'none'});
	}
	
}

//Cancel editing/replying to a comment (creating a sub-comment). Hides the quote box and clears the parent comment id value.
function cancel() {
	
	//Change Reply/Save button text.
	$('replybutton').value = 'Add Reply';

	//Hide replyto box.
	$('replyingto_hider').setStyle({display: 'none'});
	//Clear the parent_comment_id field.
	$('parent_comment_id').value = '';
	
	//Hide edit box.
	$('editing_hider').setStyle({display: 'none'});
	//Clear the edit_comment_id field.
	$('edit_comment_id').value = '';
	
	//Set mod_comment back to off.
	if ($('mod_comment')) $('mod_comment').checked = false;
	
	$('comment').focus();

}

//Insert original comment text as quote into edit textarea.
function quote() {
	var originalcomment = $('comment').value;

	var parentusername = $('comment_ownername_'+$('parent_comment_id').value).value;

	var newtext = originalcomment + "[q=" + parentusername + "]" + $('bbcode_'+$('parent_comment_id').value).value + "[/q]";

	$('comment').value = newtext;
	$('comment').focus();
}

//Check if reply is empty. If it is, alert user and return false. This can be used to abort the submit.
function checkreply() {
	if ($('comment').value == '') {
		alert('Your reply is empty. You must enter text to reply.');
		return false;
	} else {
		return true;
	}
}

//Change user preference for reply box position to top.
function replybox_top() {
	$('replybox_pos_moveto').value='top';
	$('replybox_pos_form').submit();
}
//Change user preference for reply box position to bottom.
function replybox_bottom() {
	$('replybox_pos_moveto').value='bottom';
	$('replybox_pos_form').submit();
}

