/*
    проект l2top.ru компании © GDTeam, 2006-20010.
    разработчик crocodile
    //--------------------------------------------------------------------------
    библиотека JS функций для работы l2top
*/
//определение функции экранирования кирилици в запросах
var trans = [];
for (var i = 0x410; i <= 0x44F; i++)
    trans[i] = i - 0x350; // А-Яа-я
    trans[0x401] = 0xA8;    // Ё
    trans[0x451] = 0xB8;    // ё

    // Сохраняем стандартную функцию escape()
    var escapeOrig = window.escape;

    // Переопределяем функцию escape()
    window.escape = function(str)
    {
      var ret = [];
      // Составляем массив кодов символов, попутно переводим кириллицу
      for (var i = 0; i < str.length; i++)
      {
        var n = str.charCodeAt(i);
        if (typeof trans[n] != 'undefined')
          n = trans[n];
        if (n <= 0xFF)
          ret.push(n);
      }
      return escapeOrig(String.fromCharCode.apply(null, ret));
    }
//-----------------------------------------------------------------------------
    function voteDec(id, i, typ) {
        itm = new loadList('id='+id+'&act=dec&t='+typ, 'commVote'+i);
        poll_list.push(itm);
        load_itms();
        disable();
        itm=document.getElementById('commVoteButton'+i+'r');
        itm.innerHTML = '<img src="/images/voteUD.gif" alt="Up" border="0">';
        itm.style.color = '#bbb';
        itm=document.getElementById('commVoteButton'+i+'l');
        itm.innerHTML = '<img src="/images/voteDD.gif" alt="Down" border="0">';
        itm.style.color = '#bbb';

    }
//-----------------------------------------------------------------------------
    function voteInc(id, i, typ) {
        itm = new loadList('id='+id+'&act=inc&t='+typ, 'commVote'+i);
        poll_list.push(itm);
        load_itms();
        disable();
        itm=document.getElementById('commVoteButton'+i+'r');
        itm.innerHTML = '<img src="/images/voteUD.gif" alt="Up" border="0">';
        itm.style.color = '#bbb';
        itm=document.getElementById('commVoteButton'+i+'l');
        itm.innerHTML = '<img src="/images/voteDD.gif" alt="Down" border="0">';
        itm.style.color = '#bbb';
    }
//-----------------------------------------------------------------------------
    function disable() {
        if (document.getElementById('makeVote') != null) {
	        v = document.getElementById('makeVote').innerHTML;
	        if (v>1) {
	            document.getElementById('makeVote').innerHTML = v-1;
	            return;	        }
            document.getElementById('makeVote').innerHTML = v-1;
        } else {            return;
        }
        for (i=1; i<15; i++) {
            itm=document.getElementById('commVoteButton'+i+'r');
            if (itm==null) {
                return false;
            }
            itm.innerHTML = '<img src="/images/voteUD.gif" alt="Up" border="0">';
            itm.style.color = '#bbb';
            itm=document.getElementById('commVoteButton'+i+'l');
            itm.innerHTML = '<img src="/images/voteDD.gif" alt="Down" border="0">';
            itm.style.color = '#bbb';
        }
    }
//-----------------------------------------------------------------------------
    function printBadC(id, text) {
        itm = document.getElementById('commentText'+id).style.display = '';
        itm = document.getElementById('additComm'+id).style.display = 'none';
    }
//-----------------------------------------------------------------------------
    function quote(id) {
        document.getElementById('text').value += '[quote='+id+']\n';
        window.location.href = '#comment';
    }
//-----------------------------------------------------------------------------
    function BBEsc(text) {
        r = '[$1]';
        p = /\<([\/]{0,1}[biu])\>/gi
        text = text.replace(p, r);
        return text;
    }
//-----------------------------------------------------------------------------
    function BBC(itm, code) {
        insertTag(code, itm);
    }
//-----------------------------------------------------------------------------
    eSearcType = '';
    function BBE(type, name) {
        if (document.getElementById('serchMenu').innerHTML=='' || eSearcType!=type) {
            eSearcType = type;
            name = '';
            itm = new loadList('t='+type+'&name='+name, 'serchMenu');
            poll_list.push(itm);
            load_itms();
            eSearcType = type;
        } else {
            document.getElementById('serchMenu').innerHTML = '';
        }
    }
//-----------------------------------------------------------------------------
    function BBSerch() {
        name = document.getElementById('eSearchName').value;
        itm = new loadList('t='+eSearcType+'&name='+name, 'serchMenu');
        poll_list.push(itm);
        load_itms();
        document.getElementById('loader').innerHTML = '<img src="/ajax-loader.gif" alt="" border=0>';
    }
//-----------------------------------------------------------------------------
    function BBEInsetr(type, id) {
        insertTag('['+type+'='+id+']');
        document.getElementById('serchMenu').innerHTML = '';
    }
//-----------------------------------------------------------------------------
    function pushNick(id) {
    /*добавляет ник в меню редактирования */
        name = document.getElementById('nick'+id).innerHTML;
        name = BBEsc(name);
        name = '[b]'+name+'[/b], ';
        document.getElementById('text').value += name;
        window.location.href = '#comment';
    }
//-----------------------------------------------------------------------------
    function hideItem(name) {
        /*
            функция скрывающая/показывающая элемент html
        */
        var item = document.getElementById(name);
        if(item.style.display != 'none')
            item.style.display = 'none';
        else
            item.style.display = '';
    };
//-----------------------------------------------------------------------------
        document.onkeydown = keyDown;
        LostKeyPush = 0;
        autoSerch = 0;
        function keyDown(ev) {
          if (!ev) ev = window.event;
          if (ev.which!=null)
            Key = ev.which;
          else
            Key = window.event.keyCode;
          autoSerch = 0;
          //Ctrl | Alt + Enter
          LostKeyPush = Key;
        }
//-----------------------------------------------------------------------------
    function eSearchAutoSend() {
        if (LostKeyPush==13)
            BBSerch();
        if (autoSerch>1) {
            autoSerch--;
            setTimeout('eSearchAutoSend()', 1000);
        } else if (autoSerch==1) {
            autoSerch = 1;
            BBSerch();
        } else if (document.getElementById('eSearchName').value.length>2 && autoSerch==0) {
            autoSerch = 3;
            setTimeout('eSearchAutoSend()', 1000);
        }
    }
//-----------------------------------------------------------------------------