

function new_tiny_instance(element_id, css_class, lg_enc)
{
	$("#menu_" + element_id).hide();

	$("#"+element_id).tinymce(
		{
			entity_encoding 		: "raw",
			//file_browser_callback 	: "CustomFileBrowser",
			language 				: lg_enc,
			plugins 				: "safari,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,iespell,inlinepopups,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
			//plugins 				: "ezfilemanager,safari,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,iespell,inlinepopups,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
			script_url 				: "/jscript/frameworks/tiny_mce/tiny_mce.js",
			theme 					: "advanced",
			width 					: "100%",

			theme_advanced_toolbar_location : 	"external",
			theme_advanced_statusbar_location : "bottom",
			theme_advanced_resizing : true,
			theme_advanced_resize_horizontal : false,

			theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect,|,cancel",
			theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,|,cleanup,code,|,preview,|,forecolor,backcolor",
			//theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,ezfilemanager,|,cleanup,code,|,preview,|,forecolor,backcolor",
			theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
			theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,spellchecker,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,blockquote,pagebreak,|,insertfile,insertimage",

			save_enablewhendirty : false,
			save_onsavecallback : "sti_"+element_id,
			save_oncancelcallback : "cti_"+element_id
		});

	return false;
}

function save_tiny_instance(element_id)
{

	//Put element content inside form element
	$("#tiny_form_" + element_id + " textarea[name=content]").val( $("#"+element_id).tinymce().getContent() );
	//Kill tinyMCE
	$("#"+element_id).tinymce().remove();
	//Show standard ZO Menu
	$("#menu_" + element_id).show();
	//Submit Ajax call
	$.post("/modules/pjx/texts.pl", $("#tiny_form_" + element_id).serialize());

	return false;
}

function cancel_tiny_instance(element_id)
{
	//Kill tinyMCE
	$("#"+element_id).tinymce().remove();
	//Show standard ZO Menu
	$("#menu_" + element_id).show();

	return false;
}

function new_tiny_embedded(element_name, lg_enc, css_class)
{
	$('textarea[name='+element_name+']').tinymce(
	{
		entity_encoding 	: "raw",
		language 			: lg_enc,
		plugins 			: "safari,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,iespell,inlinepopups,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",
		script_url 			: '/jscript/frameworks/tiny_mce/tiny_mce.js',
		theme 				: "advanced",
		width 				: 	"100%",

		theme_advanced_toolbar_location 	: "top",
		theme_advanced_statusbar_location 	: "bottom",
		theme_advanced_resizing 			: false,

		theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect",
		theme_advanced_buttons3 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo",
		theme_advanced_buttons2 : "fontselect,fontsizeselect,|,link,unlink,anchor,image,cleanup,code,|,preview,|,forecolor,backcolor",
		theme_advanced_buttons4 : "tablecontrols,|,hr,removeformat,visualaid",
		theme_advanced_buttons5 : "sub,sup,|,charmap,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
		theme_advanced_buttons6 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,spellchecker,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,blockquote,pagebreak,|,insertfile,insertimage"
	});
	return false;
}

function inspect(obj, maxLevels, level)
{
  var str = '', type, msg;

    // Start Input Validations
    // Don't touch, we start iterating at level zero
    if(level == null)  level = 0;

    // At least you want to show the first level
    if(maxLevels == null) maxLevels = 1;
    if(maxLevels < 1)
        return '<font color="red">Error: Levels number must be > 0</font>';

    // We start with a non null object
    if(obj == null)
    return '<font color="red">Error: Object <b>NULL</b></font>';
    // End Input Validations

    // Each Iteration must be indented
    str += '<ul>';

    // Start iterations for all objects in obj
    for(property in obj)
    {
      try
      {
          // Show "property" and "type property"
          type =  typeof(obj[property]);
          str += '<li>(' + type + ') ' + property +
                 ( (obj[property]==null)?(': <b>null</b>'):('')) + '</li>';

          // We keep iterating if this property is an Object, non null
          // and we are inside the required number of levels
          if((type == 'object') && (obj[property] != null) && (level+1 < maxLevels))
          str += inspect(obj[property], maxLevels, level+1);
      }
      catch(err)
      {
        // Is there some properties in obj we can't access? Print it red.
        if(typeof(err) == 'string') msg = err;
        else if(err.message)        msg = err.message;
        else if(err.description)    msg = err.description;
        else                        msg = 'Unknown';

        str += '<li><font color="red">(Error) ' + property + ': ' + msg +'</font></li>';
      }
    }

      // Close indent
      str += '</ul>';

    return str;
}

