/* Counts the number of characters remaining in a text field (textObj) and writes the output to an element (id = counterId) */

function displayCharCount(textId, counterId, maxChars) {
	var textElem = document.getElementById(textId);
	var counterElem = document.getElementById(counterId);
	if (textElem && counterElem) {
		var strLen = textElem.value.length;
		counterElem.innerHTML = maxChars - strLen;
	}
}

tii_callFunctionOnWindowLoad(function(event) {
	var your_comment = document.getElementById("your_comment");
	if (your_comment) {
		tii_addEventHandler(your_comment, 'change', function(event) {
			displayCharCount('your_comment', 'charcount', 1000);
		}, false);
		tii_addEventHandler(your_comment, 'keydown', function(event) {
			displayCharCount('your_comment', 'charcount', 1000);
		}, false);
	}
});
