/*** Javascript ***/
var limitTime = 0;

function limitComment(){
	limitTime=limitTime-1;
	if(limitTime>0){
		$('.btn_post').hide();
		$('#timelimit').html('還剩<font color="red"><strong> '+limitTime+' </strong></font>秒,您才可以再發表評論');
		setTimeout("limitComment()",1000);
	}else if (limitTime == 0){
		$('.btn_post').show();
		$('#timelimit').html('');
	}
}

function saveComment(category, mb_id){
	if (!mb_id) {
		$('#showmsg').html('請先登錄！');
        setCookie('commentCookie', $('#comment').val());
		$('#showmsg').css('color', 'red');
		$('#showmsg').show();
		return false;
	}
	if($.trim($('#comment').val()) == ''){
		alert('請輸入評論！');
		$('#comment').focus();
		return false;
	}
	limitTime = 10;
	limitComment();
	$('#showmsg').css('color', 'red');
	$('#showmsg').show();
	$.ajax({
		type:'post',
		url :'ajax.php?action=savecom',
		cache:false,
		data:'category='+escape(category)+'&comment='+$('#comment').val()+'&mb_id='+mb_id,
		dataType:'json',
		success:function(json) {
			$('#showmsg').html('評論成功！');
            clearCookie('commentCookie');
			$('#showmsg').hide(3000);
			$('#comment').attr('value', '');
			$('li.list:first').before('<li class="list"><img src="'+json.mb_photo+'" width="18" height="18" align="left" />'+json.comment+'</li>');
			window.location.reload();
		}
	});
}


function saveComment2(category, mb_id, issue){
	if (!mb_id) {
		$('#showmsg').html('請先登錄！');
        setCookie('commentCookie', $('#comment').val());
		$('#showmsg').css('color', 'red');
		$('#showmsg').show();
		return false;
	}
	if($.trim($('#comment').val()) == ''){
		alert('請輸入評論！');
		$('#comment').focus();
		return false;
	}
	limitTime = 10;
	limitComment();
	$('#showmsg').css('color', 'red');
	$('#showmsg').show();
	$.ajax({
		type:'post',
		url :'ajax.php?action=savecomws',
		cache:false,
		data:'category='+escape(category)+'&comment='+$('#comment').val()+'&mb_id='+mb_id+'&issue='+issue,
		dataType:'json',
		success:function(json) {
			$('#showmsg').html('評論成功！');
            clearCookie('commentCookie');
			$('#showmsg').hide(3000);
			$('#comment').attr('value', '');
			$('li.list:first').before('<li class="list"><img src="'+json.mb_photo+'" width="18" height="18" align="left" />'+json.comment+'</li>');
			window.location.reload();
		}
	});
}


function saveCommentSnap(category, mb_id, s_id,spage){
	var sectionId=0;
	if (!mb_id) {
		$('#showmsg').html('請先登錄！');
        setCookie('commentCookie', $('#comment').val());
		$('#showmsg').css('color', 'red');
		$('#showmsg').show();
		return false;
	}
	if($.trim($('#comment').val()) == ''){
		alert('請輸入評論！');
		$('#comment').focus();
		return false;
	}
	if(category=='City Snap'){
		sectionId=13;
	}else{
		sectionId=14;
	}
	limitTime = 10;
	limitComment();
	$('#showmsg').css('color', 'red');
	$('#showmsg').show();
	$.ajax({
		type:'post',
		url :'ajax.php?action=savesnap',
		cache:false,
		data:'category='+escape(category)+'&comment='+$('#comment').val()+'&mb_id='+mb_id+'&s_id='+s_id,
		dataType:'json',
		success:function(json) {
			$('#showmsg').html('評論成功！');
            clearCookie('commentCookie');
			$('#showmsg').hide(3000);
			$('#comment').attr('value', '');
			$('li.list:first').before('<li class="list"><img src="'+json.mb_photo+'" width="18" height="18" align="left" />'+json.comment+'</li>');
			window.location="action.php?category=selectPhoto&sectionId="+sectionId+"&sId="+s_id+"&page="+spage;
		}
	});
}


function checkLogin(mb_id, member){
	if (!mb_id && member=='mem') {
		$('#showmsg').html('請先登錄！');
		$('#showmsg').css('color', 'red');
		$('#showmsg').show();
		return false;
	}else{
		return true;
	}
}

