

// to avoid clashes, 
// all functions here must start with _formUtils_ 
//

/*
* checkContent - check number of characters in the mobycards promo information box
* Called when the user alters the textarea. Checks the maximum content length hasn't been exceeded, and truncates it if so.
*/
function _formUtils_checkContent( maxLength , elementName, counterElementName ) {
    var txtobj  = document.getElementById( elementName );
    var content = txtobj.value;
    if (content.length > maxLength) {
        alert('Maximum number of characters reached: ' + maxLength );
        content = content.substring( 0, maxLength );
        txtobj.value = content;
    }
    _formUtils_updateCounter( content, counterElementName, maxLength );
    return true;

}

function _formUtils_updateCounter( content, counterElementName, maxChars ) {

    var obj = document.getElementById( counterElementName );
    obj.innerHTML   = content.length + '/' + maxChars + ' chars';
}

