var def_show;
var def_showtext;
var def_showcategory;
var def_showcategorytext;
var def_module;
var ColumnCategory;
var ColumnCategoryText;
var ColumnArticle;
var ColumnArticleText;
var ColumnFile;
var ColumnFileText;
var ColumnNews;
var ColumnNewsText;
var ColumnProduct;
var ColumnProductText;
var ColumnMsg;
var ColumnMsgText;
var ColumnHr;
var ColumnHrText;
var ColumnHrBio;
var ColumnHrBioText;

function PlugOver(){
    window.top.window.ModuleDataRefresh();
}

function PlugInit(type) {
    def_show = $("#MenuModuleShowHidden").val();  //当前显示模块字段
    def_showtext = $("#MenuModuleShowTextHidden").val();
    def_showcategory = $("#MenuModuleShowCategoryHidden").val();  //当前显示模块栏目字段
    def_showcategorytext = $("#MenuModuleShowCategoryTextHidden").val();
    def_module = $("#MenuModuleName").val(); //当前选择模块
    
    ColumnCategory = $("#ModuleColumnCategory").val();
    ColumnCategoryText = $("#ModuleTextCategory").val();
    ColumnArticle = $("#ModuleColumnArticle").val();
    ColumnArticleText = $("#ModuleTextArticle").val();
    ColumnFile = $("#ModuleColumnFile").val();
    ColumnFileText = $("#ModuleTextFile").val();
    ColumnNews = $("#ModuleColumnNews").val();
    ColumnNewsText = $("#ModuleTextNews").val();
    ColumnProduct = $("#ModuleColumnProduct").val();
    ColumnProductText = $("#ModuleTextProduct").val();
    ColumnMsg = $("#ModuleColumnMsg").val();
    ColumnMsgText = $("#ModuleTextMsg").val();
    ColumnHr = $("#ModuleColumnHr").val();
    ColumnHrText = $("#ModuleTextHr").val();
    ColumnHrBio = $("#ModuleColumnHrBio").val();
    ColumnHrBioText = $("#ModuleTextHrBio").val();

    $("#MenuModuleName").change(function () {
        ModuleLoad();
    });

    ModuleLoad();
}

//模块加载
function ModuleLoad() {
    $("#MenuModuleShow").html("");
    $("#MenuModuleShowCategory").html("");
    var sel_module = $("#MenuModuleName").val(); //当前选择模块
    var columnshow = "";
    var columntext = "";
    var columnshowcategory = "";
    var columntextcategory = "";

    switch (sel_module) {
        case "单篇文章":
            columnshow = ColumnArticle;
            columntext = ColumnArticleText;
            columnshowcategory = ColumnCategory;
            columntextcategory = ColumnCategoryText;
            break;
        case "文件下载":
            columnshow = ColumnFile;
            columntext = ColumnFileText;
            columnshowcategory = ColumnCategory;
            columntextcategory = ColumnCategoryText;
            break;
        case "新闻图片":
            columnshow = ColumnNews;
            columntext = ColumnNewsText;
            columnshowcategory = ColumnCategory;
            columntextcategory = ColumnCategoryText;
            break;
        case "产品展示":
            columnshow = ColumnProduct;
            columntext = ColumnProductText;
            columnshowcategory = ColumnCategory;
            columntextcategory = ColumnCategoryText;
            break;
        case "在线留言":
            columnshow = ColumnMsg;
            columntext = ColumnMsgText;
            break;
        case "人才招聘":
            columnshow = ColumnHr;
            columntext = ColumnHrText;
            columnshowcategory = ColumnHrBio;
            columntextcategory = ColumnHrBioText;
            break;
        default:
            break;
    }

    var sel_value = "";
    var sel_text = "";
    var sel_cvalue = "";
    var sel_ctext = "";

    if (sel_module == def_module) {
        sel_value = def_show == "" ? columnshow : def_show;
        sel_text = def_showtext == "" ? columntext : def_showtext;
        sel_cvalue = def_showcategory == "" ? columnshowcategory : def_showcategory;
        sel_ctext = def_showtext == "" ? columntextcategory : def_showtext;
    } else {
        sel_value = columnshow;
        sel_text = columntext;
        sel_cvalue = columnshowcategory;
        sel_ctext = columntextcategory;
    }

    if (columnshow != "") {
        var sp_show = columnshow.split(",");
        var sp_text = sel_text.split(",");
        sel_value = "," + sel_value + ",";

        if (sp_show.length != sp_text.length) {
            sp_text = columntext.split(",");
        }

        var html = "";
        for (var i = 1; i <= sp_show.length; i++) {
            html += "<label for='MenuModuleShow" + i + "'>";
            html += "<input type=\"checkbox\" id=\"MenuModuleShow" + i + "\" name=\"MenuModuleShow\" value=\"" + sp_show[i - 1] + "\"";
            if (sel_value.indexOf("," + sp_show[i - 1] + ",") > -1)
                html += " checked=\"checked\" ";
            html += " /></label>";
            html += "<input type=\"text\" name=\"MenuModuleShowText\" class=\"inputtext w100\" maxlength=\"30\" value=\"" + sp_text[i - 1] + "\" >";
            if (i % 6 == 0)
                html += "<br />";
        }
        $("#MenuModuleShow").html(html);
    }

    if (columnshowcategory != "") {
        var sp_show = columnshowcategory.split(",");
        var sp_text = sel_ctext.split(",");
        sel_cvalue = "," + sel_cvalue + ",";
        if (sp_show.length == sp_text.length) {
            sp_text = columntextcategory.split(",");
        }

        var html = "";
        for (var i = 1; i <= sp_show.length; i++) {
            html += "<label for='MenuModuleShowCategory" + i + "'>";
            html += "<input type=\"checkbox\" id=\"MenuModuleShowCategory" + i + "\" name=\"MenuModuleShowCategory\" value=\"" + sp_show[i - 1] + "\"";
            if (sel_cvalue.indexOf("," + sp_show[i - 1] + ",") > -1)
                html += " checked=\"checked\" ";
            html += " /></label>";
            html += "<input type=\"text\" name=\"MenuModuleShowCategoryText\" class=\"inputtext w100\" maxlength=\"30\" value=\"" + sp_text[i - 1] + "\" >";
            if (i % 6 == 0)
                html += "<br />";
        }
        $("#MenuModuleShowCategory").html(html);
    }

    //栏目全选或取消事件
    $("#MenuModuleShow input[value=CategoryID]").click(function () {
        $("#MenuModuleShowCategory input[type=checkbox]").attr("checked", this.checked);
    });
}