var editor_style_1=new Abstract({style_init:function(){this.mce_handle=this.el;this.addEvent("click",this.status.bind(this));this.addEvent("click",function(a){if(!this.$init){this.mce_handle.setOpacity(1);"&nbsp;"==this.inc.doc.body.innerHTML.substr(0,6)&&(this.inc.doc.body.innerHTML=this.inc.doc.body.innerHTML.slice(6));var b=this;$ES("img",this.mce_handle).addEvent("click",function(){this.inc.win.focus()}.bind(this));$E(".ft_select",this.mce_handle).addEvent("change",function(a){if(a=this.getValue())Browser.ie&&
b.range&&b.range.select(),b.set("fontName",a)});$E(".fs_select",this.mce_handle).addEvent("change",function(a){if(a=this.getValue())Browser.ie&&b.range&&b.range.select(),b.set("fontSize",a)});$$($E(".fontColorPicker",this.el),$E(".fontBGColorPicker",this.el),$E(".ft_select",this.mce_handle),$E(".fs_select",this.mce_handle)).addEvent("click",function(){this.range=null;Browser.ie&&"none"!=this.getSelection().type.toLowerCase()&&(this.range=this.getRange());Browser.ie||(this.range=this.getRange())}.bind(this));
Ex_Loader("picker",function(){new GoogColorPicker($E(".fontColorPicker",this.el),{onSelect:function(a,b,e){Browser.ie&&this.range&&this.range.select();this.set("forecolor",a)}.bind(this),onShow:function(a){Browser.ie&&this.range&&this.range.select()}.bind(this)});new GoogColorPicker($E(".fontBGColorPicker",this.el),{onSelect:function(a,b,e){if(Browser.ie)return this.range&&this.range.select(),this.set("backColor",a);this.set("hilitecolor",a)}.bind(this),onShow:function(a){Browser.ie&&this.range&&
this.range.select()}.bind(this)})}.bind(this))}this.$init=!0}.bind(this));this.styler=$ES(".x-section",this.el);this.stylerEl=$ES(".x-style",this.el);this.align=$ES(".x-align",this.el);this.setting=$ES(".x-enable",this.el)},status:function(a){new Event(a);this.target||(this.target=a.target.getElementsByTagName("body")[0]||a.target);a=this.target.style;"transparent"==a["background-color"]&&(a["background-color"]="#fff");this.styler.setStyle("background-color","transparent"==a["background-color"]?"#fff":
a["background-color"]);this.stylerEl.setStyle("color",a.color);var b=this.queryValues("Bold","Italic","Underline","strikeThrough","subscript","superscript","align","CreateLink","FontName","FontSize","ForeColor","FormatBlock","insertOrderedList","insertUnorderedList");"center"==b.align?(this.align[0].parentNode.className="",this.align[1].parentNode.className="in",this.align[2].parentNode.className=""):"right"==b.align?(this.align[0].parentNode.className="",this.align[1].parentNode.className="",this.align[2].parentNode.className=
"in"):(this.align[0].parentNode.className="left"==b.align?"in":"",this.align[1].parentNode.className="",this.align[2].parentNode.className="");this.setting.each(function(a){a.parentNode.className=b[a.getAttribute("value")]?"in":""})},set:function(a,b){if(this.inc&&this.inc.win){Browser.ie&&this.inc.win.focus();this.exec(a,b);try{this.status.call(this)}catch(c){}}}}),mceInstance=new Class({Implements:[Events,Options],options:{acitve:!1,maskOpacity:0.5,autoHeight:!1,cleanup:!0,includeBase:!0,disabled:!1},
initialize:function(a,b){this.seri=a;var c="mce_body_"+a;this.el=$(c);this.setOptions(b);b=this.options;this.input=$E("textarea",this.el).set("ishtml","true");this.frmContainer=$(c+"_frm_container");var d=this,e=b.includeBase,g=0,h=this.frm=(new Element("iframe",{src:"about:blank",id:c+"_frm",name:c+"_frm",frameborder:0,border:0})).addEvent("load",function(){if(!g){g=1;var c=h.contentWindow,f="<base href="+SHOPBASE+"/>",f=["<html>\n<head>",e?f:"","<script>window.onerror=function(){return false;}\x3c/script>",
'<link rel="stylesheet" type="text/css" href="'+DESKTOPRESURL+'/wysiwyg_editor.css"/>',"</head>",'<body spellcheck="false" id="'+a+'" style="break-word:break-all;word-wrap:break-word;">',d.cleanup(d.input.getProperty("value"))||"&nbsp;","</body></html>"].join("\n");c.document.open();c.document.write(f);c.document.close();b.disabled?d.input.disabled=!0:(c.document.designMode="on",c.document.addEventListener?c.document.addEventListener("mousedown",d.active.bind(d),!1):c.document.attachEvent("onmousedown",
d.active.bind(d)));d.win=c;d.doc=c.document;d.input.setAttribute("filled","true");this.removeEvent("load",arguments.callee)}});h.inject(this.frmContainer);this.input.getValue=function(){if(!this.input.getAttribute("filled"))return"textarea-unfilled";if("textarea"==this.editType)return this.input.value;var a=this.getValue();return this.input.value=a}.bind(this);this.options.autoHeight&&this.autoHeight.call(this);$(c)&&(this.el=$(c).setStyle("visibility","visible"));this.input.store("mce:instance",
this)},autoHeight:function(){try{this.frm.setStyle("height",this.doc.body.offsetHeight+50)}catch(a){}},setValue:function(){this.doc.body.innerHTML=this.input.value},getValue:function(){return this.cleanup(this.doc.body.innerHTML)},regexpReplace:function(a,b,c,d){if(null==a)return a;"undefined"==typeof d&&(d="g");return a.replace(RegExp(b,d),c)},cleanup:function(a){var b=[[/<br class\="webkit-block-placeholder">/gi,"<br />"],[/<span class="Apple-style-span">(.*)<\/span>/gi,"$1"],[/\s+class="Apple-style-span"/gi,
""],[/<span style="">/gi,""],[/^([\w\s]+.*?)<div>/i,"<p>$1</p><div>"],[/<div>(.+?)<\/div>/ig,"<p>$1</p>"]],c=[[/<br\s*\/?>/gi,"<br/>"],[/^<br\/?>/g,""],[/<br\/?>$/g,""],[/<br\/?>\s*<\/(h1|h2|h3|h4|h5|h6|li|p)/gi,"</$1"],[/<p>\s*<br\/?>\s*<\/p>/gi,"<p> </p>"],[/<p>(&nbsp;|\s)*<\/p>/gi,"<p> </p>"],[/<\/p>\s*<\/p>/g,"</p>"]];c.extend([[/(<(?:img|input)[^\/>]*)>/g,"$1 />"]]);c.extend([[/<li>\s*<div>(.+?)<\/div><\/li>/g,"<li>$1</li>"],[/<span style="font-weight: bold;">(.*)<\/span>/gi,"<strong>$1</strong>"],
[/<span style="font-style: italic;">(.*)<\/span>/gi,"<em>$1</em>"],[/<b\b[^>]*>(.*?)<\/b[^>]*>/gi,"<strong>$1</strong>"],[/<i\b[^>]*>(.*?)<\/i[^>]*>/gi,"<em>$1</em>"],[/<u\b[^>]*>(.*?)<\/u[^>]*>/gi,'<span style="text-decoration: underline;">$1</span>'],[/<p>[\s\n]*(<(?:ul|ol)>.*?<\/(?:ul|ol)>)(.*?)<\/p>/ig,"$1<p>$2</p>"],[/<\/(ol|ul)>\s*(?!<(?:p|ol|ul|img).*?>)((?:<[^>]*>)?\w.*)$/g,"</$1><p>$2</p>"],[/<br[^>]*><\/p>/g,"</p>"],[/<p>\s*(<img[^>]+>)\s*<\/p>/ig,"$1\n"],[/<p([^>]*)>(.*?)<\/p>(?!\n)/g,
"<p$1>$2</p>\n"],[/<\/(ul|ol|p)>(?!\n)/g,"</$1>\n"],[/><li>/g,">\n\t<li>"],[/([^\n])<\/(ol|ul)>/g,"$1\n</$2>"],[/([^\n])<img/ig,"$1\n<img"],[/^\s*$/g,""]]);(Browser.chrome||Browser.safari)&&c.extend(b);c.each(function(b){a=a.replace(b[0],b[1])});return a=a.trim()},active:function(){if(!this.actived){this.actived=!0;var a=this.doc,b=function(a){this.fireEvent("docClick",new Event(a))}.bind(this);a.addEventListener?a.addEventListener("click",b,!1):a.attachEvent("onclick",b)}this.fireEvent("active",
this)},sleep:function(){}}),mceHandler=new Class({Implements:[Events,Options],initialize:function(a,b,c){try{this.el=$(a);this.setOptions(c);if(this.options.disabled){this.el.getElements("input, select").set("disabled",!0);return}$ES("img",this.el).each(function(a){new DropMenu(a)});b&&(b.length?b.each(this.addInstance.bind(this)):this.addInstance.call(this,b))}catch(d){alert(d.message)}"style_init"in this&&this.style_init()},addInstance:function(a){a.addEvent("active",this.active.bind(this));a.addEvent("docClick",
this.docClick.bind(this))},active:function(a){(this.inc=a)&&this.inc.sleep.call(this.inc)},docClick:function(a){this.currentEl=$(a.target);this.fireEvent("click",a)},getSelection:function(){return document.selection?this.inc.doc.selection:this.inc.win.getSelection()},getRange:function(){if(!this.inc)return!1;var a=this.getSelection();if(!a)return null;try{return 0<a.rangeCount?a.getRangeAt(0):a.createRange?a.createRange():null}catch(b){return this.inc.doc.body.createTextRange()}},setRange:function(a){if(a.select)Function.attempt(function(){a.select()});
else{var b=this.getSelection();b.addRange&&(b.removeAllRanges(),b.addRange(a))}},clearSelection:function(){if(window.getSelection){var a=this.inc.win.getSelection();a.deleteFromDocument();a.isCollapsed||a.getRangeAt(0).deleteContents();a.anchorNode&&a.collapse(a.anchorNode,a.anchorOffset)}else document.selection&&this.inc.doc.selection.clear()},emptySelection:function(){var a=this.getSelection();a.empty?a.empty():a.removeAllRanges()},selectNode:function(a,b){var c=this.getRange(),d=this.getSelection();
c.moveToElementText?Function.attempt(function(){c.moveToElementText(a);c.select()}):d.addRange?(b?c.selectNodeContents(a):c.selectNode(a),d.removeAllRanges(),d.addRange(c)):d.setBaseAndExtent(a,0,a,1);return a},isCollapsed:function(){var a=this.getRange();return a.item?!1:0==a.boundingWidth||this.getSelection().isCollapsed},collapse:function(a){var b=this.getRange(),c=this.getSelection();b.select?(b.collapse(a),b.select()):a?c.collapseToStart():c.collapseToEnd()},getContent:function(){var a=this.getRange(),
b=new Element("body");if(this.isCollapsed())return"";a.cloneContents?b.appendChild(a.cloneContents()):void 0!=a.item||void 0!=a.htmlText?b.set("html",a.item?a.item(0).outerHTML:a.htmlText):b.set("html",a.toString());return b.get("html")},getRangeText:function(){var a=this.getRange(),b=this.getSelection();return this.isCollapsed()?"":a.text||(b.toString?b.toString():"")},getNode:function(){var a=this.getRange();if(!Browser.ie){var b=null;if(a)for(b=a.commonAncestorContainer,!a.collapsed&&a.startContainer==
a.endContainer&&2>a.startOffset-a.endOffset&&a.startContainer.hasChildNodes()&&(b=a.startContainer.childNodes[a.startOffset]);"element"!=typeOf(b);)b=b.parentNode;return document.id(b)}return document.id(a.item?a.item(0):a.parentElement())},insertContent:function(a){if(Browser.ie){var b=this.getRange();if(b.pasteHTML)b.pasteHTML(a),b.collapse(!1),b.select();else if(b.insertNode)if(b.deleteContents(),b.createContextualFragment)b.insertNode(b.createContextualFragment(a));else{var c=this.inc.doc,d=c.createDocumentFragment(),
c=c.createElement("div");d.appendChild(c);c.outerHTML=a;b.insertNode(d)}}else this.inc.doc.execCommand("insertHTML",!1,a)},exec:function(a,b){if(!this.busy&&(this.busy=!0,a&&this.inc)){this.dlg&&(Browser.ie&&this.range&&this.range.select(),this.dlg.hide(),this.dlg=null);switch(a){case "formatblock":this.inc.doc.execCommand("FormatBlock",!1,"<"+b+">");break;case "wrap":this.exec("insertHTML",b[0]+this.getRangeText()+b[1]);break;case "insertHTML":"IMG"==this.getNode().tagName&&this.clearSelection();
if(this.replaceEl&&"BODY"==this.replaceEl.tagName)try{var c=this.inc.doc.createElement("div");c.innerHTML=b;c=c.firstChild;this.replaceEl.parentNode.replaceChild(c,this.replaceEl)}catch(d){MessageBox.error(d)}finally{this.replaceEl=null}else Browser.ie?(this.inc.win.focus(),c=this.getRange(),c.pasteHTML&&c.pasteHTML(b)):this.inc.doc.execCommand("insertHTML",!1,b);break;default:try{this.inc.doc.execCommand(a,!1,b)}catch(e){MessageBox.error(e)}}this.busy=!1}},mklink:function(){if(this.inc){this.replaceEl=
null;var a=this.currentEl,b;b=this.getNode();a&&a.tagName&&"body"==a.tagName.toLowerCase()&&!this.getRangeText()||(a&&a.tagName&&"a"==a.tagName.toLowerCase()?(this.isCollapsed()&&this.selectNode(b),b={text:a.innerHTML,href:a.href,alt:a.alt,title:a.title,target:a.target},this.replaceEl=a):(this.isCollapsed()&&this.selectNode(b),b={text:this.getContent()}),this.dialog("link",{height:null,width:450,ajaxoptions:{method:"post",data:b}}))}},editHTML:function(){var a=this;if(this.inc){var b=$("mce_handle_htmledit_"+
this.inc.seri),c=$("mce_handle_"+this.inc.seri);this.inc.input.getValue();b.show();c.hide();this.inc.frm.getSize();this.inc.input.show();this.inc.frmContainer.hide();b.getElement(".returnwyswyg").addEvent("click",function(){c.show();b.hide();a.inc.doc.body.innerHTML=a.inc.input.value.clean().trim();a.inc.input.hide();a.inc.frmContainer.show();a.inc.editType="wysiwyg";this.removeEvent("click",arguments.callee)});this.inc.editType="textarea"}},dialog:function(a,b){if(this.inc){this.inc.win.focus();
this.range=null;this.range=this.getRange();var c="image"==a?"index.php?app=desktop&act=alertpages&goto="+encodeURIComponent("index.php?app=image&ctl=admin_manage&act=image_broswer&type=big"):"index.php?ctl=editor&act="+a;b=Object.filter(b,function(a){return!!a});var d=this;if("image"==a)return Ex_Loader("modedialog",function(){new imgDialog(c,{onCallback:function(a,b){d.insertImg(a,b)}})});this.dlg=new Dialog(c,$merge(b,{modal:!0}));window.curEditor=this}},insertImg:function(a,b,c){a=new Element("img",
{src:b});a=(new Element("div")).adopt(a);c=c?'<div align="center">'+a.get("html")+"</div>":a.get("html");this.exec.bind(this)("insertHTML",c)},queryValue:function(a,b){"align"==a&&(a="justifyRight");try{return b?this.inc.doc.queryCommandState(a):this.inc.doc.queryCommandValue(a)}catch(c){}},queryValues:function(){for(var a={},b="Bold Italic Underline strikeThrough subscript superscript insertOrderedList insertUnorderedList".split(" "),c=0;c<arguments.length;c++)a[arguments[c]]=this.queryValue(arguments[c],
b.contains(arguments[c]));return a}});