function toogleForm(t){
	$("#replyform").toggle();	
	if(t.innerHTML=='打開評論表單'){
		t.innerHTML='關閉評論表單';
	}
	else{
		t.innerHTML='打開評論表單';
	}
	t.blur();
}

function submitComment(t){
	//載入數據
	var bid=$.trim(t.form.bid.value);
	var author=$.trim(t.form.author.value);
	if(author==""){
		alert("請留下你的大名");
		t.form.author.focus();
		return false;
	}
	var email=$.trim(t.form.email.value);
	var reg = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
	if(email!="" && !reg.test(email)){
		alert("不留拉倒!\n要留就留個正確的郵箱!");
		t.form.email.focus();
		return false;
	}
	var website=$.trim(t.form.website.value);
	var content=$.trim(t.form.content.value);
	if(content==""){
		alert("請留下你的意見");
		t.form.content.focus();
		return false;
	}
	//保留cookie
	if(t.form.ch.checked==true){
		 $.cookie('author', author, { path:'/', expires:14});
		 $.cookie('email', email, { path:'/', expires:14});
		 $.cookie('website', website, { path:'/', expires:14});
	}
	else{
		 $.cookie('author', null, { path:'/', expires:14});
		 $.cookie('email', null, { path:'/', expires:14});
		 $.cookie('website', null, { path:'/', expires:14});		
	}
	//提交狀態
	t.value="提交中…";
	t.disabled=true;
	$.post(
		'comment.php',
		{bid:bid, author:author, email:email,website:website, content:content},
		function(data){
			//成功返回值
			$("#sub").attr("disabled",false); 
			$("#sub").attr("value","提交");
			$("#content").attr("value","");
			$("#comment").append(data);	
			if(confirm("評論成功!\n你是否查看你的評論?")){
				document.documentElement.scrollTop = document.documentElement.scrollHeight;	
			}			
		}
	);
}

//刪除個人信息
function cleanCookie(){
	if(!confirm("你確定刪除個人信息嗎?")){
		return false;	
	}
	$.cookie('author', null, { path:'/', expires:14});
	$.cookie('email', null, { path:'/', expires:14});
	$.cookie('website', null, { path:'/', expires:14});	
	$("#author").attr("value","");		   
	$("#email").attr("value","");		   
	$("#website").attr("value","");
}

//啟用cookies
$(function(){
	$("#author").attr("value",$.cookie("author") ? $.cookie("author") : '');		   
	$("#email").attr("value",$.cookie("email") ? $.cookie("email") : '');		   
	$("#website").attr("value",$.cookie("website") ? $.cookie("website") : '');
});