
//******************************************************************************
// FUNCTION:	TextCounter
//******************************************************************************
// DESC:	Decrements the counter element
// PARAMS:	obj -	    element
//			id  -	    the id of the element to decrement the innerHTML
//					    (i.e. <span id=count />
//          intLength - Length of text allowed
//******************************************************************************
function TextCounter(objEvent, charCountId, wordCountId, intLength)
{ 
    var intMaxLength = intLength;
    
	if(objEvent)
	{
		var intTextLength = objEvent.value.length;
		var intCount = (intMaxLength - intTextLength);

		if (intTextLength > (intMaxLength*1))
		{
			objEvent.value = objEvent.value.substring(0,(intMaxLength*1));
		}									
		
		if (charCountId && wordCountId)
		{
			// If count is a number			
			if(!isNaN(intCount))
			{
				var objCounterText = document.getElementById(charCountId);
				var objWordCounterText = document.getElementById(wordCountId);
				// If there is an element
				if(objCounterText)
				{
					if (intTextLength-1 < intMaxLength)	{
						objCounterText.innerHTML = intCount;
					    objWordCounterText.innerHTML = intCount/5;
					}
				}
			}
		}
	}
}

