function addEvent(obj, evType, fn){ 
 if (obj.addEventListener){ 
   obj.addEventListener(evType, fn, false); 
   return true; 
 } else if (obj.attachEvent){ 
   var r = obj.attachEvent("on"+evType, fn); 
   return r; 
 } else { 
   return false; 
 } 
}
function getId(id) {
  return document.getElementById(id);
}
function replacePHP(text)
{
phpRegEx = /(\[PHP])(.*)(\[\/PHP])/g
return text.replace(phpRegEx, '<strong style="color: #800000;">[Save to View Plugin Content]</strong>');
}
function setEditorButtons()
{
if (getId('new_content'))
{
  var area = 'new_content';
  var preview = 'content_body';
}
else if (getId('postDescriptionInput'))
{
  var area = 'postDescriptionInput';
  var preview = 'preview';
}
else
  return;
  addEvent(
    getId('vEdButton'),
    'click',
    function () {
      if (tinyMCE.get(area).isHidden())
        tinyMCE.get(area).show();
      getId(area).style.display='none';
      getId(preview).innerHTML = '';
    }
  );
  addEvent(
    getId('cEdButton'),
    'click',
    function () {
      getId(area).style.position = 'static';
      if (!tinyMCE.get(area).isHidden())
        tinyMCE.get(area).hide();
      getId(preview).innerHTML = '';
    }
  );
  addEvent(
    getId('prevButton'),
    'click',
    function () {
      if (tinyMCE.get(area).isHidden()) {
        tinyMCE.get(area).show();
      }
      tinyMCE.get(area).hide();
      getId(preview).innerHTML = replacePHP(tinyMCE.get(area).getContent())+'<hr />';
      getId(area).style.position = 'absolute';
      getId(area).style.top = '-500px';
    }
  );
}
addEvent(window, 'load', setEditorButtons);
tinyMCE.init({
	mode : "exact",
	theme : "advanced",
	skin : "o2k7",
	skin_variant : "black",
	elements : "new_content, postDescriptionInput",
  plugins : "save,advimage,advlink,paste,noneditable",
	theme_advanced_buttons1 : "save,undo,redo,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,sub,sup,charmap,bullist,numlist,|,link,unlink,image,formatselect",
	theme_advanced_buttons2 : "",
	theme_advanced_buttons3 : "",
	theme_advanced_toolbar_location : "top",
	theme_advanced_statusbar_location : "bottom",
	theme_advanced_toolbar_align : "left",
    relative_urls : false,
    remove_script_host : false,
	content_css : "themes/efata/content.css",
    document_base_url : "http://efata.org/",
    apply_source_formatting : true,
    theme_advanced_blockformats : "p,address,div,h1,h2,h3,h4,blockquote",
    theme_advanced_styles : "Main Picture=mainPic",
	theme_advanced_resizing : true,
    valid_elements : "*[*]",
	cleanup : false 
});
