$(function () {
    $("input[type=text]").val("");
    $("textarea").val("");
    $("#sb").attr("readonly", "readonly");
    $("#se").attr("readonly", "readonly");
    $("#sb").datepicker({ dateFormat: 'yy-mm-dd' });
    $("#se").datepicker({ dateFormat: 'yy-mm-dd' });

    $("#btnSave").click(function () {
        if (checkRequired('BugReport') == false) {
            return false;
        }
        files = $("input[type=file]");
        var failed = false;
        files.each(function () {

            if ($(this).val() != "") {

                var point = $(this).val().lastIndexOf(".");
                if (point <= 0) {
                    SetErrorMsg("未知的文件扩展名");
                    
                    failed = true;
                }

                var type = $(this).val().substr(point).toLowerCase();

                if (!(type == ".jpg" || type == ".jpeg" || type == ".bmp" || type == ".png" || type == "gif")) {
                    SetErrorMsg("图片格式仅支持jpg,bmp,png和gif"); 
                    failed = true;
                }
            }
        });

        if (failed) {
            return false;
        }         

        if (!IsEmail($("#CreatorEmail").val())) {
            $("#CreatorEmail").addClass("redBorder");

            SetErrorMsg("邮件格式不对");
            return false;
        }
        if (!confirm("确定提交吗？")) {
            return false;
        }
        return true;

    });
});


function AddAttachment() {
    if ($("input[type=file]").length > 10) {
        alert("最多只能添加10个附件！");
        return;
    }
    var date = new Date();
    var did = "D" + date.getDate() + date.getHours() + date.getMinutes() + date.getSeconds() + date.getMilliseconds();


    
    $("<div style='clear:both;height:36px;'><input style='float:left' type='file' id='" + did + "' name='" + did +
        "'/><button type=button onclick=\"DeleteAttachment('" + did + "');\" class='btn btn-sm btn-default'>删除附件</button> </div>").appendTo($("#tdAttachment")); 
}

function DeleteAttachment(did) { 
    $("input[id=" + did + "]").parent().remove();
}

