var wysiwyg=new Class({initialize:function(c){this.TA=c.textarea||document.getElement('textarea');this.TB=new Element('div',{'class':'toolbar'});this.IF=new Element('iframe',{'frameborder':0,'src':(c.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':(c.klass||'wysiwyg')}).injectBefore(this.TA).adopt(this.TB,this.IF,this.TA);this.open=false;$each((c.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 a=new Event(e);a.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.pass([b], this))).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(a){this.TA.value=this.clean(this.doc.body.innerHTML);if(a){this.TA.removeClass('hidden');this.IF.addClass('hidden');this.TB.addClass('disabled');this.TA.focus()}},toEditor:function(a){var b=this.TA.value.trim();this.doc.body.innerHTML=b==''?'

 

':b;if(a){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 a=v||but[1];if(!v&&but[2]){if(!(a=prompt(but[1],but[2]))){return}}this.doc.execCommand(but[0],false,a)}},clean:function(c){return c.replace(/\s{2,}/g,' ').replace(/^\s+|\s+$/g,'').replace(/\n/g,'').replace(/<[^> ]*/g,function(s){return s.toLowerCase()}).replace(/<[^>]*>/g,function(s){s=s.replace(/ [^=]+=/g,function(a){return a.toLowerCase()});return s}).replace(/<[^>]*>/g,function(s){s=s.replace(/( [^=]+=)([^"][^ >]*)/g,"$1\"$2\"");return s}).replace(/<[^>]*>/g,function(s){s=s.replace(/ ([^=]+)="[^"]*"/g,function(a,b){if(b=='alt'||b=='href'||b=='src'||b=='title'||b=='style'){return a}return''});return s}).replace(/)/g,")/g,")/g,")/g,"(.+?)<\/span>/gm,'$1').replace(/(.+?)<\/span>/gm,'$1').replace(/(.+?)<\/span>/gm,'$1').replace(/(.+?)<\/span>/gm,'$2').replace(/]*)">/g,'Image').replace(/(]+[^\/])>/g,"$1 />").replace(/(.+?)<\/u>/gm,'$1').replace(/]*?>(.+?)<\/font>/gm,'$1').replace(/|<\/font>/gm,'').replace(/
\s*<\/(h1|h2|h3|h4|h5|h6|li|p)/g,'/g,'
').replace(/<(table|tbody|tr|td|th)[^>]*>/g,'<$1>').replace(/<\?xml[^>]*>/g,'').replace(/<[^ >]+:[^>]*>/g,'').replace(/<\/[^ >]+:[^>]*>/g,'').replace(/(<[^\/]>|<[^\/][^>]*[^\/]>)\s*<\/[^>]*>/g,'')}});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','

'],h2:['formatblock','

'],h3:['formatblock','

'],p:['formatblock','

'],ul:['insertunorderedlist',null],ol:['insertorderedlist',null],link:['createlink','Ingrese la URL:','http://'],unlink:['unlink',null],img:['insertimage','Ingrese la URL de la imagen:','http://'],clean:['removeformat',null],toggle:['toggleview']};