// count the number of characters left before it reaches the max.
function charCount(field, countfield, myMax) {
        // if too long, trim it
        if (field.value.length > myMax)
                field.value = field.value.substring(0, myMax);
        // otherwise, update 'characters left' label
        else
                countfield.value = myMax - field.value.length;
}


// count the number of words left before it reaches the max.
function wordCount(field, countfield, myMax) {
        var myCounter=0;
        for (x=0;x<field.value.length;x++) {
                if (field.value.charAt(x) == " " && field.value.charAt(x-1) != " ")  {
                        myCounter++;
                }
                if (myCounter > myMax) {
                        field.value = field.value.substring(0, x);
                } else {
                        countfield.value = myMax - myCounter;
                }
        }
}

