var isDev = false;
if (window.location.host === "cswb-test.icswb.com") {
    isDev = true;
}
var channelId = isDev ? 2 : 2;
var voteId = isDev ? 1 : 1;

window.CHANNEL_ID = channelId;

/** 评选Id */
window.XWV_ID = 1;
/** 首页路径 */
window.PAGE_INDEX_URL = "/h/" + channelId + "/index.html";
//window.PAGE_INDEX_URL = "/h/176/index.html";
/** 诚信参评承诺书路径 */
window.PAGE_RULES_URL = "/h/" + channelId + "/rules.html";
//window.PAGE_RULES_URL = "/h/176/rules.html";
/** 最大上传文件数量 */
window.MAX_UPLOAD_FILE_COUNT = 5;

/** 申报人 */
window.XWV_USER_TYPE_REPORT = 1;
/** 评委 */
window.XWV_USER_TYPE_JUDGE = 2;
/** 预览所有申报信息 */
window.XWV_USER_TYPE_VIEW_ALL = 3;
/** 每个专栏和系列报道限制代表作数量 */
window.LIMIT_COUNT_OF_COLUMNS = 3;


/** 评委打分链接 */
//window.XWV_JUDGES_GRADE_URL = "/default.php?mod=vote&a=xwv_vote_list&vote_id=1178&temp=vote_list_103616";
window.XWV_JUDGES_GRADE_URL = "/default.php?mod=vote&a=xwv_vote_list&vote_id="+voteId+"&temp=vote_list_"+channelId;

/** 列表类型：报纸新闻奖 */
window.LIST_TYPE_NEWSPAPER = 1;
/** 列表类型：媒体融合奖 */
window.LIST_TYPE_WEB = 2;
/** 列表类型：专栏、新闻论文奖*/
window.LIST_TYPE_ZHUANLAN = 3;
/** 列表类型：基础类*/
window.LIST_TYPE_BASIC_CLASS = 10;
/** 列表类型：专门类*/
window.LIST_TYPE_SPECIAL_CLASS = 11;
/** 列表类型：单项类*/
window.LIST_TYPE_SINGLE_CLASS = 12;


$(function () {
    if ($("#body_index").length > 0) {
        var browserInfo = getBrowserInfo();
        if (browserInfo != "Chrome" && browserInfo != "FireFox" && browserInfo != "360") {
            alert("为保证信息的完整性和准确性，建议使用360（极速模式）、谷歌（Chrome）或火狐（FireFox）浏览器。");
        }
    }

    $("#body_index").height($(document).height());

    if ($(".btn_go_rules").length > 0) {
        /** 链接：诚信参评承诺书 */
        $(".btn_go_rules").attr("href", window.PAGE_RULES_URL);
    }

    /** 报纸类型只显示报纸目录按钮，融媒体只显示融媒体目录按钮,基础类只显示基础类目录按钮，专门类只显示专门类目录按钮 */
    if ($(".btn_catalog").length > 0 && typeof Request["xwv_select_item_type"] !== "undefined") {
        var xwvSelectItemType = parseInt(Request["xwv_select_item_type"]);
        var listType = XWV_2_OBJECT.GetListTypeByXwvSelectItemType(xwvSelectItemType);
        $(".btn_catalog").hide();
        $(".btn_catalog[list_type='"+listType+"']").show();
    }

    if ($(".nav_header").length > 0) {
        $("#a_nav_report").show();
        $("#a_nav_judges").show();
        $(".span_nav_department").hide();
        $("#a_nav_modify_pass").hide();
        $("#a_nav_login_out").hide();
        if (getcookie("UID").length > 0) {
            asyncGetOneByUserId(function (data) {
                if (parseInt(data["code"]) > 0) {
                    var res = data["data"];
                    var realName = res["RealName"];
                    var departmentName = res["DepartmentName"];
                    var xwvUserType = parseInt(res["XwvUserType"]);
                    $("#a_nav_report").remove();
                    $("#a_nav_judges").remove();
                    $(".span_nav_department").text(departmentName + ":" + realName).show();
                    $("#a_nav_modify_pass").show();
                    $("#a_nav_login_out").show();
                    if (xwvUserType === window.XWV_USER_TYPE_JUDGE || xwvUserType === window.XWV_USER_TYPE_VIEW_ALL) {
                        $("#a_nav_all_catalog").show();
                    }
                }
            });
        }

        //结果查询
        $("#a_nav_result").click(function () {
            window.location.href = "/default.php?mod=vote&a=xwv_vote_result_list&vote_id="+voteId+"&temp=vote_result_list_"+channelId;
        });

        //申报入口
        $("#a_nav_report").click(function () {
            window.location.href = "/default.php?mod=user&a=login&temp=login_for_xwv_"+channelId+"&re_url=" + encodeURIComponent(window.PAGE_INDEX_URL);
        });
        //评审入口
        $("#a_nav_judges").click(function () {
            window.location.href = "/default.php?mod=user&a=login&temp=login_for_xwv_"+channelId+"&re_url=" + encodeURIComponent(window.XWV_JUDGES_GRADE_URL);
        });
        //修改密码
        $("#a_nav_modify_pass").click(function () {
            window.location.href = "/default.php?mod=user&a=modify_user_pass&temp=modify_pass_for_xwv_"+channelId+"&re_url=" + encodeURIComponent(window.PAGE_INDEX_URL);
        });
        //退出登录
        $("#a_nav_login_out").click(function () {
            window.location.href = "/default.php?mod=user&a=logout&re_url=" + encodeURIComponent(window.PAGE_INDEX_URL);
        });
        //所有目录
        $("#a_nav_all_catalog").click(function () {
            window.location.href = "/default.php?mod=xwv_select_item&a=list_of_all&temp=catalog_all_"+channelId;
        });
    }
});



//region --------------------------------新的js定义--------------------------------

var XWV_2_OBJECT = {};

//设定的集体类型编辑数量下限
XWV_2_OBJECT.collectEditorNumbers = 3;

//作品类型
XWV_2_OBJECT.language = {
    hy: {code: 1, name: "中文/汉语"},
    mgy: {code: 2, name: "蒙古文（语）"},
    zy: {code: 3, name: "壮文（语）"},
    ty: {code: 4, name: "傣文（语）"},
    cxy: {code: 5, name: "朝鲜文（语）"},
    hsky: {code: 6, name: "哈萨克文（语）"},
    wwey: {code: 7, name: "维吾尔文（语）"},
    yy: {code: 8, name: "彝文（语）"},
    jpy: {code: 9, name: "景颇文（语）"},
    lly: {code: 10, name: "傈傈文（语）"},
    zwy: {code: 11, name: "载佤文（语）"},
    yw: {code: 12, name: "英文"},
    zangwy: {code: 13, name: "藏文（语）"},
};


//作品类型
XWV_2_OBJECT.worksType = {
    default: {code: 0, name: "默认"},
    words: {code: 1, name: "文字作品"},
    audio: {code: 2, name: "音频作品"},
    video: {code: 3, name: "视频作品"},
    newMedia: {code: 4, name: "新媒体作品"},
    newspaperColumns: {code: 5, name: "报纸专栏"},
    audioColumns: {code: 6, name: "音频专栏"},
    videoColumns: {code: 7, name: "视频专栏"},
    newMediaColumns: {code: 8, name: "新媒体专栏"},
    cartoonSingle: {code: 9, name: "单幅"},
    cartoonDouble: {code: 10, name: "组画"},
    shootSingle: {code: 11, name: "单幅"},
    shootDouble: {code: 12, name: "组照"},
};

//作品体裁
XWV_2_OBJECT.genreType = {
    information: {
        code: 1,
        name: "消息",
        subWorksType: {
            words: {worksType: XWV_2_OBJECT.worksType.words, collectAuthorNumbers: 3},
            // audio: {worksType: XWV_2_OBJECT.worksType.audio, collectAuthorNumbers: 4},
            // video: {worksType: XWV_2_OBJECT.worksType.video, collectAuthorNumbers: 5},
            newMedia: {worksType: XWV_2_OBJECT.worksType.newMedia, collectAuthorNumbers: 5},
        }},
    comments: {
        code: 2,
        name: "评论",
        subWorksType: {
            words: {worksType: XWV_2_OBJECT.worksType.words, collectAuthorNumbers: 3},
            audio: {worksType: XWV_2_OBJECT.worksType.audio, collectAuthorNumbers: 4},
            video: {worksType: XWV_2_OBJECT.worksType.video, collectAuthorNumbers: 5},
            newMedia: {worksType: XWV_2_OBJECT.worksType.newMedia, collectAuthorNumbers: 5},
        }
    },
    reports: {
        code: 3,
        name: "通讯",
        subWorksType: {
            words: {worksType: XWV_2_OBJECT.worksType.words, collectAuthorNumbers: 3},
            newMedia: {worksType: XWV_2_OBJECT.worksType.newMedia, collectAuthorNumbers: 5},
        }
    },
    newsSpecialSubject: {
        code: 4,
        name: "新闻专题",
        subWorksType: {
            words: {worksType: XWV_2_OBJECT.worksType.words, collectAuthorNumbers: 3},
            newMedia: {worksType: XWV_2_OBJECT.worksType.newMedia, collectAuthorNumbers: 7},
        }
    },
    series: {
        code: 5,
        name: "系列报道",
        dealInfoTemp: "deal_series_info_"+channelId,
        listInfoTemp: "list_series_info_"+channelId,
        subWorksType: {
            words: {worksType: XWV_2_OBJECT.worksType.words, collectAuthorNumbers: 7},
            // audio: {worksType: XWV_2_OBJECT.worksType.audio, collectAuthorNumbers: 7},
            // video: {worksType: XWV_2_OBJECT.worksType.video, collectAuthorNumbers: 8},
            newMedia: {worksType: XWV_2_OBJECT.worksType.newMedia, collectAuthorNumbers: 8},
        }
    },
    newsInterview: {
        code: 6,
        name: "新闻访谈",
        subWorksType: {
            words: {worksType: XWV_2_OBJECT.worksType.words, collectAuthorNumbers: 3},
            // audio: {worksType: XWV_2_OBJECT.worksType.audio, collectAuthorNumbers: 7},
            // video: {worksType: XWV_2_OBJECT.worksType.video, collectAuthorNumbers: 8},
            newMedia: {worksType: XWV_2_OBJECT.worksType.newMedia, collectAuthorNumbers: 8},
        }
    },
    newsLive: {
        code: 7,
        name: "新闻直播",
        subWorksType: {
            audio: {worksType: XWV_2_OBJECT.worksType.audio, collectAuthorNumbers: 9},
            video: {worksType: XWV_2_OBJECT.worksType.video, collectAuthorNumbers: 10},
        }
    },
    newsColumn: {
        code: 8,
        name: "新闻栏目",
        subWorksType: {
            //newspaperSpecialColumns: {worksType: XWV_2_OBJECT.worksType.newspaperSpecialColumns, collectAuthorNumbers: 7},
            //newMediaSpecialColumns: {worksType: XWV_2_OBJECT.worksType.newMediaSpecialColumns, collectAuthorNumbers: 7},
            words: {worksType: XWV_2_OBJECT.worksType.newspaperColumns, collectAuthorNumbers: 7},
            audio: {worksType: XWV_2_OBJECT.worksType.audioColumns, collectAuthorNumbers: 7},
            video: {worksType: XWV_2_OBJECT.worksType.videoColumns, collectAuthorNumbers: 7},
            newMedia: {worksType: XWV_2_OBJECT.worksType.newMediaColumns, collectAuthorNumbers: 7},
        }
    },
    newsBusinessResearch: {
        code: 9,
        name: "新闻业务研究",
        subWorksType: {
            words: {worksType: XWV_2_OBJECT.worksType.words, collectAuthorNumbers: 3}
        }
    },
    fusionReports: {
        code: 10,
        name: "融合报道",
        subWorksType: {
            newMedia: {worksType: XWV_2_OBJECT.worksType.newMedia, collectAuthorNumbers: 8},
        }
    },
    appInnovation: {
        code: 11,
        name: "应用创新",
        subWorksType: {
            newMedia: {worksType: XWV_2_OBJECT.worksType.newMedia, collectAuthorNumbers: 8},
        }
    },
    typicalReports: {
        code: 12,
        name: "典型报道",
        subWorksType: {
            words: {worksType: XWV_2_OBJECT.worksType.words, collectAuthorNumbers: 7    }
        }
    },
    publicOpinionSupervisionReport: {
        code: 13,
        name: "舆论监督报道",
        subWorksType: {
            words: {worksType: XWV_2_OBJECT.worksType.words, collectAuthorNumbers: 7}
        }
    },
    internationalCommunication: {
        code: 14,
        name: "国际传播",
        subWorksType: {
            words: {worksType: XWV_2_OBJECT.worksType.words, collectAuthorNumbers: 7}
        }
    },
    layout: {
        code: 15,
        name: "版面",
        subWorksType: {
            words: {worksType: XWV_2_OBJECT.worksType.words, collectAuthorNumbers: 3}
        }
    },
    newsCartoon: {
        code: 16,
        name: "新闻漫画",
        subWorksType: {
            cartoonSingle: {worksType: XWV_2_OBJECT.worksType.cartoonSingle, collectAuthorNumbers: 1},
            cartoonDouble: {worksType: XWV_2_OBJECT.worksType.cartoonDouble, collectAuthorNumbers: 2}
        }
    },
    shoot: {
        code: 17,
        name: "摄影",
        subWorksType: {
            shootSingle: {worksType: XWV_2_OBJECT.worksType.shootSingle, collectAuthorNumbers: 1},
            shootDouble: {worksType: XWV_2_OBJECT.worksType.shootDouble, collectAuthorNumbers: 2}
        }
    },
    supplementWorks: {
        code: 18,
        name: "副刊作品",
        subWorksType: {
            words: {worksType: XWV_2_OBJECT.worksType.words, collectAuthorNumbers: 3}
        }
    },
};

//作者类型
XWV_2_OBJECT.authorType = {
    individual: {code: 1, name: "个人"},
    collective: {code: 2, name: "集体"},
};

//编辑类型
XWV_2_OBJECT.editorType = {
    individual: {code: 1, name: "个人"},
    collective: {code: 2, name: "集体"},
};



//region --------------------------------评选项目--------------------------------
/**
 * 评选项目
 * belongToSpecialClass 是否属于专门类
 * collectAuthorNumbers 集体作者作品的人数
 */
XWV_2_OBJECT.selectionProject = {};
XWV_2_OBJECT.selectionProject.information = {
    code: 101,
    name: "消息",
    belongToSpecialClass: 0,
    listTemp: "list_"+channelId,
    dealTemp: "deal_general_common_"+channelId,
    listInfoTemp: "",
    dealInfoTemp: "",
    subGenreType: {
        information:XWV_2_OBJECT.genreType.information
    }
};

XWV_2_OBJECT.selectionProject.comments = {
    code: 102,
    name: "评论",
    belongToSpecialClass: 0,
    listTemp: "list_"+channelId,
    dealTemp: "deal_general_common_"+channelId,
    listInfoTemp: "",
    dealInfoTemp: "",
    subGenreType: {
        comments:XWV_2_OBJECT.genreType.comments
    }
};
XWV_2_OBJECT.selectionProject.reports = {
    code: 103,
    name: "通讯",
    belongToSpecialClass: 0,
    listTemp: "list_"+channelId,
    dealTemp: "deal_general_common_"+channelId,
    listInfoTemp: "",
    subGenreType: {
        reports:XWV_2_OBJECT.genreType.reports
    }
};
XWV_2_OBJECT.selectionProject.newsSpecialSubject = {//
    code: 104,
    name: "新闻专题",
    belongToSpecialClass: 0,
    listTemp: "list_"+channelId,
    dealTemp: "deal_general_common_"+channelId,
    listInfoTemp: "",
    subGenreType: {
        newsSpecialSubject:XWV_2_OBJECT.genreType.newsSpecialSubject
    }
};
XWV_2_OBJECT.selectionProject.series = {
    code: 105,
    name: "系列报道",
    belongToSpecialClass: 0,
    listTemp: "list_series_"+channelId,
    dealTemp: "deal_series_"+channelId,
    dealInfoTemp: "deal_series_info_"+channelId,
    listInfoTemp: "list_series_info_"+channelId,
    subGenreType: {
        series:XWV_2_OBJECT.genreType.series
    }
};
XWV_2_OBJECT.selectionProject.newsInterview = {
    code: 106,
    name: "新闻访谈",
    belongToSpecialClass: 0,
    listTemp: "list_"+channelId,
    dealTemp: "deal_general_common_"+channelId,
    listInfoTemp: "",
    subGenreType: {
        newsInterview:XWV_2_OBJECT.genreType.newsInterview
    }
};
XWV_2_OBJECT.selectionProject.newsLive = {
    code: 107,
    name: "新闻直播",
    belongToSpecialClass: 0,
    listTemp: "list_"+channelId,
    dealTemp: "deal_general_common_"+channelId,
    listInfoTemp: "",
    subGenreType: {
        newsLive:XWV_2_OBJECT.genreType.newsLive
    }
};
XWV_2_OBJECT.selectionProject.webColumn = {//
    code: 108,
    name: "新闻专栏",
    belongToSpecialClass: 0,
    listTemp: "list_columns_"+channelId,
    dealTemp: "deal_columns_web_"+channelId,
    dealInfoTemp: "deal_columns_info_web_"+channelId,
    listInfoTemp: "list_columns_info_"+channelId,
    subGenreType: {
        newsColumn:XWV_2_OBJECT.genreType.newsColumn
    }
};
XWV_2_OBJECT.selectionProject.newspaperColumn = {//
    code: 109,
    name: "报纸专栏",
    belongToSpecialClass: 0,
    listTemp: "list_columns_"+channelId,
    dealTemp: "deal_columns_newspaper_"+channelId,
    dealInfoTemp: "deal_columns_info_newspaper_"+channelId,
    listInfoTemp: "list_columns_info_"+channelId,
    subGenreType: {
        newsColumn:XWV_2_OBJECT.genreType.newsColumn
    }
};
XWV_2_OBJECT.selectionProject.newsBusinessResearch = {
    code: 110,
    name: "新闻业务研究",
    belongToSpecialClass: 0,
    listTemp: "list_"+channelId,
    dealTemp: "deal_thesis_newspaper_"+channelId,
    listInfoTemp: "",
    subGenreType: {
        newsBusinessResearch:XWV_2_OBJECT.genreType.newsBusinessResearch
    }
};
XWV_2_OBJECT.selectionProject.fusionReports = {
    code: 111,
    name: "融合报道",
    belongToSpecialClass: 1,
    listTemp: "list_"+channelId,
    dealTemp: "deal_general_web_"+channelId,
    listInfoTemp: "",
    subGenreType: {
        fusionReports:XWV_2_OBJECT.genreType.fusionReports,
        // information: XWV_2_OBJECT.genreType.information,
        // comments: XWV_2_OBJECT.genreType.comments,
        // reports: XWV_2_OBJECT.genreType.reports,
        // newsSpecialSubject: XWV_2_OBJECT.genreType.newsSpecialSubject,
        // series: XWV_2_OBJECT.genreType.series,
    }
};
XWV_2_OBJECT.selectionProject.appInnovation = {
    code: 112,
    name: "应用创新",
    belongToSpecialClass: 1,
    listTemp: "list_"+channelId,
    dealTemp: "deal_general_web_"+channelId,
    listInfoTemp: "",
    subGenreType: {
        appInnovation:XWV_2_OBJECT.genreType.appInnovation
    }
};
XWV_2_OBJECT.selectionProject.majorThemeReports = {
    code: 113,
    name: "重大主题报道",
    belongToSpecialClass: 1,
    listTemp: "list_"+channelId,
    dealTemp: "deal_general_common_"+channelId,
    dealInfoTemp: "",
    listInfoTemp: "",
    subGenreType: {
        information: XWV_2_OBJECT.genreType.information,
        comments: XWV_2_OBJECT.genreType.comments,
        reports: XWV_2_OBJECT.genreType.reports,
        newsSpecialSubject: XWV_2_OBJECT.genreType.newsSpecialSubject,
        series: XWV_2_OBJECT.genreType.series,
        // newsInterview: XWV_2_OBJECT.genreType.newsInterview,
        // newsLive: XWV_2_OBJECT.genreType.newsLive,
        // fusionReports: XWV_2_OBJECT.genreType.fusionReports,
        // typicalReports: XWV_2_OBJECT.genreType.typicalReports,
        // publicOpinionSupervisionReport: XWV_2_OBJECT.genreType.publicOpinionSupervisionReport,
    },
};
XWV_2_OBJECT.selectionProject.typicalReports = {//
    code: 114,
    name: "典型报道",
    belongToSpecialClass: 1,
    listTemp: "list_"+channelId,
    dealTemp: "deal_general_common_"+channelId,
    listInfoTemp: "",
    subGenreType: {
        //reports: XWV_2_OBJECT.genreType.reports
        information: XWV_2_OBJECT.genreType.information,
        //comments: XWV_2_OBJECT.genreType.comments,
        reports: XWV_2_OBJECT.genreType.reports,
        newsSpecialSubject: XWV_2_OBJECT.genreType.newsSpecialSubject,
        series: XWV_2_OBJECT.genreType.series,
    }
};
XWV_2_OBJECT.selectionProject.publicOpinionSupervisionReport = {//
    code: 115,
    name: "舆论监督报道",
    belongToSpecialClass: 1,
    listTemp: "list_"+channelId,
    dealTemp: "deal_general_common_"+channelId,
    listInfoTemp: "",
    subGenreType: {
        // reports: XWV_2_OBJECT.genreType.reports,
        // series: XWV_2_OBJECT.genreType.series
        information: XWV_2_OBJECT.genreType.information,
        comments: XWV_2_OBJECT.genreType.comments,
        reports: XWV_2_OBJECT.genreType.reports,
        newsSpecialSubject: XWV_2_OBJECT.genreType.newsSpecialSubject,
        series: XWV_2_OBJECT.genreType.series,
    }
};
XWV_2_OBJECT.selectionProject.internationalCommunication = {//
    code: 116,
    name: "国际传播",
    belongToSpecialClass: 1,
    listTemp: "list_"+channelId,
    dealTemp: "deal_general_common_"+channelId,
    listInfoTemp: "",
    subGenreType: {
        // reports: XWV_2_OBJECT.genreType.reports,
        // series: XWV_2_OBJECT.genreType.series
        information: XWV_2_OBJECT.genreType.information,
        comments: XWV_2_OBJECT.genreType.comments,
        reports: XWV_2_OBJECT.genreType.reports,
        newsSpecialSubject: XWV_2_OBJECT.genreType.newsSpecialSubject,
        series: XWV_2_OBJECT.genreType.series,
    }
};
XWV_2_OBJECT.selectionProject.layout = {
    code: 117,
    name: "版面",
    belongToSpecialClass: 0,
    listTemp: "list_"+channelId,
    dealTemp: "deal_general_common_no_count_"+channelId,
    listInfoTemp: "",
    subGenreType: {
        newsLive:XWV_2_OBJECT.genreType.layout
    }
};
XWV_2_OBJECT.selectionProject.newsCartoon = {
    code: 118,
    name: "新闻漫画",
    belongToSpecialClass: 0,
    listTemp: "list_"+channelId,
    dealTemp: "deal_general_common_no_count_"+channelId,
    listInfoTemp: "",
    subGenreType: {
        newsLive:XWV_2_OBJECT.genreType.newsCartoon
    }
};
XWV_2_OBJECT.selectionProject.shoot = {
    code: 119,
    name: "摄影",
    belongToSpecialClass: 0,
    listTemp: "list_"+channelId,
    dealTemp: "deal_general_common_no_count_"+channelId,
    listInfoTemp: "",
    subGenreType: {
        newsLive:XWV_2_OBJECT.genreType.shoot
    }
};
XWV_2_OBJECT.selectionProject.supplementWorks = {
    code: 120,
    name: "副刊作品",
    belongToSpecialClass: 0,
    listTemp: "list_"+channelId,
    dealTemp: "deal_general_common_"+channelId,
    listInfoTemp: "",
    subGenreType: {
        newsLive:XWV_2_OBJECT.genreType.supplementWorks
    }
};
//endregion

//大类
XWV_2_OBJECT.classify = {
    basicClass: {
        code: 1,
        name: "基础类",
        catalogListType: window.LIST_TYPE_BASIC_CLASS,
        sub: [
            XWV_2_OBJECT.selectionProject.information,//消息
            XWV_2_OBJECT.selectionProject.comments,//评论
            XWV_2_OBJECT.selectionProject.reports,//通讯
            XWV_2_OBJECT.selectionProject.newsSpecialSubject,//新闻专题
            XWV_2_OBJECT.selectionProject.series,//系列报道
            XWV_2_OBJECT.selectionProject.newsInterview,//新闻访谈
            XWV_2_OBJECT.selectionProject.newsLive,//新闻直播
            XWV_2_OBJECT.selectionProject.layout,//版面
            XWV_2_OBJECT.selectionProject.newsCartoon,//新闻漫画
            XWV_2_OBJECT.selectionProject.shoot,//摄影
            XWV_2_OBJECT.selectionProject.supplementWorks,//副刊作品
        ]
    },
    specialClass: {
        code: 2,
        name: "专门类",
        catalogListType: window.LIST_TYPE_SPECIAL_CLASS,
        sub: [
            XWV_2_OBJECT.selectionProject.majorThemeReports,//重大主题报道
            XWV_2_OBJECT.selectionProject.internationalCommunication,//国际传播
            XWV_2_OBJECT.selectionProject.typicalReports,//典型报道
            XWV_2_OBJECT.selectionProject.publicOpinionSupervisionReport,//舆论监督报道
            XWV_2_OBJECT.selectionProject.fusionReports,//融合报道
            XWV_2_OBJECT.selectionProject.appInnovation//应用创新
        ]
    },
    singleClass: {
        code: 3,
        name: "单项类",
        catalogListType: window.LIST_TYPE_SINGLE_CLASS,
        sub: [
            XWV_2_OBJECT.selectionProject.webColumn,//新媒体新闻专栏
            XWV_2_OBJECT.selectionProject.newsBusinessResearch,//新闻业务研究
        ]
    }
};

/**
 * 获取大类下的评选项目
 * 调用示例：XWV_2_OBJECT.GetSubsByClassify("basicClass");
 */
XWV_2_OBJECT.GetSubsByClassify = function (classifyKey) {
    var _ = XWV_2_OBJECT.classify;
    var result = [];
    if (_.hasOwnProperty(classifyKey)) {
        result = _[classifyKey].sub;
    }
    return result;
};

/**
 * 根据评选项类型取前端 List模板
 * @param {int} xwvSelectItemType
 * @param {boolean} isDealXwvSelectItemInfo 是否处理子信息
 * @returns {string}
 */
XWV_2_OBJECT.GetListTemplateByXwvSelectItemType = function (xwvSelectItemType, isDealXwvSelectItemInfo) {
    var template = "";
    var goEach = true;
    $.each(XWV_2_OBJECT.selectionProject, function(key, item){
        if (goEach) {
            if (item.code === xwvSelectItemType) {
                isDealXwvSelectItemInfo ? template = item.listInfoTemp : template = item.listTemp;
                goEach = false;
            }
        }
    });
    return template;
}

/**
 * 获取项目类型下拉列表
 * 调用示例：XWV_2_OBJECT.GetSelectOptionForSelectItemType({selectValue:101});
 * options.selectValue: 选中值
 */
XWV_2_OBJECT.GetSelectOptionForSelectItemType = function (options) {
    var _ = XWV_2_OBJECT.selectionProject;
    var optHtml = "";
    var selectCode = parseInt(options.selectValue);
    if (isNaN(selectCode)) {
        selectCode = 0;
    }
    Object.getOwnPropertyNames(_).forEach(function (key) {
        var item = _[key];
        if (item.belongToSpecialClass > 0) {
            var selected = "";
            if (selectCode > 0 && item.code === selectCode) {
                selected = " selected ";
            }
            optHtml += '<option value="' + item.code + '" ' + selected + '>' + item.name + '</option>';
        }
    });
    return optHtml;
}

/**
 * 获取语种类型
 * 调用示例：XWV_2_OBJECT.GetSubWorksTypeBySelectGenreType(101);
 */
XWV_2_OBJECT.GetSelectOptionForLanguage = function (selectValue) {
    var optHtml = "";

    $.each(XWV_2_OBJECT.language, function(key, item){
        var selected = "";
        if (parseInt(selectValue) > 0 && item.code === parseInt(selectValue)) {
            selected = " selected ";
        }
        optHtml += '<option value="' + item.code + '" '+ selected +'>' + item.name + '</option>';
        return optHtml;
    });
    return optHtml;
};

/**
 * 获取体裁下的作品类型
 * 调用示例：XWV_2_OBJECT.GetSubWorksTypeBySelectItemType(101);
 */
XWV_2_OBJECT.GetSubWorksTypeBySelectGenreType = function (selectGenreType) {
    var result = [];

    $.each(XWV_2_OBJECT.genreType, function(key, item){
        var currentGenreType = item.code;
        if(selectGenreType == currentGenreType){
            var subWorksTypeItem = item.subWorksType;
            $.each(subWorksTypeItem, function(subKey, subItem){
                var newItem = {code: subItem.worksType.code, name: subItem.worksType.name, collectAuthorNumbers:subItem.collectAuthorNumbers};
                result.push(newItem);
            });
        }
    });
    return result;
};

/**
 * 获取体裁下作品类型下拉列表
 * 调用示例：XWV_2_OBJECT.GetSelectOptionForWorksType(1,-1);
 * selectItemType: 评选项目id
 * genreType: 选中值
 */
XWV_2_OBJECT.GetSelectOptionForWorksType = function (selectGenreType,worksType) {
    var subsBySelectionProject = XWV_2_OBJECT.GetSubWorksTypeBySelectGenreType(selectGenreType);
    var optHtml = "<option value=\"-1\">请选择</option>";
    $.each(subsBySelectionProject, function(key, item){
        var selected = "";
        if (selectGenreType > 0 && item.code === worksType) {
            selected = " selected ";
        }
        optHtml += '<option value="' + item.code + '" collectAuthorNumbers="'+item.collectAuthorNumbers+'"  '+ selected +'>' + item.name + '</option>';
    });
    return optHtml;
}

/**
 * 获取评选项目下的体裁类型
 * 调用示例：XWV_2_OBJECT.GetSubGenreTypeBySelectionProject(101);
 */
XWV_2_OBJECT.GetSubGenreTypeBySelectionProject = function (selectItemType) {
    var _ = XWV_2_OBJECT.selectionProject;
    var result = [];

    $.each(XWV_2_OBJECT.selectionProject, function(key, item){
        var currentSelectItemType = item.code;
        if(selectItemType == currentSelectItemType){
            var genreTypeItem = item.subGenreType;
            $.each(genreTypeItem, function(subKey, subItem){
                var newItem = {code: subItem.code, name: subItem.name};
                result.push(newItem);
            });
        }
    });
    return result;
};

/**
 * 获取评选项目下体裁下拉列表
 * 调用示例：XWV_2_OBJECT.GetSubGenreTypeBySelectionProject(101);
 * selectItemType: 评选项目id
 * genreType: 选中值
 */
XWV_2_OBJECT.GetSelectOptionForGenreType = function (selectItemType,genreType) {
    var subsBySelectionProject = XWV_2_OBJECT.GetSubGenreTypeBySelectionProject(selectItemType);
    var optHtml = "";
    if (isNaN(selectItemType)) {
        selectItemType = 0;
    }
    $.each(subsBySelectionProject, function(key, item){
        var selected = "";
        if (selectItemType > 0 && item.code === genreType) {
            selected = " selected ";
        }
        optHtml += '<option value="' + item.code + '" ' + selected + ' >' + item.name + '</option>';
    });
    return optHtml;
}

/**
 * 根据项目类型获得项目类型对应的默认体裁
 * 调用示例：XWV_2_OBJECT.GetDefaultGenreTypeBySelectItemType();
 * selectItemType: 评选项目id
 */
XWV_2_OBJECT.GetDefaultGenreTypeBySelectItemType = function (selectItemType) {
    var result = -1;
    switch (parseInt(selectItemType)){
        case XWV_2_OBJECT.selectionProject.information.code:
            result = XWV_2_OBJECT.genreType.information.code;
            break;
        case XWV_2_OBJECT.selectionProject.comments.code:
            result = XWV_2_OBJECT.genreType.comments.code;
            break;
        case XWV_2_OBJECT.selectionProject.reports.code:
            result = XWV_2_OBJECT.genreType.reports.code;
            break;
        case XWV_2_OBJECT.selectionProject.newsSpecialSubject.code:
            result = XWV_2_OBJECT.genreType.newsSpecialSubject.code;
            break;
        case XWV_2_OBJECT.selectionProject.series.code:
            result = XWV_2_OBJECT.genreType.series.code;
            break;
        case XWV_2_OBJECT.selectionProject.newsInterview.code:
            result = XWV_2_OBJECT.genreType.newsInterview.code;
            break;
        case XWV_2_OBJECT.selectionProject.newsLive.code:
            result = XWV_2_OBJECT.genreType.newsLive.code;
            break;
        case XWV_2_OBJECT.selectionProject.webColumn.code:
            result = XWV_2_OBJECT.genreType.newsColumn.code;
            break;
        case XWV_2_OBJECT.selectionProject.newspaperColumn.code:
            result = XWV_2_OBJECT.genreType.newsColumn.code;
            break;
        case XWV_2_OBJECT.selectionProject.newsBusinessResearch.code:
            result = XWV_2_OBJECT.genreType.newsBusinessResearch.code;
            break;
        case XWV_2_OBJECT.selectionProject.fusionReports.code:
            result = XWV_2_OBJECT.genreType.fusionReports.code;
            break;
        case XWV_2_OBJECT.selectionProject.appInnovation.code:
            result = XWV_2_OBJECT.genreType.appInnovation.code;
            break;
        case XWV_2_OBJECT.selectionProject.layout.code:
            result = XWV_2_OBJECT.genreType.layout.code;
            break;
        case XWV_2_OBJECT.selectionProject.newsCartoon.code:
            result = XWV_2_OBJECT.genreType.newsCartoon.code;
            break;
        case XWV_2_OBJECT.selectionProject.shoot.code:
            result = XWV_2_OBJECT.genreType.shoot.code;
            break;
        case XWV_2_OBJECT.selectionProject.supplementWorks.code:
            result = XWV_2_OBJECT.genreType.supplementWorks.code;
            break;
    }
    return result;
}

/**
 * 获取评选项目下作者类型下拉列表
 * 调用示例：XWV_2_OBJECT.GetSelectOptionForAuthorType(1);
 * selectValue: 选中值
 */
XWV_2_OBJECT.GetSelectOptionForAuthorType = function (selectValue) {
    var optHtml = "";
    if (isNaN(selectValue)) {
        selectValue = -1;
    }
    $.each(XWV_2_OBJECT.authorType, function(key, item){
        var selected = "";
        if (item.code === selectValue) {
            selected = " selected ";
        }
        optHtml += '<option value="' + item.code + '" ' + selected + ' >' + item.name + '</option>';
    });
    return optHtml;
}

/**
 * 获取评选项目下编辑类型下拉列表
 * 调用示例：XWV_2_OBJECT.GetSelectOptionForEditorType(1);
 * selectValue: 选中值
 */
XWV_2_OBJECT.GetSelectOptionForEditorType = function (selectValue) {
    var optHtml = "";
    if (isNaN(selectValue)) {
        selectValue = -1;
    }
    $.each(XWV_2_OBJECT.editorType, function(key, item){
        var selected = "";
        if (item.code === selectValue) {
            selected = " selected ";
        }
        optHtml += '<option value="' + item.code + '" ' + selected + ' >' + item.name + '</option>';
    });
    return optHtml;
}

/**
 * 格式化评选项类型名称
 * @param {int} xwvSelectItemType
 * @returns {string}
 */
XWV_2_OBJECT.FormatSelectItemType = function (xwvSelectItemType) {
    var strHtml = "";
    var goEach = true;
    var selectionProject = XWV_2_OBJECT.selectionProject;
    Object.getOwnPropertyNames(selectionProject).forEach(function (key) {
        var item = selectionProject[key];
        if (goEach) {
            if (item.code === xwvSelectItemType) {
                strHtml = item.name;
                goEach = false;
            }
        }
    });
    return strHtml;
}

/**
 * 根据评选项类型取前端 Deal模板
 * @param {int} xwvSelectItemType 评选项类型
 * @param {boolean} isDealXwvSelectItemInfo 是否处理子信息
 * @returns {string}
 */
XWV_2_OBJECT.GetTemplateByXwvSelectItemType = function (xwvSelectItemType, isDealXwvSelectItemInfo) {
    var template = "";
    var goEach = true;
    var _ = XWV_2_OBJECT.selectionProject;
    Object.getOwnPropertyNames(_).forEach(function (key) {
        var item = _[key];
        if (goEach) {
            if (item.code === xwvSelectItemType) {
                isDealXwvSelectItemInfo ? template = item.dealInfoTemp : template = item.dealTemp;
                goEach = false;
            }
        }
    });
    return template;
}

/**
 * 根据体裁取前端 模板
 * @param {int} genreType 体裁类型
 * @param {boolean} isDeal 是否是deal模板
 * @returns {string}
 */
XWV_2_OBJECT.GetTemplateByGenreType = function (genreType, isDeal) {
    var template = "";
    var goEach = true;
    var _ = XWV_2_OBJECT.genreType;
    Object.getOwnPropertyNames(_).forEach(function (key) {
        var item = _[key];
        if (goEach) {
            if (item.code === genreType) {
                isDeal ? template = item.dealInfoTemp : template = item.listInfoTemp;
                goEach = false;
            }
        }
    });

    return template;
}

/**
 * 取所属总目录类型（报纸新闻/媒体融合/基础类/专门类）
 * @param {int} xwvSelectItemType
 * @returns {number}
 */
XWV_2_OBJECT.GetListTypeByXwvSelectItemType = function (xwvSelectItemType) {
    var listType = 0;

    $.each(XWV_2_OBJECT.classify, function(key, item){
        var subSelectItem = item.sub;
        $.each(subSelectItem, function(subKey, subItem){
            if(subItem.code===xwvSelectItemType){
                listType = item.catalogListType;
            }
        });
    });
    return listType;
}

/**
 * 根据目录类型类型取参评项目列表
 * @param {int} listType
 * @returns {number}
 */
XWV_2_OBJECT.GetXwvSelectItemTypeListByListType = function (listType) {
    var result = [];
    if (listType === 0) {
        Object.getOwnPropertyNames(XWV_2_OBJECT.classify).forEach(function (key) {
            var item = XWV_2_OBJECT.classify[key];
            result = result.concat(item.sub);
        });
    } else {
        Object.getOwnPropertyNames(XWV_2_OBJECT.classify).forEach(function (key) {
            var item = XWV_2_OBJECT.classify[key];
            if (item.code === listType) {
                result = result.concat(item.sub);
            }
        });
    }
    return result;
}

//#endregion

/**
 * 常规新闻列表页显示隐藏列
 * @param xwvSelectItemType
 * @returns {{showNewspaperColumns: boolean, showWebColumns: boolean}}
 */
function showOrHideColumnsInGeneralList(xwvSelectItemType) {
    var result = {};
    if (xwvSelectItemType === 30) {//XWV_2_OBJECT.selectionProject.XWV_SELECT_ITEM_TYPE_MEDIA_WORKS
        result = {showWebColumns: true, showNewspaperColumns: false};
    } else {
        result = {showWebColumns: false, showNewspaperColumns: false};
    }
    return result;
}

/**
 * 取得返回首页地址里带的 re_type 参数
 * @param {int} xwvSelectItemType
 * @returns {string}
 */
function getReTypeBySelectItemType(xwvSelectItemType) {
    var reType = "";
    var goEach = true;
    Object.getOwnPropertyNames(XWV_2_OBJECT.classify).forEach(function (key) {
        var item = XWV_2_OBJECT.classify[key];
        if (goEach) {
            var subSelectItem = item.sub;
            for (var i = 0; i < subSelectItem.length; i++) {
                if (subSelectItem[i].code === xwvSelectItemType) {
                    reType = key;
                    goEach = false;
                    return false;
                }
            }
        }
    });
    return reType;
}

/**
 * 预览上传的图片
 * @param obj 要预览的file对象
 * @param {string} id 预览标签的id名称
 */
function detailFile(obj, id) {
    //FileReader
    if (window.FileReader) {//验证当前的浏览器是否支持图片预览
        var reader = new FileReader();
        var file = obj[0].files[0];
        var regexImage = /^image\//;//js正则表达式，匹配是否拥有image
        if (regexImage.test(file.type)) {
            //设置读取结束的回调函数
            reader.onload = function (data) {
                $("#" + id).attr("img_url", data.target.result);
                $("#" + id).css("visibility", "visible");
                $("#" + id).css("display", "inline-block");
                // var img = document.getElementById(id);
                // img.src = data.target.result;//将结果数据显示到img标签上
            };
            //开始读取上传的文件内容
            reader.readAsDataURL(file);
        } else {
            obj.val("");
            alert("请上传图片文件。");
        }
    } else {
        alert("浏览器该升级了，无法预览。");
    }
}

/** 获取图片真实高度 */
function getImageWidth(url, callback) {
    var img = new Image();
    img.src = url;
    // 如果图片被缓存，则直接返回缓存数据
    if (img.complete) {
        callback(img.width, img.height + 36);
    } else {
        img.onload = function () {
            callback(img.width, img.height + 36);
        }
    }
}

/** 改变状态 */
function asyncChangeStateForXwvSelectItem(xwvSelectItemId, newState, callback) {
    $.ajax({
        url: "/default.php?mod=xwv_select_item&a=async_modify_state",
        type: "POST",
        data: {xwv_select_item_id: xwvSelectItemId, state: newState},
        dataType: "jsonp",
        jsonp: "jsonpcallback",
        success: function (data) {
            callback(data);
        }
    });
}

/** 根据用户ID取评选用户信息 */
function asyncGetOneByUserId(callback) {
    $.ajax({
        url: "/default.php?mod=xwv_user&a=async_get_one_by_user_id",
        data: {},
        dataType: "jsonp",
        jsonp: "jsonpcallback",
        success: function (data) {
            callback(data);
        }
    });
}

/** 改变状态 info */
function asyncChangeStateForXwvSelectItemInfo(xwvSelectItemInfoId, newState, callback) {
    $.ajax({
        url: "/default.php?mod=xwv_select_item_info&a=async_modify_state",
        type: "POST",
        data: {xwv_select_item_info_id: xwvSelectItemInfoId, state: newState},
        dataType: "jsonp",
        jsonp: "jsonpcallback",
        success: function (data) {
            callback(data);
        }
    });
}

/** detail页禁止修改页面内容 */
function forbiddenModify() {
    $("input,textarea,select,#chk_agree_rules,.date_picker,.datetime_picker,.time_picker").attr("disabled", "disabled");
    $("#btn_add_file_input,#btn_submit").remove();
    $(".btn_del_upload_file").remove();
    $("#btn_back").removeAttr("disabled");

    //将input框里的网址替换成超链,同时显示出二维码图片
    replaceInputToLink("f_WebUrl");
    replaceInputToLink("f1_WebUrl");
    replaceInputToLink("f2_WebUrl");
    replaceInputToLink("f3_WebUrl");
}

/** 将input框里的网址替换成超链 */
function replaceInputToLink(id) {
    var obj = $("#"+id);
    var objForShowQrCode = $("#"+id+"_QrCode");
    if (obj.length > 0 && obj.val().length > 0) {
        var url = obj.val();
        obj.hide();
        obj.before('<a target="_blank" class="dis_contents a_link" href="' + url + '">' + url + '</a>');
        //obj.before(' <a target="_blank" class="dis_contents text_color_red" href="/default.php?mod=common&a=gen_qrcode&is_url=1&text=' + encodeURIComponent(url) + '"><img src="/front/ema_xwv_icswb_com/xwv_v2/img/qr_code.png" class="img_qr_code" alt="扫二维码" title="扫二维码"></a>');
        obj.parent("td").addClass("left_text");

        //在指定的地方显示二维码图片
        var imgUrl = "/default.php?mod=common&a=gen_qrcode&is_url=1&text=" + encodeURIComponent(url);
        objForShowQrCode.html(' <a target="_blank" class="dis_contents text_color_red" href="'+imgUrl+'"><img src="'+imgUrl+'" class="img_qr_big_code" alt="扫二维码" title="扫二维码"></a>');
    }
}

/**
 * 显示已上传的PDF文件（作品链接）
 * @param {boolean} isDetailPage
 * @param {int} pdfUploadFileId
 * @param {string} pdfUploadFilePath
 * @returns {string}
 */
function previewAlreadyPdfUploadFile(isDetailPage, pdfUploadFileId, pdfUploadFilePath) {
    var strHtml = "";
    if (!isNaN(pdfUploadFileId) && pdfUploadFileId > 0) {
        var strHtml = '<a href="' + pdfUploadFilePath + '" idvalue="' + pdfUploadFileId + '" target="_blank" class="a_upload_file">';
        strHtml += '<input type="hidden" id="f_PdfUploadFileId" name="f_PdfUploadFileId" value="' + pdfUploadFileId + '">';
        strHtml += '<input type="hidden" id="f_PdfUploadFilePath" name="f_PdfUploadFilePath" value="' + pdfUploadFilePath + '">';
        if (!isDetailPage) {
            strHtml += '<div class="btn_del_upload_file_pdf" title="删除">X</div>';
        }
        strHtml += '<img class="icon_pdf" src="/front/ema_xwv_icswb_com/xwv_v2/img/pdf.png" title="PDF预览"></a>';
        return strHtml;
    }
    return strHtml;
}

/**
 * 显示已上传的PDF文件（作品链接）
 * @param {boolean} isDetailPage
 * @param {int} pdfUploadFileId
 * @param {string} pdfUploadFilePath
 * @returns {string}
 */
function previewAlreadyPdfUploadFile2(isDetailPage, pdfUploadFileId, pdfUploadFilePath) {
    var strHtml = "";
    if (!isNaN(pdfUploadFileId) && pdfUploadFileId > 0) {
        var strHtml = '<a href="' + pdfUploadFilePath + '" idvalue="' + pdfUploadFileId + '" target="_blank" class="a_upload_file">';
        strHtml += '<input type="hidden" id="f_PdfUploadFile2Id" name="f_PdfUploadFile2Id" value="' + pdfUploadFileId + '">';
        strHtml += '<input type="hidden" id="f_PdfUploadFile2Path" name="f_PdfUploadFile2Path" value="' + pdfUploadFilePath + '">';
        if (!isDetailPage) {
            strHtml += '<div class="btn_del_upload_file_pdf" title="删除">X</div>';
        }
        strHtml += '<img class="icon_pdf" src="/front/ema_xwv_icswb_com/xwv_v2/img/pdf.png" title="PDF预览"></a>';
        return strHtml;
    }
    return strHtml;
}

/**
 * 显示已上传的扫描件
 * @param {boolean} isDetailPage
 * @param {int} key
 * @param {int} picUploadFileId
 * @param {string} picUploadFilePath
 * @returns {string}
 */
function previewAlreadyScanPicUploadFile(isDetailPage, key, picUploadFileId, picUploadFilePath) {
    var strHtml = "";
    if (!isNaN(picUploadFileId) && picUploadFileId > 0) {
        var strHtml = '<a href="' + picUploadFilePath + '" idvalue="' + picUploadFileId + '" target="_blank" class="a_upload_file">';
        strHtml += '<input type="hidden" id="f_Pic' + key + 'UploadFileId" name="f_Pic' + key + 'UploadFileId" value="' + picUploadFileId + '">';
        strHtml += '<input type="hidden" id="f_Pic' + key + 'UploadFilePath" name="f_Pic' + key + 'UploadFilePath" value="' + picUploadFilePath + '">';
        if (!isDetailPage) {
            strHtml += '<div class="btn_del_upload_file_scan_pic" title="删除">X</div>';
        }
        strHtml += '<img src="' + picUploadFilePath + '" title="预览"></a>';
        return strHtml;
    }
    return strHtml;
}

/**
 * 显示评选详情的已上传的PDF文件
 * @param {boolean} isDetailPage
 * @param {int} pdfUploadFileId
 * @param {string} pdfUploadFilePath
 * @param {int} key
 * @returns {string}
 */
function previewAlreadyPdfUploadFileForXwvSelectItemInfo(isDetailPage, pdfUploadFileId, pdfUploadFilePath, key) {
    var strHtml = "";
    if (!isNaN(pdfUploadFileId) && pdfUploadFileId > 0) {
        var strHtml = '<a href="' + pdfUploadFilePath + '" idvalue="' + pdfUploadFileId + '" target="_blank" class="a_upload_file">';
        strHtml += '<input type="hidden" id="f_PdfUploadFileId' + key + '" name="f_PdfUploadFileId' + key + '" value="' + pdfUploadFileId + '">';
        strHtml += '<input type="hidden" id="f_PdfUploadFilePath' + key + '" name="f_PdfUploadFilePath' + key + '" value="' + pdfUploadFilePath + '">';
        if (!isDetailPage) {
            strHtml += '<div class="btn_del_upload_file_pdf" title="删除">X</div>';
        }
        strHtml += '<img class="icon_pdf" src="/front/ema_xwv_icswb_com/xwv_v2/img/pdf.png" title="PDF预览"></a>';
        return strHtml;
    }
    return strHtml;
}

/**
 * 显示已上传的记者证
 * @param {boolean} isDetailPage
 * @param {int} pressCardUploadFileId
 * @param {string} pressCardUploadFilePath
 * @returns {string}
 */
function previewAlreadyPressCardUploadFile(isDetailPage, pressCardUploadFileId, pressCardUploadFilePath) {
    var strHtml = "";
    if (!isNaN(pressCardUploadFileId) && pressCardUploadFileId > 0) {
        var strHtml = '<a href="' + pressCardUploadFilePath + '" idvalue="' + pressCardUploadFileId + '" target="_blank" class="a_upload_file">';
        strHtml += '<input type="hidden" id="f_PressCardUploadFileId" name="f_PressCardUploadFileId" value="' + pressCardUploadFileId + '">';
        strHtml += '<input type="hidden" id="f_PressCardUploadFilePath" name="f_PressCardUploadFilePath" value="' + pressCardUploadFilePath + '">';
        if (!isDetailPage) {
            strHtml += '<div class="btn_del_upload_file_press_card" title="删除">X</div>';
        }
        strHtml += '<img src="'+pressCardUploadFilePath+'" title="预览"></a>';
        return strHtml;
    }
    return strHtml;
}

/**
 * 显示附件
 * @param {int} uploadFileCount
 * @param {boolean} isDetailPage
 * @param {int} titlePic1UploadFileId
 * @param {string} titlePic1UploadFilePath
 * @param {int} titlePic2UploadFileId
 * @param {string} titlePic2UploadFilePath
 * @param {int} titlePic3UploadFileId
 * @param {string} titlePic3UploadFilePath
 * @param {int} titlePic4UploadFileId
 * @param {string} titlePic4UploadFilePath
 * @param {int} titlePic5UploadFileId
 * @param {string} titlePic5UploadFilePath
 * @returns {{html: *, fileCount: *}}
 */
function previewAlreadyUploadFile(uploadFileCount, isDetailPage,
                                  titlePic1UploadFileId, titlePic1UploadFilePath,
                                  titlePic2UploadFileId, titlePic2UploadFilePath,
                                  titlePic3UploadFileId, titlePic3UploadFilePath,
                                  titlePic4UploadFileId, titlePic4UploadFilePath,
                                  titlePic5UploadFileId, titlePic5UploadFilePath) {
    var strHtml = "";
    if (!isNaN(titlePic1UploadFileId) && titlePic1UploadFileId > 0) {
        uploadFileCount++;
        strHtml += getAlreadyUploadFileHtml(titlePic1UploadFileId, titlePic1UploadFilePath, 1, isDetailPage);
    }
    if (!isNaN(titlePic2UploadFileId) && titlePic2UploadFileId > 0) {
        uploadFileCount++;
        strHtml += getAlreadyUploadFileHtml(titlePic2UploadFileId, titlePic2UploadFilePath, 2, isDetailPage);
    }
    if (!isNaN(titlePic3UploadFileId) && titlePic3UploadFileId > 0) {
        uploadFileCount++;
        strHtml += getAlreadyUploadFileHtml(titlePic3UploadFileId, titlePic3UploadFilePath, 3, isDetailPage);
    }
    if (!isNaN(titlePic4UploadFileId) && titlePic4UploadFileId > 0) {
        uploadFileCount++;
        strHtml += getAlreadyUploadFileHtml(titlePic4UploadFileId, titlePic4UploadFilePath, 4, isDetailPage);
    }
    if (!isNaN(titlePic5UploadFileId) && titlePic5UploadFileId > 0) {
        uploadFileCount++;
        strHtml += getAlreadyUploadFileHtml(titlePic5UploadFileId, titlePic5UploadFilePath, 5, isDetailPage);
    }
    return {html: strHtml, fileCount: uploadFileCount};
}

/**
 * 拼已上传附件html
 * @param {int} titlePicUploadFileId
 * @param {string} TitlePicUploadFilePath
 * @param {int} keyNumber
 * @param {boolean} isDetailPage
 * @returns {string}
 */
function getAlreadyUploadFileHtml(titlePicUploadFileId, TitlePicUploadFilePath, keyNumber, isDetailPage) {
    var strHtml = '<a href="' + TitlePicUploadFilePath + '" idvalue="' + titlePicUploadFileId + '" target="_blank" class="a_upload_file">';
    strHtml += '<input type="hidden" id="f_TitlePic' + keyNumber + 'UploadFileId" name="f_TitlePic' + keyNumber + 'UploadFileId" value="' + titlePicUploadFileId + '">';
    strHtml += '<input type="hidden" id="f_TitlePic' + keyNumber + 'UploadFilePath" name="f_TitlePic' + keyNumber + 'UploadFilePath" value="' + TitlePicUploadFilePath + '">';
    if (!isDetailPage) {
        strHtml += '<div class="btn_del_upload_file" title="删除">X</div>';
    }
    strHtml += '<img src="'+TitlePicUploadFilePath+'" title="预览"></a>';
    return strHtml;
}

/**
 * 根据必传代表作的数量创建html
 * @param {int} xwvSelectItemInfoCount
 * @param {object} objXwvSelectItemInfo
 * @returns {string}
 */
function getHtmlByXwvSelectItemInfoCount(xwvSelectItemInfoCount, objXwvSelectItemInfo) {
    var strPre,strLast,strHtml = '';
    if (xwvSelectItemInfoCount > 0) {
        strPre = '<table class="table_border_next">';
        strLast = '</table>';
    }

    $.each(objXwvSelectItemInfo, function (i, item) {
        var row = i + 1;
        strHtml += '<tr>';
        strHtml += '    <td style="width:80px">代表作' + row + '<input type="hidden" id="f' + row + '_XwvSelectItemInfoId" name="f' + row + '_XwvSelectItemInfoId" value="' + item["XwvSelectItemInfoId"] + '"></td>';
        strHtml += '    <td><table class="table_border_in_td"><tr>';
        strHtml += '        <td style="width:80px">标题</td>';
        strHtml += '        <td class="td_input_in"><input id="f' + row + '_XwvSelectItemInfoName" name="f' + row + '_XwvSelectItemInfoName" type="text" class="input_normal needCheck" err_tips="请填写代表作' + row + '标题" check_type="text" value="' + item["XwvSelectItemInfoName"] + '"></td>';
        strHtml += '        <td style="width:80px">字数</td>';
        strHtml += '        <td style="width:130px" class="td_input_in"><input id="f' + row + '_WordCount" name="f' + row + '_WordCount" type="text" class="input_normal input_number needCheck" err_tips="请填写代表作' + row + '字数" check_type="text" value="' + item["WordCount"] + '"></td>';
        strHtml += '    </tr></table>';
        strHtml += '    <table class="table_border_in_td"><tr class="tr_has_no_bottom_border">';
        strHtml += '        <td style="width:80px">链接</td>';
        strHtml += '        <td class="td_input_in"><input id="f' + row + '_WebUrl" name="f' + row + '_WebUrl" type="text" class="input_normal needCheck" err_tips="请填写代表作' + row + '正确的链接" check_type="url" value="' + item["WebUrl"] + '"></td>';
        strHtml += '        <td style="width:80px" class="font_size_small">PDF版本<br>(含转版)</td>';
        strHtml += '        <td style="width:130px" class="td_upload_file_pdf left_text"><input class="input_upload_file_pdf pdf_control" type="file" id="upload_file_pdf' + row + '" name="upload_file_pdf' + row + '" accept="application/pdf"></td>';
        strHtml += '        <td style="width:80px">刊登日期</td>';
        strHtml += '        <td style="width:130px" class="td_input_in"><input id="f' + row + '_PublishDate" name="f' + row + '_PublishDate" type="text" class="input_normal date_picker needCheck" err_tips="请填写代表作' + row + '刊登日期" check_type="text" value="' + item["PublishDate"] + '" readonly></td>';
        strHtml += '    </tr></table></td>';
        strHtml += '</tr>';
    });

    var difference = xwvSelectItemInfoCount - objXwvSelectItemInfo.length;
    if (difference > 0) {
        for (var i = objXwvSelectItemInfo.length; i < xwvSelectItemInfoCount; i++) {
            var row = i + 1;
            strHtml += '<tr>';
            strHtml += '    <td style="width:80px">代表作' + row + '<input type="hidden" id="f' + row + '_XwvSelectItemInfoId" name="f' + row + '_XwvSelectItemInfoId" value=""></td>';
            strHtml += '    <td><table class="table_border_in_td"><tr>';
            strHtml += '        <td style="width:80px">标题</td>';
            strHtml += '        <td class="td_input_in"><input id="f' + row + '_XwvSelectItemInfoName" name="f' + row + '_XwvSelectItemInfoName" type="text" class="input_normal needCheck" err_tips="请填写代表作' + row + '标题" check_type="text" value=""></td>';
            strHtml += '        <td style="width:80px">字数</td>';
            strHtml += '        <td style="width:130px" class="td_input_in"><input id="f' + row + '_WordCount" name="f' + row + '_WordCount" type="text" class="input_normal input_number needCheck" err_tips="请填写代表作' + row + '字数" check_type="text" value=""></td>';
            strHtml += '    </tr></table>';
            strHtml += '    <table class="table_border_in_td"><tr class="tr_has_no_bottom_border">';
            strHtml += '        <td style="width:80px">链接</td>';
            strHtml += '        <td class="td_input_in"><input id="f' + row + '_WebUrl" name="f' + row + '_WebUrl" type="text" class="input_normal needCheck" err_tips="请填写代表作' + row + '正确的链接" check_type="url" value=""></td>';
            strHtml += '        <td style="width:80px" class="font_size_small">PDF版本<br>(含转版)</td>';
            strHtml += '        <td style="width:130px" class="td_upload_file_pdf left_text"><input class="input_upload_file_pdf pdf_control" type="file" id="upload_file_pdf' + row + '" name="upload_file_pdf' + row + '" accept="application/pdf"></td>';
            strHtml += '        <td style="width:80px">刊登日期</td>';
            strHtml += '        <td style="width:130px" class="td_input_in"><input id="f' + row + '_PublishDate" name="f' + row + '_PublishDate" type="text" class="input_normal date_picker needCheck" err_tips="请填写代表作' + row + '刊登日期" check_type="text" value="" readonly></td>';
            strHtml += '    </tr></table></td>';
            strHtml += '</tr>';
        }
    }

    strHtml = strPre + strHtml + strLast;

    return strHtml;
}

/**
 * 格式化是或否
 * @param {int} intValue
 * @returns {string}
 */
function formatYesOrNo(intValue) {
    var strHtml = "否";
    if (intValue === 1) {
        strHtml = "是";
    }
    return strHtml;
}

/**
 * 报送目录页确认排序
 * @param {string} sortJson 排序数组json
 * @param {function} callback
 */
function asyncConfirmSortInCatalog(sortJson, callback) {
    $.ajax({
        url: "/default.php?mod=xwv_select_item&a=async_confirm_sort_in_catalog",
        type: "POST",
        data: {json: sortJson},
        dataType: "jsonp",
        jsonp: "jsonpcallback",
        success: function (data) {
            callback(data);
        }
    });
}

/**
 * 取得专栏的代表作数量
 * @param {int} xwvSelectItemId
 * @param {int} isMainWork
 * @param {function} callback
 */
function asyncGetCountByXwvSelectItemId(xwvSelectItemId, isMainWork, callback) {
    $.ajax({
        url: "/default.php?mod=xwv_select_item_info&a=async_get_count_by_xwv_select_item_id",
        data: {xwv_select_item_id: xwvSelectItemId, is_main_work: isMainWork},
        dataType: "jsonp",
        jsonp: "jsonpcallback",
        success: function (data) {
            callback(data);
        }
    });
}

/**
 * 检查当前代表作数量是否能提交表单
 * @param {int} currentCountInDatabase 当前总数量
 * @param {string} formAction 表单提交接口
 * @param {int} oldSelectIsMainWork 之前的选择
 * @param {int} newSelectIsMainWork 当前的选择
 * @returns {{errMessage: *, canSubmit: *}}
 */
function canSubmitFormByMainWorkCount(currentCountInDatabase, formAction, oldSelectIsMainWork, newSelectIsMainWork) {
    var can = false;
    var message = "";
    if (newSelectIsMainWork === 1) {
        if (action === "create") {//新增
            if (currentCountInDatabase < window.LIMIT_COUNT_OF_COLUMNS) {
                can = true;
            } else {
                message = "代表作数量超过限制，仅允许" + window.LIMIT_COUNT_OF_COLUMNS + "个。";
            }
        } else {//修改
            if (oldSelectIsMainWork === 0 && currentCountInDatabase < window.LIMIT_COUNT_OF_COLUMNS) {
                can = true;
            } else if (oldSelectIsMainWork === 1 && currentCountInDatabase <= window.LIMIT_COUNT_OF_COLUMNS) {
                can = true;
            } else {
                message = "代表作数量超过限制，仅允许" + window.LIMIT_COUNT_OF_COLUMNS + "个。";
            }
        }
    } else {
        can = true;
    }
    return {canSubmit: can, errMessage: message};
}

/**
 * 申报目录页显示排序号还是行号
 * @param {object} object
 * @constructor
 */
function ShowSortOrRowNumberInCatalog(object) {
    var isConfirmedSort = false;//是否曾经确认过排序
    //只要有一个排序号非“0”，就是曾经确认过排序
    object.each(function () {
        var sort = parseInt($(this).attr("sort"));
        if (sort > 0) {
            isConfirmedSort = true;
            return false;
        }
    });
    if (isConfirmedSort) {
        object.each(function () {
            var sort = parseInt($(this).attr("sort"));
            $(this).val(sort);
        });
    } else {
        object.each(function () {
            var rowNumber = parseInt($(this).attr("row_number"));
            $(this).val(rowNumber);
        });
    }
}

function getBrowserInfo() {
    var ua = navigator.userAgent.toLocaleLowerCase();
    var browserType = null;
    if (ua.match(/msie/) != null || ua.match(/trident/) != null) {
        browserType = "IE";
        // browserVersion = ua.match(/msie ([\d.]+)/) != null ? ua.match(/msie ([\d.]+)/)[1] : ua.match(/rv:([\d.]+)/)[1];
    } else if (ua.match(/firefox/) != null) {
        browserType = "FireFox";
    } else if (ua.match(/ubrowser/) != null) {
        browserType = "UC";
    } else if (ua.match(/opera/) != null) {
        browserType = "欧朋";
    } else if (ua.match(/bidubrowser/) != null) {
        browserType = "百度";
    } else if (ua.match(/metasr/) != null) {
        browserType = "搜狗";
    } else if (ua.match(/tencenttraveler/) != null || ua.match(/qqbrowse/) != null) {
        browserType = "QQ";
    } else if (ua.match(/maxthon/) != null) {
        browserType = "遨游";
    } else if (ua.match(/chrome/) != null) {
        var is360 = _mime("type", "application/vnd.chromium.remoting-viewer");

        function _mime(option, value) {
            var mimeTypes = navigator.mimeTypes;
            for (var mt in mimeTypes) {
                if (mimeTypes[mt][option] == value) {
                    return true;
                }
            }
            return false;
        }

        if (is360) {
            browserType = '360';
        } else {
            browserType = 'Chrome';
        }
    } else if (ua.match(/safari/) != null) {
        browserType = "Safari";
    }
    return browserType;
}

/**
 * 提交表单前置检查输入项是否正确
 * @param objects
 * @returns {{res: boolean, errMsg: string}}
 */
function preCheckSubmitByAllInputObject(objects) {
    var result = {res: true, errMsg: ""};
    objects.each(function () {
        var inputText = $(this).val().replace(/^\s+|\s+$/g,'');//去两头空格
        var checkType = $(this).attr("check_type");
        var errTips = $(this).attr("err_tips");
        switch (checkType) {
            case "text":
                if (inputText.length <= 0) {
                    result = {res: false, errMsg: errTips};
                    return false;
                }
                break;
            case "select":
                if (parseInt(inputText) < 0) {
                    result = {res: false, errMsg: errTips};
                    return false;
                }
                break;
            case "mobile":
                if (inputText.length <= 0 || !checkMobileNumber(inputText)) {
                    result = {res: false, errMsg: errTips};
                    return false;
                }
                break;
            case "url":
                if (inputText.length <= 0 || !checkWebUrl(inputText)) {
                    result = {res: false, errMsg: errTips};
                    return false;
                }
                break;
            case "email":
                if (inputText.length <= 0 || !checkEmail(inputText)) {
                    result = {res: false, errMsg: errTips};
                    return false;
                }
                break;
            case "department":
                if (inputText.length <= 0
                    // || getLastCharFromString(inputText) !== "报"
                ) {
                    result = {res: false, errMsg: errTips};
                    return false;
                }
                break;
            case "checked":
                if (!$(this).is(":checked")) {
                    result = {res: false, errMsg: errTips};
                    return false;
                }
                break;
            default:
                result = {res: false, errMsg: "异常！未找到输入框检查类型，请联系管理员。"};
                return false;
        }
    });
    return result;
}

/**
 * 取字符串最后一个字符
 * @param {string} value
 * @returns {*|string}
 */
function getLastCharFromString(value) {
    return value.substr(value.length - 1, 1);
}

/** 用户登录 */
function asyncLogin(userAccount, userPass, callback) {
    $.ajax({
        url: "/default.php?mod=user&a=async_login",
        dataType: "jsonp",
        jsonp:"jsonpcallback",
        data: {
            user_account: userAccount,
            user_pass: userPass
        },
        success: function (data) {
            callback(data);
        }
    });
}

/** 修改密码 */
function asyncModifyPassword(oldPassword, newPassword, callback) {
    $.ajax({
        url: "/default.php?mod=user&a=async_modify_user_pass",
        data: {old_password: oldPassword, new_password: newPassword},
        dataType: "jsonp",
        jsonp: "jsonpcallback",
        success: function (data) {
            callback(data);
        }
    });
}

//去掉回车换行
function removeNR(value) {
    return value.replace(/[(\r\n)\r\n]+/g,"");
}

