var xdtjs={
ck:function(){  //小地图左键定位
var thex=event.offsetX,they=event.offsetY
if(event.srcElement.id!="xdt"){
thex+=event.srcElement.offsetLeft;they+=event.srcElement.offsetTop
}
var baifenx=(thex-(xdtkuang.offsetWidth/2))/(xdtwid/100)
var baifeny=(they-(xdtkuang.offsetHeight/2))/(xdthei/100);
fmleft=round(-fmwid*(baifenx/100));fmtop=round(-fmhei*(baifeny/100));
if(fmleft<-(fmwid-bodywid))fmleft=-(fmwid-bodywid);if(fmleft>0)fmleft=0
if(fmtop<-(fmhei-bodyhei))fmtop=-(fmhei-bodyhei);if(fmtop>0)fmtop=0
fm1.style.left=fmleft;fm1.style.top=fmtop;closemenu();
selobj=null;xdk.style.display="none";
}
}
function gxxinxi(){  //更新小地图附带信息
shuzhidtname.innerHTML=dtname;shuzhidtnode.innerText=dtwenjian;
shuzhiw.innerText=fmwid+"cm";shuzhih.innerText=fmhei+"cm"
if(gws==""){xdt_mw1.innerText="0种";xdt_mw2.innerText="0个";xdt_mw1.onmousemove=null}else{
xdt_mw1.innerText=gws.split(",").length+"种";xdt_mw2.innerText=gwmax+"个";xdt_mw1.onmousemove=function(){showtmk(gws.replace(/\=/g,""))}}
if(kuang==""){xdt_kw1.innerText="0种";xdt_kw2.innerText="0个";xdt_kw1.onmousemove=null}else{
var kuang1=kuang.split(","),len1=0;xdt_kw1.innerText=kuang1.length+"种";xdt_kw1.onmousemove=function(){showtmk(dtname+"初始刷矿:"+kuang.replace(/\=/g,""))}
for(var i=0;i<kuang1.length;i++)len1+=parseInt(kuang1[i].split("=")[1])
xdt_kw2.innerText=len1+"个"
}
xdtkuang.style.width=bodywid/(fmwid/xdtwid);xdtkuang.style.height=bodyhei/(fmhei/xdthei)
}
function bianyi(){  //编译成XML源码对象
var new1=dtdom.createElement("n");
new1.setAttribute("name",dtname);new1.setAttribute("wid",fmwid);
new1.setAttribute("hei",fmhei);new1.setAttribute("dimian",fm1.style.backgroundImage.replace(/url\(|\)/g,""));
new1.setAttribute("bgsound",yinyue);new1.setAttribute("guishu",guishu)
if(jinfei){new1.setAttribute("fei","禁止")}else{new1.removeAttribute("fei")}
if(migong){new1.setAttribute("migong","true")}else{new1.removeAttribute("migong")}
if(huichengx!=""){new1.setAttribute("morenx",huichengx)}else{new1.removeAttribute("morenx")}
if(huichengy!=""){new1.setAttribute("moreny",huichengy)}else{new1.removeAttribute("moreny")}
if(gwmax!=0){new1.setAttribute("gwmax",gwmax)}else{new1.removeAttribute("gwmax")}
if(gws!=""){new1.setAttribute("gw",gws)}else{new1.removeAttribute("gw")}
if(kuang!=""){new1.setAttribute("kuang",kuang)}else{new1.removeAttribute("kuang")}
if(hjy!=""){new1.setAttribute("hjy",hjy)}else{new1.removeAttribute("hjy")}

for(var i=0;i<fm1.children.length;i++){
var obj=fm1.children[i],id1=obj.id
var jd=dtdom.createElement("obj")
if(id1=="fmkuang")continue;
jd.setAttribute("id",id1);jd.setAttribute("x",obj.offsetLeft);jd.setAttribute("y",obj.offsetTop);
jd.setAttribute("wid",obj.offsetWidth);jd.setAttribute("hei",obj.offsetHeight)
if(obj.ciyuan!=null)jd.setAttribute("ciyuan",obj.ciyuan);
if(obj.z!=null)jd.setAttribute("z",obj.z)
if(obj.move!=null&&obj.tagName!="DIV"){jd.setAttribute("move",obj.move)}
if(obj.dong!=null){jd.setAttribute("dong",obj.dong);jd.setAttribute("fanwei",obj.fanwei)}
if(obj.yincang!=null){jd.setAttribute("yincang",obj.yincang);}
if(id1=="pb"){
if(obj.col!=null)jd.setAttribute("col",obj.col)
if(obj.bg!=null)jd.setAttribute("bg",obj.bg)
}

if(obj.src!=null&&id1!="boos"&&obj.pub==null){jd.setAttribute("src",obj.src.replace(/.*\/img\/(.)/g,"$1"))}
if(id1=="npc"||id1=="boos"){if(obj.pub!=null){
jd.setAttribute("pub",obj.pub)
}else{
if(obj.name1!=null)jd.setAttribute("name1",obj.name1)
if(obj.face1!=null)jd.setAttribute("face",obj.face1)
if(obj.msg!=null)jd.setAttribute("msg",obj.msg)
}}
if(id1=="boos"){
if(obj.boosis!=null)jd.setAttribute("boosis",obj.boosis);
if(obj.shouxia!=null)jd.setAttribute("shouxia",obj.shouxia)
if(obj.killxs!=null)jd.setAttribute("killxs",obj.killxs)
}else if(id1=="xj"){
jd.setAttribute("bgimg",obj.bgimg);
jd.setAttribute("xjshanghai",obj.xjshanghai);
jd.setAttribute("xjsunshi",obj.xjsunshi)
}else if(id1=="exit"){
if(obj.exitto!=null)jd.setAttribute("exitto",obj.exitto)
if(obj.yincang!=null)jd.setAttribute("yincang",obj.yincang)
if(obj.exitx!=null)jd.setAttribute("exitx",obj.exitx)
if(obj.exity!=null)jd.setAttribute("exity",obj.exity)
}
if(id1=="me")continue;new1.appendChild(jd);
}
return new1
}
var quanju={  //全局操作
helpopen:function(){  //帮助信息
help1.style.left=bodywid/2-(help1.offsetWidth/2);help1.style.top=bodyhei/2-(help1.offsetHeight/2)
help1.style.visibility="visible";sd_mark=true;
},
thisym:function(){  //本地图源码
yuanmatxt1.value=bianyi().xml.replace(/\>\</g,">\n<")
ymzishu1.innerText=yuanmatxt1.value.length
ymtab1.style.left=bodywid/2-(ymtab1.offsetWidth/2);ymtab1.style.top=bodyhei/2-(ymtab1.offsetHeight/2)
ymtab1.style.visibility="visible";sd_mark=true;
},
addkw:function(){  //添加矿物
var addtext="";if(sheding1[11].value!="")addtext=",";
var kwname=kwselect.options[kwselect.selectedIndex].text
if(sheding1[11].value.indexOf(kwname)!=-1)return alert("已经添加了矿物["+kwname+"],不能重复添加")
addtext+=kwname+"="+kwjilv.options[kwjilv.selectedIndex].text.replace("个","")
sheding1[11].value+=addtext;
var tempc=sheding1[11].createTextRange();tempc.moveStart('character',sheding1[11].value.length);tempc.select()
},
sheding:function(){  //地图设置
var len1=sheding1[1].options.length;for(var i=0;i<len1;i++){sheding1[1].options.remove(0);}  //更新归属地
dtdom.load("server/ditu/chengshi.xml");var tempdom=dtdom.getElementsByTagName("n")
for(var i=0;i<tempdom.length;i++){var temp1=document.createElement('OPTION');
temp1.innerText="chengshi - "+tempdom[i].getAttribute("name");temp1.value=tempdom[i].getAttribute("name");sheding1[1].appendChild(temp1)
}
if(hjy==""){huanjingyue.selectedIndex=0}else{  //更新环境乐
for(var i=0;i<huanjingyue.options.length;i++){if(huanjingyue.options[i].text==hjy)huanjingyue.selectedIndex=i}
}

newsd1.checked=migong;
sheding1[0].value=dtname;
sheding1[2].value=fmwid;sheding1[3].value=fmhei;
sheding1[4].value=fm1.style.backgroundImage.replace(/url\(|\)/g,"");sheding1[5].value=yinyue

sheding1[6].checked=jinfei;sheding1[7].value=huichengx;sheding1[8].value=huichengy;
for(var i=0;i<sheding1[9].options.length;i++){if(sheding1[9].options[i].value==gwmax)sheding1[9].selectedIndex=i}
sheding1[10].value=gws;sheding1[11].value=kuang;

dtsd.style.left=bodywid/2-(dtsd.offsetWidth/2);dtsd.style.top=bodyhei/2-(dtsd.offsetHeight/2)
dtsd.style.visibility="visible";sd_mark=true;
for(var i=0;i<sheding1[1].options.length;i++){if(sheding1[1].options[i].value==guishu)sheding1[1].selectedIndex=i}
},
sheding2:function(){  //地图设置确认
if(sheding1[0].value.replace(/ /g,"")=="")return alert("地图名字不能为空");
var num=new Number(sheding1[2].value)
if(isNaN(num)||num<1000)return alert("地图宽度必须是数字,且值不能小于1000")
num=new Number(sheding1[3].value)
if(isNaN(num)||num<1000)return alert("地图高度必须是数字,且值不能小于1000")
if(sheding1[7].value!=""){
num=new Number(sheding1[7].value)
if(isNaN(num)||num<0)return alert("回城坐标X要么不填,要填,就必须是大于0的数字")
}
if(sheding1[8].value!=""){
num=new Number(sheding1[8].value)
if(isNaN(num)||num<0)return alert("回城坐标Y要么不填,要填,就必须是大于0的数字")
}
if(sheding1[10].value!=""&&sheding1[9].selectedIndex==0)return alert("所有魔物含有魔物信息,则魔物上限不能选择[最多0个]")
if(sheding1[9].selectedIndex!=0&&sheding1[10].value=="")return alert("魔物上限不为[最多0个]的话,那么请详细编辑所有魔物")

dtname=sheding1[0].value;guishu=sheding1[1].value;
fmwid=parseInt(sheding1[2].value);fmhei=parseInt(sheding1[3].value)
fm1.style.width=fmwid;fm1.style.height=fmhei
fm1.style.backgroundImage="url('"+sheding1[4].value+"')"
yinyue=sheding1[5].value;bgsound1.src="bgsound/"+yinyue
if(huanjingyue.selectedIndex==0){hjy="";bgsound2.src=""}else{hjy=huanjingyue.options[huanjingyue.selectedIndex].text;}
migong=newsd1.checked;jinfei=sheding1[6].checked;
huichengx=sheding1[7].value==""?"":parseInt(sheding1[7].value);
huichengy=sheding1[8].value==""?"":parseInt(sheding1[8].value);
gwmax=sheding1[9].value;gws=sheding1[10].value;kuang=sheding1[11].value
dtsd.style.visibility="hidden";sm3.rekuang();
if(huichengx!=""&&huichengy!=""){sm3.medingwei()}else{me.style.visibility="hidden"}
sm3.loadxdt();gxxinxi();sd_mark=false;
},
save:function(){  //保存
if(gongcheng.editfilename=="")return alert("无法保存，因为无法定位文件，请你先打开一个地图文件，哪怕是空白新建的。")
dtdom.load("server/ditu/"+gongcheng.editfilename+".xml");var tempdom=dtdom.getElementsByTagName("document")[0]
xdk.style.display="none";
for(var i=0;i<tempdom.childNodes.length;i++){
if(tempdom.childNodes[i].getAttribute("name")==dtname){  //固有保存
tempdom.replaceChild(bianyi(),tempdom.childNodes[i]);
yuanmatxt1.value=dtdom.xml.replace(/	/g,"").replace(/\>\</g,">\n<").replace('<?xml version="1.0"?>','<?xml version="1.0" encoding="gb2312"?>')
var newfile1=fsoobj.CreateTextFile(gongcheng.editfile,true,false);newfile1.write(yuanmatxt1.value);newfile1.close();  //赋值VALUE为了防止FSO不区分\N换行符
return alert("固有地图【"+dtname+"】更新保存完成！");
}}
 //非固有，新名称的地图
tempdom.insertBefore(bianyi(),tempdom.firstChild);
yuanmatxt1.value=dtdom.xml.replace(/	/g,"").replace(/\>\</g,">\n<").replace('<?xml version="1.0"?>','<?xml version="1.0" encoding="gb2312"?>')
var newfile1=fsoobj.CreateTextFile(gongcheng.editfile,true,false);newfile1.write(yuanmatxt1.value);newfile1.close();
alert("创建了新的地图【"+dtname+"】，存储完成！");
},
del:function(){  //清空地图
if(!confirm("你确实要清空这幅地图重新编辑??"))return;
fm1.innerHTML=me.outerHTML
sm3.loadxdt();gxxinxi();xdk.style.display="none";bianji.saveundo();
}
}

var td={
mousemove:function(isout){  //菜单鼠标移动
var obj=event.srcElement;if(obj.tagName=="FONT")obj=obj.parentElement;
var fuid=obj.offsetParent.id
if(obj.id!="td1")return;for(var i=0;i<td1.length;i++)td1[i].bgColor="";
if(isout==null){obj.bgColor="white";if(obj.menu==null)return;tab2.style.display="";
tab2.style.left=tab1.offsetLeft+tab1.offsetWidth-10;tab2.style.top=tab1.offsetTop+tab1.offsetHeight-tab2.offsetHeight
var dayuy=bodyhei-parseInt(tab2.offsetHeight)
if(evy>dayuy)tab2.style.top=dayuy
}else{if(fuid!="tab2"&&obj.menu==null)tab2.style.display="none";}
}
}