//<!--
/*
	forms.js
	Date: 10-6-05 moved from template headers into this file.
	Purpose:
		functionality for the form elements on Ratings and Rebuttals template pages.
	Dependencies:
*/

/**
 * controls behavior of the 'counter' element that is linked to the rating/rebuttal
 * input box.
 * @param counter_ctl The counter control
 * @param textarea_ctl The textarea box whose length we are checking
 * @param max_len The maximum length of the textarea input
 */
function update(counter_ctl, textarea_ctl, max_len) {
   var old = counter_ctl.value;
   counter_ctl.value = textarea_ctl.value.length;
   if (counter_ctl.value > max_len && old <= max_len) {
   alert('Too many characters in the comments box');
     if (document.styleSheets) {
       counter_ctl.style.fontWeight = 'bold';
       counter_ctl.style.color = 'black';
     }
   } else if (counter_ctl.value <= max_len && old > max_len
	       && document.styleSheets ) {
       counter_ctl.style.fontWeight = 'normal';
       counter_ctl.style.color = 'black';
   }
}

/**
 * Don't permit the text in the textarea exceed max_len.
 * This disables typing in IE, but firefox keeps replacing the last character.
 * @param textarea_ctl The textarea box whose length we are checking
 * @param evt The global event object
 * @param max_len The maximum length of the textarea input
 */
function checkMaxLength (textarea_ctl, evt, max_len) {
  if (textarea_ctl.selected && evt.shiftKey)
    // ignore shift click for select
    return true;
  var allowKey = false;
  if (textarea_ctl.selected && textarea_ctl.selectedLength > 0)
    allowKey = true;
  else {
    var keyCode = document.layers ? evt.which : evt.keyCode;
    if (keyCode == 13) {
        return false;
    } else if (keyCode < 32) {
        allowKey = true;
    } else {
    	if (navigator.appName.indexOf("Netscape")!=-1 && textarea_ctl.value.length >= max_len-1) {
        	textarea_ctl.value = textarea_ctl.value.substr(0, max_len);
        }
        allowKey = textarea_ctl.value.length < max_len;
    }
  }
  textarea_ctl.selected = false;
  return allowKey;
}
// -->