<?php
include_once("config.inc.php");
$file=substr($_GET['file'], strlen(_folder));
$target = $_GET['target'];
?>

<h3 class="sectionHeader"><?php echo _folder.$file; ?></h3>
<div id="theFunctions">
	<div id="optionsWrapper2">
		<p>
			<a href="javascript:deletefile();">Delete This File</a>
			<?php
				if($target != ""){
			?>
				&nbsp;&nbsp;-&nbsp;&nbsp;
				<a href="javascript:dialog_close('<?php echo _folder.$file; ?>');">Insert this image</a>
			<?php
				}
			?>
		</p>
	</div>
	<?php
		$extension=substr($_GET['file'], -4, 4);
		if ($extension==".jpg" || $extension==".gif" || $extension==".png") {
			echo '
			<div id="imgWrapper2">
				<img src="/'.$_GET['file'].'">
			</div>
			';
		} else {
			echo '<a href="/'.$_GET['file'].'" target="_blank">See this file</a>';
		}
	?>	
</div>

<script language="javascript">
function deletefile(codigo) {
	var fRet;
	fRet = confirm('Do you want delete this file?');
	if (fRet==false) {
		return;
	} else { 
		window.location='index.php?file=<?php echo $_GET['file']; ?>&action=delete';
		//window.location='index.php?target=<?php echo $_GET['target']; ?>&action=delete&file=<?php echo $_GET['file']; ?>';
	}
};
function dialog_close(cual) {
	var theHTML = "<img src='/" + cual + "'>";
	var target = '<?php echo $target ?>';
	var o = parent.document.getElementById(target);
	var oldHTML = o.innerHTML;
	o.innerHTML = oldHTML + theHTML;
	parent.$.colorbox.close();
	//self.close();
	
}
</script>