var addx=0,addy=0,copyobj=""  //记录操作元素的点选区域,以及存储复制的HTML
var radck=0;  //记录修改单选框,用于重设目标ID
var imgsrc="daolu/wenhao.gif";  //用于记录格式化后的IMG SRC
function radclick(eventis){  //单选框的单击
var rad1=document.getElementsByName("radio1");
for(var i=0;i<rad1.length;i++)if(rad1[i]==eventis)radck=i;
if(radck<3){tr1[6].style.display="none";tr1[7].style.display="none";tr1[8].style.display="none";xiugai1[5].disabled=false}else{
tr1[3].style.display="none";tr1[4].style.display="none";tr1[5].style.display="none";
xiugai1[5].disabled=true
}
switch(radck){
case 0:  //dl
tr1[3].style.display="";tr1[4].style.display="none";tr1[5].style.display="none";
xg_dlsrc.value=imgsrc;break;
case 1:  //npc
tr1[3].style.display="none";tr1[4].style.display="";tr1[5].style.display="none";
if(selobj.pub==null){xg_name1select.selectedIndex=0;
}else{
for(var i=0;i<xg_name1select.options.length;i++){
if(xg_name1select.options[i].value==selobj.pub)xg_name1select.selectedIndex=i}
}xg_name1select.onchange()
xg_name1.value=selobj.name1==null?"":selobj.name1;xg_npcsrc.value=imgsrc;
xg_npcsrc3.value=selobj.face1==null?"":selobj.face1;
xg_jq.value=selobj.msg==null?"":selobj.msg;
break;
case 2:  //boos
tr1[3].style.display="none";tr1[4].style.display="none";tr1[5].style.display="";
xg_boosname.value=selobj.boosis==null?"":selobj.boosis;
xg_boosjq.value=selobj.msg==null?"":selobj.msg;
xg_shouxia.value=selobj.shouxia==null?"":selobj.shouxia;
xg_killxs.checked=selobj.killxs==null?false:true;
xg_boossrc.value=selobj.face1==null?"":selobj.face1;
break;
case 3:  //禁区屏障
tr1[6].style.display="";tr1[7].style.display="none";tr1[8].style.display="none";
xg_bkcolor.value=selobj.style.backgroundColor;xg_bkcolor.style.color=xg_bkcolor.value
for(var i=0;i<xg_colselect.options.length;i++){if(xg_colselect.options[i].text==xg_bkcolor.value){xg_colselect.selectedIndex=i;break;}}
if(selobj.getAttribute("bg")!=null)xg_bgsrc.value=selobj.getAttribute("bg")
break;
case 4:  //海域
tr1[6].style.display="none";tr1[7].style.display="none";tr1[8].style.display="none";
break;
case 5:  //陷阱区
tr1[6].style.display="none";tr1[7].style.display="";tr1[8].style.display="none";
xg_xjbgsrc.value=selobj.bgimg==null?"":selobj.bgimg;xg_xjshanghai.value=selobj.xjshanghai==null?1:selobj.xjshanghai;
for(var i=0;i<xg_xjsunshi.length;i++)xg_xjsunshi[i].checked=false;
if(selobj.xjsunshi!=null){
for(var i=0;i<xg_xjsunshi.length;i++){if(selobj.xjsunshi.indexOf(i)!=-1)xg_xjsunshi[i].checked=true;}
}
break;
case 6:  //安全区
tr1[6].style.display="none";tr1[7].style.display="none";tr1[8].style.display="none";
break;
case 7:  //出口
tr1[6].style.display="none";tr1[7].style.display="none";tr1[8].style.display="";
var allmulu=fsoobj.GetFolder(gendir+"ditu\\"),all1=new Enumerator(allmulu.files),txt1=[],txt1youbiao=0;
while(!all1.atEnd()){fsoxml.load("server/ditu/"+all1.item().name);var tempdom=fsoxml.getElementsByTagName("n");
var tempcol=getcolor();
for(var i=0;i<tempdom.length;i++){
txt1[txt1youbiao]="<option style='background-color:"+tempcol+";' value='"+all1.item().name.split(".")[0]+"+-=-+"+tempdom[i].getAttribute("name")+"'>"+all1.item().name+"【"+tempdom[i].getAttribute("name")+"】";
txt1youbiao++}
all1.moveNext()}xg_exitto.outerHTML="<select id='xg_exitto'>"+txt1.join("")+"</select>"
for(var i=0;i<xg_exitto.options.length;i++){if(xg_exitto.options[i].value==selobj.exitto){xg_exitto.selectedIndex=i;break;}}
xg_exitx.value=selobj.exitx==null?0:selobj.exitx;
xg_exity.value=selobj.exity==null?0:selobj.exity;

break;
}
}
function document.onkeydown(){  //访问键盘
var key1=event.keyCode,ctrl1=event.ctrlKey,obj=event.srcElement
if(obj.tagName!="TEXTAREA"&&obj.tagName!="INPUT"){
if(sd_mark)return false;
if(ctrl1==true&&key1==86){document.body.focus();addx=event.offsetX-inx;addy=event.offsetY-iny
return bianji.paste();}
if(ctrl1==true&&key1==90)return bianji.undo();
if(ctrl1==true&&key1==89)return bianji.redo();
if(ctrl1==true&&key1==83)return quanju.save();
if(key1==112)return tool1[0].onmouseup();
if(key1==113)return tool1[1].onmouseup();
if(key1==114)return tool1[2].onmouseup();
if(key1==115)return tool1[3].onmouseup();


if(selobj!=null){if(ctrl1==true&&key1==67)return bianji.copy();
if(ctrl1==true&&key1==88)return bianji.copy(true);
if(key1==13&&xiugaikuang.style.visibility!="hidden")return bianji.xiugai2();
if(key1==46)return bianji.del()
if(key1==87||key1==38&&(selobj.offsetTop>0)){selobj.style.top=selobj.offsetTop-10;xdk.style.top=xdk.offsetTop-10}
if(key1==65||key1==37&&(selobj.offsetLeft>0)){selobj.style.left=selobj.offsetLeft-10;xdk.style.left=xdk.offsetLeft-10}
if(key1==83||key1==40&&(selobj.offsetTop<fmhei-selobj.offsetHeight)){selobj.style.top=selobj.offsetTop+10;xdk.style.top=xdk.offsetTop+10}
if(key1==39||key1==68&&(selobj.offsetLeft<fmwid-selobj.offsetWidth)){selobj.style.left=selobj.offsetLeft+10;xdk.style.left=xdk.offsetLeft+10}
return;
}
if(key1==83||key1==40&&fmtop>-(fmhei-bodyhei))fm1.style.top=fmtop-=10
if(key1==87||key1==38&&fmtop<0)fm1.style.top=fmtop+=10
if(key1==65||key1==37&&fmleft<0)fm1.style.left=fmleft+=10
if(key1==39||key1==68&&fmleft>bodywid-fmwid)fm1.style.left=fmleft-=10
}

}
var bianji={
clearundo:function(){  //重置撤销内容
untext.splice(0);unyoubiao=0;untext[unyoubiao]=fm1.innerHTML;closemenu();
},
saveundo:function(){  //存储撤销内容
if(++unyoubiao>untext.length-1)unyoubiao=0
untext[unyoubiao]=fm1.innerHTML;closemenu();sm3.loadxdt()
},
undo:function(){  //撤销
if(--unyoubiao<0)unyoubiao=untext.length-1;
xdk.style.display="none";selobj=null
fm1.innerHTML=untext[unyoubiao]==null?me.outerHTML:untext[unyoubiao];closemenu();sm3.loadxdt();
},
redo:function(){  //反撤销
if(++unyoubiao>untext.length-1)unyoubiao=0
xdk.style.display="none";selobj=null
fm1.innerHTML=untext[unyoubiao]==null?me.outerHTML:untext[unyoubiao];closemenu();sm3.loadxdt();
},
xiugai:function(){  //修改对象
sd_mark=true;closemenu();var rad1=document.getElementsByName("radio1");
if(selobj.src!=null)imgsrc=selobj.src.replace(/.*\/img\/(.)/g,"$1")
xiugai1[0].value=selobj.offsetWidth;xiugai1[1].value=selobj.offsetHeight
xiugai1[2].value=selobj.offsetLeft;xiugai1[3].value=selobj.offsetTop
xiugai1[4].value=selobj.style.zIndex;
if(selobj.move==null){xiugai1[5].selectedIndex=0}else{
for(var i=0;i<xiugai1[5].options.length;i++){
if(xiugai1[5].options[i].value==selobj.move)xiugai1[5].selectedIndex=i
}}

for(var i=0;i<ciyuan.length;i++){ciyuan[i].checked=false;}if(selobj.ciyuan!=null){
var tempciyuan=selobj.ciyuan.toString().split(",");
for(var i=0;i<tempciyuan.length;i++){
ciyuan[tempciyuan[i]-1].checked=true;
}}

if(selobj.tagName=="IMG"){  //是修改图片对象
tr1[0].style.display="";tr1[1].style.display="none";xiugai1[5].style.display="";
}else if(selobj.tagName=="DIV"){  //是修改图层对象
tr1[0].style.display="none";tr1[1].style.display="";xiugai1[5].style.display="none"
}
if(selobj.dong==null){xg_dong.checked=true;xg_fanwei.disabled=true;}else{
xg_dong.checked=false;xg_fanwei.disabled=false
for(var i=0;i<xg_fanwei.options.length;i++){
if(xg_fanwei.options[i].value==selobj.fanwei){xg_fanwei.selectedIndex=i;break;}
}}
if(selobj.yincang==null){xg_yincang.checked=false}else{xg_yincang.checked=true}
switch(selobj.id){
case "dl":rad1[0].click();break;
case "npc":rad1[1].click();break;
case "boos":rad1[2].click();break;
case "pb":rad1[3].click();break;
case "shui":rad1[4].click();break;
case "xj":rad1[5].click();break;
case "aqq":rad1[6].click();break;
case "exit":rad1[7].click();break;
}
xiugaikuang.style.left=bodywid/2-(xiugaikuang.offsetWidth/2);
xiugaikuang.style.top=bodyhei/2-(xiugaikuang.offsetHeight/2)
xiugaikuang.style.visibility="visible";
},
xiugai2:function(){  //确认了修改
selobj.style.width=xiugai1[0].value;selobj.style.height=xiugai1[1].value
selobj.style.left=xiugai1[2].value;selobj.style.top=xiugai1[3].value
if(xiugai1[4].value==0){selobj.removeAttribute("z");selobj.style.zIndex=0;}else{selobj.z=xiugai1[4].value;selobj.style.zIndex=selobj.z}
if(xiugai1[5].value==""){selobj.removeAttribute("move")}else{selobj.move=xiugai1[5].value}

if(xg_dong.checked!=true)selobj.dong=true;else selobj.removeAttribute("dong");
if(selobj.dong!=null)selobj.fanwei=xg_fanwei.value;else selobj.removeAttribute("fanwei");
if(xg_yincang.checked==true)selobj.yincang=true;else selobj.removeAttribute("yincang");
selobj.removeAttribute("ciyuan");var tempciyuan=null
for(var i=0;i<ciyuan.length;i++){if(!ciyuan[i].checked)continue;
if(tempciyuan==null)tempciyuan=(i+1);else tempciyuan+=","+(i+1);
}
if(tempciyuan!=null)selobj.ciyuan=tempciyuan;

switch(radck){
case 0:selobj.id="dl"  //改为道路
selobj.src="img/"+xg_dlsrc.value;imgsrc=xg_dlsrc.value
break;
case 1:selobj.id="npc"  //改为NPC
if(xg_name1select.selectedIndex==0){
selobj.removeAttribute("pub");selobj.name1=xg_name1.value;selobj.src="img/"+xg_npcsrc.value;imgsrc=xg_npcsrc.value
xg_jq.value.replace(/ /g,"")==""?selobj.removeAttribute("msg"):selobj.msg=xg_jq.value;
xg_npcsrc3.value.replace(/ /g,"")==""?selobj.removeAttribute("face1"):selobj.face1=xg_npcsrc3.value;
}else{selobj.pub=xg_name1select.value;
switch(selobj.pub){case "传送":
selobj.name1="传送妹";selobj.src="img/npc/mpc1.gif";selobj.face1="chuansong_small.jpg";selobj.msg="jq0_1";break;
case "商店":selobj.name1="商店姐";selobj.src="img/npc/mpc2.gif";selobj.face1="shangdian_small.jpg";break;
case "仓库":selobj.name1="仓库妹";selobj.src="img/npc/mpc3.gif";selobj.face1="npc/mpc3.jpg";break;
case "技能":
selobj.name1="技能姐";selobj.src="img/npc/mpc4.gif";selobj.face1="npc/mpc4.jpg";selobj.msg="jq0_4";break;
case "强化":
selobj.name1="强化妹";selobj.src="img/npc/mpc5.gif";selobj.face1="npc/mpc5.jpg";selobj.msg="jq0_3";break;
case "锻制":
selobj.name1="锻制妹";selobj.src="img/npc/mpc6.gif";selobj.face1="npc/mpc6.jpg";selobj.msg="jq0_2";break;
case "精炼":
selobj.name1="风云舞";selobj.src="img/gw/anhei13.gif";selobj.face1="npc/mpc6.jpg";selobj.msg="jq0_6";break;
case "掉换":
selobj.name1="万华妹";selobj.src="img/gw/wanhua.gif";selobj.face1="npc/mpc6.jpg";selobj.msg="jq0_15";break;
case "任务-暗黑兄弟会":
selobj.name1="暗黑兄弟会委托";selobj.src="img/gw/anhei12.gif";selobj.face1="lihui/qingguo_small.gif";selobj.msg="jq0_7";break;
case "任务-新选组":
selobj.name1="新选组委托";selobj.src="img/gw/hani4.gif";selobj.face1="lihui/hani3_small.gif";selobj.msg="jq0_8";break;
case "任务-圣堂天团":
selobj.name1="圣堂天团委托";selobj.src="img/gw/shengyu12.gif";selobj.face1="lihui/shengtangnv_small.gif";selobj.msg="jq0_9";break;
case "任务-帝国军团":
selobj.name1="帝国军团委托";selobj.src="img/gw/diguo8.gif";selobj.face1="lihui/shangshan_small.gif";selobj.msg="jq0_10";break;
case "任务-地狱魔军":
selobj.name1="地狱魔军委托";selobj.src="img/gw/mojun14.gif";selobj.face1="lihui/monv_small.gif";selobj.msg="jq0_11";break;
case "任务-俺样公会":
selobj.name1="俺样参谋长";selobj.src="img/gw/wj9.gif";selobj.face1="lihui/canmouzhang_small.gif";selobj.msg="jq0_14";break;
}}
break;
case 2:selobj.id="boos"  //改为boos
if(xg_boosname.value=="")return alert("必须指定一个BOSS老怪！");
selobj.msg=xg_boosjq.value!=""?xg_boosjq.value:null;
selobj.boosis=xg_boosname.value
if(xg_shouxia.value==""){selobj.removeAttribute("shouxia")}else{
selobj.shouxia=xg_shouxia.value;}
if(xg_killxs.checked){selobj.killxs=true}else{
selobj.removeAttribute("killxs")}
xg_boossrc.value.replace(/ /g,"")==""?selobj.removeAttribute("face1"):selobj.face1=xg_boossrc.value;

gwdom=null;var gwdom=new ActiveXObject("Microsoft.XMLDOM");gwdom.async=false;gwdom.load("server/gw.xml");
try{var thegw=gwdom.getElementsByTagName(xg_boosname.value.replace(/\d+\=/,""))[0];
selobj.src="img/gw/"+thegw.getAttribute("src");}catch(e){alert("操作无效,不存在这个怪物,可能是你在使用怪物编辑器后没有保存更新")}
break;
case 3:selobj.id="pb";selobj.move=4  //改为屏蔽
selobj.style.background="";selobj.style.backgroundColor=xg_bkcolor.value;
xg_bkcolor.value=="black"?selobj.removeAttribute("col"):selobj.col=xg_bkcolor.value;
if(xg_bgsrc.value==""){selobj.removeAttribute("bg")}else{
selobj.bg=xg_bgsrc.value;selobj.style.backgroundImage="url('img/background/"+selobj.bg+"')"}
selobj.style.border="";selobj.innerHTML="";selobj.style.border="3 outset "+xg_bkcolor.value;
 //border-style:
break;
case 4:selobj.id="shui";selobj.move=5  //改为水域
selobj.style.backgroundImage="url('img/background/shui"+Math.ceil((new Date().getHours()+1)/6)+".gif')";selobj.style.border="";selobj.innerHTML="";
break;
case 5:var xjsunshi="";  //改为陷阱区
for(var i=0;i<xg_xjsunshi.length;i++){if(xg_xjsunshi[i].checked==true)xjsunshi+=i;}
if(xjsunshi=="")return alert("至少选择一样损害项，比如生命。");
if(xg_xjbgsrc.value.replace(/ /g,"")=="")return alert("背景图像不可不填");
selobj.xjsunshi=xjsunshi;selobj.id="xj";selobj.move=6
selobj.bgimg=xg_xjbgsrc.value;selobj.xjshanghai=xg_xjshanghai.value;
selobj.style.backgroundImage="url('img/"+selobj.bgimg+"')";selobj.style.border="";selobj.innerHTML="";
break;
case 6:selobj.id="aqq";selobj.move=14  //改为安全区
selobj.style.border="3 dotted lime";selobj.style.background="";selobj.innerHTML="";
break;
case 7:selobj.id="exit";selobj.move=15  //改为出口
selobj.style.fontSize="15px";selobj.style.fontWeight="bold"
selobj.style.textAlign="center";selobj.style.color="Red";selobj.style.backgroundImage="url('img/background/liuxing2.gif')";
selobj.style.border="1 solid gray";
selobj.exitto=xg_exitto.value;
selobj.exitx=xg_exitx.value==""?0:xg_exitx.value;
selobj.exity=xg_exity.value==""?0:xg_exity.value;
selobj.innerHTML="前往↓<p></p>"+selobj.exitto.split("+-=-+")[1]
break;
}
xiugaikuang.style.visibility="hidden";xdk.style.display="none";selobj=null;bianji.saveundo();sd_mark=false
},
add1:function(){  //插入图像
var htm=document.createElement("IMG")
htm.style.cursor="hand";htm.src="img/"+imgsrc
htm.id="dl";htm.style.left=addx;htm.style.top=addy
htm.style.width=100;htm.style.height=100
fm1.appendChild(htm);
bianji.saveundo();
},
add2:function(){  //插入图层
var htm=document.createElement("DIV")
htm.id="pb";htm.style.left=addx;htm.style.top=addy
htm.style.width=100;htm.style.height=100;htm.style.backgroundColor="gray"
htm.move=4;htm.col="gray";htm.style.border="3 outset gray"
fm1.appendChild(htm);
bianji.saveundo();
},
copy:function(jianqie){  //复制
closemenu();copyobj=selobj.outerHTML;
if(jianqie!=null){fm1.removeChild(selobj);bianji.saveundo();}
xdk.style.display="none";selobj=null
},
paste:function(){  //粘贴
if(copyobj==null)return;selobj=null;xdk.style.display="none";
if(tab1.style.display!="none"){fm1.insertAdjacentHTML("beforeEnd",copyobj.replace(/left\: (|\-)\d+px\;/gi,"left:"+(addx)+";").replace(/top\: (|\-)\d+px\;/gi,"top:"+(addy)+";"))}
else{fm1.insertAdjacentHTML("beforeEnd",copyobj.replace(/left\: (|\-)\d+px\;/gi,"left:"+(addx)+";").replace(/top\: (|\-)\d+px\;/gi,"top:"+(addy)+";"))}
bianji.saveundo();
},
del:function(){  //删除
selobj.outerHTML="";selobj=null;xdk.style.display="none";bianji.saveundo();
},
tiqian:function(){  //提前
closemenu();var htm1=selobj.outerHTML;fm1.removeChild(selobj);fm1.insertAdjacentHTML("beforeEnd",htm1);
xdk.style.display="none";selobj=null;
},
zhihou:function(){  //置后
closemenu();var htm1=selobj.outerHTML;fm1.removeChild(selobj);fm1.insertAdjacentHTML("afterBegin",htm1);
xdk.style.display="none";selobj=null;
}
}

var heimu={
show:function(zdex){  //黑幕显示
heimukuang.style.zIndex=zdex;heimukuang.style.filter="alpha(opacity=50)";heimukuang.style.display="";
},
close:function(){  //关闭
heimukuang.style.display="none";heimukuang.style.filter=null;
}}

var liulan={
menu:"",addto:null,replace1:"",oldbgsound:"",
_open:function(themulu,addto,thetopparent,thereplace){  //智能文件浏览器开启
var dirpath=(basesrc.href+themulu).replace("file:///","").replace(/(\/)/g,"\\")
heimu.show(55000);liulantitle.innerText=dirpath
liulankuang.style.left=thetopparent.offsetLeft+event.srcElement.offsetLeft+event.offsetX+30;
liulankuang.style.top=thetopparent.offsetTop+event.srcElement.offsetTop+event.offsetY
liulankuang.style.visibility="visible";sd_mark=true;
liulan.menu=themulu;liulan.addto=addto;liulan.oldbgsound=bgsound1.src;
var dir1=fsoobj.GetFolder(dirpath),ops=[]
var all1=new Enumerator(dir1.files),i=0;
while(!all1.atEnd()){if(all1.item().name.indexOf("mbs.db")==-1){
ops[i]="<option>"+all1.item().name;i++;}all1.moveNext()}
liulanselect.outerHTML='<select size="16" style="width:100%" id="liulanselect">'+ops.join("")+'</select>';
if(thereplace==null)liulan.replace1="";else liulan.replace1=thereplace;

if(liulanselect.options.length>0){liulanselect.onchange=function(){
var houzhui=liulanselect.options[liulanselect.selectedIndex].text.split(".")[1].toLowerCase()
if(houzhui!="jpg"&&houzhui!="gif"&&houzhui!="jpeg"&&houzhui!="ico"&&houzhui!="png"&&houzhui!="bmp"){bgsound1.src=themulu+liulanselect.options[liulanselect.selectedIndex].text;return liulanimg.src="img/wp/bumingwu.gif"}
liulanimg.src=themulu+liulanselect.options[liulanselect.selectedIndex].text;
};liulanbutton.disabled=false;liulanselect.selectedIndex=1;var findtxt=addto.value.replace(/.*\/(.)/g,"$1");
for(var i=0;i<liulanselect.options.length;i++){
if(liulanselect.options[i].text==findtxt){liulanselect.selectedIndex=i;break;}
}
liulanselect.onchange();
}else{liulanbutton.disabled=true}
},
_charu:function(){  //智能文件浏览器插入
liulankuang.style.visibility='hidden';heimu.close();
if(liulan.replace1=="")liulan.addto.value=liulan.menu+liulanselect.options[liulanselect.selectedIndex].text;else liulan.addto.value=(liulan.menu+liulanselect.options[liulanselect.selectedIndex].text).replace(liulan.replace1,"");
if(bgsound1.src!=liulan.oldbgsound)bgsound1.src=liulan.oldbgsound
}
}