


// Use onFocus when putting in hints right in the text field
function clearValue(field, initValue)
{

	if (field.value == initValue)
	{
		field.value = '';

		field.style.color = '#000000';
	}

}

// Use onBlur when putting in hints right in the text field
function addValue(field, initValue)
{

	if (field.value.length < 1)
	{
		field.value = initValue;

		field.style.color = '#999999';
	}

}

function countChars()
{
	var tweetName = document.post_twitter['post_name'].value;
	
	if (tweetName == "Your Name")
	{
		tweetName = '';
	}
	
	var tweetMsg = document.post_twitter['post_tweet'].value;

	if (tweetMsg == "Enter your Tweet Here...")
	{
		tweetMsg = '';
	}

	document.getElementById('tweetcount').innerHTML = 138 - tweetMsg.length - tweetName.length;
	
	if ((tweetMsg.length + tweetName.length) >= 138)
	{
		document.post_twitter['post_tweet'].value = document.post_twitter['post_tweet'].value.substring(0, 138 - tweetName.length);
	}
}

function postTweet()
{
	var tweetName = document.post_twitter['post_name'].value;
	
	if (tweetName == "Your Name" || tweetName.length < 2)
	{
		alert('Enter your Name');
		return false;
	}
	
	var tweetMsg = document.post_twitter['post_tweet'].value;

	if (tweetMsg == "Enter your Tweet Here..." || tweetMsg.length < 3)
	{
		alert('Enter your Message');
		return false;
	}

	var myurl = '/cgi-bin/twitter.cgi?n=' + encodeURIComponent(tweetName) + "&m=" + encodeURIComponent(tweetMsg);

	document.getElementById('tweet_action').innerHTML = 'Sending...';

	var xmlHttp;

	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}

	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}

			catch (e)
			{
				alert("Your browser does not support AJAX");
				return false;
			}
		}
	}

	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
		{
			// document.getElementById('tweet_action').innerHTML = 'Done';
			
			// setTimeout("reload_page()",2000);
			
			document.getElementById('post_twitter').innerHTML = '<IMG SRC="/art/home-page/twitter-bird.png" ALT="Twitter Bird" ALIGN="LEFT" STYLE="margin: 0 10px 50px 0;">Your Tweet has been sent.<BR><BR>It will be posted shortly.<BR><BR><A HREF="#" ID="cancel_tweet">Close</A>';

			$('#cancel_tweet').click(function() {
			  $('#post_twitter').fadeOut('slow', function() {
				// Animation complete.
			  });
			});			
			
		}
	}

	xmlHttp.open("GET", myurl, true);

	xmlHttp.send(null);	
	
}

function getTweet()
{

	var myurl = '/cgi-bin/twitter.cgi';

	document.getElementById('twitter_content').innerHTML = '<BR><SMALL> &nbsp; &nbsp; Loading Tweets...</SMALL>';

	var xmlHttp;

	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}

	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}

			catch (e)
			{
				alert("Your browser does not support AJAX");
				return false;
			}
		}
	}

	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
		{			
			document.getElementById('twitter_content').innerHTML = xmlHttp.responseText;		
		}
	}

	xmlHttp.open("GET", myurl, true);

	xmlHttp.send(null);	
	
}


function reload_page()
{
	window.location.reload();
}



