﻿var _cityObj = FtMap.getCityParams(window.location.hostname.split(".")[0]);
FCConfig.city = _cityObj.code;
var mout;   //城市选择菜单(待封装...)

/*  
   ftmapSearch: 地图搜索对象
*/
var ftmapSearch = {
    params: '',
    key: Methods.getURLParam(window.location.href, "k"),

    sbus: Methods.getURLParam(window.location.href, "sb"),
    ebus: Methods.getURLParam(window.location.href, "eb"),

    bn: Methods.getURLParam(window.location.href, "k"),
    regioncode: Methods.getURLParam(window.location.href, "regioncode"),
    nb: Methods.getURLParam(window.location.href, "nb"),
    price: Methods.getURLParam(window.location.href, "price"),
    r: Methods.getURLParam(window.location.href, "r"),
    p: Methods.getURLParam(window.location.href, "p"),

    mode: false,    //true:map; false:list;   
    parameter: "",
    state: true,

    init: function() {    //面页初始化
        if ($('.select_search .selected').length == 0) $('.select_search li').eq(0).addClass('selected');
        ftmapSearch.initialName = jQuery.trim($(".select_search .selected").text()); //默认搜索类型        
        ftmapSearch.selectName = ftmapSearch.initialName,  //当前搜索类型  
        ftmapSearch.ftsearchCutover(ftmapSearch.initialName); //初始默认类型信息        
        $(".select_search li").bind("click", function(e) {     //绑定搜索类型按钮
            ftmapSearch.state = ftmapSearch.initialName == jQuery.trim($(this).text());
            $(".select_search .selected").attr("class", "");
            $(this).attr("class", "selected");
            ftmapSearch.selectName = $.trim($(this).text());
            ftmapSearch.ftsearchCutover(ftmapSearch.selectName);
        });
        if (ftmapSearch.bn) $("#_keywork").focus().val(ftmapSearch.bn);
        if (ftmapSearch.key) $("#_keywork").focus().val(ftmapSearch.key);
        if (ftmapSearch.sbus) $("#bus_start").focus().val(ftmapSearch.sbus);
        if (ftmapSearch.ebus) $("#bus_end").focus().val(ftmapSearch.ebus);
    },

    ftsearchCutover: function(n) {
        $("#_keywork").removeClass();
        switch (n) {
            case "房价地图":    //地图模式
                ftmapSearch.example = "输入小区名、地址";
                $("#e_bus,#mapSearch").hide(); $("#_keywork").addClass("ss_txt").show();
                break;
            case "新房":
                ftmapSearch.example = "输入小区名、地址";
                $("#e_bus").hide(); $("#_keywork").addClass("ss_txt_map").show(); $("#mapSearch").show();
                break;
            case "商业":
                ftmapSearch.example = "输入小区名、地址";
                $("#e_bus").hide(); $("#_keywork").addClass("ss_txt_map").show(); $("#mapSearch").show();
                break;
            case "二手房":
                ftmapSearch.example = "输入小区名、地址";
                $("#e_bus").hide(); $("#_keywork").addClass("ss_txt_map").show(); $("#mapSearch").show();
                break;
            case "租房":
                ftmapSearch.example = "输入小区名、地址";
                $("#e_bus").hide(); $("#_keywork").addClass("ss_txt_map").show(); $("#mapSearch").show();
                break;
            case "小区房价":
                ftmapSearch.example = "输入小区名、地址";
                //ftmapSearch.url = "/building/";
                $("#e_bus,#mapSearch").hide(); $("#_keywork").addClass("ss_txt").show();
                break;
            case "经纪人":
                ftmapSearch.example = "输入经纪人名、门店名";
                //ftmapSearch.url = "/broker/";
                $("#e_bus,#mapSearch").hide(); $("#_keywork").addClass("ss_txt").show();
                break;
            case "公交":        //地图模式                
                $("#bus_start").example("输入起点", { class_name: 'fgrey' });
                $("#bus_end").example("输入终点", { class_name: 'fgrey' });
                $("#_keywork,#mapSearch").hide(); $("#e_bus").show();
                return; break;
        }
        //搜索框事件
        $("#_keywork").unbind().example(ftmapSearch.example, { class_name: 'fgrey' }).searchAuto();
    },

    ftbusConversion: function() { //获取返程路线
        var s = jQuery.trim($("#bus_start").val());
        var e = jQuery.trim($("#bus_end").val());
        if (s != "" && s != "输入起点" && e != "" && e != "输入终点") {
            $("#bus_start").val(e);
            $("#bus_end").val(s);
        }
        this.ftSubmit();
    },

    ftbusSearch: function() { //公交搜索
        var urlWriter = new UrlWriterHelper(this.url);
        var s = jQuery.trim($("#bus_start").val());
        var e = jQuery.trim($("#bus_end").val());
        if (s == "" || s == "输入起点") { alert("请输入起点"); $("#bus_start").focus(); return; }
        if (e == "" || e == "输入终点") { alert("请输入终点"); $("#bus_end").focus(); return; }
        //提交数据返回搜索结果
        //this.parameter = Methods.addTimeparam("?sb=" + encodeURIComponent(s) + "&eb=" + encodeURIComponent(e));
        this.params = urlWriter.QueryExceptParam(this.params, "sb", encodeURIComponent(s));
        this.params = urlWriter.QueryExceptParam(this.params, "eb", encodeURIComponent(e));
        window.open(this.url + this.params + "/", "_blank");   //"_self"
    },

    ftKeySearch: function() { //关键字搜索
        if (!ftmapSearch.mode) {
            var urlWriter = new UrlWriterHelper(this.url);
            var key = $.trim($("#_keywork").val()); if (key == "" || key == ftmapSearch.example) key = "";
            this.params = urlWriter.QueryExceptParam(this.params, "k", encodeURIComponent(key));
            window.open(urlWriter.MakeUrl(this.params, "", ""), ftmapSearch.mode ? "_blank" : "_self");
        }
        else {
            var key = $.trim($("#_keywork").val());
            /* 空搜索模式 */
            if (key == "" || key == ftmapSearch.example) key = "";
            switch (ftmapSearch.selectName) {
            
                case "二手房":this.parameter = "?menu=3&k=" + encodeURIComponent(key);break;
                case "租房":this.parameter = "?menu=3&k=" + encodeURIComponent(key);break;
                case "商业":this.parameter = "?menu=2&k=" + encodeURIComponent(key);break;
                default:this.parameter = "?k=" + encodeURIComponent(key);break;
            }
            
            //提交数据返回搜索结果
            var x = "", y = "";
            if (typeof (buildingsResult) != 'undefined') {
                $.each(buildingsResult.Items, function(e) {
                    if (buildingsResult.Items[e].BuildingName == key) {
                        x = buildingsResult.Items[e].X;
                        y = buildingsResult.Items[e].Y;
                        return false;
                    }
                })
                if (x != "" && y != "") {
                    var o = FtMap.gisToE(FCConfig.city, x, y);
                    x = o.x;
                    y = o.y;
                }
            }
            this.parameter += "&x=" + x + "&y=" + y;
            
            window.open(this.url + Methods.addTimeparam(this.parameter), ftmapSearch.mode ? "_blank" : "_self");
        }
    },

    ftSubmit: function(obj) {    //提交搜索
        ftmapSearch.mode = false;
        switch (ftmapSearch.selectName) {
            case "公交":
                ftmapSearch.url = "/map/transit/"; ftmapSearch.params = "sb_eb";
                ftmapSearch.ftbusSearch(); return;
            case "房价地图":
                ftmapSearch.url = "/map/default.aspx";
                ftmapSearch.mode = true; break;
            case "新房":
                var key = $.trim($("#_keywork").val());
                if (key == "" || key == ftmapSearch.example) { key = ""; }
                if ($(obj).attr("mode") == "map") { ftmapSearch.url = "/newbuilding/newhousemap.aspx"; ftmapSearch.mode = true; }
                else { ftmapSearch.url = "/house/new/"; ftmapSearch.params = "regioncode_bid0_era_k_price_t0_crm_time_adb_ade_pdb_pde_bp_nb0_py_brd0_odb"; }
                break;
            case "商业":
                var key = $.trim($("#_keywork").val());
                if (key == "" || key == ftmapSearch.example) { key = ""; }
                if ($(obj).attr("mode") == "map") { ftmapSearch.url = "/house/biz/housemap.aspx"; ftmapSearch.mode = true; }
                else { ftmapSearch.url = "/house/biz/"; ftmapSearch.params = "a_ud0_bid0_regioncode_ct_cid0_expt-1_csid0_ccid0_brd0_bp_fl_k_bht0_sdp_swd_sht_sw0_tp_lp_ldp_pbr_ut_odb"; }
                break;
            case "二手房":
                var key = $.trim($("#_keywork").val());
                if (key == "" || key == ftmapSearch.example) { key = ""; }
                if ($(obj).attr("mode") == "map") { ftmapSearch.url = "/house/trade/housemap.aspx"; ftmapSearch.mode = true; }
                else { ftmapSearch.url = "/house/trade/"; ftmapSearch.params = "a_ud0_bid0_regioncode_ct_cid0_expt-1_csid0_ccid0_brd0_bp_fl_k_hk0_p_r_spt0_sc-1_era_dk_odb_menu0" }
                break;
            case "租房":
                var key = $.trim($("#_keywork").val());
                if (key == "" || key == ftmapSearch.example) { key = ""; }
                if ($(obj).attr("mode") == "map") { ftmapSearch.url = "/house/lease/housemap.aspx"; ftmapSearch.mode = true; }
                else { ftmapSearch.url = "/house/lease/"; ftmapSearch.params = "a_ud0_bid0_regioncode_ct_cid0_expt-1_csid0_ccid0_brd0_bp_fl_k_hk0_p_ut_lw_fee_r_rpt0_dk_odb" }
                break;
            case "小区房价": ftmapSearch.url = "/building/"; ftmapSearch.params = "regioncode_bid0_era_k_bp_isnew_py_adb_ade_t0_odb"; break;
            case "经纪人": ftmapSearch.url = "/broker/"; ftmapSearch.params = "k_regioncode"; break;
        }
        ftmapSearch.ftKeySearch();
    }
}

/*  
   ftbusSearch: 公交搜索对象
*/
var ftbusSearch = {
    linePoints: new Array(),    
    currBusItemId: 0,    
    init:function(){
        $("#sbus").example("输入起点", {class_name:'fgrey'}).bind("keydown",function(e){if(e.keyCode == 13)ftbusSearch.searchBusNo();return;});
        $("#ebus").example("输入终点", {class_name:'fgrey'}).bind("keydown",function(e){if(e.keyCode == 13)ftbusSearch.searchBusNo();return;});
        $(".mini_soso_btn").bind("click",ftbusSearch.searchBusNo);
        if(ftmapSearch.sbus)$("#sbus").focus().val(ftmapSearch.sbus);
        if(ftmapSearch.ebus)$("#ebus").focus().val(ftmapSearch.ebus);
        ftbusSearch.ftmapSearcher();
        if(ftmapSearch.sbus!="")ftbusSearch.searchBusNo();
    },
    
    searchBusNo:function(){
        var s = jQuery.trim($("#sbus").val());
        var e = jQuery.trim($("#ebus").val());
        if(s=="" || s=="输入起点"){alert("请输入起点");$("#sbus").focus();return;}
        if(e=="" || e=="输入终点"){alert("请输入终点");$("#ebus").focus();return;}
        $(".wxts").innerHTML = "<img src='http://www.fangtoo.com/about/ft/loading.gif' title='正在检索数据...'/>正在检索公交信息....";
        ftbusSearch.mapSearcher.searchBus(_cityObj.name, $P("sbus").value, $P("ebus").value);
        ftbusSearch.currBusItemId = 0;
    },
    
    
    ftmapSearcher:function(){   //初始化搜索器        
        this.mapSearcher = new FtMapSearch();    
        this.mapSearcher.onBusSearchResponse = this.searchMapBusPositionResponse;
        this.mapSearcher.onBusPathSearchResponse = this.searchMapBusPathResponse;
        this.mapSearcher.onPosClick = this.searchBusStationClick;
    },
    
    searchMapBusPositionResponse: function(data){    //公交搜索返回
        if(data.start <= 0) {
            $(".wxts").html("&nbsp;<img src=\"" + FCConfig.staticHostHeadSite + "/images/map_start_point.gif\" align=\"absmiddle\" /> 我们无法明确此目的地<font style='color:red'>起点</font>,请修改输入重新搜索！");
            $("#sbus").focus().val(""); $(".wxts").show("fast"); $("#bus_list").hide("fast"); return;
        }
        if(data.end <= 0) {
            $(".wxts").html("&nbsp;<img src=\"" + FCConfig.staticHostHeadSite + "/images/map_end_point.gif\" align=\"absmiddle\" /> 我们无法明确此目的地<font style='color:red'>终点</font>,请修改输入重新搜索！");
            $("#ebus").focus().val(""); $(".wxts").show("fast"); $("#bus_list").hide("fast"); return;
        }
        var ctx=new Array();
        ctx[ctx.length] = "<p><strong><img src=\"" + FCConfig.staticHostHeadSite + "/images/map_start_point.gif\" align=\"absmiddle\" />&nbsp;起点，请选择最合适的地址</strong><select id=\"orgPOS\" size=\"8\" class=\"select_item\" onchange=\"ftbusSearch.setMapPos(this)\">";
        for(var i = 0; i < data.start.length; i++){
            var posItem = data.start[i];
            ctx[ctx.length] = "<option id=\""+ posItem.point.l +","+ posItem.point.b+"\" value=\""+ posItem.pos +"\"";
            ctx[ctx.length] = (i != 0)? ">" : "selected=\"selected\">"
            ctx[ctx.length] = posItem.name;
            ctx[ctx.length] = (posItem.station == "false") ? "" : "公交站";
            ctx[ctx.length] = "</option>"
        }
        ctx[ctx.length] ="</select></p>";
        ctx[ctx.length] = "<p><strong><img src=\"" + FCConfig.staticHostHeadSite + "/images/map_end_point.gif\" align=\"absmiddle\" />&nbsp;终点，请选择最合适的地址</strong><select id=\"desPOS\" size=\"8\" class=\"select_item\" onchange=\"ftbusSearch.setMapPos(this)\">";
        for(var i = 0; i < data.end.length; i++){
            var posItem = data.end[i];
            ctx[ctx.length] = "<option id=\""+ posItem.point.l +","+ posItem.point.b+"\" value=\""+ posItem.pos +"\"";
            ctx[ctx.length] = (i != 0) ? ">" : "selected=\"selected\">"
            ctx[ctx.length] = posItem.name;
            ctx[ctx.length] = (posItem.station=="false") ? "" : "公交站";
            ctx[ctx.length] = "</option>"
        }
        ctx[ctx.length] ="</select></p>";
        ctx[ctx.length] ="<input type='button' class='public_btn' value='继续搜索 ' onclick='ftbusSearch.searchMapBusPath()' >";
    	
        $("#bus_list").html(ctx.join(''));    
        var pointPos = $P("orgPOS").options[$P("orgPOS").selectedIndex].id.split(",");
        PageMap.mapB.setMapCenter(pointPos[0],pointPos[1],true);
        $(".wxts,#divBA1").hide("fast");
        $("#bus_list").show("fast"); 
    },

    searchMapBusPath: function(){    //继续搜索入口
        var desPOS,orgPOS,desName,orgName;
        desPOS = $P("desPOS").options[$P("desPOS").selectedIndex].value;
        desName = Methods.getSelectText($P("desPOS"));
        orgPOS = $P("orgPOS").options[$P("orgPOS").selectedIndex].value;
        orgName = Methods.getSelectText($P("orgPOS"));
        $("#bus_list").html("<img src='http://www.fangtoo.com/about/ft/loading.gif' title='正在检索数据...'/>正在检索公交信息....");
        ftbusSearch.mapSearcher.searchBusPath(orgPOS,orgName,desPOS,desName);
    },

    searchMapBusPathResponse: function(data) {   //继续搜索返回
        var ctx=new Array();
        ftbusSearch.linePoints.length = 0;
        ctx[ctx.length] = "<div class='bus_list_title'>从 <span>" + data.startName + "</span> 到 <span>" + data.endName + "</span> 共有 <span>" + data.count + "</span> 套方案 <a href='javascript:ftbusSearch.searchBusNo();'>返回</a></div>";
        for(var i = 0; i < data.length; i++)
        {
            ctx.push("<div id=\"list_" + i + "\"");
            ctx.push(i == 0 ? "class=\"bus_list_pick\">" : "class=\"bus_list\" onmouseover=\"this.className='bus_list_over'\" onmouseout=\"this.className='bus_list'\">");
            ctx.push("<p onclick=\"ftbusSearch.showBusItem(" + i + ")\" class=\"plan\">方案<strong>" + (i + 1) + "</strong>:");
            ctx.push(data[i].changeTimes == 0 ? "<nobr>" + data[i].title + "<strong>直达</strong></nobr>" : "<nobr title=\"" + data[i].title + "\">" + data[i].title + "<span>换乘" + data[i].changeTimes + "次</span></nobr>");
            ctx.push("</p>");
            ctx.push("<ul id=\"item_" + i + "\" class=\"item_list\"");
            ctx.push(i == 0 ? "style=\"display:block\">" : "style=\"display:none\">");
            ctx.push("<li class=\"whole_cour\">全程约" + data[i].distance + "公里，需要约" + data[i].time + "分钟</li>");
            ctx.push("<li class=\"start_point\"><img src=\"" + FCConfig.staticHostHeadSite + "/images/map_start_point.gif\" align=\"absmiddle\" />&nbsp;<strong>起点</strong>：<a href=\"javascript:PageMap.mapB.setMapCenter(" + data.startPoint.l + "," + data.startPoint.b + ",true)\">" + data.startName + "</a></li>");
            ctx.push("<li class=\"bus_con\">" + data[i].detail + "</li>");
            ctx.push("<li class=\"end_point\"><img src=\"" + FCConfig.staticHostHeadSite + "/images/map_end_point.gif\"  align=\"absmiddle\" />&nbsp;<strong>终点</strong>：<a href=\"javascript:PageMap.mapB.setMapCenter(" + data.endPoint.l + "," + data.endPoint.b + ",true)\">" + data.endName + "</a></li>");
            ctx.push("</ul>");
            ctx.push("</div>");
		    var tmpData = data[i];
		    tmpData.end=data.endPoint;
		    tmpData.start=data.startPoint;
            ftbusSearch.linePoints[ftbusSearch.linePoints.length]=tmpData;
        }
        $("#bus_list").html(ctx.join(''));
        if($P("list_0")) ftbusSearch.showPos(0);
    },
    
    searchBusStationClick: function(l,b){
        PageMap.mapB.setMapCenter(l,b);
    },
    
    showPos: function(id) {	//画公交线
        //转换ftsearch来的公交线路数据到 ftmap需要的格式
	    var lineDataStr = FtMapSearch.parseTrafficeLineData(PageMap.mapB,ftbusSearch.linePoints[id]);
        var linestyle = {
	        color:"#ff0000",
	        width:5,
	        transparence:0.8,
	        point:{
		        color:"#00cccc",
		        oncolor:"#ff0000",
		        roundcolor:"#ffffff",
		        width:5,
		        roundwidth:8
	        }
        };
	    PageMap.mapB.drawTrafficLine(lineDataStr,linestyle);
    },


    showTrafficLine: function(id){   //显示交通路线
	    var lineDataStr = FtMapSearch.parseTrafficeLineData(PageMap.mapB,ftbusSearch.linePoints[id]);
	    PageMap.mapB.drawTrafficLine(lineDataStr,linestyle);
    },
    
    setMapPos: function(e) {
        var pointPos = new Array();
        pointPos = e.options[e.selectedIndex].id.split(",");
        PageMap.mapB.setMapCenter(pointPos[0],pointPos[1],true);
    },
    
    showBusItem : function(id) {
        if(id != ftbusSearch.currBusItemId)
        {
            $P("list_" + id).className = "bus_list_pick";
            $P("list_" + id).onmouseout = null;
            $P("list_" + id).onmouseover = null;
            $P("item_" + id).style.display = "block";
            $P("list_" + ftbusSearch.currBusItemId).className = "bus_list";
            $P("list_" + ftbusSearch.currBusItemId).onmouseout = ftbusSearch.mouseOutItem;
            $P("list_" + ftbusSearch.currBusItemId).onmouseover = ftbusSearch.mouseOverItem;
            $P("item_" + ftbusSearch.currBusItemId).style.display = "none";
            ftbusSearch.showPos(id);
            ftbusSearch.currBusItemId = id;
        }
    },
    
    mouseOutItem: function(e) {
        e=e||event; 
        var tag=e.srcElement||e.target;
        var pa=tag.tagName.toLowerCase();
        while(pa!="div")
        {
            tag=tag.parentNode;
            pa=tag.tagName.toLowerCase();
            if(pa=="body")return;
        }
        tag.className='bus_list';
    },

    mouseOverItem: function(e) {
        e=e||event; 
        var tag=e.srcElement||e.target;
        var pa=tag.tagName.toLowerCase();
        while(pa!="div")
        {
            tag=tag.parentNode;
            pa=tag.tagName.toLowerCase();
            if(pa=="body")return;
        }
        tag.className='bus_list_over';
    }

}

/*
    housePricesMap:房价地图
*/
var housePricesMap = {
    _in: 0,
    init: function() {
        ftmapSearch.example = "小区名、地址或关键字";
        $("#mini_keywork").example(ftmapSearch.example, { class_name: 'fgrey' }).bind("mini_keywork", function(e) { if (e.keyCode == 13) housePricesMap.searchMapPositon(1); return; });
        $(".mini_soso_btn").bind("click", function() { housePricesMap.searchMapPositon(1) });
        if (ftmapSearch.key) { $("#mini_keywork").focus().val(ftmapSearch.key); }
        $("#mini_keywork").searchAuto(function() { housePricesMap.searchMapPositon(1) });
        housePricesMap.ftmapSearcher();
        if (ftmapSearch.key != "") housePricesMap.searchMapPositon(1);
    },

    ftmapSearcher: function() {   //初始化搜索器        
        this.mapSearcher = new FtMapSearch();
        this.mapSearcher.onMapSearchResponse = this.searchMapPositonResponse;
    },

    searchMapPositon: function(page) {    //关键字搜索入口
        if (($P("mini_keywork").value.trim() == "" || $P("mini_keywork").value == ftmapSearch.example) && $("#region").val() == "" && $("#avgprice").val() == "") {
            alert("请选择搜索条件！"); return;
        }
        $(".wxts,divBA1").hide("fast");
        $(".bus_list_con").html("<img src='http://www.fangtoo.com/about/ft/loading.gif' title='正在检索数据...'/>正在检索位置信息....");
        housePricesMap._in = page; housePricesMap.mapSearcher.searchMap(_cityObj.name, $P("mini_keywork").value, 10, page);
    },

    searchMapPositonResponse: function(data) {    //关键字搜索返回结果        
        var buildCon;
        if (data == null || data.pageNum == 0) {
            buildCon = housePricesMap.searchBuiding(1);
        } else {
            buildCon = housePricesMap.searchBuiding(housePricesMap._in);
        }
        eval(buildCon);
        var ctx = new Array();
        var build = BuildingList["List"];
        ctx[ctx.length] = "<div class=\"bus_list_title\">搜索结果:<span>" + parseInt(BuildingList.PageItem) + "</span>条,总页数:<span>" + parseInt(BuildingList.totalPage) + "</span>页,每页显示:<span>" + BuildingList.PageSize + "</span>条</div><ul class=\"bus_list_item\">";
        var go = false;
        var hangprice = "";
        var hangrate = "";
        var info = "<li onclick=\"housePricesMap.goToStation({0},{1},{2},'{3}')\" onmouseover=\"this.className='over'\" onmouseout=\"this.className=''\">" +
                   "<a href='javascript:void(0);' onclick=\"javascript:window.open('/building/{7}/','_blank');\">{3}</a>&nbsp;{5}{6}<br />" +
                   "<span class=\"fgrey\">{4}</span></li>";

        if (data.pageNum < BuildingList["totalPage"]) {   //房途网数据列表
            if (build != null) {
                for (j in build) {
                    if (build[j]["BuildingID"] != "" && build[j]["PosX"] != "" && build[j]["PosY"] != "") {   //解决有价格无坐标
                        var gP = PageMap.mapB.eMapToGis(build[j]["PosX"], build[j]["PosY"]);
                        if (!go) {
                            housePricesMap.goToStation(gP.l, gP.b, build[j]["bhId"], build[j]["BuildingName"]);
                            go = true;
                        }
                        if (build[j]["hangPrice"] != "" && build[j]["hangPrice"] != "0") {
                            _price = parseFloat(build[j]["hangPrice"]).toFixed(0);
                            if (_price == "0") _price = "--";
                            hangprice = housePricesMap.format("<span class=\"f1\">均价：{0}</span><span class=\"fgrey\">元/㎡</span>", _price);
                        } else { hangprice = ""; }
                        if (build[j]["hangRate"] != "" && build[j]["hangRate"] != "0") {
                            if (build[j]["hangRate"].substring(0, 1) == "-") {
                                hangrate = housePricesMap.format("&nbsp;<span class=\"f2\">{0}</span><br />", parseFloat(build[j]["hangRate"]).toFixed(1) + "% ↓");
                            } else {
                                hangrate = housePricesMap.format("&nbsp;<span class=\"f2\">{0}</span><br />", parseFloat(build[j]["hangRate"]).toFixed(1) + "% ↑");
                            }
                        } else { hangrate = ""; }
                        ctx[ctx.length] = housePricesMap.format(info, gP.l, gP.b, build[j]["bhId"], build[j]["BuildingName"], build[j]["Addr"], hangprice, hangrate, build[j]["BuildingID"]);
                    }
                }
            } else {
                //alert("null");
            }
        } else if (data.pageNum == BuildingList["totalPage"] && BuildingList["totalPage"]) {   //房途网数据列表+Mapbar数据列表
            var ii = parseInt(BuildingList["PageItem"]) - parseInt((BuildingList["totalPage"] - 1) * BuildingList["PageSize"]);
            var ic = 0;
            for (var b = 0; b < ii; b++) {
                if (build[b]["BuildingID"] != "" && build[b]["PosX"] != "" && build[b]["PosY"] != "") {   //解决有价格无坐标
                    var gP = PageMap.mapB.eMapToGis(build[b]["PosX"], build[b]["PosY"]);
                    if (!go) {
                        housePricesMap.goToStation(gP.l, gP.b, build[b]["bhId"], build[b]["BuildingName"]);
                        go = true;
                    }
                    if (build[b]["hangPrice"] != "" && build[b]["hangPrice"] != "0") {
                        _price = parseFloat(build[b]["hangPrice"]).toFixed(0);
                        if (_price == "0") _price = "--";
                        hangprice = housePricesMap.format("<span class=\"f1\">均价：{0}</span><span class=\"fgrey\">元/㎡</span>", _price);
                    } else { hangprice = ""; }
                    if (build[b]["hangRate"] != "" && build[b]["hangRate"] != "0") {
                        if (build[b]["hangRate"].substring(0, 1) == "-") {
                            hangrate = housePricesMap.format("&nbsp;<span class=\"f2\">{0}</span><br />", parseFloat(build[b]["hangRate"]).toFixed(1) + "% ↓");
                        } else {
                            hangrate = housePricesMap.format("&nbsp;<span class=\"f2\">{0}</span><br />", parseFloat(build[b]["hangRate"]).toFixed(1) + "% ↑");
                        }
                    } else { hangrate = ""; }
                    ctx[ctx.length] = housePricesMap.format(info, gP.l, gP.b, build[b]["bhId"], build[b]["BuildingName"], build[b]["Addr"], hangprice, hangrate, build[b]["BuildingID"]);
                } else { ic++; }
            }
            for (var c = 0; c < (data.peer - ii + ic); c++) {
                if (!go) {
                    housePricesMap.goToStation(data[c].point.l, data[c].point.b, 0, data[c].name);
                    go = true;
                }
                if (parseInt(data.totalCount) - 1 < c)
                    break;
                ctx[ctx.length] = "<li onclick=\"housePricesMap.goToStation(" + data[c].point.l + "," + data[c].point.b + ",0,'" + data[c].name + "')\" onmouseover=\"this.className='over'\" onmouseout=\"this.className=''\">";
                ctx[ctx.length] = "<a onclick=\"housePricesMap.goToStation(" + data[c].point.l + "," + data[c].point.b + ",0,'" + data[c].name + "')\">" + data[c].name + "</a> [模糊定位]<br />";
                ctx[ctx.length] = "<span class='fgrey'>" + data[c].addr + "; " + data[c].phone + "</span>";
                ctx[ctx.length] = "</li>";
            }
        } else if (data.pageNum > BuildingList["totalPage"]) { //Mapbar数据列表
            for (var i = 0; i < data.length; i++) {
                if (!go) {    //mapbar定位
                    housePricesMap.goToStation(data[i].point.l, data[i].point.b, 0, data[i].name);
                    go = true;
                }
                ctx[ctx.length] = "<li onclick=\"housePricesMap.goToStation(" + data[i].point.l + "," + data[i].point.b + ",0,'" + data[i].name + "')\" onmouseover=\"this.className='over'\" onmouseout=\"this.className=''\">";
                ctx[ctx.length] = "<a onclick=\"housePricesMap.goToStation(" + data[i].point.l + "," + data[i].point.b + ",0,'" + data[i].name + "')\">" + data[i].name + "</a> [模糊定位]<br />";
                ctx[ctx.length] = "<span class='fgrey'>" + data[i].addr + "; " + data[i].phone + "</span>";
                ctx[ctx.length] = "</li>";
            }
        }
        ctx[ctx.length] = "</ul>";
        $(".bus_list_con").html(ctx.join(''));
        var tnum;
        if (parseInt(data.totalCount) > 100) {
            tnum = 100;
        } else {
            tnum = parseInt(data.totalCount);
        }
        var pageObj = new PagerObj(parseInt(BuildingList.PageItem), parseInt(BuildingList.PageIndex), parseInt(BuildingList.PageSize));
        pageObj.baseScript = "housePricesMap.searchMapPositon(__0__)"; housePricesMap._in = 0;
        $("#page").html(pageObj.MapBuildPager());
    },

    format: function() {
        if (arguments.length == 0)
            return null;

        var str = arguments[0];
        for (var i = 1; i < arguments.length; i++) {
            var re = new RegExp('\\{' + (i - 1) + '\\}', 'gm');
            str = str.replace(re, arguments[i]);
        }
        return str;
    },

    goToStation: function(l, b, bhId, CName) {   //定位
        if (!PageMap.mapB) return;
        PageMap.mapB.showPane = true;
        PageMap.mapB.showFlagPane(l, b, bhId, CName);
    },

    goToUrl: function(id) { },

    searchBuiding: function(page) {    //关键字搜索
        var url = "/house/dataoffer.aspx?searchmap=2&type=jsonbuildinglist&page=" + page + "&regioncode=" + $("#region").val() + "&bp=" + $("#avgprice").val();
        if ($P("mini_keywork").value != ftmapSearch.example) { url += "&k=" + encodeURIComponent($P("mini_keywork").value); }
        var content = Methods.getAjaxStr(url);
        return content;
    }
}

/*
    页面初始化
*/
$(function(){ 
    ftmapSearch.init();
    followDivShow();
});

/*
    面页右下角提示
*/
var _tutu = "http://www.53kf.com/company.php?arg=fangtoo&style=1";
var _tutu_IsList = false;//是否房源列表
function followDivShow(){    
    if(oCookie.getCookie("follow") != "false"){     //显示]
        Methods.loadJS("/com/dataoff.aspx?way=tutu", "Kefu", function() {
            if (typeof (_qq) != "undefined") {
                _tutu = _qq;
            }
            var content = '<div id="followFangtoo" style="position:absolute; right:0; bottom:0; z-index:999;"><img src="' + FCConfig.staticHostHeadSite + '/images/float_tutu.gif" border="0" usemap="#Map100" /><map id="Map100" name="Map100"><area shape="rect" coords="160,5,176,20" href="javascript:followDivClose();" /><area shape="rect" coords="90,79,167,101" href="' + _tutu + '" target="_blank" /></map></div>';
            if (_tutu_IsList) {
                content = "<div id='followFangtoo' class='kf53' style='position:absolute; right:0; bottom:0; z-index:999;'><a class='clbtn' href='javascript:followDivClose();'></a><div class='kf53_con'><div class='f14 fbold lh'>您找到合适的房子了吗？如果没找到,就找房途小助手途途帮忙！</div><div style='padding: 5px 0pt;'><input type='button' class='kf53btn1' onclick='window.open(\"" + _tutu + "\")' >&nbsp;<input type='button' class='kf53btn2' onclick='followDivClose();'></div></div></div>";
            }
            $(content).appendTo("body");
            $('#followFangtoo').followDiv();
            oCookie.setCookie("follow", "true", "", "/", document.domain);
        });
    }
}


function followDivClose(){      //关闭      
    $("#followFangtoo").hide("fast");
    oCookie.setCookie("follow","false","","/",document.domain);
}

/*
    房源详细页面
*/
function followTip(){
    Methods.loadJS("/com/dataoff.aspx?way=tutu","Kefu",function(){
        if(typeof(_qq)!="undefined"){
            _tutu=_qq;
        }
        var html = '<div id="followTip" style="right:0px; top:200px; position:fixed; z-index:9999;" >'+
                    '<div id="tipTitle" style="cursor:pointer; float:left;" onclick="$(this).hide();$(\'#showTip\').show(\'slow\');"><img src="' + FCConfig.staticHostHeadSite + '/images/service_btn.gif" /></div>' +
                    '<div id="showTip" style="display:none; float:right;"><img src="'+FCConfig.staticHostHeadSite+'/images/service_show.gif" border="0" usemap="#Map111" />'+
                    '<map name="Map111" id="Map111">'+
                    '<area shape="rect" coords="206,62,280,93" target="_blank" href="'+_tutu+'" /><area shape="rect" coords="268,5,291,24" onclick="$(\'#showTip\').hide();$(\'#tipTitle\').show(\'slow\');" href="javascript:" />'+
                    '</map>'+
                    '</div>';
        $(html).appendTo("body");
        if(jQuery.browser.msie && window.navigator.userAgent.indexOf("MSIE 6.0") != -1){
            $("#followTip").css('position','absolute');
        }
        window.setTimeout("$(\'#tipTitle\').hide();$(\'#showTip\').show(\'slow\');",10000);
    });
}