$(function () {
    function ValidTemp() {
        var ModelName = $("#ModelName"),
        AppPoolTempId = $("#AppPoolTempId"),
        BandWidth = $("#BandWidth"),
        Space = $("#Space"),
        Flow = $("#Flow"),
        vPath = $("#vPath"),
        IIS = $("#IIS"),
        UserPath = $("#UserPath"),
        defaultDOC = $("#defaultDOC"),
        HttpErrors = $("#HttpErrors"),
        ShareSiteNum = $("#ShareSiteNum"),
        ScriptMaps = $("#ScriptMaps"),
        FreeDomain = $("#FreeDomain"),
    allFields = $([])
        .add(ModelName)
        .add(AppPoolTempId)
        .add(BandWidth)
        .add(Space)
        .add(Flow)
        .add(vPath)
        .add(IIS)
        .add(UserPath)
        .add(defaultDOC)
        .add(HttpErrors)
        .add(ShareSiteNum)
        .add(ScriptMaps)
        .add(FreeDomain)
        ;
        var bValid = true;
        allFields.removeClass("ui-state-error");
        bValid = bValid && checkLength(ModelName, "模版名称", 3, 16);
        bValid = bValid && checkNumlength(AppPoolTempId, "选择程序池", 1, 2147483647);
        bValid = bValid && checkNumlength(BandWidth, "带宽", 0, 32767);
        bValid = bValid && checkNumlength(Space, "空间容量", 0, 2147483647);
        bValid = bValid && checkNumlength(Flow, "月流量", 0, 2147483647);
        bValid = bValid && checkNumlength(vPath, "子目录数", 0, 2147483647);
        bValid = bValid && checkNumlength(IIS, "IIS连接数", 0, 2000000000);
        bValid = bValid && checkRegexp(UserPath, RegEx_WindowsPath, "用户存放目录格式不正确");

        bValid = bValid && checkLength(defaultDOC, "默认文档",1, 512);
        bValid = bValid && checkRegexp(HttpErrors, RegEx_UrlPath, "404错误地址不能为空");
        bValid = bValid && checkNumlength(ShareSiteNum, "程序池共享站点数", 0, 2147483647);
        bValid = bValid && checkLength(ScriptMaps, "如：.asp,.php,.aspx", 3, 2147483647);
        bValid = bValid && checkRegexp(FreeDomain, RegEx_Domain, "赠送域名格式错误");
        return bValid;
    }
    $("form").submit(function () {
        if (!ValidTemp()) {
            $(this).find("button[type=submit]").removeClass("loading").removeAttr("disabled");
            return false;
        }
    });
});