(function($){$.fn.document=function(){var a=this[0];if(a.nodeName.toLowerCase()=='iframe')return a.contentWindow.document;else return $(this)};$.fn.documentSelection=function(){var a=this[0];if(a.contentWindow.document.selection)return a.contentWindow.document.selection.createRange().text;else return a.contentWindow.getSelection().toString()};$.fn.wysiwyg=function(a){if(arguments.length>0&&arguments[0].constructor==String){var b=arguments[0].toString();var c=[];for(var i=1;i<arguments.length;i++)c[i-1]=arguments[i];if(b in Wysiwyg){return this.each(function(){$.data(this,'wysiwyg').designMode();Wysiwyg[b].apply(this,c)})}else return this}var d={};if(a&&a.controls){var d=a.controls;delete a.controls}var a=$.extend({html:'<'+'?xml version="1.0" encoding="UTF-8"?'+'><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">STYLE_SHEET</head><body>INITIAL_CONTENT</body></html>',css:{},debug:false,autoSave:true,rmUnwantedBr:true,brIE:true,controls:{},messages:{}},a);a.messages=$.extend(true,a.messages,Wysiwyg.MSGS_EN);a.controls=$.extend(true,a.controls,Wysiwyg.TOOLBAR);for(var e in d){if(e in a.controls)$.extend(a.controls[e],d[e]);else a.controls[e]=d[e]}return this.each(function(){Wysiwyg(this,a)})};function Wysiwyg(a,b){return this instanceof Wysiwyg?this.init(a,b):new Wysiwyg(a,b)}$.extend(Wysiwyg,{insertImage:function(a,b){var c=$.data(this,'wysiwyg');if(c.constructor==Wysiwyg&&a&&a.length>0){if(b){c.editorDoc.execCommand('insertImage',false,'#jwysiwyg#');var d=c.getElementByAttributeValue('img','src','#jwysiwyg#');if(d){d.src=a;for(var e in b){d.setAttribute(e,b[e])}}}else{c.editorDoc.execCommand('insertImage',false,a)}}},createLink:function(a){var b=$.data(this,'wysiwyg');if(b.constructor==Wysiwyg&&a&&a.length>0){var c=$(b.editor).documentSelection();if(c.length>0){b.editorDoc.execCommand('unlink',false,[]);b.editorDoc.execCommand('createLink',false,a)}else if(b.options.messages.nonSelection)alert(b.options.messages.nonSelection)}},setContent:function(a){var b=$.data(this,'wysiwyg');b.setContent(a);b.saveContent()},clear:function(){var a=$.data(this,'wysiwyg');a.setContent('');a.saveContent()},MSGS_EN:{nonSelection:'select the text you wish to link'},TOOLBAR:{bold:{visible:true,tags:['b','strong'],css:{fontWeight:'bold'}},italic:{visible:true,tags:['i','em'],css:{fontStyle:'italic'}},strikeThrough:{visible:false,tags:['s','strike'],css:{textDecoration:'line-through'}},underline:{visible:false,tags:['u'],css:{textDecoration:'underline'}},separator00:{visible:false,separator:true},justifyLeft:{visible:false,css:{textAlign:'left'}},justifyCenter:{visible:false,tags:['center'],css:{textAlign:'center'}},justifyRight:{visible:false,css:{textAlign:'right'}},justifyFull:{visible:false,css:{textAlign:'justify'}},separator01:{visible:false,separator:true},indent:{visible:false},outdent:{visible:false},separator02:{visible:false,separator:true},subscript:{visible:false,tags:['sub']},superscript:{visible:false,tags:['sup']},separator03:{visible:false,separator:true},undo:{visible:false},redo:{visible:false},separator04:{visible:false,separator:true},insertOrderedList:{visible:false,tags:['ol']},insertUnorderedList:{visible:false,tags:['ul']},insertHorizontalRule:{visible:false,tags:['hr']},separator05:{separator:true},createLink:{visible:true,exec:function(){var a=$(this.editor).documentSelection();if(a.length>0){if($.browser.msie)this.editorDoc.execCommand('createLink',true,null);else{var b=prompt('URL','http://');if(b&&b.length>0){this.editorDoc.execCommand('unlink',false,[]);this.editorDoc.execCommand('createLink',false,b)}}}else if(this.options.messages.nonSelection)alert(this.options.messages.nonSelection)},tags:['a']},insertImage:{visible:true,exec:function(){if($.browser.msie)this.editorDoc.execCommand('insertImage',true,null);else{var a=prompt('URL','http://');if(a&&a.length>0)this.editorDoc.execCommand('insertImage',false,a)}},tags:['img']},separator06:{separator:true},h1mozilla:{visible:true&&$.browser.mozilla,className:'h1',command:'heading',arguments:['h1'],tags:['h1']},h2mozilla:{visible:true&&$.browser.mozilla,className:'h2',command:'heading',arguments:['h2'],tags:['h2']},h3mozilla:{visible:true&&$.browser.mozilla,className:'h3',command:'heading',arguments:['h3'],tags:['h3']},h1:{visible:true&&!($.browser.mozilla),className:'h1',command:'formatBlock',arguments:['Heading 1'],tags:['h1']},h2:{visible:true&&!($.browser.mozilla),className:'h2',command:'formatBlock',arguments:['Heading 2'],tags:['h2']},h3:{visible:true&&!($.browser.mozilla),className:'h3',command:'formatBlock',arguments:['Heading 3'],tags:['h3']},separator07:{visible:false,separator:true},cut:{visible:false},copy:{visible:false},paste:{visible:false},separator08:{separator:true&&!($.browser.msie)},increaseFontSize:{visible:true&&!($.browser.msie),tags:['big']},decreaseFontSize:{visible:true&&!($.browser.msie),tags:['small']},separator09:{separator:true},html:{visible:false,exec:function(){if(this.viewHTML){this.setContent($(this.original).val());$(this.original).hide()}else{this.saveContent();$(this.original).show()}this.viewHTML=!(this.viewHTML)}},removeFormat:{visible:true,exec:function(){this.editorDoc.execCommand('removeFormat',false,[]);this.editorDoc.execCommand('unlink',false,[])}}}});$.extend(Wysiwyg.prototype,{original:null,options:{},element:null,editor:null,init:function(a,b){var c=this;this.editor=a;this.options=b||{};$.data(a,'wysiwyg',this);var d=a.width||a.clientWidth;var e=a.height||a.clientHeight;if(a.nodeName.toLowerCase()=='textarea'){this.original=a;if(d==0&&a.cols)d=(a.cols*8)+21;if(e==0&&a.rows)e=(a.rows*16)+16;var f=this.editor=$('<iframe></iframe>').css({minHeight:(e-6).toString()+'px',width:(d-8).toString()+'px'}).attr('id',$(a).attr('id')+'IFrame');if($.browser.msie){this.editor.css('height',(e).toString()+'px')}}var g=this.panel=$('<ul></ul>').addClass('panel');this.appendControls();this.element=$('<div></div>').css({width:(d>0)?(d).toString()+'px':'100%'}).addClass('wysiwyg').append(g).append($('<div><!-- --></div>').css({clear:'both'})).append(f);$(a).hide().before(this.element);this.viewHTML=false;this.initialHeight=e-8;this.initialContent=$(a).val();this.initFrame();if(this.initialContent.length==0)this.setContent('');if(this.options.autoSave)$('form').submit(function(){c.saveContent()});$('form').bind('reset',function(){c.setContent(c.initialContent);c.saveContent()})},initFrame:function(){var c=this;var d='';if(this.options.css&&this.options.css.constructor==String)d='<link rel="stylesheet" type="text/css" media="screen" href="'+this.options.css+'" />';this.editorDoc=$(this.editor).document();this.editorDoc_designMode=false;try{this.editorDoc.designMode='on';this.editorDoc_designMode=true}catch(e){$(this.editorDoc).focus(function(){c.designMode()})}this.editorDoc.open();this.editorDoc.write(this.options.html.replace(/INITIAL_CONTENT/,this.initialContent).replace(/STYLE_SHEET/,d));this.editorDoc.close();this.editorDoc.contentEditable='true';if($.browser.msie){setTimeout(function(){$(c.editorDoc.body).css('border','none')},0)}$(this.editorDoc).click(function(a){c.checkTargets(a.target?a.target:a.srcElement)});$(this.original).focus(function(){$(c.editorDoc.body).focus()});if(this.options.autoSave){$(this.editorDoc).keydown(function(){c.saveContent()}).keyup(function(){c.saveContent()}).mousedown(function(){c.saveContent()})}if(this.options.css){setTimeout(function(){if(c.options.css.constructor==String){}else $(c.editorDoc).find('body').css(c.options.css)},0)}$(this.editorDoc).keydown(function(a){if($.browser.msie&&c.options.brIE&&a.keyCode==13){var b=c.getRange();b.pasteHTML('<br />');b.collapse(false);b.select();return false}})},designMode:function(){if(!(this.editorDoc_designMode)){try{this.editorDoc.designMode='on';this.editorDoc_designMode=true}catch(e){}}},getSelection:function(){return(window.getSelection)?window.getSelection():document.selection},getRange:function(){var a=this.getSelection();if(!(a))return null;return(a.rangeCount>0)?a.getRangeAt(0):a.createRange()},getContent:function(){return $($(this.editor).document()).find('body').html()},setContent:function(a){$($(this.editor).document()).find('body').html(a)},saveContent:function(){if(this.original){var a=this.getContent();if(this.options.rmUnwantedBr)a=(a.substr(-4)=='<br>')?a.substr(0,a.length-4):a;$(this.original).val(a)}},appendMenu:function(a,b,c,d){var e=this;var b=b||[];$('<li></li>').append($('<a><!-- --></a>').addClass(c||a)).mousedown(function(){if(d)d.apply(e);else e.editorDoc.execCommand(a,false,b);if(e.options.autoSave)e.saveContent()}).appendTo(this.panel)},appendMenuSeparator:function(){$('<li class="separator"></li>').appendTo(this.panel)},appendControls:function(){for(var a in this.options.controls){var b=this.options.controls[a];if(b.separator){if(b.visible!==false)this.appendMenuSeparator()}else if(b.visible){this.appendMenu(b.command||a,b.arguments||[],b.className||b.command||a||'empty',b.exec)}}},checkTargets:function(a){for(var b in this.options.controls){var c=this.options.controls[b];var d=c.className||c.command||b||'empty';$('.'+d,this.panel).removeClass('active');if(c.tags){var e=a;do{if(e.nodeType!=1)break;if($.inArray(e.tagName.toLowerCase(),c.tags)!=-1)$('.'+d,this.panel).addClass('active')}while(e=e.parentNode)}if(c.css){var e=$(a);do{if(e[0].nodeType!=1)break;for(var f in c.css)if(e.css(f).toString().toLowerCase()==c.css[f])$('.'+d,this.panel).addClass('active')}while(e=e.parent())}}},getElementByAttributeValue:function(a,b,c){var d=this.editorDoc.getElementsByTagName(a);for(var i=0;i<d.length;i++){var e=d[i].getAttribute(b);if($.browser.msie){e=e.substr(e.length-c.length)}if(e==c)return d[i]}return false}})})(jQuery);