
function checkLogin(){
	var msg = "";
	if(document.getElementById("member_account").value==""){
		document.getElementById("member_account").focus();
		msg = "請輸入帳號\n\n";
	}
	if(document.getElementById("member_password").value==""){
		msg += "請輸入密碼\n";
	}
	if(msg!=""){
		alert(msg);
		return false;
	}
	return true;
}

function SendFriendForm(){
	var Name = document.getElementById("userName").value;
	var Reciver = document.getElementById("userReciver").value;
	var Code = document.getElementById("code1").value;
	var msg = "";
	if(Name==""){
		msg = "請輸入寄件者姓名\n";
	}
	msg += check_email(Reciver);
	
	if(Code==""){
		msg += "請輸入驗證碼\n";
	}else if(!checkAlp(dstText)){
		msg += "請輸入英文符號";
	}
	
	if(msg!=""){
		alert("請修正以下錯誤\n\n"+msg);
		return false;
	}
	
}

function checkAlp(dstText){
	data = dstText.match(/[^A-Za-z]/gi);
	if (data || !dstText) return false;
	return true;
}

function check_email(email){
	var len = email.length;
	if(len==0)
		return "您的收件者 email不能空白! \n";
	if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)))
		return "請輸入正確的收件者 email!\n";
	return "";
}

function timeToColse(){
	window.opener=null; 
	window.open("","_self"); 
	window.close();
}

$(document).ready(function(){
	setTimeout("timeToColse()",5400000);				   
	$(window).unload( function () {
			$.ajax({
				url:"/lastview.php",
				type:"post",
				data:"",
				cache:false,
				dataType:"text",
				chartset:"utf-8",
				success:function(returnData){
					if(returnData=="Success"){
					//	alert('成功');
					}else{
					//	alert(' 失敗:'+returnData);
					}
				}
			});	
				
		} )
	

} );

function addWordFavorite(id){
	$.ajax({
		url:"/account/addFavorite.php",
		type:"post",
		data:"id="+id,
		cache:false,
		dataType:"html",
		chartset:"utf-8",
		success:function(returnData){
			returnData = returnData.replace("<br>","");
			returnData = returnData.replace('\n',"");
			if(returnData=="S" || returnData=="R"){
				alert('已將文章加入至我的最愛');
			}else if(returnData=="E1"){
				alert('資訊錯誤');
				window.location.reload();
			}else if(returnData=="E2"){
				if(!confirm('請先登入會員!!\n\n【確定】鍵 => 前往登入頁\n【取消】鍵 => 停留本頁面')){ return false; }else{ location.href='/account/'; }
			}else if(returnData=="E3"){
				alert('文章資訊錯誤');
			}else{
				alert('加入我的最愛失敗');
			}
		}
	});	
}

function removeFavorite(id){
	$.ajax({
		url:"/account/rmFavorite.php",
		type:"post",
		data:"id="+id,
		cache:false,
		dataType:"html",
		chartset:"utf-8",
		success:function(returnData){
			returnData = returnData.replace("<br>","");
			returnData = returnData.replace('\n',"");
			if(returnData=="S" || returnData=="R"){
				window.location.reload();
				//alert('文章已從我的最愛移除');
			}else if(returnData=="E1"){
				alert('資訊錯誤');
				window.location.reload();
			}else if(returnData=="E2"){
				if(!confirm('請先登入會員!!\n\n【確定】鍵 => 前往登入頁\n【取消】鍵 => 停留本頁面')){ return false; }else{ location.href='/account/'; }
			}else{
				alert('文章從我的最愛移除失敗');
			}
		}
	});	
}


function removeWordFavorite(id){
	$.ajax({
		url:"/account/rmFavorite.php",
		type:"post",
		data:"id="+id,
		cache:false,
		dataType:"text",
		chartset:"utf-8",
		success:function(dvalue){
			dvalue = dvalue.replace('<br>','');
			dvalue = dvalue.replace('\n','');
			if(dvalue=='E1'){
				alert('資料錯誤!');
				window.location.reload();
			}else if(dvalue=='E2'){
				alert('請重新登入!');
				location.href='/account/';
			}else if(dvalue.substring(0,1)=='S'){
				var offs = parseInt(dvalue.substring(1,dvalue.length));
				var now_offs = parseInt($('#offset').val());
				if(now_offs >=10 && now_offs >=offs){
					top.location.href='favorite.php?offset='+(now_offs-10);
				}else{
					top.location.href='favorite.php?offset='+now_offs;
				}
			}else{
				alert('刪除失敗!');
			}
		}
	});	
}

