// Gaia Ajax Widgets Copyright (C) 2007  Frost Innovation AS. details at http://ajaxwidgets.com/
Gaia.RichEdit=function(element,options){this.initialize(element,options);}
Object.extend(Gaia.RichEdit.prototype,Gaia.WebControl.prototype);Object.extend(Gaia.RichEdit.prototype,{initialize:function(element,options){this.baseInitializeWebControl(element,options);this.element.contentWindow.document.open();this.element.contentWindow.document.write('<html xmlns="http://www.w3.org/1999/xhtml"><head>');if(this.options.cssFile)
this.element.contentWindow.document.write('<link id="cssFile" rel="stylesheet" media="screen" type="text/css" href="'+this.options.cssFile+'"/>');this.element.contentWindow.document.write('</head><body style="margin:0;padding:0">');if(this.options.text)
this.element.contentWindow.document.write(this.options.text);this.element.contentWindow.document.write('</body></html>');this.element.contentWindow.document.close();if(this.element.contentWindow.document.designMode){this.element.contentWindow.document.designMode="on";}else{this.element.contentWindow.document.body.contentEditable=true;}
this.onSubmit=this.submit.bind(this);Element.observe(document.forms[0],'submit',this.onSubmit);var cont=document.createElement('input');cont.type='hidden';cont.id=this.element.id+'_VALUE';cont.name=cont.id;document.getElementsByTagName('form')[0].appendChild(cont);setTimeout(function(){this.setFocus();this.onBlur=this.blur.bind(this);Element.observe(document.body,'mousedown',this.onBlur);}.bind(this),1000);},setCssFile:function(value){this.options.cssFile=value;this.element.contentWindow.document.getElementById('cssFile').href=value;return this;},blur:function(){this.activeElement=this.element.contentWindow.document.activeElement;if(window.getSelection){var sel=this.element.contentWindow.getSelection();if(sel.rangeCount>0){this.currentRange=sel.getRangeAt(0);}}
else if(document.selection){this.currentRange=this.element.contentWindow.document.selection.createRange();}
this.onClick=this.click.bind(this);Element.observe(this.element.contentWindow.document,'mousedown',this.onClick);Element.stopObserving(document.body,'mousedown',this.onBlur);delete this.onBlur;},click:function(){this.onBlur=this.blur.bind(this);Element.observe(document.body,'mousedown',this.onBlur);Element.stopObserving(this.element.contentWindow.document,'mousedown',this.onClick);delete this.onClick;},execCommand:function(cmd,ui,vValue){if(window.getSelection){this.element.contentWindow.document.execCommand(cmd,ui,vValue);}else{if(this.currentRange)
this.currentRange.execCommand(cmd,ui,vValue);else
this.element.contentWindow.document.execCommand(cmd,ui,vValue);}
return this;},pasteHtml:function(value){if(window.getSelection){var range;if(this.currentRange){range=this.currentRange;}else{var sel=this.element.contentWindow.getSelection();range=sel.getRangeAt(0);}
var content=this.element.contentWindow.document.createElement('span');content.innerHTML=value;range.deleteContents();range.insertNode(content);}
else if(document.selection){if(this.currentRange){this.currentRange.select();this.currentRange.pasteHTML(value);}
else
this.element.contentWindow.document.selection.createRange().pasteHTML(value);}
return this;},submit:function(){var cont=$(this.element.id+'_VALUE');var value=this.getElementValue();while(value.indexOf('\r\n')!=-1){value=value.replace('\r\n','{n|n|');}
while(value.indexOf('\n')!=-1){value=value.replace('\n','{n|n|');}
cont.value=value;},setText:function(value){this.element.contentWindow.document.body.innerHTML=value;return this;},setTabIndex:function(value){this.element.tabIndex=value;return this;},setFocus:function(){try{if(navigator.userAgent.toLowerCase().indexOf('opera')!=-1)
this.element.focus();else
this.element.contentWindow.focus();}
catch(err){}
return this;},getSelectedText:function(){if(window.getSelection){if(this.element.contentWindow.document.getSelection){return this.element.contentWindow.document.getSelection();}else{return this.element.contentWindow.getSelection();}}else{return this.element.contentWindow.document.selection.createRange().text;}},getElementValue:function(){var value=this.element.contentWindow.document.body.innerHTML;while(value.indexOf('<')!=-1){value=value.replace('<','{||');}
while(value.indexOf('>')!=-1){value=value.replace('>','||}');}
return value;},_getElementPostValue:function(){var retVal='&'+encodeURIComponent(this.element.id+'_VALUE')+'='+encodeURIComponent(this.getElementValue())+'&'+encodeURIComponent(this.element.id+'_SELECTED')+'='+encodeURIComponent(this.getSelectedText());return retVal;}});Gaia.RichEdit.browserFinishedLoading=true;