// JavaScript Document

var twit = new Cookie(document, "stwitter",120);

twit.load();


	function decreaseCount()
	{
		lendiv = document.getElementById("len")
		var newLen = 140 - document.fform.status.value.length;
		
		if (newLen > 50)
			lendiv.innerHTML = newLen.toString();
		else if (newLen > 20)
			lendiv.innerHTML = "<font size='+2'>" + newLen.toString() + "</font>";
		else if (newLen >= 0)
			lendiv.innerHTML = "<font size='+3'>" + newLen.toString() + "</font>";
		else
			lendiv.innerHTML = "<font size='+3' color='Red'>" + newLen.toString() + "</font>";
	}

	function checkSubmit()
	{
		if (document.fform.username.value.length == 0 ||
			document.fform.password.value.length == 0 ||
			document.fform.status.value.length > 140)
		{
			alert("problem on page")
			return false;
		}
		else
		{	
			twit.userid = document.fform.username.value;
			twit.password = document.fform.password.value;

			twit.store();
			
			var content = $('div.tweetdiv');
		
			if (!($(content).is(':hidden'))) {
					$(content).slideUp("medium");
				}			
			
			return true;
		}
			
	}
	
	function useCookies()
	{
		if (document.fform.username.value == "")
		{
		
			if (twit.userid===undefined)
			{
			}
			else
			{
				document.fform.username.value = twit.userid;
				document.fform.password.value = twit.password;
				document.fform.action += "?subtwitter"
				document.fform.submit();
			}

			//alert (document.fform.action)
			
		}
		
		showStuff()
	}

function changePage()
{
		var content = $('div.tweetdiv');
	
		if (!($(content).is(':hidden'))) {
				$(content).slideUp("medium");
			}		
	
		document.fform.action += "?subtwitter"
		document.fform.submit();
}



function showStuff()
{
	var content = $('div.tweetdiv');

	if ($(content).is(':hidden')) {
            $(content).slideDown(1500);
        }
}

function downClickPage()
{

	document.fform.page.value = parseFloat(document.fform.page.value) - 1;
	changePage();
}
function upClickPage()
{

	document.fform.page.value = parseFloat(document.fform.page.value) + 1;
	changePage();
}




function replyTweet(author, id)
{
	
	document.fform.status.focus();
	
	document.fform.status.value = "@" + author + " ";
	document.fform.in_reply_to_status_id.value = id;

}

function deleteTweet(id)
{
	//alert(id);
	
	if (confirm("Do you really want to delete this Tweet?"))
	{
		document.fform.username.value = twit.userid;
		document.fform.password.value = twit.password;
		document.fform.action += "?subtwitter&deleteid=" + id;
		document.fform.submit();	
	}
}
