_GLOBAL_VAR["sectionTitleTip"] = "Section Heading";
_GLOBAL_VAR["sectionDescTip"] = "Description";

function saveSection(sectionIndex, type) {
    var f = $("sectionForm_"+sectionIndex);
    var url = "/bookmark_list/save_section";
    var title = f.title.value.trim();
    var desc = f.desc.value.trim();
    if(title=='' && desc==''){
        return false;
    }
    if(title==_GLOBAL_VAR["sectionTitleTip"] && desc==_GLOBAL_VAR["sectionDescTip"]){
        return false;
    }
    showCentralNoticer(DIS_10);
    new Ajax.Request(url,
    {
        asynchronous:true,
        evalScripts:false,
        onComplete:function(request){
            saveSectionComplete(request, sectionIndex, type)
            },
        parameters:Form.serialize(f)
        }
    );
    return false;
}
function addSection() {
    var editor = $("sectionForm_-1");
    var holder = $("sectionEditorHolder");
    if(editor) {
        editor.remove();
    }
    new Insertion.Top(holder, makeSectionEditor("-1", "create"));
    holder.show();
}
function editSection(sectionIndex) {
    switchSectionView(sectionIndex, "update");
}

function makeSectionEditor(sectionIndex, type) {
    var form = document.createElement("form");
    form.className = "sectionForm";
    form.name = "sectionForm";
    form.method = "post";
    form.id = "sectionForm_"+sectionIndex;
    form.action = "javascript:void(0);";
    form.setAttribute("autocomplete", "off");
    form.onsubmit = function(){
        saveSection(sectionIndex, type); return false;
    };
    
        
    var input = new Element("input", {
        "type":"text",
        "class":"firstIinputTxt",
        "name":"title"
    });
    input.size = "60";
    input.maxlength = "255";
    input.style.marginRight = "5px";
    input.style.color = "#777";
    input.value = _GLOBAL_VAR["sectionTitleTip"];
    
    input.onfocus = function(){
        if(this.value.trim()==_GLOBAL_VAR["sectionTitleTip"]){
            this.value="";
            this.style.color = "#000";
        }
        }
    input.onblur = function(){
        if(this.value.blank()){
            this.value=_GLOBAL_VAR["sectionTitleTip"];
            this.style.color = "#777";
        }
        }
    var d = new Element("div");
    d.appendChild(input)
    form.appendChild(d);
    
    input = document.createElement("input");
    input.type = "hidden";
    input.name = "list_id";
    input.value = _GLOBAL_VAR['list_id'];
    d = new Element("div");
    d.appendChild(input)
    form.appendChild(d);
    
    if(type=="update") {
        input = document.createElement("input");
        input.type = "hidden";
        input.name = "section_id";
        input.value = _GLOBAL_VAR['bookmarks'][sectionIndex].itemId;
        form.appendChild(input);
    }
        
    // description
    var txtA = new Element("textarea", {
        "class":"firstITextarea",
        "name":"desc"
    })
    txtA.style.color = "#777";
    txtA.value = _GLOBAL_VAR["sectionDescTip"];
    txtA.onfocus = function(){
        if(this.value.trim()==_GLOBAL_VAR["sectionDescTip"]){
            this.value="";
            this.style.color = "#000";
        }
        }
    txtA.onblur = function(){
        if(this.value.blank()){
            this.value=_GLOBAL_VAR["sectionDescTip"];
            this.style.color = "#777";
        }
        }
    
    form.appendChild(txtA);
    

    var d = new Element("div", {
        "class":"btnRow"
    })
    
    // submit
    input = document.createElement("input");
    input.type = "submit";
    input.className = "firstIBtn";
    input.value = "Add Section";
    d.appendChild(input);
    
    // cancel
    var aCancel = document.createElement("a");
    aCancel.href = "javascript:void(0);";
    aCancel.className = "cancelLink";
    aCancel.innerHTML = "Cancel";
    aCancel.onclick = function() {
        switchSectionView(sectionIndex, type)
        };
    d.appendChild(aCancel);
    
    form.appendChild(d);
    
    return form;
}
function initSectionEditor(sectionIndex) {
    var form = $("sectionForm_"+sectionIndex);
    if(form) {
        form.title.value = _GLOBAL_VAR['bookmarks'][sectionIndex].title;
        if(form.title.value.blank()){
            form.title.value = _GLOBAL_VAR["sectionTitleTip"];
            form.title.style.color = "#777";
        }
        form.desc.value = _GLOBAL_VAR['bookmarks'][sectionIndex].desc;
        if(form.desc.value.blank()){
            form.desc.value = _GLOBAL_VAR["sectionDescTip"];
            form.desc.style.color = "#777";
        }
    }
}
function initSectionDisplay(sectionIndex) {
    $("sectionTitle_"+sectionIndex).innerHTML= _GLOBAL_VAR['bookmarks'][sectionIndex].title;
    $("sectionDesc_"+sectionIndex).innerHTML= _GLOBAL_VAR['bookmarks'][sectionIndex].desc;
}
function switchSectionView(sectionIndex, type) {
    if(type=="create") {
        $("sectionForm_"+sectionIndex).style.display = "none";
    }else {
        section = $("sDisplayTemp_"+sectionIndex);
        if(section.style.display=="") {
            section.style.display = "none";
            if($("sectionForm_"+sectionIndex)) $("sectionForm_"+sectionIndex).style.display = "";
            else new Insertion.Top("bookmarkItem_"+sectionIndex, makeSectionEditor(sectionIndex, "update"));
            initSectionEditor(sectionIndex);
        }else {
            section.style.display = "";
            $("sectionForm_"+sectionIndex).style.display = "none";
            initSectionDisplay(sectionIndex);
        }
    }
    return false;
}
function renderNewSection(section) {
    var newSection = document.createElement("li");
    newSection.id = "bookmarkListContent_"+section.position;
    newSection.setAttribute("pIndex", section.itemIndex);
    
    var item = document.createElement("div");
    item.id = "bookmarkItem_"+section.itemIndex;
    item.className = "sectionItem";

    var drag = document.createElement("div");
    drag.className = "dragHandler";
    item.appendChild(drag);
    
    var div = document.createElement("div");
    div.id = "sDisplayTemp_"+section.itemIndex;
    div.className = "sectionItemDisplayTemp";
    
    // title
    var span = document.createElement("span")
    span.id = "sectionTitle_"+section.itemIndex;
    span.innerHTML = section.title;
    span.onclick = function(){
        editSection(section.itemIndex);
    };
    span.className = "sectionTitle";
    span.style.cursor = "text";
    span.style.display = "block";
    span.setAttribute("onmouseover", "this.style.backgroundColor='#ffffcc'");
    span.setAttribute("onmouseout", "this.style.backgroundColor='#f5f5f5'");
    div.appendChild(span);
    
    // description
    var p = document.createElement("p")
    p.id = "sectionDesc_"+section.itemIndex;
    p.innerHTML = section.desc;
    p.onclick = function(){
        editSection(section.itemIndex);
    };
    p.style.cursor = "text";
    p.className = "sectionDesc";
    p.style.display = "block";
    p.setAttribute("onmouseover", "this.style.backgroundColor='#ffffcc'");
    p.setAttribute("onmouseout", "this.style.backgroundColor='#f5f5f5'");
    div.appendChild(p);
    
    var opt = new Element("div", {
        id:"bookmarkItem_menu_"+section.itemIndex,
        className:"menuBox"
    });
    opt.innerHTML = "<a href=\"javascript:void(0);\" id=\"bookmarkItem_menu_item_"+section.itemIndex+"_5\"  onclick=\"removeBFromList.bind(this, "+section.itemIndex+")();\">Remove from list</a>";
    opt.innerHTML += " | <a href=\"javascript:void(0);\" id=\"bookmarkItem_menu_item_"+section.itemIndex+"_1\"  onclick=\"moveToTop.bind(this, "+section.itemIndex+")();\">Top</a>";
    opt.innerHTML += " | <a href=\"javascript:void(0);\" id=\"bookmarkItem_menu_item_"+section.itemIndex+"_2\"  onclick=\"moveToBottom.bind(this, "+section.itemIndex+")();\">Bottom</a>";
    opt.innerHTML += " | <a href=\"javascript:void(0);\" id=\"bookmarkItem_menu_item_"+section.itemIndex+"_3\"  onclick=\"moveUp.bind(this, "+section.itemIndex+")();\">Up</a>";
    opt.innerHTML += " | <a href=\"javascript:void(0);\" id=\"bookmarkItem_menu_item_"+section.itemIndex+"_4\"  onclick=\"moveDown.bind(this, "+section.itemIndex+")();\">Down</a>";
    div.appendChild(opt);
    item.appendChild(div)
    
    newSection.appendChild(item);
    newSection.onmouseover = hoverMenuBox.bind(newSection);
    newSection.onmouseout = outMenuBox.bind(newSection);
    
    new Insertion.Top("bookmarkListContent", newSection);
    
    //initBookmarkFloatMenu();
    
    initSortable();
    
    var updatedRange = [_GLOBAL_VAR['bookmarks'][section.itemIndex].position];
    var indexSequence = Sortable.sequence("bookmarkListContent");
    updatedRange[1] = indexSequence[0];
    setNewSequence(updatedRange, indexSequence);
    
}

function saveSectionComplete(request, sectionIndex, type) {
    hideCentralNoticer();
    if(request.status=="200") {
        var result = request.responseText.evalJSON();
        if(type=="create") {
            var section = {};
            section.title = result["title"];
            section.desc = result["desc"];
            section.itemIndex = _GLOBAL_VAR['bookmarks'].length;
            section.index = section.itemIndex;
            section.itemType = ITEM_TYPE_SECTION;
            section.position = result["position"];
            section.itemId = result["section_id"];
            _GLOBAL_VAR['bookmarks'].push(section);
            switchSectionView("-1", type);
            $("sectionEditorHolder").hide();
            renderNewSection(section);
        }else {
            var section = _GLOBAL_VAR['bookmarks'][sectionIndex];
            section.title = result["title"];
            section.desc = result["desc"];
            switchSectionView(sectionIndex, type);
        }
    }else if(request.status=="400") {
		
    }else if(request.status=="500") {
        alert(EXC_1);
    }
}


function newListSubmit() {
    var form = document.forms["newListForm"];
    var url = "/bookmark_list/new_list";
    loading("newListLoader", "medium");
    $("newListSubmitBtn").disabled = true;
    new Ajax.Request(url,
    {
        asynchronous:true,
        evalScripts:false,
        onComplete:function(request){
            newListSubmitComplete(request)
            },
        parameters:Form.serialize(form)
        }
    );
    return false;
}

function newListSubmitComplete(request) {
    loadComplete("newListLoader");
    $("newListSubmitBtn").disabled = false;
    if(request.status=="200") {
        var item = request.responseText.evalJSON();
        mylightWindow.deactivate();
        appendBListItem(item);
    }else {
}
}

function loadUserBLists() {
    var url = "/bookmark_list/load_user_b_list?u_name="+_GLOBAL_VAR['username'];
    loading("bookmarkListLoader");
    new Ajax.Request(url,
    {
        asynchronous:true,
        evalScripts:false,
        onComplete:function(request){
            loadUserBListsComplete(request)
            }
    });
    return false;
}
function loadUserBListsComplete(request) {
    loadComplete("bookmarkListLoader");
    if(request.status=="200") {
        _GLOBAL_VAR['lists'] = request.responseText.evalJSON();
        renderBLists(_GLOBAL_VAR['lists']);
    }else {
}
}
function renderBLists(lists) {
    var ul = $("bookmarkListUL");
    for(var i=0; i<lists.length; i++) {
        var li = document.createElement("li");
        li.id = "bListItem_"+i;
        var a = document.createElement("a");
        a.innerHTML = lists[i].title;
        a.href = BOOKMARK_HOST+"/list/"+lists[i].uri;
        li.appendChild(a);
        ul.appendChild(li);
    }
}
function appendBListItem(item) {
    item.index = _GLOBAL_VAR['lists'].length;
    _GLOBAL_VAR['lists'].push(item);
    var ul = $("bookmarkListUL");
    var li = document.createElement("li");
    li.id = "bListItem_"+(_GLOBAL_VAR['lists'].length-1);
    var a = document.createElement("a");
    a.innerHTML = item.title;
    a.href = BOOKMARK_HOST+"/list/"+item.uri;
    li.appendChild(a);
    ul.appendChild(li);
//new Effect.Highlight(li);
}

function generatorOff() {
    clearInterval(_GLOBAL_VAR['geneTimer']);
}

function generatorOn() {
    _GLOBAL_VAR['geneTimer'] = setInterval(generateUri, 200);
}
function generateUri() {
    var form = document.forms["listForm"];
    title = form.title.value.trim();
    title = title.replace(/[^\d\w\-\_\s]/g, '');
    form.uri.value = title.underscore().replace(/\s+/g, "-");
}

function isValidTitle(titleEl){
    var title = titleEl.value.trim();
    if(title=="") {
        flashNotice2(DIS_19, "noticer_title");
        return false;
        titleEl.focus();
    }
    return true;
}

function isValidURI(uriEl){
    var uri = uriEl.value.trim();
    var uriRule = /[^\d\w\-\_\s]/;
    if(uri=="" || uriRule.test(uri) || uri.length>100) {
        flashNotice2(DIS_21, "noticer_uri");
        return false;
        uriEl.focus();
    }
    return true;
}

function selPrivacy(mode){
    if(mode==2) {
        $("catOption").hide();
    }else {
        $("catOption").show();
    }
}
function submitListBefore(type) {
    try {
        var form = document.forms["listForm"];
        if(!isValidTitle(form.title)) {
            return false;
        }
        if(form.privacy[0].checked && form.cat.value=="0") {
            flashNotice2(DIS_20, "noticer_cat");
            return false;
        }
        // new list
        if(type==0) {
            if(!isValidURI(form.uri)) {
                return false;
            }
        // update list
        }else {
    }
    }catch(e) {
        return false;
    }
    return true;
}

function privateView() {
    window.location.href='/list/'+_GLOBAL_VAR['username'].toLowerCase()+'/'+_GLOBAL_VAR['list'].uri;
}

function editList(uri) {   
    self.location.href = '/bookmark_list/edit_list?uri='+uri;
}
function deleteList(listID) {
    if(confirm('Delete list?')){self.location.href='/bookmark_list/delete_list?list_id='+listID;}
}
function archiveList(listID){
    var url = "/bookmark_list/archive_list";
    showCentralNoticer(DIS_10);
    new Ajax.Request(url,
    {
        asynchronous:true,
        evalScripts:false,
        parameters:{
            list_id:listID
        },
        onComplete:function(request){
            if(request.status=="200"){
                hideCentralNoticer();
                $("list_"+listID).remove();
                $("archive_list_num").innerHTML = parseInt($("archive_list_num").innerHTML) +1;
                $("active_list_num").innerHTML = parseInt($("active_list_num").innerHTML) - 1;
            }
        }
    });
    return false;
}

function activeList(listID){
    var url = "/bookmark_list/active_list";
    showCentralNoticer(DIS_10);
    new Ajax.Request(url,
    {
        asynchronous:true,
        evalScripts:false,
        parameters:{
            list_id:listID
        },
        onComplete:function(request){
            if(request.status=="200"){
                hideCentralNoticer();
                $("list_"+listID).remove();
                $("archive_list_num").innerHTML = parseInt($("archive_list_num").innerHTML) - 1;
                $("active_list_num").innerHTML = parseInt($("active_list_num").innerHTML) + 1;
            }
        }
    });
    return false;
}


function forwardList() {
}
function publishListAndPublicView() {
    var url = "/bookmark_list/publish_list";
    showCentralNoticer(DIS_10);
    new Ajax.Request(url,
    {
        asynchronous:true,
        evalScripts:false,
        onComplete:function(request){
            hideCentralNoticer();
            if(request.status=="200") {
                publicView();
            }else if(request.status=="500"){
                alert(EXC_1);
            }
            },
        parameters:"list_id="+_GLOBAL_VAR['list'].list_id
        });
    return false;
}

function printList(u) {
    var url = u || window.location.href;
    url = url + (url.indexOf('?')!=-1 ? "&print=1" : "?print=1");
    var w = window.open(url, null);
}

/*------------------------------------------------
 * list item sortable
 *-----------------------------------------------*/
function listChanged() {
}
function listUpdated() {
    try{
        outMenuBox.bind($(_GLOBAL_VAR['lastUpdatedBItem']))();
        var itemPrefix = "bookmarkListContent_";
        var lastUpdatedItemIndex = _GLOBAL_VAR['lastUpdatedBItem'].split("_")[1];
        var lastUpdatedItem = _GLOBAL_VAR['bookmarks'][$(_GLOBAL_VAR['lastUpdatedBItem']).getAttribute("pIndex")];
        var indexSequence = Sortable.sequence("bookmarkListContent");
        //console.log(indexSequence);
        var updatedItem = [];
        var updatedRange = [parseInt(lastUpdatedItemIndex)];
        var preIndex = parseInt(indexSequence[0]);
        for(var k=0; k<indexSequence.length; k++) {
            i = parseInt(indexSequence[k]);
            if(i==lastUpdatedItemIndex) {
                if(preIndex==i) {
                    updatedRange.push(parseInt(indexSequence[1]));
                }else
                if (preIndex>i) {
                    updatedRange.push(parseInt(preIndex));
                }else {
                    updatedRange.push(parseInt(preIndex)+1);
                }
                break;
            }
            preIndex = i;
        }

        //console.log("move:"+updatedRange[0]+" to:"+updatedRange[1]);
    
        // down to up
        if(updatedRange[0] > updatedRange[1]) {
            $(itemPrefix+updatedRange[0]).id = itemPrefix+"temp";
            for(var i=updatedRange[0]-1; i>=updatedRange[1]; i--) {
                var item = $(itemPrefix+i);
                if(item) {
                    item.id = itemPrefix+(i+1);
                }
            }
            $(itemPrefix+"temp").id = itemPrefix+updatedRange[1];
        // up to down
        }else {
            $(itemPrefix+updatedRange[0]).id = itemPrefix+"temp";
            for(var i=updatedRange[0]+1; i<=updatedRange[1]; i++) {
                var item = $(itemPrefix+i);
                if(item) {
                    item.id = itemPrefix+(i-1);
                }
            }
            $(itemPrefix+"temp").id = itemPrefix+updatedRange[1];
        }
        syncServer(lastUpdatedItem, updatedRange);
        return false;
    }catch(e) {
    //alert("An exception occured in the script.Error name: " + e.name + ".Error message: " + e.message);
    }
}
function syncLocalModel(updatedRange) {
    var bIndex;
    _GLOBAL_VAR['bookmarks'].each(function(b) {
        if(b.position==updatedRange[0]) bIndex=b.itemIndex;
    });
    // down to up
    if(updatedRange[0] > updatedRange[1]) {
        _GLOBAL_VAR['bookmarks'].each(function(b) {
            if(b.position<updatedRange[0] && b.position>=updatedRange[1]) {
                b.position++;
            }
                
        });
    // up to down
    }else {
        _GLOBAL_VAR['bookmarks'].each(function(b) {
            if(b.position>updatedRange[0] && b.position<=updatedRange[1])
                b.position--;
        });
    }
    _GLOBAL_VAR['bookmarks'][bIndex].position = updatedRange[1];
}
function syncServer(lastUpdatedItem, updatedRange) {
    var url = "/bookmark_list/update_position";
    var jsonInfos = $H({
        list_id:_GLOBAL_VAR['list_id'],
        item_id:lastUpdatedItem.itemId,
        update_range:updatedRange,
        item_type:lastUpdatedItem.itemType
        }).toJSON();
    showCentralNoticer(DIS_10);
    new Ajax.Request(url,
    {
        asynchronous:true,
        evalScripts:false,
        onComplete:function(request){
            if(request.status=="200") {
                hideCentralNoticer();
                syncLocalModel(updatedRange);
            }else if(request.status=="500"){
                alert(EXC_1);
            }
            },
        parameters:"json_infos="+jsonInfos
        }
    );
    return false;
}

function initSortable() {
    try {
        Sortable.create("bookmarkListContent",
        {
            dropOnEmpty:true,
            hoverclass:'hoverListItem',
            handle:'dragHandler',
            containment:["bookmarkListContent"],
            constraint:'vertical',
            scroll:window,
            scrollSensitivity:50,
            onChange:listChanged,
            onUpdate:listUpdated
        });
    }catch(e) {
    //alert("An exception occured in the script.Error name: " + e.name + ".Error message: " + e.message);
    }
}
function onHoverBListItem(element) {
    _GLOBAL_VAR['lastUpdatedBItem'] = element.id;
}

function setNewSequence(updatedRange, indexSequence) {   
    if(typeof(updatedRange[1])=="undefined" || updatedRange[0]==updatedRange[1]) return false;
    var aIndexRange = [];
    indexSequence.each(function(pos, index){
        if(pos==updatedRange[0]){
            aIndexRange[0] = index;
        }else if(pos==updatedRange[1]) {
            aIndexRange[1] = index;
        }
    });
    indexSequence.splice(aIndexRange[0], 1);
    var headA = indexSequence.slice(0, aIndexRange[1]);
    headA.push(updatedRange[0].toString());
    var tailA = indexSequence.slice(aIndexRange[1], indexSequence.length);
    var newSequence = headA.concat(tailA);
    Sortable.setSequence("bookmarkListContent", newSequence);
    _GLOBAL_VAR['lastUpdatedBItem'] = "bookmarkListContent_"+updatedRange[0];
    listUpdated();
}

function moveToTop() { 
    
    var index = arguments[0];
    var updatedRange = [_GLOBAL_VAR['bookmarks'][index].position];
    var indexSequence = Sortable.sequence("bookmarkListContent");
    updatedRange[1] = indexSequence[0];
    setNewSequence(updatedRange, indexSequence);
    outMenu.bind(this)();
}
function moveToBottom() {
    var index = arguments[0];
    var updatedRange = [_GLOBAL_VAR['bookmarks'][index].position];
    var indexSequence = Sortable.sequence("bookmarkListContent");
    updatedRange[1] = indexSequence.last();
    setNewSequence(updatedRange, indexSequence);
    outMenu.bind(this)();
}
function moveUp() {
    var index = arguments[0];
    var updatedRange = [_GLOBAL_VAR['bookmarks'][index].position];
    var indexSequence = Sortable.sequence("bookmarkListContent");
    indexSequence.each(function(pos, index){
        if(pos==updatedRange[0]) updatedRange[1] = indexSequence[index-1];
    });
    setNewSequence(updatedRange, indexSequence);
    outMenu.bind(this)();
}
function moveDown() {
    var index = arguments[0];
    var updatedRange = [_GLOBAL_VAR['bookmarks'][index].position];
    var indexSequence = Sortable.sequence("bookmarkListContent");
    indexSequence.each(function(pos, index){
        if(pos==updatedRange[0]) updatedRange[1] = indexSequence[index+1];
    });
    setNewSequence(updatedRange, indexSequence);
    outMenu.bind(this)();
}

/*-----------------------------------
 * guest book
 *-----------------------------------*/
 
function postGBComment(){
    var f = $("commentForm");
    if(f.cContent.value.blank() || f.captcha.value.blank()){
        return false;
    }
    var url = "/bookmark_list/add_gb_comment";
    var json = $H({
        lid : _GLOBAL_VAR['list'].list_id,
        list_owner_id : _GLOBAL_VAR['list'].owner_id,
        body : f.cContent.value,
        captcha : f.captcha.value
    }).toJSON();
    var subBtn = $("commentSubBtn");
    subBtn.value = "Processing...";
    subBtn.disabled = true;
    showCentralNoticer(DIS_10);
    new Ajax.Request(url,
    {
        asynchronous:true,
        evalScripts:false,
        onComplete:function(request){
            $("captchaIframe").src = $("captchaIframe").src;
            hideCentralNoticer();
            subBtn.value = "Add Comment";
            subBtn.disabled = false;
            if(request.status=="200") {
                var comments = $("gbComments");
                new Insertion.Bottom(comments, "<li class='gbItem'>"+request.responseText+"</li>");
                f.reset();
                var cIframe = $("gbCaptcha");
                if(cIframe){
                    cIframe.src = cIframe.src;
                }
                updateTotalCount(1);
                var cp = $("noticer_captcha");
                if(cp){
                    cp.hide()
                    }
            }else if(request.status=="400") {
                if(request.responseText=="captcha") {
                    flashNotice2("captcha error","noticer_captcha");
                }
            }
        },
        parameters:"json="+encodeURIComponent(json)
        });
    return false;
}
function updateTotalCount(count) {
    var totalCountEls = document.select('.gbCommentsTotal');
    totalCountEls.each(function(t) {
        t.update(parseInt(t.innerHTML)+count);
    });
}
function removeGBComment(pid) {
    var remover = this;
    var url = "/bookmark_list/delete_gb_comment";
    var json = $H({
        lid : _GLOBAL_VAR['list'].list_id,
        pid : pid
    }).toJSON();
    showCentralNoticer(DIS_10);
    remover.innerHTML = "processing...";
    new Ajax.Request(url,
    {
        asynchronous:true,
        evalScripts:false,
        onComplete:function(request){
            hideCentralNoticer();
            if(request.status=="200") {
                var r = request.responseText.evalJSON();
                if(r.code=="1") {
                    remover.up().remove();
                }
                updateTotalCount(-1);
            }
        },
        parameters:"json="+encodeURIComponent(json)
        });
    return false;
}

function removeBmClick(index){
    var b = $("bookmarkItem_"+index);
    var top = Position.cumulativeOffset(b)[1]-180;
    var pw = new PopWindow({optEnabled: true, left:100, top:top, title:"Remove Item",root:"leftColumn"});
    $('wContent').innerHTML = '';
    $('wSubmit').remove();
    $('wContent').innerHTML = '';
    new Insertion.Top('wOptions','<input id="removeFromListButton" type="button" style="width:120px;margin-right:5px;" value="Remove from list" />');
    $("removeFromListButton").onclick=function(){removeBFromList(index);PopWindow.instance.hide();};
    new Insertion.Top('wOptions','<input id="removeBmButton" type="button" style="width:130px;margin-right:5px;" value="Delete completely" />');
    $("removeBmButton").onclick = function(){deleteB(index);PopWindow.instance.hide();};
    pw.show();
}