    var lastDiv;
    lastDiv = 's';

    function quickreply(tree) {
        if (! document.getElementById) return false;
    }

    function quickQuote(poster,postID,pCount) {

        qqTag = 'qq' + postID + '.' + pCount;
        
        if (document.getElementById)
        {
            var s;
            s = new String(document.getElementById(qqTag).innerHTML);
            s = s.replace(/\n/g, "");
            s = s.replace(/\r/g, "");
            s = s.replace(/\t/g, "");
            document.getElementById('comment_text').value += "[qq." + postID + "." + pCount +".][i]" + poster + " said:[/i][br]" + s + "[/qq]\n\n";
            quickreply(postID);

            tree = postID;
            var tree_field = document.getElementById('comment_tree');
            if (tree != 'fake_s')
                tree_field.value = tree;

            var qr_div = document.getElementById('s');
            var cur_div = document.getElementById(tree);

            if (lastDiv == 's') {
                qr_div.style.display = 'inline';

                // only one swap
                swapnodes(qr_div, cur_div);
            } else if (lastDiv != tree) {
                  var last_div = document.getElementById(lastDiv);

                  // Two swaps
                  swapnodes(last_div, cur_div);
                  swapnodes(qr_div, last_div);
            }

            lastDiv = tree;
            // So it doesn't follow the link
            return false;
        }
    }

    function swapnodes (orig, to_swap) {
        var parent_node = orig.parentNode;
        var next_sibling = orig.nextSibling;
        to_swap.parentNode.replaceChild(orig, to_swap);
        parent_node.insertBefore(to_swap, next_sibling);
        return true;
    }
    
    function checkPostAdd(frm, liveDivS) {
        if (document.getElementById('post_text').value == '')
            alert('Пожалуйста, введите текст'); 
        else
        {
            var cp = [];
            for (var i=0; i < frm.length; i++)
            {
                current = frm.elements[i];
                // no selects
                if (current.type == 'radio' || current.type == 'checkbox')
                {
                    if (current.checked) cp[current.name] = current.value;
                }
                else 
                    cp[current.name] = current.value;
            }
            cp['xe'] = 'postAdded';
            cp['ex'] = liveDivS;
            liveDiv = eval(liveDivS);
            liveDiv.executeAction('submit_new', cp);
        }
        return false;
    }

    function postAdded(html, liveDivS)
    {
        liveDiv = eval(liveDivS);
        liveDiv.fetchBuffer(liveDiv.offset);
    }

    function checkPostEdit(frm, liveDivS) {
        if (document.getElementById('post_text').value == '')
            alert('Пожалуйста, введите текст'); 
        else
        {
            overlib('<div id=\'indicator\'></div>', WIDTH, 50, RELY,0,RELX, -1,CSSCLASS,TEXTFONTCLASS,'OLfontClass',FGCLASS,'OLfgClass', BGCLASS,'OLbgClass',CAPTIONFONTCLASS,'OLcapfontClass', CLOSEFONTCLASS, 'OLcapfontClass');
            var cp = [];
            for (var i=0; i < frm.length; i++)
            {
                current = frm.elements[i];
                // no selects
                if (current.type == 'radio' || current.type == 'checkbox')
                {
                    if (current.checked) cp[current.name] = current.value;
                }
                else 
                    cp[current.name] = current.value;
            }
            cp['xe'] = 'resetPostEdit';
            cp['ex'] = liveDivS;
            liveDiv = eval(liveDivS);
            liveDiv.executeAction('submit_edit', cp);
        }
        return false;
    }

    function checkComment(frm, liveDiv) {
        if (document.getElementById('comment_text').value == '')
            alert('Пожалуйста, введите комментарий'); 
        else
        {
            var cp = [];
            for (var i=0; i < frm.length; i++)
            {
                current = frm.elements[i];
                // no selects
                if (current.type == 'radio' || current.type == 'checkbox')
                {
                    if (current.checked) cp[current.name] = current.value;
                }
                else 
                    cp[current.name] = current.value;
            }
            cp['xe'] = 'commentAdded';
            liveDiv.executeAction('submit', cp);
        }
        return false
    }

    function commentAdded(html, p)
    {
        var lastDiv_div = document.getElementById(lastDiv);
        var qr_div = document.getElementById('s');
        var nd = document.createElement('div');
        nd.setAttribute('id', p);
        if (lastDiv != 's')
            qr_div.parentNode.parentNode.insertBefore(nd, qr_div.parentNode.nextSibling);
        else
            qr_div.parentNode.insertBefore(nd, qr_div.nextSibling);
        //if (lastDiv != 's') 
        //{
        //    var tree_field = document.getElementById('comment_tree');
        //    tree_field.value = null;
        //    var f_div = document.getElementById('fake_s');
        //     swapnodes(lastDiv_div, f_div);
        //    lastDiv = 's';
        //}
        nd.innerHTML = html;
        nd.style.display = 'inline';
        qr_div.style.display = 'none';
    }


var jsCurrentUser;

function localize(s)
{
    if (s == 'said') return document.write('написал');
}

function showPosOptions (ID, currentuser, nriDiv, liveDivS)
{
    if (document.getElementById)
    {
        jsCurrentUser = currentuser;
        var posListArray = posModOptionList.split(':.:');
        
        var dataLine = "<table border=0><tr><td><small>0.0001</small></td><td><div class='slider' id='slider-" + nriDiv + "' tabIndex='1'><input class='slider-input' id='slider-input-" + nriDiv + "' name='slider-input-" + nriDiv + "'/></div></td><td><small>" + document.getElementById(nriDiv + 'value').innerHTML 
                + " </small></td><td><select onChange='submitModeration(this.value, 1, " + ID + ", \"" + liveDivS + "\"); return nd();'><option>Причина:</option>";
        
        for (var i=0; i < posListArray.length; i++)
        {
            posLineArray = posListArray[i].split('::');
            if (posLineArray[0] != "")
            {
                dataLine = dataLine + "<option value='" + posLineArray[0] + "'>" + posLineArray[1] + "</option>";
            }
        }
        dataLine = dataLine + "</select></td></tr></table>";
        
        overlib(dataLine, STICKY, CAPTION, 'Оценить положительно:', CLOSECLICK, HAUTO, ABOVE, CSSCLASS,TEXTFONTCLASS,'OLfontClass',FGCLASS,'OLfgClass', BGCLASS,'OLbgClass',CAPTIONFONTCLASS,'OLcapfontClass', CLOSEFONTCLASS, 'OLcapfontClass');   
        
        var postSlider = new Slider(document.getElementById("slider-" + nriDiv),document.getElementById("slider-input-" + nriDiv));
        
        var maxNRI = document.getElementById(nriDiv + 'value').innerHTML * 1000;
        
        postSlider.setMaximum(maxNRI);
        postSlider.setMinimum(1);
        postSlider.setUnitIncrement(1); 
        
        postSlider.onchange = function () { document.getElementById(nriDiv).innerHTML = (postSlider.getValue() / 1000); };
        postSlider.setValue(maxNRI);        
    }
    
}

function showNegOptions (ID, currentuser, nriDiv, liveDivS)
{
    if (document.getElementById)
    {
        jsCurrentUser = currentuser;
        var posListArray = negModOptionList.split(':.:');
        var dataLine = "<table border=0><tr><td><small>0.0001</small></td><td><div class='slider' id='slider-" + nriDiv + "' tabIndex='1'><input class='slider-input' id='slider-input-" + nriDiv + "' name='slider-input-" + nriDiv + "'/></div></td><td><small>" + document.getElementById(nriDiv + 'value').innerHTML 
                + " </small></td><td><select onChange='submitModeration(this.value, 2, " + ID + ", \"" + liveDivS + "\"); return nd();' style='float:right;'><option>Причина:</option>";
        
        for (var i=0; i < posListArray.length; i++)
        {
            posLineArray = posListArray[i].split('::');
            if (posLineArray[0] != "")
            {
                dataLine = dataLine + "<option value='" + posLineArray[0] + "'>" + posLineArray[1] + "</option>";
            }
        }
        
        dataLine = dataLine + "</select></td></tr></table>";
        
        overlib(dataLine, STICKY, CAPTION, 'Оценить отрицательно:', CLOSECLICK, HAUTO, ABOVE, CSSCLASS,TEXTFONTCLASS,'OLfontClass',FGCLASS,'OLfgClass', BGCLASS,'OLbgClass',CAPTIONFONTCLASS,'OLcapfontClass', CLOSEFONTCLASS, 'OLcapfontClass');   
        
        var postSlider = new Slider(document.getElementById("slider-" + nriDiv),document.getElementById("slider-input-" + nriDiv));
        
        var maxNRI = document.getElementById(nriDiv + 'value').innerHTML * 1000;
        
        postSlider.setMaximum(maxNRI);
        postSlider.setMinimum(1);
        postSlider.setUnitIncrement(1); 
        
        postSlider.onchange = function () { document.getElementById(nriDiv).innerHTML = (postSlider.getValue() / 1000); };
        postSlider.setValue(maxNRI);        
    }   
}

function submitModeration(reason, posNeg, ID, liveDivS)
{
    nd();
    if (document.getElementById)
    {
        var amountToMod = document.getElementById(ID + 'currentNRI').innerHTML;
        liveDiv = eval(liveDivS);
        liveDiv.executeAction('comment_rating', {'amount' : amountToMod, 'reason' : reason, 'posNeg' : posNeg, 'ld': liveDivS, 'ex' : ID, 'xe' : 'changeModLine'});
    }   
}

// Scores....

function changeModLine(html, par)
{
    var modLineArray = par.split(':|:');
    postTag = "postRating" + modLineArray[0];
    
    if (document.getElementById)
    {
        var x = document.getElementById(postTag);
        x.innerHTML="<div class='moderateLine'>" + html + "</div>";
        //x.parentNode.parentNode.parentNode.parentNode.previousSibling.id = modLineArray[2];
        //applyThreshold();
        
        liveDiv = eval(modLineArray[1]);
        liveDiv.executeAction('update_comment_mark', {'xe' : 'updateComment', 'ex' : modLineArray[0]});
    }   
}

function updateComment(html, par)
{
    postTag = new String();
    postTag = "comment" + par;
    
    if (document.getElementById)
    {
        var x = document.getElementsByTagName('div');
        
        for (var i=0;i<x.length;i++)
        {
            
            if (x[i].className == postTag)
            {   
                x[i].style.display = 'block';
                x[i].innerHTML = html;
                
            }
        }
    }
}

// Inline edit....

function showCommentDeleteWindow(rowID, liveDivS)
{
    if(confirm('Нажми на OK для подтверждения удаления'))
    {
        liveDiv = eval(liveDivS);
        liveDiv.executeAction('comment_delete', {'xe' : 'finishCommentDelete', 'ex' : rowID});
    }
}

function finishCommentDelete(html, rowId)
{
    if (document.getElementById)
    {
        postDiv = document.getElementById(rowId);
        if (postDiv)
        {
            postDiv.parentNode.style.display="none";
        }
    }
}

function showCommentEditWindow(rowID, liveDivS)
{
    overlib('<div id=\'indicator\'></div>', WIDTH, 50, RELY,0,RELX, -1,CSSCLASS,TEXTFONTCLASS,'OLfontClass',FGCLASS,'OLfgClass', BGCLASS,'OLbgClass',CAPTIONFONTCLASS,'OLcapfontClass', CLOSEFONTCLASS, 'OLcapfontClass');
    postTag = new String();
    postTag = "postContent" + rowID;
    ratingTag = "postRating"+ rowID;
    if (document.getElementById)
    {
        var x = document.getElementById(postTag);
        x.innerHTML="<b>Обработка запроса на редактирование...</b>";
        
        var ratingLine = document.getElementById(ratingTag);
        ratingLine.style.display="none";
    }
    liveDiv = eval(liveDivS);
    liveDiv.executeAction('show_edit', {'id' : rowID, 'xe' : 'updateCommentEditWindow', 'ex' : rowID + ':|:' + liveDivS});
}

function updateCommentEditWindow(html, rowID)
{
    nd();
    resultArray = rowID.split(':|:');
    rowID = resultArray[0];
    divID = resultArray[1];
    
    if (document.getElementById)
    {
        var x = document.getElementById(postTag);
        x.innerHTML="<form name=editForm onSubmit=\"return callSubmitCommentEdit(\'" + divID + "\', \'" + rowID + "\');\"><textarea name=editText" + rowID + " cols=60 rows=15 style='width: 98%'>" + html + "</textarea><br/><input class=button type=submit value=\'Сохранить изменения\'></form>";

    }
}

function callSubmitCommentEdit(divID, rowID)
{
    overlib('<div id=\'indicator\'></div>', WIDTH, 50, RELY,0,RELX, -1,CSSCLASS,TEXTFONTCLASS,'OLfontClass',FGCLASS,'OLfgClass', BGCLASS,'OLbgClass',CAPTIONFONTCLASS,'OLcapfontClass', CLOSEFONTCLASS, 'OLcapfontClass');
    var textAreas = document.getElementsByTagName("textarea");
    textAreaName = new String();
    textAreaName = "editText" + rowID;
    submitVal = new String();
    var cp = [];
    cp['xe'] = 'resetCommentEdit';
    cp['ex'] = rowID;
    for (var i=0;i<textAreas.length;i++)
    {
        if (textAreas[i].name==textAreaName)
        {
            cp['comment'] = textAreas[i].value;
        }
    }
    liveDiv = eval(divID);
    //Object.dpDump(liveDiv, "asdf", false, 1);
    liveDiv.executeAction('submit_edit', cp);
    
    return false;
}

function resetCommentEdit(html, rowID)
{
    
    nd();
    postTag = new String();
    ratingTag = new String();
    postTag = "postContent" + rowID;
    ratingTag = "postRating"+ rowID;
    
    
    if (document.getElementById)
    {
        var x = document.getElementById(postTag);
        x.innerHTML=html;
                

        var postRating = document.getElementById(ratingTag);    
        postRating.style.display="block";
    }   
}

function showPostNewWindow(liveDivS)
{
    overlib('<div id=\'indicator\'></div>', WIDTH, 50, RELY,0,RELX, -1,CSSCLASS,TEXTFONTCLASS,'OLfontClass',FGCLASS,'OLfgClass', BGCLASS,'OLbgClass',CAPTIONFONTCLASS,'OLcapfontClass', CLOSEFONTCLASS, 'OLcapfontClass');
    postTag = new String();
    postTag = "add_blog_post";
    if (document.getElementById)
    {
        var x = document.getElementById(postTag);
        x.innerHTML="<b>Обработка запроса на редактирование...</b>";
    }
    liveDiv = eval(liveDivS);
    var req=[];
    req['xe'] = 'updatePostNewWindow';
    req['ex'] = liveDivS;
    liveDiv.executeAction('show_new', req);
}

function updatePostNewWindow(html, rowID)
{
    nd();
    
    if (document.getElementById)
    {
        var x = document.getElementById('add_blog_post');
        x.innerHTML=html;

    }
}



function showPostEditWindow(rowID, liveDivS)
{
    overlib('<div id=\'indicator\'></div>', WIDTH, 50, RELY,0,RELX, -1,CSSCLASS,TEXTFONTCLASS,'OLfontClass',FGCLASS,'OLfgClass', BGCLASS,'OLbgClass',CAPTIONFONTCLASS,'OLcapfontClass', CLOSEFONTCLASS, 'OLcapfontClass');
    postTag = new String();
    postTag = "pp" + rowID;
    if (document.getElementById)
    {
        var x = document.getElementById(postTag);
        x.innerHTML="<b>Обработка запроса на редактирование...</b>";
    }
    liveDiv = eval(liveDivS);
    liveDiv.executeAction('show_edit', {'id' : rowID, 'ld': liveDivS, 'xe' : 'updatePostEditWindow', 'ex' : rowID + ':|:' + liveDivS});
}

function updatePostEditWindow(html, rowID)
{
    nd();
    resultArray = rowID.split(':|:');
    rowID = resultArray[0];
    divID = resultArray[1];
    
    if (document.getElementById)
    {
        var x = document.getElementById(postTag);
        x.innerHTML = html;
    }
}

function resetPostEdit(html, rowID)
{
    resultArray = rowID.split(':|:');
    rowID = resultArray[0];
    divID = resultArray[1];
    liveDiv = eval(divID);
    liveDiv.fetchBuffer(liveDiv.offset);
}


function showPostDeleteWindow(rowID, liveDivS)
{
    if(confirm('Нажми на OK для подтверждения удаления'))
    {
        liveDiv = eval(liveDivS);
        liveDiv.executeAction('post_delete', {'xe' : 'finishPostDelete', 'id' : rowID, 'ex' : liveDivS});
    }
}

function finishPostDelete(html, divID)
{
    liveDiv = eval(divID);
    liveDiv.fetchBuffer(liveDiv.offset);
}

//////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////
/* Smooth scrolling
   Changes links that link to other parts of this page to scroll
   smoothly to those links rather than jump to them directly, which
   can be a little disorienting.
   
   sil, http://www.kryogenix.org/
   
   v1.0 2003-11-11
   v1.1 2005-06-16 wrap it up in an object
*/

var ss = {
  fixAllLinks: function() {
    // Get a list of all links in the page
    var allLinks = document.getElementsByTagName('a');
    // Walk through the list
    for (var i=0;i<allLinks.length;i++) {
      var lnk = allLinks[i];
      if ((lnk.href && lnk.href.indexOf('#') != -1) && 
          ( (lnk.pathname == location.pathname) ||
	    ('/'+lnk.pathname == location.pathname) ) && 
          (lnk.search == location.search)) {
        // If the link is internal to the page (begins in #)
        // then attach the smoothScroll function as an onclick
        // event handler
        ss.addEvent(lnk,'click',ss.smoothScroll);
      }
    }
  },

  smoothScroll: function(e) {
    // This is an event handler; get the clicked on element,
    // in a cross-browser fashion
    if (window.event) {
      target = window.event.srcElement;
    } else if (e) {
      target = e.target;
    } else return;

    // Make sure that the target is an element, not a text node
    // within an element
    if (target.nodeName.toLowerCase() != 'a') {
      target = target.parentNode;
    }
  
    // Paranoia; check this is an A tag
    if (target.nodeName.toLowerCase() != 'a') return;
  
    // Find the <a name> tag corresponding to this href
    // First strip off the hash (first character)
    anchor = target.hash.substr(1);
    // Now loop all A tags until we find one with that name
    var allLinks = document.getElementsByTagName('a');
    var destinationLink = null;
    for (var i=0;i<allLinks.length;i++) {
      var lnk = allLinks[i];
      if (lnk.name && (lnk.name == anchor)) {
        destinationLink = lnk;
        break;
      }
    }
    if (!destinationLink) destinationLink = document.getElementById(anchor);

    // If we didn't find a destination, give up and let the browser do
    // its thing
    if (!destinationLink) return true;
  
    // Find the destination's position
    var destx = destinationLink.offsetLeft; 
    var desty = destinationLink.offsetTop;
    var thisNode = destinationLink;
    while (thisNode.offsetParent && 
          (thisNode.offsetParent != document.body)) {
      thisNode = thisNode.offsetParent;
      destx += thisNode.offsetLeft;
      desty += thisNode.offsetTop;
    }
  
    // Stop any current scrolling
    clearInterval(ss.INTERVAL);
  
    cypos = ss.getCurrentYPos();
  
    ss_stepsize = parseInt((desty-cypos)/ss.STEPS);
    ss.INTERVAL =
setInterval('ss.scrollWindow('+ss_stepsize+','+desty+',"'+anchor+'")',10);
  
    // And stop the actual click happening
    if (window.event) {
      window.event.cancelBubble = true;
      window.event.returnValue = false;
    }
    if (e && e.preventDefault && e.stopPropagation) {
      e.preventDefault();
      e.stopPropagation();
    }
  },

  scrollWindow: function(scramount,dest,anchor) {
    wascypos = ss.getCurrentYPos();
    isAbove = (wascypos < dest);
    window.scrollTo(0,wascypos + scramount);
    iscypos = ss.getCurrentYPos();
    isAboveNow = (iscypos < dest);
    if ((isAbove != isAboveNow) || (wascypos == iscypos)) {
      // if we've just scrolled past the destination, or
      // we haven't moved from the last scroll (i.e., we're at the
      // bottom of the page) then scroll exactly to the link
      window.scrollTo(0,dest);
      // cancel the repeating timer
      clearInterval(ss.INTERVAL);
      // and jump to the link directly so the URL's right
      location.hash = anchor;
    }
  },

  getCurrentYPos: function() {
    if (document.body && document.body.scrollTop)
      return document.body.scrollTop;
    if (document.documentElement && document.documentElement.scrollTop)
      return document.documentElement.scrollTop;
    if (window.pageYOffset)
      return window.pageYOffset;
    return 0;
  },

  addEvent: function(elm, evType, fn, useCapture) {
    // addEvent and removeEvent
    // cross-browser event handling for IE5+,  NS6 and Mozilla
    // By Scott Andrew
    if (elm.addEventListener){
      elm.addEventListener(evType, fn, useCapture);
      return true;
    } else if (elm.attachEvent){
      var r = elm.attachEvent("on"+evType, fn);
      return r;
    } else {
      alert("Handler could not be removed");
    }
  } 
}

ss.STEPS = 25;

ss.addEvent(window,"load",ss.fixAllLinks);