/*!
 * Modernizr v2.8.3
 * www.modernizr.com
 *
 * Copyright (c) Faruk Ates, Paul Irish, Alex Sexton
 * Available under the BSD and MIT licenses: www.modernizr.com/license/
 */

/*
 * 城市选择控件
 */


(function ($) {




    $.SelectBusinssareas = function (_l, backData) {
        
        $.popAlter({
            content: "正在加载城市，请稍等...", okCallback: function (btnval) {
                if (btnval == 1) {

                    var that = $(".ok-click");
                    that.hide().after("<span>请稍后...</span>");


                    var vselt = $("#kd_CityCon").children("li").length;
                    if (vselt == undefined || vselt == 0) {
                        alert("请选择城市");

                        that.show().next("span").remove();
                    } else {

                        var areaData = "";
                        $('#sysmodal').modal('hide');

                        $("#kd_CityCon").children("li").each(function (i, n) {

                            var cityId = $(this).attr("cityId");
                            var parents = $(this).attr("parents");
                            var cityName = $(this).attr("cityName");
                            if (i == 0) {
                                areaData += '{Id:' + cityId + ',parents:"' + parents + '",Name:"' + cityName + '"}';
                            }
                            else {
                                areaData += ',{Id:' + cityId + ',parents:"' + parents + '",Name:"' + cityName + '"}';
                            }
                        });

                        var areas = eval("([" + areaData + "])");
                        backData(areas);
                    }
                }
            }, Buttons: [{Name:'确定',Val:1}]
        });

        var parentId = _l.parentId;
        var cityIds = _l.cityIds;
        var deep = _l.deep;
        var at = _l.at;

        if (at == '' || at == undefined) {
            at = 0;
        }

        if (deep == '' || deep == undefined) {
            deep = 3;
        }

        $.ajax({
            type: "POST",
            url: "/CityArea/AreaPartial?at="+at+"&parentId=" + parentId + "&cityIds=" + cityIds + "&deep=" + deep,
            success: function (data) {
                $(".modal-body").html(data);
            }
        });
    }
    $.Selectareas = function (_l, backData) {


        $.popAlter({
            content: "正在加载城市，请稍等...", okCallback: function (btnval) {
                if (btnval == 1) {
                    var that = $(".ok-click");
                    that.hide().after("<span>请稍后...</span>");
                    var val = $("#kq_content").find('input:radio:checked').attr("Parents");
                    
                    if (val == undefined || val == "") {
                        alert("请选择城市");

                        that.show().next("span").remove();
                    } else {
                        $('#sysmodal').modal('hide');
                        $.ajax({
                            type: "POST",
                            url: "/CityArea/CommonAreasListByIds?ids=" + val,
                            success: function (data) {

                                backData(data);
                            }
                        });
                    }
                }
            },
            Buttons: [{Name:"确定",Val:1}]
        });

        var parentId = _l.parentId;
        var deep = _l.deep;
        var at = _l.at;

        if (at == '' || at == undefined) {
            at = 0;
        }
        if (deep == '' || deep == undefined) {
            deep = 3;
        }
        $.ajax({
            type: "POST",
            url: "/CityArea/AreaPartial?at=" + at + "&parentId=" + parentId + "&deep=" + deep,
            success: function (data) {


                $(".modal-body").html(data);
            }
        });
    }
})(jQuery);