<?php
defined('_JEXEC') or die('Direct Access to this location is not allowed.');

JImport( 'joomla.html.editor' );
$editor = JFactory::getEditor();
echo $editor->display("bfEditor",'',500,300,40,20,1);
echo '<br/><br/><input type="submit" value="'.JText::_('SAVE').'" onclick="saveText();parent.SqueezeBox.close();"/>';
echo '<script>
window.onload = function(){
	var item = parent.app.findDataObjectItem(parent.app.selectedTreeElement.id, parent.app.dataObject);
	if(item && item.properties.type == "page"){
		'.$editor->setContent('bfEditor','item.properties.pageIntro').'
	} else if(item && item.properties.type == "section"){
		'.$editor->setContent('bfEditor','item.properties.description').'
	}
	// workaround for quote bug with jce
	var testEditor = '.$editor->getContent('bfEditor').'
	if(testEditor == "item.properties.pageIntro" || testEditor == "item.properties.description"){
		if(item && item.properties.type == "page"){
			setTimeout("setIntro()",500);
		} else if(item && item.properties.type == "section"){
			setTimeout("setDescription()",500);
		}
	}
};
function saveText(){
	var item = parent.app.findDataObjectItem(parent.app.selectedTreeElement.id, parent.app.dataObject);
	if(item && item.properties.type == "page"){
		item.properties.pageIntro = '.$editor->getContent('bfEditor').'
	} else if(item && item.properties.type == "section"){
		item.properties.description = '.$editor->getContent('bfEditor').'
	}
	'.$editor->save('bfEditor').'
}
function setIntro(){
	var item = parent.app.findDataObjectItem(parent.app.selectedTreeElement.id, parent.app.dataObject);
	'.$editor->setContent('bfEditor','\'+item.properties.pageIntro+\'').'
}
function setDescription(){
	var item = parent.app.findDataObjectItem(parent.app.selectedTreeElement.id, parent.app.dataObject);
	'.$editor->setContent('bfEditor','\'+item.properties.description+\'').'
}
</script>';

