function addcase(aid,cid,usercase)
{
	$.post("/bookcase.php",{action:"add",bid:aid,cid:cid,usercase:usercase},function(data)
	{
		var result=data.split("|");
		if(result[0]==0)
		{
			$.growlUI('提示', result[1],1); 
		}
		else if(result[0]==1)
		{
			$.growlUI('提示', result[1]); 
		}
	});
}


function votebook(aid)
{
	$.post("/vote.php",{id:aid},function(data)
	{
		var result=data.split("|");
		if(result[0]==0)
		{
			$.growlUI('提示', result[1],1); 
		}
		else if(result[0]==1)
		{
			$.growlUI('提示', result[1]); 
		}
	});
}


function showWindow(type)
{
	if(type=="login")
	{
		if($("#ajaxlogin").length > 0)
		{
			$.blockUI({ message: $('#ajaxlogin'),css: { width: '500px',background:'none repeat scroll 0 0 #F1F5FA' } });
		}
		else
		{
			$.post("/login.php",{ajax:"yes"},function (data,textStatus)
			{
				$("#append_parent").append(data);
				$.blockUI({ message: $('#ajaxlogin'),css: { width: '500px',background:'none repeat scroll 0 0 #F1F5FA' } });
			});
		}
	}
	else if(type=="register")
	{
		if($("#ajaxregister").length >0 )
		{
			$.blockUI({ message: $('#ajaxregister'),css: { width: '500px',background:'none repeat scroll 0 0 #F1F5FA' } })
		}
		else
		{
			$.post("/register.php",{ajax:"yes"},function (data,textStatus)
			{
				$("#append_parent").append(data);
				$.blockUI({ message: $('#ajaxregister'),css: { width: '500px',background:'none repeat scroll 0 0 #F1F5FA' } })
			});
		}
	}
}

function reg(username,password1,password2,email,code,sex,qq)
{
	if(username.length<2)
	{
		$("#returnmessage4").addClass("onerror").html("用户名不能少于2个字符！");
		return;
	}

	if(username.length>30)
	{
		$("#returnmessage4").addClass("onerror").html("用户名不能多于30个字符！");
		return;
	}

	if(password1.length<6 || password2.length<6)
	{
		$("#returnmessage4").addClass("onerror").html("密码不能少于6位！");
		return;
	}

	if(password1!=password2)
	{
		$("#returnmessage4").addClass("onerror").html("两次输入密码不同！");
		return;
	}

	if(email.length<=5)
	{
		$("#returnmessage4").addClass("onerror").html("请正确填写邮箱！");
		return;
	}

	if(email.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) == -1)
	{
		$("#returnmessage4").addClass("onerror").html("请正确填写邮箱！");
		return;
	}

	if(code.length!=4)
	{
		$("#returnmessage4").addClass("onerror").html("验证码只能为4位！");
		return;
	}

	$("#layer_reg").hide();
	$("#layer_message").show();
	$("#messageleft1").html('正在提交数据，如长时间没反映请 <a href="javascript:;" onclick="regback();">[点击此处]</a> ``返回上页重新提交！');

	$.post("/register.php",{action:"reg",ajax:"yes",username:username,password:password1,email:email,code:code,qq:qq,sex:sex},function(data)
	{
		var result=data.split("|");
		if(result[0]==0)
		{
			$('#layer_reg').show();
			$('#layer_message').hide();
			$("#returnmessage4").addClass("onerror").html(result[1]);
		}
		else if(result[0]==1)
		{
			$.growlUI('提示', '恭喜您，注册成功！~~'); 
		}

	});
}

function login(username,password,cookie)
{
	if(username.length<2 || password.length<5)
	{
		$("#returnmessage").addClass("onerror").html("用户名、密码不能为空！");
		return;
	}
	$.post("/login.php",{action:"login",ajax:"yes",username:username,password:password,cookie:cookie},function(data){
		var result=data.split("|");
		if(result[0]==0)
		{
			$("#returnmessage").addClass("onerror").html(result[1]);
		}
		else if(result[0]==1)
		{
			$.growlUI('提示', '恭喜您，登陆成功！~~'); 
		}
	});
}

function regback()
{
	$("#layer_reg").show();
	$("#layer_message").hide();
}

function errorreport(type)
{
	if(type==1)
	{
		
	}
	else if(type==2)
	{
		
	}
}
