function WDFW_LoadCKEditorExtension (_pluginName, _pluginImagePath, _pluginLabel, _pluginFunc) {

	if (typeof(CKEDITOR) != 'undefined') {
	
		if (CKEDITOR.plugins.registered[_pluginName]) { return }
		
		var loadEditorExtension_Execute = { exec: function (editor) {_pluginFunc(editor) } }		
	
		CKEDITOR.plugins.add( _pluginName,
		{
		    init: function (editor) {
		        editor.addCommand(_pluginName, loadEditorExtension_Execute);
		        editor.ui.addButton(_pluginName,
		            {
		                label	: _pluginLabel,
		                icon	: _pluginImagePath,
		                command	: _pluginName
		            });
		    }
		})
	}
	
} // END: WDFW_LoadCKEditorExtension

function WDFW_CKEditor_InsertPicture (_source, _className, _width, _height, _CKEditor) {
	
	var _range = WDFW_CKEditor_GetCursorPosition(_CKEditor);
	if (_className != null) {
		var _img = dojo.create ('img', {src: _source, className: _className});
	} else {
		var _img = dojo.create ('img', {src: _source});
	}
	
	if (_width != '') { dojo.style(_img, 'width', _width+'px') }
	if (_height != '') { dojo.style(_img, 'height', _height+'px') }
	_range.insertNode (_img);
	
} // END: WDFW_CKEditor_InsertPicture

function WDFW_CKEditor_GetCursorPosition (_CKEditor) {

	//var _editor = dojo.query('[id$="'+_editorID+'"]')[0];
	
	if(CKEDITOR.env.ie)	{
	  //CKEDITOR.instances[_editor.id].getSelection().unlock(true);
	  //return(CKEDITOR.instances[_editor.id].getSelection().getNative().createRange().text);
		_CKEditor.getSelection().unlock(true);
		return(_CKEditor.getSelection().getNative().createRange().text);	  
	} else {
	  //return(CKEDITOR.instances[_editor.id].getSelection().getNative().getRangeAt(0));
	  var _selection = _CKEditor.getSelection();
	  var _native = _selection.getNative();
	  var _range = _native.getRangeAt(0);
	  return _range;
	}
	
} // END: WDFW_CKEditor_GetCursorPosition

function WDFW_CKEditor_GetCursorNode (_CKEditor) {

	if(CKEDITOR.env.ie)	{
		_CKEditor.getSelection().unlock(true);
		return(_CKEditor.getSelection().getNative());	  
	} else {
	  var _selection = _CKEditor.getSelection();
	  var _native = _selection.getNative();
	  return _native;
	}

} // END: WDFW_CKEditor_GetCursorNode

function WDFW_CKEditor_GetSelectedText (_CKEditor) {

	var selectedText = '';
	var selection = _CKEditor.getSelection();
	
	if ( selection.getType() == CKEDITOR.SELECTION_TEXT ) {
		if ( CKEDITOR.env.ie ) {
			selection.unlock(true);
			selectedText = selection.getNative().createRange().text;
		} else {
			selectedText = selection.getNative();
		}
	} else if ( selection.getType() == CKEDITOR.SELECTION_ELEMENT ) {
	
		if(CKEDITOR.env.ie)	{
			selectedText = selection.getNative().createRange().text;	  
		} else {
			var _native = selection.getNative();
	  		selectedText = _native.getRangeAt(0);
	  	}
	}
	
	return selectedText.toString();

} // END: WDFW_CKEditor_GetSelectedText
