$(function()
{
	//检查是否登录
	if($("#comment_staus").length>0)
	{
		$.ajax(
		{
			type:"post",
			cache:false,
			url:webroot+"plug/comment.asp?act=islogin",
			data:"gourl="+contenturl,
			success:function(_){$("#comment_staus").html(_);checkcomment();}
		});
	}
	if($("#commenttop").length>0)
	{
		$.ajax(
		{
			type:"post",
			cache:false,
			url:webroot+"plug/comment.asp?act=load&id="+infoid,
			success:function(_){$("#commenttop").html(_);}
		});
	}

})	

function checkcomment()
{
	$(".form_comment").validator(
	{
		stopOnError:true,
		theme:'yellow_top',
		ignore:':hidden',
		valid:function(form)
		{
			$.fn.tips({type:'loading',content:'数据提交中'});
			$.ajax(
			{
				url:webroot+"plug/comment.asp?act=add&id="+infoid,
				type:"post",
				data:$(form).serialize(),
				success:function(data){
					data=jQuery.parseJSON(data);
					var type="warn";
					if(data.status=="y"){type="ok";}
					$.fn.tips({type:type,content:data.info});
					if(data.status=="y")
					{
						var act=data.info.substring(0,1);
						var info=data.info.substring(1);
						$.fn.tips({type:"ok",content:info});
						$("#comment_content").text("");
						if(act==2)
						{
							if($("#commenttop").length>0)
							{
								$.ajax(
								{
									type:"post",
									cache:false,
									url:webroot+"plug/comment.asp?act=load&id="+infoid,
									success:function(_){$("#commenttop").html(_);}
								});
							}
							else{setTimeout(function(){location.href=''+contenturl+'';},1500)}
						}
					}
				}
			});
		}
	});
}
