/*
 * xhEditor - WYSIWYG XHTML Editor
 * @requires jQuery v1.3.2
 * 
 * @author Yanis.Wang<yanis.wang@gmail.com>
 * @site http://pirate9.com/
 * @licence LGPL(http://www.opensource.org/licenses/lgpl-license.php)
 * 
 * @Version: 1.0.0 beta build 100110
 */
(function(h){h.fn.xheditor=function(i,s){return this.each(function(){if(this.tagName.toLowerCase()!="textarea"){return}if(i){if(!this.objxhe){var J=h(this).attr("xheditor");if(J){try{eval("J="+J)}catch(K){}s=h.extend({},J,s)}var L=new h.xheditor(this,s);if(L.init()){this.objxhe=L}else{L=null}}}else{if(this.objxhe){this.objxhe.remove();this.objxhe=null}}})};var k=0,t=h.browser.msie,m=h.browser.mozilla,H=h.browser.safari,u=false,l=true;var d,C,q,j;var F,D;F=window.location.href.replace(/[\?#].*$/,"").replace(/[\/\\][^\/]*$/,"");F+="/";var G=h("script[src*=xheditor]"),p;for(var A=0;A<G.length;A++){p=G[A].src;if(p.match(/xheditor[^\/]*\.js/i)){D=p.replace(/[\?#].*$/,"").replace(/(^|[\/\\])[^\/]*$/,"");if(D!=""){D+="/"}break}}var E={27:"esc",9:"tab",32:"space",13:"return",8:"backspace",145:"scroll",20:"capslock",144:"numlock",19:"pause",45:"insert",36:"home",46:"del",35:"end",33:"pageup",34:"pagedown",37:"left",38:"up",39:"right",40:"down",112:"f1",113:"f2",114:"f3",115:"f4",116:"f5",117:"f6",118:"f7",119:"f8",120:"f9",121:"f10",122:"f11",123:"f12"};var n=["#FFFFFF","#E5E4E4","#D9D8D8","#C0BDBD","#A7A4A4","#8E8A8B","#827E7F","#767173","#5C585A","#000000","#FEFCDF","#FEF4C4","#FEED9B","#FEE573","#FFED43","#F6CC0B","#E0B800","#C9A601","#AD8E00","#8C7301","#FFDED3","#FFC4B0","#FF9D7D","#FF7A4E","#FF6600","#E95D00","#D15502","#BA4B01","#A44201","#8D3901","#FFD2D0","#FFBAB7","#FE9A95","#FF7A73","#FF483F","#FE2419","#F10B00","#D40A00","#940000","#6D201B","#FFDAED","#FFB7DC","#FFA1D1","#FF84C3","#FF57AC","#FD1289","#EC0078","#D6006D","#BB005F","#9B014F","#FCD6FE","#FBBCFF","#F9A1FE","#F784FE","#F564FE","#F546FF","#F328FF","#D801E5","#C001CB","#8F0197","#E2F0FE","#C7E2FE","#ADD5FE","#92C7FE","#6EB5FF","#48A2FF","#2690FE","#0162F4","#013ADD","#0021B0","#D3FDFF","#ACFAFD","#7CFAFF","#4AF7FE","#1DE6FE","#01DEFF","#00CDEC","#01B6DE","#00A0C2","#0084A0","#EDFFCF","#DFFEAA","#D1FD88","#BEFA5A","#A8F32A","#8FD80A","#79C101","#3FA701","#307F00","#156200","#D4C89F","#DAAD88","#C49578","#C2877E","#AC8295","#C0A5C4","#969AC2","#92B7D7","#80ADAF","#9CA53B"];var B=[{n:"p",t:"普通段落"},{n:"h1",t:"标题1"},{n:"h2",t:"标题2"},{n:"h3",t:"标题3"},{n:"h4",t:"标题4"},{n:"h5",t:"标题5"},{n:"h6",t:"标题6"},{n:"pre",t:"已编排格式"},{n:"address",t:"地址"}];var c=[{n:"宋体",c:"SimSun"},{n:"仿宋体",c:"FangSong_GB2312"},{n:"黑体",c:"SimHei"},{n:"楷体",c:"KaiTi_GB2312"},{n:"微软雅黑",c:"Microsoft YaHei"},{n:"Arial"},{n:"Arial Narrow"},{n:"Arial Black"},{n:"Comic Sans MS"},{n:"Courier New"},{n:"System"},{n:"Times New Roman"},{n:"Tahoma"},{n:"Verdana"}];var x=[{n:"xx-small",wkn:"x-small",s:"8pt",t:"极小"},{n:"x-small",wkn:"small",s:"10pt",t:"特小"},{n:"small",wkn:"medium",s:"12pt",t:"小"},{n:"medium",wkn:"large",s:"14pt",t:"中"},{n:"large",wkn:"x-large",s:"18pt",t:"大"},{n:"x-large",wkn:"xx-large",s:"24pt",t:"特大"},{n:"xx-large",wkn:"-webkit-xxx-large",s:"36pt",t:"极大"}];var e=[{s:"左对齐",v:"justifyleft",t:"左对齐"},{s:"居中",v:"justifycenter",t:"居中"},{s:"右对齐",v:"justifyright",t:"右对齐"},{s:"两端对齐",v:"justifyfull",t:"两端对齐"}],f=[{s:"数字列表",v:"insertOrderedList",t:"数字列表"},{s:"符号列表",v:"insertUnorderedList",t:"符号列表"}];var a='<div>使用键盘快捷键(Ctrl+V)把内容粘贴到方框里，按 确定</div><div><textarea id="xhePastetextValue" wrap="soft" spellcheck="false" style="width:300px;height:100px;" /></div><div style="text-align:right;"><input type="button" id="xheSave" value="确定" /></div>';var b='<div>链接地址: <input type="text" id="xheLinkHref" value="http://" class="xheText" /></div><div>打开方式: <select id="xheLinkTarget"><option selected="selected" value="">默认</option><option value="_blank">新窗口</option><option value="_self">当前窗口</option><option value="_parent">父窗口</option></select></div><div style="display:none">链接文字: <input type="text" id="xheLinkText" value="" class="xheText" /></div><div style="text-align:right;"><input type="button" id="xheSave" value="确定" /></div>';var z='<div>图片文件：<input type="text" id="xheImgSrc" value="http://" class="xheText" /></div><div>替换文本：<input type="text" id="xheImgAlt" /></div><div>对齐方式：<select id="xheImgAlign"><option selected="selected" value="">默认</option><option value="left">左对齐</option><option value="right">右对齐</option><option value="top">顶端</option><option value="middle">居中</option><option value="baseline">基线</option><option value="bottom">底边</option></select></div><div>宽度高度：<input type="text" id="xheImgWidth" style="width:40px;" /> x <input type="text" id="xheImgHeight" style="width:40px;" /></div><div>边框大小：<input type="text" id="xheImgBorder" style="width:40px;" /></div><div>水平间距：<input type="text" id="xheImgHspace" style="width:40px;" /> 垂直间距：<input type="text" id="xheImgVspace" style="width:40px;" /></div><div style="text-align:right;"><input type="button" id="xheSave" value="确定" /></div>';var I='<div>动画文件：<input type="text" id="xheFlashSrc" value="http://" class="xheText" /></div><div>宽度高度：<input type="text" id="xheFlashWidth" style="width:40px;" value="480" /> x <input type="text" id="xheFlashHeight" style="width:40px;" value="400" /></div><div style="text-align:right;"><input type="button" id="xheSave" value="确定" /></div>';var y='<div>媒体文件：<input type="text" id="xheMediaSrc" value="http://" class="xheText" /></div><div>宽度高度：<input type="text" id="xheMediaWidth" style="width:40px;" value="480" /> x <input type="text" id="xheMediaHeight" style="width:40px;" value="400" /></div><div style="text-align:right;"><input type="button" id="xheSave" value="确定" /></div>';var g='<div>行数列数：<input type="text" id="xheTableRows" style="width:40px;" value="3" /> x <input type="text" id="xheTableColumns" style="width:40px;" value="2" /></div><div>标题单元：<select id="xheTableHeaders"><option selected="selected" value="">无</option><option value="row">第一行</option><option value="col">第一列</option><option value="both">第一行和第一列</option></select></div><div>宽度高度：<input type="text" id="xheTableWidth" style="width:40px;" value="200" /> x <input type="text" id="xheTableHeight" style="width:40px;" value="" /></div><div>边框大小：<input type="text" id="xheTableBorder" style="width:40px;" value="1" /></div><div>表格间距：<input type="text" id="xheTableCellSpacing" style="width:40px;" value="1" /> 表格填充：<input type="text" id="xheTableCellPadding" style="width:40px;" value="1" /></div><div>对齐方式：<select id="xheTableAlign"><option selected="selected" value="">默认</option><option value="left">左对齐</option><option value="center">居中</option><option value="right">右对齐</option></select></div><div>表格标题：<input type="text" id="xheTableCaption" /></div><div style="text-align:right;"><input type="button" id="xheSave" value="确定" /></div>';var r='<div style="width:200px;word-wrap:break-word;word-break:break-all;"><p><span style="font-size:20px;color:#1997DF;">xhEditor</span><br />版本：v1.0.0 beta build 100110</p><p>xhEditor是一个基于jQuery开发的跨平台开源迷你XHTML编辑器组件。</p><p><a href="http://xheditor.com/" target="_blank">http://xheditor.com/</a></p></div>';var o=[{t:"em0",s:"em0.gif"},{t:"em1",s:"em1.gif"},{t:"em2",s:"em2.gif"},{t:"em3",s:"em3.gif"},{t:"em4",s:"em4.gif"},{t:"em5",s:"em5.gif"},{t:"em6",s:"em6.gif"},{t:"em7",s:"em7.gif"},{t:"em8",s:"em8.gif"},{t:"em9",s:"em9.gif"},{t:"em10",s:"em10.gif"},{t:"em11",s:"em11.gif"},{t:"em12",s:"em12.gif"},{t:"em13",s:"em13.gif"},{t:"em14",s:"em14.gif"},{t:"em15",s:"em15.gif"},{t:"em16",s:"em16.gif"},{t:"em17",s:"em17.gif"},{t:"em18",s:"em18.gif"},{t:"em19",s:"em19.gif"},{t:"em20",s:"em20.gif"},{t:"em21",s:"em21.gif"},{t:"em22",s:"em22.gif"},{t:"em23",s:"em23.gif"},{t:"em24",s:"em24.gif"},{t:"em25",s:"em25.gif"},{t:"em26",s:"em26.gif"},{t:"em27",s:"em27.gif"},{t:"em28",s:"em28.gif"},{t:"em29",s:"em29.gif"},{t:"em30",s:"em30.gif"},{t:"em31",s:"em31.gif"},{t:"em32",s:"em32.gif"},{t:"em33",s:"em33.gif"},{t:"em34",s:"em34.gif"},{t:"em35",s:"em35.gif"},{t:"em36",s:"em36.gif"},{t:"em37",s:"em37.gif"},{t:"em38",s:"em38.gif"},{t:"em39",s:"em39.gif"},{t:"em40",s:"em40.gif"},{t:"em41",s:"em41.gif"},{t:"em42",s:"em42.gif"},{t:"em43",s:"em43.gif"},{t:"em44",s:"em44.gif"},{t:"em45",s:"em45.gif"},{t:"em46",s:"em46.gif"},{t:"em47",s:"em47.gif"},{t:"em48",s:"em48.gif"},{t:"em49",s:"em49.gif"},{t:"em50",s:"em50.gif"},{t:"em51",s:"em51.gif"},{t:"em52",s:"em52.gif"},{t:"em53",s:"em53.gif"},{t:"em54",s:"em54.gif"},{t:"em55",s:"em55.gif"}];var w={GStart:{},GEnd:{},Separator:{},Cut:{t:"剪切 (Ctrl+X)"},Copy:{t:"复制 (Ctrl+C)"},Paste:{t:"粘贴 (Ctrl+V)"},Pastetext:{t:"粘贴文本"},Blocktag:{t:"段落标签"},Fontface:{t:"字体"},FontSize:{t:"字号"},Bold:{t:"加粗 (Ctrl+B)",s:"Ctrl+B"},Italic:{t:"斜体 (Ctrl+I)",s:"Ctrl+I"},Underline:{t:"下划线 (Ctrl+U)",s:"Ctrl+U"},Strikethrough:{t:"中划线 (Ctrl+S)",s:"Ctrl+S"},FontColor:{t:"字体颜色"},BackColor:{t:"背景颜色"},Removeformat:{t:"删除文字格式"},Align:{t:"对齐"},List:{t:"列表"},Outdent:{t:"取消引用"},Indent:{t:"引用"},Link:{t:"超链接"},Unlink:{t:"取消超链接"},Img:{t:"图片"},Flash:{t:"Flash动画"},Media:{t:"多媒体文件"},Emot:{t:"表情"},Html:{t:"可以运行的html代码"},Hidden:{t:"会员可见"},Table:{t:"表格"},Source:{t:"源代码"},Preview:{t:"预览"},Fullscreen:{t:"全屏编辑 (Esc)",s:"Esc"},About:{t:"关于 xhEditor"}};var v={mini:"GStart,Fontface,FontSize,Bold,Italic,Underline,Strikethrough,FontColor,Removeformat,GEnd,Separator,GStart,Align,List,Indent,Outdent,GEnd,Separator,GStart,Link,Unlink,Img,Flash,Media,Emot,GEnd,Separator,GStart,Html,Hidden,Source,GEnd",full:"GStart,Cut,Copy,Paste,Pastetext,GEnd,Separator,GStart,Blocktag,Fontface,FontSize,Bold,Italic,Underline,Strikethrough,FontColor,BackColor,Removeformat,GEnd,Separator,GStart,Align,List,Outdent,Indent,GEnd,Separator,GStart,Link,Unlink,Img,Flash,Media,Emot,Table,GEnd,Separator,GStart,Source,Preview,Fullscreen,About,GEnd"};h.xheditor=function(Z,O){var W={skin:"default",tools:"full",clickCancelDialog:true,linkTag:false,internalScript:false,inlineScript:false,internalStyle:true,inlineStyle:true,showBlocktag:false,forcePtag:true,keepValue:true,upLinkExt:"zip,rar,txt",upImgExt:"jpg,jpeg,gif,png",upFlashExt:"swf",upMediaExt:"wmv,avi,wma,mp3,mid",modalWidth:350,modalHeight:220,modalTitle:true,baseUrl:F,defLinkText:"点击打开链接",layerShadow:3};var af=this,M=Z,ag=h(M),T=ag.closest("form"),X,s,V,am,N,ad;var U;var Y=false,R=false,K=false,al=false,ac=false,J=false,ab="",aj;var ak=0;this.settings=h.extend({},W,O);if(af.settings.plugins){w=h.extend({},w,af.settings.plugins)}if(af.settings.tools.match(/^\s*(mini|simple|full)\s*$/i)){af.settings.tools=h.trim(af.settings.tools);af.settings.tools=v[af.settings.tools]}af.settings.tools=af.settings.tools.split(",");var Q="xheCSS_"+af.settings.skin,ae="xhe"+k+"_container",i="xhe"+k+"_Tool",aa="xhe"+k+"_iframearea",ai="xhe"+k+"_iframe";var ah="",L=D+"xheditor_skin/"+af.settings.skin+"/";J=af.settings.showBlocktag;if(J){ah+=" showBlocktag"}var P=[];this.init=function(){if(h("#"+Q).length==0){h("head").append('<link id="'+Q+'" rel="stylesheet" type="text/css" href="'+L+'ui.css" />')}var aq=af.settings.width||M.style.width||ag.outerWidth();ak=af.settings.height||ag.outerHeight();if(/^[0-9\.]+$/i.test(""+aq)){aq+="px"}var ap="",au,aw;h.each(af.settings.tools,function(ax,ay){au=w[ay];if(ay=="GStart"){ap+='<span class="xheGStart"/>'}else{if(ay=="GEnd"){ap+='<span class="xheGEnd"/>'}else{if(ay=="Separator"){ap+='<span class="xheSeparator"/>'}else{if(ay=="BtnBr"){ap+="<br />"}else{if(au.c){aw=au.c}else{aw="xheIcon xheBtn"+ay}ap+='<span><a href="javascript:void(0);" title="'+au.t+'" name="'+ay+'" class="xheButton xheEnabled"><span class="'+aw+'" /></a></span>';if(au.s){af.addShortCut(au.s,ay)}}}}}});ap+="<br />";ag.after(h('<span id="'+ae+'" class="xhe_'+af.settings.skin+'" style="display:none"><table cellspacing="0" cellpadding="0" class="xheLayout" style="width:'+aq+";height:"+ak+'px;"><tbody><tr><td id="'+i+'" class="xheTool" style="height:1px;"></td></tr><tr><td id="'+aa+'" class="xheIframeArea"><iframe frameborder="0" id="'+ai+'" src="javascript:void(0);" style="width:100%;"></iframe></td></tr></tbody></table></span>'));X=h("#"+i);s=h("#"+aa);var ar='<html><head><meta content="text/html; charset=UTF-8" http-equiv="Content-Type"/><link rel="stylesheet" href="'+L+'iframe.css"/>';if(af.settings.loadCSS){var ao=af.settings.loadCSS;if(S(ao,"array")){for(var at in ao){ar+='<link rel="stylesheet" href="'+ao[at]+'"/>'}}else{ar+='<link rel="stylesheet" href="'+ao+'"/>'}}ar+="<base"+(af.settings.baseUrl!=F?' href="'+af.settings.baseUrl+'"':"")+' /></head><body spellcheck="false" dir="ltr" class="editMode'+ah+'"></body></html>';V=h("#"+ai)[0].contentWindow;am=h(V);try{N=V.document;ad=h(N);N.open();N.write(ar);N.close();if(t){N.body.contentEditable="true"}else{N.designMode="On"}}catch(av){}setTimeout(af.setOpts,300);af.setSource();V.setInterval=null;X.append(ap);X.find(".xheButton").click(function(ay){af.hidePanel();af.focus();aj=ay;var ax=h(this);if(ax.is(".xheEnabled")){af.exec(ax.attr("name"))}return false}).mousedown(function(){return false});d=h("#xhePanel");C=h("#xheShadow");q=h("#xheCntLine");if(d.length==0){d=h('<div id="xhePanel"></div>').mousedown(function(ax){ax.stopPropagation()});C=h('<div id="xheShadow"></div>');q=h('<div id="xheCntLine"><img src="'+L+'img/spacer.gif" /></div>');h(document.body).append(d).append(C).append(q)}h(document).mousedown(af.clickCancelPanel);ad.mousedown(af.clickCancelPanel);if(t){ad.bind("beforedeactivate",function(){if(t&&!R){U=af.getRng()}});am.focus(function(){if(t&&!R&&U){U.select();U=null}})}h("#"+ae).show();s.css("height",ak-X.outerHeight());ag.hide();ag.focus(af.focus);T.submit(af.getSource).bind("reset",af.setSource);var an=h(window);an.unload(af.getSource).bind("beforeunload",af.getSource);an.resize(af.fixFullHeight);am.focus(function(){if(af.settings.focus){af.settings.focus()}}).blur(function(){if(af.settings.blur){af.settings.blur()}});if(H){am.click(af.fixAppleSel)}ad.keydown(af.checkShortCut).keydown(af.forcePtag);k++;Y=true;if(af.settings.fullscreen){af.toggleFullscreen()}if(af.settings.readonly){af.toggleReadonly(true)}else{if(af.settings.sourceMode){setTimeout(af.toggleSource,20)}}return true};this.remove=function(){ag.unbind("focus",af.focus);T.unbind("submit",af.getSource).unbind("reset",af.setSource);var an=h(window);an.unbind("unload",af.getSource).unbind("beforeunload",af.getSource);an.unbind("resize",af.fixFullHeight);if(H){am.unbind("click",af.fixAppleSel)}ad.unbind("keydown",af.checkShortCut).unbind("keydown",af.forcePtag);h("#"+ae).remove();ag.show();Y=false};this.setCSS=function(an){try{af._exec("styleWithCSS",an)}catch(ao){try{af._exec("useCSS",!an)}catch(ao){}}};this.setOpts=function(){if(Y&&!K&&!R){af.setCSS(false);try{af._exec("enableObjectResizing",true)}catch(an){}try{af._exec("enableInlineTableEditing",false)}catch(an){}if(t){try{af._exec("BackgroundImageCache",true)}catch(an){}}}};this.forcePtag=function(ao){if(R||K||ao.keyCode!=13||ao.shiftKey||ao.ctrlKey||ao.altKey){return true}var an=af.getParent("p,h1,h2,h3,h4,h5,h6,pre,address,div,li");if(af.settings.forcePtag){if(an.length==0){af._exec("formatblock","<p>")}}else{af.pasteHTML("<br />");return false}};this.innsertHtml=function(){af.appendHTML("[html]<br />请在这里输入可以执行的html代码<br />\[/html]")};this.innsertHidden=function(){af.appendHTML("<hr class=\"hidden\" \/>在此输入会员可见内容。<hr class=\"hidden\" \/>")};this.fixFullHeight=function(){if(!m&&!H){s.height("100%");if(al){s.css("height",s.outerHeight()-X.outerHeight())}if(t){X.hide().show()}}};this.fixAppleSel=function(ap){ap=ap.target;if(ap.tagName.match(/(img|embed)/i)){var ao=af.getSel(),an=N.createRange();an.selectNode(ap);ao.removeAllRanges();ao.addRange(an)}};this.focus=function(){if(!R){am.focus()}else{h("#sourceCode",N).focus()}return false};this.getSel=function(){return V.getSelection?V.getSelection():N.selection};this.getRng=function(){var ap=af.getSel(),an;try{an=ap.rangeCount>0?ap.getRangeAt(0):(ap.createRange?ap.createRange():N.createRange())}catch(ao){}if(!an){an=t?N.body.createTextRange():N.createRange()}return an};this.getParent=function(an){var ao=af.getRng(),ap;if(!t){ap=ao.commonAncestorContainer;if(!ao.collapsed){if(ao.startContainer==ao.endContainer&&ao.startOffset-ao.endOffset<2&&ao.startContainer.hasChildNodes()){ap=ao.startContainer.childNodes[ao.startOffset]}}}else{ap=ao.item?ao.item(0):ao.parentElement()}an=an?an:"*";ap=h(ap);if(!ap.is(an)){ap=h(ap).closest(an)}return ap};this.getSelect=function(ar){var aq=af.getSel(),an=af.getRng(),ao=true;if(!an||an.item){ao=false}else{ao=!aq||an.boundingWidth==0||an.collapsed}if(ar=="text"){return ao?"":(an.text||(aq.toString?aq.toString():""))}var at;if(an.cloneContents){var ap=h("<div></div>"),au;au=an.cloneContents();if(au){ap.append(au)}at=ap.html()}else{if(S(an.item)){at=an.item(0).outerHTML}else{if(S(an.htmlText)){at=an.htmlText}else{at=an.toString()}}}at=af.processHTML(at,"read");at=af.cleanHTML(at);at=af.formatXHTML(at);return at};function S(ao,an){var ap=typeof(ao);if(!an){return ap!="undefined"}if(an=="array"&&(ao.hasOwnProperty&&ao instanceof Array)){return true}return ap==an}this.pasteHTML=function(aq){if(R||K){return false}af.focus();aq=af.processHTML(aq,"write");var an=af.getRng();aq+='<span id="__caret" />';if(an.insertNode){an.deleteContents();an.insertNode(an.createContextualFragment(aq))}else{an.pasteHTML(aq)}var ao=h("#__caret",N),ar=ao[0],ap=af.getSel();if(t){an.moveToElementText(ar);an.select()}else{an.selectNode(ar);ap.removeAllRanges();ap.addRange(an)}ao.remove()};this.pasteText=function(an){if(!an){an=""}an=af.domEncode(an);an=an.replace(/\r?\n/g,"<br>");af.pasteHTML(an)};this.appendHTML=function(an){if(R||K){return false}af.focus();an=af.processHTML(an,"write");h(N.body).append(an)};this.domEncode=function(ao){if(ao){var an={"<":"&lt;",">":"&gt;"};ao=ao.replace(/[<>]/g,function(ap){return an[ap]})}return ao};this.setSource=function(an){setTimeout(function(){af._setSource(an)},10)};this._setSource=function(an){U=null;if(typeof an!="string"&&an!=""){an=ag.val()}if(R){h("#sourceCode",N).val(an)}else{if(af.settings.beforeSetSource){an=af.settings.beforeSetSource(an)}an=af.formatXHTML(an);h(N.body)[0].innerHTML=af.processHTML(an,"write")}};this.processHTML=function(av,au){var aq=' class="Apple-style-span"';if(au=="write"){if(af.settings.keepValue){function an(az,aw,ay,aC,aA,ax,aB){ay+=" _xhe_"+aC+'="'+ax+'"';return"<"+aw+ay+" "+aB+">"}av=av.replace(/<(\w+(?:\:\w+)?)(\s+[^>]*?(src|href)\s*=\s*(['"]?)\s*([^"\s]*)\s*\4[^\/>]*?)(\/?)>/ig,an)}av=av.replace(/<(\/?)del( [^>]+)?>/ig,"<$1strike$2>");if(m){av=av.replace(/<(\/?)strong( [^>]+)?>/ig,"<$1b$2>");av=av.replace(/<(\/?)em( [^>]+)?>/ig,"<$1i$2>")}else{if(H){av=av.replace(/("|;)\s*font-size\s*:\s*([a-z-]+)(;?)/ig,function(aA,aC,aw,aB){var ay,az;for(var ax=0;ax<x.length;ax++){ay=x[ax];if(aw==ay.n){az=ay.wkn;break}}return aC+"font-size:"+az+aB});av=av.replace(/<strong( [^>]+)?>/ig,"<span"+aq+' style="font-weight: bold;"$1>');av=av.replace(/<em( [^>]+)?>/ig,"<span"+aq+' style="font-style: italic;"$1>');av=av.replace(/<u( [^>]+)?>/ig,"<span"+aq+' style="text-decoration: underline;"$1>');av=av.replace(/<strike( [^>]+)?>/ig,"<span"+aq+' style="text-decoration: line-through;"$1>');av=av.replace(/<\/(strong|em|u|strike)>/ig,"</span>");av=av.replace(/<span((?:\s+[^>]+)?\s+style="([^"]*;)*\s*(font-family|font-size|color|background-color)\s*:\s*[^;"]+\s*;?"[^>]*)>/ig,"<span"+aq+"$1>")}else{if(t){av=av.replace(/&apos;/ig,"&#39;");av=av.replace(/\s+(disabled|checked|readonly|selected)\s*=\s*[\"\']?(false|0)[\"\']?/ig,"")}}}av=av.replace(/<a(\s+[^>]+)?\/>/,"<a$1></a>");if(!H){function ar(aC,aG,aw,az){var aF="",ay,aE,aD,aB;ay=aw.match(/font-family\s*:\s*([^;"]+)/i);if(ay){aF+=' face="'+ay[1]+'"'}aE=aw.match(/font-size\s*:\s*([^;"]+)/i);if(aE){aE=aE[1].toLowerCase();for(var ax=0;ax<x.length;ax++){if(aE==x[ax].n||aE==x[ax].s){aD=ax+1;break}}if(aD){aF+=' size="'+aD+'"';aw=aw.replace(/(^|;)(\s*font-size\s*:\s*[^;"]+;?)+/ig,"$1")}}aB=aw.match(/(?:^|[\s;])color\s*:\s*([^;"]+)/i);if(aB){var aA;if(aA=aB[1].match(/rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/i)){aA=Number(aA[1])*65536+Number(aA[2])*256+Number(aA[3]);aA=aA.toString(16);while(aA.length<6){aA="0"+aA}aB[1]="#"+aA}else{if(aA=aB[1].match(/^#([0-9a-f])([0-9a-f])([0-9a-f])$/i)){aB[1]="#"+aA[1]+aA[1]+aA[2]+aA[2]+aA[3]+aA[3]}}aF+=' color="'+aB[1]+'"'}aw=aw.replace(/(^|;)(\s*(font-family|color)\s*:\s*[^;"]+;?)+/ig,"$1");if(aF!=""){if(aw){aF+=' style="'+aw+'"'}return"<font"+aF+">"+az+"</font>"}else{return aC}}av=av.replace(/<(span)(?:\s+[^>]+)? style="((?:[^"]*?;)*\s*(?:font-family|font-size|color)\s*:[^"]*)"(?: [^>]+)?>(((?!<\1(\s+[^>]+)?>)[\s\S])*?)<\/\1>/ig,ar);av=av.replace(/<(span)(?:\s+[^>]+)? style="((?:[^"]*?;)*\s*(?:font-family|font-size|color)\s*:[^"]*)"(?: [^>]+)?>(((?!<\1(\s+[^>]+)?>)[\s\S]|<\1(\s+[^>]+)?>((?!<\1(\s+[^>]+)?>)[\s\S])*?<\/\1>)*?)<\/\1>/ig,ar);av=av.replace(/<(span)(?:\s+[^>]+)? style="((?:[^"]*?;)*\s*(?:font-family|font-size|color)\s*:[^"]*)"(?: [^>]+)?>(((?!<\1(\s+[^>]+)?>)[\s\S]|<\1(\s+[^>]+)?>((?!<\1(\s+[^>]+)?>)[\s\S]|<\1(\s+[^>]+)?>((?!<\1(\s+[^>]+)?>)[\s\S])*?<\/\1>)*?<\/\1>)*?)<\/\1>/ig,ar)}}else{if(af.settings.keepValue){function ao(az,aw,ay,aB,aA,ax){ay=ay.replace(new RegExp("\\s+"+aB+"\\s*=\\s*([\"']?)[^\\1\\s]*\\1","ig")," "+aB+'="'+ax.replace(/\$/g,"$$$$")+'"');return"<"+aw+ay+">"}av=av.replace(/<(\w+(?:\:\w+)?)(\s+[^>]*?_xhe_(src|href)\s*=\s*(['"]?)\s*([^\4\s]*)\s*\4[^>]*)>/ig,ao)}if(H){av=av.replace(/("|;)\s*font-size\s*:\s*([a-z-]+)(;?)/ig,function(aA,aC,aw,aB){var ay,az;for(var ax=0;ax<x.length;ax++){ay=x[ax];if(aw==ay.wkn){az=ay.n;break}}return aC+"font-size:"+az+aB});var at=[{r:/font-weight:\sbold/ig,t:"strong"},{r:/font-style:\sitalic/ig,t:"em"},{r:/text-decoration:\sunderline/ig,t:"u"},{r:/text-decoration:\sline-through/ig,t:"strike"}];function ap(aC,ax,az,ay,aD){var aw=az+ay,aB="";for(var aA=0;aA<at.length;aA++){if(aw.match(at[aA].r)){aB=at[aA].t;break}}if(aB){return"<"+aB+">"+aD+"</"+aB+">"}else{return aC}}av=av.replace(/<(span)(\s+[^>]+|)? class="Apple-style-span"(\s+[^>]+|)?>(((?!<\1(\s+[^>]+)?>)[\s\S])*?)<\/\1>/ig,ap);av=av.replace(/<(span)(\s+[^>]+|)? class="Apple-style-span"(\s+[^>]+|)?>(((?!<\1(\s+[^>]+)?>)[\s\S]|<\1(\s+[^>]+)?>((?!<\1(\s+[^>]+)?>)[\s\S])*?<\/\1>)*?)<\/\1>/ig,ap);av=av.replace(/<(span)(\s+[^>]+|)? class="Apple-style-span"(\s+[^>]+|)?>(((?!<\1(\s+[^>]+)?>)[\s\S]|<\1(\s+[^>]+)?>((?!<\1(\s+[^>]+)?>)[\s\S]|<\1(\s+[^>]+)?>((?!<\1(\s+[^>]+)?>)[\s\S])*?<\/\1>)*?<\/\1>)*?)<\/\1>/ig,ap)}av=av.replace(/(\s+)(?:_xhe_|_moz_|_webkit_)[^=]+?\s*=\s*(["']?)[^\2\s>]*\2\s*/ig,"$1");av=av.replace(/<(\w+[^>]*?)\s+class="?(?:apple|webkit)\-[^ >]*([^>]*?)>/ig,"<$1$2>")}return av};this.getSource=function(){var an;if(R){an=h("#sourceCode",N).val()}else{an=af.processHTML(h(N.body).html(),"read");an=af.cleanWord(an);an=af.cleanHTML(an);an=af.formatXHTML(an);if(af.settings.beforeGetSource){an=af.settings.beforeGetSource(an)}}ag.val(an);return an};this.cleanWord=function(an){if(an.match(/mso-|MsoNormal/i)){an=an.replace(/<!--([\s\S]*?)-->|<style(\s+[^>]+)?>[\s\S]*?<\/style>/ig,"");an=an.replace(/<\/?\w+:[^>]*>/ig,"");an=an.replace(/<(\w+[^>]*?)\s+class="?mso[^ >]*([^>]*?)>/ig,"<$1$2>");an=an.replace(/<(\w+[^>]*?)\s+lang="?[^ \>]*([^>]*?)>/ig,"<$1$2>");an=an.replace(/<(\w+[^>]*?)\s+align="?left"?([^>]*?)>/ig,"<$1$2>");an=an.replace(/\s*mso-[^:]+:[^;"]+;?\s*/ig,"");an=an.replace(/\s*margin: 0cm 0cm 0pt\s*;\s*/ig,"");an=an.replace(/\s*margin: 0cm 0cm 0pt\s*"/ig,'"');an=an.replace(/\s*text-align:[^;"]+;?\s*/ig,"");an=an.replace(/\s*font-variant:[^;"]+;?\s*/ig,"");an=an.replace(/<(\w+[^>]*?)\s+style="?"?(\s+|>)/ig,"<$1$2");an=an.replace(/<(\w+[^>]*?)\s+style="?\s*([^">]+)\s*"?([^>]*?)>/ig,function(aq,ap,ar,ao){return"<"+ap+' style="'+ar.replace(/&quot;/ig,"")+'"'+ao+">"})}return an};this.cleanHTML=function(ao){ao=ao.replace(/<\??xml(:\w+)?( [^>]+)?>([\s\S]*?<\/xml>)?/ig,"");ao=ao.replace(/<(meta|title)(\s+[^>]+)?>/ig,"");if(!af.settings.linkTag){ao=ao.replace(/<link(\s+[^>]+)?>/ig,"")}if(!af.settings.internalScript){ao=ao.replace(/<(script)(\s+[^>]+)?>(((?!<\1(\s+[^>]+)?>)[\s\S]|<\1(\s+[^>]+)?>((?!<\1(\s+[^>]+)?>)[\s\S]|<\1(\s+[^>]+)?>((?!<\1(\s+[^>]+)?>)[\s\S])*?<\/\1>)*?<\/\1>)*?)<\/\1>/ig,"")}if(!af.settings.inlineScript){ao=ao.replace(/<(\w+)(\s+[^>]+?)?\s+on(?:click|dblclick|mousedown|mouseup|mousemove|mouseover|mouseout|mouseenter|mouseleave|keydown|keypress|keyup|change|select|submit|reset|blur|focus|load|unload)\s*=\s*(["']?)[^"']*?\3(\s+[^>]+?)?>/ig,"<$1$2$4>")}if(!af.settings.internalStyle){ao=ao.replace(/<(style)(\s+[^>]+)?>(((?!<\1(\s+[^>]+)?>)[\s\S]|<\1(\s+[^>]+)?>((?!<\1(\s+[^>]+)?>)[\s\S]|<\1(\s+[^>]+)?>((?!<\1(\s+[^>]+)?>)[\s\S])*?<\/\1>)*?<\/\1>)*?)<\/\1>/ig,"")}if(!af.settings.inlineStyle){ao=ao.replace(/<(\w+)(\s+[^>]+?)?\s+style\s*=\s*(["']?)[^"']*?\3(\s+[^>]+?)?>/ig,"<$1$2$4>")}for(var an=0;an<3;an++){ao=ao.replace(/<(strong|b|u|del|strike|s|em|i)(?:\s+[^>]+)?>(((?!<\1(\s+[^>]+)?>)([ \t\r\n]|&nbsp;))*?)<\/\1>/ig,function(aq,ap,ar){if(ar.match(/&nbsp;/i)){return ar.replace(/ +/g,"")}else{return""}})}ao=ao.replace(/<\/(strong|b|u|strike|em|i)>((?:\s|<br\/?>|&nbsp;)*?)<\1>/ig,"$2");ao=ao.replace(/<(p|div)(?:\s+[^>]+)?>(((?!<\1(?: [^>]+)?>)[\s\S])+?)<\/\1>/ig,function(ar,ap,at){var aq=at.replace(/<\/?(span|strong|b|u|strike|em|i)(\s+[^>]+)?>/ig,"");aq=aq.replace(/([ \t\r\n]|&nbsp;)+/ig,"");if(aq!=""){return ar}else{return"<"+ap+"></"+ap+">"}});ao=ao.replace(/^(\r?\n)+/g,"");ao=ao.replace(/(\r?\n)+/g,"\r\n");ao=ao.replace(/\s+$/g,"");return ao};this.formatXHTML=function(aA){var aw=az("area,base,basefont,br,col,frame,hr,img,input,isindex,link,meta,param,embed");var ap=az("address,applet,blockquote,button,center,dd,dir,div,dl,dt,fieldset,form,frameset,hr,iframe,ins,isindex,li,map,menu,noframes,noscript,object,ol,p,pre,script,table,tbody,td,tfoot,th,thead,tr,ul");var an=az("a,abbr,acronym,applet,b,basefont,bdo,big,br,button,cite,code,del,dfn,em,font,i,iframe,img,input,ins,kbd,label,map,object,q,s,samp,script,select,small,span,strike,del,strong,sub,sup,textarea,tt,u,var");var aJ=az("colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr");var ax=az("checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected");var aI=az("script,style");var ao={b:"strong",i:"em",s:"del",strike:"del"};var aF=/^<(\w+(?:\:\w+)?)((?:\s+[\w-\:]*(?:\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|[^>\s]+))?)*)\s*(\/?)>/;var au=/^<\/(\w+(?:\:\w+)?)[^>]*>/;var aD=/([\w-(?:\:\w+)?]+)(?:\s*=\s*(?:(?:"((?:\\.|[^"])*)")|(?:'((?:\\.|[^'])*)')|([^>\s]+)))?/g;var ar,aC=0,aq=[],av=aA,ay="",aB=[];aq.last=function(){return this[this.length-1]};while(aA){if(!aq.last()||!aI[aq.last()]){aC=0;if(aA.indexOf("<!")==0){match=aA.match(/^<!(?:--)?([\s\S]*?)(?:--)?>/);if(match){aC=match[0].length;aB.push("<!--"+match[1]+"-->")}else{aC=1}}else{if(aA.indexOf("</")==0){match=aA.match(au);if(match){aC=match[0].length;match[0].replace(au,aG)}else{aC=1}}else{if(aA.indexOf("<")==0){match=aA.match(aF);if(match){aC=match[0].length;match[0].replace(aF,aH)}else{aC=1}}}}if(aC==1){aB.push("&lt;")}if(aC>0){aA=aA.substring(aC)}else{ar=aA.search(/<[^<>]+>/);ay=ar<0?aA:aA.substring(0,ar);aA=ar<0?"":aA.substring(ar);aB.push(af.domEncode(ay))}}else{aA=aA.replace(/^([\s\S]*?)<\/(?:style|script)>/i,function(aK,aL){aB.push(aL);return""});aG("",aq.last())}av=aA}aG();aA=aB.join("");function az(aN){var aM={},aK=aN.split(",");for(var aL=0;aL<aK.length;aL++){aM[aK[aL]]=true}return aM}function at(aL){if(aL){aL=aL.toLowerCase();var aK=ao[aL];if(aK){aL=aK}}else{aL=""}return aL}function aH(aK,aM,aN,aL){aM=at(aM);if(ap[aM]){while(aq.last()&&an[aq.last()]){aG("",aq.last())}}if(aJ[aM]&&aq.last()==aM){aG("",aM)}aL=aw[aM]||!!aL;if(!aL){aq.push(aM)}aB.push("<"+aM);aN.replace(aD,function(aP,aO){aO=aO.toLowerCase();var aQ=arguments[2]?arguments[2]:arguments[3]?arguments[3]:arguments[4]?arguments[4]:ax[aO]?aO:"";if(aQ){aB.push(" "+aO+'="'+aQ.replace(/(^|[^\\])"/g,'$1\\"')+'"')}});aB.push((aL?" /":"")+">")}function aG(aK,aM){if(!aM){var aN=0}else{aM=at(aM);for(var aN=aq.length-1;aN>=0;aN--){if(aq[aN]==aM){break}}}if(aN>=0){for(var aL=aq.length-1;aL>=aN;aL--){aB.push("</"+aq[aL]+">")}aq.length=aN}}function aE(aO,aS,aP,aM){var aQ="",aL,aR,aN,aK;aL=aP.match(/ face\s*=\s*"\s*([^"]+)\s*"/i);if(aL){aQ+="font-family:"+aL[1]+";"}aR=aP.match(/ size\s*=\s*"\s*(\d+)\s*"/i);if(aR){aQ+="font-size:"+x[aR[1]-1].n+";"}aN=aP.match(/ color\s*=\s*"\s*([^"]+)\s*"/i);if(aN){aQ+="color:"+aN[1]+";"}aK=aP.match(/ style\s*=\s*"\s*([^"]+)\s*"/i);if(aK){aQ+=aK[1]}if(aQ){aM='<span style="'+aQ+'">'+aM+"</span>"}return aM}aA=aA.replace(/<(font)(\s+[^>]+|)?>(((?!<\1(\s+[^>]+)?>)[\s\S])*?)<\/\1>/ig,aE);aA=aA.replace(/<(font)(\s+[^>]+|)?>(((?!<\1(\s+[^>]+)?>)[\s\S]|<\1(\s+[^>]+)?>((?!<\1(\s+[^>]+)?>)[\s\S])*?<\/\1>)*?)<\/\1>/ig,aE);aA=aA.replace(/<(font)(\s+[^>]+|)?>(((?!<\1(\s+[^>]+)?>)[\s\S]|<\1(\s+[^>]+)?>((?!<\1(\s+[^>]+)?>)[\s\S]|<\1(\s+[^>]+)?>((?!<\1(\s+[^>]+)?>)[\s\S])*?<\/\1>)*?<\/\1>)*?)<\/\1>/ig,aE);return aA};this.toggleShowBlocktag=function(ao){if(J===ao){return}J=!J;var an=h(N.body);if(J){ah+=" showBlocktag";an.addClass("showBlocktag")}else{ah=ah.replace(" showBlocktag","");an.removeClass("showBlocktag")}};this.toggleReadonly=function(an){if(ac===an){return}if(R){af.toggleSource(true)}ac=!ac;if(ac){if(!K){af.togglePreview(true)}X.find("[name=Preview]").toggleClass("xheEnabled").toggleClass("xheActive")}else{X.find("[name=Preview]").toggleClass("xheEnabled").toggleClass("xheActive");if(K){af.togglePreview()}}};this.toggleSource=function(ao){if(K||R===ao){return}X.find("[name=Source]").toggleClass("xheEnabled").toggleClass("xheActive");X.find(".xheButton").not("[name=Source],[name=Fullscreen],[name=About]").toggleClass("xheEnabled");if(u){af.hidePanel()}var an=h(N.body),ap=af.getSource();if(!R){if(t){N.body.contentEditable="false"}else{N.designMode="Off"}an.attr("scroll","no").attr("class","sourceMode").html('<textarea id="sourceCode" wrap="soft" spellcheck="false" height="100%" />');an.find("#sourceCode").blur(af.getSource)}else{an.find("#sourceCode").remove();if(t){N.body.contentEditable="true"}else{N.designMode="On";if(m){af._exec("inserthtml","-")}}an.removeAttr("scroll").attr("class","editMode"+ah);setTimeout(function(){V.scrollTo(0,0)},10)}R=!R;af._setSource(ap);X.find("[name=Source]").toggleClass("xheEnabled");setTimeout(af.setOpts,300)};this.togglePreview=function(ao){if(R||K===ao){return}X.find("[name=Preview]").toggleClass("xheActive").toggleClass("xheEnabled");X.find(".xheButton").not("[name=Preview],[name=Fullscreen],[name=About]").toggleClass("xheEnabled");var an=h(N.body);if(!K){if(t){N.body.contentEditable="false"}else{N.designMode="Off"}an.attr("class","previewMode");an[0].innerHTML=an.html();h("head base",N).attr("target","_blank")}else{if(t){N.body.contentEditable="true"}else{N.designMode="On"}an.attr("class","editMode"+ah);an[0].innerHTML=an.html();h("head base",N).removeAttr("target")}K=!K;X.find("[name=Preview]").toggleClass("xheEnabled");setTimeout(af.setOpts,300)};this.toggleFullscreen=function(ap){if(al===ap){return}if(u){af.hidePanel()}var ao=h("#"+ae).find(".xheLayout"),an=h("#"+ae);if(al){if(h.boxModel===false){ag.after(an)}ao.attr("style",ab);s.height(ak-X.outerHeight())}else{if(h.boxModel===false){h("body").append(an)}ab=ao.attr("style");ao.removeAttr("style");s.height("100%");setTimeout(af.fixFullHeight,100)}al=!al;an.toggleClass("xhe_Fullscreen");h("html").toggleClass("xhe_Fullfix");X.find("[name=Fullscreen]").toggleClass("xheActive");setTimeout(af.setOpts,300)};this.addShortCut=function(an,ao){P[an.toLowerCase()]=ao};this.checkShortCut=function(ap){if(R||K){return true}aj=ap;var ao=aj.which,an=E[ao],aq=an?an:String.fromCharCode(ao).toLowerCase();sKey="";sKey+=aj.ctrlKey?"ctrl+":"";sKey+=aj.altKey?"alt+":"";sKey+=aj.shiftKey?"shift+":"";sKey+=aq;if(P[sKey]){af.exec(P[sKey]);return false}};this.showMenu=function(ap,aq){var ao=h('<div class="xheMenu"></div>'),an;h.each(ap,function(at,ar){an=h('<a href="javascript:void(0);" title="'+ar.t+'">'+ar.s+"</a>").click(function(){af.focus();aq(ar.v);af.hidePanel();return false}).mousedown(function(){return false});ao.append(an)});af.showPanel(ao)};this.showColor=function(ar){var ao=h('<div class="xheColor"></div>'),ap,an,aq=0;ap=h("<div></div>");h.each(n,function(au,at){aq++;an=h('<a href="javascript:void(0);" title="'+at+'" style="background:'+at+'"><img src="'+L+'img/spacer.gif" /></a>').click(function(){af.focus();ar(at);af.hidePanel()}).mousedown(function(){return false});ap.append(an);if(aq%10==0){ao.append(ap);ap=h("<div></div>")}});ao.append(ap);af.showPanel(ao)};this.showPastetext=function(){var ao=h(a),ap=h("#xhePastetextValue",ao),an=h("#xheSave",ao);an.click(function(){af.focus();var aq=ap.val();if(aq){af.pasteText(aq)}af.hidePanel();return false});af.showDialog(ao)};this.attr=function(ap,aq,an){if(!aq){return false}var ao="_xhe_"+aq;if(an){ap.attr(aq,an);if(af.settings.keepValue){ap.removeAttr(ao).attr(ao,an)}}an=ap.attr(aq);if(af.settings.keepValue){an=ap.attr(ao)||an}return an};this.showLink=function(){var ao=h(b),ar=af.getParent("a"),ap=h("#xheLinkText",ao),au=h("#xheLinkHref",ao),at=h("#xheLinkTarget",ao),an=h("#xheSave",ao),aq=af.getSelect();if(ar.length==1){au.val(af.attr(ar,"href"));at.attr("value",ar.attr("target"))}else{if(aq==""){ap.val(af.settings.defLinkText).closest("div").show()}}if(af.settings.upLinkUrl){af.ajaxUploadInit(au,af.settings.upLinkUrl,af.settings.upLinkExt)}an.click(function(){af.focus();var aw=au.val();if(aw==""||ar.length==0){af._exec("unlink")}if(aw!=""&&aw!="http://"){if(ar.length==0){if(aq==""){var av=ap.val();if(!av){av=aw}af.pasteHTML('<a href="#xhe_tmpurl">'+av+"</a>")}else{af._exec("createlink","#xhe_tmpurl")}ar=h('a[href$="#xhe_tmpurl"]',N)}af.attr(ar,"href",aw);if(at.val()!=""){ar.attr("target",at.val())}else{ar.removeAttr("target")}}af.hidePanel();return false});af.showDialog(ao)};this.showImg=function(){var aw=h(z),ap=af.getParent("img"),aq=h("#xheImgSrc",aw),ax=h("#xheImgAlt",aw),az=h("#xheImgAlign",aw),ar=h("#xheImgWidth",aw),at=h("#xheImgHeight",aw),ay=h("#xheImgBorder",aw),an=h("#xheImgVspace",aw),au=h("#xheImgHspace",aw),av=h("#xheSave",aw);if(ap.length==1){aq.val(af.attr(ap,"src"));ax.val(ap.attr("alt"));az.val(ap.attr("align"));ar.val(ap.attr("width"));at.val(ap.attr("height"));ay.val(ap.attr("border"));var ao=ap.attr("vspace"),aA=ap.attr("hspace");an.val(ao<=0?"":ao);au.val(aA<=0?"":aA)}if(af.settings.upImgUrl){af.ajaxUploadInit(aq,af.settings.upImgUrl,af.settings.upImgExt)}av.click(function(){af.focus();var aC=aq.val();if(aC!=""&&aC!="http://"){var aG=aC.split("|");if(aG.length>1){var aE='<img src="xhe_tmpurl"',aF;if(ax.val()!=""){aE+=' alt="'+ax.val()+'"'}if(az.val()!=""){aE+=' align="'+az.val()+'"'}if(ar.val()!=""){aE+=' width="'+ar.val()+'"'}if(at.val()!=""){aE+=' height="'+at.val()+'"'}if(ay.val()!=""){aE+=' border="'+ay.val()+'"'}if(an.val()!=""){aE+=' vspace="'+an.val()+'"'}if(au.val()!=""){aE+=' hspace="'+au.val()+'"'}aE+=" />";for(var aD in aG){aC=aG[aD];if(aC!=""){aC=aC.split(",");aF=aE;aF=aF.replace("xhe_tmpurl",aC[0]);if(aC[1]){aF='<a href="'+aC[1]+'" target="_blank">'+aF+"</a>"}af.pasteHTML(aF)}}}else{if(aG.length==1){aC=aG[0];if(aC!=""){aC=aC.split(",");if(ap.length==0){af.pasteHTML('<img src="'+aC[0]+'#xhe_tmpurl" />');ap=h('img[src$="#xhe_tmpurl"]',N)}af.attr(ap,"src",aC[0]);if(ax.val()!=""){ap.attr("alt",ax.val())}else{ap.removeAttr("alt")}if(az.val()!=""){ap.attr("align",az.val())}else{ap.removeAttr("align")}if(ar.val()!=""){ap.attr("width",ar.val())}else{ap.removeAttr("width")}if(at.val()!=""){ap.attr("height",at.val())}else{ap.removeAttr("height")}if(ay.val()!=""){ap.attr("border",ay.val())}else{ap.removeAttr("border")}if(an.val()!=""){ap.attr("vspace",an.val())}else{ap.removeAttr("vspace")}if(au.val()!=""){ap.attr("hspace",au.val())}else{ap.removeAttr("hspace")}if(aC[1]){var aB=ap.parent("a");if(aB.length==0){ap.wrap("<a></a>");aB=ap.parent("a")}af.attr(aB,"href",aC[1]);aB.attr("target","_blank")}}}}}else{if(ap.length==1){ap.remove()}}af.hidePanel();return false});af.showDialog(aw)};this.showEmbed=function(an,ay,av,az,ar,ao,ap){var aA=h(ay),aq=af.getParent('embed[type="'+av+'"],embed[classid="'+az+'"]'),au=h("#xhe"+an+"Src",aA),at=h("#xhe"+an+"Width",aA),aw=h("#xhe"+an+"Height",aA),ax=h("#xheSave",aA);if(ao){af.ajaxUploadInit(au,ao,ap)}af.showDialog(aA);if(aq.length==1){au.val(af.attr(aq,"src"));at.val(aq.attr("width"));aw.val(aq.attr("height"))}ax.click(function(){af.focus();var aD=au.val();if(aD!=""&&aD!="http://"){var aC=at.val(),aH=aw.val(),aG=/^[0-9]+$/;if(!aG.test(aC)){aC=412}if(!aG.test(aH)){aH=300}var aI='<embed type="'+av+'" classid="'+az+'" src="xhe_tmpurl"'+ar;var aB=aD.split("|");if(aB.length>1){var aF=aI+"";aF+=' width="'+aC+'" height="'+aH+'" />';for(var aE in aB){aD=aB[aE];if(aD!=""){af.pasteHTML(aF.replace("xhe_tmpurl",aD))}}}else{if(aB.length==1){aD=aB[0];if(aq.length==0){af.pasteHTML(aI.replace("xhe_tmpurl",aD+"#xhe_tmpurl")+" />");aq=h('embed[src$="#xhe_tmpurl"]',N)}af.attr(aq,"src",aD);aq.attr("width",aC);aq.attr("height",aH)}}}else{if(aq.length==1){aq.remove()}}af.hidePanel();return false})};this.ajaxUploadInit=function(aq,ao,ar){var ap='<span class="xheUpload"><input type="text" style="visibility:hidden;" /><input type="button" value="上传" class="xheBtn" />',an;if(ao.substr(0,1)=="!"){an=h(ap+"</span>");aq.after(an);h(".xheBtn",an).before(aq).click(function(){u=false;af.showIframeModal(ao.substr(1),"上传文件",function(au){if(au.substr(0,1)=="!"){aq.val(au.substr(1));aq.closest(".xheDialog").find("#xheSave").click()}else{aq.val(au)}},null,null,function(){u=true})})}else{an=h(ap+'<input type="file" class="xheFile" size="13" name="filedata" id="xheUploadFile" /></span>');aq.after(an);h(".xheBtn",an).before(aq);var at=h("#xheUploadFile",an);at.change(function(){var av=at.val();if(av!=""){if(av.match(new RegExp(".("+ar.replace(/,/g,"|")+")$","i"))){u=false;var au=af.showModal("文件上传",'<div style="margin:22px 0;text-align:center;line-height:30px;">文件上传中，请稍候……<br /><img src="'+L+'img/loading.gif"></div>',320,150,function(){u=true});af.ajaxUpload(at,ao,function(aw){au.remove();if(aw.err){alert(aw.err)}else{var ax=aw.msg;if(ax.substr(0,1)=="!"){aq.val(ax.substr(1));aq.closest(".xheDialog").find("#xheSave").click()}else{aq.val(ax)}}},function(){au.remove()})}else{alert("上传文件扩展名必需为："+ar)}}})}};this.ajaxUpload=function(aq,an,aw,at){var av=new Date().getTime(),au="jUploadFrame"+av;var ao=h('<iframe name="'+au+'" class="xheUploadIO" />').appendTo("body");var ap=h('<form action="'+an+'" target="'+au+'" method="post" enctype="multipart/form-data" class="xheUploadForm"></form>').appendTo("body");var ax=h(aq),ar=ax.clone().attr("disabled","true");ax.before(ar).appendTo(ap);ap.submit();ao.load(function(){setTimeout(function(){ar.before(ax).remove();ao.remove();ap.remove()},100);var ay=h(ao[0].contentWindow.document.body).text(),aA=Object;try{eval("aA="+ay)}catch(az){}if(aA.err!=undefined&&aA.msg!=undefined){aw(aA)}else{alert(an+" 上传接口发生错误！\r\n\r\n返回的错误内容为：\r\n\r\n"+ay);at()}})};this.showIframeModal=function(ax,ar,av,at,ap,ao){var an=h('<iframe frameborder="0" src="'+ax+'" style="width:100%;height:100%;display:none;" /><div class="xheModalIfmWait"></div>'),aw=h(an[0]),aq=h(an[1]);var au=af.showModal(ar,an,at,ap,ao);aw.load(function(){var az=aw[0].contentWindow,ay=h(az.document);az.callback=function(aA){ay.unbind("keydown",au.escCheck);au.remove();av(aA)};ay.keydown(au.escCheck);aw.show();aq.remove()})};this.showModal=function(aw,au,ax,at,ap){if(h(".xheModal").length==1){return false}var ao,ay,an,av;ax=ax?ax:af.settings.modalWidth;at=at?at:af.settings.modalHeight;av=af.settings.layerShadow;ao=h('<div class="xheModal" style="width:'+(ax-1)+"px;height:"+at+"px;margin:-"+Math.ceil(at/2)+"px 0px 0px -"+Math.ceil(ax/2)+'px;">'+(af.settings.modalTitle?'<div class="xheModalTitle"><span class="xheModalClose" title="关闭 (Esc)"></span>'+aw+"</div>":"")+'<div class="xheModalContent"></div></div>').appendTo("body");an=h('<div class="xheModalOverlay"></div>').appendTo("body").mousedown(function(){return false});if(av>0){ay=h('<div class="xheModalShadow" style="width:'+ao.outerWidth()+"px;height:"+ao.outerHeight()+"px;margin:-"+(Math.ceil(at/2)-av-2)+"px 0px 0px -"+(Math.ceil(ax/2)-av-2)+'px;"></div>').appendTo("body").mousedown(function(){return false})}h(".xheModalContent",ao).css("height",at-(af.settings.modalTitle?h(".xheModalTitle").outerHeight():0)).html(au);function ar(){h(document).unbind("keydown",aq);ao.remove();if(av>0){ay.remove()}an.remove();if(ap){ap()}}this.remove=ar;function aq(az){if(az.which==27){ar();return false}}this.escCheck=aq;h(document).keydown(aq);h(".xheModalClose",ao).click(this.remove);an.show();if(av>0){ay.show()}ao.show();return this};this.showEmot=function(){var ar=h('<div class="xheEmot"></div>'),ap,an,aq=0,ao=D+"ubb/";ap=h("<div></div>");h.each(o,function(au,at){aq++;an=h('<a href="javascript:void(0);" title="'+at.t+'"><img src="'+ao+at.s+'" width=19/></a>').click(function(){af.focus();af.pasteHTML('<img src="'+ao+at.s+'" alt="'+at.t+'  width=19">');af.hidePanel()}).mousedown(function(){return false});ap.append(an);if(aq%8==0){ar.append(ap);ap=h("<div></div>")}});ar.append(ap);af.showPanel(ar)};this.showTable=function(){var ao=h(g),an=h("#xheTableRows",ao),az=h("#xheTableColumns",ao),aw=h("#xheTableHeaders",ao),aq=h("#xheTableWidth",ao),ar=h("#xheTableHeight",ao),ay=h("#xheTableBorder",ao),ap=h("#xheTableCellSpacing",ao),au=h("#xheTableCellPadding",ao),ax=h("#xheTableAlign",ao),at=h("#xheTableCaption",ao),av=h("#xheSave",ao);av.click(function(){af.focus();var aM=at.val(),aL=ay.val(),aE=an.val(),aA=az.val(),aC=aw.val(),aB=aq.val(),aI=ar.val(),aG=ap.val(),aJ=au.val(),aK=ax.val();var aH,aF,aD="<table"+(aL!=""?' border="'+aL+'"':"")+(aB!=""?' width="'+aB+'"':"")+(aI!=""?' width="'+aI+'"':"")+(aG!=""?' cellspacing="'+aG+'"':"")+(aJ!=""?' cellpadding="'+aJ+'"':"")+(aK!=""?' align="'+aK+'"':"")+">";if(aM!=""){aD+="<caption>"+aM+"</caption>"}if(aC=="row"||aC=="both"){aD+="<tr>";for(aH=0;aH<aA;aH++){aD+='<th scope="col">&nbsp;</th>'}aD+="</tr>";aE--}aD+="<tbody>";for(aH=0;aH<aE;aH++){aD+="<tr>";for(aF=0;aF<aA;aF++){if(aF==0&&(aC=="col"||aC=="both")){aD+='<th scope="row">&nbsp;</th>'}else{aD+="<td>&nbsp;</td>"}}aD+="</tr>"}aD+="</tbody></table>";af.pasteHTML(aD);af.hidePanel();return false});af.showDialog(ao)};this.showAbout=function(){var ao=h(r),an=h("#xheSave",ao);an.click(function(){af.focus();af.hidePanel();return false});af.showDialog(ao)};this.showDialog=function(aq){var ap=h('<div class="xheDialog"></div>'),an=h("#xheSave",aq);if(an.length==1){aq.find("input[type=text]").keypress(function(at){if(at.which==13){an.click();return false}});an.after(' <input type="button" id="xheCancel" value="取消" />');h("#xheCancel",aq).click(af.hidePanel);if(!af.settings.clickCancelDialog){l=false;var ao=h('<div class="xheFixCancel"></div>').appendTo("body").mousedown(function(){return false});var ar=s.offset();ao.css({left:ar.left,top:ar.top,width:s.outerWidth(),height:s.outerHeight()})}}ap.append(aq);af.showPanel(ap)};this.clickCancelPanel=function(){if(l){af.hidePanel()}};this.showPanel=function(ap){if(u){af.hidePanel()}d.empty().append(ap).css("left",0).css("top",0);j=h(aj.target).closest("a");var aq=j.offset();var ao=aq.left,ar=aq.top;ar+=j.outerHeight()-1;j.addClass("xheActive");q.css({left:ao+1,top:ar}).show();if((ao+d.outerWidth())>document.body.clientWidth){ao-=(d.outerWidth()-j.outerWidth())}var an=af.settings.layerShadow;if(an>0){C.css({left:ao+an,top:ar+an,width:d.outerWidth(),height:d.outerHeight()}).show()}d.css("left",ao).css("top",ar).show();u=true};this.hidePanel=function(){if(u){j.removeClass("xheActive");C.hide();q.hide();d.hide();u=false;if(!l){h(".xheFixCancel").remove();l=true}}};this.exec=function(aq){var at=w[aq].e;if(at){return at.call(this)}aq=aq.toLowerCase();switch(aq){case"cut":try{N.execCommand(aq);if(!N.queryCommandSupported(aq)){throw"Error"}}catch(ap){alert("您的浏览器安全设置不允许使用剪切操作，请使用键盘快捷键(Ctrl + X)来完成")}break;case"copy":try{N.execCommand(aq);if(!N.queryCommandSupported(aq)){throw"Error"}}catch(ap){alert("您的浏览器安全设置不允许使用复制操作，请使用键盘快捷键(Ctrl + C)来完成")}break;case"paste":try{N.execCommand(aq);if(!N.queryCommandSupported(aq)){throw"Error"}}catch(ap){alert("您的浏览器安全设置不允许使用粘贴操作，请使用键盘快捷键(Ctrl + V)来完成")}break;case"pastetext":if(window.clipboardData){af.pasteText(window.clipboardData.getData("Text",true))}else{af.showPastetext()}break;case"blocktag":var ar=[];h.each(B,function(av,au){ar.push({s:"<"+au.n+">"+au.t+"</"+au.n+">",v:"<"+au.n+">",t:au.t})});af.showMenu(ar,function(au){af._exec("formatblock",au)});break;case"fontface":var an=[];h.each(c,function(av,au){au.c=au.c?au.c:au.n;an.push({s:'<span style="font-family:'+au.c+'">'+au.n+"</span>",v:au.c,t:au.n})});af.showMenu(an,function(au){af._exec("fontname",au)});break;case"fontsize":var ao=[];h.each(x,function(av,au){ao.push({s:'<span style="font-size:'+au.s+'">'+au.t+"("+au.s+")</span>",v:av+1,t:au.t})});af.showMenu(ao,function(au){af._exec("fontsize",au)});break;case"fontcolor":af.showColor(function(au){af._exec("forecolor",au)});break;case"backcolor":af.showColor(function(au){if(t){af._exec("backcolor",au)}else{af.setCSS(true);af._exec("hilitecolor",au);af.setCSS(false)}});break;case"align":af.showMenu(e,function(au){af._exec(au)});break;case"list":af.showMenu(f,function(au){af._exec(au)});break;case"link":af.showLink();break;case"img":af.showImg();break;case"flash":af.showEmbed("Flash",I,"application/x-shockwave-flash","clsid:d27cdb6e-ae6d-11cf-96b8-4445535400000",' wmode="opaque" quality="high" menu="false" play="true" loop="true"',af.settings.upFlashUrl,af.settings.upFlashExt);break;case"media":af.showEmbed("Media",y,"application/x-mplayer2","clsid:6bf52a52-394a-11d3-b153-00c04f79faa6",' enablecontextmenu="false" autostart="false"',af.settings.upMediaUrl,af.settings.upMediaExt);break;case"emot":af.showEmot();break;case 'html':af.innsertHtml();break;case 'hidden':if(confirm("确实要使用会员可见功能吗？该功能不利于您的帖子被检索！")){af.innsertHidden()};break;case"table":af.showTable();break;case"source":af.toggleSource();break;case"preview":af.togglePreview();break;case"fullscreen":af.toggleFullscreen();break;case"about":af.showAbout();break;default:af._exec(aq);break}};this._exec=function(an,ao){if(ao!=undefined){return N.execCommand(an,false,ao)}else{return N.execCommand(an,false,null)}}};h(function(){h("textarea.xheditor,textarea[xheditor]").xheditor(true);h("textarea.xheditor-mini").xheditor(true,{tools:"mini"});h("textarea.xheditor-simple").xheditor(true,{tools:"simple"})})})(jQuery);