﻿//全局便量
var gApp = null;
var gMap = null;
var ajaxObj = null;
//var _START = '';
var _winsize = {x: 0, y: 0};
var fWindow = null;

if(!SKINPATH) alert('Skin Path Not Found!');

// 搜索模块
var ModSearchBox = new Class({
    initialize: function() {
        var tabs = [
            {'tab': $('tabSearchMap'), 'pnl': $('pnlSearchMap')}, 
            {'tab': $('tabSearchBus'), 'pnl': $('pnlSearchBus')}, 
            {'tab': $('tabSearchTag'), 'pnl': $('pnlSearchTag')}
        ];
        
        this.tabs = new TabBox(tabs, 0, this.ontabchange.bind(this), {'normal': 'tab', 'active': 'tabactive'});
        
        this.pshMap = new PnlOfMapSearch();
        this.pshBus = new PnlOfBusSearch(); 
        this.pshTag = new PnlOfTagSearch();
        
        $('sysSearchTab').addEvent('click', function(evt){evt.stop()}.bindWithEvent(this));
        $('sysSearchTab').addEvent('dblclick', function(evt){evt.stop()}.bindWithEvent(this));
    },
    ontabchange: function(tab) {
        if (tab.tab.id == this.pshMap.id) this.pshMap.onshow();
        if (tab.tab.id == this.pshBus.id) this.pshBus.onshow();
        if (tab.tab.id == this.pshTag.id) this.pshTag.onshow();
    }
});

// 页签管理类
var TabBox = new Class({
    initialize: function(tabList, activeIndex, onchange, cssTabClass) {
        if (!activeIndex) activeIndex = 0;
        this.activeIndex = activeIndex;
        this.tabList = [];
        this.cssTabClass = (cssTabClass) ? (cssTabClass) : ({'normal': 'tab', 'active': 'tabactive'});
        this.onchange = onchange;
        this.lt = window.ie6 ? 0 : 500;
        for (var i = 0; i < tabList.length; i++) {
            var item = {
                'index': i,
                'tab': $(tabList[i].tab),
                'pnl': $(tabList[i].pnl),
                'fx': $(tabList[i].pnl).effects({duration: this.lt, transition: Fx.Transitions.Sine.easeOut}),
                'active': false
            };
            item.active = (i == activeIndex);
            item.tab.className = (item.active) ? (this.cssTabClass.active) : (this.cssTabClass.normal);
            this.tabList.push(item);
            item.fx.addEvent('onComplete', this.onfxcomplete.bind(item));
            $(tabList[i].pnl).setStyle('display', ((activeIndex == i) ? ('') : ('none')));
            $(tabList[i].tab).addEvent('click', this.ontabclick.bindWithEvent(this, [i]));
        }
    },
    ontabclick: function(evt, index) {
        this.select(index);
    },
    onfxcomplete: function(evt) {
        if (this.active) this.pnl.style.display = ''; else this.pnl.style.display = 'none';
    },
    getActiveTab: function() {
        return this.tabList[this.activeIndex]; 
    },
    select: function(index) {
        if (this.activeIndex == index) return ;
        
        for (var i = 0; i < this.tabList.length; i++) {
            if (i != index && this.tabList[i].active) {
                this.tabList[i].active = false;
                this.tabList[i].pnl.style.display = 'none';
                this.tabList[i].tab.className = this.cssTabClass.normal;
            }
        }
        
        this.activeIndex = index;
        this.tabList[this.activeIndex].tab.className = this.cssTabClass.active;
        this.tabList[this.activeIndex].pnl.setOpacity(0);
        this.tabList[this.activeIndex].pnl.style.display = '';
        this.tabList[this.activeIndex].active = true;
        this.tabList[this.activeIndex].fx.stop();
        this.tabList[this.activeIndex].fx.start({'opacity': [0, 1]});
        
        if (this.onchange) this.onchange(this.tabList[this.activeIndex]);
    }
});
TabBox.implement(new Events);

// 地图搜索面板
var PnlOfMapSearch = function(){
    var searchButton = $('btnSearchMap');

    searchButton.addEvent('mouseenter', function() {
        this.className = 'searchbtnoff';
    });
    searchButton.addEvent('mouseleave', function() {
        this.className = 'searchbtnon';
    });
    searchButton.addEvent('click', function() {
        doMapSearch(1);
       
        
    });
};
PnlOfMapSearch.onshow = function(){};

// 地图搜索建议
var SearchSuggest = function() {
    var searchInput = $('txtSearchValue');
    searchInput.value = DefaultSearchText;
    searchInput.addEvent('focus', function() {
        if (this.value.trim() == DefaultSearchText) this.value = '';
        this.className= 'inputboxactive';
    });
    searchInput.addEvent('blur', function() {
        if (this.value.trim() == '') this.value = DefaultSearchText;
        this.className = 'inputbox';
    });
    
    var completer = new Autocompleter.Citylr(searchInput, 'sg2.ashx', {
        'useSelection': false,
        'maxChoices': 10,
		'onRequest': function(el) {
		    searchInput.className = 'inputboxonrequest';
		},
		'onComplete': function(el) {
			searchInput.className = 'inputboxactive';
			searchInput.focus();
		},
		'onFailure': function(){
		    searchInput.className = 'inputboxactive';
		},
		'onGetQueryString': function(value) {
		    return {'s':value};
		},
		'onSelect': function(ele) {
		    completer.ajax.cancel();
		    completer.hideChoices();
		    searchInput.className = 'inputboxactive';
		    
		    doMapSearch(1);
		}
	});
	completer.ajax.setHeader('svcop', 'search');
	completer.ajax.setHeader('Query-Type', '3');
};
var _SRLISTTIP = null;
function addNoResultTip() {
    var slistdivs = gMap.resultList.handle.getElementsByTagName("DIV");
    for (var i = 0; i < slistdivs.length; i++) {
        if (slistdivs[i].className == 'srList') {
            _SRLISTTIP = slistdivs[i].appendChild($("searchTipHTML"));
        }
    }
}
//进行地图搜索
function doMapSearch(page) {
    var kw = $('txtSearchValue').value.trim();
    if (kw == DefaultSearchText || kw == "") return;
    var filterWords = filterSearchKeyWord.split(',');
    var tempkw = kw;
    for (var i = 0; i < filterWords.length; i++) {
        kw = kw.replace(filterWords[i], "");
    }
    if (kw == "") kw = tempkw;
    
    var areaSch = 'city';
    
    if ($("sp_AreaSch").checked) {
        var areaObj = gMap.getcurrarea();
        areaSch = areaObj.l + "," + areaObj.t + "," + areaObj.r + "," + areaObj.b;
    }
    
    ajaxObj.getMapSearch(kw, 0, areaSch, page, cb);
    function cb(res) {
        eval('var srdata = ' + res.value);
        
        _SRLISTTIP.style.display = srdata.c == 0 ? "" : "none";
        
        gMap.resultList.loadList(srdata);
        gMap.resultList.setOptions({
            onItemClick: function(item) {
                BaseInfoWin.Show(parseInt(item.pos.x), parseInt(item.pos.y), item.id, item.nameA);
                return;
            },
            onPageClick: function(pg) {
                doMapSearch(pg);
            },
            onHide: function(){
                gMap.layerData.clearMarks();
            }
        });
        
        gMap.layerData.addMarks(srdata.list, false);
        gMap.layerData.setOnMarkClick(showinfo);
         $('ifr_google').src='googleSearch.htm?' + escape($('txtSearchValue').value);
        //gMap.resultList.setExtraInfo(true, $('d_googlead').innerHTML);
        
        gMap.resultList.show();
    }
    
    function showinfo(pop) {
        BaseInfoWin.Show(parseInt(pop.pos.x), parseInt(pop.pos.y), pop.id, pop.n);
    }
};

//区域搜索选择
var AreaChk = {
    init: function() {
        this.chkdiv = $("sp_AreaSch");
        this.chkdiv.checked = false;
        this.chkdiv.onclick = function() {AreaChk.clk();};
        $('lab_AreaSch').onclick = function() {AreaChk.clk();};
    },
    clk: function() {
        this.chkdiv.checked = !this.chkdiv.checked;
        if (this.chkdiv.checked) {
            $("img_ck1").className = 'areachk2';
        }
        else {
            $("img_ck1").className = 'areachk1';
        }   
    }
};

var BusSearch = {
    isLocating: '',
    searchByName: function() {
        if ($("txt_bus_s").value == '出发地' || $("txt_bus_e").value == '目的地') return;
        var sn = escape($("txt_bus_s").value);
        var en = escape($("txt_bus_e").value);
        showpage("Bus.aspx?sn=" + sn + "&en=" + en);
    },
    searchByPOS: function() {
        var sp = escape($("hid_bus_poss").value);
        var ep = escape($("hid_bus_pose").value);
        if (sp == '0' || ep == '0') return;
        showpage("Bus.aspx?sp=" + sp + "&ep=" + ep);
    },
    searchByLine: function() {
        var bid = $('txtBusLine').value.trim();
        if (bid == "0") return;
        ajaxObj.getBusLine(parseInt(bid), cb);
        function cb(res) {
            var temp = res.value.split("~");
            eval('var srdata = ' + temp[0]);
            
            _SRLISTTIP.style.display = srdata.c == 0 ? "" : "none";
            
            gMap.resultList.showBIGImage = false;
            gMap.resultList.loadList(srdata);
            gMap.resultList.setOptions({
                onItemClick: function(item) {
                    BusInfoWin.Show(item.pos.x, item.pos.y, item.id, item.nameA);
                },
                onHide: function(){
                    gMap.layerData.clearMarks();
                }
            });
            
            gMap.layerData.addMarks(srdata.list, false);
            gMap.layerData.setOnMarkClick(showinfo);
            
            gMap.resultList.setExtraInfo(true, temp[1]);
            
            gMap.resultList.show();
        }
        
        function showinfo(pop) {
            BusInfoWin.Show(pop.pos.x, pop.pos.y, pop.id, pop.n);
        }   
    },
    searchByStation: function() {
        var busstation = $("txt_bus_station").value;
        if (busstation == "") return;
        ajaxObj.searchBusStation(busstation, bscb);
        function bscb(res) {
            eval('var srdata = ' + res.value);
            
            _SRLISTTIP.style.display = srdata.c == 0 ? "" : "none";
            
            gMap.resultList.showBIGImage = false;
            gMap.resultList.loadList(srdata);
            gMap.resultList.setOptions({
                onItemClick: function(item) {
                    BusInfoWin.Show(item.pos.x, item.pos.y, item.id, item.nameA);
                },
                onHide: function(){
                    gMap.layerData.clearMarks();
                }
            });
            
            gMap.layerData.addMarks(srdata.list, false);
            gMap.layerData.setOnMarkClick(showbsstation);
            gMap.resultList.setExtraInfo(false, "");
            
            gMap.resultList.show();
        }
        
        function showbsstation(pop) {
            BusInfoWin.Show(pop.pos.x, pop.pos.y, pop.id, pop.n);
        }
    },
    locatePOS: function(flag) {
        if (this.isLocating != '') this.cancelFromBtn(this.isLocating);
        $("btn_locate" + flag).style.display = 'none';
        $("btn_cancel_" + flag).style.display = '';
        $("link_locate" + flag).style.display = 'none';
        $("link_fincancel_" + flag).style.display = 'none';
        GetPOS('', '', '', '', '', 'BusSearch.finLocate(\'' + flag + '\', mapx, mapy)', 'BusSearch.cancelLocate(\'' + flag + '\')');
        this.isLocating = flag;
    },
    cancelFromBtn: function (flag) {
        this.cancelLocate(flag);
        gMap.opGetPOS.cancel();
    },
    cancelLocate: function(flag) {
        $("btn_locate" + flag).style.display = '';
        $("btn_cancel_" + flag).style.display = 'none';
        $("link_locate" + flag).style.display = 'none';
        $("link_fincancel_" + flag).style.display = 'none';
        this.isLocating = '';
        $("hid_bus_pos" + flag).value = '0';
        gMap.layerImages.remove('Icon_Bus_' + flag);
    },
    finLocate: function(flag, x, y) {
        $('img_clearMark').style.display = '';
        $('img_clearMark').onclick = function(){gMap.layerImages.remove('Icon_Bus_s');gMap.layerImages.remove('Icon_Bus_e');$('img_clearMark').style.display = 'none';};
        $("btn_locate" + flag).style.display = 'none';
        $("btn_cancel_" + flag).style.display = 'none';
        $("link_locate" + flag).style.display = '';
        $("link_fincancel_" + flag).style.display = '';
        $("hid_bus_pos" + flag).value = x + "," + y;
        var bus_locate = gMap.layerImages.add('Icon_Bus_' + flag, 'images/bus/locate_' + (flag == 's' ? 'start' : 'end') + '.gif', x, y, 25, 29, 12, 28);
        this.isLocating = '';
    },
    showPOS: function(flag) {
        var pos = $("hid_bus_pos" + flag).value.split(',');
        gMap.flyTo(pos[0], pos[1]);
    }
};
// 公交搜索面板
var PnlOfBusSearch= function(){
    var searchBusLine = $("btnBusLine");
    var bussel = $("busSel");
    var locates = $("btn_locates");
    var locatee = $("btn_locatee");
    var startStation=$("txt_bus_s");
    var endStation=$("txt_bus_e");
    var searchStation=$("txt_bus_station");    
    
    startStation.value=StartStationName;
    endStation.value=EndStationName;
    searchStation.value=SearchStationName;    
    
    bussel.onchange = function() {
        for (var i = 1; i < 5; i++) {
            if (this.value == i) {
                $("d_busmode" + i).style.display = '';
            }
            else {
                $("d_busmode" + i).style.display = 'none';
            }
        } 
    };
    searchBusLine.addEvent('mouseenter', function() {
        this.className = 'searchbtnoff';
    });
    searchBusLine.addEvent('mouseleave', function() {
        this.className = 'searchbtnon';
    });
    searchBusLine.addEvent('click', function() {
        if (bussel.value == "1") {
            BusSearch.searchByName();
        }
        if (bussel.value == "4") {
            BusSearch.searchByPOS();
        }
        if (bussel.value == "2") {
            BusSearch.searchByLine();
        }
        if (bussel.value == "3") {
            BusSearch.searchByStation();
        }
    });
    locates.addEvent('click', function() {
        BusSearch.locatePOS('s');
    });
    locatee.addEvent('click', function() {
        BusSearch.locatePOS('e');
    });
    $("btn_cancel_s").addEvent('click', function() {
        BusSearch.cancelFromBtn('s');
    }); 
    $("link_locates").addEvent('click', function() {
        BusSearch.showPOS('s');
    });
    $("link_fincancel_s").addEvent('click', function() {
        BusSearch.cancelLocate('s');
    });
    $("btn_cancel_e").addEvent('click', function() {
        BusSearch.cancelFromBtn('e');
    });
    $("link_locatee").addEvent('click', function() {
        BusSearch.showPOS('e');
    });
    $("link_fincancel_e").addEvent('click', function() {
        BusSearch.cancelLocate('e');
    });
};
PnlOfBusSearch.onshow = function(){};

// Tag搜索面板
var PnlOfTagSearch= function(){
    var searchButton= $('btnSchTag');

    searchButton.addEvent('mouseenter', function() {
        this.className = 'searchbtnoff';
    });
    searchButton.addEvent('mouseleave', function() {
        this.className = 'searchbtnon';
    });
    searchButton.addEvent('click', function(){
        var tagkw = $('txtSchTagValue').value.trim();
        if (tagkw == "") return;
        showpage($('selTagType').value + tagkw );
    });
};
PnlOfTagSearch.onshow = function(){};

// tag 搜索建议
var TagSuggest = function() {
    var sel = $('selTagType');
    var tagsearchInput = $('txtSchTagValue');
    tagsearchInput.value = "";
    tagsearchInput.addEvent('focus', function() {
        this.className = 'inputboxactive';
    });
    tagsearchInput.addEvent('blur', function() {
        this.className = 'inputbox';
    });
    tagsearchInput.addEvent('keyup', function(evt) {
		evt = new Event(evt);
		if (evt.key == 'enter') showpage(sel.value + tagsearchInput.value);
	});

    var completer = new Autocompleter.Citylr(tagsearchInput, 'tagsg2.ashx', {
        'useSelection': false,
        'maxChoices': 10,
		'onRequest': function(el) {
		    tagsearchInput.className = 'inputboxonrequest';
		},
		'onComplete': function(el) {
			tagsearchInput.className = 'inputboxactive';
			tagsearchInput.focus();
		},
		'onFailure': function() {
		    tagsearchInput.className = 'inputboxactive';
		},
		'onGetQueryString': function(value) {
		    return {
		        'type': sel.options[sel.selectedIndex].text == '主题'? "topic" : "tag",
		        's': value
		    };
		},
		'onSelect': function(ele) {
		    completer.ajax.cancel();
		    tagsearchInput.className = 'inputboxactive';
		    showpage(sel.value + tagsearchInput.value);
		}
	});
	completer.ajax.setHeader('svcop', 'search');
	completer.ajax.setHeader('Query-Type', '3');
};

// 应用程序类
var Map2App = new Class({
    initialize: function() {
        this._welCome = $('d_Welcome');
        this._welLoadTip = $('d_LoadingTip');
        this.oSysBody = $('sysBody');
        this.oSysBanner = $('sysBanner');
        this.oMap = $('sysMap');
        this.oSplit = $('sysSplit');
        this.oSideBox = $('sysSideBox');
        
        this.oMap.style.cursor = 'default';
        this.oSideBox.style.cursor = 'default';
        this.oMap.setStyles({'overflow': 'hidden'});
        
        this.isFullScreen = false;
        this.isShowSideBox = true;
        
        if (Cookie.get('fs') == 'true') this.isFullScreen = true; else this.isFullScreen = false;
		if (Cookie.get('side') == 'false') this.isShowSideBox = false; else this.isShowSideBox = true;
        
        var p = this.oSplit.getCoordinates();
	    this.oSplitButton = new Element('div', {'styles': {
		    'position': 'absolute',
		    'left': 0,
		    'border': 'none',
		    'width': p.width,
		    'cursor': 'pointer'
		}});
		
		this.oSplitButton.className = this.isShowSideBox ? 'msplitoff1' : 'msplitoff2';
	    this.oSplit.appendChild(this.oSplitButton);
	    this.oSplitButton.addEvent('click', this.splitClick.bindWithEvent(this));
	    this.oSplitButton.addEvent('mouseenter', function(){this.className = gApp.isShowSideBox ? 'mspliton1' : 'mspliton2';});
	    this.oSplitButton.addEvent('mouseleave', function(){this.className = gApp.isShowSideBox ? 'msplitoff1' : 'msplitoff2';});
	    
	    this.oSideBox.setStyle('width', SIDEBOX_WIDTH);
	    this.oSideBox.setHTML('<iframe id="frmSidebox" name="frmSidebox" width="100%" style="background-color:#fff; border: none;" frameborder="no" marginheight="0" marginwidth="0" border="0" src="" scrolling="yes"></iframe>');
	    this.frmSidebox = $('frmSidebox');
	    this.frmSrc = SIDEBOX_URL;
	    this.frmSideBoxItv = null;
	    this.setSideFrameSrc(SIDEBOX_URL);
	    
	    this.resizeItv = null;
        
        this.modSearch = new ModSearchBox();
        
        this.resize();
    },
    setSidePanelSize: function(value){
	    if (value && (parseInt(value) > 100) && this.oSideBox) {
	        SIDEBOX_WIDTH = parseInt(value);
	        this.oSideBox.setStyle('width', SIDEBOX_WIDTH);
	        this.resize();
	    }
	},
	//showpage
	setSideFrameSrc: function(src) {
	    $clear(this.frmSideBoxItv);
	    this.frmSrc = src;
	    if (this.frmSidebox) {
	        this.togSizeBox(true);
	        this.frmSideBoxItv = setTimeout(function() {
	            this.frmSidebox.src = 'jump2page.htm?' + escape(this.frmSrc);
	        }.bind(this), 30);
	    }
	},
    splitClick: function() {
        this.togSizeBox();
    },
    resize: function() {
        var winHeight = window.getHeight();
        var winWidth = window.getWidth();
        
        // [note][wenkang]注：只有先改变可见性，才能得到正确的元素的坐标位置
        if (!this.isFullScreen) {
            this.oSysBanner.style.display = '';
            this.oSplit.style.display = '';
        }
        
        var minW = SIDEBOX_WIDTH + 200;
        var minH = this.oSysBanner.getCoordinates().height + 200;
        
        if (winWidth < minW) {
            this.oSysBody.style.width = minW + 'px';
            this.oSysBanner.style.width = minW + 'px';
        }
        else {
            this.oSysBody.style.width = winWidth + 'px';
            this.oSysBanner.style.width = winWidth + 'px';
        }
        
        var bannerHeight = ((this.isFullScreen) ? 0 : (this.oSysBanner.getCoordinates().height));
        if (winHeight < minH) {
            this.oSysBody.setStyles({'height': minH - bannerHeight});
        }
        else {
            this.oSysBody.setStyles({'height': winHeight - bannerHeight});
        }
        
        if (this.isFullScreen) {
            this.oSysBanner.style.display = 'none';
            this.oSplit.style.display = 'none';
            this.oSideBox.style.display = 'none';
            var bodyCoord = this.oSysBody.getCoordinates();
            this.oMap.setStyles({
                'left': bodyCoord.left,
                'top': bodyCoord.top,
                'width': bodyCoord.width,
                'height': bodyCoord.height
            });
        }
        else {
            this.oSysBanner.style.display = '';
            this.oSplit.style.display = '';
            var bodyCoord = this.oSysBody.getCoordinates();
            if (this.isShowSideBox) {
                this.oSideBox.style.display = '';
                this.oSideBox.setStyles({
                    'left': bodyCoord.width - SIDEBOX_WIDTH,
                    'top': bodyCoord.top,
                    'width': SIDEBOX_WIDTH,
                    'height': bodyCoord.height
                });
                this.oSplit.setStyles({
                    'left': bodyCoord.width - this.oSplit.getCoordinates().width - this.oSideBox.getCoordinates().width,
                    'top': bodyCoord.top,
                    'height': bodyCoord.height
                });
                this.oMap.setStyles({
                    'left': bodyCoord.left,
                    'top': bodyCoord.top,
                    'width': bodyCoord.width - this.oSplit.getCoordinates().width - this.oSideBox.getCoordinates().width,
                    'height': bodyCoord.height
                });
            }
            else {
                this.oSideBox.style.display = 'none';
                this.oSplit.setStyles({
                    'left': bodyCoord.width - this.oSplit.getCoordinates().width,
                    'top': bodyCoord.top,
                    'height': bodyCoord.height
                });
                this.oMap.setStyles({
                    'left': bodyCoord.left,
                    'top': bodyCoord.top,
                    'width': bodyCoord.width-this.oSplit.getCoordinates().width,
                    'height': bodyCoord.height
                });
            }
            this.oSplitButton.setStyle('top', Math.round(bodyCoord.height - this.oSplitButton.getCoordinates().height) / 2);
            if (this.frmSidebox) this.frmSidebox.setStyles({'width': this.oSideBox.style.width, 'height': this.oSideBox.style.height});
        }
        
        if (gMap) {
            // [note][wenkang]为何做这个延迟：IE下，改变窗口大小时，会重复执行onresize事件
            $clear(this.resizeItv);
            this.resizeItv = setTimeout(function(){gMap.resize();}, 100);
        }
        Cookie.set('fs', this.isFullScreen);
		Cookie.set('side', this.isShowSideBox);
		
		HotTab.resize();
    },
    //showrightbox, open:true, close:false
    togSizeBox: function(value) {
        if ((typeof value) == 'boolean') this.isShowSideBox = value; else this.isShowSideBox = (this.isShowSideBox == true) ? (false) : (true);
		this.resize();
    },
    togFullScreen: function(value) {
        if ((typeof value) == 'boolean') {
            this.isFullScreen = value; 
        }
        else {
            this.isFullScreen = !this.isFullScreen;
        }
        
        var fbtn = null;
        if (this.isFullScreen) {
            fbtn = gMap.toolbar.getButton('btn_tofulscr').options.imgOffsetNormal= {'x': -398, 'y': -110};
            fbtn = gMap.toolbar.getButton('btn_tofulscr').options.imgOffsetOver= {'x': -398, 'y': -148};
        }
        else {
            fbtn = gMap.toolbar.getButton('btn_tofulscr').options.imgOffsetNormal= {'x': -338, 'y': -110};
            fbtn = gMap.toolbar.getButton('btn_tofulscr').options.imgOffsetOver= {'x': -338, 'y': -148};
        }
        
        gMap.popupmenu.handle.getElementsByTagName("DIV")[1].innerHTML = (this.isFullScreen) ? ('&nbsp;&nbsp;&nbsp;退 出 全 屏') : ('&nbsp;&nbsp;&nbsp;全 屏 显 示');
        
        this.resize();
    },
    closeWelcome: function() {
        this._welCome.style.display = 'none';
        this._welLoadTip.style.display = 'none';
    }
});

/*toolbar*/
var InitToolBar = function() {
    var btnWidth = 82;
    var ddlWidth = 82;
    var mapMenus = {
        "FulSrc": null,
        "MapTool": null,
        "ObjView": null,
        "MapOpt": null,
        "GPSTool": null
    };
    gMap.toolbar.handle.setStyles({
        'height': '32px',
        'border': '0px',
        'opacity': 1
    });
    
    gMap.toolbar.handle.className = 'bgPic cssToolBar';
    mapMenus.FulSrc = gMap.toolbar.addButton('btn_tofulscr', {
        'caption': '',
        'width': 64,
        'onClick': function(tb) {
            gApp.togFullScreen();
        },
        'height': 31,
        'imgSrc': $Skin('images/mainbg.png'),
        'imgOffsetNormal': {'x': -338, 'y': -110},
        'imgOffsetOver': {'x': -338, 'y': -148},
        'BGActive': '',
        'BGOver': '',
        'BGNormal': '#fff'
    });
    
    mapMenus.ObjView = gMap.toolbar.addButton('btn_objview', {
        'caption': '',
        'type': TBType.ddb,
        'width': btnWidth,
        'height': 31,
        'imgSrc': $Skin('images/mainbg.png'),
        'imgOffsetNormal': {'x': -89, 'y': -110},
        'imgOffsetOver': {'x': -89, 'y': -148},
        'BGActive': '',
        'BGOver': '',
        'BGNormal': '' 
    });
    
    mapMenus.ObjView.setMenu(
        '<ul class="ddList">' +
            '<li><a href="#" onclick="mapObjView.Show(\'0\');return false;">路名</a></li>' +
            '<li><a href="#" onclick="mapObjView.Show(\'bs\');return false;">公车</a></li>' +
            '<li><a href="#" onclick="mapObjView.Show(\'26,27\');return false;">住宿</a></li>' +
            '<li><a href="#" onclick="mapObjView.Show(\'5,6,7,8,9\');return false;">餐饮</a></li>' +
            '<li><a href="#" onclick="mapObjView.Show(\'1,2,3,4,36\');return false;">娱乐</a></li>' +
            '<li><a href="#" onclick="mapObjView.Show(\'16,17,38\');return false;">购物</a></li>' +
            '<li><a href="#" onclick="mapObjView.Show(\'19,20,21,22\');return false;">美容</a></li>' +
            '<li><a href="#" onclick="mapObjView.Show(\'29\');return false;">银行</a></li>' +
            '<li><a href="#" onclick="mapObjView.Show(\'39\');return false;">药店</a></li>' +
            '<li><a href="#" onclick="mapObjView.Show(\'31\');return false;">加油站</a></li>' +
            '<li><a href="#" onclick="mapObjView.Show(\'\');return false;">清除</a></li>' +
        '</ul>', ddlWidth);
        
    mapMenus.MapTool = gMap.toolbar.addButton('btn_maptool', {
        'caption': '', 
        'type': TBType.ddb,
        'width': btnWidth,
        'height': 31,
        'imgSrc': $Skin('images/mainbg.png'),
        'imgOffsetNormal': {'x': -173, 'y': -110},
        'imgOffsetOver': {'x': -173, 'y': -148},
        'BGActive': '',
        'BGOver': '',
        'BGNormal': '' 
    });
    mapMenus.MapTool.setMenu(
        '<ul class="ddList">' +
            '<li><a href="#" onclick="mapTools.Show(0, \'c\');return false;">地图便签</a></li>' +
            '<li><a href="#" onclick="mapTools.Show(1, \'c\');return false;">创建主题</a></li>' +
            '<li><a href="#" onclick="mapTools.Show(2, \'c\');return false;">纠错举报</a></li>' +
            '<li><a href="#" onclick="mapTools.Show(3, \'c\');return false;">报告新标注</a></li>' +
            '<li><a href="mini.aspx" target="_blank">地图接口</a></li>' +
        '</ul>', ddlWidth);
    
    mapMenus.MapOpt = gMap.toolbar.addButton('btn_mapopt', {
        'caption': '', 
        'type': TBType.ddb,
        'width': btnWidth,
        'height': 31,
        'imgSrc': $Skin('images/mainbg.png'),
        'imgOffsetNormal': {'x': -5, 'y': -110},
        'imgOffsetOver': {'x': -5, 'y': -148},
        'BGActive': '',
        'BGOver': '',
        'BGNormal': '' 
    });
    mapMenus.MapOpt.setMenu(
        '<ul class="ddList">' +
            '<li><a href="#" onclick="mapView(1);return false;">航拍图</a></li>' +
            '<li><a href="#" onclick="mapView(2);return false;">三维图</a></li>' +
            '<li><a href="#" onclick="mapView(3);return false;">路名</a></li>' +
            '<li><a href="#" onclick="mapObjView.Show(\'hot\');return false;">标注</a></li>' +
        '</ul>', ddlWidth);
        
    mapMenus.GPSTool = gMap.toolbar.addButton('btn_getGPS', {
        'caption': '',
        'width': btnWidth,
        'onClick': function(tb) {
            showpage('GetDegreesByGPS.aspx');
        },
        'height': 31,
        'imgSrc': $Skin('images/mainbg.png'),
        'imgOffsetNormal': {'x': -252, 'y': -110},
        'imgOffsetOver': {'x': -252, 'y': -148},
        'BGActive': '',
        'BGOver': '',
        'BGNormal': ''
    });  
};
//mapView
var mapView = function(idx) {
    switch (idx) {
        case 1:
            if (gMap.maptype != MAP_AERO) gMap.changeMapType(MAP_AERO);
            break
        case 2:
            if (gMap.maptype != MAP_3D) gMap.changeMapType(MAP_3D);
            break;
        case 3:
            gMap.showRN();
            break;
        default:
            break;
    }
    gMap.birdview.updateButtonStatus();
};
var mapObjView = {
    _ids: '',
    Show: function(ids) {
        if (ids == 'hot') {
            gMap.layerData.clearMarks();
            gMap.showHS(!gMap.showlabel);
            gMap.birdview.updateButtonStatus();
            return;
        }
        else {
            if (gMap.showlabel) {
                gMap.showHS(!gMap.showlabel);
            }
            gMap.birdview.updateButtonStatus();
            this.loadObjByCatID(ids);
        }
    },
    loadObjByCatID: function(ids) {
        if (ids == '') {
            if (gMap.showlabel) {
                gMap.showHS(!gMap.showlabel);
            }
            gMap.layerData.clearMarks();
            gMap.birdview.updateButtonStatus();
        }
        else {
            if (gMap.mapzoom < 2) return;
            this._ids = ids;
            var ca = gMap.getcurrarea();
            ajaxObj.getTypeHints(ids, ca.l, ca.t, ca.r, ca.b, mvcb);
            function mvcb(res) {
                eval("var list = " + res.value);
                gMap.layerData.addMarks(list, false);
                gMap.layerData.setOnMarkClick(showinfo);
            }
            function showinfo(pop) {
                if (mapObjView._ids != 'bs') {
                    BaseInfoWin.Show(pop.pos.x, pop.pos.y, pop.id, pop.n);
                }
                else {
                    BusInfoWin.Show(pop.pos.x, pop.pos.y, pop.id, pop.n);
                }
            }
        }
    }
};
//mapTools
var mapTools = {
    toolsparm: '',
    Show: function(idx, isCommon) {
        switch (idx) {
            case 0:              
                GetPOS('', '', '', '', '', 'TipWin.Show(mapx, mapy, "map/Tip.aspx?x=" + mapx + "&y=" + mapy + "&' + mapTools.toolsparm + '")', '');
                break;
            case 1:
                if (isCommon == null) {
                    GetPOS('', '', '', '', '', 'PubInfoWin.Show(mapx, mapy, "map/PubInfo.aspx?x=" + mapx + "&y=" + mapy + "&' + mapTools.toolsparm + '")', '');
                }
                else {
                    showpage("tagtitledetail.aspx?New=1");
                }
                break;
            case 2:
                GetPOS('', '', '', '', '', 'ErrWin.Show(mapx, mapy, "map/ErrReport.aspx?x=" + mapx + "&y=" + mapy + "&' + mapTools.toolsparm + '")', '');
                break;
            case 3:
                GetPOS('', '', '', '', '', 'NewObjWin.Show(mapx, mapy, "map/NewObjReport.aspx?x=" + mapx + "&y=" + mapy + "&' + mapTools.toolsparm + '")', '');
                break;
            default:
                break;
        }
        this.toolsparm = '';   
    }
};
//右键菜单
var InitPopupMenu = function() {
    var menuWidth = 106;
    var menuHeight = 18;
    
    gMap.popupmenu.addButton('popFullScreen', {
        'width': menuWidth,
        'height': menuHeight, 
        'textAlign': 'left', 
        'caption': '&nbsp;&nbsp;&nbsp;全 屏 显 示',
        'onClick': function(button) {
            gApp.togFullScreen();
            button.setCaption(((gApp.isFullScreen)?('&nbsp;&nbsp;&nbsp;退 出 全 屏'):('&nbsp;&nbsp;&nbsp;全 屏 显 示')));
        }
    });
    gMap.popupmenu.addButton('mapTip', {
        'width': menuWidth, 
        'height': menuHeight,
        'textAlign': 'left', 
        'caption': '&nbsp;&nbsp;&nbsp;地 图 便 签',
        'onClick': function() {
            mapTools.Show(0);
        }
    });
    gMap.popupmenu.addButton('pubInfo', {
        'width': menuWidth, 
        'height': menuHeight,
        'textAlign': 'left', 
        'caption': '&nbsp;&nbsp;&nbsp;发 布 信 息',
        'onClick': function() {
            mapTools.Show(1,'c');
        }
    });
    gMap.popupmenu.addButton('errReport', {
        'width': menuWidth, 
        'height': menuHeight,
        'textAlign': 'left', 
        'caption': '&nbsp;&nbsp;&nbsp;纠 错 举 报',
        'onClick': function() {
            mapTools.Show(2);
        }
    });
   
    gMap.popupmenu.addButton('newObj', {
        'width': menuWidth, 
        'height': menuHeight,
        'textAlign': 'left', 
        'caption': '&nbsp;&nbsp;&nbsp;报<span style="margin-left: 1px;">告</span><span style="margin-left: 2px;">新</span><span style="margin-left: 2px;">标</span><span style="margin-left: 2px;">注</span>',
        'onClick': function() {
            mapTools.Show(3);
        }
    });
     gMap.popupmenu.addButton('errReport', {
        'width': menuWidth, 
        'height': menuHeight,
        'textAlign': 'left', 
        'caption': '&nbsp;&nbsp;&nbsp;分 享 地 图',
        'onClick': function() {
            window.open('mini.aspx');
        }
    });
    gMap.popupmenu.handle.setStyles({
        'border': 'solid 1px #69c',
        'background-color': '#fff'
    });
    
    var ds = gMap.popupmenu.handle.getElementsByTagName("DIV");
    for (var i = 0; i < ds.length; i++) {
        if (ds[i].style.overflow == 'hidden') {
            ds[i].style.border = 'solid 1px #69c';
            ds[i].style.borderBottom = 'none';
        }
    }
    ds[ds.length - 2].style.borderBottom = 'solid 1px #69c';
};
/*public*/
function showpage(url) {
    gApp.setSideFrameSrc(url);
}
function zoomTo(size) {
   var maparea = $("sysMap").getCoordinates();
   var xy = {x: 0, y: 0};
   xy.x = parseInt(maparea.width / 2);
   xy.y = parseInt(maparea.height / 2);
   gMap.zoomByPos(size, xy);
}
function GetPOS(tip, w, h, title, tipContent, code, end) {
    _tip = tip == "" ? "" : tip;
    _w = w == "" ? 185 : w;
    _h = h == "" ? 48 : h;
    _title = title == "" ? "getPOS" : title;
    _tipContent = tipContent == "" ? "请移动鼠标到目标位置：<br />单击『鼠标左键』获取该点坐标<br />单击『鼠标右键』取消获取坐标" : content;
    gMap.opHint.show(_tip, _w, _h);
    gMap.opHint.handle.setStyles({
        "background-color": "#ffc",
        "width": _w,
        "height": _h,
        "text-align": "center",
        "color": '#003',
        "border": 'solid 1px #666'
    });
    if (window.ie) gMap.opHint.handle.setStyle("padding-top", 4);
    
    gMap.opGetPOS.start(
        _title,
        _tipContent,
        function(opid, mapx, mapy){eval(code);},
        function(opid){eval(end);}
    );
}
function getIfrPage(url, w, h, isScrolling) {
    _scr = isScrolling ? 'yes' : 'no';
    return '<iframe id="ifr_win" frameborder="0" height="' + h + 'px" width="' + w + 'px" scrolling="' + _scr + '" src="jump2page.htm?' + url + '" marginheight="0" marginwidth="0"></iframe>';
}
/*Wins*/
function initDefWin() {
    gMap.wins.def.handle.setStyles({
            'border': 'solid 1px #b3d0e1',
            'background-color': '#fff'
        });
    gMap.wins.def.hTitle.setStyles({
        'border': 'none',
        'background-color': '#fff',
        'height': '18px',
        'line-height': '18px'
    });
    gMap.wins.def.hTitle.className = 'bgPic commonwinTitle';
    gMap.wins.def.hCaption.className = 'commonwinCaption';
    gMap.wins.def.hCaption.setStyles({
        'background-color': 'Transparent',
        'line-height': '17px'
    });
    gMap.wins.def.hContent.setStyle('border', 'none');
    
    gMap.wins.def.WIN_BTN_RIGHT = 2;
    gMap.wins.def.WIN_CAPTION_OFFSET = -40;
    gMap.wins.def.hClose.setup({
	    'imgSrc': $Skin('images/mainbg.png'),
	    BGActive: '',
	    BGOver: '',
	    BGNormal: '',
	    caption: '关闭',
	    'width': 15,
	    'height': 15,
	    'imgOffsetNormal': {'x': -404, 'y': -274},
	    'imgOffsetOver': {'x': -350, 'y': -274},
	    'imgOffsetActive': {'x': -350, 'y': -274}
    });
}
var BaseInfoWin = {
    init: function() {
        gMap.wins['BaseInfoWin'] = new MapWindow(gMap);
        this.winw = 309;
        this.winh = 300;
        this.contentObj = $("d_BaseWin");
        this.WinObj = $("d_WinObj")
        this.loading = $("d_BaseWin_loading");
        this.infoContent = $("d_BaseWin_ctt");
        this.cpg = $("d_BaseWin_cpg");
        this.cobj = $("d_BaseWin_c");
        this.errPnl = $('d_BaseWin_err');
        this.errContent = $('i_BaseWin_err_c');
        this.errImg = $('i_BaseWin_err_img');
        this.errList = $('d_BaseWin_err_list');
        this.errUsrname = $("i_Base_err_uname");
        this.ajax = ajaxObj;
        this.aroundbs = false;
        
        this.tab = $("tb_BaseWin_tab").getElementsByTagName("TD");
        for (var i = 0; i < this.tab.length; i++) {
            this.tab[i]._idx = i;
            this.tab[i].onclick = function(){BaseInfoWin.Tab(this._idx);};
        }  
        this.tabpnl = [$("d_BaseWin_baseinfo"), $("d_BaseWin_around"), $("d_BaseWin_err")];
        gMap.wins['BaseInfoWin'].handle.setStyles({
            'border': 'solid 1px #b3d0e1',
            'background-color': '#fff'
        });
        gMap.wins['BaseInfoWin'].hTitle.setStyles({
            'border': 'none',
            'background-color': '#fff',
            'height': '18px',
            'line-height': '18px'
        });
        gMap.wins['BaseInfoWin'].hTitle.className = 'bgPic basewinTitle';
        gMap.wins['BaseInfoWin'].hCaption.className = 'basewinCaption';
        gMap.wins['BaseInfoWin'].hCaption.setStyles({
            'background-color': 'Transparent',
            'line-height': '17px'
        });
        gMap.wins['BaseInfoWin'].hContent.setStyle('border', 'none');
        
        gMap.wins['BaseInfoWin'].WIN_BTN_CELLSPACE = 1;
        gMap.wins['BaseInfoWin'].WIN_BTN_RIGHT= 2;
        gMap.wins['BaseInfoWin'].hClose.setup({
		    'imgSrc': $Skin('images/mainbg.png'),
		    BGActive: '',
		    BGOver: '',
		    BGNormal: '',
		    caption: '关闭',
		    'width': 15,
		    'height': 15,
		    'imgOffsetNormal': {'x': -404, 'y': -274},
		    'imgOffsetOver': {'x': -350, 'y': -274},
		    'imgOffsetActive': {'x': -350, 'y': -274}
	    });
	    
	    gMap.wins['BaseInfoWin'].hMax.setup({
	        'onClick': function(){BaseInfoWin.MaxObj();},
		    'imgSrc': $Skin('images/mainbg.png'),
		    BGActive: '',
		    BGOver: '',
		    BGNormal: '',
		    caption: '查看标注详细信息',
		    'width': 15,
		    'height': 15,
		    'imgOffsetNormal': {'x': -387, 'y': -274},
		    'imgOffsetOver': {'x': -333, 'y': -274},
		    'imgOffsetActive': {'x': -333, 'y': -274}
	    });
	    gMap.wins['BaseInfoWin'].hMax.setVisible(true);
	    
	    gMap.wins['BaseInfoWin'].hFav.setup({
	        'onClick': function(){BaseInfoWin.copyURL();},
		    'imgSrc': $Skin('images/mainbg.png'),
		    BGActive: '',
		    BGOver: '',
		    BGNormal: '',
		    caption: '复制该标注的链接',
		    'width': 15,
		    'height': 15,
		    'imgOffsetNormal': {'x': -370, 'y': -274},
		    'imgOffsetOver': {'x': -316, 'y': -274},
		    'imgOffsetActive': {'x': -316, 'y': -274}
	    });
	    gMap.wins['BaseInfoWin'].hFav.setVisible(true);
    },
    Show: function(x, y, id, title) {
        if (id < 1) return;
        
        this.Tab(0);
        
        gMap.wins['BaseInfoWin'].show(x, y, title, this.WinObj, this.winw, this.winh);
        
        var loadinfo = false;
        if (this.contentObj._id != id) loadinfo = true;
        
        if (loadinfo) {
            this.contentObj._id = id;
            this.getBaseInfo(id);
        }
    },
    Tab: function(idx) {
        for (var i = 0; i < this.tab.length; i++) {
            this.tab[i].className = (idx == i) ? "tabsel" : "tabnor";
            this.tabpnl[i].style.display = (idx == i) ? "" : "none";
        }
        gMap.wins['BaseInfoWin'].update();
        
        if (idx == 2 && this.errPnl._id != this.contentObj._id) {
			this.getErrReport(this.contentObj._id);
		}
    },
    getBaseInfo: function(id) {
        
        this.ishop = false;
        this.objinfo = false;      
		this.infoContent.innerHTML = '&nbsp;';
	    
	    AjaxPro.queue.abortMethod('getInfo');
	    this.ajax.getInfo(id, cb.bind(this), null, ajaxld.bind(this));
	    
        function cb(res) {
	        eval("var o = " + res.value);
	        var chtml = '';
	        if (o.eurl != '') {
		        chtml += '<div class="objImg"><a href="redirect.aspx?' + escape(o.eurl) + '" target="_blank"><img src="desimg.ashx?id=' 
		               + id + '" title="点击图片打开商家主页" alt="" /></a></div>';
                chtml += '<div class="objImgTip">←点击图片打开商家主页☆</div>';
                this.ishop = true;
                fWindow.open('redirect.aspx?' + o.eurl);
	        }
	       
	        if (o.extinfo) {
	            chtml += '<div class="objImg"><a href="redirect.aspx?' + id + '" target="_blank"><img src="desimg.ashx?id=' 
	                   + id + '" title="点击图片查看标注详细信息" alt="" /></a></div>';
                chtml += '<div class="objImgTip">←点击图片查看详细信息☆</div>';
	            this.objinfo = true;
	            fWindow.open('redirect.aspx?' + id);
	        }
	        
	        if (o.eurl == '' && !o.extinfo) {
		        chtml += '<div class="objImg"><img src="desimg.ashx?id=' + id + '" alt="" /></div>';
	        }
	        
    	    chtml += '<div><div class="objInfoName"><span>&nbsp;</span>' + o.add + '</div>';
            chtml += '<div class="objInfoPhone"><span>&nbsp;</span>' + o.tel + '</div>';
            chtml += '<div class="objInfoDes"><span>&nbsp;</span>' + o.des + '</div></div>';

	        this.infoContent.innerHTML = chtml;

	        if (o.ge) if (confirm('是"寻宝助手"叫你来的吗？')) {
	            this.continueGame();
    	    }
        }
	    
	    function ajaxld(e) {
            this.loading.style.display = e ? '' : 'none';
        }
		
		this.getChildObjs(id, 1, false);
    },
    getChildObjs: function(id, p, selfcall) {
        if (!selfcall) {
            this.cpg.style.display = 'none';
            this.cobj.style.display = 'none';
        }
        
		AjaxPro.queue.abortMethod('getChildren');
		this.ajax.getChildren(id, p, 8, cb.bind(this), null, ajaxld.bind(this));
		
		function cb(res) {
			eval ('var o = ' + res.value);
			var html = '', pghtml = '';
			if (o.pgc > 1) {
				for (var i = 0; i < o.pgc; i++) {
					if ((i + 1) == o.pg) {
						pghtml += '[<span style="color: #f00; padding: 0px 2px;">' + (i + 1) + '</span>]';
					}
					else {
						pghtml += '[<a href="#" onclick="BaseInfoWin.getChildObjs(' + id + ', ' + (i + 1) + ', true);return false;">' + (i + 1) + '</a>]';
					}
				}
				this.cpg.innerHTML = pghtml;
				this.cpg.style.display = '';
			}
			if (o.c > 0) {
				for (var i = 0; i < o.list.length; i++) {
					var o1 = o.list[i];
					html += '<div><a href="#" onclick="BaseInfoWin.Show(' + o1.x + ', ' + o1.y + ', ' + o1.id + ', \'' + o1.n + '\');return false;">' + o1.n + '</a></div>';
				}
				this.cobj.innerHTML = html;
				this.cobj.style.display = '';
			}
		}
		
		function ajaxld(e) {
			this.loading.style.display = e ? '' : 'none';
		}
    },
    getErrReport: function(id) {       
        this.errPnl._id = id;
		this.errList.innerHTML = '';
		this.errContent.value = '';
		this.errImg.value = '';
		
		AjaxPro.queue.abortMethod('loadErrReport');
		this.ajax.loadErrReport(id, cb.bind(this), null, ajaxld.bind(this));
		
		function cb(res) {
			this.errList.innerHTML = res.value;
			this.errContent.value = '';
		    this.errImg.value = '';
		}
		
		function ajaxld(e) {
			this.loading.style.display = e ? '' : 'none';
		}
	},
    AddErrPic: function() {
		var path = showModalDialog("_users/updatePageHolder.htm?res=image", window, 'dialogHeight: 250px; dialogWidth: 440px; status: 0; center: Yes; scroll: no; help: no;');
		if (path != null) this.errImg.value = path;
	},
	SubmitErr: function() {
		if (this.errContent.value == '') {
			alert('请填写错误描述');
			this.errContent.focus();
			return;
		}
		
		AjaxPro.queue.abortMethod('submitErrorReport');
		this.ajax.submitErrorReport(this.errContent.value, this.errUsrname.value, this.errImg.value, this.errPnl._id, cb.bind(this), null, ajaxld.bind(this));
		
		function cb(res) {
			if (res.value == 'ok') {
					alert('纠错举报已提交,感谢您的支持和帮助.');
					this.getErrReport(this.errPnl._id);
			}
			else {
			    alert(res.value);
			}
		}
		
		function ajaxld(e){
		    this.loading.style.display = e ? '' : 'none';
		}
	},
    getAroundInfo: function(cat) {
        if (gMap.mapzoom < 2) return;
        if (cat == 'bs') this.aroundbs = true; else this.aroundbs = false;
        AjaxPro.queue.abortMethod('searchAround');
        var areaObj = gMap.getcurrarea();
        var areaSch = areaObj.l + "," + areaObj.t + "," + areaObj.r + "," + areaObj.b;
        this.ajax.searchAround(cat, areaSch, cb.bind(this), null, ajaxld.bind(this));
        
	    function cb(res) {
            eval('var srdata = ' + res.value);
            
            _SRLISTTIP.style.display = srdata.c == 0 ? "" : "none";
            
            if (this.aroundbs) gMap.resultList.showBIGImage = false; else gMap.resultList.showBIGImage = true;
            gMap.resultList.loadList(srdata);
            gMap.resultList.setOptions({
                onItemClick: function(item) {
                    if (BaseInfoWin.aroundbs) {
                        BusInfoWin.Show(parseInt(item.pos.x), parseInt(item.pos.y), item.id, item.nameA);
                    }
                    else {
                        BaseInfoWin.Show(parseInt(item.pos.x), parseInt(item.pos.y), item.id, item.nameA);
                    }
                    return;
                },
                onPageClick: function(pg) {
                    doMapSearch(pg);
                },
                onHide: function(){
                    gMap.layerData.clearMarks();
                }
            });
            
            gMap.layerData.addMarks(srdata.list, false);
            gMap.layerData.setOnMarkClick(showaroundinfo);
            gMap.resultList.setExtraInfo(false, "");
            
            gMap.resultList.show();
        }
        
        function showaroundinfo(pop) {
            if (BaseInfoWin.aroundbs) {
                BusInfoWin.Show(parseInt(pop.pos.x), parseInt(pop.pos.y), pop.id, pop.n);
            }
            else {
                BaseInfoWin.Show(parseInt(pop.pos.x), parseInt(pop.pos.y), pop.id, pop.n);
            }
        }
	    
	    function ajaxld(e) {
		    this.loading.style.display = e ? '' : 'none';
	    }
    },
    AddtoFav: function() {
        AjaxPro.queue.abortMethod('AddToFavor');
        this.ajax.AddToFavor(this.contentObj._id, cb.bind(this), null, ajaxld.bind(this));
        
		function cb(res) {
			if (res.value == 'ok') {
				alert('已添加到收藏夹');
			}
			else {
			    alert(res.value);
			}
		}
		function ajaxld(e) {
			this.loading.style.display = e ? '' : 'none';
		}
    },
    MaxObj: function() {
        if (this.ishop || this.objinfo) {
            window.open("redirect.aspx?" + this.contentObj._id);
        }
    },
    copyURL: function() {
        this.mourl = appurl + "?MO@" + this.contentObj._id;
        if (copyToClipboard(this.mourl)) alert('地点标注链接已复制');
    },
    continueGame: function() {
     
    }
};
var BusInfoWin = {
    init: function() {
        gMap.wins['BusInfoWin'] = new MapWindow(gMap);
        
        gMap.wins['BusInfoWin'].handle.setStyles({
            'border': 'solid 1px #b3d0e1',
            'background-color': '#fff'
        });
        gMap.wins['BusInfoWin'].hTitle.setStyles({
            'border': 'none',
            'background-color': '#fff',
            'height': '18px',
            'line-height': '18px'
        });
        gMap.wins['BusInfoWin'].hTitle.className = 'bgPic commonwinTitle';
        gMap.wins['BusInfoWin'].hCaption.className = 'commonwinCaption';
        gMap.wins['BusInfoWin'].hCaption.setStyles({
            'background-color': 'Transparent',
            'line-height': '17px'
        });
        gMap.wins['BusInfoWin'].hContent.setStyle('border', 'none');
        
        gMap.wins['BusInfoWin'].WIN_BTN_RIGHT = 2;
        gMap.wins['BusInfoWin'].WIN_CAPTION_OFFSET = -40;
        gMap.wins['BusInfoWin'].hClose.setup({
		    'imgSrc': $Skin('images/mainbg.png'),
		    BGActive: '',
		    BGOver: '',
		    BGNormal: '',
		    caption: '关闭',
		    'width': 15,
		    'height': 15,
		    'imgOffsetNormal': {'x': -404, 'y': -274},
		    'imgOffsetOver': {'x': -350, 'y': -274},
		    'imgOffsetActive': {'x': -350, 'y': -274}
	    });
    },
    Show: function(x, y, id, n) {
        ajaxObj.getBusLinesByStation(id, cb);
        function cb(res) {
            var linesdiv = "<div class=\"busstationInfo\">{0}</div>";
            var lines = "";
            if (res.value != "") {
                var list = res.value;
                
                if (list != null && list.length > 0) {
                    for (var i = 0; i < list.length; i++) {
                        lines += "<a href=\"#\" onclick=\"BusInfoWin.getLineById(" + list[i].ID + ");return false;\">" + list[i].Name + "</a>";
                    }
                }
            }
            linesdiv = linesdiv.replace("{0}", lines);
            gMap.wins['BusInfoWin'].show(x, y, n, linesdiv, 200, 100);
        }
    },
    getLineById: function(id) {
        $("txtBusLine").value = id;
        BusSearch.searchByLine();
    }
};
var TipWin = {
    init: function() {
        gMap.wins['TipWin'] = new MapWindow(gMap);
        this.ifrw = 190;
        this.ifrh = 109;
        this.winw = 194;
        this.winh = 136;
        this.contenth = this.winh - 27;
        this.title = "地图便签";
        
        gMap.wins['TipWin'].handle.setStyles({
            'border': 'solid 1px #b3d0e1',
            'background-color': '#fff'
        });
        gMap.wins['TipWin'].hTitle.setStyles({
            'border': 'none',
            'background-color': '#fff',
            'height': '18px',
            'line-height': '18px'
        });
        gMap.wins['TipWin'].hTitle.className = 'bgPic commonwinTitle';
        gMap.wins['TipWin'].hCaption.className = 'commonwinCaption';
        gMap.wins['TipWin'].hCaption.setStyles({
            'background-color': 'Transparent',
            'line-height': '17px'
        });
        gMap.wins['TipWin'].hContent.setStyle('border', 'none');
        
        gMap.wins['TipWin'].WIN_BTN_RIGHT = 2;
        gMap.wins['TipWin'].WIN_CAPTION_OFFSET = -40;
        gMap.wins['TipWin'].hClose.setup({
		    'imgSrc': $Skin('images/mainbg.png'),
		    BGActive: '',
		    BGOver: '',
		    BGNormal: '',
		    caption: '关闭',
		    'width': 15,
		    'height': 15,
		    'imgOffsetNormal': {'x': -404, 'y': -274},
		    'imgOffsetOver': {'x': -350, 'y': -274},
		    'imgOffsetActive': {'x': -350, 'y': -274}
	    });
    },
    Show: function(x, y, url) {
        var ifr = getIfrPage(url, this.ifrw, this.ifrh, false);
        gMap.wins['TipWin'].show(x, y, this.title, ifr, this.winw, this.winh);
        gMap.wins['TipWin'].hContent.style.height = this.contenth + "px";    
    },
    SetWinHeight: function(h) {
        $("ifr_win").height = this.ifrh + h + "px";
        gMap.wins['TipWin'].hContent.style.height = this.contenth + h + "px";
    }
};
var PubInfoWin = {
    init: function() {
        gMap.wins['PubInfoWin'] = new MapWindow(gMap);
        this.ifrw = 280;
        this.ifrh = 360;
        this.winw = 284;
        this.winh = 370;
        this.title = "发布信息";
        
        gMap.wins['PubInfoWin'].handle.setStyles({
            'border': 'solid 1px #b3d0e1',
            'background-color': '#fff'
        });
        gMap.wins['PubInfoWin'].hTitle.setStyles({
            'border': 'none',
            'background-color': '#fff',
            'height': '18px',
            'line-height': '18px'
        });
        gMap.wins['PubInfoWin'].hTitle.className = 'bgPic commonwinTitle';
        gMap.wins['PubInfoWin'].hCaption.className = 'commonwinCaption';
        gMap.wins['PubInfoWin'].hCaption.setStyles({
            'background-color': 'Transparent',
            'line-height': '17px'
        });
        gMap.wins['PubInfoWin'].hContent.setStyle('border', 'none');
        
        gMap.wins['PubInfoWin'].WIN_BTN_RIGHT = 2;
        gMap.wins['PubInfoWin'].WIN_CAPTION_OFFSET = -40;
        gMap.wins['PubInfoWin'].hClose.setup({
		    'imgSrc': $Skin('images/mainbg.png'),
		    BGActive: '',
		    BGOver: '',
		    BGNormal: '',
		    caption: '关闭',
		    'width': 15,
		    'height': 15,
		    'imgOffsetNormal': {'x': -404, 'y': -274},
		    'imgOffsetOver': {'x': -350, 'y': -274},
		    'imgOffsetActive': {'x': -350, 'y': -274}
	    });
    },
    Show: function(x, y, url) {
        var ifr = getIfrPage(url, this.ifrw, this.ifrh, false);
        gMap.wins['PubInfoWin'].show(x, y, this.title, ifr, this.winw, this.winh);    
    }
};
var ErrWin = {
    init: function() {
        gMap.wins['ErrWin'] = new MapWindow(gMap);
        this.ifrw = 190;
        this.ifrh = 250;
        this.winw = 194;
        this.winh = 260;
        this.title = "纠错举报";
        
        gMap.wins['ErrWin'].handle.setStyles({
            'border': 'solid 1px #b3d0e1',
            'background-color': '#fff'
        });
        gMap.wins['ErrWin'].hTitle.setStyles({
            'border': 'none',
            'background-color': '#fff',
            'height': '18px',
            'line-height': '18px'
        });
        gMap.wins['ErrWin'].hTitle.className = 'bgPic commonwinTitle';
        gMap.wins['ErrWin'].hCaption.className = 'commonwinCaption';
        gMap.wins['ErrWin'].hCaption.setStyles({
            'background-color': 'Transparent',
            'line-height': '17px'
        });
        gMap.wins['ErrWin'].hContent.setStyle('border', 'none');
        
        gMap.wins['ErrWin'].WIN_BTN_RIGHT = 2;
        gMap.wins['ErrWin'].WIN_CAPTION_OFFSET = -40;
        gMap.wins['ErrWin'].hClose.setup({
		    'imgSrc': $Skin('images/mainbg.png'),
		    BGActive: '',
		    BGOver: '',
		    BGNormal: '',
		    caption: '关闭',
		    'width': 15,
		    'height': 15,
		    'imgOffsetNormal': {'x': -404, 'y': -274},
		    'imgOffsetOver': {'x': -350, 'y': -274},
		    'imgOffsetActive': {'x': -350, 'y': -274}
	    });
    },
    Show: function(x, y, url) {
        var ifr = getIfrPage(url, this.ifrw, this.ifrh, false);
        gMap.wins['ErrWin'].show(x, y, this.title, ifr, this.winw, this.winh);    
    }
};
var NewObjWin = {
    init: function() {
        gMap.wins['NewObjWin'] = new MapWindow(gMap);
        this.ifrw = 280;
        this.ifrh = 390;
        this.winw = 284;
        this.winh = 410;
        this.title = "报告新标注";
        
        gMap.wins['NewObjWin'].handle.setStyles({
            'border': 'solid 1px #b3d0e1',
            'background-color': '#fff'
        });
        gMap.wins['NewObjWin'].hTitle.setStyles({
            'border': 'none',
            'background-color': '#fff',
            'height': '18px',
            'line-height': '18px'
        });
        gMap.wins['NewObjWin'].hTitle.className = 'bgPic commonwinTitle';
        gMap.wins['NewObjWin'].hCaption.className = 'commonwinCaption';
        gMap.wins['NewObjWin'].hCaption.setStyles({
            'background-color': 'Transparent',
            'line-height': '17px'
        });
        gMap.wins['NewObjWin'].hContent.setStyle('border', 'none');
        
        gMap.wins['NewObjWin'].WIN_BTN_RIGHT = 2;
        gMap.wins['NewObjWin'].WIN_CAPTION_OFFSET = -40;
        gMap.wins['NewObjWin'].hClose.setup({
		    'imgSrc': $Skin('images/mainbg.png'),
		    BGActive: '',
		    BGOver: '',
		    BGNormal: '',
		    caption: '关闭',
		    'width': 15,
		    'height': 15,
		    'imgOffsetNormal': {'x': -404, 'y': -274},
		    'imgOffsetOver': {'x': -350, 'y': -274},
		    'imgOffsetActive': {'x': -350, 'y': -274}
	    });
    },
    Show: function(x, y, url) {
        var ifr = getIfrPage(url, this.ifrw, this.ifrh, false);
        gMap.wins['NewObjWin'].show(x, y, this.title, ifr, this.winw, this.winh);    
    }
};
var HotTab = {
    init: function() {
        this.show = true;
        if (typeof(_HOTTABS) == "undefined") {
            this.show = false;
            return;
        }
        
        this._hottab_tb = document.body.appendChild(document.createElement("TABLE"));
        this._hottab_tb.className = "HotTab_TB";
        this._hottab_tb.border = "0";
        this._hottab_tb.cellPadding = "0";
        this._hottab_tb.cellSpacing  = "1";
        
        this._hottab_tbody = this._hottab_tb.appendChild(document.createElement("TBODY"));
        
        this._hottab_tr = this._hottab_tbody.appendChild(document.createElement("TR"));
        this.tds = new Array();
        
        for (var i = 0; i < _HOTTABS.length; i++) {
            var td = document.createElement("TD");
            td._ison = _HOTTABS[i].isOn;
            td._idx = i;
            if (_HOTTABS[i].isOn == -1) {
                td.className = "HotTab_on";
            }
            else {
                td.className = _HOTTABS[i].isOn == 1 ? "HotTab_on" : "HotTab_off";
            }
            td.innerHTML = _HOTTABS[i].name;
            td.onclick = function(){HotTab.tabclick(this);};
            this.tds.push(this._hottab_tr.appendChild(td));    
        }
        this.resize();
    },
    resize: function() {
        if (!this.show) return;
        var bodycoord = $("sysBody").getCoordinates();
        this._hottab_tb.style.top = bodycoord.top + "px";
    },
    tabclick: function(obj) {
        if (obj._ison != -1) {
            obj._ison = obj._ison == 1 ? 0 : 1;
            obj.className = obj._ison == 1 ? "HotTab_on" : "HotTab_off";
        }
        _HOTTABS[obj._idx].clickfun();
    }
};

function ShowTagInWin(x, y, title, id) {           
    var ifrstr = '<div style="width: 286px; margin: 0px auto;"><iframe id="tag_ifr" scrolling="yes" frameborder="0" src="jump2page.htm?tagInfo.aspx?id=' 
               + id + '" width="286px" height="340px" style=\"margin: 0px; padding: 0px;\"></iframe></div>';
    
    gMap.wins.def.show(x, y, title, ifrstr, 290, 250); 
}
function ShowTagSourceOnMap() {
    if (typeof(_TSHide) == "undefined") return;
    _TSHide = !_TSHide;
    if (_TSARR.length < 1) return;
    if (_TSHide) {
        zoomTo(_TSZoom);
        gMap.layerData.addMarks(_TSARR, true);
        gMap.layerData.setOnMarkClick(_tsshowinfo);
        gMap.flyTo(_TSARR[0].x, _TSARR[0].y);
    }
    else {
        try{
            gMap.layerData.clearMarks();
            gMap.wins.def.hide();
        }
        catch(e){}
    }
    function _tsshowinfo(pop) {
        ShowTagInWin(parseInt(pop.pos.x), parseInt(pop.pos.y), pop.n, pop.id);
    }
}
function ShowBaseMap(flag) {
    if (flag == 1) {
        gMap.layerData.clearMarks();
        gMap.changeMapType((DEFAULTTYPE == 1 ? MAP_AERO : MAP_3D));
        gMap.showRN(DEFAULTSHOWRN);
        gMap.showHS(DEFAULTSHOWLABEL);
        zoomTo(DEFAULTZOOM);
        gMap.flyTo(DEFAULTPOS.x, DEFAULTPOS.y);
        gMap.birdview.updateButtonStatus();
    }
    else {
        if (typeof(_DefMapShowObj) == "undefined") return;
        gMap.layerData.clearMarks();
        gMap.wins["BaseInfoWin"].hide();
        gMap.changeMapType((DEFAULTTYPE == 1 ? MAP_AERO : MAP_3D));
        gMap.showRN(DEFAULTSHOWRN);
        gMap.showHS(DEFAULTSHOWLABEL);
        zoomTo(DEFAULTZOOM);
        gMap.birdview.updateButtonStatus();
        BaseInfoWin.Show(_DefMapShowObj.mox, _DefMapShowObj.moy, _DefMapShowObj.moid, _DefMapShowObj.mon);
        gMap.flyTo(_DefMapShowObj.mox, _DefMapShowObj.moy);
    }
}
function ExtAjaxPro() {
    AjaxPro.RequestQueue.prototype.abortMethod = function(method) {
	    if (this.timer != null) {
		    clearTimeout(this.timer);
	    }
	    this.timer = null;
	    for (var i = 0; i < this.queue.length; i++) {
		    if (this.queue[i][1] == method) this.queue.splice(i--, 1);
	    }
	    for(var i = 0; i < this.requests.length; i++) {
		    if (this.requests[i].method == method && this.requests[i].isRunning == true) {
			    this.requests[i].abort();
		    }
	    }
    }
}
function checkWinSize() {
    var wsize = window.getSize().size;
    if (_winsize.x != wsize.x || _winsize.y != wsize.y) {
        if (gApp) gApp.resize();
        _winsize.x = wsize.x;
        _winsize.y = wsize.y;
    }
}
function ForceWindow()
{
  this.r = document.documentElement;
  this.f = document.createElement("FORM");
  this.f.target = "_blank";
  this.f.method = "post";
  this.r.insertBefore(this.f, this.r.childNodes[0]);
}
ForceWindow.prototype.open = function(sUrl)
{
  this.f.action = sUrl;
  //this.f.submit();
}
var ShowPopUpWin = {
    isBack: false,
    isRunning: false,
    timerId_e: null,
    _holderWidth: 252,
    _holderHeight: 142,
    show: function() {
        if (typeof(POPUPWINWORD) == "undefined" || POPUPWINWORD == '') return;
        var wsize = window.getSize();
        $('td_PopUpWin_Content').innerHTML = POPUPWINWORD;
        $('d_PopUpWin').style.top = wsize.size.y - this._holderHeight + 'px';
        window.setTimeout(function() {
            ShowPopUpWin.isRunning = true;
            $('d_PopUpWin').effect('left', {duration: 4000, transition:Fx.Transitions.linear, onComplete: function(){ShowPopUpWin.isRunning = false;}}).start((-1 * ShowPopUpWin._holderWidth), 0);
        }, 1000);
        this.timerId_e = window.setTimeout(function() {
            ShowPopUpWin.isBack = true;
            $('d_PopUpWin').effect('left', {duration: 4000, transition:Fx.Transitions.linear, onComplete: function(){ShowPopUpWin.isBack = false;}}).start(0, (-1 * ShowPopUpWin._holderWidth));
            
        }, 10000);
    },
    close: function() {
        if (this.isBack || this.isRunning) return;
        $clear(this.timerId_e);
        $('d_PopUpWin').effect('left', {duration: 500, transition:Fx.Transitions.linear}).start(0, (-1 * ShowPopUpWin._holderWidth));
    }
};

function jumpToTitleSearch() {
    showpage('tagtitlelist.aspx?g=0&sort=0&title=' + $('txtSearchValue').value);
}

/*Event Init*/

// AjaxPro Abort方法
ExtAjaxPro();

// 创建应用程序
gApp= new Map2App();

// 创建地图
gMap= new CityMap('sysMap');

// ajax对象
ajaxObj = NewMapAjaxSvc;

// 创建弹出窗
fWindow = new ForceWindow();

// 窗口初始化
initDefWin();
BaseInfoWin.init();
BusInfoWin.init();
TipWin.init();
PubInfoWin.init();
ErrWin.init();
NewObjWin.init();

gMap.showHS(DEFAULTSHOWLABEL);
gMap.cbHSClick = function( _id, _name, _x, _y ) {
    BaseInfoWin.Show(_x, _y, _id, _name);
};

// 初始化工具栏
InitToolBar();

// 初始化右键菜单
InitPopupMenu();

// 搜索建议
SearchSuggest();
// Tag建议
TagSuggest();
   
// 区域搜索选择
AreaChk.init();

HotTab.init();

// 调整窗口大小
gMap.resize();

// 关闭欢迎
gApp.closeWelcome();

// 无结果提示
addNoResultTip();

window.setInterval(checkWinSize, 2000);

if (_START == 'MO') BaseInfoWin.Show(mox, moy, moid, mon); 
if (_START == 'TIP') gMap.wins.def.show(mox, moy, _tipt, _tipc, 200, 120);
if (_START == 'URL') showpage(jumpurl);
if (_START == 'TAG') ShowTagInWin(mox, moy, _tagt, _tagid);
if (typeof(_HOT_TABS_IDX) != "undefined") {
    _HOTTABS[_HOT_TABS_IDX].clickfun();    
}

ShowPopUpWin.show();

window.addEvent('resize', function() {
    if (gApp) gApp.resize();
});

/*Event Init End*/