// idea from http://www.alistapart.com/articles/scripttriggers/
// parts from plone_javascripts.js
// (2005) by Jodok Batlogg <batlogg@solution2u.net>

function registerPloneFunction(func){
    // registers a function to fire onload. 
    // Turned out we kept doing this all the time
    // Use this for initilaizing any javascript that should fire once the page has been loaded. 
    // 
    if (window.addEventListener) window.addEventListener("load",func,false);
    else if (window.attachEvent) window.attachEvent("onload",func);
}

function restrictMaxlength() {
  var x = document.getElementsByTagName('textarea');
  for (var i=0;i<x.length;i++) {
    if (x[i].getAttribute('maxlength')) {
      x[i].onkeyup = checkLength;
      x[i].onchange = x[i].onkeyup;
      x[i].onkeyup();
    }  }
}
registerPloneFunction(restrictMaxlength)
function checkLength() {  counter = document.getElementById(this.id + '_charsleft');
  counter.value = this.getAttribute('maxlength') - this.value.length;
  if (counter.value < 1) {
    counter.className = "notify";
  } else {
    counter.className = "";
  }  }