
function DoceboLink(editor) {
    this.editor = editor;
	var cfg = editor.config;
	var self = this;

	cfg.registerButton({
        id       : "docebolink",
        tooltip  : this._lc("Load Link"),
        image    : editor.imgURL("ed_link.gif", "DoceboLink"),
        textMode : false,
        action   : function(editor) {
                     self.buttonPress(editor);
                   }
    });

	cfg.addToolbarElement("docebolink", "createlink", 0);
}

DoceboLink._pluginInfo = {
	name          : "DoceboLink",
	version       : "1.0.0",
	developer     : "Fabio Provano",
	license       : "htmlArea"
};

DoceboLink.prototype._lc = function(string) {
    return HTMLArea._lc(string, 'DoceboLink');
};

DoceboLink.prototype.buttonPress  = function(editor) {
	// Costruzione dell'oggetto parametri da passare alla dialog.
	window.old_text = editor.getSelectedHTML();
	outparam = {
		content : ''//editor.getSelectedHTML()
	}; // Fine costruzione parametri per il passaggio alla dialog.
	editor._popupDialog( '../../mod_link/index_xinha.php?sn=' + DoceboSession, function( html ) {
		if ( !html ) {
			//user must have pressed Cancel
			return false;
		}

		if(html.type == 'link') {
			editor.insertHTML( '<a href="' + html.url + '" title="' + html.title + '">' + html.code + '</a>' );
		}
		else if (html.type == 'wiki_new') {
			editor.insertHTML( '[[' + html.title + ']] ' );
		}
		else if (html.type == 'wiki_sel') {
			editor.insertHTML( '[[' + html.page_code + ' | ' + html.title + ']] ' );
		}

	}, outparam);
};
