<?php require '../public/system/headers/headers.php';?>
<?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 echo $this->headScript(); ?>
<script type="text/javascript">
$(document).ready(function(){
    var upload_images, upload_files,
    url_website = '<?php echo $this->websiteUrl; ?>';
//uploads images
upload_images = new SWFUpload({
	flash_url : url_website+'system/js/swfupload/swfupload.swf',
	upload_url: url_website+'sys/backend_swfuploader/uploadimages/',
    file_size_limit : "8 MB",
	file_types : "*.gif;*.png;*.jpg;*.avi;*.mov;*.mp4;*.swf;*.flv;*.mpeg;*.wmv;*.mpg;",
	file_types_description : "Web Image or Video Files",
	file_upload_limit : 50,
	file_queue_limit : 0,
    custom_settings : {
    	progressTarget : "UploadProgress1",
		cancelButtonId : "btnCancel1"
	},
	debug: false,
    button_placeholder_id: 'adminuploadpics',
    button_image_url: url_website+'system/js/swfupload/<?php echo $this->browsePictures;//"swf-upload-browse-pictures-french.png";?>',
    button_width: "200",
	button_height: "31",
    button_action: SWFUpload.BUTTON_ACTION.SELECT_FILES,
    button_cursor: SWFUpload.CURSOR.HAND,
    button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
	file_queued_handler : fileQueued,
	file_queue_error_handler : fileQueueError,
	file_dialog_complete_handler : fileDialogComplete,
	upload_start_handler : uploadStartImages,
	upload_progress_handler : uploadProgress,
	upload_error_handler : uploadError,
	upload_success_handler : uploadSuccessImages,
	upload_complete_handler : uploadComplete,
	queue_complete_handler : queueCompleteImages
});      
function uploadStartImages() {
    var ltrim = /^\s+/g;
	var rtrim = /\s+$/g;
    document.getElementById('adminuploadselectfolder').setAttribute('disabled','disabled');
    var new_folder = document.getElementById('adminuploadcreatefolder').value;
    new_folder = new_folder.replace(ltrim, '');
    new_folder = new_folder.replace(rtrim, '');
    if(new_folder != '' && new_folder != 'Create new Folder'){
        upload_images.addPostParam('folder', new_folder);
    } else {
    	var elm = document.getElementById('adminuploadselectfolder');
        var text = elm.options[elm.selectedIndex].value;
        if(text != '') {
            upload_images.addPostParam('folder', text);
        } else {
            document.getElementById('adminuploadselectfolder').removeAttribute('disabled');
            this.cancelQueue();
            $(".errors").html("No files uploaded. Please select folder.");
            $(".errors").show();
        }
    }
}
function uploadSuccessImages(file, serverData){
    var obj = eval('(' + serverData + ')');    
    if(obj.folder != '') {
        elm = document.getElementById('adminuploadselectfolder');
        if(elm.options[elm.selectedIndex].value != obj.folder) {
            elm.options[elm.length] = new Option(obj.folder, obj.folder, false, true);
             if(parent.document.getElementById('adminselectimgfolder') != null) {
                 var elm2 = parent.document.getElementById('adminselectimgfolder');
                 elm2.options[elm2.length] = new Option(obj.folder, obj.folder, false, false);
             }
        }
    } else {
    	this.cancelQueue();
        $(".errors").html("Can't create folder.");
        $(".errors").show();
    }
    document.getElementById('adminuploadselectfolder').removeAttribute('disabled');    
    try {
        var progress = new FileProgress(file, this.customSettings.progressTarget);
        progress.setComplete();
        progress.setStatus("Complete.");
        progress.toggleCancel(false);
    } catch (ex) {
        this.debug(ex);
    }   
    if(document.getElementById('adminuploadcreatefolder').value != 'Create new Folder') {
        document.getElementById('adminuploadcreatefolder').value = '';
    } 
}
function queueCompleteImages(numFilesUploaded) {
    document.getElementById('UploadProgress1').innerHTML = '';
    if(numFilesUploaded > 0 && $('#adminuploadselectfolder').val() != '') {
        $(".success").html(numFilesUploaded+" file"+(numFilesUploaded == 1 ? "" : "s")+" uploaded. In &quot;"+$('#adminuploadselectfolder').val()+"&quot;");
        $(".success").show();
    }
}
//uploads files
upload_files = new SWFUpload({
	flash_url : url_website+'system/js/swfupload/swfupload.swf',
	upload_url: url_website+'sys/backend_swfuploader/uploadfiles/',
	file_size_limit : "8 MB",
	file_types : "*.zip;*.rar;*.gif;*.png;*.jpg;*.avi;*.wmv;*.wma;*.mov;*.pdf;*.mpg;*.mp4;*.swf;*.fla;*.doc;*.xsl;*.txt;*.ppf;*.exe;*.mp3;*.wav;*.ttf;*.ogg;*.gom;*.flv;*.lng;",
	file_types_description : "All Files",
	file_upload_limit : 50,
	file_queue_limit : 0,
    custom_settings : {
    	progressTarget : "UploadProgress2",
		cancelButtonId : "btnCancel2"
	},
	debug: false,
    button_placeholder_id: 'adminuploadfiles',
    button_image_url: url_website+'system/js/swfupload/<?php echo $this->browseFiles;//"swf-upload-browse-files.png";?>',
    button_width: "200",
	button_height: "31",
    button_action: SWFUpload.BUTTON_ACTION.SELECT_FILES,
    button_cursor: SWFUpload.CURSOR.HAND,
    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 : uploadSuccessFiles,
	upload_complete_handler : uploadComplete,
	queue_complete_handler : queueCompleteFiles
});
function uploadSuccessFiles(file, serverData){
    var obj = eval('(' + serverData + ')');
    if(parent.document.getElementById('list_files') != null && obj.file != '') {
        var title;
        var reg = /\..{3}$/g;
        title = obj.file.replace(reg, '');        
        var text = "<p style='text-align:left;font-size:12px;'>";
        text += "<a href='javascript:;' title='"+title+"' onmousedown=\"$('#admincontentarea').tinymce().execCommand('mceInsertContent', false,";
        text += "'<a href=\\'"+url_website+"downloads/"+obj.file+"\\' title=\\'"+title+"\\'>"+obj.file+"</a>');\">"+obj.file+"</a></p>";
        parent.document.getElementById('list_files').innerHTML += text;
    }
    try {
		var progress = new FileProgress(file, this.customSettings.progressTarget);
		progress.setComplete();
		progress.setStatus("Complete.");
		progress.toggleCancel(false);

	} catch (ex) {
		this.debug(ex);
	}
}
function queueCompleteFiles(numFilesUploaded){
    document.getElementById('UploadProgress2').innerHTML = '';
    if(numFilesUploaded > 0){
        $(".success").html(numFilesUploaded+" file"+(numFilesUploaded === 1 ? "" : "s")+" uploaded.");
        $(".success").show();        
    }
}
});
</script>
<div id="seotoaster" class="uploadthings">
<div class="close_window" onclick="parent.tb_remove();"></div>
<div class="admineditwhat">{%Upload things%}</div>
<div class="or">{%OR%}</div>
<div class="errors" style="display: none;" onclick="this.style.display='none';"></div>
<div class="success" style="display: none;" onclick="this.style.display='none';"></div>
<!-- list folders -->
<?php if(!empty($this->listFolders) && is_array($this->listFolders)): ?>
<select name="adminuploadselectfolder" id="adminuploadselectfolder">
        <option value="" selected="selected">select folder</option>
        <?php foreach($this->listFolders as $folderName): ?>           
                <option value="<?php echo $folderName; ?>"><?php echo $folderName; ?></option>            
        <?php endforeach; ?>
    </select>
<?php else: ?>
    <select name="adminuploadselectfolder" id="adminuploadselectfolder">
        <option value="" selected="selected">select folder</option>
    </select>
<?php endif; ?>
<!-- end list folders -->
<form action="javascript:;">
<input type="text" style="color:#999;" value="Create new Folder" onfocus="this.value='';this.style.color='#000';" name="adminuploadcreatefolder" id="adminuploadcreatefolder" />
<input name="adminuploadfiles" type="button" value="{%BROWSE FILES%}"  id="adminuploadfiles"/>
<input name="adminuploadpics" type="button" value="{%BROWSE PICTURES%}" class="adminuploadpics" id="adminuploadpics"/>
<input disabled="disabled" id="btnCancel1" value="Cancel All Uploads" onclick="cancelQueue(upload_images);" style="margin-left: 2px; font-size: 8pt; height: 29px; display:none;" type="button">
<input disabled="disabled" id="btnCancel2" value="Cancel All Uploads" onclick="cancelQueue(upload_files);" style="margin-left: 2px; font-size: 8pt; height: 29px; display:none;" type="button">
</form>
<div id="UploadProgress1"></div>
<div id="UploadProgress2"></div>

	<p id="pandvtext">{%Pictures and videos%} </p>
	<p id="formatingtext">{%(.jpg .gif .png | .mp4 .avi .mov .flv)%}</p>
	<p id="instructionimagestext">
		{%All uploaded pictures will be resized 3
		times for automatic insertion each time
		you edit content on your web site.
		Upload as many images as you want.
		%}
	</p>
	<p id="uploadfilestext">{%I want to upload files%}</p>
	<p id="filestext">{%(video,photos,files)%}</p>
	<p id="instructionvideotext">
		{%All uploaded [files] will be displayed
		as "links" in your websites for people
		to "Download" them.%}
	</p>
	
	<p id="pricetext">
		{%Ex.Please download our price
		list here:Price list.pdf%}
	</p>
<input type="hidden" id="hid-main-wsurl" name="hid-main-wsurl" value="<?php echo $this->websiteUrl; ?>" />
</div>
