function sendReply(id)
{
	if ($('#reply_message_' + id).val() == '')
	{
		alert('请输入回复内容.');
		
		return false;
	}
	
	var replyid = id;
	
	$('#reply_loading_' + id).html(' &nbsp; <img src="images/animation_loading_small.gif" alt="Loading..." />');
	
	$('#reply_message_' + replyid + '_submit').hide();
	
	$.post(BASE_URL + 'httprequest.php?act=sendreply', 'entryid=' + id + '&message=' + $('#reply_message_' + id).val() + '&nickname=' + $('#reply_nickname_' + id).val(), function (ajax, status)
	{			
		if (status == 'timeout' || status == 'error')
		{
			if (status == 'timeout')
			{
				alert('网络通信超时,请稍后重试.');
			}
			else
			{
				alert('内部服务器错误,请稍后重试.');
			}
			
			$('#reply_loading_' + id).empty();
			$('#reply_message_' + replyid + '_submit').show();
			
			return false;
		}
		
		if (ajax == 'done')
		{
			$.get(BASE_URL + 'httprequest.php?act=getreply&entryid=' + replyid, function(data) {
				$('#reply_contents_' + replyid).html(data);
				$('#reply_loading_' + replyid).empty();
				
				document.getElementById('reply_message_' + replyid).value = '';
				
				$('#reply_message_' + replyid + '_submit').show();
			});
		}
		else
		{
			alert(data);
			
			$('#reply_loading_' + id).empty();
			$('#reply_message_' + replyid + '_submit').show();
		}
	});
}

var entry_content = new Array();

function editEntry(objectid, prefixid)
{
	entry_content[objectid] = $('#entry_content_' + objectid).html();
	
	//entry_html = $('#entry_html_' + objectid).html().replace(/\<br>/ig, "\r\n").replace(/\<br \/>/ig, "\r\n");
	entry_html = $('#entry_html_' + objectid).html();
	
	$('#entry_content_' + objectid).html('<form id="edit_entry_' + objectid + '" method="post"><textarea class="input_message" name="message" style="width: 99%" rows="10">' + entry_html + '</textarea><div style="padding: 10px 0"><div style="float:right"><input type="button" value="保 存" id="submit_edit_entry_' + objectid + '" onclick="saveEditEntry(' + objectid + ')" /> <input type="button" value="撤 销" onclick="cancelEditEntry(' + objectid + ')" /></div><select class="write_prefix" name="prefix"><option selected="selected" value="0">说</option><option style="padding:0; margin: 0;" value="7" class="was">不久前</option><option style="padding:0; margin: 0;" value="31" class="was">今天</option><option style="padding:0; margin: 0;" value="30" class="will">准备</option><option style="padding:0; margin: 0;" value="18" class="shares">分享</option><option style="padding:0; margin: 0;" value="27" class="was">刚刚</option><option style="padding:0; margin: 0;" value="14" class="hates">厌恶</option><option style="padding:0; margin: 0;" value="20" class="hates">发愁</option><option style="padding:0; margin: 0;" value="32" class="hates">咆哮</option><option style="padding:0; margin: 0;" value="16" class="likes">喜欢</option><option style="padding:0; margin: 0;" value="11" class="will">将会</option><option style="padding:0; margin: 0;" value="10" class="hopes">希望</option><option style="padding:0; margin: 0;" value="21" class="likes">开心</option><option style="padding:0; margin: 0;" value="19" class="hates">心烦</option><option style="padding:0; margin: 0;" value="22" class="was">忘记</option><option style="padding:0; margin: 0;" value="3" class="thinks">想</option><option style="padding:0; margin: 0;" value="33" class="shares">收藏</option><option style="padding:0; margin: 0;" value="25" class="says">正在</option><option style="padding:0; margin: 0;" value="23" class="needs">汗</option><option style="padding:0; margin: 0;" value="28" class="shares">看</option><option style="padding:0; margin: 0;" value="26" class="was">缺魂</option><option style="padding:0; margin: 0;" value="13" class="wants">要</option><option style="padding:0; margin: 0;" value="5" class="feels">觉得</option><option style="padding:0; margin: 0;" value="29" class="shares">读</option><option style="padding:0; margin: 0;" value="24" class="hates">郁闷</option><option style="padding:0; margin: 0;" value="9" class="asks">问</option><option style="padding:0; margin: 0;" value="12" class="needs">需要</option></select><div class="clear"></div></div></form>');
	
	if (prefixid > 0)
	{
		$('#entry_content_' + objectid + ' select').val(prefixid);
	}
}

function saveEditEntry(objectid)
{
	$('#submit_edit_entry_' + objectid).attr('disabled', true).val('处理中...');
	
	$.post(BASE_URL + '?act=edit&id=' + objectid, $('#edit_entry_' + objectid).formToArray(), function (ajax, status)
	{						
		if (status == 'timeout' || status == 'error')
		{
			if (status == 'timeout')
			{
				alert('网络通信超时,请稍后重试.');
			}
			else
			{
				alert('内部服务器错误,请稍后重试.');
			}
			
			$('#submit_edit_entry_' + objectid).attr('disabled', false).val('保 存');
			
			return false;
		}
		
		if (ajax == 'authorizeerror')
		{
			alert('权限不足,操作中止.');
			
			cancelEditEntry(objectid);
			
			return false;
		}

		$('#entry_content_' + objectid).html(ajax);

		entry_content[objectid] = ajax;
	});
}

function cancelEditEntry(objectid)
{
	$('#entry_content_' + objectid).html(entry_content[objectid]);
}

function doFollow()
{
	$.facebox('<iframe src="' + BASE_URL + '?act=dofollow" width="640" height="380" frameborder="0" noresize="noresize"></iframe>');
}

function setTab(el, id)
{
	$('ul.tab li').removeClass('selected');
	
	$('.tab_content_block').hide();
	
	//$('#' + id).fadeIn('fast');
	
	document.getElementById(id).style.display = '';
	
	el.className = 'selected';
}

var follow_current_page = 1;
var follow_data = '';

function loadFollow()
{
	follow_current_page++;
	follow_data = '';
	
	$('#load_follows').addClass('loading').html('<img src="images/animation_loading_small.gif" alt="Loading..." title="Loading..." class="lineobj" style="padding: 3px 0 0 0;" border="0" />');
	
	$.getJSON(BASE_URL + 'httprequest.php?act=load_follows&page=' + follow_current_page, function (data) {
		if (data == 'no_more')
		{
			$('#load_follows').html('没有更多了');
			
			return true;
		}
		
		$.each(data, function(i, item) {				
			follow_data += item;
		});
		
		$('#follow_data').html($('#follow_data').html() + follow_data);
			
		$('#load_follows').removeClass('loading').text('更 多');
	});
}

function quickComment(followid, entryid)
{
	var message = prompt('请输入评论内容:', '');
	
	if (message)
	{
		$.facebox('<iframe src="' + BASE_URL + 'httprequest.php?act=quickcomment&followid=' + followid + '&entryid=' + entryid + '&message=' + encodeURIComponent(message) + '" width="860" height="480" frameborder="0" noresize="noresize"></iframe>');
	}
}

setInterval(function () {
	document.getElementById('cron').src = BASE_URL + 'httprequest.php?act=cron&' + Math.random();
	
	$.get(BASE_URL + 'httprequest.php?act=getplaying', function (data) {
		$('#playing').html(data);
	})
}, 60000);
