/*
 * xhEditor - WYSIWYG XHTML Editor
 * @requires jQuery v1.4.2
 * 
 * @author Yanis.Wang<yanis.wang@gmail.com>
 * @site http://xheditor.com/
 * @licence LGPL(http://www.opensource.org/licenses/lgpl-license.php)
 * 
 * @Version: 1.0.0 rc1 build 100301
 */
(function(i){i.fn.xheditor=function(E,F){var G=[];this.each(function(){if(this.tagName.toLowerCase()!="textarea"){return}if(E){if(!this.editor){var H=i(this).attr("xheditor");if(H){try{H=eval("("+H+")")}catch(I){}F=i.extend({},H,F)}var J=new i.xheditor(this,F);if(J.init()){this.editor=J;G.push(J)}else{J=null}}}else{if(this.editor){this.editor.remove();this.editor=null}}});if(G.length==0){G=false}if(G.length==1){G=G[0]}return G};var k=0,l=i.browser.version,s=i.browser.msie,n=i.browser.mozilla,C=i.browser.safari,t=false,m=true;var e,A,q,j;var c;i("script[src*=xheditor]").each(function(){var E=this.src;if(E.match(/xheditor[^\/]*\.js/i)){c=E.replace(/[\?#].*$/,"").replace(/(^|[\/\\])[^\/]*$/,"$1");return false}});var B={27:"esc",9:"tab",32:"space",13:"enter",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 o=["#FFFFFF","#CCCCCC","#C0C0C0","#999999","#666666","#333333","#000000","#FFCCCC","#FF6666","#FF0000","#CC0000","#990000","#660000","#330000","#FFCC99","#FF9966","#FF9900","#FF6600","#CC6600","#993300","#663300","#FFFF99","#FFFF66","#FFCC66","#FFCC33","#CC9933","#996633","#663333","#FFFFCC","#FFFF33","#FFFF00","#FFCC00","#999900","#666600","#333300","#99FF99","#66FF99","#33FF33","#33CC00","#009900","#006600","#003300","#99FFFF","#33FFFF","#66CCCC","#00CCCC","#339999","#336666","#003333","#CCFFFF","#66FFFF","#33CCFF","#3366FF","#3333FF","#000099","#000066","#CCCCFF","#9999FF","#6666CC","#6633FF","#6600CC","#333399","#330099","#FFCCFF","#FF99FF","#CC66CC","#CC33CC","#993399","#663366","#330033"];var z=[{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 d=[{n:"新細明體",c:"PMingLiu"},{n:"細明體",c:"mingliu"},{n:"標楷體",c:"DFKai-SB"},{n:"微軟正黑體",c:"Microsoft JhengHei"},{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 w=[{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 f=[{s:"靠左對齊",v:"justifyleft"},{s:"置中",v:"justifycenter"},{s:"靠右對齊",v:"justifyright"},{s:"左右對齊",v:"justifyfull"}],g=[{s:"數字列表",v:"insertOrderedList"},{s:"符號列表",v:"insertUnorderedList"}];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 y='<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 D='<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 x='<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 h='<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 rc1 build 100301</p><p>xhEditor是一個基於jQuery開發的跨平台開源迷你XHTML編輯器組件。</p><p><a href="http://xheditor.com/" target="_blank">http://xheditor.com/</a></p></div>';var p={"default":{name:"默認",width:25,height:18,line:6,list:{biggrin:"Big grin",smile:"Smile",titter:"Titter",lol:"Lol",call:"Call",victory:"Victory",shy:"Shy",handshake:"Handshake",kiss:"Kiss",sad:"Sad",cry:"Cry",huffy:"Huffy",mad:"Mad",tongue:"Tongue",sweat:"Sweat",shocked:"Shocked",time:"Time",hug:"Hug"}}};var v={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:"減少縮排 (Shift+Tab)",s:"Shift+Tab"},Indent:{t:"增加縮排 (Tab)",s:"Tab"},Link:{t:"超連結"},Unlink:{t:"取消超連結"},Img:{t:"圖片"},Flash:{t:"Flash動畫"},Media:{t:"多媒體文件"},Emot:{t:"表情"},Table:{t:"表格"},Source:{t:"原始碼"},Preview:{t:"預覽"},Fullscreen:{t:"全螢幕編輯 (Esc)",s:"Esc"},About:{t:"關於 xhEditor"}};var u={mini:"GStart,Bold,Italic,Underline,Strikethrough,GEnd,Separator,GStart,Align,List,GEnd,Separator,GStart,Link,Img,About,GEnd",simple:"GStart,Blocktag,Fontface,FontSize,Bold,Italic,Underline,Strikethrough,FontColor,BackColor,GEnd,Separator,GStart,Align,List,Outdent,Indent,GEnd,Separator,GStart,Link,Img,Emot,About,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"};i.xheditor=function(O,ab){var ai={skin:"default",tools:"full",clickCancelDialog:true,linkTag:false,internalScript:false,inlineScript:false,internalStyle:true,inlineStyle:true,showBlocktag:false,forcePtag:true,upLinkExt:"zip,rar,txt",upImgExt:"jpg,jpeg,gif,png",upFlashExt:"swf",upMediaExt:"wmv,avi,wma,mp3,mid",modalWidth:350,modalHeight:220,modalTitle:true,defLinkText:"點擊打開鏈接",layerShadow:3,emotMark:false,upBtnText:"上傳",wordDeepClean:true};var H=this,ae=O,X=i(ae),af=X.closest("form"),S,ad,an,F,Q,V,aa;var I;var ao=false,P=false,M=false,J=false,Y=false,ap=false,T="",am;var ah=0;this.settings=i.extend({},ai,ab);var E=H.settings.plugins;if(E){var G=[];i.each(E,function(ar){G.push(ar)});u.full=u.full.replace("Table","Table,"+G.join(","));v=i.extend({},v,E)}if(H.settings.tools.match(/^\s*(mini|simple|full)\s*$/i)){H.settings.tools=i.trim(H.settings.tools);H.settings.tools=u[H.settings.tools]}if(!H.settings.tools.match(/(^|,)\s*About\s*(,|$)/i)){H.settings.tools+=",About"}H.settings.tools=H.settings.tools.split(",");c=U(c,"abs");var ag="xheCSS_"+H.settings.skin,aj="xhe"+k+"_container",K="xhe"+k+"_Tool",L="xhe"+k+"_iframearea",N="xhe"+k+"_iframe";var R="",aq=c+"xheditor_skin/"+H.settings.skin+"/",ak=p,W=U(c,"rel")+"xheditor_emot/",al="";ak=i.extend({},ak,H.settings.emots);ap=H.settings.showBlocktag;if(ap){R+=" showBlocktag"}var Z=[];this.init=function(){if(i("#"+ag).length==0){i("head").append('<link id="'+ag+'" rel="stylesheet" type="text/css" href="'+aq+'ui.css" />')}var av=H.settings.width||ae.style.width||X.outerWidth();ah=H.settings.height||X.outerHeight();if(ah<=0){alert("當前textarea處於隱藏狀態，請將之顯示後再初始化xhEditor，或者直接初始化時指定height高度值");return false}if(/^[0-9\.]+$/i.test(""+av)){av+="px"}var au="",az,aB;i.each(H.settings.tools,function(aC,aD){az=v[aD];if(aD=="GStart"){au+='<span class="xheGStart"/>'}else{if(aD=="GEnd"){au+='<span class="xheGEnd"/>'}else{if(aD=="Separator"){au+='<span class="xheSeparator"/>'}else{if(aD=="BtnBr"){au+="<br />"}else{if(az.c){aB=az.c}else{aB="xheIcon xheBtn"+aD}au+='<span><a href="javascript:void(0);" title="'+az.t+'" name="'+aD+'" class="xheButton xheEnabled" tabindex="-1"><span class="'+aB+'" /></a></span>';if(az.s){H.addShortcuts(az.s,aD)}}}}}});au+="<br />";X.after(i('<span id="'+aj+'" class="xhe_'+H.settings.skin+'" style="display:none"><table cellspacing="0" cellpadding="0" class="xheLayout" style="width:'+av+";height:"+ah+'px;"><tbody><tr><td id="'+K+'" class="xheTool" style="height:1px;"></td></tr><tr><td id="'+L+'" class="xheIframeArea"><iframe frameborder="0" id="'+N+'" src="" style="width:100%;"></iframe></td></tr></tbody></table></span>'));S=i("#"+K);ad=i("#"+L);var aw='<html><head><meta content="text/html; charset=UTF-8" http-equiv="Content-Type"/><link rel="stylesheet" href="'+aq+'iframe.css"/>';if(H.settings.loadCSS){var at=H.settings.loadCSS;if(ac(at,"array")){for(var ax in at){aw+='<link rel="stylesheet" href="'+at[ax]+'"/>'}}else{aw+='<link rel="stylesheet" href="'+at+'"/>'}}aw+='</head><body spellcheck="false" dir="ltr" class="editMode'+R+'"></body></html>';an=i("#"+N)[0].contentWindow;F=i(an);try{Q=an.document;V=i(Q);Q.open();Q.write(aw);Q.close();if(s){Q.body.contentEditable="true"}else{Q.designMode="On"}}catch(aA){}setTimeout(H.setOpts,300);H.setSource();an.setInterval=null;S.append(au);S.find(".xheButton").click(function(aD){H.hidePanel();H.focus();am=aD;var aC=i(this);if(aC.is(".xheEnabled")){H.exec(aC.attr("name"))}return false}).mousedown(function(){return false});e=i("#xhePanel");A=i("#xheShadow");q=i("#xheCntLine");if(e.length==0){e=i('<div id="xhePanel"></div>').mousedown(function(aC){aC.stopPropagation()});A=i('<div id="xheShadow"></div>');q=i('<div id="xheCntLine"><img src="'+aq+'img/spacer.gif" /></div>');i(document.body).append(e).append(A).append(q)}i(document).mousedown(H.clickCancelPanel);V.mousedown(H.clickCancelPanel);if(s){V.bind("beforedeactivate",function(){if(s&&!P){I=H.getRng()}});F.focus(function(){if(s&&!P&&I){I.select();I=null}})}aa=i('<iframe class="xheHideArea" />').appendTo("body");i("#"+aj).show();ad.css("height",ah-S.outerHeight());X.hide();X.focus(H.focus);af.submit(H.getSource).bind("reset",H.setSource);var ar=i(window);ar.unload(H.saveUnload).bind("beforeunload",H.saveUnload);ar.resize(H.fixFullHeight);F.focus(function(){if(H.settings.focus){H.settings.focus()}}).blur(function(){if(H.settings.blur){H.settings.blur()}});if(C){F.click(H.fixAppleSel)}V.keydown(H.checkShortcuts).keydown(H.forcePtag).bind("mousedown click",function(aC){X.trigger(aC.type)});i("body",V).bind("paste",H.cleanPaste);var ay=H.settings.shortcuts;if(ay){i.each(ay,function(aC,aD){H.addShortcuts(aC,aD)})}k++;ao=true;if(H.settings.fullscreen){H.toggleFullscreen()}if(H.settings.readonly){H.toggleReadonly(true)}else{if(H.settings.sourceMode){setTimeout(H.toggleSource,20)}}return true};this.remove=function(){if(t){H.hidePanel()}X.unbind("focus",H.focus);af.unbind("submit",H.getSource).unbind("reset",H.setSource);var ar=i(window);ar.unbind("unload",H.saveUnload).unbind("beforeunload",H.saveUnload);ar.unbind("resize",H.fixFullHeight);i("#"+aj).remove();X.show();ao=false};this.saveUnload=function(){H.getSource()};this.cleanPaste=function(){if(s&&!P){var at,ar=aa[0].contentWindow.document.body;ar.innerHTML="";ar.createTextRange().execCommand("Paste");at=ar.innerHTML;if(at.indexOf("&nbsp;")==0){at=at.substring(6)}at=H.cleanWord(at);at=H.cleanHTML(at);H.pasteHTML(at);return false}};this.setCSS=function(ar){try{H._exec("styleWithCSS",ar)}catch(at){try{H._exec("useCSS",!ar)}catch(at){}}};this.setOpts=function(){if(ao&&!M&&!P){H.setCSS(false);try{H._exec("enableObjectResizing",true)}catch(ar){}if(s){try{H._exec("BackgroundImageCache",true)}catch(ar){}}}};this.forcePtag=function(at){if(P||M||at.keyCode!=13||at.shiftKey||at.ctrlKey||at.altKey){return true}var ar=H.getParent("p,h1,h2,h3,h4,h5,h6,pre,address,div,li");if(H.settings.forcePtag){if(ar.length==0){H._exec("formatblock","<p>")}}else{H.pasteHTML("<br />");return false}};this.fixFullHeight=function(){if(!n&&!C){ad.height("100%");if(J){ad.css("height",ad.outerHeight()-S.outerHeight())}if(s){S.hide().show()}}};this.fixAppleSel=function(au){au=au.target;if(au.tagName.match(/(img|embed)/i)){var at=H.getSel(),ar=H.getRng();ar.selectNode(au);at.removeAllRanges();at.addRange(ar)}};this.focus=function(){if(!P){F.focus()}else{i("#sourceCode",Q).focus()}return false};this.getSel=function(){return an.getSelection?an.getSelection():Q.selection};this.getRng=function(){var au=H.getSel(),ar;try{ar=au.rangeCount>0?au.getRangeAt(0):(au.createRange?au.createRange():Q.createRange())}catch(at){}if(!ar){ar=s?Q.body.createTextRange():Q.createRange()}return ar};this.getParent=function(ar){var at=H.getRng(),au;if(!s){au=at.commonAncestorContainer;if(!at.collapsed){if(at.startContainer==at.endContainer&&at.startOffset-at.endOffset<2&&at.startContainer.hasChildNodes()){au=at.startContainer.childNodes[at.startOffset]}}}else{au=at.item?at.item(0):at.parentElement()}ar=ar?ar:"*";au=i(au);if(!au.is(ar)){au=i(au).closest(ar)}return au};this.getSelect=function(aw){var av=H.getSel(),ar=H.getRng(),at=true;if(!ar||ar.item){at=false}else{at=!av||ar.boundingWidth==0||ar.collapsed}if(aw=="text"){return at?"":(ar.text||(av.toString?av.toString():""))}var ax;if(ar.cloneContents){var au=i("<div></div>"),ay;ay=ar.cloneContents();if(ay){au.append(ay)}ax=au.html()}else{if(ac(ar.item)){ax=ar.item(0).outerHTML}else{if(ac(ar.htmlText)){ax=ar.htmlText}else{ax=ar.toString()}}}if(at){ax=""}ax=H.processHTML(ax,"read");ax=H.formatXHTML(ax);ax=H.cleanHTML(ax);return ax};function ac(at,ar){var au=typeof(at);if(!ar){return au!="undefined"}if(ar=="array"&&(at.hasOwnProperty&&at instanceof Array)){return true}return au==ar}this.pasteHTML=function(av){if(P||M){return false}H.focus();av=H.processHTML(av,"write");var au=H.getSel(),ar=H.getRng();av+='<span id="_xhe_temp" />';if(ar.insertNode){ar.deleteContents();ar.insertNode(ar.createContextualFragment(av))}else{if(ar.item){H._exec("delete");ar=H.getRng()}ar.pasteHTML(av)}var at=i("#_xhe_temp",Q),aw=at[0];if(s){ar.moveToElementText(aw);ar.select()}else{ar.selectNode(aw);au.removeAllRanges();au.addRange(ar)}at.remove()};this.pasteText=function(ar){if(!ar){ar=""}ar=H.domEncode(ar);ar=ar.replace(/\r?\n/g,"<br />");H.pasteHTML(ar)};this.appendHTML=function(ar){if(P||M){return false}H.focus();ar=H.processHTML(ar,"write");i(Q.body).append(ar)};this.domEncode=function(ar){return ar.replace(/[<>]/g,function(at){return{"<":"&lt;",">":"&gt;"}[at]})};this.setSource=function(ar){setTimeout(function(){H._setSource(ar)},10)};this._setSource=function(ar){I=null;if(typeof ar!="string"&&ar!=""){ar=X.val()}if(P){i("#sourceCode",Q).val(ar)}else{if(H.settings.beforeSetSource){ar=H.settings.beforeSetSource(ar)}ar=H.formatXHTML(ar);ar=H.cleanWord(ar);ar=H.cleanHTML(ar);i(Q.body)[0].innerHTML=H.processHTML(ar,"write")}};this.processHTML=function(aB,ay){var aA=' class="Apple-style-span"';if(ay=="write"){function au(aE,aC,aF,aD){aD=aD.split(",");if(!aD[1]){aD[1]=aD[0];aD[0]=""}if(aD[0]=="default"){aD[0]=""}return aE.replace(/\s+src\s*=\s*(["']?).*?\1(\s|$|\/|>)/i,"$2").replace(aC,' src="'+W+(aD[0]?aD[0]:"default")+"/"+aD[1]+'.gif"'+(H.settings.emotMark?' emot="'+(aD[0]?aD[0]+",":"")+aD[1]+'"':""))}aB=aB.replace(/<img(?:\s+[^>]*?)?(\s+emot\s*=\s*(["']?)\s*(.+?)\s*\2)(?:\s+[^>]*?)?\/?>/ig,au);function at(aF,aD,aC,aH,aG,aE){return aF.replace(aC,aC+" _xhe_"+aH+'="'+aE+'"')}aB=aB.replace(/<(\w+(?:\:\w+)?)(?:\s+[^>]*?)?(\s+(src|href)\s*=\s*(["']?)\s*(.*?)\s*\4)(?:\s+[^>]*?)?\/?>/ig,at);aB=aB.replace(/<(\/?)del(\s+[^>]*?)?>/ig,"<$1strike$2>");if(n){aB=aB.replace(/<(\/?)strong(\s+[^>]*?)?>/ig,"<$1b$2>");aB=aB.replace(/<(\/?)em(\s+[^>]*?)?>/ig,"<$1i$2>")}else{if(C){aB=aB.replace(/("|;)\s*font-size\s*:\s*([a-z-]+)(;?)/ig,function(aG,aI,aC,aH){var aE,aF;for(var aD=0;aD<w.length;aD++){aE=w[aD];if(aC==aE.n){aF=aE.wkn;break}}return aI+"font-size:"+aF+aH});aB=aB.replace(/<strong(\s+[^>]*?)?>/ig,"<span"+aA+' style="font-weight: bold;"$1>');aB=aB.replace(/<em(\s+[^>]*?)?>/ig,"<span"+aA+' style="font-style: italic;"$1>');aB=aB.replace(/<u(\s+[^>]*?)?>/ig,"<span"+aA+' style="text-decoration: underline;"$1>');aB=aB.replace(/<strike(\s+[^>]*?)?>/ig,"<span"+aA+' style="text-decoration: line-through;"$1>');aB=aB.replace(/<\/(strong|em|u|strike)>/ig,"</span>");aB=aB.replace(/<span((?:\s+[^>]*?)?\s+style="([^"]*;)*\s*(font-family|font-size|color|background-color)\s*:\s*[^;"]+\s*;?"[^>]*)>/ig,"<span"+aA+"$1>")}else{if(s){aB=aB.replace(/&apos;/ig,"&#39;");aB=aB.replace(/\s+(disabled|checked|readonly|selected)\s*=\s*[\"\']?(false|0)[\"\']?/ig,"")}}}aB=aB.replace(/<a(\s+[^>]*?)?\/>/,"<a$1></a>");if(!C){function aw(aJ,aN,aC,aG){var aM="",aF,aL,aK,aI;aF=aC.match(/font-family\s*:\s*([^;"]+)/i);if(aF){aM+=' face="'+aF[1]+'"'}aL=aC.match(/font-size\s*:\s*([^;"]+)/i);if(aL){aL=aL[1].toLowerCase();for(var aD=0;aD<w.length;aD++){if(aL==w[aD].n||aL==w[aD].s){aK=aD+1;break}}if(aK){aM+=' size="'+aK+'"';aC=aC.replace(/(^|;)(\s*font-size\s*:\s*[^;"]+;?)+/ig,"$1")}}aI=aC.match(/(?:^|[\s;])color\s*:\s*([^;"]+)/i);if(aI){var aH;if(aH=aI[1].match(/\s*rgb\s*\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\)/i)){aI[1]="#";for(var aE=1;aE<=3;aE++){aI[1]+=(aH[aE]-0).toString(16)}}aI[1]=aI[1].replace(/^#([0-9a-f])([0-9a-f])([0-9a-f])$/i,"#$1$1$2$2$3$3");aM+=' color="'+aI[1]+'"'}aC=aC.replace(/(^|;)(\s*(font-family|color)\s*:\s*[^;"]+;?)+/ig,"$1");if(aM!=""){if(aC){aM+=' style="'+aC+'"'}return"<font"+aM+">"+aG+"</font>"}else{return aJ}}aB=aB.replace(/<(span)(?:\s+[^>]*?)?\s+style\s*=\s*"((?:[^"]*?;)*\s*(?:font-family|font-size|color)\s*:[^"]*)"(?: [^>]+)?>(((?!<\1(\s+[^>]*?)?>)[\s\S])*?)<\/\1>/ig,aw);aB=aB.replace(/<(span)(?:\s+[^>]*?)?\s+style\s*=\s*"((?:[^"]*?;)*\s*(?:font-family|font-size|color)\s*:[^"]*)"(?: [^>]+)?>(((?!<\1(\s+[^>]*?)?>)[\s\S]|<\1(\s+[^>]*?)?>((?!<\1(\s+[^>]*?)?>)[\s\S])*?<\/\1>)*?)<\/\1>/ig,aw);aB=aB.replace(/<(span)(?:\s+[^>]*?)?\s+style\s*=\s*"((?:[^"]*?;)*\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,aw)}}else{var az=H.settings.localUrl;function ax(aD,aF,aE,aC){if(az){aC=U(aC,az)}return aD.replace(new RegExp("\\s+"+aF+"\\s*=\\s*([\"']?).*?\\1([\\s/>])","ig")," "+aF+'="'+aC.replace(/\$/g,"$$$$")+'"$2')}aB=aB.replace(/<(?:\w+(?:\:\w+)?)(?:\s+[^>]*?)?\s+_xhe_(src|href)\s*=\s*(["']?)\s*(.*?)\s*\2(?:\s+[^>]*?)?\/?>/ig,ax);if(C){aB=aB.replace(/("|;)\s*font-size\s*:\s*([a-z-]+)(;?)/ig,function(aG,aI,aC,aH){var aE,aF;for(var aD=0;aD<w.length;aD++){aE=w[aD];if(aC==aE.wkn){aF=aE.n;break}}return aI+"font-size:"+aF+aH});var ar=[{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 av(aI,aD,aF,aE,aJ){var aC=aF+aE,aH="";for(var aG=0;aG<ar.length;aG++){if(aC.match(ar[aG].r)){aH=ar[aG].t;break}}if(aH){return"<"+aH+">"+aJ+"</"+aH+">"}else{return aI}}aB=aB.replace(/<(span)(\s+[^>]*?)?\s+class\s*=\s*"Apple-style-span"(\s+[^>]*?)?>(((?!<\1(\s+[^>]*?)?>)[\s\S])*?)<\/\1>/ig,av);aB=aB.replace(/<(span)(\s+[^>]*?)?\s+class\s*=\s*"Apple-style-span"(\s+[^>]*?)?>(((?!<\1(\s+[^>]*?)?>)[\s\S]|<\1(\s+[^>]*?)?>((?!<\1(\s+[^>]*?)?>)[\s\S])*?<\/\1>)*?)<\/\1>/ig,av);aB=aB.replace(/<(span)(\s+[^>]*?)?\s+class\s*=\s*"Apple-style-span"(\s+[^>]*?)?>(((?!<\1(\s+[^>]*?)?>)[\s\S]|<\1(\s+[^>]*?)?>((?!<\1(\s+[^>]*?)?>)[\s\S]|<\1(\s+[^>]*?)?>((?!<\1(\s+[^>]*?)?>)[\s\S])*?<\/\1>)*?<\/\1>)*?)<\/\1>/ig,av)}aB=aB.replace(/\s+(?:_xhe_|_moz_|_webkit_)[^=]+?\s*=\s*(["']?).*?\1([\s/>])/ig,"$2");aB=aB.replace(/(<\w+[^>]*?)\s+class\s*=\s*(["']?)\s*(?:apple|webkit)\-.+?\s*\2([\s/>])/ig,"$1$3")}return aB};this.getSource=function(ar){var at;if(P){at=i("#sourceCode",Q).val()}else{at=H.processHTML(i(Q.body).html(),"read");at=at.replace(/^\s*(?:<(p|div)(?:\s+[^>]*?)?>)?\s*<br[^>]*>\s*(?:<\/\1>)?\s*$/ig,"");at=H.formatXHTML(at,ar);at=H.cleanWord(at);at=H.cleanHTML(at);if(H.settings.beforeGetSource){at=H.settings.beforeGetSource(at)}}X.val(at);return at};this.cleanWord=function(at){if(at.match(/mso-|MsoNormal/i)){var ar=H.settings.wordDeepClean;at=at.replace(/(<link(?:\s+[^>]*?)?)\s+href\s*=\s*(["']?)\s*file:\/\/.+?\s*\2((?:\s+[^>]*?)?\s*\/?>)/ig,"");at=at.replace(/<!--[\s\S]*?-->|<!(--)?\[[\s\S]+?\](--)?>|<style(\s+[^>]*?)?>[\s\S]*?<\/style>/ig,"");at=at.replace(/<\/?\w+:[^>]*>/ig,"");if(ar){at=at.replace(/<\/?(span|a|img)(\s+[^>]*?)?>/ig,"")}at=at.replace(/(<\w+(?:\s+[^>]*?)?)\s+class\s*=\s*(["']?)\s*mso.+?\s*\2((?:\s+[^>]*?)?\s*\/?>)/ig,"$1$3");at=at.replace(/(<\w+(?:\s+[^>]*?)?)\s+lang\s*=\s*(["']?)\s*.+?\s*\2((?:\s+[^>]*?)?\s*\/?>)/ig,"$1$3");at=at.replace(/(<\w+(?:\s+[^>]*?)?)\s+align\s*=\s*(["']?)\s*left\s*\2((?:\s+[^>]*?)?\s*\/?>)/ig,"$1$3");at=at.replace(/<\w+(?:\s+[^>]*?)?(\s+style\s*=\s*(["']?)\s*(.*?)\s*\2)(?:\s+[^>]*?)?\s*\/?>/ig,function(av,au,ax,aw){aw=i.trim(aw.replace(/\s*(mso-[^:]+:.+?|margin\s*:\s*0cm 0cm 0pt\s*|(text-align|font-variant|line-height)\s*:\s*.+?)(;|$)\s*/ig,""));return av.replace(au,ar?"":aw?' style="'+aw+'"':"")})}return at};this.cleanHTML=function(at){at=at.replace(/<\??xml(:\w+)?(\s+[^>]*?)?>([\s\S]*?<\/xml>)?/ig,"");at=at.replace(/<\/?(html|head|body|meta|title)(\s+[^>]*?)?>/ig,"");if(!H.settings.linkTag){at=at.replace(/<link(\s+[^>]*?)?>/ig,"")}if(!H.settings.internalScript){at=at.replace(/<script(\s+[^>]*?)?>[\s\S]*?<\/script>/ig,"")}if(!H.settings.inlineScript){at=at.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(!H.settings.internalStyle){at=at.replace(/<style(\s+[^>]*?)?>[\s\S]*?<\/style>/ig,"")}if(!H.settings.inlineStyle){at=at.replace(/(<\w+)(\s+[^>]*?)?\s+style\s*=\s*(["']?).*?\3((?:\s+[^>]*?)?\/?>)/ig,"$1$2$4")}for(var ar=0;ar<3;ar++){at=at.replace(/<(strong|b|u|del|strike|s|em|i)(?:\s+[^>]*?)?>(((?!<\1(\s+[^>]*?)?>)([ \t\r\n]|&nbsp;))*?)<\/\1>/ig,function(av,au,aw){if(aw.match(/&nbsp;/i)){return aw.replace(/ +/g,"")}else{return""}})}at=at.replace(/<\/(strong|b|u|strike|em|i)>((?:\s|<br\/?>|&nbsp;)*?)<\1(\s+[^>]*?)?>/ig,"$2");at=at.replace(/<(p|div)(?:\s+[^>]*?)?>(((?!<\1(?: [^>]+)?>)[\s\S])+?)<\/\1>/ig,function(aw,au,ax){var av=ax.replace(/<\/?(span|strong|b|u|strike|em|i)(\s+[^>]*?)?>/ig,"");av=av.replace(/([ \t\r\n]|&nbsp;)+/ig,"");if(av!=""){return aw}else{return"<"+au+"></"+au+">"}});return at};this.formatXHTML=function(aG,az){var aC=aE("area,base,basefont,br,col,frame,hr,img,input,isindex,link,meta,param,embed");var av=aE("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 at=aE("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 aP=aE("colgroup,dd,dt,li,options,p,td,tfoot,th,thead,tr");var aD=aE("checked,compact,declare,defer,disabled,ismap,multiple,nohref,noresize,noshade,nowrap,readonly,selected");var aO=aE("script,style");var au={b:"strong",i:"em",s:"del",strike:"del"};var aL=/^<(\w+(?:\:\w+)?)((?:\s+[\w-\:]*(?:\s*=\s*(?:(?:"[^"]*")|(?:'[^']*')|[^>\s]+))?)*)\s*(\/?)>/;var ay=/^<\/(\w+(?:\:\w+)?)[^>]*>/;var aJ=/([\w-(?:\:\w+)?]+)(?:\s*=\s*(?:(?:"((?:\\.|[^"])*)")|(?:'((?:\\.|[^'])*)')|([^>\s]+)))?/g;var aI=0,aw=[],aB=aG.replace(/\t*\r?\n\t*/g,""),aH=Array(),aF=-1,aA="body";aw.last=function(){return this[this.length-1]};while(aB.length>0){if(!aw.last()||!aO[aw.last()]){aI=0;if(aB.substring(0,4)=="<!--"){aI=aB.indexOf("-->");if(aI!=-1){aI+=3;ar(aB.substring(0,aI))}}else{if(aB.substring(0,2)=="</"){match=aB.match(ay);if(match){match[0].replace(ay,aM);aI=match[0].length}}else{if(aB.charAt(0)=="<"){match=aB.match(aL);if(match){match[0].replace(aL,aN);aI=match[0].length}}}}if(aI==0){aI=aB.indexOf("<");if(aI==0){aI=1}else{if(aI<0){aI=aB.length}}ar(H.domEncode(aB.substring(0,aI)))}aB=aB.substring(aI)}else{aB=aB.replace(/^([\s\S]*?)<\/(style|script)>/i,function(aS,aQ,aR){ar(aQ);return""});aM("",aw.last())}}aM();aG=aH.join("");aH=null;function aE(aT){var aS={},aQ=aT.split(",");for(var aR=0;aR<aQ.length;aR++){aS[aQ[aR]]=true}return aS}function ax(aR){if(aR){aR=aR.toLowerCase();var aQ=au[aR];if(aQ){aR=aQ}}else{aR=""}return aR}function aN(aT,aR,aS,aQ){aR=ax(aR);if(av[aR]){while(aw.last()&&at[aw.last()]){aM("",aw.last())}}if(aP[aR]&&aw.last()==aR){aM("",aR)}aQ=aC[aR]||!!aQ;if(!aQ){aw.push(aR)}aT=Array();aT.push("<"+aR);aS.replace(aJ,function(aV,aU){aU=aU.toLowerCase();var aW=arguments[2]?arguments[2]:arguments[3]?arguments[3]:arguments[4]?arguments[4]:aD[aU]?aU:"";if(aW){aT.push(" "+aU+'="'+aW.replace(/(^|[^\\])"/g,'$1\\"')+'"')}});aT.push((aQ?" /":"")+">");ar(aT.join(""),aR,true)}function aM(aS,aR){if(!aR){var aT=0}else{aR=ax(aR);for(var aT=aw.length-1;aT>=0;aT--){if(aw[aT]==aR){break}}}if(aT>=0){for(var aQ=aw.length-1;aQ>=aT;aQ--){ar("</"+aw[aQ]+">",aw[aQ])}aw.length=aT}}function ar(aT,aS,aV){if(az){if(aT.match(/^[\s\t]*$/)){return}var aU=av[aS],aQ=aU?aS:"",aR;if(aU){if(aV){aF++}if(aA==""){aF--}}else{if(aA){aF++}}if(aQ!=aA||aU){aH.push("\r\n");if(aF>0){aR=aF;while(aR--){aH.push("\t")}}}aH.push(aT);if(aS=="br"){aH.push("\r\n");if(aF>0){aR=aF;while(aR--){aH.push("\t")}}}if(aU&&!aV){aF--}aA=aU?aS:""}else{aH.push(aT)}}function aK(aU,aY,aV,aS){var aW="",aR,aX,aT,aQ;aR=aV.match(/ face\s*=\s*"\s*([^"]+)\s*"/i);if(aR){aW+="font-family:"+aR[1]+";"}aX=aV.match(/ size\s*=\s*"\s*(\d+)\s*"/i);if(aX){aW+="font-size:"+w[(aX[1]>7?7:(aX[1]<1?1:aX[1]))-1].n+";"}aT=aV.match(/ color\s*=\s*"\s*([^"]+)\s*"/i);if(aT){aW+="color:"+aT[1]+";"}aQ=aV.match(/ style\s*=\s*"\s*([^"]+)\s*"/i);if(aQ){aW+=aQ[1]}if(aW){aS='<span style="'+aW+'">'+aS+"</span>"}return aS}aG=aG.replace(/<(font)(\s+[^>]*?)?>(((?!<\1(\s+[^>]*?)?>)[\s\S])*?)<\/\1>/ig,aK);aG=aG.replace(/<(font)(\s+[^>]*?)?>(((?!<\1(\s+[^>]*?)?>)[\s\S]|<\1(\s+[^>]*?)?>((?!<\1(\s+[^>]*?)?>)[\s\S])*?<\/\1>)*?)<\/\1>/ig,aK);aG=aG.replace(/<(font)(\s+[^>]*?)?>(((?!<\1(\s+[^>]*?)?>)[\s\S]|<\1(\s+[^>]*?)?>((?!<\1(\s+[^>]*?)?>)[\s\S]|<\1(\s+[^>]*?)?>((?!<\1(\s+[^>]*?)?>)[\s\S])*?<\/\1>)*?<\/\1>)*?)<\/\1>/ig,aK);aG=aG.replace(/^(\s*\r?\n)+|(\s*\r?\n)+$/g,"");return aG};this.toggleShowBlocktag=function(at){if(ap===at){return}ap=!ap;var ar=i(Q.body);if(ap){R+=" showBlocktag";ar.addClass("showBlocktag")}else{R=R.replace(" showBlocktag","");ar.removeClass("showBlocktag")}};this.toggleReadonly=function(ar){if(Y===ar){return}if(P){H.toggleSource(true)}Y=!Y;if(Y){if(!M){H.togglePreview(true)}S.find("[name=Preview]").toggleClass("xheEnabled").toggleClass("xheActive")}else{S.find("[name=Preview]").toggleClass("xheEnabled").toggleClass("xheActive");if(M){H.togglePreview()}}};this.toggleSource=function(at){if(M||P===at){return}S.find("[name=Source]").toggleClass("xheEnabled").toggleClass("xheActive");if(t){H.hidePanel()}var ar=i(Q.body),au=H.getSource(!P);P=!P;if(P){if(s){Q.body.contentEditable="false"}else{Q.designMode="Off"}ar.attr("scroll","no").attr("class","sourceMode").html('<textarea id="sourceCode" wrap="soft" spellcheck="false" height="100%" />');ar.find("#sourceCode").blur(H.getSource);H._setSource(au)}else{ar.find("#sourceCode").remove();ar.removeAttr("scroll").attr("class","editMode"+R);if(s){Q.body.contentEditable="true"}else{Q.designMode="On"}if(n){H._exec("inserthtml","-")}H._setSource(au);setTimeout(function(){an.scrollTo(0,0)},10)}S.find("[name=Source]").toggleClass("xheEnabled");S.find(".xheButton").not("[name=Source],[name=Fullscreen],[name=About]").toggleClass("xheEnabled");setTimeout(H.setOpts,300)};this.togglePreview=function(at){if(P||M===at){return}S.find("[name=Preview]").toggleClass("xheActive").toggleClass("xheEnabled");var ar=i(Q.body);if(!M){if(s){Q.body.contentEditable="false"}else{Q.designMode="Off"}ar.attr("class","previewMode");ar[0].innerHTML=ar.html();i("head base",Q).attr("target","_blank")}else{if(s){Q.body.contentEditable="true"}else{Q.designMode="On"}ar.attr("class","editMode"+R);ar[0].innerHTML=ar.html();i("head base",Q).removeAttr("target")}M=!M;S.find("[name=Preview]").toggleClass("xheEnabled");S.find(".xheButton").not("[name=Preview],[name=Fullscreen],[name=About]").toggleClass("xheEnabled");setTimeout(H.setOpts,300)};this.toggleFullscreen=function(au){if(J===au){return}if(t){H.hidePanel()}var at=i("#"+aj).find(".xheLayout"),ar=i("#"+aj);if(J){at.attr("style",T);ad.height(ah-S.outerHeight())}else{T=at.attr("style");at.removeAttr("style");ad.height("100%");setTimeout(H.fixFullHeight,100)}J=!J;ar.toggleClass("xhe_Fullscreen");i("html").toggleClass("xhe_Fullfix");S.find("[name=Fullscreen]").toggleClass("xheActive");setTimeout(H.setOpts,300)};this.showMenu=function(au,av){var at=i('<div class="xheMenu"></div>'),ar;i.each(au,function(ax,aw){ar=i('<a href="javascript:void(0);" title="'+(aw.t?aw.t:aw.s)+'">'+aw.s+"</a>").click(function(){H.focus();av(aw.v);H.hidePanel();return false});at.append(ar)});H.showPanel(at)};this.showColor=function(aw){var at=i('<div class="xheColor"></div>'),au,ar,av=0;au=i("<div></div>");i.each(o,function(ay,ax){av++;ar=i('<a href="javascript:void(0);" title="'+ax+'" style="background:'+ax+'"><img src="'+aq+'img/spacer.gif" /></a>').click(function(){H.focus();aw(ax);H.hidePanel();return false});au.append(ar);if(av%7==0){at.append(au);au=i("<div></div>")}});at.append(au);H.showPanel(at)};this.showPastetext=function(){var at=i(a),au=i("#xhePastetextValue",at),ar=i("#xheSave",at);ar.click(function(){H.focus();var av=au.val();if(av){H.pasteText(av)}H.hidePanel();return false});H.showDialog(at)};this.showLink=function(){var at=i(b),aw=H.getParent("a"),au=i("#xheLinkText",at),ay=i("#xheLinkHref",at),ax=i("#xheLinkTarget",at),ar=i("#xheSave",at),av=H.getSelect();if(aw.length==1){ay.val(H.attr(aw,"href"));ax.attr("value",aw.attr("target"))}else{if(av==""){au.val(H.settings.defLinkText).closest("div").show()}}if(H.settings.upLinkUrl){H.uploadInit(ay,H.settings.upLinkUrl,H.settings.upLinkExt)}ar.click(function(){H.focus();var aC=ay.val();if(aC==""||aw.length==0){H._exec("unlink")}if(aC!=""&&aC!="http://"){var aF=aC.split("|"),aA=ax.val(),aB=au.val();if(aF.length>1){H._exec("unlink");av=H.getSelect();var aE='<a href="xhe_tmpurl"',az;if(aA!=""){aE+=' target="'+aA+'"'}aE+=">xhe_tmptext</a>&nbsp;";aB=(av!=""?av:(aB?aB:aC));for(var aD in aF){aC=aF[aD];if(aC!=""){aC=aC.split(",");az=aE;az=az.replace("xhe_tmpurl",aC[0]);az=az.replace("xhe_tmptext",aC[1]?aC[1]:aB);H.pasteHTML(az)}}}else{aC=aF[0].split(",");if(aw.length==0){if(av==""){if(!aB){aB=aC[0]}H.pasteHTML('<a href="#xhe_tmpurl">'+aB+"</a>")}else{H._exec("createlink","#xhe_tmpurl")}aw=i('a[href$="#xhe_tmpurl"]',Q)}H.attr(aw,"href",aC[0]);if(aA!=""){aw.attr("target",aA)}else{aw.removeAttr("target")}if(aC[1]){aw.text(aC[1])}}}H.hidePanel();return false});H.showDialog(at)};this.showImg=function(){var aA=i(y),au=H.getParent("img"),av=i("#xheImgSrc",aA),aB=i("#xheImgAlt",aA),aD=i("#xheImgAlign",aA),aw=i("#xheImgWidth",aA),ax=i("#xheImgHeight",aA),aC=i("#xheImgBorder",aA),ar=i("#xheImgVspace",aA),ay=i("#xheImgHspace",aA),az=i("#xheSave",aA);if(au.length==1){av.val(H.attr(au,"src"));aB.val(au.attr("alt"));aD.val(au.attr("align"));aw.val(au.attr("width"));ax.val(au.attr("height"));aC.val(au.attr("border"));var at=au.attr("vspace"),aE=au.attr("hspace");ar.val(at<=0?"":at);ay.val(aE<=0?"":aE)}if(H.settings.upImgUrl){H.uploadInit(av,H.settings.upImgUrl,H.settings.upImgExt)}az.click(function(){H.focus();var aF=av.val();if(aF!=""&&aF!="http://"){var aP=aF.split("|"),aM=aB.val(),aN=aD.val(),aG=aw.val(),aJ=ax.val(),aR=aC.val(),aO=ar.val(),aL=ay.val();if(aP.length>1){var aH='<img src="xhe_tmpurl"',aK;if(aM!=""){aH+=' alt="'+aM+'"'}if(aN!=""){aH+=' align="'+aN+'"'}if(aG!=""){aH+=' width="'+aG+'"'}if(aJ!=""){aH+=' height="'+aJ+'"'}if(aR!=""){aH+=' border="'+aR+'"'}if(aO!=""){aH+=' vspace="'+aO+'"'}if(aL!=""){aH+=' hspace="'+aL+'"'}aH+=" />&nbsp;";for(var aI in aP){aF=aP[aI];if(aF!=""){aF=aF.split(",");aK=aH;aK=aK.replace("xhe_tmpurl",aF[0]);if(aF[1]){aK='<a href="'+aF[1]+'" target="_blank">'+aK+"</a>"}H.pasteHTML(aK)}}}else{if(aP.length==1){aF=aP[0];if(aF!=""){aF=aF.split(",");if(au.length==0){H.pasteHTML('<img src="'+aF[0]+'#xhe_tmpurl" />');au=i('img[src$="#xhe_tmpurl"]',Q)}H.attr(au,"src",aF[0]);if(aM!=""){au.attr("alt",aM)}else{au.removeAttr("alt")}if(aN!=""){au.attr("align",aN)}else{au.removeAttr("align")}if(aG!=""){au.attr("width",aG)}else{au.removeAttr("width")}if(aJ!=""){au.attr("height",aJ)}else{au.removeAttr("height")}if(aR!=""){au.attr("border",aR)}else{au.removeAttr("border")}if(aO!=""){au.attr("vspace",aO)}else{au.removeAttr("vspace")}if(aL!=""){au.attr("hspace",aL)}else{au.removeAttr("hspace")}if(aF[1]){var aQ=au.parent("a");if(aQ.length==0){au.wrap("<a></a>");aQ=au.parent("a")}H.attr(aQ,"href",aF[1]);aQ.attr("target","_blank")}}}}}else{if(au.length==1){au.remove()}}H.hidePanel();return false});H.showDialog(aA)};this.showEmbed=function(ar,aC,az,aD,aw,at,au){var aE=i(aC),av=H.getParent('embed[type="'+az+'"],embed[classid="'+aD+'"]'),ay=i("#xhe"+ar+"Src",aE),ax=i("#xhe"+ar+"Width",aE),aA=i("#xhe"+ar+"Height",aE),aB=i("#xheSave",aE);if(at){H.uploadInit(ay,at,au)}H.showDialog(aE);if(av.length==1){ay.val(H.attr(av,"src"));ax.val(av.attr("width"));aA.val(av.attr("height"))}aB.click(function(){H.focus();var aF=ay.val();if(aF!=""&&aF!="http://"){var aN=ax.val(),aJ=aA.val(),aG=/^[0-9]+$/;if(!aG.test(aN)){aN=412}if(!aG.test(aJ)){aJ=300}var aK='<embed type="'+az+'" classid="'+aD+'" src="xhe_tmpurl"'+aw;var aM=aF.split("|");if(aM.length>1){var aH=aK+"",aL;aH+=' width="xhe_width" height="xhe_height" />&nbsp;';for(var aI in aM){aF=aM[aI].split(",");aL=aH;aL=aL.replace("xhe_tmpurl",aF[0]);aL=aL.replace("xhe_width",aF[1]?aF[1]:aN);aL=aL.replace("xhe_height",aF[2]?aF[2]:aJ);if(aF!=""){H.pasteHTML(aL)}}}else{if(aM.length==1){aF=aM[0].split(",");if(av.length==0){H.pasteHTML(aK.replace("xhe_tmpurl",aF[0]+"#xhe_tmpurl")+" />");av=i('embed[src$="#xhe_tmpurl"]',Q)}H.attr(av,"src",aF[0]);av.attr("width",aF[1]?aF[1]:aN);av.attr("height",aF[2]?aF[2]:aJ)}}}else{if(av.length==1){av.remove()}}H.hidePanel();return false})};this.showEmot=function(ax){var av=i('<div class="xheEmot"></div>');ax=ax?ax:(al?al:"default");var aK=ak[ax];var aE=W+ax+"/",aC=0,ar=[],aA="";var aG=aK.width,at=aK.height,ay=aK.line,aw=aK.count,aH=aK.list;if(aw){for(var aD=1;aD<=aw;aD++){aC++;ar.push('<a href="javascript:void(0);" style="background-image:url('+aE+aD+'.gif);" emot="'+ax+","+aD+'">&nbsp;</a>');if(aC%ay==0){ar.push("<br />")}}}else{i.each(aH,function(aM,aL){aC++;ar.push('<a href="javascript:void(0);" style="background-image:url('+aE+aM+'.gif);" emot="'+ax+","+aM+'" title="'+aL+'">&nbsp;</a>');if(aC%ay==0){ar.push("<br />")}})}var az=ay*(aG+12),aF=Math.ceil(aC/ay)*(at+12),aI=az*0.75;if(aF<=aI){aI=""}aA=i("<style>"+(aI?".xheEmot div{width:"+(az+20)+"px;height:"+aI+"px;}":"")+".xheEmot div a{width:"+aG+"px;height:"+at+"px;}</style><div>"+ar.join("")+"</div>");i("a",aA).click(function(){H.focus();H.pasteHTML('<img emot="'+i(this).attr("emot")+'">');H.hidePanel();return false});av.append(aA);var aJ=0,au=["<ul>"],aB;i.each(ak,function(aM,aL){aJ++;au.push("<li"+(ax==aM?' class="cur"':"")+'><a href="javascript:void(0);" group="'+aM+'">'+aL.name+"</a></li>")});if(aJ>1){au.push('</ul><br style="clear:both;" />');aB=i(au.join(""));i("a",aB).click(function(){al=i(this).attr("group");H.showEmot(al);return false});av.append(aB)}H.showPanel(av)};this.showTable=function(){var at=i(h),ar=i("#xheTableRows",at),aD=i("#xheTableColumns",at),aA=i("#xheTableHeaders",at),av=i("#xheTableWidth",at),aw=i("#xheTableHeight",at),aC=i("#xheTableBorder",at),au=i("#xheTableCellSpacing",at),ay=i("#xheTableCellPadding",at),aB=i("#xheTableAlign",at),ax=i("#xheTableCaption",at),az=i("#xheSave",at);az.click(function(){H.focus();var aQ=ax.val(),aP=aC.val(),aI=ar.val(),aE=aD.val(),aG=aA.val(),aF=av.val(),aM=aw.val(),aK=au.val(),aN=ay.val(),aO=aB.val();var aL,aJ,aH="<table"+(aP!=""?' border="'+aP+'"':"")+(aF!=""?' width="'+aF+'"':"")+(aM!=""?' width="'+aM+'"':"")+(aK!=""?' cellspacing="'+aK+'"':"")+(aN!=""?' cellpadding="'+aN+'"':"")+(aO!=""?' align="'+aO+'"':"")+">";if(aQ!=""){aH+="<caption>"+aQ+"</caption>"}if(aG=="row"||aG=="both"){aH+="<tr>";for(aL=0;aL<aE;aL++){aH+='<th scope="col">&nbsp;</th>'}aH+="</tr>";aI--}aH+="<tbody>";for(aL=0;aL<aI;aL++){aH+="<tr>";for(aJ=0;aJ<aE;aJ++){if(aJ==0&&(aG=="col"||aG=="both")){aH+='<th scope="row">&nbsp;</th>'}else{aH+="<td>&nbsp;</td>"}}aH+="</tr>"}aH+="</tbody></table>";H.pasteHTML(aH);H.hidePanel();return false});H.showDialog(at)};this.showAbout=function(){var at=i(r),ar=i("#xheSave",at);ar.click(function(){H.focus();H.hidePanel();return false});H.showDialog(at)};this.attr=function(au,av,ar){if(!av){return false}var at="_xhe_"+av;if(ar){au.attr(av,ar).removeAttr(at).attr(at,ar)}return au.attr(at)||au.attr(av)};this.addShortcuts=function(ar,at){ar=ar.toLowerCase();if(Z[ar]==undefined){Z[ar]=Array()}Z[ar].push(at)};this.checkShortcuts=function(au){if(P||M){return true}am=au;var at=am.which,ar=B[at],aw=ar?ar:String.fromCharCode(at).toLowerCase();sKey="";sKey+=am.ctrlKey?"ctrl+":"";sKey+=am.altKey?"alt+":"";sKey+=am.shiftKey?"shift+":"";sKey+=aw;var av=Z[sKey];if(av){i.each(av,function(ax,ay){if(i.isFunction(ay)){ay.call(H)}else{H.exec(ay)}});return false}};this.uploadInit=function(aw,au,ay,ar){var at=i('<span class="xheUpload"><input type="text" style="visibility:hidden;" tabindex="-1" /><input type="button" value="'+H.settings.upBtnText+'" class="xheBtn" tabindex="-1" /></span>'),av=i(".xheBtn",at);aw.after(at);av.before(aw);if(au.substr(0,1)=="!"){av.click(function(){t=false;H.showIframeModal("上傳文件",au.substr(1),ax,null,null,function(){t=true})})}else{at.append('<input type="file" class="xheFile" size="13" name="filedata" tabindex="-1" />');var az=i(".xheFile",at);az.change(function(){var aB=az.val();if(aB!=""){if(aB.match(new RegExp(".("+ay.replace(/,/g,"|")+")$","i"))){t=false;var aA=H.showModal("文件上傳",'<div style="margin:22px 0;text-align:center;line-height:30px;">文件上傳中，請稍候……<br /><img src="'+aq+'img/loading.gif"></div>',320,150,function(){t=true});H.ajaxUpload(az,au,function(aC){aA.remove();if(aC.err){alert(aC.err)}else{ax(aC.msg)}},function(){aA.remove()})}else{alert("上傳文件擴展名必需為: "+ay)}}})}function ax(aD){var aB=false,aC=H.settings.onUpload,aA=ac(aD,"string")?aD:aD.url;if(aA.substr(0,1)=="!"){aB=true;aA=aA.substr(1)}if(ar){ar(aA)}else{aw.val(aA)}if(aC){aC(aD)}if(aB){aw.closest(".xheDialog").find("#xheSave").click()}}};this.ajaxUpload=function(av,ar,aA,ax){var az=new Date().getTime(),ay="jUploadFrame"+az;var at=i('<iframe name="'+ay+'" class="xheHideArea" />').appendTo("body");var au=i('<form action="'+ar+'" target="'+ay+'" method="post" enctype="multipart/form-data" class="xheHideArea"></form>').appendTo("body");var aB=i(av),aw=aB.clone().attr("disabled","true");aB.before(aw).appendTo(au);au.submit();at.load(function(){setTimeout(function(){aw.before(aB).remove();at.remove();au.remove()},100);var aC=i(at[0].contentWindow.document.body).text(),aE=Object;try{aE=eval("("+aC+")")}catch(aD){}if(aE.err!=undefined&&aE.msg!=undefined){aA(aE)}else{alert(ar+" 上傳接口發生錯誤！\r\n\r\n返回的錯誤內容為: \r\n\r\n"+aC);ax()}})};this.showIframeModal=function(aw,aB,az,ax,au,at){var ar=i('<iframe frameborder="0" src="'+aB+'" style="width:100%;height:100%;display:none;" /><div class="xheModalIfmWait"></div>'),aA=i(ar[0]),av=i(ar[1]);var ay=H.showModal(aw,ar,ax,au,at);aA.load(function(){var aD=aA[0].contentWindow,aC=i(aD.document);aD.callback=function(aE){aC.unbind("keydown",ay.escCheck);ay.remove();az(aE)};aC.keydown(ay.escCheck);aA.show();av.remove()})};this.showModal=function(aB,az,aC,ay,av){if(i(".xheModal").length==1){return false}var au,aD,ar,aA,at;aC=aC?aC:H.settings.modalWidth;ay=ay?ay:H.settings.modalHeight;aA=H.settings.layerShadow;au=i('<div class="xheModal" style="width:'+(aC-1)+"px;height:"+ay+"px;margin-left:-"+Math.ceil(aC/2)+"px;"+(s&&l<=7?"":"margin-top:-"+Math.ceil(ay/2)+"px")+'">'+(H.settings.modalTitle?'<div class="xheModalTitle"><span class="xheModalClose" title="關閉 (Esc)"></span>'+aB+"</div>":"")+'<div class="xheModalContent"></div></div>').appendTo("body");ar=i('<div class="xheModalOverlay"></div>').appendTo("body");if(aA>0){aD=i('<div class="xheModalShadow" style="width:'+au.outerWidth()+"px;height:"+au.outerHeight()+"px;margin-left:-"+(Math.ceil(aC/2)-aA-2)+"px;"+(s&&l<=7?"":"margin-top:-"+(Math.ceil(ay/2)-aA-2)+"px")+'"></div>').appendTo("body")}i(".xheModalContent",au).css("height",ay-(H.settings.modalTitle?i(".xheModalTitle").outerHeight():0)).html(az);if(s&&l==6){at=i("select:visible").css("visibility","hidden")}function ax(){if(at){at.css("visibility","visible")}i(document).unbind("keydown",aw);au.remove();if(aA>0){aD.remove()}ar.remove();if(av){av()}}this.remove=ax;function aw(aE){if(aE.which==27){ax();return false}}this.escCheck=aw;i(document).keydown(aw);i(".xheModalClose",au).click(this.remove);ar.show();if(aA>0){aD.show()}au.show();return this};this.showDialog=function(av){var au=i('<div class="xheDialog"></div>'),ax=i(av),ar=i("#xheSave",ax);if(ar.length==1){ax.find("input[type=text]").keypress(function(ay){if(ay.which==13){ar.click();return false}});ar.after(' <input type="button" id="xheCancel" value="取消" />');i("#xheCancel",ax).click(H.hidePanel);if(!H.settings.clickCancelDialog){m=false;var at=i('<div class="xheFixCancel"></div>').appendTo("body").mousedown(function(){return false});var aw=ad.offset();at.css({left:aw.left,top:aw.top,width:ad.outerWidth(),height:ad.outerHeight()})}}au.append(ax);H.showPanel(au)};this.clickCancelPanel=function(){if(m){H.hidePanel()}};this.showPanel=function(au){if(t){H.hidePanel()}e.empty().append(au).css("left",0).css("top",0);j=i(am.target).closest("a");var av=j.offset();var at=av.left,aw=av.top;aw+=j.outerHeight()-1;j.addClass("xheActive");q.css({left:at+1,top:aw}).show();if((at+e.outerWidth())>document.body.clientWidth){at-=(e.outerWidth()-j.outerWidth())}var ar=H.settings.layerShadow;if(ar>0){A.css({left:at+ar,top:aw+ar,width:e.outerWidth(),height:e.outerHeight()}).show()}e.css("left",at).css("top",aw).show();t=true};this.hidePanel=function(){if(t){j.removeClass("xheActive");A.hide();q.hide();e.hide();t=false;if(!m){i(".xheFixCancel").remove();m=true}}};this.exec=function(av){var ax=v[av].e;if(ax){return ax.call(H)}av=av.toLowerCase();switch(av){case"cut":try{Q.execCommand(av);if(!Q.queryCommandSupported(av)){throw"Error"}}catch(au){alert("您的瀏覽器安全設置不允許使用剪下操作，請使用鍵盤快捷鍵(Ctrl + X)來完成")}break;case"copy":try{Q.execCommand(av);if(!Q.queryCommandSupported(av)){throw"Error"}}catch(au){alert("您的瀏覽器安全設置不允許使用複製操作，請使用鍵盤快捷鍵(Ctrl + C)來完成")}break;case"paste":try{Q.execCommand(av);if(!Q.queryCommandSupported(av)){throw"Error"}}catch(au){alert("您的瀏覽器安全設置不允許使用貼上操作，請使用鍵盤快捷鍵(Ctrl + V)來完成")}break;case"pastetext":if(window.clipboardData){H.pasteText(window.clipboardData.getData("Text",true))}else{H.showPastetext()}break;case"blocktag":var aw=[];i.each(z,function(az,ay){aw.push({s:"<"+ay.n+">"+ay.t+"</"+ay.n+">",v:"<"+ay.n+">",t:ay.t})});H.showMenu(aw,function(ay){H._exec("formatblock",ay)});break;case"fontface":var ar=[];i.each(d,function(az,ay){ay.c=ay.c?ay.c:ay.n;ar.push({s:'<span style="font-family:'+ay.c+'">'+ay.n+"</span>",v:ay.c,t:ay.n})});H.showMenu(ar,function(ay){H._exec("fontname",ay)});break;case"fontsize":var at=[];i.each(w,function(az,ay){at.push({s:'<span style="font-size:'+ay.s+'">'+ay.t+"("+ay.s+")</span>",v:az+1,t:ay.t})});H.showMenu(at,function(ay){H._exec("fontsize",ay)});break;case"fontcolor":H.showColor(function(ay){H._exec("forecolor",ay)});break;case"backcolor":H.showColor(function(ay){if(s){H._exec("backcolor",ay)}else{H.setCSS(true);H._exec("hilitecolor",ay);H.setCSS(false)}});break;case"align":H.showMenu(f,function(ay){H._exec(ay)});break;case"list":H.showMenu(g,function(ay){H._exec(ay)});break;case"link":H.showLink();break;case"img":H.showImg();break;case"flash":H.showEmbed("Flash",D,"application/x-shockwave-flash","clsid:d27cdb6e-ae6d-11cf-96b8-4445535400000",' wmode="opaque" quality="high" menu="false" play="true" loop="true"',H.settings.upFlashUrl,H.settings.upFlashExt);break;case"media":H.showEmbed("Media",x,"application/x-mplayer2","clsid:6bf52a52-394a-11d3-b153-00c04f79faa6",' enablecontextmenu="false" autostart="false"',H.settings.upMediaUrl,H.settings.upMediaExt);break;case"emot":H.showEmot();break;case"table":H.showTable();break;case"source":H.toggleSource();break;case"preview":H.togglePreview();break;case"fullscreen":H.toggleFullscreen();break;case"about":H.showAbout();break;default:H._exec(av);break}};this._exec=function(ar,at){if(at!=undefined){return Q.execCommand(ar,false,at)}else{return Q.execCommand(ar,false,null)}};function U(at,ax){var aw=location.protocol,au=location.hostname,ar=location.port,av=location.pathname.replace(/\\/g,"/").replace(/[^\/]+$/i,"");ar=(ar=="")?"80":ar;at=i.trim(at);if(aw=="file:"){ax="abs"}if(ax!="abs"){at=at.replace(new RegExp(aw+"\\/\\/"+au.replace(/\./g,"\\.")+"(?::"+ar+")"+(ar=="80"?"?":"")+"(/|$)","i"),"/")}if(ax=="rel"){at=at.replace(new RegExp("^"+av.replace(/([\/\.\+\[\]\(\)])/g,"\\$1"),"i"),"")}if(ax!="rel"){if(!at.match(/^((https?|file):\/\/|\/)/i)){at=av+at}}if(ax=="abs"){if(!at.match(/(https?|file):\/\//i)){at=aw+"//"+location.host+at}}return at}};i(function(){i("textarea.xheditor,textarea[xheditor]").xheditor(true);i("textarea.xheditor-mini").xheditor(true,{tools:"mini"});i("textarea.xheditor-simple").xheditor(true,{tools:"simple"})})})(jQuery);