/* 弹出框选项 */
CmsData.Selects = {
    Open: function (id) {    //打开选择导航层
        if (!document.getElementById("Trans" + id)) {
            var html = "";
            html += "<div id='Trans" + id + "' class='transCenter' style='height:460px;overflow-y:auto;' >";
            html += "<iframe id='iframe" + id + "' style='width:100%;height:100%;border:0;' frameborder=\"0\" scrolling=\"auto\" ></iframe>";
            html += "</div>";
            html += "<div class='transBottom' >";
            html += "<input type=\"button\" class=\"btn btnsure\" value=\" 确 定 \" onclick=\"CmsData.Selects.BtnSure('" + id + "')\" />";
            html += "<input type=\"button\" class=\"btn btnclose\" value=\" 取 消 \" onclick=\"CmsData.Selects.BtnClose('" + id + "')\" />";
            html += "</div>";
            CmsData.Common.TransCreate("数据选择框", id, "width:650px;left:100px;top:20px; position:fixed;", 2, html);
        }

        var sql = "";
        switch (id) {
            case "CategoryIDS":
                sql = "&menuid=" + CmsData.Common.QueryString("menuid");
                break;
            default:
                sql = "&pagesize=10";
                break;
        }

        $("#iframe" + id).attr("src", "page.aspx?path=list&type=" + id + sql + "&r=" + Math.random());  //防缓存
        CmsData.Common.TransToggle(id);
    },
    BtnClose: function (id) {   //关闭窗口
        CmsData.Common.TransToggle(id);
    },
    BtnSure: function (id) {    //确定选择
        CmsData.Selects.Success(id);
        CmsData.Selects.BtnClose(id);
    },
    ID: function () {    //弹出列表 选择 获取ID集
        var id = "";
        switch (_Type) {
            case "CategoryIDS":
            case "NewsIDS":
            case "FileIDS":
            case "ProductIDS":
            case "Zip":
            case "CategoryNewsIDS":
            case "CategoryFileIDS":
            case "CategoryProductIDS":
            case "CategoryZip":
                id = _Type;
                break;
            default:
                break;
        }
        return id;
    },
    Checked: function (obj) {    //弹出列表 选择 设置对应ID选中及赋值
        var id = CmsData.Selects.ID();
        if (id != "") {
            var vals = $("#" + id, window.parent.document);
            var val = $(obj).val();
            switch (id) {
                case "Zip":
                case "CategoryZip":
                    if (obj.checked) {
                        vals.val(val);
                        $("#DataList table tbody tr input[name=CKRow]").attr("checked", false);
                        $(obj).attr("checked", true);
                    } else
                        vals.val("");
                    break;
                default:
                    if (obj.checked)
                        vals.val(vals.val() + val + ",");
                    else
                        vals.val(CmsData.Common.RemoveAt(vals.val(), val));
                    break;
            }
        }
    },
    Success: function (id) {    //选择完成
        switch (_Type) {
            case "Zip":
            case "CategoryZip":
                break;
            default:
                var html = "";
                var val = $("#" + id).val();
                if (val != "") {
                    $.ajax({
                        type: "get",
                        dataType: "json",
                        url: "dataajax.aspx?type=" + id + "&stype=json&ids=" + val + "&r=" + Math.random(),
                        async: false,
                        beforeSend: function (XMLHttpRequest) { },
                        success: function (data) {
                            switch (id) {
                                case "CategoryIDS":
                                    $.each(data.json, function (index, obj) {
                                        html += "<span>" + obj.CategoryName + "</span>";
                                    });
                                    break;
                                default:
                                    $.each(data.json, function (index, obj) {
                                        html += "<label>" + obj.Title + "</label>";
                                    });
                                    break;
                            }
                        },
                        error: function () { }
                    });
                }

                $("#" + id + "Show").html(html);
                break;
        }
    },
    Init: function () { //初始加载 选中
        var id = CmsData.Selects.ID();
        if (id != "") {
            var vals = $("#" + id, window.parent.document);
            $("#DataList table tbody tr").each(function () {
                var obj = $(this).find("input[name=CKRow]");
                if (CmsData.Common.IndexOf(vals.val(), obj.val())) {
                    obj.attr("checked", true);
                    $(this).addClass("trselect");
                }
            });
        }
    }
};