var popSet=new Array();
var idlist=[];
var actionSet='';
var isEntity=false;
var localeExt='';
if(o_locale=='zh_tw'){
	localeExt='_'+o_locale;
}

function waitMap(){
	try{
		if(popomap.getMapStatus()){
			popomap.setEvent('onmousedown',mymousedown);
			//popomap.setEvent('onmousemove',mymousemove);
			popomap.setEvent('onmouseup',mymouseup);
			popomap.setEvent('onAreaClick',myAreaClick);
			popomap.setEvent('onUnitClick',myUnitClick);
			popomap.setEvent('customFun',myCustomFun);
			//popomap.setMapTip('<img src="images/map/rightTip.gif">');
			setDocDomain();
		}
		else{
			setTimeout('waitMap()',500);
		}
	}
	catch(e){
		setTimeout('waitMap()',500);
	}
}

function mymousedown(evt){
}
function mymousemove(evt){
	window.status=popomap.getCurX(evt)+':'+popomap.getCurY(evt);
}
function mymouseup(evt){
	if(actionSet=='') return;
	//var s=60*popomap.getZoom();
	popSet['X']=Math.round(popomap.getCurX(evt));
	popSet['Y']=Math.round(popomap.getCurY(evt));
	if(popSet[actionSet]){
		htmlStr=popSet[actionSet];
		htmlStr=htmlStr.replace('{$X}',popSet['X']);
		htmlStr=htmlStr.replace('{$Y}',popSet['Y']);
	}

	if(evt.button==2){
		switch(actionSet){
			case 'addNote':
				addNote();
				break;
			case 'addErr':
				addErr(popSet['X'],popSet['Y']);
				break;
			case 'addPost':
				addPost();
				break;
			case 'getPosXY':
				getPosXY();
				break;
			case 'setSmart':
				setSmart();
				break;
			case 'getPtInfo':
				getPtInfo();
				break;
			default:
				break;
		}
	}
	isEntity=false;
}
function myAreaClick(evt){
	isEntity=true;
	return;
	//alert(popomap.getAreaUnitInfo().AreaName+'/'+popomap.getAreaUnitInfo().AreaID+':'+popomap.getAreaUnitInfo().UnitName+'/'+popomap.getAreaUnitInfo().UnitID);
	posx=popomap.getAreaUnitInfo().x;
	posy=popomap.getAreaUnitInfo().y;
	createHistory(popomap.getAreaUnitInfo().AreaID,0,posx,posy,popomap.getAreaUnitInfo().AreaName);
}
function myUnitClick(evt){return;
	//alert(popomap.getAreaUnitInfo().AreaName+'/'+popomap.getAreaUnitInfo().AreaID+':'+popomap.getAreaUnitInfo().UnitName+'/'+popomap.getAreaUnitInfo().UnitID);
	posx=popomap.getAreaUnitInfo().x;
	posy=popomap.getAreaUnitInfo().y;
	createHistory(popomap.getAreaUnitInfo().AreaID,popomap.getAreaUnitInfo().UnitID,posx,posy,popomap.getAreaUnitInfo().UnitName);
}
function myCustomFun(evt,sign){
	switch(sign){
		case 'removeAll':
			removeAll();
			break;
		case 'removePop_addNote':
			removePop_addNote();
			break;
		case 'removePop_showNote':
			removePop_showNote();
			break;
		case 'removePop_addPost':
			removePop_addPost();
			break;
		case 'removePop_showPost':
			removePop_showPost();
			break;
		case 'removePop_addErr':
			removePop_addErr();
			break;
		case 'removePop_showInfo':
			removePop_showInfo();
			break;
		case 'addErr':
			addErr();
			break;
		case 'howArrive':
			howArrive();
			break;
		default:
			alert('custom');
	}
}
function getMapRang(){
	var centerX=popomap.getCenterX();
	var centerY=popomap.getCenterY();
	var mapWidth=popomap.getMapWidth();
	var mapHeight=popomap.getMapHeight();
	var zz=Math.pow(2,popomap.getZoom()-1);
	var startX=centerX-Math.floor(mapWidth/2)*zz;
	var startY=centerY-Math.floor(mapHeight/2)*zz;
	var endX=startX+mapWidth*zz;
	var endY=startY+mapHeight*zz;
	return {centerX:centerX,centerY:centerY,mapWidth:mapWidth,mapHeight:mapHeight,startX:startX,startY:startY,endX:endX,endY:endY};
}
function getCoor(){
	var x=popomap.getAreaUnitInfo().x;
	var y=popomap.getAreaUnitInfo().y;
	x=Math.floor(x/2);
	y=Math.floor(y/2);
	return {x:x,y:y};
}
function getEUInfo(){
	var x=popomap.getAreaUnitInfo().x;
	var y=popomap.getAreaUnitInfo().y;
	var areaId=popomap.getAreaUnitInfo().AreaID;
	var areaName=popomap.getAreaUnitInfo().AreaName;
	var unitId=popomap.getAreaUnitInfo().UnitId;
	var unitName=popomap.getAreaUnitInfo().UnitName;
	var id=0;
	var name='';
	var flag=0;
	if(areaId){
		id=areaId;
		name=areaName;
	}
	else{
		id=unitId;
		name=unitName;
		flag=1;
	}
	return {id:id,name:name,x:x,y:y,flag:flag};
}
function getMapId(){
	return map;
}
function go2xy(x,y){
	popomap.go2xy(x,y);
}
function go2xyS(x,y){
	popomap.go2xyS(x,y);
}
function selectMode(mode){
	popomap.selectMode(mode);
}
function showUserPop(arr){
	popomap.addUserPop(arr);
}
function cleanUserPop(){
	popomap.addUserPop();
}
function cleanActionSet(){
	actionSet='';
	popomap.setMapTip();
}
function loadXY(){
	var str=(document.location.href).split('?');
	var xy=str[1],x=0,y=0;
	if(xy){
		xy=xy.split(',');
		if(xy[0]&&xy[1]){
			x=parseInt(xy[0]);
			y=parseInt(xy[1]);
			switchNavView(0);
		}
	}
	popomap.init(x,y,true);
	popomap.createPop('popAnchor','<img src="/images/flag.gif">',x,y,0,17,5);
}
var isDoMapInit=false;
function mapInit(times){
	if(!times) times=0;
	times++;
	if(times>100) return;
	if(isDoMapInit) return;
	var str=(document.location.href).split('?');
	var xy=str[1],x=0,y=0;
	if(xy){
		xy=xy.split(',');
		if(xy[0]&&xy[1]){
			x=parseInt(xy[0]);
			y=parseInt(xy[1]);
		}
	}
	if(typeof(x)!='number'||typeof(y)!='number'||x==0||y==0){
		//alert(typeof(x));
		return;
	}
	else {
		switchNavView();switchMapView();
	}
	try{
		popomap.init(x,y);
		popomap.createPop('popAnchor','<img src="/images/flag.gif">',x,y,0,17,5);
	}
	catch(e){
		var fun='mapInit('+times+')';
		window.setTimeout(fun,500);
	}
}

function removePop_All(){
	popomap.removePop('addNote');
	popomap.removePop('addErr');
	popomap.removePop('addPost');
	popomap.removePop('showPost');
	popomap.removePop('showNote');
	return false;
}
function addNoteOpen(){
	actionSet='addNote';
	popomap.setMapTip('<img src="images/map/rightTip.gif">');
	popomap.selectMode(0);
}
function addNote(x,y){
	var sx=150*Math.pow(2,popomap.getZoom()-1);
	var htmlStr=popSet['addNote'];
	if(!x)x=popSet['X'];
	if(!y)y=popSet['Y'];
	htmlStr=htmlStr.replace('{$X}',x);
	htmlStr=htmlStr.replace('{$Y}',y);
	htmlStr=htmlStr.replace('{$MAP}',map);
	htmlStr=htmlStr.replace('{$LOCALE}',o_locale);
	removePop_addNote();
	popomap.go2xyS(parseInt(x)+sx,y,null,createPop_addNote);
	function createPop_addNote(){
		cleanActionSet();
		popomap.createPop('addNote',htmlStr,x,y,0,103,5);
	}
}
function removePop_addNote(){
	popomap.removePop('addNote');
	return false;
}
function addErrOpen(){
	actionSet='addErr';
	popomap.setMapTip('<img src="images/map/rightTip.gif">');
	popomap.selectMode(0);
}
function addErr(x,y){
	if(!x||!y) {
		x=popomap.getAreaUnitInfo().x;
		y=popomap.getAreaUnitInfo().y;
	}
	var sx=150*Math.pow(2,popomap.getZoom()-1);
	var htmlStr=popSet['addErr'];
	if(!x)x=popSet['X'];
	if(!y)y=popSet['Y'];
	htmlStr=htmlStr.replace('{$X}',x);
	htmlStr=htmlStr.replace('{$Y}',y);
	htmlStr=htmlStr.replace('{$MAP}',map);
	htmlStr=htmlStr.replace('{$LOCALE}',o_locale);
	popomap.setMapTip();
	removePop_addErr();
	popomap.go2xyS(parseInt(x)+sx,y,null,createPop_addErr);
	function createPop_addErr(){
		cleanActionSet();
		popomap.createPop('addErr',htmlStr,x,y,0,118,5);
	}
}
function removePop_addErr(){
	popomap.removePop('addErr');
	return false;
}
function addPostOpen(){
	actionSet='addPost';
	popomap.setMapTip('<img src="images/map/rightTip.gif">');
}
function addPost(x,y){
	var sx=200*Math.pow(2,popomap.getZoom()-1);
	var htmlStr=popSet['addPost'];
	if(!x)x=popSet['X'];
	if(!y)y=popSet['Y'];
	htmlStr=htmlStr.replace('{$X}',x);
	htmlStr=htmlStr.replace('{$Y}',y);
	htmlStr=htmlStr.replace('{$ID}',boardid);
	htmlStr=htmlStr.replace('{$LOCALE}',o_locale);
	removePop_addPost();
	popomap.go2xyS(parseInt(x)+sx,y,null,createPop_addPost);
	function createPop_addPost(){
		cleanActionSet();
		popomap.createPop('addPost',htmlStr,x,y,0,145,5);
	}
}
function removePop_addPost(flag){
	popomap.removePop('addPost');
	if(flag) changenews();
	return false;
}
function showPost(id,x,y,times){
	if(!times) times=0;
	isDoMapInit=true;
	times++;
	if(times>100) return;
	try{
		var sx=200*Math.pow(2,popomap.getZoom()-1);
		htmlStr=popSet['showPost'];
		htmlStr=htmlStr.replace('{$ID}',id);
		removePop_showPost();
		popomap.go2xy(x+sx,y);
		createPop_showPost();
	}
	catch(e){
		var fun='showPost('+id+','+x+','+y+','+times+')';
		window.setTimeout(fun,500);
	}

	function createPop_showPost(){
		popomap.createPop('showPost',htmlStr,x,y,0,145,5);
		mapInit();
	}
}
function removePop_showPost(){
	popomap.removePop('showPost');
	return false;
}
function showNote(id,x,y,times){
	if(!times) times=0;
	isDoMapInit=true;
	times++;
	if(times>100) return;
	if(popomap.getMapStatus()){
		var url='/resource/js/assistant/'+Math.floor(id/1000)+'/'+id+localeExt+'.js';
		postData(url,null,parseData);
	}
	else{
		var fun='showNote('+id+',0,0,'+times+')';
		window.setTimeout(fun,100);
	}

	function parseData(value){
		try{
			if(value){
				var o=eval('('+value+')');
				x=o.x;
				y=o.y;
			}
			else{
				popomap.init(x,y,true);
				return;
			}
		}
		catch(e){
			popomap.init(x,y,true);
			return;
		}
		switchNavView(0);
		htmlStr=popSet['showNote'];
		htmlStr=htmlStr.replace('{$ID}',id);
		htmlStr=htmlStr.replace('{$LOCALE}',o_locale);
		removePop_showNote();
		createPop_showNote();
	}

	function createPop_showNote(){
		if(!x||!y)	return;
		var sx=150*Math.pow(2,popomap.getZoom()-1);
		popomap.go2xy(x+sx,y);
		popomap.createPop('showNote',htmlStr,x,y,0,103,5);
		popomap.init(x+sx,y);
	}
}
function removePop_showNote(){
	popomap.removePop('showNote');
	return false;
}
function showPop(x,y,content,times){
	if(!times) times=0;
	times++;
	if(times>100) return;
	if(!x||!y) return;
	try{
		var sy=35*Math.pow(2,popomap.getZoom()-1);
		var htmlStr='<div style="border: 1px solid #209FE2;background-color:#59D2FF;padding:3px;font-size:12px;" nowrap>'+content+'</div><img src="images/map/point.gif" width="17px" height="17px">';
		if(getNavStatus()) {switchNavView(0);switchMapView(1);popomap.init(x,y);}
		popomap.removePop('tempPop');
		popomap.go2xy(x,y);
		popomap.createPopT('tempPop',htmlStr,x,y-sy,0,0,5);
	}
	catch(e){
		var fun='showPop('+x+','+y+',\''+content+'\''+times+')';
		window.setTimeout(fun,100);
	}
}
function showStation(id,x,y,name,times){
	if(!times) times=0;
	times++;
	if(times>100) return;
	if(!x||!y) return;
	try{
		if(getNavStatus()) {switchNavView(0);switchMapView(1);popomap.init(x,y);}
		popomap.removePop('lineSt2');
		popomap.go2xy(x,y);
		var obj={id:id,x:x,y:y,name:name,type:'bs_2'};
		popomap.createUserPop(obj,{global:true,display:true,idStr:'lineSt2'});
	}
	catch(e){
		var fun='showStation('+id+','+x+','+y+',\''+name+'\''+times+')';
		window.setTimeout(fun,100);
	}
}
function showResult(id,type,times){
	if(!times) times=0;
	times++;
	if(times>100) return;

	var url='';
	if(type==1)
		url='/resource/js/entity/'+map+'/'+Math.floor(id/1000)+'/'+id+'.js';
	else 
		url='/resource/js/unit/'+map+'/'+Math.floor(id/1000)+'/'+id+'.js';
	if(popomap.getMapStatus()){
		postData(url,null,parsexml);
	}
	else{
		var fun='showResult('+id+','+type+','+times+')';
		window.setTimeout(fun,100);
	}


	function parsexml(value){
		var x=0,y=0;
		try{
			if(value){
				var o=eval('('+value+')');
				x=o.x;
				y=o.y;
			}
			else{
				popomap.init(x,y,true);
				return;
			}
		}
		catch(e){
			popomap.init(x,y,true);
			return;
		}
		//popomap.go2xy(x,y);
		var noSlowF=false;
		if(getNavStatus()) {switchNavView(0);switchMapView(1);popomap.init(x,y);noSlowF=true;}
		if(type==1)
			popomap.showOCInfo(x,y,id,0,false,noSlowF);
		else 
			popomap.showOCInfo(x,y,0,id,true,noSlowF);
	}
}
function showResult2(id,x,y,type,name){
	//alert(id+','+x+','+y+','+type+','+name);
	if(getNavStatus()) {switchNavView(0);switchMapView(1);popomap.init(x,y);noSlowF=true;}
	if(type==1)
		popomap.showOCInfo(x,y,id,0,false,false);
	else if(type==2)
		popomap.showOCInfo(x,y,0,id,true,false);
	else
		showPop(x,y,name);
}
function showInfo(id,x,y,type,subtype,times){
	if(!times) times=0;
	isDoMapInit=true;
	times++;
	if(times>100) return;
	try{
		if(getNavStatus()) {switchNavView(0);popomap.init(x,y);}
		var url='http://'+infoDomain+'/{@TYPE}/index.jspa?_flowId=view&type={@TYPE}&typeid={@SUBTYPE}&id={@ID}&locale={$LOCALE}';
		var sx=180*Math.pow(2,popomap.getZoom()-1);
		var sy=20*Math.pow(2,popomap.getZoom()-1);
		htmlStr=popSet['showInfo'];
		if(!x||!y){
			htmlStr=popSet['showInfo1'];
			x=popomap.getCenterX()-sx;
			y=popomap.getCenterY()+sy;
		}		
		url=url.replace('{@ID}',id);
		url=url.replace('{$LOCALE}',o_locale);
		url=url.replace(/{@TYPE}/g,type);
		url=url.replace(/{@SUBTYPE}/g,subtype);
		htmlStr=htmlStr.replace(/#{url}/,url);
		removePop_showInfo();
		popomap.go2xy(parseInt(x)+sx,parseInt(y)-sy);
		createPop_showInfo();
	}
	catch(e){
		var fun='showInfo('+id+','+x+','+y+','+times+')';
		window.setTimeout(fun,500);
	}

	function createPop_showInfo(){
		popomap.createPop('showInfo',htmlStr,x,y,-55,165,5);
		mapInit();
	}
}
function removePop_showInfo(){
	popomap.removePop('showInfo');
	return false;
}
function showJm(x,y,id,type){
	var url='';
	if(type==1){
		url='/hall.jspa?_flowId=view&id='+id;
	}
	else{
		url='/basesite.jspa?_flowId=view&id='+id;
	}
	var sx=180*Math.pow(2,popomap.getZoom()-1);
	var sy=20*Math.pow(2,popomap.getZoom()-1);
	var htmlStr=popSet['jm'];
	htmlStr=htmlStr.replace('!{url}',url);
	popomap.removePop('pop_jm');
	popomap.go2xyS(parseInt(x)+sx,parseInt(y)-sy);
	popomap.createPop('pop_jm',htmlStr,x,y,-55,165,7);
}
function showJmIcon(data){
	if(data.length==0) return;
	showUserPop(data);

	var typeId={jm:1,jm2:2};
	var first=data[0];
	var id=first.id;
	var x=first.x;
	var y=first.y;
	var t=first.type.split('_')[0];
	var type=typeId[t];
	popomap.go2xy(x,y);
	//showJm(x,y,id,type);
}
function getPosXYOpen(){
	actionSet='getPosXY';
	national.showMsg('%{MousePointInfo:点右键获取地址}');
	popomap.setMapTip('<span style="color:red;font-size:12px;">'+national.getStr('Prompt','MousePointInfo','点右键获取地址')+'</span>');
}
function getPosXY(){
	ifrRight.document.forms[0].x.value=popSet['X'];
	ifrRight.document.forms[0].y.value=popSet['Y'];
	cleanActionSet();
}
function getPtInfoOpen(){
	isEntity=false;
	actionSet='getPtInfo';
	national.showMsg('%{MousePointInfo:点右键获取地址}');
	popomap.setMapTip('<span style="color:red;font-size:12px;">'+national.getStr('Prompt','MousePointInfo','点右键获取地址')+'</span>');
}
function getPtInfo(){
	if(confirm(national.getStr('Prompt','DoSetPoint','您确定设置该点吗')+'？')){
		var x=Math.floor(popSet['X']/2);
		var y=Math.floor(popSet['Y']/2);
		var id='';
		var name='';
		if(isEntity){
			id=popomap.getAreaUnitInfo().AreaID;
			name=popomap.getAreaUnitInfo().AreaName;
		}
		ifrRight.document.forms[0].centerX.value=x;
		ifrRight.document.forms[0].centerY.value=y;
		ifrRight.document.forms[0].entity.value=id;
		ifrRight.document.forms[0].entityName.value=name;
		actionSet='';
		popomap.setMapTip();
	}
}
function gotoTarget(x,y,id,cid){
	//popomap.removePop('his');
	//popomap.go2xyS(x,y,null,null);
	//popomap.createPopT('his',name,x,y,0,0,5);
	popomap.showOCInfo(x,y,id,cid,true);
}
function around(flag,type,disFlag){
	changePanel(2);
	var url='/newmap/yp.jspa?_flowId=around';
	if(flag=='2') url='/newmap/info.jspa?_flowId=around';
	var range='500';
	if(disFlag) range='1000';
	var x=Math.floor(popomap.getAreaUnitInfo().x/2);
	var y=Math.floor(popomap.getAreaUnitInfo().y/2);
	var params='&map='+map+'&range='+range+'&x='+x+'&y='+y+'&type='+type+'&locale='+o_locale;
	url+=params;
	rightOpen(url);
}
function unitjoin(){
	var o=popomap.getAreaUnitInfo();
	rightOpen('newmap/yp.jspa?_flowId=joinbyentity&entity='+o.AreaID+'&entityName='+encodeURIComponent(o.AreaName)+'&centerX='+Math.floor(o.x/2)+'&centerY='+Math.floor(o.y/2)+'&map='+map+'&city='+city+'&locale='+o_locale);
}
function unitjoin2(){
	rightOpen('newmap/yp.jspa?_flowId=join&map='+map+'&city='+city+'&locale='+o_locale);
}
function howArrive(value){
	//$('divArrive').style.display='';
	var id=0;
	if(popomap.getAreaUnitInfo().UnitID)
		id=popomap.getAreaUnitInfo().UnitID;
	else
		id=popomap.getAreaUnitInfo().AreaID;
	document.forms['arrive'].to.value=id;
	document.forms['arrive'].from.value=value;
	doArrive(document.forms['arrive']);
}
function doArrive(form){
	if (isEmpty(form.from.value)){
   	   national.showMsg('%{EmptyFrom:起始不能为空}');
	   //form.from.focus();
       return false;
	}else{
		form.action = '/newmap/busline.jspa';
		form.target = 'ifrRight';
	}
	if(setMapValue(form)) {
		changePanel(2);
		setPanel2Style();
		form.submit();
	}
}
function remove_howArrive(){
	$('divArrive').style.display='none';
}
var upFlag=null;
function setSmartOpen(type){
	if(upFlag!=null){
		national.showMsg('%{ActionHalt:前面的操作未完成}');
		return false;
	}
	actionSet='setSmart';
	if(type=='from'){
		upFlag=0;
	}
	else if(type=='to'){
		upFlag=1;
	}
	return true;
}
function setSmartClose(type){
	actionSet='';
	if(type=='from'){
		popomap.removePop('setSmartStart');
	}
	else if(type=='to'){
		popomap.removePop('setSmartEnd');
	}
	else{
		popomap.removePop('setSmartStart');
		popomap.removePop('setSmartEnd');
	}
	upFlag=null;
}
function setSmart(){
	actionSet='';
	var x=popSet['X'];
	var y=popSet['Y'];
	var coor=Math.floor(x/2)+','+Math.floor(y/2);
	//popomap.invokeFun('findStation',x,y,fun);
	if(upFlag==0){
		var htmlStr='<div style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=images/map/start.png);width:63px;height:41px"></div>';
		if(window.brw!='ie') htmlStr='<img src="images/map/start.png" width=63 height=41 border=0>';
		popomap.removePop('setSmartStart');
		popomap.createPop('setSmartStart',htmlStr,x,y,20,41,5);
		ifrRight.setFromPos(coor);
		upFlag=null;
	}
	else if(upFlag==1){
		var htmlStr='<div style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=images/map/end.png);width:63px;height:41px"></div>';
		if(window.brw!='ie') htmlStr='<img src="images/map/end.png" width=63 height=41 border=0>';
		popomap.removePop('setSmartEnd');
		popomap.createPop('setSmartEnd',htmlStr,x,y,20,41,5);
		ifrRight.setToPos(coor);
		upFlag=null;
	}
	function fun(value){
		if(!value){
			alert('附近没有找到公交车站,请重新设置');
		}
	}
}
var hisTotal=0;
var posx=0,posy=0;
function createHistory(aid,uid,x,y,name){
	var parNode=$('tdHistory');
	var children=parNode.getElementsByTagName('a');
	for(var i=0;i<children.length;i++){
		if(children[i].style._aid==aid&&children[i].style._uid==uid)
			return;
	}
	var a=document.createElement('a');
	var b=document.createElement('br');
	a.style._aid=aid;
	a.style._uid=uid;
	a.className='b1';
	a.href='javascript:gotoTarget('+x+','+y+','+aid+','+uid+')';
	a.innerHTML=name;
	parNode.insertBefore(b,parNode.firstChild);
	parNode.insertBefore(a,parNode.firstChild);
}
function drawRoadLine(id){
	switchNavView(0);
	cleanLine();
	$('divMapClear').style.display='';
	var url='/resource/js/simplelabel/'+map+'/'+Math.floor(id/1000)+'/'+id+'.js';
	var line=eval('('+postData(url)+')');
	var xs=line.xs;
	var ys=line.ys;
	var x=xs.split(',')[0];
	var y=ys.split(',')[0];
	var o={id:id,x:x,y:y,xs:xs,ys:ys,strokeweight:5,autoZoom:true};
	popomap.go2xyS(x,y);
	popomap.drawLine(o);
}
function getBusLine(id){
	var url='/resource/js/busline/'+map+'/'+id+localeExt+'.js';
	var line=eval('('+postData(url)+')');
	var xs=line.xs;
	var ys=line.ys;
	var stations=line.stations;
	/*var xx=xs.split(';');
	var yy=ys.split(';');
	var upx=xx[0].split(',');
	var upy=yy[0].split(',');
	var x=upx[0];
	var y=upy[0];
	var downx=[];
	var downy=[];
	var downxArr=[];
	var downyArr=[];
	if(xx.length>1){
		for(var i=1;i<xx.length;i++){
			downxArr[i-1]=xx[i].split(',');
			downyArr[i-1]=yy[i].split(',');
		}
		var downArri=0;
		var flag=false;
		for(var i=upx.length-1;i>=0;i--){
			if(!flag){
				if(Math.abs(downxArr[downArri][0]-upx[i])<=2){
					flag=true;
				}
				downx[downx.length]=upx[i];
				downy[downy.length]=upy[i];
			}
			else{
				var arr1=downxArr[downArri];
				var arr2=downyArr[downArri];
				if(Math.abs(arr1[arr1.length-1]-upx[i])<=2){
					for(var j=1;j<arr1.length;j++){
						downx[downx.length]=arr1[j];
						downy[downy.length]=arr2[j];
					}
					flag=false;
					downArri++;
					if(downArri==downxArr.length) break;
					//if(Math.abs(downxArr[downArri][0]-upx[i])<=2){
						//i++;
					//}
				}
			}
		}
	}
	else{
		for(var i=upx.length-1;i>=0;i--){
			downx[downx.length]=upx[i];
			downy[downy.length]=upy[i];
		}
	}*/

	var up_tmp=[];
	var down_tmp=[];
	for(var i=0;i<stations.length;i++){
		if(stations[i].state==0){
			up_tmp[up_tmp.length]=stations[i];
			down_tmp[down_tmp.length]=stations[i];
		}
		else if(stations[i].state==1){
			up_tmp[up_tmp.length]=stations[i];
		}
		else if(stations[i].state==-1){
			down_tmp[down_tmp.length]=stations[i];
		}
	}
	var half=Math.floor(down_tmp.length/2);
	var length=down_tmp.length;
	for(var i=0;i<half;i++){
		var a=down_tmp[i];
		down_tmp[i]=down_tmp[length-1-i];
		down_tmp[length-1-i]=a;
	}

	var xx=xs.split(';');
	var yy=ys.split(';');
	var upx=xx[0].split(',');
	var upy=yy[0].split(',');
	var downx;
	var downy;
	if(xx.length>1){
		downx=xx[1].split(',');
		downy=yy[1].split(',');
		for(var i=upx.length-1;i>=0;i--){
			if(upx[i]==downx[downx.length-1]){
				var xt=upx.slice(0,i).reverse();
				var yt=upy.slice(0,i).reverse();
				downx=downx.concat(xt);
				downy=downy.concat(yt);
			}
		}
	}
	else{
		downx=xx[0].split(',').reverse();
		downy=yy[0].split(',').reverse();
	}

	var up=[];
	var down=[];
	var ids=[];
	if(true){
		var upi=0;
		for(var i=0;i<upx.length;i++){
			if(up_tmp.length&&Math.abs(up_tmp[upi].x-upx[i])<=2&&Math.abs(up_tmp[upi].y-upy[i])<=2){
				up.push(up_tmp[upi]);
				ids[up_tmp[upi].id]=1;
				if(upi==up_tmp.length-1){
					//upMax=i;
					break;
				}
				upi++;
			}
			else{
				up.push({x:upx[i],y:upy[i]});
			}
		}
		var downi=0;
		for(var i=0;i<downx.length;i++){
			if(down_tmp.length&&down_tmp[downi]&&Math.abs(down_tmp[downi].x-downx[i])<=2&&Math.abs(down_tmp[downi].y-downy[i])<=2){
				down.push(down_tmp[downi]);
				if(ids[down_tmp[downi].id]){
					ids[down_tmp[downi].id]+=2;
				}
				else{
					ids[down_tmp[downi].id]=2;
				}
				downi++;
			}
			else{
				down.push({x:downx[i],y:downy[i]});
			}
		}
	}
	line.upStations=up_tmp;
	line.downStations=down_tmp;
	line.up=up;
	line.down=down;
	return line;
}
function getLine(blid1,blid2,id1,id2,id3){
	var line1=null;
	var line2=null;
	var bl1=null;
	var bl2=null;
	if(blid1&&id1&&id2){
		line1=getBusLine(blid1);
		var stations=line1.stations;
		for(var i=0;i<stations.length;i++){
			if(stations[i].id==id1){
				bl1=line1.up;
				break;
			}
			if(stations[i].id==id2){
				bl1=line1.down;
				break;
			}
		}
	}
	if(blid2&&id3){
		line2=getBusLine(blid2);
		var stations=line2.stations;
		for(var i=0;i<stations.length;i++){
			if(stations[i].id==id2){
				bl2=line2.up;
				break;
			}
			if(stations[i].id==id3){
				bl2=line2.down;
				break;
			}
		}
	}
	var line=[];
	var flag=false;
	var len2=0;
	if(bl1){
		for(var i=0;i<bl1.length;i++){
			if(bl1[i].id&&bl1[i].id==id1)flag=true;
			if(flag){
				line.push(bl1[i]);
			}
			if(bl1[i].id&&bl1[i].id==id2){
				flag=false;
				break;
			}			
		}
	}
	if(bl2){
		for(var i=0;i<bl2.length;i++){
			if(flag){
				line.push(bl2[i]);
				len2++;
			}
			if(bl2[i].id&&bl2[i].id==id2)flag=true;			
			if(bl2[i].id&&bl2[i].id==id3){
				flag=false;
				break;
			}
		}
	}
	if(blid1&&!bl1&&!bl2){
		line1=getBusLine(blid1);
		line=line1.up;
	}
	return {line:line,len2:len2};
}
function drawBusLine(blid1,blid2,id1,id2,id3){
	switchNavView(0);
	cleanLine();
	$('divMapClear').style.display='';
	//var line=getLine(50040,50041,570,387,676);
	var result=getLine(blid1,blid2,id1,id2,id3);
	var line=result.line;
	var len2=result.len2;
	var x=line[0].x;
	var y=line[0].y;
	xs=x;
	ys=y;
	for(var i=1;i<line.length-len2;i++){
		xs+=','+line[i].x;
		ys+=','+line[i].y;
		//alert(line[i].x+','+line[i].y);
	}
	popomap.zoomto(4);
	popomap.go2xy(x,y);
	var o={id:0,x:x,y:y,xs:xs,ys:ys,autoZoom:true,strokecolor:'#00FF00',strokeweight:3,endarrow:'block'};
	if(brw=='ie')popomap.drawLine(o);
	xs=line[0].x+','+line[1].x;
	ys=line[0].y+','+line[1].y;
	o={id:2,x:x,y:y,xs:xs,ys:ys,autoZoom:true,strokecolor:'#00FF00',strokeweight:3,endarrow:'block'};
	if(brw=='ie')popomap.drawLine(o);
	if(len2){
		var x2=line[line.length-len2-1].x;
		var y2=line[line.length-len2-1].y;
		var xs2=x2;
		var ys2=y2;
		for(var i=line.length-len2;i<line.length;i++){
			xs2+=','+line[i].x;
			ys2+=','+line[i].y;
			//alert(line[i].x+','+line[i].y);
		}
		var o={id:3,x:x2,y:y2,xs:xs2,ys:ys2,autoZoom:true,strokecolor:'#0000FF',strokeweight:3,endarrow:'block'};
		if(brw=='ie')popomap.drawLine(o);
	}
	for(var i=0;i<line.length;i++){
		//var htmlStr='<img src="http://api.o.cn/images/bus.gif" id="bus'+stations[i].id+'" title="'+stations[i].name+'" style="cursor:pointer">';
		if(!line[i].id) continue;
		var htmlStr='<div style="border: 1px solid #209FE2;background-color:#59D2FF;padding:3px;font-size:12px;" nowrap>'+line[i].name+'</div><img src="images/map/point.gif" width="17px" height="17px">';
		if(id3&&line[i].id==id2){
			var htmlStr='<div style="border: 1px solid #209FE2;background-color:red;padding:3px;font-size:12px;" nowrap>'+line[i].name+'</div><img src="images/map/point.gif" width="17px" height="17px">';
		}
		//idlist[idlist.length]=popomap.createPop('busStation'+line[i].id,htmlStr,line[i].x,line[i].y,0,35,5);
		line[i].type='bs_1';
		idlist[idlist.length]=popomap.createUserPop(line[i],{global:true,display:true,idStr:'lineSt'+line[i].id});
	}
}
function mapClear(){
	setSmartClose();
	cleanLine();
	cleanUserPop();
}
function cleanLine(){
	popomap.destroyAllG();
	for(var i=0;i<idlist.length;i++){
		var id=idlist[i];
		popomap.removePop(id);
	}
	idlist=[];
	//setSmartClose();
	$('divMapClear').style.display='none';
}
function drag(obj,src){
	src.onmousedown=function(evt){
		if(!evt) evt=window.event;
		var d=document;
		var x=evt.clientX-obj.offsetLeft;
		var y=evt.clientY-obj.offsetTop;
		obj.setCapture();
		
		d.onmousemove=function(evt){
			if(!evt) evt=window.event;
			obj.style.left=evt.clientX-x;
			obj.style.top=evt.clientY-y;
		};

		d.onmouseup=function(evt){
			if(!evt) evt=window.event;
			obj.releaseCapture();
			d.onmousemove=null;
			d.onmouseup=null;
		};
	}
}
function loadXML(url,fun)
{
	var xmlDoc;
	if (window.ActiveXObject){
		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.async=false;
		xmlDoc.load(url);
		doxml();
	}
	else if (document.implementation &&document.implementation.createDocument){
		xmlDoc= document.implementation.createDocument("","",null);
		try{
			xmlDoc.load(url);
			xmlDoc.onload=doxml;
		}
		catch(e){}
	}
	else{
		alert('load xml error!');
	}

	function doxml(){
		if(xmlDoc.documentElement)fun(xmlDoc.documentElement);
		xmlDoc=null;
		delete xmlDoc;
	}
}
function checkBrowse(){
	if(!window.XMLHttpRequest){
		window.XMLHttpRequest=function(){
			var xmlHttp=null;
			var progids=['Microsoft.XMLHTTP', 'MSXML2.XMLHTTP.5.0', 'MSXML2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP'];
			for(var i=0;i<progids.length;i++){
				try{
					xmlHttp=new ActiveXObject(progids[i]);
					break;
				}
				catch(e){}
			}
			if(xmlHttp==null){
				//alert('无法创建对象');
			}
			return xmlHttp;
		};
	}
}
function postData(url,postValue,fun,method,async){
	var xmlObj = null;
	if(window.XMLHttpRequest){
		xmlObj = new XMLHttpRequest();
	}
	else {
		return;
	}
	method=method=='POST'?'POST':'GET';
	async=false;
	if(typeof(fun)=='function')async=true;
	if(async) xmlObj.onreadystatechange = doData;
	xmlObj.open (method, url, async);
	if(method=='POST'){
		//xmlObj.setrequestheader("Content-Length",postValue.length);
		xmlObj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	}
	xmlObj.send (postValue);
	if(!async){
		return getData();
	}

	function getData(){
		if(xmlObj.getResponseHeader('Content-Type')=='text/xml')
			return xmlObj.responseXML;
		else
			return xmlObj.responseText;
	}

	function doData(){
		if(xmlObj.readyState!=4){
			return;
		}
		if(xmlObj.status==200){
			fun(getData());
			xmlObj.onreadystatechange=function(){};
			xmlObj.abort();
			xmlObj=null;
			delete xmlObj;
		}
		else{
			fun(null);
			xmlObj.onreadystatechange=function(){};
			xmlObj.abort();
			xmlObj=null;
			delete xmlObj;
		}
	}
}
checkBrowse();
waitMap();
//showNote(2,59530,39298);
//mapInit();
popSet['addNote']='<div class="window_shadow2"><div class="window_boder2" ><div style="position:absolute; margin-left:-56px; margin-top:65px; padding:0px;"><img src="images/xinxi/point.gif" width="55" height="39"></div><div class="window_boder_tt"><div class="window_boder_tt_left">'+national.getStr('Citymap','AddNote','添加便签')+'</div><div class="window_close"><img src="/images/map/close.gif" width="16" height="16" style="cursor:pointer;" onclick="mapApi.myCustomFun(null,\'removePop_addNote\')"></div></div><iframe id="ifSmallAddPost" style="WIDTH:200px;HEIGHT:130px" scrolling="no" frameborder="no" src="/newmap/assistant.jspa?_flowId=edit&map={$MAP}&x={$X}&y={$Y}&locale={$LOCALE}"></iframe></div></div>';
popSet['showNote']='<div class="window_shadow2"><div class="window_boder2" ><div style="position:absolute; margin-left:-56px; margin-top:65px; padding:0px;"><img src="images/xinxi/point.gif" width="55" height="39"></div><div class="window_boder_tt"><div class="window_boder_tt_left">'+national.getStr('Citymap','Note','便签')+'</div><div class="window_close"><img src="/images/map/close.gif" width="16" height="16" style="cursor:pointer;" onclick="mapApi.myCustomFun(null,\'removePop_showNote\')"></div></div><iframe id="ifSmallAddPost" style="WIDTH:200px;HEIGHT:130px" scrolling="no" frameborder="no" src="/newmap/assistant.jspa?_flowId=view&id={$ID}&locale={$LOCALE}"></iframe></div></div>';
popSet['addErr']='<div class="window_shadow2"><div class="window_boder2" ><div style="position:absolute; margin-left:-56px; margin-top:80px; padding:0px;"><img src="images/xinxi/point.gif" width="55" height="39"></div><div class="window_boder_tt"><div class="window_boder_tt_left">'+national.getStr('Citymap','Mistake','糾錯')+'</div><div class="window_close"><img src="/images/map/close.gif" width="16" height="16" style="cursor:pointer;" onclick="mapApi.myCustomFun(null,\'removePop_addErr\')"></div></div><iframe id="ifAddErr" style="WIDTH:210px;HEIGHT:160px" scrolling="no" frameborder="no" src="/newmap/mistake.jspa?_flowId=edit&map={$MAP}&x={$X}&y={$Y}&locale={$LOCALE}"></iframe></div></div>';
popSet['addPost']='<div style="width:469px;"><table width="100%" border="0" cellspacing="0" cellpadding="0">    <tr>      <td width="69" background="images/bbs_69x1.gif"  valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">        <tr>          <td height="110px">&nbsp;</td>        </tr>        <tr>          <td><img src="images/bbs_69x35.gif" width="69px" height="35px" /></td>        </tr>      </table></td>      <td style="border-top-width: 3px;border-right-width: 3px;border-bottom-width: 3px;border-top-style: solid;border-right-style: solid;border-bottom-style: solid;border-top-color: #CCCCCC;border-right-color: #CCCCCC;border-bottom-color: #CCCCCC;background-color: #FFFFFF;"><table width="100%" border="0" cellpadding="0" cellspacing="0">        <tr>          <td bgcolor="#F6F6F6" width="380px" style="font-size:12px"><b>&nbsp;发表猎闻</b></td>          <td width="20px" bgcolor="#F6F6F6"><img src="images/bbs_close.gif" style="cursor:pointer;" onclick="parent.removePop_addPost()"></td>        </tr>        <tr>          <td colspan="2"><iframe id="ifAddErr" style="WIDTH:400px;HEIGHT:250px" scrolling="yes" frameborder="no" src="/newmap/message.jspa?_flowId=edit&typeId={$ID}&x={$X}&y={$Y}&locale={$LOCALE}"></iframe></td>        </tr>      </table></td>    </tr>  </table></div>';
popSet['showPost']='<div style="width:410px;"><table width="100%" border="0" cellspacing="0" cellpadding="0">    <tr>      <td width="69" background="images/bbs_69x1.gif"  valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">        <tr>          <td height="110px">&nbsp;</td>        </tr>        <tr>          <td><img src="images/bbs_69x35.gif" width="69px" height="35px" /></td>        </tr>      </table></td>      <td style="border-top-width: 3px;border-right-width: 3px;border-bottom-width: 3px;border-top-style: solid;border-right-style: solid;border-bottom-style: solid;border-top-color: #CCCCCC;border-right-color: #CCCCCC;border-bottom-color: #CCCCCC;background-color: #FFFFFF;"><table width="100%" border="0" cellpadding="0" cellspacing="0">        <tr>          <td bgcolor="#F6F6F6" width="345px" style="font-size:12px"><b>&nbsp;猎闻</b></td>          <td width="20px" bgcolor="#F6F6F6"><img src="images/bbs_close.gif" style="cursor:pointer;" onclick="mapApi.myCustomFun(null,\'removePop_showPost\')"></td>        </tr>        <tr>          <td colspan="2"><iframe id="ifAddErr" style="WIDTH:360px;HEIGHT:250px" scrolling="yes" frameborder="no" src="/newmap/message.jspa?_flowId=view&id={$ID}&locale={$LOCALE}"></iframe></td>        </tr>      </table></td>    </tr>  </table></div>';
popSet['showInfo']='<div style="position:absolute;left:-67px;top:153px;"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="24px" height="24px">  <param name="movie" value="/images/flash/kkk.swf">  <param name="quality" value="high">  <param name="wmode" value="transparent">   <embed src="api/images/kkk.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="24px" height="24px"></embed></object></div><div style="position:absolute;left:-53px;top:129px;"><img src="images/map/point2.gif"></div><img border="0" style="position:absolute;left:310px;top:6px;cursor:pointer" src="/images/map/close.gif" onclick="mapApi.removePop(\'showInfo\')"><div id="Layer1">	<div style="background:#fff;padding:1 0 0 1;width:332;height:230;">	<div style="height:100%; width:100%; ">		<div style="background:#fff;height:100%; width:100%;">		  <iframe src="#{url}" height="100%" width="100%" frameborder="0" scrolling="no" ></iframe>		</div>	</div>	</div>	</div>';
popSet['showInfo1']='<div style="position:absolute;left:400px;top:10px;border: 1px solid #ff6600;color:ff6600;padding: 0 2;cursor:pointer;margin: 0 2 0 0;" onClick="mapApi.myCustomFun(null,\'removePop_showInfo\')"><span style="font-family: Verdana, Arial, Helvetica, sans-serif;	font-size: 9px;"><b>X</b></span></div><div id="Layer1">	<div style="background:#fff;border:1px solid #60B9F2;padding:1 0 0 1;width:420;height:300;">	<div style="height:100%; width:100%; background:#AFE0FD; padding:3px;">		<div style="background:#fff;height:100%; width:100%;">		  <iframe src="http://info.o.cn/mainview.jsp?type={$TYPE}&subtype={$SUBTYPE}&id={$ID}&locale={$LOCALE}" height="100%" width="100%" frameborder="0" scrolling="no" ></iframe>		</div>	</div>	</div>	<div></div>';
popSet['jm']='<div style="position:absolute;left:-67px;top:153px;"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="24px" height="24px">  <param name="movie" value="/images/flash/kkk.swf">  <param name="quality" value="high">  <param name="wmode" value="transparent">   <embed src="api/images/kkk.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="24px" height="24px"></embed></object></div><div style="position:absolute;left:-53px;top:129px;"><img src="/images/map/point2.gif"></div><img border="0" style="position:absolute;left:310px;top:6px;cursor:pointer" src="/images/map/close.gif" onclick="mapApi.removePop(\'pop_jm\')"><div id="Layer1">	<div style="background:#fff;padding:1 0 0 1;width:332;height:290;">	<div style="height:100%; width:100%; ">		<div style="background:#fff;height:100%; width:100%;"><iframe src="!{url}" height="100%" width="100%" frameborder="0" scrolling="no" ></iframe></div>	</div>	</div>	</div>';