var AF = site_root+'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(AF+'?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(AF+'?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;
	if(!is_element('ajax_tag'))	$('body').append('<div id="ajax_tag"></div>');
	setXY('ajax_tag',300,e);
	$('#ajax_tag').html('<img src="'+site_root+'skin/img/default/loading.gif" align="absmiddle" style="margin-right:5px;" />数据载入中...');
	$.ajax({
		url:AF+'?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="$RN(\'ajax_tag\');" title="关闭">关闭</a></span>'+tag+'</h3>'+list);
		}
	});
}
function translate(data,type,appendTo)
{
	$('#'+appendTo).show().html('<img src="'+site_root+'skin/img/default/loading1.gif" align="absmiddle" style="margin-right:5px;" />正在翻译中...');
	$.post(
		AF+'?action=translate',
		'type='+type+'&data='+encodeURIComponent(data),
		function(data)
		{
			eval('json='+data);
			if(json.error)	return	$('#'+appendTo).html('<strong style="color:red;text-align:center">'+json.error+'</strong>');
			if(json.data)	return	$('#'+appendTo).html(decode(json.data));
			else return	$('#'+appendTo).html('您翻译的文字超过了长度限制或者载入翻译数据失败，我们建议您：<br />如果文字比较长（通常超过2000个字的话翻译容易出错），请分段翻译；<br/>如果您的文字不多，那么可以刷新后再试一次；<br/>如果还不行，那么请您给我们<a href="mailto:insuns.com">发送邮件</a>，我们会及时回复您！');
		}
	);
}