var AP = 'ajax.'+ext;
function post_comment()
{
	var arr = ['content_id','username_id','checkcode_id'];
	var cop = comment_option;
	var data = '';
	if(!cop.article_id)	return $('#return_msg').html('<font color="red">非法提交！</font>').show();
	if(!cop.open)
	{
		$('#return_msg').html('<font color="red">评论功能已关闭！</font>').show();
		return setTimeout("$('#"+cop.comment_area_id+"').hide('slow')",3000);
	}
	for(var i=0;i<arr.length;i++)
	{
		var a = arr[i];
		if(!cop[a] || !is_element(cop[a]))	return $('#return_msg').html('配置错误，'+arr[i]+'缺失！').show();
		var v = $.trim($('#'+cop[a]).val());
		if(!v && a!='username_id')
		{
			$('#'+cop[a]).focus();
			return $('#return_msg').show().html('<font color="red">信息填写不完整！</font>');
		}
		data += '&'+a.split('_')[0]+'='+encodeURIComponent(v);
	}
	$.post(site_root+AP+'?action=post_comment',data+'&article_id='+cop.article_id,
		function(data)
		{
			eval('json='+data);
			if(json.error)
			{
				$('#return_msg').html(json.error).show();
				$('#'+cop.checkcode_id).focus().val('');
			}
			else
			{
				$('#return_msg').html(json.msg).show();
				$('#'+cop.content_id).empty();
			}
			$('#'+cop.checkcode_img_id).attr('src',$('#'+cop.checkcode_img_id).attr('src')+'?t='+Math.random());
			setTimeout("$('#return_msg').hide('slow')",3000);
		});
}
function load_comment(p)
{
	if(!p || p<1)	p = 1;
	if(!comment_option.comment_area_id || !comment_option.list_id || !is_element(comment_option.comment_area_id) || !is_element(comment_option.list_id) || !comment_option.article_id)	return;
	if(!comment_option.open)	$('#'+comment_option.comment_area_id).hide();
	$('#'+comment_option.list_id).html('Loading...');
	$('#'+comment_option.list_id).load(site_root+AP+'?action=load_comment_list&article_id='+comment_option.article_id+'&page='+p+'&t='+Math.random());
}
function load_tag(tag,e)
{
	e = window.event || e;
	tag = $.trim(tag);
	if(!tag)	return;
	var elm = $('#ajax_tag');
	if(!elm.attr('id'))	elm = $('<div id="ajax_tag"></div>').attr('id','ajax_tag').appendTo('body');
	elm.width(300);
	$('#ajax_tag').xy(e);
	$('#ajax_tag').html('<img src="'+site_root+'/skin/img/default/loading.gif" align="absmiddle" style="margin-right:5px;" />数据载入中...');
	$.ajax({
		url:site_root+AP+'?action=load_tag&tag='+encodeURIComponent(tag)+'&t='+Math.random(),
		success:function(data)
		{
			var list = '';
			eval('var json='+data);
			if(json)
			{
				for(var i=0;i<json.length;i++)
				{
					list += '<li>'+(i+1)+'. <a href="'+decode(json[i]['url'])+'" target="_blank" title="'+decode(json[i]['title'])+'">'+decode(json[i]['title'])+"</a></li>\n";
				}
			}
			list = list ? '<ul>'+list+'</ul><p class="fr"><a href="'+site_root+'/tag.'+ext+'?w='+ encodeURIComponent(tag)+'" target="_blank">更多...</a></p>': '<p>该标签下尚无文章!</p>';
			$('#ajax_tag').html('<h3><span class="fr close"><a href="javascript:" onclick="$(\'ajax_tag\').remove();" title="关闭">关闭</a></span>'+tag+'</h3>'+list);
		}
	});
}