Namespace.register("UB")
window.onload = function () { U.M.OLM(); U.M.stopRefresh(); }

//主页面收藏文件夹数据创建区域
UB.FVC_SU = function (e, d) {
    var i, a, f = $$("frag");
    for (i = 0; i < e.length; i++) {
        a = $$("div", { "id": e[i].CateID, "className": "CFV_T", "onclick": [[ChangeColor, (["this"])], [UB.CK, ([e[i]])]] }, f);
        $$("div", { "className": "AF_A_B AF_A_A" }, a); $$("div", { "className": "AF_A_D", "innerHTML": e[i].CateName }, a);
    }
    d.appendChild(f);
}

//辅助函数 后台给收藏框添加 Title和Url
CUAT = function (url, t) {
    $("#A_T_V")[0].value = t;
    $("#A_T_U")[0].value = url;
}

//点击改变颜色
function ChangeColor(obj) {
    var i, a = (obj ? $(obj).parentg() : $("#CFV_C")).Child();
    for (i = 0; i < a.length; i++) { a[i].style.backgroundColor = (obj == a[i]) ? "#99ccff" : ""; }
}

//辅助函数 给指定的div赋予value值
UB.CK = function (e) {
    var i, c = ["AscFV", "DelFV"];
    for (i = 0; i < c.length; i++) { $("#" + c[i])[0].value = e.Guid; }
}

//添加 收藏条目到数据库
UB.FVDef = function (id) {
    var a = $("#A_T_V")[0].value.Trim(), b = $("#A_T_U")[0].value.Trim();
    if (a && b && id && UB.UID != "") { WE.AddFV(a, b, id, UB.UID); WE.OpenAddFVC(''); alert("添加成功"); }
    else { alert(!UB.UID ? "请登录1473" : !id ? "请选择文件夹" : "完善收藏内容"); }
}

//添加文件夹按钮点击事件
UB.FVCAdd = function (oId) {
    if (!$("#AddFVC")[0]) {
        var a = $$("div", { "className": "CFV_T" }, $("#" + oId)[0]);
        $$("div", { "className": "AF_A_B AF_A_A" }, a);
        var b = $$("div", { "className": "AF_A_D" }, a);
        $$("input", { "type": "text", "id": "AddFVC", "onclick": U.M.StopBubble, "onblur": [[UB.isFVCAdd, ([a])]], "onkeyup": [[U.M.returnkeylogin, ([null, [[UB.isFVCAdd, ([a])]]])]] }, b).focus();
        $("#AscFV")[0].value = ""; $("#DelFV")[0].value = ""; ChangeColor();
    }
}

//判断是否创建文件夹
UB.isFVCAdd = function (a) {
    try {
        var b = $(a).Child(); c = $(b[1]).Child()[0].value.Trim();
        if (c == "") { $(a).remove(); }
        else if (UB.UID) { WE.FVCadd(UB.UID, c, U.M.getFun(UB.AsynFVCAdd, a, b)); }
        else { WE.OpenAddFVC(''); }
    } catch (e) { }
}


//异步添加
UB.AsynFVCAdd = function (a, b, json) {
    var _e = eval("(" + json + ")")[0]; UB.Cate.push(_e);
    b[1].innerHTML = $("#AddFVC")[0].value; a.id = _e.CateID;
    (a.onclick = U.M.apply(a, [[ChangeColor, ([a])], [UB.CK, ([_e])]]))();
}

//删除收藏文件夹及以内收藏
UB.FVC_DEL = function (id) {
    if (id && confirm("真的要删除么？")) {
        WE.DelFVC(_this, U.M.getFun(UB.AsynFVC_DEL, id))
    }
}

UB.AsynFVC_DEL = function (id, json) {
    var e = eval('(' + json + ')');
    if (e.TF == 1) {
        for (var i = 0; UB.Cate.length; i++) { UB.Cate.splice(i, 1); break; }
        $("#" + id).remove();
    }
} 