// JavaScript Document

function textCounter(field, maxlimit, countfield) {

  var currentLength = field.value.length;
  var charCount = 0;
  
  if(countfield != null)  {
    charCount = countfield.value;
  }
  
  charCount = maxlimit - currentLength;
  
  if(countfield != null)  {
    if (charCount > 0) {
      countfield.value = charCount;
    } else {
      countfield.value = 0;
    }
  }  

  if (currentLength > maxlimit) {
    alert('You exceeded the maximum allowable characters.  Some text may have been lost.  Please review before sending.');
    field.value = field.value.substring(0, maxlimit);
    return false;
  }
  
  return true;
}
