/**
* @author   $Author: martijn $
* @revision $Revision: 43 $
* @date     $Date: 2009-07-24 21:26:03 +0200 (Fri, 24 Jul 2009) $
*/
// counts the nr of chars in the shoutname and shouttext field
function updateTextLimitCounter()
{
	shoutTextLength = document.getElementById('shouttext').value.length;
	shoutNameLength = document.getElementById('shoutname').value.length
	totalLength     = shoutTextLength + shoutNameLength;
	
	document.getElementById('textLimitCounter').value = maxTotalLength - totalLength;
}
// updates how many chars are left and trims when max is reached
function trimFieldLength(fieldEl) 
{
	if(totalLength > maxTotalLength)
	{
		//alert('too long, trim it'); 
		fieldEl.value = fieldEl.value.substring(0, (fieldEl.value.length - totalLength + maxTotalLength - 1));
	}	
}

function handleSubmit()
{
	shoutnameEl = document.getElementById('shoutname');
	shouttextEl = document.getElementById('shouttext');

	// everything filled in?
	validated   = validateShout(shoutnameEl, shouttextEl); 
		
	if(validated == true)
	{
		// submit, reset text and counter
		document.getElementById('shoutboxform').submit();
		shouttextEl.value = '';
		shouttextEl.focus();
		updateTextLimitCounter();
	}
}

function validateShout(shoutnameEl, shouttextEl)
{
	validated = true;
	
	if(shoutnameEl.value.length == 0 )
	{
		shoutnameEl.className = 'error';
		validated = false;
	}	
	else
	{
		shoutnameEl.className = 'text';	
	}
	
	if ( shouttextEl.value.length == 0)
	{
		shouttextEl.className = 'error';
		validated = false;
	}	
	else
	{
		shoutnameEl.className = 'textarea';	
	}
	
	
	
	return validated;
}

