function write_comment(){
	if( ! is_user_logged ){
		alert("You must be logged in to comment.");
//		window.location.hash = "#main";
		return false;
	}
	if( !jQuery.data($("#comment_form").get(0), "h") )
		jQuery.data( $("#comment_form").get(0), "h", $("#comment_form").show().height() );
	var height = jQuery.data($("#comment_form").get(0), "h");
	height = height;
	
	$("#comment_form_wrap")
		.animate({opacity:0},0,"linear",function(){$(this).css("visibility","hidden")})
		.height( 0 )
		.animate({height:height},600,"linear",function(){$(this).css("visibility","")})
		.animate({opacity:1},600);
	$('#comment_write_link').html('<a href="javascript:void(0)" onclick="return cancel_write()">&raquo; never mind</a>');
}
function cancel_write(){
	$('#comment_write_link').html('<a href="javascript:void(0)" onclick="return write_comment()">&raquo; write your comment</a>');

	var height = jQuery.data($("#comment_form").get(0), "h");
	$("#comment_form_wrap")
		.animate({opacity:0},600,'linear',function(){
			$(this)
				.css("visibility","hidden")
				.animate({height:0},600,'linear',function(){ $(this).css("display","none"); });
		});
	
	$("#comment").val("").blur();
	$("#comment_summary").val("").blur();
	$("#comment_errors")
		.animate({opacity:0},400)
		.animate({height:0},400,'linear',function(){
			$(this)
				.empty()
				.remove();
		});
}
function submit_comment(form){
	if( ! is_user_logged && comment_strict_user ){
		alert('You need to be logged in before you can submit your comment.');
		return false;
	}
	if( form.agree.checked && form.comment.value ){
		if( new_comment && new_comment(form) )
			return false;

		return false;
	}else{
		if( ! form.comment.value ){
			alert('You can\'t submit without your comment.');
			form.comment.focus();
		}else if( ! form.agree.checked ){
			alert('Have you read the guidelines for posting comments?');
			form.agree.focus();
		}
		return false;
	}
}
function change_comment_page(page){
	comment_page(page,{
		callback:'jc_morecomment_user_get',
		relation:'user',
		rel_id:userkey,
		cpp: comments_per_page,
		url: comment_url
	},'comment_container');
	
	return false;
}

var flagged_comments = [];
function flag_this_comment( comment_id, flag ){
	if( ! is_user_logged && comment_strict_user_flag ){
		alert('You need to log in to flag comments.');
		return false;
	}
	for( var i in flagged_comments )
		if( flagged_comments[i] == comment_id ) return false;

	flagged_comments.push(comment_id);
	if( flag_comment(comment_id, flag) )
		$("#comment-flag-"+comment_id).addClass("flagged").attr("title","You have already flagged this comment,\n it is awaiting admin moderation.");
	
	return true;
}

