
    //城市区域联动
    function setCity(citySelector,areaSelector,plateSelector){
        var cityId = $("#"+citySelector).val();
        var baseArea = $("#"+areaSelector);
        var basePlate = $("#"+plateSelector);
        baseArea.find('option:not(:first-child)').remove();
        basePlate.find('option:not(:first-child)').remove();
        //城市联动区域
        searchCity(cityId,baseArea)
    }

    //区域联动板块
    function setArea(citySelector,areaSelector,plateSelector){
        var cityId = $("#"+citySelector).val();
        var areaId = $("#"+areaSelector).val();
        var basePlate = $("#"+plateSelector);
        basePlate.find('option:not(:first-child)').remove();
        searchArea(cityId,areaId,basePlate);
    }

    //搜索城市的方法
    function searchCity(cityId,optionId){
        $.ajax({
            type: "GET",
            url: "/tospur/wp-admin/admin-ajax.php",
            data: "action=serachCity&cityId="+cityId,
            success:function(json){
                addOption(json,optionId);
            }
        });
    }

    //搜索区域的方法
    function searchArea(cityId,areaId,optionId){
        $.ajax({
            type: "GET",
            url: "/tospur/wp-admin/admin-ajax.php",
            data: "action=serachCity&cityId="+cityId+"&districtId="+areaId,
            success:function(json){
                addOption(json,optionId);
            }
        });
    }

    function existsCancel(){
        $("#preview,#houseImg").on("click",".existsCancel,.featureCancel",function(){
            $(this).parent().remove();
        });
    }


    //租房与二手房中钥匙与车库的选项
    function setCheckBox(){
        $("input[id='keyCheck']").change(function(){
            textDisable("keyCheck","key");
        });
        $("input[id='garageCheck']").change(function(){
            textDisable("garageCheck","garage");
        });
    }



    //控制当二手房租房中钥匙与车库被勾选时，后面的文本域可使用
    function textDisable(checkId,textId){
        if($('input[id="'+checkId+'"]:checked').length > 0){
            $("#"+textId).removeAttr("disabled");
        }else{
            $("#"+textId).attr("disabled","true");
        }
    }



    //往给定id的select中添加option
    function addOption(json,select){
        var selectId = select.attr("id");
        //select.find('option:not(:first-child)').remove();
        for(var i = 0; i <=json.length-1; i++){
            var id = json[i]["id"];
            var value = json[i]["value"];
            if(value == ""){
                value = "不限";
            }
            if(selectId.indexOf("creage") > -1|| selectId.indexOf("rice") > -1){
                id = value;
            }
            var Option = $("<option>").attr({"value": id}).append(value);
            select.append(Option);
        }
    }

    //控制推荐房源与置业顾问的个数
    function controlCommand(id,number,type){
        var num  = $("#"+id+" > div").length;
        if(num>number){
            if(type==0){
                alert("最多只能推荐3个房源");
            }else if(type==1){
                alert("您只能推荐一位置业顾问");
            }
            $("#"+id).find("div:last-child").remove();
        }
    }

    function getUrlParmas(){
        var href = location.search.substr(1,location.search.length-1);
        var params = href.split("&");
        var map = {};
        for(item in params){
            var key = params[item].split("=")[0] || "";
            var value = params[item].split("=")[1] || "";
            map[key] = value;
        }
        return map;
    }

    function setDate(id){
        $("#"+id).datepicker({
            dateFormat: "yy-mm-dd"
        });
    }
    //建筑年代的下拉框
    function setAge(){
        for(var i = 1981; i<= 2020; i++){
            var option = $("<option>").append(i);
            $("#pageAge").append(option);
        }
    }

    //租房二手房中，修改界面下拉框的信息还原
    function revertOption(data){
        $.each(data,function(i,item){
            $("form").find("select[name='"+i+"']").val(item);
        });


    }

    //搜索面积的方法
    function searchAcreage(cityId,optionId){
        $.ajax({
            type: "GET",
            url: "/tospur/wp-admin/admin-ajax.php",
            data: "action=searchArea&cityId="+cityId,
            success:function(json){
                addOption(json,optionId);
            }
        });
    }
    //搜索单价的方法
    function searchPrice(cityId,optionId){
        $.ajax({
            type: "GET",
            url: "/tospur/wp-admin/admin-ajax.php",
            data: "action=searchUnitPriceRange&cityId="+cityId,
            success:function(json){
                addOption(json,optionId);
            }
        });
    }

    function searchTotalPrice(cityId,optionId){
        $.ajax({
            type: "GET",
            url: "/tospur/wp-admin/admin-ajax.php",
            data: "action=searchTotalPrice&cityId="+cityId,
            success:function(json){
                addOption(json,optionId);
            }
        });
    }

    function searchRentalPrice(cityId,optionId){
        $.ajax({
            type: "GET",
            url: "/tospur/wp-admin/admin-ajax.php",
            data: "action=searchRentalPrice&cityId="+cityId,
            success:function(json){
                addOption(json,optionId);
            }
        });
    }

    function search_form_set_page(){
        var search_flag = false;
		var search_form = $('#search_form');
        $('form').submit(function () {
            var search_select = search_form.find('select');
            var search_input = search_form.find('input[type=text],input[type=date]');
            $.each(search_select, function (index, item) {
                var search_select_value = $(item).find('option:selected').val();
                if (search_select_value != -1) {
                    search_flag = true;
                }
            });
            $.each(search_input, function (index, item) {
                var search_input_value = $(item).val();
                if (search_input_value != '') {
                    search_flag = true;
                }
            });
            if (search_flag) {
                $('input[name=paged]').val('1');
            }
        });
    }

    function allot_consultant(name) {
        //批量操作
        $('select[name=action],select[name=action2]').change(function () {
            //分配置业顾问
            if ($(this).find('option:selected').val() == 'allot') {
                //选择房/客源
                var checkbox = $('input[name="' + name + '[]"]');
                if (checkbox.is(':checked')) {
                    var array = [];
                    $('input[name="' + name + '[]"]:checked').map(function () {
                        var consultant_id = Number($(this).data('consultant'));
                        if (array.indexOf(consultant_id) == -1) {
                            array.push(consultant_id);
                        }
                    });
                    var confirmFlag = true;
                    if (array.length > 1) {
                        confirmFlag = confirm('当前选择的房/客源置业顾问不同，是否继续');
                    }
                    if (confirmFlag) {
                        $('#myConsultant').modal('show');
                    }
                    //未选择房/客源，下拉框显示批量操作
                } else {
                    $(this).find('option:first').attr('selected', 'selected');
                    alert('请选择房/客源');
                    return false;
                }
            }
        });
        init_modal_myConsultantList(function (data) {
            var consultant_id = Number(data.id);
            $('#allot_consultant_id').val(consultant_id);
            $( "#doaction" ).trigger( "click" );
        });

        $("#myConsultant").on("hide.bs.modal", function () {
            var allot_consultant_id = Number($('#allot_consultant_id').val());
            if (!allot_consultant_id) {
                $('select[name=action],select[name=action2]').find('option:first').attr('selected', 'selected');
            }
        });
    }
    Date.prototype.Format = function (fmt) {
        var o = {
            "M+": this.getMonth() + 1,
            "d+": this.getDate(),
            "h+": this.getHours(),
            "m+": this.getMinutes(),
            "s+": this.getSeconds(),
            "q+": Math.floor((this.getMonth() + 3) / 3),
            "S": this.getMilliseconds()
        };
        if (/(y+)/.test(fmt))
            fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
        for (var k in o)
            if (new RegExp("(" + k + ")").test(fmt))
                fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
        return fmt;
    };



