var mapAction={action:'',argu:[]};
var htmls={};
var isComplete=false;

var ui={
	init:function(){
		this.topH=118;
		this.leftW=386;
		this.minW=960;
		this.allShow=true;
		this.leftShow=true;
		this.plMenuId='navBtn_1';
	},
	initSearchTip:function(){
		var LocalAddressTip=new AddressTip('LocalSearch',$g('searchDiv_1'),document.forms['localForm'].lot,23,55);
		LocalAddressTip.setData({hot:cityData.lot});
		LocalAddressTip.setClickEvent(LocalAddressTipClick);
		LocalAddressTip.renderContent();
		var LocalLabelTip=new LabelTip('LocalSearch',$g('searchDiv_1'),document.forms['localForm'].keyword,260,55);
		LocalLabelTip.setData({hot:(o_strlist['local_hotLabel']||'').split(',')});
		LocalLabelTip.renderContent();

		var InfoAddressTip=new AddressTip('InfoSearch',$g('searchDiv_2'),document.forms['infoForm'].lot,23,55);
		InfoAddressTip.setData({hot:cityData.lot});
		InfoAddressTip.setClickEvent(InfoAddressTipClick);
		InfoAddressTip.renderContent();
		var InfoLabelTip=new LabelTip('InfoSearch',$g('searchDiv_2'),document.forms['infoForm'].keyword,260,55);
		InfoLabelTip.setData({hot:(o_strlist['info_hotLabel']||'').split(',')});
		InfoLabelTip.renderContent();

		var ProductAddressTip=new AddressTip('ProductSearch',$g('searchDiv_3'),document.forms['productForm'].lot,23,55);
		ProductAddressTip.setData({hot:cityData.lot});
		ProductAddressTip.setClickEvent(ProductAddressTipClick);
		ProductAddressTip.renderContent();
		var ProductLabelTip=new LabelTip('ProductSearch',$g('searchDiv_3'),document.forms['productForm'].keyword,260,55);
		ProductLabelTip.setData({hot:(o_strlist['product_hotLabel']||'').split(',')});
		ProductLabelTip.renderContent();

		var TrafficFromAddressTip=new AddressTip('TrafficFrom',$g('jttab_1'),document.forms['trafficForm'].startName,23,55);
		var data={hot:cityData.lot};
		TrafficFromAddressTip.setData(data);
		TrafficFromAddressTip.setClickEvent(TrafficFromAddressTipClick);
		TrafficFromAddressTip.renderContent();
		var TrafficToAddressTip=new AddressTip('TrafficTo',$g('jttab_1'),document.forms['trafficForm'].endName,270,55);
		TrafficToAddressTip.setData(data);
		TrafficToAddressTip.setClickEvent(TrafficToAddressTipClick);
		TrafficToAddressTip.renderContent();

		this.LocalAddressTip=LocalAddressTip;
		this.LocalLabelTip=LocalLabelTip;
		this.InfoAddressTip=InfoAddressTip;
		this.InfoLabelTip=InfoLabelTip;
		this.ProductAddressTip=ProductAddressTip;
		this.ProductLabelTip=ProductLabelTip;
		this.TrafficFromAddressTip=TrafficFromAddressTip;
		this.TrafficToAddressTip=TrafficToAddressTip;
		$g('searchDiv_1_tip1').onclick=function(){
			LocalAddressTip.switchView();return false;
		};
		$g('searchDiv_1_tip2').onclick=function(){
			LocalLabelTip.switchView();return false;
		};
		$g('searchDiv_2_tip1').onclick=function(){
			InfoAddressTip.switchView();return false;
		};
		$g('searchDiv_2_tip2').onclick=function(){
			InfoLabelTip.switchView();return false;
		};
		$g('searchDiv_3_tip1').onclick=function(){
			ProductAddressTip.switchView();return false;
		};
		$g('searchDiv_3_tip2').onclick=function(){
			ProductLabelTip.switchView();return false;
		};
		$g('jttab_1_tip1').onclick=function(){
			TrafficFromAddressTip.switchView();return false;
		};
		$g('jttab_1_tip2').onclick=function(){
			TrafficToAddressTip.switchView();return false;
		};

		mapSearchTip=new SearchTip(document.forms['localForm'].keyword,'map/topSearch.shtml?act=map',10,mapKeywordClick);
		mapSearchTip.setDataHandler(tipDataHandler);
		infoSearchTip=new SearchTip(document.forms['infoForm'].keyword,'map/topSearch.shtml?act=info',10,infoKeywordClick);
		infoSearchTip.setDataHandler(tipDataHandler);
		productSearchTip=new SearchTip(document.forms['productForm'].keyword,'map/topSearch.shtml?act=product',10,productKeywordClick);
		productSearchTip.setDataHandler(tipDataHandler);
		trafficStartSearchTip=new SearchTip(document.forms['trafficForm'].startName,'map/topSearch.shtml?act=traffic',10,trafficStartKeywordClick);
		trafficStartSearchTip.setDataHandler(tipDataHandler);
		trafficEndSearchTip=new SearchTip(document.forms['trafficForm'].endName,'map/topSearch.shtml?act=traffic',10,trafficEndKeywordClick);
		trafficEndSearchTip.setDataHandler(tipDataHandler);
	},
	setTipState:function(types){
		var tips=['mapSearchTip','infoSearchTip','productSearchTip','trafficStartSearchTip','trafficEndSearchTip'];
		try{
			for(var i=0;i<tips.length;i++){
				var o=window[tips[i]];
				if(types.indexOf(tips[i])==-1){
					o.hidden();
				}
				else{
					o.setPos();
				}
			}
		}
		catch(e){
		}
	},
	menuClick:function(obj){
		var oldIndex=this.plMenuId.replace('navBtn_','');
		var oldObj=$g(this.plMenuId);
		var oldContent=$g('Mmenu_'+oldIndex);
		oldObj.className='';
		if(oldContent) oldContent.style.display='none';
		
		var index=obj.id.replace('navBtn_','');
		var content=$g('Mmenu_'+index);
		obj.className='sel';
		if(content) content.style.display='';
		
		this.plMenuId=obj.id;
		if(!this.leftShow)this.showLeft();
	},
	moreMenu:function(flag){
		if(flag) $g('moreNavi').style.display='';
		else $g('moreNavi').style.display='none';
	},
	changePanel:function(panel,subPanel,url){
		var panelBtn=$g('navBtn_'+panel);
		if(panelBtn){
			if(panelBtn.style.display='none')panelBtn.style.display='';
			this.menuClick(panelBtn);
			if(!url)url=panelBtn.href;
		}
		if(url) $g('leftIfr').src=url;
	},
	getCurrentPanelId:function(){
		var index=this.plMenuId.replace('btn','');
		if(index) return parseInt(index);
		else return null;
	},
	viewUserPanl:function(flag){
		//$g('btn8').style.display=flag?'':'none';
	},
	openTarget:function(url){
		$g('leftIfr').src=url;
	},
	showLeft:function(flag){
		if(!this.allshow){
			if(this.leftShow)$g('leftDiv').style.display='';
			$g('panelbtn').style.display='';
		}
		if(typeof(flag)!='undefined'&&flag==this.leftShow) return;
		if(!this.leftShow){
			$g('leftDiv').style.display='';
			$g('panelbtn').className='panelbtn_out';
			this.leftShow=true;
		}
		else{
			$g('leftDiv').style.display='none';
			$g('panelbtn').className='panelbtn_in';
			this.leftShow=false;
		}
		this.adjust_width();
		$g('panelbtn').style.left=(this.leftShow?this.leftW:0)+'px';
	},
	showFull:function(o){
		if(!o) o=MainMenu.getMenuItemById('fullScreen');
		if(!this.allShow){
			$g('top').style.display='';
			if(this.leftShow)$g('leftDiv').style.display='';
			$g('panelbtn').style.display='';
			this.allShow=true;
			o.setState(false);
			o.setName('全屏');
		}
		else{
			$g('top').style.display='none';
			$g('leftDiv').style.display='none';
			$g('panelbtn').style.display='none';
			this.allShow=false;
			o.setState(true);
			o.setName('返回');
		}
		this.adjust_height();
		this.adjust_width();
	},
	adjust_height:function(){
		var topH=this.topH;
		if(!this.allShow)topH=0;
		$g('MapCon').style.height=(this.bodyHeight-topH)+'px';
		$g('leftDiv').style.height=(this.bodyHeight-topH)+'px';
		$g('leftIfr').style.height=(this.bodyHeight-topH-2)+'px';
		$g('mapParentDiv').style.height=(this.bodyHeight-topH)+'px';
		$g('mapDiv').style.height=(this.bodyHeight-topH)+'px';
		//$g('panelbtn').style.top=Math.floor((this.bodyHeight-topH)/2)+'px';
		this.setMapHeight(this.bodyHeight-topH);
	},
	ajustNav:function(){
		var w=navUtils1.getWidth();
		var h=navUtils1.getHeight();
		var mapW=$g('mapParentDiv').offsetWidth;
		var mapH=$g('mapParentDiv').offsetHeight;
		$g('divMapNavContent').style.left=Math.floor((mapW-w)/2)+'px';
		$g('divMapNavContent').style.top=Math.floor((mapH-h)/2)+'px';
	},
	setMapHeight:function(h){
		try{
			omapApi.setHeight(h+'px');
			omapApi.getMap().mapApi.doc_resize();//temp
		}
		catch(e){}
	},
	adjust_width:function(){
		if(this.bodyWidth<this.minW) this.bodyWidth=this.minW;
		var leftW=this.leftW;
		if(!this.leftShow||!this.allShow) leftW=0;
		$g('header').style.width=this.bodyWidth+'px';
		$g('MapCon').style.width=this.bodyWidth+'px';
		$g('mapParentDiv').style.marginLeft=leftW+'px';
		$g('mapParentDiv').style.width=(this.bodyWidth-leftW)+'px';
		$g('mapDiv').style.width=(this.bodyWidth-leftW)+'px';
		$g('maptools').style.width=(this.bodyWidth-leftW)+'px';
	},
	resize:function(){
		this.bodyHeight=document.documentElement.clientHeight;
		this.adjust_height();
		
		this.bodyWidth=document.documentElement.clientWidth;
		this.adjust_width();
		this.ajustNav();
	},
	showCenter:function(obj,width,height){
		var target=null;
		if(typeof(obj)=='string') target=$g(obj);
		else if(typeof(obj)=='object') target=obj;
		if(!target) return;
		target.style.display='';
		var w=width || target.offsetWidth;
		var h=height || target.offsetHeight;
		var left=(this.bodyWidth-w)/2;
		var top=(this.bodyHeight-h)/2;
		target.style.left=left+'px';
		target.style.top=top+'px';
	}
};
function doc_resize(){
	ui.resize();
}
function doc_onload(){
	ui.init();
	ui.initSearchTip();
	ui.resize();//alert(ui.bodyHeight);alert($g('MapCon').style.height);
	mapLoader();
	setGame();

	idexMenu.getMain().render($g('menuDiv'));
	document.onmouseup=body_onmouseup;
	isComplete=true;
}
function body_onmouseup(){
	mapSearchTip.hidden();
	infoSearchTip.hidden();
	productSearchTip.hidden();
	trafficStartSearchTip.hidden();
	trafficEndSearchTip.hidden();
	tipTools.hiddenAll();
}
function doParams(){
	var params=utils.web.getRequestParameters();
	if(params.id){
		mapAction={action:'showResult',argu:[params.id,1]};
	}
	else if(params.cid){
		mapAction={action:'showResult',argu:[params.cid,2]};
	}
	else if(params.noteid){
		mapAction={action:'showNote',argu:[params.noteid]};
	}
	else if(params.right){
		mapAction={action:'doRight',argu:[params.right,params.unit,params.param1]};
	}
	else if(params.action){
		mapAction={action:'action',argu:[params.action,params.param1,params.param2,params.param3]};
	}
	//alert(mapAction.action+'|'+mapAction.argu);
}
function isBodyLoadedWithMessage(action){
	if(!isComplete) {
		alert('请在地图加载完以后再操作!');
		return false;
	}
	return true;
}
var gameUi={
	gameOnMin:function(){
		utils.html.swapImages(null,'gameNavBtn','images/version2/skin/mlmm.gif');
		this.gameIsMin=true;
	},
	gameOnMax:function(){
		this.gameIsMin=false;
		utils.html.swapImages(null,'gameNavBtn','images/version2/skin/mlbut1.gif');
	},
	gameOnClose:function(){
		this.gameIsOpen=false;
		this.gameIsMin=false;
		utils.html.swapImages(null,'gameNavBtn','images/version2/skin/mlbut1.gif');
		if(ui.isFullScren()) ui.fullScreen();
	},
	openGame:function(){
		if(!isBodyLoadedWithMessage()) return;
		//if(getNavStatus()) {switchNavView(0);}
		if(!this.gameIsOpen){
			this.gameIsOpen=true;
		}
		if(this.gameIsMin) gameLib.show();
		else{
			if(!Ogame_Contrl) Ogame_Contrl=new Ogame.Contrl();
			Ogame_Contrl.Ogame_show(true);
			utils.html.swapImages(null,'gameNavBtn','images/version2/skin/mlbut1.gif');
		}
		//if(!ui.isFullScren()) ui.fullScreen();
	},
	closeGame:function(){
		if(!this.gameIsOpen) return;
		gameLib.preClose(true);
	},
	over3:function(){
		if(this.gameIsOpen) return;
		utils.html.swapImages(null,'gameNavBtn','images/version2/skin/mlbut2.gif');
	},
	out3:function(){
		if(this.gameIsOpen) return;
		utils.html.swapImages(null,'gameNavBtn','images/version2/skin/mlbut1.gif');
	}
}
function enterGameRoom(){
	var entityId=omapApi.getAreaUnitInfo().AreaID;
	var url=OgameSite+'/portal/project.html?id='+entityId+'&host='+document.domain;
	ui.openTarget(url);
}
function setGame(){
	if(!gameMap[mapConfig.domain]) return;
	try{
		gameLib.addEvent('onMin',gameUi.gameOnMin.bind(navUtils));
		gameLib.addEvent('onClose',gameUi.gameOnClose.bind(navUtils));
		gameLib.addEvent('onMax',gameUi.gameOnMax.bind(navUtils));
	}
	catch(e){
	}
	$g('gameNav').style.display='';
	$g('navBtn_5').style.display='';
	$g('navBtn_5').href=OgameSite+'/portal/sidebar.html?host='+document.domain+'&map='+map;
}
doParams();
window.onload=doc_onload;
window.onresize=doc_resize;

var htmlManager=new utils.HtmlManager('/js/htmls');
var staticHtmlManager=new utils.HtmlManager('http://'+domain_config.static+'/js/htmls');

//url处理开始---------------------------
var paramMap={};
paramMap['map']=mapConfig.mapid;
paramMap['info_domain']=infoDomain;
var urlMap={};
urlMap['addNote']='member/note.shtml?_flowId=mine-edit&map=!{map}&x=!{x}&y=!{y}';
urlMap['addError']='/newmap/mistake.shtml?_flowId=edit&map=!{map}&x=!{x}&y=!{y}&locale=!{locale}';
urlMap['showNote']='/newmap/note.shtml?_flowId=view-ui&noteid=!{id}&type=!{type}';
urlMap['downMap']='/map/mappic.shtml?act=savefile&mapType=!{mapType}&mapLevel=!{mapLevel}&startX=!{startX}&startY=!{startY}&endX=!{endX}&endY=!{endY}';
urlMap['viewMap']='/map/mappic.shtml?mapType=!{mapType}&mapLevel=!{mapLevel}&startX=!{startX}&startY=!{startY}&endX=!{endX}&endY=!{endY}';
urlMap['printMap']='/page/common/printMap.html';
urlMap['mailMap']='/page/mappicMail.shtml';
urlMap['around']='/newmap/yp.shtml?_flowId=around&map=!{map}&range=!{range}&x=!{x}&y=!{y}&type=!{type}&locale=!{locale}';
urlMap['infoaround']='/newmap/info.shtml?_flowId=around&map=!{map}&range=!{range}&x=!{x}&y=!{y}&type=!{type}&locale=!{locale}';
urlMap['showInfo']='http://!{info_domain}/facade/leftinfo.shtml?act=detail&type=INFO&id=!{id}';
urlMap['showHouse']='http://!{info_domain}/facade/leftinfo.shtml?act=detail&type=HOUSE&id=!{id}';
urlMap['showProduct']='http://!{info_domain}/facade/prodetail.shtml?act=detail&type=PRODUCT&id=!{id}';
var urlManager=new utils.UrlManager(urlMap,paramMap);

//url处理结束---------------------------

//菜单处理开始---------------------------
var idexMenu={
	getMain:function(){
		var database2=[];
		//database2.push({id:10001,englishName:'BusStation',name:'公交'});
		//database2.push({id:10002,englishName:'SubwayStation',name:'地铁'});
		//database2.push({id:10003,name:'menu6_2',parent:10006});
		//database2.push({id:10004,name:'menu6_1_1',parent:10005});
		//database2.push({id:10005,name:'menu6_1',parent:10006});
		//database2.push({id:10006,name:'menu6'});
		//database2.push({id:10007,englishName:'testSign',name:'testSign'});
		//database=database2.concat(database);
		//database=[];
		var menuData=[];
		for(var i=0;i<database.length;i++){
			database[i].option={clickFun:loadSign,width:62};
			if(database[i].display){
				database[i].option.state=true;
				database[i].option.disabled=true;
			}
			menuData.push(database[i]);
		}

		//menuData.push({id:'tools',name:'工具'});
		//menuData.push({});
		//menuData.push({id:'note',name:'便签',option:{clickFun:addNoteOpen}});
		//menuData.push({id:'BusStation',name:'公交',option:{clickFun:loadSign}});
		//menuData.push({id:'SubwayStation',name:'地铁',option:{clickFun:loadSign}});
		//menuData.push({});
		menuData.push({id:'fullScreen',name:'全屏',option:{clickFun:fullScreen}});

		return menuUtil.getMenu(menuData);
	},
	regSigns:function(){
		var dataLoader=popomap.getInnerInstances().dataLoader;
		for(var i=0;i<database.length;i++){
			var sign=database[i];
			var signName=sign.englishName;
			if(sign.ico)sign.ico='http://'+domain_config.image+sign.ico;
			if(signName&&!dataLoader.getSignHandler(signName)){
				dataLoader.regSign(signName,null,{isLoad:sign.display,viewType:sign.viewType,z:6});
				dataLoader.getSignHandler(signName).setSign(signName,'layer',sign.ico||'yp_1.gif',sign.viewType);
			}
			if(sign.display){
				omapApi.loadSign(signName);
				isloadSign[signName]=true;
			}
		}
	}
};
var isloadSign={};
isloadSign['BusStation']=false;
isloadSign['SubwayStation']=false;
isloadSign['3']=false;
function loadSign(o){
	var id=o.data.englishName;
	if(isloadSign[id]) isloadSign[id]=false;
	else isloadSign[id]=true;
	var value=isloadSign[id];
	
	if(value) popomap.loadSign(id);
	else popomap.removeSign(id);
	/*for(var item in isloadSign){
		if(isloadSign[item]&&item!=id){
			isloadSign[item]=false;
			popomap.removeSign(item);
		}
	}*/
}

function doScale(o){
	popomap.selectMode(1);
}
function doArea(o){
	popomap.selectMode(7);
}
function fullScreen(o){
	ui.showFull(o);
}
//发送邮件
function sendMappicEmail(){
	utils.html.appendStyle('email','css/skin/email.css');
	if(!htmlManager.getHtml('index','mail')) return;
	o_ui.SendMapMail.viewEmailForm(true);
}

//打印地图
function printMap(){
	utils.html.appendStyle('print','css/skin/print.css');
	if(!htmlManager.getHtml('printMap','print1')) return;
	o_ui.printMap.viewPrintForm(true);
	o_ui.printMap.printStep(1);
}

//下载地图
function downloadMap(){
	var params=getMapRange();
	params.mapLevel=omapApi.getZoom();
	params.mapType=3;
	var url=urlManager.getUrl('downMap',params);
	location.href=url;
}

//菜单处理结束---------------------------


//搜索处理开始---------------------------
function posValueChange(obj){
	obj._coor='';
}
function setSearchKeyword(obj,value){
	if(!value) return;
	if(!obj._value)obj._value=obj.value;
	obj.value=value;
}
function localSearch(keyword){
	var form=document.forms['localForm'];
	if(keyword)form.keyword.value=keyword;
	var msg='关键字不能不为空\n';
	var flag=true;
	if(!form.keyword._value){
		form.keyword._value=form.keyword.value;
		flag=false;
	}
	if(form.keyword.value==''||form.keyword.value==form.keyword._value){
		flag=false;
	}

	if(!flag)alert(msg);
	else{
		if(form.lot.value!=''){
			var x,y;
			if(form.lot._coor){x=form.centerX.value;y=form.centerY.value;}
			ui.LocalAddressTip.addHistory(form.lot.value,x,y);
		}
		ui.LocalLabelTip.addHistory(form.keyword.value);
		if(!form.lot._coor)form.around.value='';
	}
	if(keyword)form.submit();
	//form.lot._coor='';
	clearPosIco();

	return flag;
}
function infoSearch(keyword){
	var form=document.forms['infoForm'];
	if(keyword)form.keyword.value=keyword;
	var msg='关键字不能不为空\n';
	var flag=true;
	if(!form.keyword._value){
		form.keyword._value=form.keyword.value;
		flag=false;
	}
	if(form.keyword.value==''||form.keyword.value==form.keyword._value){
		flag=false;
	}

	if(!flag)alert(msg);
	else{
		if(form.lot.value!=''){
			var x,y;
			if(form.lot._coor){x=form.x.value;y=form.y.value;}
			ui.InfoAddressTip.addHistory(form.lot.value,x,y);
		}
		ui.InfoLabelTip.addHistory(form.keyword.value);
		if(form.lot._coor){
			form.action = "http://"+infoDomain+"/facade/leftinfo.shtml";
			form.act.value= "searchentity";
			form.around.value =form.x.value+","+form.y.value+",2000";
		}
		else{
			form.action = "http://"+infoDomain+"/facade/leftinfo.shtml";
			form.act.value= "pagesearch";
			form.around.value ="";
		}
	}
	if(keyword)form.submit();
	//form.lot._coor='';
	clearPosIco();
	return flag;
}
function productSearch(keyword){
	var form=document.forms['productForm'];
	if(keyword)form.keyword.value=keyword;
	var msg='关键字不能不为空\n';
	var flag=true;
	if(!form.keyword._value){
		form.keyword._value=form.keyword.value;
		flag=false;
	}
	if(form.keyword.value==''||form.keyword.value==form.keyword._value){
		flag=false;
	}

	if(!flag)alert(msg);
	else{
		if(form.lot.value!=''){
			var x,y;
			if(form.lot._coor){x=form.x.value;y=form.y.value;}
			ui.ProductAddressTip.addHistory(form.lot.value,x,y);
		}
		ui.ProductLabelTip.addHistory(form.keyword.value);
		if(form.lot._coor){
			form.action = "http://"+infoDomain+"/facade/leftpro.shtml";
			form.act.value= "searchByEntity";
			form.around.value =form.x.value+","+form.y.value+",2000";
		}
		else{
			form.action = "http://"+infoDomain+"/facade/leftpro.shtml";
			form.act.value= "pagesearch";
			form.around.value ="";
		}
	}
	if(keyword)form.submit();
	//form.lot._coor='';
	clearPosIco();

	return flag;
}
function trafficSearch1Check(form){
	var msg='';
	var flag=true;
	var startName=form.startName;
	var endName=form.endName;
	if(!startName._value)startName._value=startName.value;
	if(!endName._value)endName._value=endName.value;
	if(startName.value==''||startName.value==startName._value){
		msg+='开始位置不能不为空\n';
		flag=false;
	}
	if(endName.value==''||endName.value==endName._value){
		msg+='结束位置不能不为空\n';
		flag=false;
	}
	if(!flag)alert(msg);
	else{
		var x1,y1;
		if(form.startName._coor){x1=form.startX.value;y1=form.startY.value;}
		ui.TrafficFromAddressTip.addHistory(form.startName.value,x1,y1);
		var x2,y2;
		if(form.endName._coor){x2=form.endX.value;y2=form.endY.value;}
		ui.TrafficToAddressTip.addHistory(form.endName.value,x2,y2);
	    if(form.startName._coor==''){
			form.startType.value='';
			form.startId.value='';
			form.startX.value='';
			form.startY.value='';
	    }
	    if(form.endName._coor==''){
			form.endType.value='';
			form.endId.value='';
			form.endX.value='';
			form.endY.value='';
	    }
	}
	//form.startName._coor='';
	//form.endName._coor='';
	clearPosIco();
	return flag;
}
function setSearchFormCoor(formName){
	alert('在地图上单击右键即可设定坐标');
	getPointInfoOpen(fun);
	var form=document.forms[formName];
	function fun(o){
		if(formName!='localForm'){
			form.x.value=o.x;
			form.y.value=o.y;
		}
		else{
			form.centerX.value=o.x;
			form.centerY.value=o.y;
		}
		setSearchKeyword(form.lot,'坐标已设');
		form.around.value='1000';
		showFlag(o.x,o.y,'当前位置');
		form.lot._coor=1;
	}
}
function setTrafficFormStartCoor1(formName){
	alert('在地图上单击右键即可设定坐标');
	getPointInfoOpen(fun);

	function fun(o){
		form.startType.value='COOR';
		form.startId.value='';
		form.startX.value=o.x;
		form.startY.value=o.y;
		setSearchKeyword(form.startName,'坐标已设');
		form.startName._coor=1;
	}
}
function setTrafficFormStartCoor(){
	alert('在地图上单击右键即可设定坐标');
	getPointInfoOpen(fun);
	var form=document.forms['trafficForm'];
	function fun(o){
		form.startType.value='COOR';
		form.startId.value='';
		form.startX.value=o.x;
		form.startY.value=o.y;
		setSearchKeyword(form.startName,'坐标已设');
		setTrafficStart(o.x,o.y);
		form.startName._coor=1;
	}
}

function setTrafficFormEndCoor(){
	alert('在地图上单击右键即可设定坐标');
	getPointInfoOpen(fun);
	var form=document.forms['trafficForm'];
	function fun(o){
		form.endType.value='COOR';
		form.endId.value='';
		form.endX.value=o.x;
		form.endY.value=o.y;
		setSearchKeyword(form.endName,'坐标已设');
		setTrafficEnd(o.x,o.y);
		form.endName._coor=1;
	}
}
function trafficSearchCheck2(form){
	var msg='关键字不能不为空\n';
	var flag=true;
	if(!form.name._value)form.name._value=form.name.value;
	if(form.name.value==''||form.name.value==form.name._value){
		flag=false;
	}
	if(!flag)alert(msg);
	return flag;
}
function LocalAddressTipClick(o){
	var form=document.forms['localForm'];
	form.around.value='1000';
	form.centerX.value=o.x;
	form.centerY.value=o.y;
	omapApi.go2xyS(o.x,o.y);
	showFlag(o.x,o.y,'当前位置');
}
function InfoAddressTipClick(o){
	var form=document.forms['infoForm'];
	form.around.value='1000';
	form.x.value=o.x;
	form.y.value=o.y;
	omapApi.go2xyS(o.x,o.y);
	showFlag(o.x,o.y,'当前位置');
}
function ProductAddressTipClick(o){
	var form=document.forms['productForm'];
	form.around.value='1000';
	form.x.value=o.x;
	form.y.value=o.y;
	omapApi.go2xyS(o.x,o.y);
	showFlag(o.x,o.y,'当前位置');
}
function TrafficFromAddressTipClick(o){
	var form=document.forms['trafficForm'];
	form.startType.value='COOR';
	form.startId.value='';
	form.startX.value=o.x;
	form.startY.value=o.y;
	omapApi.go2xyS(o.x,o.y);
	setTrafficStart(o.x,o.y);
}
function TrafficToAddressTipClick(o){
	var form=document.forms['trafficForm'];
	form.endType.value='COOR';
	form.endId.value='';
	form.endX.value=o.x;
	form.endY.value=o.y;
	omapApi.go2xyS(o.x,o.y);
	setTrafficEnd(o.x,o.y);
}
//搜索处理结束---------------------------


//搜索提示开始---------------------------
function mapKeywordClick(d){
	var re=/(<font.*?>)|(<\/font.*?>)/g;
	var keyword=d.name.replace(re,'');
	localSearch(keyword);
}
function infoKeywordClick(d){
	var re=/(<font.*?>)|(<\/font.*?>)/g;
	var keyword=d.name.replace(re,'');
	infoSearch(keyword);
}
function productKeywordClick(d){
	var re=/(<font.*?>)|(<\/font.*?>)/g;
	var keyword=d.name.replace(re,'');
	productSearch(keyword);
}
function trafficStartKeywordClick(d){
	var re=/(<font.*?>)|(<\/font.*?>)/g;
	var keyword=d.name.replace(re,'');
	var point=d;

	var form=document.forms['trafficForm'];
	form.startType.value=point.type;
	form.startId.value=point.id;
	form.startName.value=point.name;
	form.startX.value=point.x;
	form.startY.value=point.y;
	form.startName._coor=1;
	//point.typeId=checkType(point);
	//return point;
}
function trafficEndKeywordClick(d){
	var re=/(<font.*?>)|(<\/font.*?>)/g;
	var keyword=d.name.replace(re,'');
	var point=d;

	var form=document.forms['trafficForm'];
	form.endType.value=point.type;
	form.endId.value=point.id;
	form.endName.value=point.name;
	form.endX.value=point.x;
	form.endY.value=point.y;
	form.endName._coor=1;
	//point.typeId=checkType(point);
	//return point;
}
function tipDataHandler(list){
	if(!list) return;
	for(var i=0;i<list.length;i++){
		//alert(list[i].name+':'+hightlightSustr(list[i].name,20));
		list[i].title=hightlightSustr(list[i].name,20);
	}
}
function hightlightSustr(str,len){
	var re=/<.*?>(.*?)<\/.*?>/g;
	var num=0,keyMap={};
	str=str.replace(re,function(mstr,m1){keyMap[m1]=mstr;return m1;});
	var strlen=str.length;
	str=str.substr(0,len);
	if(strlen>=len) str+='  ...';
	for(var item in keyMap){
		str=str.replace(item,keyMap[item]);
	}
	//alert(str);
	return str;
}
//搜索提示结束---------------------------

function showCityList(){
	if(!htmlManager.getHtml('index','cityList')) return;
	var targetId='cityCon';

	var style=$g(targetId).style;
	if(!style.display) style.display='none';
	else style.display='';
}
function ext_CitySelect(domain){
	location.href='http://'+domain+'.'+domain_config.main;
}

function getNavStatus(){return false;
	if($g('divMapNav').style.display=='')
		return true;
	else 
		return false;
}
function switchNavView(flag){
	navUtils1.switchNavViewOut(flag);
}

function setLoginStatus_ext(o){
	var loginPrompt = document.getElementById("loginFrom"); 
	if(!o||!o.nickName){
		loginStatus='';
		//loginPrompt.innerHTML='<p>[<a href="login.jsp" target="leftIfr">登录</a>]&nbsp;[<a href="person.shtml" target="leftIfr">注册</a>]</p>';
		loginPrompt.innerHTML='<p>[<a href="javascript:showMapLoginDiv();">登录</a>]&nbsp;[<a href="http://ucenter.o.cn/register.jsp" target="_blank">注册</a>]</p>';
		
		ui.viewUserPanl(false);
	}
	else{
		try{navUtils.loadNote(true);}catch(e){}
		loginStatus=o.nickName;	
	    loginPrompt.innerHTML='<p>下午好！<a href="http://ucenter.o.cn/memcp.jsp" target="_blank"  class="cRed" >'+o.nickName+'</a>&nbsp;[<a href="http://ucenter.o.cn/memcp.jsp" target="_blank"  >管理</a>]&nbsp;[<a href="javascript:passportLogout()">退出</a>]</p>';
		ui.viewUserPanl(true);
		
	}
}

function showLoginPanel(returnPanel,returnSubPanel,returnUrl){
	var url='login.jsp';
	if(typeof(returnPanel)!='undefined'){
		url+='?returnUrl='+encodeURIComponent(returnUrl)+'&returnPanel=7&returnSubPanel='+returnSubPanel;
		ui.changePanel(0,null,url);
	}
	else{
		ui.changePanel(0);
	}
}

function changeTab(selectClassName,unSelectClassName,key,content,preIndex){
	this.selectClassNameArr=new Array();
	this.unSelectClassNameArr=new Array();
	if(typeof(preIndex)!='number') this.preIndex=0;
	else this.preIndex=preIndex;
	this.change=function(index){
		var preKey=document.getElementById(key+this.preIndex);
		var preContent=document.getElementById(content+this.preIndex);
		var curKey=document.getElementById(key+index);
		var curContent=document.getElementById(content+index);
		if(preKey){			
			if(!this.unSelectClassNameArr[this.preIndex]){
				preKey.className=unSelectClassName;
			}
			else{
				preKey.className=this.unSelectClassNameArr[this.preIndex];
			}
		//alert(preKey.id);
		}
		if(!this.selectClassNameArr[index]){
				curKey.className=selectClassName;
		}
		else{
			curKey.className=this.selectClassNameArr[index];
		}		
		if(preContent){
			preContent.style.display='none';
		}
		curContent.style.display='';
		this.preIndex=index;
	};
	this.putClassName=function(selectClassName,unSelectClassName,index){
		this.selectClassNameArr[index]=selectClassName;
		this.unSelectClassNameArr[index]=unSelectClassName;
	};
}

var tipTools={
	viewTips:[],
	pushView:function(obj){
		this.viewTips.push(obj);
	},
	removeView:function(obj){
		for(var i=0;i<this.viewTips.length;i++){
			if(this.viewTips[i]==obj){
				this.viewTips.splice(i,1);
				break;
			}
		}
	},
	hiddenAll:function(){
		if(this.viewTips.length){
			for(var i=0;i<this.viewTips.length;i++){
				this.viewTips[i].hidden();
			}
			this.viewTips=[];
		}
	}
};
function AddressTip(){
	this.initAddressTip.apply(this,arguments);
}
AddressTip.count=0;
AddressTip.instances={};
AddressTip.getInstance=function(id){
	return AddressTip.instances[id];
};
AddressTip.prototype={
	initAddressTip:function(id,parent,input,left,top){
		this.id=id;
		this.count=AddressTip.count++;
		AddressTip.instances[this.count]=this;
		this.input=input;
		var div=document.createElement('div');
		div.className='pop_con';
		div.style.position='absolute';
		div.style.left=left+'px';
		div.style.top=top+'px';
		div.style.zIndex=10;
		div.style.display='none';
		div.onmouseover=function(){this.style.zIndex=100};
		div.onmouseout=function(){this.style.zIndex=10};
		utils.html.cancelEvent(div,'mouseup');
		utils.html.addEventListener(this.input,'change',function(){this._coor='';},false);

		var h2=document.createElement('h2');
		h2.innerHTML='我的生活圈<span class="closebt"><a href="javascript:AddressTip.getInstance('+this.count+').hidden()" title="关闭"></a></span>';
		div.appendChild(h2);

		var div1=document.createElement('div');
		div1.className='pop_d';
		div1.innerHTML='<dl></dl><div class="hackbox"></div>';
		div.appendChild(div1);
		this.favAddr=div1.firstChild;

		var hot_h2=document.createElement('h2');
		hot_h2.innerHTML='·热门地点';
		div.appendChild(hot_h2);

		var hot_ul=document.createElement('ul');
		hot_ul.className='pop_ul1';
		this.hot=div.appendChild(hot_ul);

		var his_h2=document.createElement('h2');
		his_h2.innerHTML='·历史记录';
		div.appendChild(his_h2);

		var his_ul=document.createElement('ul');
		his_ul.className='pop_ul1';
		this.his=div.appendChild(his_ul);

		this.element=parent.appendChild(div);
	},
	setData:function(data){
		this.data=data;
	},
	renderContent:function(){
		this.renderMain();
		this.renderHot();
		this.renderHis();
	},
	renderMain:function(){
		var list=this.getFavData()||[];
		var item0=list[0]||{value:''};
		var dt0=document.createElement('dt');
		dt0.innerHTML='<img src="images/version2/skin/tip/office.gif" />关注点：';
		var dd0=document.createElement('dd');
		dd0.innerHTML='<a href="#" onclick="AddressTip.getInstance('+this.count+').setInputValue(this)" _args="'+item0.x+','+item0.y+'">'+item0.value+'</a><a href="#" onclick="AddressTip.getInstance('+this.count+').edit1_pre(this)" style="color:#999">[添加]</a>';
		this.favAddr.appendChild(dt0);
		this.favAddr.appendChild(dd0);

		var item1=list[1]||{value:''};
		var dt1=document.createElement('dt');
		dt1.innerHTML='<img src="images/version2/skin/tip/home.gif" />居住地：';
		var dd1=document.createElement('dd');
		dd1.innerHTML='<a href="#" onclick="AddressTip.getInstance('+this.count+').setInputValue(this)" _args="'+item1.x+','+item1.y+'">'+item1.value+'</a><a href="#" onclick="AddressTip.getInstance('+this.count+').edit1_pre(this)" style="color:#999">[添加]</a>';
		this.favAddr.appendChild(dt1);
		this.favAddr.appendChild(dd1);

		if(list.length<=2)return;
		for(var i=2;i<list.length;i++){
			var dt2=document.createElement('dt');
			dt2.innerHTML='<img src="images/version2/skin/tip/fav.gif" />'+list[i].title+'：';
			var dd2=document.createElement('dd');
			dd2.innerHTML='<a href="#" onclick="AddressTip.getInstance('+this.count+').setInputValue(this)">'+list[i].value+'</a><a href="#" onclick="AddressTip.getInstance('+this.count+').edit2(this)"><img src="images/version2/skin/tip/edit.gif" alt="修改" /></a><a href="#" onclick="AddressTip.getInstance('+this.count+').del(this)"><img src="images/version2/skin/tip/delBt.gif" alt="删除" /></a>';
			this.favAddr.appendChild(dt2);
			this.favAddr.appendChild(dd2);
		}
	},
	renderHot:function(){
		var list=this.data.hot||[];
		this._renderUl(this.hot,list);
	},
	renderHis:function(){
		var list=this.getHistory()||[];
		this._renderUl(this.his,list);
	},
	_renderUl:function(container,list){
		for(var i=0;i<list.length;i++){
			var li=document.createElement('li');
			li.innerHTML='<a href="#" onclick="AddressTip.getInstance('+this.count+').setInputValue(this)" _args="'+list[i].x+','+list[i].y+'">'+list[i].value+'</a>';
			container.appendChild(li);
		}
	},
	getFavData:function(){
		if(!this.favData){
			var str=utils.CookieManager.getCookie('js_AddressTip_fav')||',;,';
			var arr=str.split(';');
			for(var i=0;i<arr.length;i++){
				var t=arr[i].split(',');
				arr[i]={title:t[0],value:t[1],x:t[2],y:t[3]};
			}
			this.favData=arr;
		}
		return this.favData;
	},
	refreshFavData:function(){
		var favData=this.favData;
		var str='';
		for(var i=0;i<favData.length;i++){
			str+=favData[i].title+','+favData[i].value+','+favData[i].x+','+favData[i].y;
			if(i!=favData.length-1)str+=';';
		}
		var expires=30;
		utils.CookieManager.setCookie('js_AddressTip_fav',str,expires);
	},
	getHistory:function(){
		if(!this.hisData){
			var str=utils.CookieManager.getCookie('js_AddressTip_history_'+this.id)||'';
			var arr=str?str.split(';'):[];
			for(var i=0;i<arr.length;i++){
				var t=arr[i].split(',');
				arr[i]={value:t[0],x:t[1],y:t[2]};
			}
			this.hisData=arr;
		}
		return this.hisData;
	},
	refreshHistory:function(){
		var hisData=this.hisData;
		var str='';
		for(var i=0;i<hisData.length;i++){
			str+=hisData[i].value+','+(hisData[i].x||'')+','+(hisData[i].y||'');
			if(i!=hisData.length-1)str+=';';
		}
		var expires=60*60;
		utils.CookieManager.setCookie('js_AddressTip_history_'+this.id,str,expires);
	},
	addHistory:function(value,x,y){
		if(value.indexOf('坐标')!=-1)return;
		for(var i=0;i<this.hisData.length;i++){
			if(this.hisData[i].value==value)return;
		}
		if(this.hisData.length>=10){
			this.hisData.splice(0,1);
		}
		x=x||'';
		y=y||'';
		this.hisData.push({value:value,x:x,y:y});
		this.refreshHistory();
	},
	edit1_pre:function(obj){
		var _this=this;
		alert('请先在地图单击右键设定坐标！');
		getPointInfoOpen(xyback);
		function xyback(o){
			_this.x=o.x;
			_this.y=o.y;
			_this.edit1(obj);
		}
	},
	edit1:function(obj){
		var curDD=obj.parentNode;
		var index=this._getFavAddrIndex(curDD);
		if(index==-1)return;
		var list=this.getFavData();
		var item=list[index];
		curDD.innerHTML='<input type="text" class="add_tip2" value="'+item.value+'"/><input type="button" class="tip_sub" value="确定"  onclick="AddressTip.getInstance('+this.count+').pressEdit1(this)"/><input type="button" class="tip_sub" value="取消"  onclick="AddressTip.getInstance('+this.count+').pressEdit1(this,1)"/>';
	},
	pressEdit1:function(obj,reset){
		var curDD=obj.parentNode;
		var index=this._getFavAddrIndex(curDD);
		if(index==-1)return;
		var list=this.getFavData();
		var item=list[index];
		if(!reset){
			if(!this._checkInput(null,curDD.firstChild.value))return;
			item.value=curDD.firstChild.value;
			item.x=this.x;
			item.y=this.y;
		}
		curDD.innerHTML='<a href="#" onclick="AddressTip.getInstance('+this.count+').setInputValue(this)" _args="'+item.x+','+item.y+'">'+item.value+'</a><a href="#" onclick="AddressTip.getInstance('+this.count+').edit1_pre(this)" style="color:#999">[修改]</a>';
		this.refreshFavData();
	},
	_checkInput:function(title,value){
		if(title!=null){
			if(title.length==0||title.length>3){
				alert('输入框1(标题）长度为1-3');
				return false;				
			}
			if(!this._filterInput(title))return false;
		}
		if(value!=null){
			if(value.length==0||value.length>10){
				alert('输入框2(内容）长度为1-10');
				return false;				
			}
			if(!this._filterInput(value))return false;
		}
		return true;
	},
	_filterInput:function(str){
		var list=[',',';','<','>'];
		for(var i=0;i<list.length;i++){
			if(str.indexOf(list[i])!=-1){
				alert('非法字符');
				return false;
			}
		}
		return true;
	},
	_getFavAddrIndex:function(obj){
		var childNodes=this.favAddr.childNodes;
		var n=-1;
		for(var i=0;i<childNodes.length;i++){
			if(childNodes[i]==obj)n=Math.floor(i/2);
		}
		return n;
	},
	setClickEvent:function(fun){
		this.clickEvent=fun;
	},
	setInputValue:function(objA){
		var args=objA.getAttribute('_args')||'';

		if(!this.input._value)this.input._value=this.input.value;
		this.input.value=objA.innerHTML;
		if(args&&args!=','&&this.clickEvent){
			this.input._coor=1;
			var arr=args.split(',');
			var o={x:arr[0],y:arr[1]};
			this.clickEvent(o);
			//alert(o.x+','+o.y);
		}
		this.hidden();
	},
	switchView:function(){
		if(this.element.style.display=='none')this.show();
		else this.hidden();
	},
	show:function(){
		this.his.innerHTML='';
		this.renderHis();
		this.element.style.display='';
		tipTools.pushView(this);
	},
	hidden:function(){
		this.element.style.display='none';
		//tipTools.removeView(this);
	}
};
function LabelTip(){
	this.initLabelTip.apply(this,arguments);
}
LabelTip.count=0;
LabelTip.instances={};
LabelTip.getInstance=function(id){
	return LabelTip.instances[id];
};
LabelTip.prototype={
	initLabelTip:function(id,parent,input,left,top){
		this.id=id;
		this.count=LabelTip.count++;
		LabelTip.instances[this.count]=this;
		this.input=input;
		var div=document.createElement('div');
		div.className='pop_con';
		div.style.position='absolute';
		div.style.left=left+'px';
		div.style.top=top+'px';
		div.style.zIndex=10;
		div.style.display='none';
		div.onmouseover=function(){this.style.zIndex=100};
		div.onmouseout=function(){this.style.zIndex=10};
		utils.html.cancelEvent(div,'mouseup');

		var hot_h2=document.createElement('h2');
		hot_h2.innerHTML='·热门标签<span class="closebt"><a href="javascript:LabelTip.getInstance('+this.count+').hidden()" title="关闭"></a></span>';
		div.appendChild(hot_h2);

		var hot_ul=document.createElement('ul');
		hot_ul.className='pop_ul1';
		this.hot=div.appendChild(hot_ul);

		var his_h2=document.createElement('h2');
		his_h2.innerHTML='·历史记录';
		div.appendChild(his_h2);

		var his_ul=document.createElement('ul');
		his_ul.className='pop_ul1';
		this.his=div.appendChild(his_ul);

		this.element=parent.appendChild(div);
	},
	setData:function(data){
		this.data=data;
	},
	renderContent:function(){
		this.renderHot();
		this.renderHis();
	},
	renderHot:function(){
		var list=this.data.hot||[];
		this._renderUl(this.hot,list);
	},
	renderHis:function(){
		var list=this.getHistory()||[];
		this._renderUl(this.his,list);
	},
	_renderUl:function(container,list){
		for(var i=0;i<list.length;i++){
			var li=document.createElement('li');
			li.innerHTML='<a href="#" onclick="LabelTip.getInstance('+this.count+').setInputValue(this)">'+list[i]+'</a>';
			container.appendChild(li);
		}
	},
	getHistory:function(){
		if(!this.hisData){
			var str=utils.CookieManager.getCookie('js_LabelTip_history_'+this.id)||'';
			var arr=str.split(';');
			this.hisData=arr;
		}
		return this.hisData;
	},
	refreshHistory:function(){
		var hisData=this.hisData;
		var str='';
		for(var i=0;i<hisData.length;i++){
			str+=hisData[i];
			if(i!=hisData.length-1)str+=';';
		}
		var expires=60*60;
		utils.CookieManager.setCookie('js_LabelTip_history_'+this.id,str,expires);
	},
	addHistory:function(value){
		if(value.indexOf('坐标')!=-1)return;
		if(this.hisData.length>=10){
			this.hisData.splice(0,1);
		}
		this.hisData.push(value);
		this.refreshHistory();
	},
	setInputValue:function(objA){
		if(!this.input._value)this.input._value=this.input.value;
		this.input.value=objA.innerHTML;
		this.hidden();
	},
	switchView:function(){
		if(this.element.style.display=='none')this.show();
		else this.hidden();
	},
	show:function(){
		this.his.innerHTML='';
		this.renderHis();
		this.element.style.display='';
		tipTools.pushView(this);
	},
	hidden:function(){
		this.element.style.display='none';
		//tipTools.removeView(this);
	}
};
//导航

//方法
function textEvent(obj,type){
	switch(type){
		case 'focus':
			obj.isfocus=true;
			utils.html.cleanText(obj,1);
			break;
		case 'blur':
			obj.isfocus=false;
			utils.html.cleanText(obj,0);
			break;
	}
}


//搜索切换
var o1=new changeTab('MapSearch','','searchBtn_','searchDiv_',1);
//分类推荐
var o2=new changeTab('hoverBtn','normalBtn','todayBtn_','todayTab_',1);
//黄页切换
var o3=new changeTab('hoverBtn','normalBtn','joinBtn_','joinTab_',1);
//分类广告切换
var o4=new changeTab('seleced','','tuiBtn_','tui_',1);
var o5=new changeTab('seleced','','tuiBtn_','tui_',4);
//地图窗口
var o6=new changeTab('hover','','tabBtn_','main_',1);
//公交搜索
var o7=new changeTab('jtBtn_on','jtBtn_out','jtBtn_','jttab_',1);

//服务
var o8=new changeTab('serHov','','serBtn_','SerTab_',1);