/* textLimitor - limit text entered by user to specific length */

function textCounter(l) {
	
	var limit = l;
	var userText = document.sms_form.comment_tarea.value;
	var userLength = userText.length;
	var available_word;
	
	if (userLength > limit) {
		
        userText = userText.substring(0, limit);
        document.sms_form.comment_tarea.value = userText;
		
		// only use for firefox, other browsers work fine without this line
		document.getElementById('comment_tarea').scrollTop = document.getElementById('comment_tarea').scrollHeight;
	}
	
	if (limit - userLength >= 0) { available_word = limit - userLength; }
	else { available_word = 0; }
		
	document.getElementById('sms_box_word_count').innerHTML = "可輸入"+available_word+"字";
}
