
var fmWindow;
var fmFolder;
var fmPortalID;
var fmSrcField;
var fmSrcType;

function fmInit(folderName, portalID) {
	fmFolder	= folderName;
	fmPortalID	= portalID;
}

function fileBrowserCallBack(field_name, url, type, win) {

	fmWindow	= win;
	fmSrcField	= field_name;
	fmSrcType	= type;

	var fmWinUrl	= '/admin/filemanager/index.php?Folder=' + fmFolder + '&Field=' + field_name + '&Portal=' + fmPortalID;
	var fmWinName	= 'FileManager';
	var fmWinOpts	= 'width=640,height=480,toolbar=0,menubar=0,location=0,directories=0,status=0,copyhistory=0,resizable=1,scrollbars=1';

	window.open(fmWinUrl, fmWinName, fmWinOpts);
}

function callBackReturn(field_name, url) {
	fmWindow.document.forms[0].elements[field_name].value = url;
	if(fmSrcType == 'image') {
		if(!fmWindow.document.forms[0].elements['alt'].value) {
			fmWindow.document.forms[0].elements['alt'].value 	= 'Obrazok';
			fmWindow.document.forms[0].elements['title'].value	= 'Obrazok';
		}
		fmWindow.showPreviewImage(url);
	}
}

function returnUrl(field, url){
	window.opener.callBackReturn(field, url);
	top.close(this);
}

function noFileBrowser() {
	return false;
}

function editorInstanceInit(textareaID, toolbarSet, folder, theme, height, portalID) {

	var buttonsDisable;
	var buttons1,
		buttons2,
		buttons3
	;
	var buttons1_add,
		buttons2_add,
		buttons3_add
	;

	var fileBrowserCallback;
	var plugins;
	var contentCss;

	contentCss   = '/schemes/' + theme + '/css/?scheme=' + theme + '&files=editor';

	switch(toolbarSet) {

		case 'Basic':

			buttonsDisable	= "styleselect, cleanup, help, newdocument";

			//buttons1		= "cut,copy,paste,pastetext,pasteword,separator,undo,redo,separator";
			buttons1		= "undo,redo,separator";
			buttons1_add	= "bold,italic,underline,separator,bullist,numlist,separator,outdent,indent,separator,sub,sup,separator,link,unlink,emotions,separator,forecolor,backcolor";

			buttons2		= "";
			buttons2_add	= "";

			buttons3		= "";
			buttons3_add	= "";

			plugins			= "inlinepopups,table,advlink,emotions,insertdatetime,searchreplace,contextmenu,paste,style";

			fileBrowserCallback	= 'noFileBrowser';
			break;

		case 'Discussion':

			buttonsDisable	= "styleselect, cleanup, help, newdocument";

			//buttons1		= "cut,copy,paste,pastetext,pasteword,separator,undo,redo,separator";
			buttons1		= "undo,redo,separator";
			buttons1_add	= "bold,italic,underline,separator,bullist,numlist,separator,outdent,indent,separator,sub,sup,separator,link,unlink,emotions,separator,forecolor,backcolor";

			buttons2		= "";
			buttons2_add	= "";

			buttons3		= "";
			buttons3_add	= "";

			plugins			= "inlinepopups,table,advimage,advlink,emotions,insertdatetime,flash,searchreplace,contextmenu,paste,style";

			fileBrowserCallback	= "fileBrowserCallBack";
			break;

		case 'Standard':

			buttonsDisable	= "cleanup, help, newdocument";

			//buttons1		= "code,separator,cut,copy,paste,pastetext,pasteword,separator,undo,redo,separator,replace,separator";
			buttons1		= "code,separator,undo,redo,separator,replace,separator";
			buttons1_add	= "bold,italic,underline,separator,justifyleft,justifycenter,justifyright,justifyfull,separator,bullist,numlist,separator,outdent,indent,separator,sub,sup";

			buttons2		= "visualaid,table,separator,link,unlink,anchor,separator,hr,image,emotions,flash,separator,charmap,separator";
			buttons2_add	= "forecolor,backcolor,removeformat,separator,formatselect,styleselect";
/*
,styleprops
*/
			buttons3		= "";
			buttons3_add	= "";

			plugins			= "inlinepopups,table,advimage,advlink,emotions,insertdatetime,flash,searchreplace,contextmenu,paste,style";

			fileBrowserCallback	= "fileBrowserCallBack";
			break;

		case 'Advanced':

			buttonsDisable	= "styleselect, cleanup, help, newdocument";

			//buttons1		= "code,separator,cut,copy,paste,pastetext,pasteword,separator,undo,redo,separator,replace,separator";
			buttons1		= "code,separator,undo,redo,separator,replace,separator";
			buttons1_add	= "bold,italic,underline,separator,justifyleft,justifycenter,justifyright,justifyfull,separator,bullist,numlist,separator,outdent,indent,separator,sub,sup";

			buttons2		= "visualaid,table,separator,link,unlink,anchor,separator,hr,image,emotions,flash,separator,charmap,separator";
			buttons2_add	= "forecolor,backcolor,removeformat,separator,formatselect";

			buttons3		= "";
			buttons3_add	= "";

			plugins			= "inlinepopups,table,advimage,advlink,emotions,insertdatetime,flash,searchreplace,contextmenu,paste,style";

			fileBrowserCallback	= "fileBrowserCallBack";
			break;

		case 'Full':

			buttonsDisable	= "styleselect, cleanup, help, newdocument";

			//buttons1		= "code,separator,cut,copy,paste,pastetext,pasteword,separator,undo,redo,separator,replace,separator";
			buttons1		= "code,separator,undo,redo,separator,replace,separator";
			buttons1_add	= "bold,italic,underline,separator,justifyleft,justifycenter,justifyright,justifyfull,separator,bullist,numlist,separator,outdent,indent,separator,sub,sup";

			buttons2		= "visualaid,table,separator,link,unlink,anchor,separator,hr,image,emotions,flash,separator,charmap,separator";
			buttons2_add	= "forecolor,backcolor,styleprops,removeformat,separator,formatselect";

			buttons3		= "";
			buttons3_add	= "";

			plugins			= "inlinepopups,table,advimage,advlink,emotions,insertdatetime,flash,searchreplace,contextmenu,paste,style";

			fileBrowserCallback	= "fileBrowserCallBack";
			break;

		default:

			buttonsDisable	= "styleselect, cleanup, help, newdocument";

			//buttons1		= "code,separator,cut,copy,paste,pastetext,pasteword,separator,undo,redo,separator,replace,separator";
			buttons1		= "code,separator,undo,redo,separator,replace,separator";
			buttons1_add	= "bold,italic,underline,separator,justifyleft,justifycenter,justifyright,justifyfull,separator,bullist,numlist,separator,outdent,indent,separator,sub,sup";

			buttons2		= "visualaid,table,separator,link,unlink,anchor,separator,hr,image,emotions,flash,separator,charmap,separator";
			buttons2_add	= "forecolor,backcolor,removeformat,separator,formatselect";

			buttons3		= "";
			buttons3_add	= "";

			plugins			= "inlinepopups,table,advimage,advlink,emotions,insertdatetime,flash,searchreplace,contextmenu,paste,style";

			fileBrowserCallback	= "fileBrowserCallBack";
	}

	fmInit(folder, portalID);

	tinyMCE.init({

		language:	"sk",
		height:		height,
		mode :		"exact",
		elements :	textareaID,

		theme :		"advanced",
		plugins :	plugins,

		theme_advanced_toolbar_location :	"top",
		theme_advanced_toolbar_align :		"left",
		theme_advanced_path_location :		"bottom",

		theme_advanced_disable : buttonsDisable,

		theme_advanced_buttons1 : 		buttons1,
		theme_advanced_buttons1_add :	buttons1_add,

		theme_advanced_buttons2 : 		buttons2,
		theme_advanced_buttons2_add :	buttons2_add,

		theme_advanced_buttons3 :		buttons3,

		theme_advanced_blockformats : "p,h4,h3,h2,h1",

		extended_valid_elements : "object[classid|codebase|width|height],embed[src|width|height],a[name|href|target|title|onclick],img[class|style|src|align|alt|title|onmouseover|onmouseout|name],hr[class|style],span[class|style]",

		convert_urls : false,
		relative_urls : false,
		inline_styles : true,

		file_browser_callback : fileBrowserCallback,

		content_css : contentCss,
		accessibility_warnings : true,

		theme_advanced_resize_horizontal : false,
    	theme_advanced_resizing : true,

    	apply_source_formatting : true
	});
}
