function create() {
    var title = document.getElementById("title");
    if (title.value.length == 0) {
        alert("主标题不可为空！");
        return;
    }
    var subtitle = document.getElementById("subtitle");
    if (subtitle.value.length == 0) {
        alert("副标题不可为空！");
        return;
    }
    var startTime = document.getElementById("starttime");
    if (startTime.value.length == 0) {
        alert("开始时间不可为空！");
        return;
    }
    var endTime = document.getElementById("endtime");
    if (endTime.value.length == 0) {
        alert("结束时间不可为空！");
        return;
    }
    // 比较开始时间和结束时间
    var momentStartTime = moment(startTime.value)
    var momentEndTime = moment(endTime.value)
    if (momentEndTime.isSameOrBefore(momentStartTime)) {
        alert("结束时间必现大于开始时间")
        return
    }
    var cover = document.getElementById("cover");
    if (cover.src.length == 0) {
        alert("封面图不可为空！");
        return;
    }
    var fineWork = document.getElementById("input-fine-work")
    var master = document.getElementById("input-master")
    var classification = document.getElementById("classification");

    $.ajax({
        type: "POST",
        url: "/manage_exhibitions/create",
        data: JSON.stringify({
            title: title.value,
            subtitle: subtitle.value,
            start_time: dateFormat(startTime.value),
            end_time: dateFormat(endTime.value),
            cover: cover.src,
            fine_work: fineWork.checked,
            master: master.checked,
            classification: Number(classification.value)
        }),
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (user) {
            alert("创建展览成功");
            location.href = "/manage/manage_exhibitions?valid=1&index=1";
        },
        error: function (xhr, textStatus, error) {
            var msg = JSON.parse(xhr.responseText);
            alert(msg.error);
        }
    });
}

function back() {
    history.back();
}

// upload
document.getElementById("upload-btn").addEventListener('change', function(event){
    uploadExhibitionCover(event.target, function(url) {
        var cover = document.getElementById("cover");
        cover.src = url;
    })
});