var overLimit = 0;
var max_attempts = 1; // warning on second attempt
/**
  Checks the length of a form element (normally textarea), and if the length is more than the maximum characters,
  it truncates it.   A warning is also given after max_attempts at exceeding the limit.
  @param	textarea	the textarea to check (as a DOM object - recommended "this").
  @param	maxLength	the maximum number of characters.
  @date	2009-08-18
  @author	Tristan Roberts - WebVentures.
*/

function checkLength(textarea, maxLength) {
  if (textarea.value.length > maxLength) {
    textarea.value = textarea.value.substring(0, maxLength);
    if (overLimit > max_attempts) {
      alert('Sorry, please enter a maximum of ' + maxLength + ' characters.');
    }
    overLimit++;
  }
}

function adviseWrap(textarea, maxLength) {
  if (textarea.value.length > maxLength) {
    textarea.value = textarea.value.substring(0, maxLength);
    if (overLimit > max_attempts) {
      alert('Sorry, a maximum of ' + maxLength + ' characters is possible.  Please use the next field for overflow text.');
    }
    overLimit++;
  }
}

