
(function($){if(typeof $.fn.rte==="undefined"){var defaults={media_url:"/utils/graphics/rte/",content_css_url:"/thrcss/rte.css",dot_net_button_class:null,max_height:350};$.fn.rte=function(options){$.fn.rte.html=function(iframe){return iframe.contentWindow.document.getElementsByTagName("body")[0].innerHTML;};var opts=$.extend(defaults,options);return this.each(function(){var textarea=$(this);var iframe;var element_id=textarea.attr("id");function enableDesignMode(){var content=textarea.val();if($.trim(content)==''){content='<br />';}
if(iframe){textarea.hide();$(iframe).contents().find("body").html(content);$(iframe).show();$("#toolbar-"+element_id).remove();textarea.before(toolbar());return true;}
iframe=document.createElement("iframe");iframe.frameBorder=0;iframe.frameMargin=0;iframe.framePadding=0;iframe.height=200;if(textarea.attr('class'))
iframe.className=textarea.attr('class');if(textarea.attr('id'))
iframe.id=element_id;if(textarea.attr('name'))
iframe.title=textarea.attr('name');textarea.after(iframe);var css="";if(opts.content_css_url){css="<link type='text/css' rel='stylesheet' href='"+opts.content_css_url+"' />";}
var doc="<html><head>"+css+"</head><body class='frameBody'>"+content+"</body></html>";tryEnableDesignMode(doc,function(){$("#toolbar-"+element_id).remove();textarea.before(toolbar());textarea.hide();});}
function tryEnableDesignMode(doc,callback){if(!iframe){return false;}
try{iframe.contentWindow.document.open();iframe.contentWindow.document.write(doc);iframe.contentWindow.document.close();}catch(error){}
if(document.contentEditable){iframe.contentWindow.document.designMode="On";callback();return true;}
else if(document.designMode!=null){try{iframe.contentWindow.document.designMode="on";callback();return true;}catch(error){}}
setTimeout(function(){tryEnableDesignMode(doc,callback)},500);return false;}
function disableDesignMode(submit){var content=$(iframe).contents().find("body").html();if($(iframe).is(":visible")){textarea.val(content);}
if(submit!==true){textarea.show();$(iframe).hide();}}
function toolbar(){var tb=$("<div class='rte-toolbar' id='toolbar-"+element_id+"'><div><p><a href='#' class='bold'><img src='"+opts.media_url+"bold.png' title='negrita' /></a><a href='#' class='italic'><img src='"+opts.media_url+"italic.png' title='cursiva' /></a><a href='#' class='underline'><img src='"+opts.media_url+"underline.png' title='subrayado' /></a></p><p><a href='#' class='unorderedlist'><img src='"+opts.media_url+"unordered.png' title='lista' /></a><a href='#' class='link'><img src='"+opts.media_url+"link.png' title='link' /></a><a href='#' class='unlink'><img src='"+opts.media_url+"unlink.png' title='quitar link' /></a></p><p><a href='#' class='clean'><img src='"+opts.media_url+"clean.png' title='quitar formato' /></a></p><p><a href='#' class='undo'><img src='"+opts.media_url+"undo.png' title='deshacer' /></a><a href='#' class='redo'><img src='"+opts.media_url+"redo.png' title='rehacer' /></a></p><p><a href='#' class='disable'><img src='"+opts.media_url+"close.png' title='cerrar editor' /></a></p></div></div>");$('select',tb).change(function(){var index=this.selectedIndex;if(index!=0){var selected=this.options[index].value;formatText("formatblock",'<'+selected+'>');}});$('.bold',tb).click(function(){formatText('bold');return false;});$('.italic',tb).click(function(){formatText('italic');return false;});$('.underline',tb).click(function(){formatText('underline');return false;});$('.unorderedlist',tb).click(function(){formatText('insertunorderedlist');return false;});$('.link',tb).click(function(){var p=prompt("URL:");
if(p) formatText('CreateLink',p);return false;});$('.unlink',tb).click(function(){formatText('Unlink');return false;});$('.clean',tb).click(function(){formatText('RemoveFormat');return false;});$('.undo',tb).click(function(){formatText('undo');return false;});$('.redo',tb).click(function(){formatText('redo');return false;});$('.disable',tb).click(function(){disableDesignMode();var edm=$('<a class="rte-edm" href="#">Modo dise&ntilde;o</a>');tb.empty().append(edm);edm.click(function(e){e.preventDefault();enableDesignMode();$(this).remove();});return false;});$(iframe).parents('form').submit(function(){disableDesignMode(true);});var iframeDoc=$(iframe.contentWindow.document);iframeDoc.keyup(function(){var body=$('body',iframeDoc);if(body.scrollTop()>0){var iframe_height=parseInt(iframe.style['height'])
if(isNaN(iframe_height))
iframe_height=0;var h=Math.min(opts.max_height,iframe_height+body.scrollTop())+'px';iframe.style['height']=h;}
return true;});return tb;};function formatText(command,option){iframe.contentWindow.focus();try{iframe.contentWindow.document.execCommand(command,false,option);}catch(e){}
iframe.contentWindow.focus();};function getSelectionElement(){if(iframe.contentWindow.document.selection){selection=iframe.contentWindow.document.selection;range=selection.createRange();try{node=range.parentElement();}
catch(e){return false;}}else{try{selection=iframe.contentWindow.getSelection();range=selection.getRangeAt(0);}
catch(e){return false;}
node=range.commonAncestorContainer;}
return node;};enableDesignMode();$('#csubmit').click(function(e){e.preventDefault();e.stopPropagation();ccontent=iframe.contentWindow.document.getElementsByTagName("body")[0].innerHTML;});});};}})(jQuery);