{extends file=$smarty.const.SMARTY_LAYOUT_MAIN_POPUP}

{block name="template-head" append}
	{$JS->loadGroup("fieldset")}
	{$CSS->loadGroup("fieldset")}
	{$JS->loadGroup("optionsBox.icons")}
	{$CSS->loadGroup("optionsBox.icons")}
{/block}

{block name="css" append}
	<style type='text/css'>
		fieldset.default {
			margin-bottom: 2em;
		}
	</style>
{/block}

{block name="operations" append}
	<select class="filesList" style="min-width:200px; max-width:600px;">
		<option value="">{$lang['viewDocument']['formFields']['defaultFile']}</option>
		{if $filesList}
			{foreach from=$filesList key=indexArray item=files}
				<option value="{$files['file']}"
					{if !$files['fileExists']} class="dummy-file-not-exists" {/if}>

					{if $files['name']}
						{$files['name']} - {$files['time']}
					{else}
						{$files['file']} - {$files['time']}
					{/if}
				</option>
			{/foreach}
		{else}
			<option value="" class="dummy-file-not-exists" >-</option>
		{/if}
	</select>

	<button type="button" id="buttonDownload"
		onclick="
			if ($(this).up('div.engine-header').down('select').value == '') {
				alert('{$lang['viewDocument']['formFields']['invalidFile']}');
			}
			else {
				if ($('buttonDownload').up('div.engine-header').down('select.filesList')[$('buttonDownload').up('div.engine-header').down('select.filesList').selectedIndex].hasClassName('dummy-file-not-exists')){
					alert('{$lang['downloadFile']['errorFile']}');
				}
				else {
					window.location = MVC.appUrl(MVC.CURRENT_MODULE, 'downloadFile', { 'file': $(this).up('div.engine-header').down('select').value, 'idDocument' : {$idDocument}});
				}
			}
		"
	>{$lang['viewDocument']['formFields']['downloadButton']}</button>




	<button type="button" id="viewAllDocumentDetails"
		onclick="window.location= MVC.appUrl(MVC.CURRENT_MODULE, 'documentDetails', { 'idDocument' : {$idDocument}});"
	>{$lang['viewDocument']['formFields']['documentDetails']}</button>

{/block}

{block name="content" prepend}
	{$mvcView->renderImportedDocument($importedDocumentObj)}
{/block}
