//
// utils.js
//

// setFocus(fieldName)
// Sets focus to the specified field
function setFocus(fieldName) {
	ele = document.getElementById(fieldName);

	ele.focus();
	if ( (! ele.selectedIndex) & (ele.getAttribute('Type') == 'text') ) {
		document.getElementById(fieldName).select();
	}
}

//
// updateCharCount(ele, maxChars)
//
// Limits ele's content length to maxChars and updates ele's panel with remaining char count
//
function updateCharCount(ele, maxChars) {
	var charCount = ele.value.length;

	// Truncate value if greater than maxChars
	if ( charCount > maxChars ) {
		charCount = maxChars;
		ele.value = ele.value.substr(0, maxChars);
	}

	var remainingChars = maxChars - charCount;
	var eleName = ele.id;
	var panel = eleName + 'Panel';

	document.getElementById(panel).innerHTML = '(' + remainingChars + ' chars)';
}
