<?php

defined('_JEXEC') or die;

class DtregisterViewMedia extends JViewLegacy
{
	public function display($tpl = null)
	{
		// Do not allow cache
		
		JResponse::allowCache(false);

		JResponse::allowCache(false);

		$app = JFactory::getApplication();

		$lang	= JFactory::getLanguage();
		if(!isset($_GET['task']) || $_GET['task'] != "files"){
         JHtml::_('behavior.framework', true);
		 JHtml::_('script', 'media/popup-imagemanager.js', true, true);
		JHtml::_('stylesheet', 'media/popup-imagemanager.css', array(), true);
		ob_start();
		?>
        <script>
       // window.addEvent('domready', function() {
       
        
       ImageManager.setFolder =  function (folder,asset,author)
	{
		//this.showMessage('Loading');

		for(var i = 0; i < this.folderlist.length; i++)
		{
			if(folder == this.folderlist.options[i].value) {
				this.folderlist.selectedIndex = i;
				break;
			}
		}
		this.frame.location.href='index.php?option=com_dtregister&controller=media&task=files&tmpl=component&folder=' + folder + '&asset=' + asset + '&author=' + author;
      

	}
   // });
    </script>
        <?php
		echo $js = ob_get_clean();
		$document = JFactory::getDocument();
		//$document->addScriptDeclaration($js);
		if ($lang->isRTL()) :
			JHtml::_('stylesheet', 'media/popup-imagelist_rtl.css', array(), true);
		endif;

        $config = JComponentHelper::getParams('com_media');
		$app	= JFactory::getApplication();
		$lang	= JFactory::getLanguage();
$ftp = !JClientHelper::hasCredentials('ftp');

		$this->session = JFactory::getSession();
		$this->config = $config;
		}
		 if(isset($_GET['task']) && $_GET['task'] == "files") {
		$document = JFactory::getDocument();
		$document->addScriptDeclaration("var ImageManager = window.parent.ImageManager;");
		JHtml::_('stylesheet', 'media/popup-imagelist.css', array(), true);
		} 
		$images = $this->get('images');
		
		$folders = $this->get('folders');
		$docs = $this->get('docs');
		$state = $this->get('state');
        $this->folderList = $this->get('folderList');
		$this->baseURL = COM_MEDIA_BASEURL;
		$this->images = &$images;
		$this->folders = &$folders;
		$this->docs = &$docs;
		$this->state = &$state;

		parent::display($tpl);
	}

	function setFolder($index = 0)
	{
		if (isset($this->folders[$index]))
		{
			$this->_tmp_folder = &$this->folders[$index];
		}
		else
		{
			$this->_tmp_folder = new JObject;
		}
	}

	function setImage($index = 0)
	{
		if (isset($this->images[$index]))
		{
			$this->_tmp_img = &$this->images[$index];
		}
		else
		{
			$this->_tmp_img = new JObject;
		}
	}
}
