var UIF={frame:function(n,c){var i=document.getElementById(n);if(!i){var d=document.createElement("DIV");d.className="hidden";d.innerHTML="<iframe src=\"about:blank\" id=\""+n+"\" name=\""+n+"\" onload=\"UIF.onLoad('"+n+"')\"></iframe>";document.body.appendChild(d);i=document.getElementById(n);}i.onComplete=c;return n;},send:function(f,n,c){f.setAttribute("target",UIF.frame(n,c));},onLoad:function(n){var i=document.getElementById(n);if(i.contentDocument){var d=i.contentDocument;}else{if(i.contentWindow){var d=i.contentWindow.document;}else{var d=window.frames[n].document;}}if(d.location.href=="about:blank"){return;}i.onComplete(d.body.innerHTML);}};var wysiwyg=new Class({initialize:function(_3452){this.TA=_3452.textarea||document.getElement("textarea");this.TB=new Element("div",{"class":"toolbar"});this.IF=new Element("iframe",{"frameborder":0,"src":(_3452.src||"about:blank")}).addEvent("load",function(){this.doc=this.IF.contentWindow.document;this.doc.designMode="on";this.toggleView();}.bind(this));this.CT=new Element("div",{"class":(_3452.klass||"wysiwyg")}).injectBefore(this.TA).adopt(this.TB,this.IF,this.TA);this.open=false;$each((_3452.buttons||["strong","em","u","superscript","subscript",null,"left","center","right","indent","outdent",null,"h1","h2","h3","p","ul","ol",null,"img","link","unlink",null,"clean","toggle"]),function(b){if(!b){new Element("span",{"class":"spacer"}).inject(this.TB);}else{if(Browser.Engine.trident){new Element("a",{"class":b,"href":"//"+b}).addEvent("click",function(e){var ev=new Event(e);ev.stop();if(b=="toggle"){this.toggleView();}else{this.exec(b);}}.bind(this)).inject(this.TB);}else{new Element("span",{"class":b}).addEvent("click",(b=="toggle"?this.toggleView.bind(this):this.exec.bind(this,[b]))).inject(this.TB);}}},this);},toggleView:function(){if($try(function(){if(this.doc.body){return true;}}.bind(this))){if(this.open){this.toTextarea(true);}else{this.toEditor(true);}this.open=!this.open;}},toTextarea:function(view){this.TA.value=this.clean(this.doc.body.innerHTML);if(view){this.TA.removeClass("hidden");this.IF.addClass("hidden");this.TB.addClass("disabled");this.TA.focus();}},toEditor:function(view){var val=this.TA.value.trim();if(Browser.Engine.trident){if(val!=""){this.doc.write(val);}}else{this.doc.body.innerHTML=val==""?"":val;if(Browser.Engine.gecko){this.IF.setStyle("display","none");this.IF.setStyle("display","block");}}if(view){this.TA.addClass("hidden");this.IF.removeClass("hidden");this.TB.removeClass("disabled");}},exec:function(b,v){if(this.open){this.IF.contentWindow.focus();but=_BUTTONS[b];var val=v||but[1];if(!v&&but[2]){if(!(val=prompt(but[1],but[2]))){return;}}this.doc.execCommand(but[0],false,val);}},clean:function(html){return this.pastefromword(html);},pastefromword:function(html){return wdg_editor_pastefromword(html);}});var _BUTTONS={strong:["bold",null],em:["italic",null],u:["underline",null],superscript:["superscript",null],subscript:["subscript",null],left:["justifyleft",null],center:["justifycenter",null],right:["justifyright",null],indent:["indent",null],outdent:["outdent",null],h1:["formatblock","<H1>"],h2:["formatblock","<H2>"],h3:["formatblock","<H3>"],p:["formatblock","<P>"],ul:["insertunorderedlist",null],ol:["insertorderedlist",null],link:["createlink","Insert URL:","http://"],unlink:["unlink",null],img:["insertimage","Insert Image URL:","http://"],clean:["removeformat",null],toggle:["toggleview"]};function wdg_editor_init(){$$("textarea").each(function(item){if(item.getProperty("class").indexOf("nohtml")==-1){var W2=new wysiwyg({textarea:item});}});}function wdg_editor_init_editor(el){el.getElements("textarea").each(function(item){if(item.getProperty("class").indexOf("nohtml")==-1){var W2=new wysiwyg({textarea:item});}});}function wdg_editor_update_change(){$$("textarea").each(function(item){var _3464=item.getPrevious();if(_3464){if(_3464.get("tag")=="iframe"){var doc=_3464.contentWindow.document;var value=wdg_editor_cleanHTML(doc.body.innerHTML);item.set("text",value);}}});}function wdg_editor_cleanHTML(html){return wdg_editor_pastefromword(html);}function wdg_editor_insert_image(el,url){try{var _346a=el.getPrevious();}catch(e){var _346a=$(el).getPrevious();}if(_346a){_346a.contentWindow.focus();_346a.contentWindow.document.execCommand("insertimage",false,url);}}function wdg_editor_insert_html(el,html){try{var _346d=el.getPrevious();}catch(e){var _346d=$(el).getPrevious();}if(_346d){_346d.contentWindow.focus();if(!Browser.Engine.trident){_346d.contentWindow.document.execCommand("insertHTML",false,html);}else{_346d.contentWindow.document.selection.createRange().pasteHTML(html);}}}function wdg_editor_replace_html(el,html){try{var _3470=el.getPrevious();}catch(e){var _3470=$(el).getPrevious();}if(_3470){_3470.contentWindow.focus();_3470.contentWindow.document.body.innerHTML=html;}}function wdg_editor_pastefromword(html){html=html.replace(/<\!--[\s\S]*?-->/g,"");html=html.replace(/<o:p>\s*<\/o:p>/g,"");html=html.replace(/<o:p>[\s\S]*?<\/o:p>/g,"&nbsp;");html=html.replace(/\s*mso-[^:]+:[^;"]+;?/gi,"");html=html.replace(/\s*MARGIN: 0(?:cm|in) 0(?:cm|in) 0pt\s*;/gi,"");html=html.replace(/\s*MARGIN: 0(?:cm|in) 0(?:cm|in) 0pt\s*"/gi,"\"");html=html.replace(/\s*TEXT-INDENT: 0cm\s*;/gi,"");html=html.replace(/\s*TEXT-INDENT: 0cm\s*"/gi,"\"");html=html.replace(/\s*PAGE-BREAK-BEFORE: [^\s;]+;?"/gi,"\"");html=html.replace(/\s*FONT-VARIANT: [^\s;]+;?"/gi,"\"");html=html.replace(/\s*tab-stops:[^;"]*;?/gi,"");html=html.replace(/\s*tab-stops:[^"]*/gi,"");ignoreFont=true;if(ignoreFont){html=html.replace(/\s*face="[^"]*"/gi,"");html=html.replace(/\s*face=[^ >]*/gi,"");html=html.replace(/\s*FONT-FAMILY:[^;"]*;?/gi,"");}html=html.replace(/<(\w[^>]*) class=([^ |>]*)([^>]*)/gi,"<$1$3");removeStyles=false;if(removeStyles){html=html.replace(/<(\w[^>]*) style="([^\"]*)"([^>]*)/gi,"<$1$3");}html=html.replace(/<STYLE[^>]*>[\s\S]*?<\/STYLE[^>]*>/gi,"");html=html.replace(/<(?:META|LINK)[^>]*>\s*/gi,"");html=html.replace(/<(\w[^>]*) lang=([^ |>]*)([^>]*)/gi,"<$1$3");html=html.replace(/<SPAN\s*>([\s\S]*?)<\/SPAN>/gi,"$1");html=html.replace(/<FONT\s*>([\s\S]*?)<\/FONT>/gi,"$1");html=html.replace(/<\\?\?xml[^>]*>/gi,"");html=html.replace(/<w:[^>]*>[\s\S]*?<\/w:[^>]*>/gi,"");html=html.replace(/<\/?\w+:[^>]*>/gi,"");html=html.replace(/<(U|I|STRIKE)>&nbsp;<\/\1>/g,"&nbsp;");html=html.replace(/<H\d>\s*<\/H\d>/gi,"");html=html.replace(/<(\w+)[^>]*\sstyle="[^"]*DISPLAY\s?:\s?none[\s\S]*?<\/\1>/ig,"");html=html.replace(/<(\w[^>]*) language=([^ |>]*)([^>]*)/gi,"<$1$3");html=html.replace(/<(\w[^>]*) onmouseover="([^\"]*)"([^>]*)/gi,"<$1$3");html=html.replace(/<(\w[^>]*) onmouseout="([^\"]*)"([^>]*)/gi,"<$1$3");pasteFromWordKeepsStructure=true;if(pasteFromWordKeepsStructure){html=html.replace(/<H(\d)([^>]*)>/gi,"<h$1>");html=html.replace(/<(H\d)><FONT[^>]*>([\s\S]*?)<\/FONT><\/\1>/gi,"<$1>$2</$1>");html=html.replace(/<(H\d)><EM>([\s\S]*?)<\/EM><\/\1>/gi,"<$1>$2</$1>");}else{html=html.replace(/<H1([^>]*)>/gi,"<div$1><b><font size=\"6\">");html=html.replace(/<H2([^>]*)>/gi,"<div$1><b><font size=\"5\">");html=html.replace(/<H3([^>]*)>/gi,"<div$1><b><font size=\"4\">");html=html.replace(/<H4([^>]*)>/gi,"<div$1><b><font size=\"3\">");html=html.replace(/<H5([^>]*)>/gi,"<div$1><b><font size=\"2\">");html=html.replace(/<H6([^>]*)>/gi,"<div$1><b><font size=\"1\">");html=html.replace(/<\/H\d>/gi,"</font></b></div>");var re=new RegExp("(<P)([^>]*>[\\s\\S]*?)(</P>)","gi");html=html.replace(re,"<div$2</div>");html=html.replace(/<([^\s>]+)(\s[^>]*)?>\s*<\/\1>/g,"");html=html.replace(/<([^\s>]+)(\s[^>]*)?>\s*<\/\1>/g,"");html=html.replace(/<([^\s>]+)(\s[^>]*)?>\s*<\/\1>/g,"");}return html;}
