<script type="text/javascript">

// char counter
var charsToGo;

function charCounter(charInputSrcName, maxCharCount, outputTargetName) 
{
	var charInputSrc = document.getElementById(charInputSrcName);
	var outputTargetSrc = document.getElementById(outputTargetName);
	
	if (charInputSrc != null) 
	{
		// Check length
		if (charInputSrc.value.length <= maxCharCount) 
		{
			// Calculate remaining chars
			charsToGo = maxCharCount - charInputSrc.value.length;
			outputTargetSrc.innerHTML = '(' + charsToGo + '&nbsp;{CHARACTERS})';
		}
		else
		{
			charInputSrc.value = charInputSrc.value.substring(0, maxCharCount);
		}
		charsToGo = maxCharCount - charInputSrc.value.length;
	}
}

function counterOutput(charInputSrcName, maxCharCount, outputTargetName)
{
	var charInputSrc = document.getElementById(charInputSrcName);
	
	// check for global variable
	if (charsToGo == null) 
	{
		// calculate value
		charsCount = maxCharCount - charInputSrc.value.length; 
	}
	else
	{
		charsCount = charsToGo;
	}
	document.write('<span name=\"'
		+ outputTargetName + '\" id=\"' + outputTargetName +'\">('
		+ charsCount + '&nbsp;{CHARACTERS})</span>')
}
</script>
