function setRTEHTML(editorName) {
	//alert(editorName +" = " + YAHOO.widget.EditorInfo.getEditorById(editorName));
	if (YAHOO.widget.EditorInfo.getEditorById(editorName)) {
		//alert("html =" + YAHOO.widget.EditorInfo.getEditorById(editorName).getEditorHTML());
		document.getElementById(editorName).value = YAHOO.lang
				.trim(YAHOO.widget.EditorInfo.getEditorById(editorName)
						.getEditorHTML());
	}
}
function showRichTextEditor(editorName, editorTitle, img_src_url) {    var Dom = YAHOO.util.Dom,
    Event = YAHOO.util.Event,
    win = null;

var myEditor = new YAHOO.widget.Editor(editorName, {
    height: '100px',
    width: '100%',
    autoHeight: true,
    dompath: true, //Turns on the bar at the bottom
    animate: true //Animates the opening, closing and moving of Editor windows
    
});

var state = 'off';

myEditor.on('toolbarLoaded', function() {
    //When the toolbar is loaded, add a listener to the insertimage button
this.toolbar.set('titlebar', editorTitle);
   this.toolbar.on('insertimageClick', function() {
        //Get the selected element
        var _sel = this._getSelectedElement();
        //If the selected element is an image, do the normal thing so they can manipulate the image
        if (_sel && _sel.tagName && (_sel.tagName.toLowerCase() == 'img')) {
            //Do the normal thing here..
        } else {
            //They don't have a selected image, open the image browser window
            win = window.open(img_src_url, 'IMAGE_BROWSER', 'left=20,top=20,width=600,height=500,toolbar=0,resizable=1,status=0,scrollbars=1');
            if (!win) {
                //Catch the popup blocker
                alert('Please disable your popup blocker!!');
            }
            //This is important.. Return false here to not fire the rest of the listeners
            return false;
        }
    }, this, true);
}, myEditor, true);
myEditor.on('afterOpenWindow', function() {
    //When the window opens, disable the url of the image so they can't change it
    var url = Dom.get('insertimage_url');
    if (url) {
        url.disabled = true;
    }
}, myEditor, true);


myEditor.on('toolbarLoaded', function() {
    var codeConfig = {
        type: 'push', label: 'Edit HTML Code', value: 'editcode'
    };
    YAHOO.log('Create the (editcode) Button', 'info', 'example');
    this.toolbar.addButtonToGroup(codeConfig, 'insertitem');
    
    this.toolbar.on('editcodeClick', function() {
        var ta = this.get('element'),
            iframe = this.get('iframe').get('element');

        if (state == 'on') {
            state = 'off';
            this.toolbar.set('disabled', false);
            YAHOO.log('Show the Editor', 'info', 'example');
            YAHOO.log('Inject the HTML from the textarea into the editor', 'info', 'example');
            this.setEditorHTML(ta.value);
            if (!this.browser.ie) {
                this._setDesignMode('on');
            }

            Dom.removeClass(iframe, 'editor-hidden');
            Dom.addClass(ta, 'editor-hidden');
            this.show();
            this._focusWindow();
        } else {
            state = 'on';
            YAHOO.log('Show the Code Editor', 'info', 'example');
            this.cleanHTML();
            YAHOO.log('Save the Editors HTML', 'info', 'example');
            Dom.addClass(iframe, 'editor-hidden');
            Dom.removeClass(ta, 'editor-hidden');
            this.toolbar.set('disabled', true);
            this.toolbar.getButtonByValue('editcode').set('disabled', false);
            this.toolbar.selectButton('editcode');
            this.dompath.innerHTML = 'Editing HTML Code';
            this.hide();
        }
        return false;
    }, this, true);

    this.on('cleanHTML', function(ev) {
        YAHOO.log('cleanHTML callback fired..', 'info', 'example');
        this.get('element').value = ev.html;
    }, this, true);
    
    this.on('afterRender', function() {
        var wrapper = this.get('editor_wrapper');
        wrapper.appendChild(this.get('element'));
        this.setStyle('width', '100%');
        this.setStyle('height', '100%');
        this.setStyle('visibility', '');
        this.setStyle('top', '');
        this.setStyle('left', '');
        this.setStyle('position', '');

        this.addClass('editor-hidden');
    }, this, true);
}, myEditor, true);


myEditor.render();
}
