// Prints one or multiple Textarea(s) which will limit the text to a maximum length
// Tested on Firefox 1.5 and 3.0 and Internet Explorer 6.0 and 7.0
// For details about JavaScript events try the sample at the bottom of the page:
// mediaevent.de/javascript/onkeydown.html
// on various browsers to study the multiple differences!

// ATTENTION: onKeyDown and onKeyUp will NOT work here!!
function OnTextareaKeyPress(oEvent, oArea, MaxLen)
{
    Chr = -1;
    if (window.event) // MSIE (does not fire DEL, BACKSPACE keys)
    {
        // event.charCode is undefined on MSIE!!
        Chr = window.event.keyCode;
    }
    else if (oEvent) // Firefox (fires also DEL, BACKSPACE keys with charCode=0)
    {
        // oEvent.keyCode returns nonsense but NOT the ASCII code on Firefox!!
        Chr = oEvent.charCode;
    }

    // return false to block characters if text too long
    // return true for all control keys!!
    return (Chr < 32 || oArea.value.length < MaxLen);
}

// Shorten PASTED texts which cannot be captured in OnTextareaKeyPress()
function OnTextareaKeyUp(oArea, MaxLen)
{
    if (oArea.value.length > MaxLen)
        oArea.value = oArea.value.substring(0, MaxLen);
}
