$(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 ($("#place_Provinces").val() == "0" || $("#place_Cities").val() == "0" || $("#place_Districts").val() == "0") {
            $("#place_Provinces").parent("p").find("span").attr("class", "point ico-error R");
            $("#place_Provinces").parent("p").find("span").text("请选择籍贯");
            return false;
        } else {
            $("#place_Provinces").parent("p").find("span").attr("class", "point ico-via Q");
            $("#place_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); }
        });
    })

    ////////////////////////////////////////////////////////籍贯///////////////////////////////////////////////////////

    //绘出省
    function showPlaceProvices() {
        $.ajax({
            type: "get",
            url: "/XmlData/Provinces.xml",
            //data: null,
            datatype: "xml",
            beforeSend: function (xml) { },
            success: function (xml) {
                $("#place_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>";
                });
                $("#place_Provinces").html(showHtml);
            },
            error: function (xml) { alert('Error loading XML document' + xml); }
        });
    }
    showPlaceProvices();

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

                //清除
                $("#place_Cities").html("<option value=\"0\">== 选择城市 ==</option>");
                $("#place_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>";
                });
                $("#place_Cities").html(showHtml);

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

    //点击城市绘出区域
    $("#place_Cities").change(function () {
        var obj = $(this);
        $.ajax({
            type: "get",
            url: "/XmlData/Districts.xml",
            //data: null,
            datatype: "xml",
            beforeSend: function (xml) { },
            success: function (xml) {
                $("#place_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>";
                });
                $("#place_Districts").html(showHtml);
            },
            error: function (xml) { alert('Error loading XML document' + xml); }
        });
    })
})