function toggle(id) {
	$('#'+id).slideToggle();
}

// onlinestatus
function onlineStatus_get() {
	$.get('/AjaxHandler?classid=1&action=getOnlineStatus', function(text) {
		if (text == "") {
			$('#os_text_wrap').slideUp();
		} else {
			$('#os_text').html(text);
			$('#os_text_wrap').slideDown();
		}
	});
}
function onlineStatus_set(statusText) {
	$.get('/AjaxHandler?classid=1&action=setOnlineStatus&onlinestatus_text='+encodeURIComponent(statusText), function(r) {
		if (r == "200") {
			$('#os_controls').slideUp();
			$('#os_textarea').val('').blur();
			onlineStatus_get();
			minifeedRefresh();
		}
	});
}
function onlineStatus_submit() {
	onlineStatus_set($('#os_textarea').val());
}
function onlineStatus_clear() {
	$('#os_text_wrap').slideUp();
	onlineStatus_set('');
}

// comments
function comment_refresh(sid) {
	$.get('/AjaxHandler?classid=1&action=getStatusComment'+'&status_id='+encodeURIComponent(sid), function(text) {
		$('#comment_list'+sid).html(text);
	});
}
function comment_refreshAll() {
	$('input[id^=statusID]').each(function() {
		comment_refresh($(this).val());
	});
}
function comment_submit(id){
	toggle('comment_editor'+id);
	var ctext = $('#comment_text'+id).val();
	var sid = $('#statusID'+id).val();
	$.get('/AjaxHandler?classid=1&action=setStatusComment&onlinestatus_text='+encodeURIComponent(ctext)+'&status_id='+encodeURIComponent(sid), function(text) {
		comment_refresh(sid);
	});
}
function comment_delete(cid) {
	if(confirm('Soll dieser Kommentar wirklich gelöscht werden?')) {
		$.get('/AjaxHandler?classid=1&action=delComment&comment_id='+encodeURIComponent(cid), function(text) {
			$('#c'+cid).remove();
		});
	}
}

// poll comments
function poll_delComment(iCommentID,iPollID) {
	if(confirm('Soll dieser Kommentar wirklich gelöscht werden?')) {
		$('#divPollComments').innerHTML="<div align=center><img src=media/shared/ajax-loader.gif valign=center></div>";
		$.get('/AjaxHandler?classid=1&action=delPollComment&comment_id='+encodeURIComponent(iCommentID)+'&poll_id='+encodeURIComponent(iPollID), function(text) {
			poll_refreshComments(text);
		});
	}
}
function poll_submitComment(pollid) {
	var comment = $('#pollcomment_text');
	if(comment.val()=="") {
		alert("Dein Kommentar sollte schon einen Inhalt haben!");
		return false;
	}
	toggle('poll_editor');
	$('#divPollComments').html("<div align=center><img src=media/shared/ajax-loader.gif valign=center></div>");
	$.get('/AjaxHandler?classid=1&action=setPollComment'+'&iText='+encodeURIComponent(comment.val())+'&pollid='+encodeURIComponent(pollid), function(text) {
		poll_refreshComments(text);
		comment.val("");
	});
}
function poll_refreshComments(text) {
	$('#divPollComments').html(text);
}

// minifeed
function ajaxRefreshMinifeed(action, params) {
	$('#minifeedTab').html('<div style="margin: 60px 0px; text-align:center;"><img src="/media/shared/ajax-loader.gif"></div>');
	
	var url = '/AjaxHandler?classid=3&action='+action;
	if (params) { url += params; }
	
	$('#minifeedTab').load(url, function(r) {
		$('[id^=comment_editor]').show();
		$('[id^=comment_text]').elastic();
		$('[id^=comment_editor]').hide();
		$('a[data-role=button]').button();
	});
}

function minifeedShowtab(tab, ofs, ru, is_public) {
	var params="";
	if (tab)	{ params+="&tab="+tab; }
	if (ofs>0)	{ params+="&ofs="+ofs; }
	if (ru)		{ params+="&ru="+ru; }
	if (is_public) { params+="&public_feed=true"; }
	
	ajaxRefreshMinifeed('refreshMinifeed', params);
}

function minifeedSaveSettings(removeuser) {
	var params="&tab=2";
	
	params+="&t="+$('#filterTime').val();
	$('input[name=filters]').not(':checked').each(function() {
		params+="&f["+$(this).val()+"]=1";
	});
	
	if (removeuser) { params+="&ru="+removeuser; }
	if ($('#au') && $('#au').val()!='') {
		params+="&au="+$('#au').val();
	}
	
	ajaxRefreshMinifeed('setMinifeedOptions', params);
}

function minifeedRefresh() {
	_gaq.push(['_trackEvent', '/ajax/Minifeed', 'refresh']);
	minifeedShowtab(1);
}
