
   // textarea management

   function setMaxLength() 
   {
      var x = document.getElementsByTagName('textarea');
      var counter = document.createElement('div');
      counter.className = 'counter';
      for (var i=0;i<x.length;i++)
      {
         if (x[i].getAttribute('maxlength')) 
         {
            var counterClone = counter.cloneNode(true);
            counterClone.relatedElement = x[i];
            counterClone.innerHTML = '<span>0</span> of '+x[i].getAttribute('maxlength')+' characters';
            x[i].parentNode.insertBefore(counterClone,x[i].nextSibling);
            x[i].relatedElement = counterClone.getElementsByTagName('span')[0];
            x[i].onkeyup = x[i].onchange = checkMaxLength;
            x[i].onkeyup();
         }
      }
   }

   function checkMaxLength() 
   {
      var maxLength = this.getAttribute('maxlength');
      var currentLength = this.value.length;
      if (currentLength > maxLength)
         this.relatedElement.className = 'alert';
      else
         this.relatedElement.className = '';
      this.relatedElement.firstChild.nodeValue = currentLength;
   }

   $(function() { setMaxLength(); });


   // comment display / hide

   function showComments(id,type)
   {  
      $("div#commentbar" + id + type + " a.commentshow").fadeOut("fast",function()
      {
         $("div#commentbar" + id + type + " a.commentworking").fadeIn("fast",function()
         {
            $("div#comments" + id + type).load("/comments.php?id=" + id + "&type=" + type,function()
            {
               $(this).slideDown("fast",function()
               {
                  $("div#commentbar" + id + type + " a.commentworking").fadeOut("fast",function()
                  {
                     $("div#commentbar" + id + type + " a.commenthide").fadeIn("fast");
                  });
               });
            });
         });
      });
   }

   function hideComments(id,type)
   {
      $("div#comments" + id + type)
         .slideUp("fast",function()
         {
            $("div#commentbar" + id + type + " a.commenthide").fadeOut("fast",function()
            {
               $("div#commentbar" + id + type + " a.commentshow").fadeIn("fast");
            });
         });
   }



