$(function () {
    //提交判断
    $("form").submit(function () {
        $("input[type='text'],input[type='password'],textarea").trigger("blur");

        ///新增方法填写在此///
        //所在地
        if ($("#seat_Provinces").val() == "0" || $("#seat_Cities").val() == "0" || $("#seat_Districts").val() == "0") {
            $("#seat_Provinces").parent("p").find("span").attr("class", "point ico-error R");
            $("#seat_Provinces").parent("p").find("span").text("请选择所在地");
            return false;
        } else {
            $("#seat_Provinces").parent("p").find("span").attr("class", "point ico-via Q");
            $("#seat_Provinces").parent("p").find("span").text("验证通过");
        }

        /////

        if ($("form span").hasClass("ico-error")) {
            $("input:submit").attr("disabled", false);
            alert("请按照提示正确操作，检查各项填写");
            return false;
        } else {
            $("input:submit").attr("disabled", true);
            $("input:submit").next("span").attr("class", "Q");
            $("input:submit").next("span").html("正在提交中…");
        }
    });

    ////////////////////////////////////////////////////////所在地///////////////////////////////////////////////////////

    //绘出省
    function showSeatProvices() {
        $.ajax({
            type: "get",
            url: "/XmlData/Provinces.xml",
            //data: null,
            datatype: "xml",
            beforeSend: function (xml) { },
            success: function (xml) {
                $("#seat_Provinces").attr("disabled", false);
                var showHtml = "<option value=\"0\"> == 选择省份 ==</option>";
                $(xml).find("Provinces > Province").each(function (i) {
                    showHtml += "<option value=\"" + $(this).attr("ID") + "\">" + $(this).attr("ProvinceName") + "</option>";
                });
                $("#seat_Provinces").html(showHtml);
            },
            error: function (xml) { alert('Error loading XML document' + xml); }
        });
    }
    showSeatProvices();

    //点击省绘出市
    $("#seat_Provinces").change(function () {
        var obj = $(this);
        $.ajax({
            type: "get",
            url: "/XmlData/Cities.xml",
            //data: null,
            datatype: "xml",
            beforeSend: function (xml) { },
            success: function (xml) {
                $("#seat_Cities").attr("disabled", false);

                //清除
                $("#seat_Cities").html("<option value=\"0\">== 选择城市 ==</option>");
                $("#seat_Districts").html("<option value=\"0\">== 选择地区 ==</option>");

                var showHtml = "<option value=\"0\"> == 选择城市 ==</option>";
                $(xml).find("Cities > City[PID=" + obj.val() + "]").each(function (i) {
                    showHtml += "<option value=\"" + $(this).attr("ID") + "\">" + $(this).attr("CityName") + "</option>";
                });
                $("#seat_Cities").html(showHtml);

            },
            error: function (xml) { alert('Error loading XML document' + xml); }
        });
    })

    //点击城市绘出区域
    $("#seat_Cities").change(function () {
        var obj = $(this);
        $.ajax({
            type: "get",
            url: "/XmlData/Districts.xml",
            //data: null,
            datatype: "xml",
            beforeSend: function (xml) { },
            success: function (xml) {
                $("#seat_Districts").attr("disabled", false);
                var showHtml = "<option value=\"0\">== 选择地区 ==</option>";
                $(xml).find("Districts > District[CID=" + obj.val() + "]").each(function (i) {
                    showHtml += "<option value=\"" + $(this).attr("ID") + "\">" + $(this).attr("DistrictName") + "</option>";
                });
                $("#seat_Districts").html(showHtml);
            },
            error: function (xml) { alert('Error loading XML document' + xml); }
        });
    })
})