﻿// based on http://www.quirksmode.org/book/examplescripts/maxlength/textarea.js


function setMaxLength(textareaId, maxLength, statusId)
{
    var textareaControl = document.getElementById(textareaId);
    var statusControl = document.getElementById(statusId);

    if (!textareaControl) return;
    
    var attribute = document.createAttribute("maxlength");
    attribute.nodeValue = maxLength;
    textareaControl.setAttributeNode(attribute); 

    statusControl.value = '0/' + maxLength;
    textareaControl.relatedElement = statusControl;
    textareaControl.onkeyup = textareaControl.onchange = checkMaxLength;
    textareaControl.onkeyup();
}

function checkMaxLength()
{
    var maxLength = this.getAttribute('maxlength');
    var currentLength = this.value.length;
    
    if (currentLength > maxLength)
        this.relatedElement.className = 'textBoxOverflow';
    else
        this.relatedElement.className = '';
        
    this.relatedElement.innerHTML = currentLength + '/' + maxLength;
}
