function restrictLength(elemId, maxLen, numElemId)
{
	// USAGE: This function should be set to the "onkeyup" event of the element
	//elemId = ID of the element to track
	//maxLen =  max number of characters allowed
	//numElemId =  ID of the element that will be used for counting
	
	elem = document.getElementById(elemId);
	num = document.getElementById(numElemId);
	
	if (elem.value.length >= maxLen) {
		// Reached the Maximum length so trim the textarea
		elem.value = elem.value.substring(0, maxLen);
		
		// Notify user
		alert('The content exceeds the character limit.  The content has been truncated to fit the limit.');
	}
	
	if (num.type == 'text')
		num.value = maxLen - elem.value.length;
	else
		num.innerHTML = (maxLen - elem.value.length).toString();
	
}
function resizeTextArea(elemId, minRows) {
	
	// USAGE: This function should be set to the "onfocus" and/or the "onkeydown" event of the element
	// elemId = ID of the element to track
	// minRows = The minimum amount of rows you want to shrink the textarea to
	
	elem = document.getElementById(elemId);
	text = elem.value;
	cols = elem.cols;
	hard = 0;
	last = 0;
	
	soft = Math.floor(text.length / (cols));
	
	while ( true ) {
        last = text.indexOf("\n", last+1);
        if ( last == -1 ) break;
        hard++;
    }
	
	if ((soft + hard) < minRows)
		elem.rows = minRows;
	else
		elem.rows = (soft + hard);
}

function showOverlay(overlayId) {

	if (overlayId == null) {
		overlayId = 'overlay';
		messageId = 'overlay_msg';
	} else {
		messageId = overlayId + '_msg';
	}
	
	el = document.getElementById(overlayId);
	el.style.visibility = (el.style.visibility == "visible") ? "hidden" : "visible";
	
	el = document.getElementById(messageId);
	el.style.visibility = (el.style.visibility == "visible") ? "hidden" : "visible";
}

function clearDefaultValue(elemId, defaultText) {
	// USAGE: This function should be set to the "onfocus" event of the element
	// elemId = ID of the element to track
	// defaultText =  default text; needs to match the defaut "value" of the element.
	
	elem = document.getElementById(elemId);
	
	if (elem.value == defaultText) 
		elem.value = '';
}

function toggleDiv(divId) {
	el = document.getElementById(divId);
	el.style.display = (el.style.display == "block") ? "none" : "block";
}
