    function ShowPic(sPicURL) {
        window.open('/profile/blog/preview?image='+sPicURL, '', 'resizable=1,HEIGHT=200,WIDTH=200, scrollbars=yes');
    }
    
    var lastDiv;
    lastDiv = 's';

    var lastEditBox;

    function setLastEditBox(x) 
    {
        if (lastEditBox != null)
            lastEditBox.style.display = 'none';

        lastEditBox = x;
        x.style.display = 'inline';
    }

    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');
            var tree_field = document.getElementById('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) {
        if (orig != null)
        {
            var parent_node = orig.parentNode;
            var next_sibling = orig.nextSibling;
            if (to_swap != null)
            {
                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('Please, enter post content'); 
        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 if (current.type == 'submit')
                {
                    current.onclick = function () {return false;}
                    current.style.color = '#888888';
                }
                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);
        edCanvas = document.getElementById('post_text');
    }

    function checkPostEdit(frm, liveDivS) {
        if (document.getElementById('post_text').value == '')
            alert('Please, enter post content'); 
        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('Please, type the comment'); 
        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 if (current.type == 'submit')
                {
                    current.onclick = function () {return false;}
                    current.style.color = '#888888';
                }
                else 
                    cp[current.name] = current.value;
            }
            cp['xe'] = 'commentAdded';
            //alert(liveDiv.div);
            liveDiv.executeAction('submit', cp);
        }
        return false
    }

    function commentFailed(html)
    {
        var lastDiv_div = document.getElementById(lastDiv);
        lastDiv_div.innerHTML = html;
        alert(html);
        // bringin toolbar panel back 
        edToolbar("comm_quicktags");
    }

    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);
        try {
        if (lastDiv != 's')
            qr_div.parentNode.parentNode.insertBefore(nd, qr_div.parentNode.nextSibling);
        else
            qr_div.parentNode.insertBefore(nd, qr_div.nextSibling);
        } catch (e) 
        {
            //alert(e);
        }
        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';
        }
        try {
        	nd.innerHTML = String(html);
        } catch (e) {
            //alert(e.message);
        }
        nd.style.display = 'inline';
        qr_div.style.display = 'none';
    }


var jsCurrentUser;

function localize(s)
{
    if (s == 'said') return document.write('wrote');
}

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>Reason:</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, 'Vote positively:', CLOSECLICK, RELX, -200, 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>Reason:</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, 'Vote negatively:', CLOSECLICK, RELX, -200, 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 showCommentReportWindow(rowID, liveDivS)
{
    var reply = prompt("Why do you report this comment for review?", "")
    if(reply == "" || !reply) {
        alert('Describe the reason of report to continue');
    } else {
        liveDiv = eval(liveDivS);
        liveDiv.executeAction('comment_report', {'xe' : 'finishCommentReport', 'ex' : rowID, 'why' : reply});
    }
}

function finishCommentReport(html, rowId)
{
    if (document.getElementById)
    {
        reportEl = document.getElementById('report_'+rowId);
        if (reportEl)
        {
            reportEl.style.display="font-weight: bold";
            reportEl.innerHTML = "reported!";
        }
    }
}

function showCommentDeleteWindow(rowID, liveDivS)
{
    if(confirm('Press OK to confirm delete'))
    {
        liveDiv = eval(liveDivS);
        liveDiv.executeAction('comment_delete', {'xe' : 'finishCommentDelete', 'ex' : rowID});
    }
}

function finishCommentDelete(html, rowId)
{
    if (document.getElementById)
    {
        postDiv = document.getElementById('com'+rowId);
        if (postDiv)
        {
            postDiv.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>Processing edit request...</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];

    postTag = new String();
    postTag = "postContent" + rowID;
    
    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 style='width:85%' type=submit value=\'Save changes\'></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";
    }   
}


// change comments's category

function showCommCatChangeWindow(rowID, catId, liveDivS)
{
    if(confirm('Press OK to change category'))
    {
        liveDiv = eval(liveDivS);
        liveDiv.executeAction('category_change', {'xe' : 'finishCommCatChange', 'id' : rowID, 'cat_id' : catId, 'ex' : liveDivS});
    }
}

function finishCommCatChange(html, divID)
{
    liveDiv = eval(divID);
    liveDiv.fetchBuffer(liveDiv.offset);
}

/* Post related functions */

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>Processing edit request...</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;
        setLastEditBox(x);
        edToolbar("comm_quicktags");
        edCanvas = document.getElementById('post_text');
    }
}



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>Processing edit request...</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];

    postTag = new String();
    postTag = "pp" + rowID;
    
    if (document.getElementById)
    {
        var x = document.getElementById(postTag);
        setLastEditBox(x);
        x.innerHTML = html;
    }
    //edToolbar("comm_quicktags");
}

function resetPostEdit(html, rowID)
{
    nd();
    resultArray = rowID.split(':|:');
    rowID = resultArray[0];
    divID = resultArray[1];
    liveDiv = eval(divID);
    liveDiv.fetchBuffer(liveDiv.offset);
}

function showTopicDeleteWindow(rowID, liveDivS)
{
    showPostDeleteWindow(rowID, liveDivS);
}

function showPostDeleteWindow(rowID, liveDivS)
{
    if(confirm('Press OK to confirm delete'))
    {
        liveDiv = eval(liveDivS);
        liveDiv.executeAction('post_delete', {'xe' : 'finishPostDelete', 'id' : rowID, 'ex' : liveDivS});
    }
}

function finishPostDelete(html, divID)
{
    liveDiv = eval(divID);
    liveDiv.fetchBuffer(liveDiv.offset);
}

// change topic's category

function showPostCatChangeWindow(rowID, catId, liveDivS)
{
    if(confirm('Press OK to change category'))
    {
        liveDiv = eval(liveDivS);
        liveDiv.executeAction('category_change', {'xe' : 'finishPostCatChange', 'id' : rowID, 'cat_id' : catId, 'ex' : liveDivS});
    }
}

function finishPostCatChange(html, divID)
{
    liveDiv = eval(divID);
    liveDiv.fetchBuffer(liveDiv.offset);
}

// display last comments

function callShowLastPost(rowID, liveDivS)
{
    if (document.getElementById)
    {
        overlib('<div id=\'indicator\'></div>', STICKY, WIDTH, 50, RELY,0,RELX, -1,CSSCLASS,TEXTFONTCLASS,'OLfontClass',FGCLASS,'OLfgClass', BGCLASS,'OLbgClass',CAPTIONFONTCLASS,'OLcapfontClass', CLOSEFONTCLASS, 'OLcapfontClass');
        liveDiv = eval(liveDivS);
        liveDiv.executeAction('last_post', {'id' : rowID, 'ld': liveDivS, 'xe' : 'displayLastPost'});
    }
}

function displayLastPost(dataLine)
{
    if (document.getElementById)
    {
        dataLine = dataLine + '<div onClick=\'javascript: nd();\' class=\'closeButton\'></div>';
        overlib(dataLine, STICKY, WIDTH, 500, ABOVE, LEFT, CSSCLASS,TEXTFONTCLASS,'OLfontClass',FGCLASS,'OLfgClass', BGCLASS,'OLbgClass',CAPTIONFONTCLASS,'OLcapfontClass', CLOSEFONTCLASS, 'OLcapfontClass');
    }
        
}

function displayLastPostFloat(dataLine)
{
    if (document.getElementById)
    {
        dataLine = dataLine + '<a href=\'javascript:void(0);\' onClick=\'nd();\' onMouseOver=\'nd();\' class=\'closeButton\'></div>';
        overlib(dataLine, STICKY, WIDTH, 500, ABOVE, RIGHT, CSSCLASS,TEXTFONTCLASS,'OLfontClass',FGCLASS,'OLfgClass', BGCLASS,'OLbgClass',CAPTIONFONTCLASS,'OLcapfontClass', CLOSEFONTCLASS, 'OLcapfontClass');
    }
        
}