var iPerPost=0; //Money Per Post
var iMoneySign=""; //Money Symbol
var iMoneyName="Points"; //Name of money

if(document.modifyForm && document.modifyForm.customtitle){
      var iCustom=document.modifyForm.customtitle;
      iCustomTr=iCustom.parentNode.parentNode.parentNode;
      var iPosts=document.modifyForm.posts.value;
      var iMoney=iCustomTr.cloneNode(true);
      iMoney.childNodes[0].firstChild.innerHTML=iMoneyName;
      iMoney.childNodes[1].innerHTML='<input type="text" size="35" maxlength="30" id="iMonInp" disabled="true" value="'+(parseInt(iPosts)*parseInt(iPerPost))+'" /><b'+'r /><b'+'r /><div style="float: left;"><input type="text" size="5" maxlength="25" id="iAddInp" /><a onclick="javascript: iAddMoney(this)" style="cursor: pointer;">Add</a></div><div style="float: right;"><input type="text" size="5" maxlength="25" id="iMinusInp" /><a onclick="javascript: iAddMoney(this)" style="cursor: pointer;">Minus</a> &nb'+'sp; &nb'+'sp; </div>';
      iMoney.childNodes[2].firstChild.innerHTML='This is the user\'s amount of '+iMoneyName+' that will be displayed in their mini profile. Use the functions on the left to alter the amount.';
      iCustomTr.parentNode.insertBefore(iMoney, iCustomTr.nextSibling);
      var iMonInp=document.getElementById('iMonInp');
      iHoldChange=0;
      if(iCustom.value.match(/\[M0n:(.+?)\]/)){
            iHoldChange=RegExp.$1;
            iMonInp.value=parseInt(RegExp.$1)+parseInt(iMonInp.value);
            iCustom.value=iCustom.value.replace(/\[M0n:(.+?)\]/g, '');
      }
      if(document.addEventListener){
            document.modifyForm.addEventListener('submit', iSaveMoney, false);
            document.modifyForm.posts.addEventListener('keyup', function(){
                  iMonInp.value=parseInt(iHoldChange)+(this.value*iPerPost);
            }, false);
      }
    else{
            document.modifyForm.attachEvent('onsubmit', iSaveMoney);
            document.modifyForm.posts.attachEvent('onkeyup', function(){
                  iMonInp.value=parseInt(iHoldChange)+(document.modifyForm.posts.value*iPerPost);
            });
    }
}
function iSaveMoney(){
      var iCustom=document.modifyForm.customtitle;
      var iMonInp=document.getElementById('iMonInp').value;
      var iPosts=document.modifyForm.posts.value;
      var iDefault=iPerPost*iPosts;
      if(iDefault!=iMonInp && !iMonInp.match(/NaN/)){
            iAddition=parseInt(iMonInp)-parseInt(iDefault);
            iCustom.value=iCustom.value+'[M0n:'+iAddition+']';
      }
}
function iAddMoney(iLink){
      var iMonInp=document.getElementById('iMonInp');
      iSum=iMonInp.value;
      var iPrev=iLink.previousSibling;
      if(!iPrev.value.match(/^(\d+)$/)){
            alert('Please only insert numerals.');
      }
      else if(iLink.innerHTML=="Add" && iPrev.value.match(/^(\d+)$/)){
            iSum=parseInt(iMonInp.value)+parseInt(RegExp.$1);
            iHoldChange=parseInt(iHoldChange)+parseInt(RegExp.$1);
      }
      else if(iLink.innerHTML=="Minus" && iPrev.value.match(/^(\d+)$/)){
            iSum=parseInt(iMonInp.value)-parseInt(RegExp.$1);
            iHoldChange=parseInt(iHoldChange)-parseInt(RegExp.$1);
      }
      iPrev.value='';
      iMonInp.value=iSum;
}
if(location.href.match(/action=(display|viewprofile|(user)?recent|(calendar|pm)view|search2)/) || location.href.match(/index.cgi$/) && document.title.match(/Preview/) && document.postForm){
      var iTd=document.getElementsByTagName('td');
      var i=iTd.length;
      while(--i){
            if(iTd.item(i).width=="20%" && iTd.item(i).className.match(/windowbg(2)?/) && iTd.item(i).vAlign=="top" && iTd.item(i).innerHTML.match(/Posts:\s(.+?)<br\s?\/?>/i)){
                  var iAddIt=(iTd.item(i).innerHTML.match(/\[M0n:(.+?)\]/))? RegExp.$1 : '0';
                  var iPost=(iTd.item(i).innerHTML.match(/Posts:\s(.+?)<br\s?\/?>/i))? RegExp.$1.replace(/,/g, '')*iPerPost : '';
                  var iMonSpan=document.createElement('span');
                  iMonSpan.innerHTML='<b'+'r />'+iMoneyName+': '+iMoneySign+(parseInt(iAddIt)+(iPost));
                  iTd.item(i).appendChild(iMonSpan);
                  iTd.item(i).innerHTML=iTd.item(i).innerHTML.replace(/(<br\s?\/?>)?\[M0n:(.+?)\]/gi, '');
            }
      }
}