function checkLimit(ele, update)
{
	$(update).innerHTML=ele.value.length;
}
function updateMe()
{
	text = $('update-text').value;
	what = $('update-what').value;
	$('saving').show();
	$('update-me').disabled=true;
	$('update-what').disabled=true;
	$('update-text').disabled=true;
	new Ajax.Request("/ajax/postMessage.php", {
		parameters: 'text='+encodeURIComponent(text)+'&what='+encodeURIComponent(what),
		onComplete: function t(response){
			checkLimit($('update-text'), 'char-count');
			$('update-me').disabled=false;
			$('update-what').disabled=false;
			$('update-text').disabled=false;
			$('saving').hide();
			message = response.responseText.split("<message>")[1];
			text = response.responseText.split("<text>")[1];
			if(response.responseText.split("<success>")[1] == "false"){
				$('update-msg').innerHTML= message;
				$('update-text').value=text;
			}
			else{
				$('update-msg').innerHTML= message;
				$('update-text').value="";
			}
			checkLimit($('update-text'), 'char-count');
		}
	});
}
function reply(service, name)
{
	$('update-what').value=service;
	$('update-text').value= "@"+name+ " " + $('update-text').value;
	$('update-text').focus();
}
function addImage()
{
	$('iframe_image').show();
}
var isFetching=false;
function refreshTimeline()
{
	if(!isFetching){
		isFetching=true;
		service=$('service-replies').value;
		if(service!=""){
			$('replies').innerHTML="<center><img src='/images/loading.gif' alt='Loading' /></center>";
			new Ajax.Updater('replies', '/ajax/refreshTimeline.php', {
				parameters: 'service='+encodeURIComponent(service),
				onComplete: function t(){
					isFetching=false;
				}
			});
		}
	}else{
		alert("We're already checking for you, hang tight.");
	}
}
function getTimeline()
{
	$('refresh').hide();
	service=$('service-replies').value;
	if(service!=""){
		$('replies').innerHTML="<center><img src='/images/loading.gif' alt='Loading' /></center>";
		new Ajax.Updater('replies', '/ajax/getTimeline.php', {
			parameters: 'service='+encodeURIComponent(service),
			onSuccess: function t(){
				$('refresh').show();
			}
		});
	}
}