function limit_chars(textarea, limit, info, msg, emesg) {
    if (!msg) msg = 'You have %d characters left.';
    var text = textarea.value;
    var textlength = text.length;

    if (textlength > limit) {
        //info.html('You cannot write more than ' + limit + ' characters!');
        //info.html('<span class="errtxt">Exceeded!</span>');
        info.html('<span class="errtxt">' + emesg + '</span>');
        textarea.value = text.substr(0,limit);
        return false;
    } else {
        info.html(msg.replace('%d', limit - textlength));
        return true;
    }
}
