var popSet=new Array();
var actionSet='';

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.setMapTip('<img src="api/images/rightTip.gif">');
		}
		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();
	htmlStr=popSet[actionSet];
	popSet['X']=Math.round(popomap.getCurX(evt));
	popSet['Y']=Math.round(popomap.getCurY(evt));
	htmlStr=htmlStr.replace('{$X}',popSet['X']);
	htmlStr=htmlStr.replace('{$Y}',popSet['Y']);

	if(evt.button==2&&actionSet=='addNote'){
		var sx=150*Math.pow(2,popomap.getZoom()-1);
		removePop_addNote();
		popomap.go2xyS(popSet['X']+sx,popSet['Y'],null,createPop_addNote);
	}
	if(evt.button==2&&actionSet=='addErr'){
		var sx=150*Math.pow(2,popomap.getZoom()-1);
		removePop_addErr();
		popomap.go2xyS(popSet['X']+sx,popSet['Y'],null,createPop_addErr);
	}
	if(evt.button==2&&actionSet=='addPost'){
		var sx=200*Math.pow(2,popomap.getZoom()-1);
		removePop_addPost();
		popomap.go2xyS(popSet['X']+sx,popSet['Y'],null,createPop_addPost);
	}


	function createPop_addNote(){
		popomap.createPop('addNote',htmlStr,popSet['X'],popSet['Y'],0,145,5);
	}
	function createPop_addErr(){
		popomap.createPop('addErr',htmlStr,popSet['X'],popSet['Y'],0,145,5);
	}
	function createPop_addPost(){
		popomap.createPop('addPost',htmlStr,popSet['X'],popSet['Y'],0,145,5);
	}
}
function myAreaClick(evt){
	//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){
	//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);
}
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.appendChild(a);
	parNode.appendChild(b);
}
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 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 showNote(id,x,y,times){
	if(!times) times=0;
	isDoMapInit=true;
	times++;
	if(times>100) return;
	if(!x||!y) loadxml();
	try{
		htmlStr=popSet['showNote'];
		htmlStr=htmlStr.replace('{$ID}',id);
		removePop_showNote();
		createPop_showPost();
	}
	catch(e){
		var fun='showNote('+id+','+x+','+y+','+times+')';
		window.setTimeout(fun,100);
	}

	function createPop_showPost(){
		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,145,5);
		mapInit();
	}
	function loadxml(){
		var url='/xml/assistant/0/'+id+'.xml';
		loadXML(url,parsexml);
	}
	function parsexml(xmlelm){
		if(xmlelm){
			x=xmlelm.getElementsByTagName('xo')[0].firstChild.nodeValue;
			y=xmlelm.getElementsByTagName('yo')[0].firstChild.nodeValue;
			//content=xmlelm.getElementsByTagName('content')[0].firstChild.nodeValue;
			xmlelm=null;
			delete xmlelm;
		}
		else{
			x=0;
			y=0;
		}
	}
}
function showResult(id,type){
	var url='';
	if(type==1)
		url='/gzresource/xml/area/'+Math.floor(id/5000)+'/'+id+'.xml';
	else 
		url='/gzresource/xml/unit/'+Math.floor(id/5000)+'/'+id+'.xml';
	loadXML(url,parsexml);


	function parsexml(xmlelm){
		if(xmlelm){
			if(type==1){
				x=xmlelm.getElementsByTagName('xo')[0].firstChild.nodeValue;
				y=xmlelm.getElementsByTagName('yo')[0].firstChild.nodeValue;
			}
			else{
				x=xmlelm.getElementsByTagName('xo')[0].firstChild.nodeValue;
				y=xmlelm.getElementsByTagName('yo')[0].firstChild.nodeValue;
			}
			xmlelm=null;
			delete xmlelm;
		}
		else{
			x=0;
			y=0;
		}
		//popomap.go2xy(x,y);
		if(type==1)
			popomap.showOCInfo(x,y,id,0,false,true);
		else 
			popomap.showOCInfo(x,y,0,id,true,true);
	}
}
var isDoMapInit=false;
function mapInit(times){
	if(!times) times=0;
	times++;
	if(times>100) return;
	if(isDoMapInit) return;
	try{
		popomap.init();
	}
	catch(e){
		var fun='mapInit('+times+')';
		window.setTimeout(fun,500);
	}
}
function addPostOpen(){
	actionSet='addPost';
}
function addNoteOpen(){
	actionSet='addNote';
}
function addErrOpen(){
	actionSet='addErr';
}
function removePop_addNote(){
	popomap.removePop('addNote');
	return false;
}
function removePop_addErr(){
	popomap.removePop('addErr');
	return false;
}
function removePop_addPost(){
	popomap.removePop('addPost');
	return false;
}
function removePop_showPost(){
	popomap.removePop('showPost');
	return false;
}
function removePop_showNote(){
	popomap.removePop('showNote');
	return false;
}
function removePop_All(){
	popomap.removePop('addNote');
	popomap.removePop('addErr');
	popomap.removePop('addPost');
	popomap.removePop('showPost');
	popomap.removePop('showNote');
	return false;
}
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;
	}
}
waitMap();
//showNote(2,59530,39298);
//mapInit();
popSet['addNote']='<div style="width:398px;">  <table width="330" 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="315px"><img src="images/bq.gif" width="78" height="26"></td>            <td width="20" bgcolor="#F6F6F6"><img src="images/bbs_close.gif" width="16" height="26" style="cursor:pointer" onclick="parent.removePop_addNote()"></td>          </tr>          <tr>            <td colspan="2"><iframe id="ifSmallAddPost" style="WIDTH:330px;HEIGHT:190px" scrolling="no" frameborder="no" src="/mutual/assistant.jspa?_flowId=edit&x={$X}&y={$Y}"></iframe></td>          </tr>                </table></td>    </tr>  </table></div>';
popSet['showNote']='<div style="width:398px;">  <table width="330" 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="315px"><img src="images/bq.gif" width="78" height="26"></td>            <td width="20" bgcolor="#F6F6F6"><img src="images/bbs_close.gif" width="16" height="26" style="cursor:pointer" onclick="parent.removePop_showNote()"></td>          </tr>          <tr>            <td colspan="2"><iframe id="ifSmallAddPost" style="WIDTH:330px;HEIGHT:190px" scrolling="no" frameborder="no" src="/mutual/assistant.jspa?_flowId=view&id={$ID}"></iframe></td>          </tr>                </table></td>    </tr>  </table></div>';
popSet['addErr']='<div style="width:398px;"><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="315px"><img src="images/jc.gif" width="86" height="26"></td>          <td width="20px" bgcolor="#F6F6F6"><img src="images/bbs_close.gif" style="cursor:pointer;" onclick="parent.removePop_addErr()"></td>        </tr>        <tr>          <td colspan="2"><iframe id="ifAddErr" style="WIDTH:330px;HEIGHT:160px" scrolling="no" frameborder="no" src="/mutual/mistake.jspa?_flowId=edit&x={$X}&y={$Y}"></iframe></td>        </tr>      </table></td>    </tr>  </table></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="/mutual/message.jspa?_flowId=edit&x={$X}&y={$Y}"></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="parent.removePop_showPost()"></td>        </tr>        <tr>          <td colspan="2"><iframe id="ifAddErr" style="WIDTH:360px;HEIGHT:250px" scrolling="yes" frameborder="no" src="/mutual/message.jspa?_flowId=view&id={$ID}"></iframe></td>        </tr>      </table></td>    </tr>  </table></div>';