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('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('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 name="prefix" class="write_prefix">' + $('#prefix').html() + '</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('?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" scrolling="no" 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('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>');
	}
}

function switch_sync_change(elem)
{
	if (elem.value == 'twitter')
	{
		document.getElementById('sync_api_import').disabled = true;
	}
	else
	{
		document.getElementById('sync_api_import').disabled = false;
	}
	
	if (elem.value == 'none')
	{
		document.getElementById('sina_sync').style.display = 'none';
		document.getElementById('normal_sync').style.display = 'none';
	}
	else if (elem.value == 'sina')
	{
		document.getElementById('sina_sync').style.display = '';
		document.getElementById('normal_sync').style.display = 'none';
	}
	else
	{
		document.getElementById('sina_sync').style.display = 'none';
		document.getElementById('normal_sync').style.display = '';
	}
}

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