var editor = null;
function initEditor() 
{
var editor = new HTMLArea("tresc_form"); //your form id

var cfg = editor.config; // this is the default configuration


//// SETTINGS /////


////// new buttons ////////

//new window size function

if (screen.width > 800)
{
var l = 340;
var t = 200;
var lh = 120;
var th = 60;
}
else
{
var l = 210;
var t = 120;
var lh = 70;
var th = 50;
}


//upload image
cfg.registerButton("uploadimage", "Zapisz obrazek na serwer", "htmlarea/images/up_image.gif", false,
    function(upload) 
    {
    window.open('htmlarea/popups/upload_image.php', 'upload' ,'left='+l+', top='+t+', width=300 , height=200 , menubar=no');
    } );

//help
cfg.registerButton("help", "Pomoc", "htmlarea/images/ed_help.gif", false,
    function(help) 
    {
    window.open('htmlarea/popups/help.html', 'help' ,'left='+lh+', top='+th+', width=600 , height=700 , menubar=no, resizable=1');
    } );

//button bullet
cfg.registerButton("bullet", "Wstaw kropkę", "htmlarea/images/ed_bullet.gif", false,
    function(editor) 
    {
    editor.insertHTML("&bull; "); 
    } );

//akapit
cfg.registerButton("akapit", "Wstaw akapit", "htmlarea/images/ed_akapit.gif", false,
    function(editor) 
    {
    editor.insertHTML("&nbsp;&nbsp;&nbsp;&nbsp; "); 
    } );

//unformat-html
cfg.registerButton("unformat", "Usuń HTML", "htmlarea/images/ed_unformat.gif", false,
    function(editor) 
    {

	editor._popupDialog("unformat.html", function(param) 
	{ 
		if (param) 
		{ 
			if (param["cleaning_area"] == "all")	
			{ 
			var html = editor._doc.body.innerHTML; 
			} 
			else
			{ 
			var html = editor.getSelectedHTML(); 
			} 	
 
				if (param["html_all"]== true)
				{ 
				html = html.replace(/<[\!]*?[^<>]*?>/g, ""); // Remove any tags 
				} 
 
				// formatting ANY CSS, FONT, B, STRONG, I, EM, U and  STRIKE tags 
				if (param["formatting"] == true)
				{ 		
					html = html.replace(/style="[^"]*"/gi, ""); // remove ALL CSS 
					html = html.replace(/<\/?font[^>]*>/gi,""); //remove font tags 
					html = html.replace(/<\/?b>/gi,""); //remove b tags NOT br tags 
					html = html.replace(/<\/?strong[^>]*>/gi,""); //remove strong tags 
					html = html.replace(/<\/?i>/gi,""); //remove i tags 
					html = html.replace(/<\/?em[^>]*>/gi,""); //remove em tags 
					html = html.replace(/<\/?u[^>]*>/gi,""); //remove u tags 
					html = html.replace(/<\/?strike[^>]*>/gi,""); //remove strike tags 
					html = html.replace(/ align=[^\s|>]*/gi,"");	//remove alignment 
					html = html.replace(/ class=[^\s|>]*/gi,"");	//remove classes 
				} 

					if (param["cleaning_area"] == "all")
					{ 
				 	editor._doc.body.innerHTML = html; 
					}
					else
					{ 
					editor.insertHTML(html); 
					} 
			}
			else
			{
			return false; 	// User clicked cancel 
			}
		}, null); 
	
    } );

// set your toolbar
cfg.toolbar = [
 		[ "fontname", "space",
		  "fontsize", "space", "space",
		  "bold", "italic", "underline", "separator",
		  "subscript", "superscript", "separator",
		  "copy", "cut", "paste", "separator", "insertimage", "uploadimage"],

		[  "justifyleft", "justifycenter", "justifyright", "justifyfull", "separator",
		  "insertorderedlist", "insertunorderedlist", "outdent", "indent", "separator",
		  "forecolor", "hilitecolor", "separator",
		  "akapit","bullet","inserthorizontalrule", "createlink","inserttable","separator", "unformat", "htmlmode", "separator",
		   "help", "about" ]
];


// Editor style
cfg.pageStyle = "body {font-family: Verdana; font-size:13px; }";


// generate editor
  editor.generate();
}
