this.charCountDefinitions = $H();

function setCharCount(inputID, charsMax) {
	this.charCountDefinitions[inputID] = charsMax;
}

// Updates the number of characters remaining
function updateCharCount(el) {
	if (typeof(el) == "string") {
		elem = $(el);
	} else {
		elem = el;
	}
	charsLeftName = elem.id + 'CharsRemaining';
	charsRemaining = this.charCountDefinitions[elem.id] - elem.value.length;
	if (charsRemaining > 0) {
		$(charsLeftName).update("You have " + charsRemaining + " characters remaining");
	} else if (charsRemaining == 0) {
		$(charsLeftName).update("You have no characters remaining");
	} else if (charsRemaining < 0) {
		$(charsLeftName).update("You have exceeded the character limit by " + (charsRemaining * -1) + " characters");
	}
}

function updateAllCharCounts() {
	this.charCountDefinitions.each(function(pair) {
    	updateCharCount(pair.key);
	});
}

// Clears the current value of an element
function clearSelection(name, reloadId) {
	el = $(name);
	if (el) {
		if (el.tagName == "SELECT") {
			if (el.multiple) {
				for (var i = 0 ; i < el.options.length ; i++) {
					el.options[i].selected  = false;
				}
			} else {
				el.selectedIndex = 0;
			}
		} else {
			el.value = "";
		}
	}
	if (reloadId) {
		$(reloadId).submit();
	}
	return false;
}