<?php $this->headLink()->appendStylesheet($this->websiteUrl . 'system/css/seotoaster.css'); ?>
<?php $this->headLink()->appendStylesheet($this->websiteUrl .'system/js/thickbox/thickbox.css'); ?>
<?php $this->headLink()->appendStylesheet($this->websiteUrl . 'system/css/swfupload.css'); ?>
<?php echo $this->headLink(); ?>
<?php $this->headScript()->appendFile($this->websiteUrl . 'system/js/jquery/jquery.js'); ?>
<?php $this->headScript()->appendFile($this->websiteUrl . 'system/js/thickbox/thickbox.js'); ?>
<?php $this->headScript()->appendFile($this->websiteUrl . 'system/js/swfupload/swfupload.js'); ?>
<?php $this->headScript()->appendFile($this->websiteUrl . 'system/js/swfupload/swfupload.queue.js'); ?>
<?php $this->headScript()->appendFile($this->websiteUrl . 'system/js/swfupload/fileprogress.js'); ?>
<?php $this->headScript()->appendFile($this->websiteUrl . 'system/js/swfupload/handlers.js'); ?>
<?php $this->headScript()->appendFile($this->websiteUrl . 'system/js/theme/theme.js'); ?>
<?php echo $this->headScript(); ?>
<script type="text/javascript">
$(document).ready(function(){    
var url_website = '<?php echo $this->websiteUrl; ?>';
var settings = {
	flash_url : ""+url_website+"system/js/swfupload/swfupload.swf",
	upload_url: ""+url_website+"sys/backend_theme/uploadtheme/",
	file_size_limit : "30 MB",
	file_types : "*.zip;",
	file_types_description : "Zip File",
	file_upload_limit : 10,
	file_queue_limit : 0,
    custom_settings : {
    	progressTarget : "process",
		cancelButtonId : "btnCancel"
		},
	debug: false,
    button_placeholder_id: 'submit',
    button_image_url: ""+url_website+"system/js/swfupload/<?php echo $this->browseThemes;//"swf-upload-browse-files.png";?>",
    button_width: "200",
	button_height: "31",
    button_cursor: SWFUpload.CURSOR.HAND,
    button_action: SWFUpload.BUTTON_ACTION.SELECT_FILE,
    button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,		
	file_queued_handler : fileQueued,
	file_queue_error_handler : fileQueueError,
	file_dialog_complete_handler : fileDialogComplete,
	upload_start_handler : uploadStart,
	upload_progress_handler : uploadProgress,
	upload_error_handler : uploadError,
	upload_success_handler : uploadSuccess,
	upload_complete_handler : uploadComplete,
	queue_complete_handler : queueComplete
};

var swfu = new SWFUpload(settings);

function uploadStart(){
	swfu.addPostParam('overwrite', document.getElementById('overwrite').checked);
}
function uploadSuccess(file, serverData){
	var obj = eval('(' + serverData + ')');
            
    if(obj.error){                
    	$("#process").html('');
        $("#msg").html(obj.message);
        $("#msg").show();
    } else {
    	if(!obj.exist_theme){
        	var str = '<div class="one_theme" align="center" id="'+obj.theme+'-div">';
            str += '<img src="'+obj.preview+'" border="1" width="160" height="170" />';
            str += '<p align="left"><input type="radio" name="select_theme" value="'+obj.theme+'"><span>'+obj.theme+'</span>';
            str += '<img style="cursor:pointer;" src="<?php echo $this->websiteUrl; ?>system/images/ico_delete.gif" onclick="if(confirm(\'Do you really want to delete this theme?\')) { deleteTheme(\'<?php echo $this->websiteUrl; ?>\', \''+obj.theme+'\')}else {return false;};" />';
            str += '<p align="right"><a href="javascript:;" onclick="downloadTheme(\'<?php echo $this->websiteUrl;?>\',\''+obj.theme+'\');" title="download this theme">Download</a></p>';
            str += '</p><p style="clear:both;"></p></div>';
            $(".list_themes").html($(".list_themes").html()+str);
        }                
        try {
	        	var progress = new FileProgress(file, this.customSettings.progressTarget);
	            progress.setComplete();
	            progress.setStatus("Complete.");
	            progress.toggleCancel(false);
        	} catch (ex) {
        		this.debug(ex);
        	}
	}
}
});
</script>
<div id="seotoaster" class="theme">
	<div class="admineditwhat">{%Themes%} &nbsp;&nbsp;&nbsp;<i>({%current theme%}: <?php echo $this->currentThemeName; ?>)</i></div>
<div class="close_window" onclick="parent.tb_remove();parent.location.reload();"></div>
<div id="uploadtheme">
<?php if($this->zipExtensionEnabled): ?>    
	<form action="javascript:;">
	<input type="button" name="submit" id="submit" value="submit" />    
	<p style="margin-top:5px;"><input type="checkbox" name="overwrite" id="overwrite" /><label> {%replace theme?%}</label></p>
	<input type="button" disabled="disabled" id="btnCancel" value="Cancel All Uploads" onclick="cancelQueue(swfu);" style="margin-left: 2px; font-size: 8pt; height: 29px; display:none;">
	</form>
	<div id="process"></div>
	<div id="msg" class="errors" style="display: none;" onclick="this.style.display='none';"></div>
<?php else: ?>
	<div class="errors" style="top:35;left:50px;width:450px;padding:20px;" onclick="this.style.display='none';">
    Your server does not have ZIP extension installed. Please install ZIP extension or upload your new theme by FTP.</div>
<?php endif; ?>
 </div>
 <?php if(isset($this->success) && $this->success === false): ?><div class="errors" onclick="this.style.display='none';">This theme does not have required files or does not exist!</div><?php endif; ?>
<?php if(isset($this->success) && $this->success === true): ?><div class="success" onclick="this.style.display='none';">The theme applied!</div><?php endif; ?>
<h2 align="center">{%List themes%}</h2>
<form action="<?php echo $this->websiteUrl; ?>sys/backend_theme/selecttheme/" method="post" id="themes" name="themes">
<div class="list_themes">
<?php if(!empty($this->listThemes) && is_array($this->listThemes)): ?>
    <?php foreach($this->listThemes as $theme): ?>
    	<?php if(!empty($theme) && $theme != ''): ?>
       	<div class="one_theme" align="center" id="<?php echo $theme;?>-div" <?php if($this->currentThemeName == $theme): ?>style="background:#FFFFCC;"<?php endif;?>>
<?php if(file_exists($this->pathThemes . $theme . '/preview.jpg')): $src = $this->websiteUrl . 'themes/' . $theme . '/preview.jpg';	elseif(file_exists($this->pathThemes . $theme . '/preview.gif')): $src = $this->websiteUrl . 'themes/' . $theme . '/preview.gif'; elseif(file_exists($this->pathThemes . $theme . '/preview.png')):	$src = $this->websiteUrl . 'themes/' . $theme . '/preview.png';	else: $src = $this->websiteUrl . 'system/images/noimage.png'; endif; ?>
		<img src="<?php echo $src; ?>" border="1" width="160" height="170" />
		<p align="left">
			<?php if($this->currentThemeName == $theme): ?>
			<input type="radio" checked="checked" name="select_theme" value="<?php echo $theme; ?>"><span><?php echo $theme; ?></span>
				<?php if($this->zipExtensionEnabled): ?><p align="right"><a href="javascript:;" onclick="downloadTheme('<?php echo $this->websiteUrl;?>','<?php echo $theme;?>');" title="download this theme">{%Download%}</a></p><?php endif; ?>
           <?php else: ?>
           		<input type="radio" name="select_theme" value="<?php echo $theme; ?>"><span><?php echo $theme; ?></span>
                <img style="cursor:pointer;" src="<?php echo $this->websiteUrl; ?>system/images/ico_delete.gif" onclick="if(confirm('Do you really want to delete this theme?')) { deleteTheme('<?php echo $this->websiteUrl; ?>', '<?php echo $theme; ?>')}else {return false;};" />
                <?php if($this->zipExtensionEnabled): ?><p align="right"><a href="javascript:;" onclick="downloadTheme('<?php echo $this->websiteUrl;?>','<?php echo $theme;?>');" title="download this theme">{%Download%}</a></p><?php endif; ?>
           <?php endif; ?>
        </p>
	    <p style="clear:both;"></p>
		</div>
		<?php endif; ?>
	<?php endforeach; ?>
<?php endif; ?>
<p style="clear:both;"></p>
</div>	
	<input type="submit" class="formsubmit" name="submit" id="theme_submit" value="{%Apply Theme%}">
	<input type="hidden" id="hid-main-wsurl" name="hid-main-wsurl" value="<?php echo $this->websiteUrl; ?>" />
</form>
</div>