/*
Characters Left Counter
http://s9.invisionfree.com/iFusion/
*/

function charsLeft(){
  var cFont = document.createElement("font");
  var cTxt = document.createTextNode("Characters Left: ");
  var iCounter = document.createElement("input");

  iCounter.id = "postcounter";
  iCounter.size = "6";
  iCounter.value = "60000";
  iCounter.disabled = true;
  cFont.style.fontWeight = "bold";
  cFont.size = "2";
  cFont.appendChild(cTxt);

  if(document.REPLIER.Post){
      with(document.REPLIER){
        Post.parentNode.appendChild(document.createElement("br"));
        Post.parentNode.appendChild(cFont);
        Post.parentNode.appendChild(iCounter);
      }
  }
}

function iMaths(){
  if(document.REPLIER.Post && document.getElementById("postcounter")){
      var postLen = document.REPLIER.Post.value.length;
      document.getElementById("postcounter").value = 60000 - postLen;
      if(document.getElementById("postcounter").value < 0){
        document.getElementById("postcounter").value = 0;
      }
  }
}

if(location.href.match(/act=Post/i)){
  charsLeft();
  document.onkeypress = iMaths;
  document.onkeydown = iMaths;
  window.onload = iMaths;
}