
    //城市区域联动
    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,#feature").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");
        }
    }


    //搜索置业顾问的方法
    function searchConsultant(consulCityId,consultantName){
        $.ajax({
            type: "GET",
            url: "/tospur/wp-admin/admin-ajax.php",
            data: "action=searchConsultant&consulCityId="+consulCityId+"&consultantName="+consultantName,
            success:function(json){
                for(var i = 0; i <=json.length-1; i++){
                    var name = json[i]["consultantName"];
                    var imgUrl = json[i]["imageUrl"];
                    var img = $("<img>").attr({"src":imgUrl,"height":100,"width":100,"style":"margin-right:50px"});
                    var li = $("<li>").attr("id",json[i]["id"]).append(img).append(name).addClass("consultantImg");
                    $("#consultantList").append(li);
                }
            }
        });
    }


    //往给定id的select中添加option
    function addOption(json,select){
        var selectId = select.attr("id");
        for(var i = 0; i <=json.length-1; i++){
            var id = json[i]["id"];
            var value = json[i]["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+" > p").length;
        if(num>number){
            if(type==0){
                alert("最多只能推荐3个房源");
            }else if(type==1){
                alert("您只能推荐一位置业顾问");
            }
            $("#"+id).find("p: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);
            }
        });
    }




