
function commentLimitChars() {
	var cmntArea = document.getElementById('comment');
	var limit = 2000;
	if (cmntArea) {
		if (cmntArea.value.length > limit) {
			cmntArea.value = cmntArea.value.substr(0, limit);
			alert('Your comment may not exceed ' + limit + ' characters in length.');
		}
	}
}

function commentLimitCharsAddEvent(obj, evType, fn, useCapture){
	if (obj.addEventListener){
		// W3C Registration
		obj.addEventListener(evType, fn, useCapture);
		return true;
	} else if (obj.attachEvent){
		// IE Registration
		return obj.attachEvent('on' + evType, fn);
	} else {
		// Fall back to traditional
		var eventName = 'on' + evType;
		var oldEvent = obj[eventName];
		if (typeof(oldEvent) != 'function') {
			obj[eventName] = fn;
		} else {
			obj[eventName] = function() {
				if (oldEvent) {
					oldEvent();
				}
				fn();
			}
		}
		return true;
	}
}

function commentLimitCharsInit() {
	// document.getElementById('commentform').ondblclick = function() { // zzdebug
	var cmntArea = document.getElementById('comment');
	if (cmntArea) {
		commentLimitCharsAddEvent(cmntArea, 'keydown', commentLimitChars, false);
		commentLimitCharsAddEvent(cmntArea, 'keyup', commentLimitChars, false);
		commentLimitCharsAddEvent(cmntArea, 'blur', commentLimitChars, false);
		commentLimitCharsAddEvent(cmntArea, 'focus', commentLimitChars, false);
		commentLimitCharsAddEvent(cmntArea, 'input', commentLimitChars, false);
	}
	// } // zzdebug
}

commentLimitCharsAddEvent(window, 'load', commentLimitCharsInit, false);

