
var popSet=new Array();
var actionCallBack={};
var actionSet='';

//----------------------------------------------
//
function setActionSet(value){
	actionSet=value;
}
function getActionSet(){
	return actionSet;
}
function cleanActionSet(){
	actionSet='';
	popomap.setMapTip();
}

//add Error
function addErrOpen(){//打开纠错功能
	setActionSet('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'];
	var params={x:x,y:y};
	htmlStr=htmlStr.replace('!{url}',pageConfig.getUrl('addError',params));
	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 getPosXYOpen(callback){//打开获取坐标功能
	actionCallBack['getPosXY']=callback;
	setActionSet('getPosXY');
	alert('点右键获取地址');
	popomap.setMapTip('<span style="color:red;font-size:12px;">点右键获取地址</span>');
}
function getPosXYClose(){//关闭获取坐标功能
	actionCallBack['getPosXY']='';
	popomap.removePop('popAnchor');
	cleanActionSet();
}
function getPosXY(){//获取坐标
	var o={x:popSet['X'],y:popSet['Y']};
	var fun=actionCallBack['getPosXY'];
	if(typeof fun=='function')fun(o);
	else if(typeof fun=='string') crossApi.execute({action:fun,params:o});

	popomap.removePop('popAnchor');
	popomap.createPopT('popAnchor','<img src="images/map/anchor.gif">',popSet['X'],popSet['Y'],12,12,5);
}
function getPointInfoOpen(fun){//打开获取坐标和实体信息功能
	isEntity=false;
	actionCallBack['getPointInfo']=fun;
	setActionSet('getPointInfo');
	popomap.setMapTip('<img src="images/map/rightTip2.gif">');
}
function getPointInfo(){//获取坐标和实体信息
	if(confirm('您确定设置该点吗？')){
		var x=popSet['X'];
		var y=popSet['Y'];
		var id='';
		var name='';
		if(isEntity){
			id=popomap.getAreaUnitInfo().AreaID;
			name=popomap.getAreaUnitInfo().AreaName;
		}
		var o={entityId:id,entityName:name,x:x,y:y};
		var fun=actionCallBack['getPointInfo'];
		if(fun){
			if(typeof fun=='function')fun(o);
			else if(typeof fun=='string') crossApi.execute({action:fun,params:o});
		}
		cleanActionSet();
		popomap.setMapTip();
	}
}

function removePop_All(){
	//popomap.removePop('addNote');
	popomap.removePop('addErr');
	//popomap.removePop('addPost');
	//popomap.removePop('showPost');
	//popomap.removePop('showNote');
	return false;
}

//----------------------------------------------
//
var omapUtils={
	//实现插入iframe的界面
	createIframe:function(id,title,url,width,height,x,y){
		var htmlStr=popSet['ifr'];		//得到插入的html的内容
		htmlStr=htmlStr.replace('!{src}',url);	//替换iframe的url
		htmlStr=htmlStr.replace('!{html_id}',id);		//替换id
		htmlStr=htmlStr.replace('!{html_title}',title);//替换标题
		htmlStr=htmlStr.replace('!{w1}',width+70);	//外部界面宽
		htmlStr=htmlStr.replace('!{h1}',height+50);	//外部界面高
		htmlStr=htmlStr.replace('!{w2}',width);		//内容的宽
		htmlStr=htmlStr.replace('!{hw}',height);		//内容的高

		var sx=150*Math.pow(2,omapApi.getZoom()-1);
		var sy=150*Math.pow(2,omapApi.getZoom()-1);
		this.removeIframe(id);						//如果有同名的iframe移除
		//omapApi.go2xy(x+sx,y+sy);
		omapApi.createPopT(id,htmlStr,x,y,0,96,5);	//插入
	},
	removeIframe:function(id){
		omapApi.removePop(id);
	},
	showMapInfo:function(id,type){
		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';
		postData(url,null,fun,'GET');

		function fun(value){
			if(!value) {
				popomap.init(0,0,true);
				return;
			}
			var o=null;
			try{o=eval('('+value+')');}
			catch(e){
				popomap.init(0,0,true);
				return;
			}
			popomap.init(o.x,o.y,true);
			if(type==1){
				if(o.type=='BUILDING'){
					omapApi.getInnerInstances().infoBox.showWindow(id,0);
				}
				else{
					omapApi.showMapInfo(id,type);
				}
			}
			else omapApi.showMapInfo(id,type);
		}
	},
	showPop:function(x,y,content,times){//显示简单的pop
		if(!times) times=0;
		times++;
		if(times>100) return;
		if(!x||!y) return;
		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);
	}
};
function showResult(id,type){
	popomap.showMapInfo(id,type);
}
function showResult2(id,x,y,type,name){
	if(type==1)
		popomap.showOCInfo(x,y,id,0,false,false);
	else if(type==2)
		popomap.showOCInfo(x,y,0,id,true,false);
	else
		omapUtils.showPop(x,y,name);
}
function showInfoBox(id,index){
	omapApi.getInnerInstances().infoBox.showWindow(id,index);
}

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/map/popwin/point.gif" width="55" height="39"></div><div class="window_boder_tt"><div class="window_boder_tt_left">纠错</div><div class="window_close"><img src="/images/map/close.gif" width="16" height="16" style="cursor:pointer;" onclick="parent.removePop_addErr();;return false;"></div></div><iframe id="ifAddErr" style="WIDTH:210px;HEIGHT:160px" scrolling="no" frameborder="no" src="!{url}"></iframe></div></div>';
popSet['ifr']='<div class="Mapinfo_min" style="width:!{w1}px;height:!{h1}px">  <div class="pointer"><img src="images/map/popwin/ui_point.gif"></div>  <div class="con">   <div class="name">      <div class="icon"><img src="images/map/popwin/getblog2.gif" width="14" height="14"></div>  <div class="closebt"><a href="#" onclick="parent.omapUtils.removeIframe(\'!{html_id}\');return false;"></a></div>  <div class="info_h2">!{html_title}</div>   </div>   <div class="box"><iframe id="userIfr" name="userIfr" style="WIDTH:!{w2}px;HEIGHT:!{h2}px" scrolling="no" frameborder="no" src="!{src}"></iframe></div>  </div></div></div>';