﻿// JavaScript
// Jfp 08-12-09
// Init

var floatMenu, autoGis;
var pops = [];

var pageVars = {
	bodySize : null,
	topHeight : 103,
	HDPanesTemp : null,
	hDCtrl : null,
	mapTemp : null,
	autoGis : null,
	mapTempWidth : 0,
	mapTempHeight : 0,
	HDLine : null,
	HDLineWidth : 8,
	mainBody : null,
	ifmTemp : null,
	rightIfm : null,
	mainBodyWidth : 363,
	HDLineBut : null,
	searchKey : null,
	searchBut : null,
	cityListDlg : null,
	infoDlg: null
}

var LIB_LOADED;
function fnLoadInit() {
	if(!LIB_LOADED) {
    	setTimeout(fnLoadInit, 10);
    	return;
	}
	//pageVars.searchType = new NavButton($("searchType"), 1, ["skin def", "skin hov" , "skin cur"]);
	//pageVars.navBut = new NavButton($("rButTemp"), 0, ["skin def", "skin hov" , "skin cur"]);
	pageVars.headerMenu = new NavButton($("header_menu"), 0, ["header_menu1", "header_menu1_hov" , "header_menu1_cur"]);
	pageVars.HDPanesTemp = $("HDPanesTemp");
	pageVars.leftTemp = $("leftTemp");
	pageVars.mapTemp = $("mapTemp"); pageVars.HDLine = $("HDLine"); pageVars.mainBody = $("mainBody");
	pageVars.ifmTemp = $("rIfmBorderCenter"); pageVars.rightIfm = $("rightIfm");
	pageVars.HDLineBut = $("HDLineBut");
	pageVars.mainIfm = $("mainIfm");
	createHDCtrl();
	
	// 创建搜索控件
	//var searchCtrl = new SearchCtrl();
//	pageVars.searchType.buttons.forEach(function(a){
//	    a.chgGroup = searchCtrl.chgGroup.bind(searchCtrl);
//	});
//	$("trafficSType").chgGroup = searchCtrl.chgGroup.bind(searchCtrl);
//	$("trafficSType").onchange = function() {
//	    this.chgGroup("traffic" + this.value);
//	}
//	searchCtrl.onAdvSearchButClick = setRPage;
//	searchCtrl.onSearchButClick = function(searchType) {
//	    if(searchType == "traffic0") {
//	        if(searchCtrl.trafficSBegin.value == "" || searchCtrl.trafficSEnd.value == "") {
//	            alert("请输入起始地和目的地！");
//	            return false;
//	        }
//            if(searchCtrl.trafficSBegin.value == searchCtrl.trafficSEnd.value) {
//                alert("起始地和目的地不能相同！");
//                return false;
//	        }
//	    }
//	}
//	searchCtrl.chgGroup("house");
	
	// 创建页面Tab
	//pageVars.tabCtrl = new TabCtrl(pageVars.leftTemp, pageVars.mapTemp);

	// 创建右侧框架内部Tab控件
	pageVars.rIfmTab = new RIfmTab({rIfmBg : $("rIfmBorderBg"), tabTemp : $("rIfmTabTemp"), rIfm : pageVars.rightIfm});
	
	$attachEvent(window, $EventName.resize, resizePage);
	resizePage();
	[pageVars.leftTemp, pageVars.HDLine, pageVars.mainBody].forEach(function(a){a.style.display = "block"});
	
	loadMap();
	
	//$("site_city").innerText = GeneralConfig.city + "站";
	
	var hType = location.search.match(/(^|\?|&)hType[ ]*=[ ]*([^&=]*)/);
	if(hType && hType.length >= 3 && hType[2] != "") {
	    var index = ['newHouse','tenement','rTenement','sale','buy','community'].indexOf(hType[2]);
	    if(index > -1)
	        setRPage('', 'fangchan', index);
	}
}

//在左侧框架中显示指定页面，tabIndex取值0－2，默认为1，0为地图，2号位置专门用来显示详细信息页（details.aspx/show.aspx）
function showPage(url, tabIndex) {
    if(typeof tabIndex != "number") tabIndex = 1;
    pageVars.tabCtrl.showTab(tabIndex, url);
    
    hidePopDlg();
}

//指定右框页面
//function setRPage(url, tabType, tabIndex) {
//    pageVars.autoGis.vG.sign.removeType();
//    if(!tabType) {
//        if(url == "") return;
//        pageVars.rIfmTab.hideTab();
//        if(url.match(/\?/))
//            url += "&t=" + new Date().valueOf();
//        else
//            url += "?t=" + new Date().valueOf();
//        pageVars.rightIfm.src = url;
//    }else {
//        if(!pageVars.autoGis) return;
//        if(tabType == "fangchan")
//            pageVars.rIfmTab.showTab([
//	                              {id: "rTab_newHouse", label : "新房", title: "新房", icon : "/images/rTab_newHouse.png", url : "../rightPage/house/newHouse/more.aspx?searchTypes=newhosue&areaId=&typeid=&price=&fitmentid=0&keywords=&t=", action : chgPopType}, 
//	                              {id: "rTab_sale", label : "二手房", title: "二手房销售", icon : "/images/rTab_sale.png", url : "../rightPage/house/sale/more.aspx?searchTypes=chushou&areaId=&typeid=&price=&fitmentid=0&keywords=&t=", action : chgPopType},
//	                              {id: "rTab_community", label : "小区", title: "小区",icon : "/images/rTab_community.png", url : "../rightPage/house/community/more.aspx?searchTypes=community&areaId=&typeid=&price=&fitmentid=0&keywords=", action : chgPopType},
//	                              {id: "rTab_tenement", label : "出租", title: "出租房", icon : "/images/rTab_tenement.png", url : "../rightPage/house/tenement/more.aspx?searchTypes=chuzu&areaId=&typeid=&price=&fitmentid=0&keywords=&t=", action : chgPopType},
//	                              {id: "rTab_rTenement", label : "求租", title: "求租", icon : "/images/rTab_rTenement.png", url : "../rightPage/house/rTenement/more.aspx?searchTypes=newhosue&areaId=&typeid=&price=&fitmentid=0&keywords=&t=", action : chgPopType},
//	                              {id: "rTab_buy", label : "求购", title: "二手房求购",icon : "/images/rTab_buy.png", url : "../rightPage/house/buy/more.aspx?searchTypes=newhosue&areaId=&typeid=&price=&fitmentid=0&keywords=&t=", action : chgPopType}
//	                             ], tabType, tabIndex, url);
////	    else if(url == "jiaju")
////            pageVars.rIfmTab.showTab([
////	                              {label : "工作", icon : "/images/biao3.png", url : "http://www.google.com"},
////	                              {label : "生活", icon : "url(/skins/images/icon.gif) 0 -24px", url : "http://www.baidu.com"}
////	                             ], url, 0);
//    }
//    
//    hidePopDlg();
//    
//    if(!pageVars.hDCtrl.HDCtrlPro.expand)
//        pageVars.hDCtrl.chgExpand();
//}

function setRPage(url, type) {
    if(url == "") return;
    pageVars.autoGis.vG.sign.removeType();
    if(url.match(/\?/))
        url += "&t=" + new Date().valueOf();
    else
        url += "?t=" + new Date().valueOf();
    pageVars.rightIfm.src = url;
    //this.buttons[this.curIndex].className = this.butCss[0];
    //pageVars.cityListDlg.body.className = "skin cur";
    if(type)
        chgPopType(type);
    
    if(pageVars._curTab) {
        pageVars._curTab.className = "skin def";
    }
    this.className = "skin cur";
    pageVars._curTab = this;
}

function chgPopType(type) {
    hidePopDlg();
    //var type = id.replace(/rTab_/, "");
    //pageVars.autoGis.vG.hotSpot.chgPopType(type);
    pageVars.autoGis.vG.sign.setType("houseInfo", {sType: type, onClick: showInfo});
    pageVars.listDlg_showed = null;
}

function hidePopDlg() {
    if(pageVars.infoDlg && pageVars.infoDlg.showed)
        pageVars.infoDlg.hide();
        
    if(pageVars.listDlg && pageVars.listDlg.showed)
        pageVars.listDlg.hide();
}

function loadMap() {
	if(!AutoGis) {
    	setTimeout(loadMap, 10);
    	return;
	}
	pageVars.autoGis = new AutoGis("mapTemp", {mapType :"NORMAL",useMapType : true,useEye : true, useHotSpot : true, usePop: true, useNav : false, showNav: false, showHotspotInfo: true, showAD: true});
	autoGis = pageVars.autoGis;
//	pageVars.tabCtrl.onTabClick = function(index) {
//	    if(index == 0) {
//	        autoGis.checkResize();
//	    }
//	}
//	pageVars.tabCtrl.onBeforeMapHidden = function() {
//	    if(autoGis.vG.anchorStarting)
//	        autoGis.vG.stopAnchor();
//	    
//	    pageVars.listDlg_showed = (pageVars.listDlg && pageVars.listDlg.showed);
//        hidePopDlg();
//	}
//	pageVars.tabCtrl.onBeforeMapShow = function() {
//	    if(pageVars.listDlg_showed) {
//	        pageVars.listDlg.show();
//	        pageVars.listDlg_showed = null;
//	    }
//	}
	
	if(autoGis.vG.hotSpot)
	    autoGis.vG.hotSpot.onPopClick = showInfo;
	    
	var _id = findValue(location.href, "id");
    if(_id != "") {
        AjaxSend({id: _id}, "_page.getNewHouseInfo", function(value, context) {
            if(value != "") {
                autoGis.vG.hotSpot.curObjId = getValue(value, "id");
                var t = getValue(value, "latlng").split(",");
                var w = getValue(value, "latlngWX").split(",");
                autoGis.vG.setCenter(new GLatLng(parseFloat(t[0]), parseFloat(t[1])));
                showInfo(getValue(value, "class"),getValue(value, "id"),getValue(value, "name"),getValue(value, "latlng"),getValue(value, "latlngWX"),"");
            }
        });
	}
	
	autoGis.onMoveEnd = function(centerLatLng) {
        var ifm = $("rightIfm");
        if(!ifm) return;
        //pageVars.navBut.curIndex == 2
	    if(ifm.src.match(/about_other/)) {
	        var doc = ifm.contentWindow.document;
	        var refreshBut;
	        if((refreshBut = doc.getElementById("refreshBut")) && refreshBut.onclick)
	            refreshBut.onclick();
	    }
	}
	   
    autoGis.vG.sign.setType("houseInfo", {sType: "newHouse", onClick: showInfo});
	
	//chgPopType("newHouse");
	//2010-05-01
	//setTimeout(createPopDia,500);
}


function getAutogisInstance() {
    return pageVars.autoGis.vG;
}

function createHDCtrl() { //创建分隔面板控制实例
	var hDCtrlPro = new HDCtrlProperty();
	with(hDCtrlPro) {
		HDLine = pageVars.HDLine;
		HDLineBut = pageVars.HDLineBut;
		panes = [pageVars.leftTemp, pageVars.mainBody];
		exPaneWidth = pageVars.mainBodyWidth;
		indexCanEx = 1;
		leftCss = ["skin lDef", "skin lHov"];
		rightCss = ["skin rDef", "skin rHov"];
		expand = true;
	}
	pageVars.hDCtrl = new HDCtrl(hDCtrlPro);
	pageVars.hDCtrl.onResized = function(mapTempWidth) {
		pageVars.mapTempWidth = mapTempWidth;
		// 此处重设地图尺寸
		pageVars.autoGis.checkResize();
	}
	pageVars.hDCtrl.onPositionChanged = function() {
	    pageVars.rightIfm.src = pageVars.rightIfm.src;
	}
}

function resizePage() {
	pageVars.bodySize = fnGetWindowSize();
	pageVars.HDPanesTemp.style.width = pageVars.bodySize.width + 10 + "px";
	pageVars.HDPanesTemp.style.height = pageVars.bodySize.height + 10 + "px";
	pageVars.mapTempWidth = pageVars.bodySize.width - pageVars.HDLineWidth - ((pageVars.mainBody.style.display == "none") ? 0 : pageVars.mainBodyWidth);
	pageVars.mapTempHeight = pageVars.bodySize.height - pageVars.topHeight;
	if(pageVars.mapTempWidth < 100) pageVars.mapTempWidth = 100;
	if(pageVars.mapTempHeight < 100) pageVars.mapTempHeight = 100;
	pageVars.leftTemp.style.width = pageVars.mapTempWidth + "px";
	pageVars.mainBody.style.height = pageVars.HDLine.style.height = pageVars.leftTemp.style.height = pageVars.mapTempHeight + "px";
	pageVars.ifmTemp.style.width = pageVars.mainBodyWidth + "px";
	pageVars.ifmTemp.style.height = pageVars.mapTempHeight - 16 + "px";
	pageVars.HDLineBut.style.marginTop = (pageVars.mapTempHeight - 34) / 2 + "px";
	
	setMenuWidth();
	
	if(pageVars.autoGis)
	    pageVars.autoGis.checkResize();
}

function setMenuWidth() {
    var menuTemp = $("menuTemp");
    var children = $("header_menu").children;
    var i, w = 320, width = pageVars.bodySize.width;
    var flag = false;
    for(i=0; i<children.length; i++) {
        if(w + 84 > width) {
            children[i].style.display = "none";
            flag = true;
        }else
            children[i].style.display = "inline";
        w += 84;
    }
    
    $("menuOut_l").className = "menuOut_l_dis";
    $("menuOut_r").className = flag ? "menuOut_r" : "menuOut_r_dis";
}

function menuOutLClick() {
    if(this.className == "menuOut_l_dis") return;
    var children = $("header_menu").children;
    var i, before;
    for(i=0; i<children.length; i++) {
        if(children[i].style.display == "none")
            before = children[i];
        else
            break;
    }
    before.style.display = "inline";
    if(i <= 1) $("menuOut_l").className = "menuOut_l_dis";
    
    for(i=children.length - 1; i>=0; i--) {
        if(children[i].style.display != "none") {
            before = children[i];
            break;
        }
    }
    before.style.display = "none";
    $("menuOut_r").className = "menuOut_r";
}

function menuOutRClick() {
    if(this.className == "menuOut_r_dis") return;
    var children = $("header_menu").children;
    var i, before;
    
    for(i=children.length - 1; i>0; i--) {
        if(children[i].style.display == "none")
            before = children[i];
        else
            break;
    }
    before.style.display = "inline";
    if(i >= children.length - 2) $("menuOut_r").className = "menuOut_r_dis";
    
    for(i=0; i<children.length; i++) {
        if(children[i].style.display != "none") {
            before = children[i];
            break;
        }
    }
    before.style.display = "none";
    $("menuOut_l").className = "menuOut_l";
}

function chgSearchTip(index) {
    $("searchKeyG1").style.display = "none";
    $("searchKeyG0").style.display = "";
    pageVars.searchKey.value = pageVars.searchTip[index];
}

function chgToTraffic() {
    $("searchKeyG0").style.display = "none";
    $("searchKeyG1").style.display = "";
}

function showNav() {
    pageVars.autoGis.vG.navMap.show(0, null, true);
}

function showCityList() {
    if(!pageVars.cityListDlg) {
        pageVars.cityListDlg = new Dialog("全国城市列表", 320, 380);
        with(pageVars.cityListDlg) {
            setCanMove(false);
            setCanMini(false);
            
            setBody("正在加载数据，请稍等...");
            AjaxSend("", "Data.DataLoader.loadCityList", function(value, context) {
                pageVars.cityListDlg.setBody(value);
                pageVars.cityListDlg.body.className = "dialogBody1";
            });
        }
        pageVars.cityListDlg.onBeforeClose = function() {
            this.hidden();
            return false;
        }.bind(pageVars.cityListDlg);
    }

    pageVars.cityListDlg.show(210, 103);
}

//function showInfo(type, id, name, latlng, latlngWX, mapClick) {
//    position(latlng, latlngWX, mapClick);
//    
//    if(type == "newHouse" || type == "community") {
//        if(!pageVars.infoDlg)
//            pageVars.infoDlg = new InfoDialog(type, id);
//        pageVars.infoDlg.show(type, id, name);
//    }else {
//        if(!pageVars.listDlg)
//            pageVars.listDlg = new ListDialog(type);
//        pageVars.listDlg.show(type, id, name);
//    }
//}

function showInfo(type, id, name, latlng, latlngWX, mapClick) {
    position(latlng, latlngWX, mapClick);
    //alert(type);
    if(type == "newHouse" || type == "community") {
        if(!pageVars.infoDlg)
            pageVars.infoDlg = new InfoDialog(type, id);
        pageVars.infoDlg.show(type, id, name);
        pageVars.infoDlg.latlng = (latlng == "" || latlng == null) ? latlngWX:latlng;
    }else {
        if(!pageVars.listDlg)
            pageVars.listDlg = new ListDialog(type);
        pageVars.listDlg.show(type, id, name);
    }
    
//    var sign = pageVars.autoGis.vG.sign;
//    if(!sign) return;
//    var ele = $(type + "_" + id);alert(ele);
//    if(!ele) return;
//    ele._this.select(ele);
}

function showInfo_new(type, id, name, latlng, latlngWX, mapClick) {
    position(latlng, latlngWX, mapClick);
    
    if(type == "newHouse") {
        if(!pageVars.infoDlg)
            pageVars.infoDlg = new InfoDialog(type, id);
        pageVars.infoDlg.show(type, id, name);
    }
    else if(type == "community")
    {
        if(!pageVars.communityDlg)
        {
            pageVars.communityDlg = createCommunityDialog(id,name,latlng,latlngWX,mapClick);
        }
        else
        {
            pageVars.communityDlg.style.display = "inline";
        }
        AjaxSend({id: id, latlng:latlng, latlngWX:latlngWX}, "Data.DataLoader.loadCommunityInfo", showCommunityInfo);
    }
    else {
        if(!pageVars.listDlg)
            pageVars.listDlg = new ListDialog(type);
        pageVars.listDlg.show(type, id, name);
    }
}

function position(latlng, latlngWX, mapClick) {
    var a, mapType, vG = pageVars.autoGis.vG;
    if(typeof(latlng) == "string" && latlng.match(/^-?\d+\.\d+,-?\d+\.\d+$/)) {
        a = latlng.split(",");
        mapType = "MODEL";
    }else if(typeof(latlngWX) == "string" && latlngWX.match(/^-?\d+\.\d+,-?\d+\.\d+$/)){
        a = latlngWX.split(",");
        mapType = "NORMAL";
    }
    
//    if(pageVars.tabCtrl.curIndex != 0)
//        pageVars.tabCtrl.showTab(0, null);
//    else
//        hidePopDlg();
    
    if(!mapClick && mapType && mapType != vG.mapType)
        pageVars.autoGis.chgMapType(mapType);
    if(a)
        vG.setCenter(new GLatLng(parseFloat(a[0]), parseFloat(a[1])));
}

//手工登录处理
function login(userName, requestUrl) {
    $("divNoLogin").style.display = "none";
    $("divLogin").style.display = "inline";
    $("divLogin").innerHTML = "你好，" +　userName + "<a href='#' onclick='logout();'>[退出]</a>";
    
    if(requestUrl) {
        location.href = requestUrl;
    }
}

//手工退出处理
function logout() {
    $("divNoLogin").style.display = "inline";
    $("divLogin").style.display = "none";
    showPage("/uCenter/logout.aspx");
    setRPage("/rightPage/index/index.htm");
}

//自动检测是否在登录状态
function autoLogout() {
    $("divNoLogin").style.display = "inline";
    $("divLogin").style.display = "none";
}

//注册成功
function regSuccess(userName) {
    login(userName);
    $('rightIfm').src = '/rightPage/PersonOperateMenu.aspx?'.concat(Math.random());
    showPage('/uCenter/reg/PersonCenter.aspx');
    alert('注册成功!');
}

//我的房图
function showPersonCenter(){
    showPage('/uCenter/reg/PersonCenter.aspx');
}

function searchHouse() {
    var typeid = "0";
    var price = "0";
    var fitmentid = "0";
    var areaid = "0";
    var keyWords = "";
    var subValue = "";
    var searchTypes = ($("searchType_newHouse").checked ? "newHouse" : ($("searchType_chuzu").checked ? "chuzu" : "2sf"));
       
    if(searchTypes == "newHouse")
    {
        typeid = $("typeId").value;
        price = $("price_newHouse").value;
        areaid = $("areaId").value;
        keyWords = $("keywordss").value;
        subValue = "searchTypes=newhosue&areaId=" + areaid + "&wuye=" + typeid + "&price=" + price + "&fitmentid=" + fitmentid + "&keyword1=" + keyWords;
        setRPage("/rightPage/house/newHouse/more.aspx?"+subValue);
    }
    else if(searchTypes == "chuzu")
    {
        typeid = $("typeId").value;
        price = $("price_chuzu").value;
        areaid = $("areaId").value;
        keyWords = $("keywordss").value;
        subValue = "searchTypes=chuzu&areaId=" + areaid + "&wuye=" + typeid + "&price=" + price + "&fitmentid=" + fitmentid + "&keyword1=" + keyWords;
        setRPage("/rightPage/house/tenement/more.aspx?"+subValue);
    }
    else if(searchTypes == "2sf")
    {
        typeid = $("typeId").value;
        price = $("price_chuchou").value;
        areaid = $("areaId").value;
        keyWords = $("keywordss").value;
        subValue = "searchTypes=chushou&areaId=" + areaid + "&wuye=" + typeid + "&price=" + price + "&fitmentid=" + fitmentid + "&keyword1=" + keyWords;
        setRPage("/rightPage/house/sale/more.aspx?"+subValue);
    }
      else if(searchTypes == "dt")
    {
         typeid = $("typeId").value;
        price = $("price_newHouse").value;
        areaid = $("areaId").value;
        keyWords = $("keywordss").value;
        subValue = "searchTypes=newhosue&areaId=" + areaid + "&wuye=" + typeid + "&price=" + price + "&fitmentid=" + fitmentid + "&keyword1=" + keyWords;
        setRPage("/rightPage/house/newHouse/more_dt.aspx?"+subValue);
    }
    
}

function createCommunityDialog()
{
    var CommunityDlgTemp = $C("div",{id:"aaaaaaaa"});
    with(CommunityDlgTemp) {
        style.position = "absolute";
        //style.display = "none";
        style.zIndex = 1000;
        innerHTML = "<div style=\"position:absolute;z-index:101;margin:120px 0 0 1px;width:43px;height:35px;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + apiPath + "images/left.png',sizingMethod='image');\"><!--[if !IE]><!--><img src='" + apiPath + "images/left.png' /><!--<![endif]--></div>";
    }
    CommunityDlgTemp.onmousedown = CommunityDlgTemp.onmouseup = CommunityDlgTemp.onclick = CommunityDlgTemp.onmousewheel = function(event) {
        event = event || window.event;
        cancelBubble(event);
    };
    $To(CommunityDlgTemp, $("layer103"));
    
    var CommunityDialog = new Dialog("title", 300, 260, CommunityDlgTemp);
    CommunityDialog.setCanMini(false);
    CommunityDialog.onBeforeClose = hideInfo;
    var div = $C("div", {className: "hotSpot_img"});
    CommunityDialog.infoImg = $To($C("img", {src: "/images/001.gif"}), div);
    CommunityDialog.setMainBody(div);
    CommunityDialog.infoDiv = $C("div", {className: "hotSpot_info"});
    CommunityDialog.appendMainBody(CommunityDialog.infoDiv);
    CommunityDialog.appendTab("周边配套", "", false).body.style.height = "196px";
    
    var temp = $C("div");
    temp.style.lineHeight = "30px";
    CommunityDialog.appendTab("出租房源", temp, false);
    var div = $To($C("div"), temp);
    div.innerHTML = "查找范围：";
    
    var temp1 = $C("div");
    temp1.style.lineHeight = "30px";
    CommunityDialog.appendTab("出售房源", temp1, false);
    var div1 = $To($C("div"), temp1);
    div1.innerHTML = "查找范围：";
    
    CommunityDialog.appendTab("公交换乘", "", false).body.style.height = "196px";
    CommunityDialog.busForm = $C("div", {className: "hotSpotInfo_busForm"});
    CommunityDialog.setTabBody(3, CommunityDialog.busForm, true, true)
    
    CommunityDialog.show(43, 0);
    createCommunityBusForm(CommunityDialog.busForm);
    pageVars.communityDialog = CommunityDialog;
    
    return CommunityDlgTemp;
}

function hideInfo()
{
    if(pageVars.communityDlg)
    {
        pageVars.communityDlg.style.display = "none";
    }
    return false;
}

function showCommunityInfo(value, context) {
    if(value == "") return;
    if(pageVars.communityDlg)
    {
        pageVars.communityDialog.setTitle(getValue(value,"name"));
        var latlng = getValue(value,"latlng")=="" ? getValue(value,"latlngWX"):getValue(value,"latlng");
        latlngs = latlng.split(",");
        var curPoint = gisToMap(new GLatLng(parseFloat(latlngs[0]),parseFloat(latlngs[1])));
        var x = curPoint.x/(autoGis.zoom + 1);
        var y = curPoint.y/(autoGis.zoom + 1);
        pageVars.communityDlg.style.left = parseInt(x) + "px";
        pageVars.communityDlg.style.top = parseInt(y) - 155 + "px";
        var str = "<strong>小区:</strong>" + getValue(value,"name");
        str += "<br><strong>地址:</strong>" + getValue(value,"address");
        pageVars.communityDialog.infoDiv.innerHTML = str;
        var zbpt = getValue(value,"layout");
        var cz = getValue(value,"cz");
        var cs = getValue(value,"cs");
        pageVars.communityDialog.setTabBody(0, zbpt);
        pageVars.communityDialog.setTabBody(1, cz);
        pageVars.communityDialog.setTabBody(2, cs);
        pageVars.communityDlg.style.display = "block";
        pageVars.communityDialog.setTabWidth();
        
        autoGis.vG.panTo(new GLatLng(parseFloat(latlngs[0]),parseFloat(latlngs[1])));
    }
}

function createCommunityBusForm(form)
{
    form.curType = "deuce";

    form.group1 = $To($C("div", {className: "group"}), form);
    $To($C("span", {innerText: "从"}), form.group1);
    form.from = $To($C("input", {type: "text", className: "short", value: "起点站", def: "起点站", onfocus: focus, onblur: blur}), form.group1);
    $To($C("span", {innerText: "到"}), form.group1);
    form.to = $To($C("input", {type: "text", className: "short",value: "目的站", def: "目的站", onfocus: focus, onblur: blur}), form.group1);

    div = $To($C("div", {className: "group"}), form);
    div.style.textAlign = "right";
    form.searchBut = $To($C("div", {className: "defBut", innerText: "搜索"}), div);
    form.searchBut.onclick = this.busSearch.bind(this);
    
    form.result = $To($C("div", {className: "result"}), form);
}

function focus() {
    if(this.value == this.def)
        this.value = "";
}
function blur() {
    if(this.value == "")
        this.value = this.def;
}

function busSearch() {
    if(!pageVars.communityDialog)
    {
        return;
    }
    var form = pageVars.communityDialog.busForm;
    if(form.curType == "deuce" && (form.from.value == "" || form.from.value  == form.from.def || form.to.value == "" || form.to.value == form.to.def)) {
        alert("请输入起始站和目的站！");
        return;
    }
    
    if(form.curType == "deuce") {
        $("busBtn").select(event);
        setRPage('/rightPage/bus/bus_result.aspx?from=' + form.from.value + '&to=' + form.to.value);
    }
}
function getLatLng()
{
    var latlng = autoGis.vG.getCenter();
    return latlng.lat() + "," + latlng.lng();
}

function createSignDlg() {
    var div = $C("div");
    with(div) {
                style.position = "absolute";
                style.display = "none";
                style.zIndex = 1001;
                innerHTML = "<div style=\"position:absolute;z-index:101;margin:50px 0 0 1px;width:43px;height:35px;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + apiPath + "images/left.png',sizingMethod='image');\"><!--[if !IE]><!--><img src='" + apiPath + "images/left.png' /><!--<![endif]--></div>";
    }
    div.onmousedown = div.onmouseup = div.onclick = div.onmousewheel = function(event) {
        event = event || window.event;
        cancelBubble(event);
    };
    
    var dlg = new Dialog("pop", 260, 164, div);
    dlg.setCanMini(false);
    dlg.onBeforeClose = function() {
        this.parent.style.display = "none";
        return false;
    }
    dlg.show(43, 0);
    div.dialog = dlg;
    
    var vG = pageVars.autoGis.vG;
    var entity = new Entity(new GLatLng(0, 0), div, 0, 98, 100001);
    vG.addOverlay(entity);
    div.entity = entity;
    
    vG.sign.onBeforeRemove = function() {
        pageVars.signDlg.style.display = "none";
    }
    
    return div;
}

function showSignInfo(id, name, latlng, address, phone, mapClick) {
    var signDlg = pageVars.signDlg;
    if(!signDlg) signDlg = pageVars.signDlg = createSignDlg();
    
    signDlg.dialog.setTitle(name);
    var ADStr = "<iframe src='/ad1.htm' frameborder='0' width='234' height='60' scrolling='no' style='position:absolute;left:12px;bottom:9px'></iframe>";
    signDlg.dialog.setBody("<div style='padding:5px;line-height:22px;'>地址：" + address + "<br>电话：" + (phone || "未知") + "</div><div style='position:absolute;right:12px;bottom:68px;cursor:pointer' onclick=\"findHere('" + latlng + "')\">周边查找</div>" + ADStr);
    
    if(!mapClick) position(latlng, null, true);
    var a = latlng.split(",");
    signDlg.entity.moveTo(new GLatLng(parseFloat(a[0]), parseFloat(a[1])));
    
    signDlg.style.display = "";
}

function hidSignDlg() {
    pageVars.signDlg.style.display = "none";
}

function findHere(latlng) {
    hidSignDlg();
    
    var ifm = $("rightIfm");
    if(!ifm) return;
    var doc = ifm.contentWindow.document;
    var refreshBut;
    if(refreshBut = doc.getElementById("refreshBut"))
        refreshBut.onclick = null;
    ifm.src = "/mapPage/newhouse/about_other.aspx"
//    var doc = ifm.contentWindow.document;
//    var refreshBut;
//    if(findOther = doc.getElementById("findOther"))
//        findOther.onclick();
        
    var a = latlng.split(",");
    pageVars.autoGis.vG.setCenter(new GLatLng(parseFloat(a[0]), parseFloat(a[1])));
}
