var swfu;var fileQueue;function swfUploadLoaded(){}function fileSelect(){}function fileQueued(file){try{fileQueue.push({'id':file.id,'name':file.name,'time':0,'size':file.size,'loaded':0,'status':file.filestatus});createProgressBar(file);$('#start-button').show();$('#cancel-button').show();$('#close-button').hide();$('#control-buttons').show()}catch(ex){this.debug(ex)}}function fileDialogComplete(numFilesSelected,numFilesQueued){}function fileQueueError(file,errorCode,message){try{switch(errorCode){case SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED:return;case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:alert("The file you selected is too big.");this.debug("Error Code: File too big, File name: "+file.name+", File size: "+file.size+", Message: "+message);return;case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:alert("The file you selected is empty. Please select another file.");this.debug("Error Code: Zero byte file, File name: "+file.name+", File size: "+file.size+", Message: "+message);return;case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:alert("The file you choose is not an allowed file type.");this.debug("Error Code: Invalid File Type, File name: "+file.name+", File size: "+file.size+", Message: "+message);return;default:alert("An error occurred in the upload. Try again later.");this.debug("Error Code: "+errorCode+", File name: "+file.name+", File size: "+file.size+", Message: "+message);return}}catch(ex){this.debug(ex)}}function uploadStart(file){try{index=queueIndexByFileId(file.id);fileQueue[index].time=new Date().getTime()/1000;return true}catch(ex){this.debug(ex);return false}}function uploadProgress(file,bytesLoaded,bytesTotal){var index=queueIndexByFileId(file.id);if(index>=0){fileQueue[index].status=file.status;var received_kb=new Number(bytesLoaded/1024).toFixed(2);var size_kb=new Number(bytesTotal/1024).toFixed(2);var lasttime=new Date().getTime()/1000;var frequency=lasttime-fileQueue[index].time;if(frequency>=1){var speed_kb=new Number((bytesLoaded-fileQueue[index].loaded)/1024/frequency).toFixed(2);fileQueue[index].loaded=bytesLoaded;fileQueue[index].time=lasttime;if(speed_kb>0){var time=Math.round((size_kb-received_kb)/speed_kb);var time_h=Math.floor(time/3600);var time_m=Math.floor((time-time_h*3600)/60);var time_s=time-time_h*3600-time_m*60;time_h=(time_h<10)?'0'+time_h:time_h;time_m=(time_m<10)?'0'+time_m:time_m;time_s=(time_s<10)?'0'+time_s:time_s}else{time_h='00';time_m='00';time_s='00'}var percent=Math.round(bytesLoaded/bytesTotal*100);$('#'+file.id+'_status').html(received_kb+'KB of '+size_kb+'KB, Time Left: '+time_h+':'+time_m+':'+time_s+' (at '+speed_kb+' KB/s)');$('#'+file.id+'_percent').css('width',percent+'%')}}}function uploadError(file,errorCode,message){try{switch(errorCode){case SWFUpload.UPLOAD_ERROR.MISSING_UPLOAD_URL:alert("There was a configuration error.  You will not be able to upload a resume at this time.");this.debug("Error Code: No backend file, File name: "+file.name+", Message: "+message);return;case SWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED:alert("You may only upload 1 file.");this.debug("Error Code: Upload Limit Exceeded, File name: "+file.name+", File size: "+file.size+", Message: "+message);return;case SWFUpload.UPLOAD_ERROR.FILE_CANCELLED:case SWFUpload.UPLOAD_ERROR.UPLOAD_STOPPED:break;case SWFUpload.UPLOAD_ERROR.HTTP_ERROR:alert("Upload temporary unavailable.");this.debug("Error Code: HTTP Error, File name: "+file.name+", Message: "+message);break;case SWFUpload.UPLOAD_ERROR.UPLOAD_FAILED:alert("Upload temporary unavailable.");this.debug("Error Code: Upload Failed, File name: "+file.name+", File size: "+file.size+", Message: "+message);break;case SWFUpload.UPLOAD_ERROR.IO_ERROR:alert("Connection lost. Please, check your internet connection and try again.");this.debug("Error Code: IO Error, File name: "+file.name+", Message: "+message);break;case SWFUpload.UPLOAD_ERROR.SECURITY_ERROR:this.debug("Error Code: Security Error, File name: "+file.name+", Message: "+message);break;case SWFUpload.UPLOAD_ERROR.FILE_CANCELLED:this.debug("Error Code: Upload Cancelled, File name: "+file.name+", Message: "+message);break;case SWFUpload.UPLOAD_ERROR.UPLOAD_STOPPED:this.debug("Error Code: Upload Stopped, File name: "+file.name+", Message: "+message);break;default:alert("Upload temporary unavailable.");this.debug("Error Code: "+errorCode+", File name: "+file.name+", File size: "+file.size+", Message: "+message);return}}catch(ex){this.debug(ex)}}function uploadSuccess(file,serverData){var index=queueIndexByFileId(file.id);fileQueue[index].status=SWFUpload.FILE_STATUS.COMPLETE;$('#'+file.id+'_cancel').html('<input type="button" value="'+close_caption+'" onclick="removeProgressBar(\''+file.id+'\')" />');$('#'+file.id+'_status').html(completed_caption);$('#'+file.id+'_percent').css('width','100%');$('#'+file.id+'_progress').append(serverData)}function uploadComplete(file){try{for(i=0;i<fileQueue.length;i++){if(fileQueue[i].status!=SWFUpload.FILE_STATUS.COMPLETE&&fileQueue[i].status!=SWFUpload.FILE_STATUS.CANCELLED){swfu.startUpload();return}}swfu.setButtonText(browse_caption);swfu.setButtonDisabled(false);$('#cancel-button').hide();$('#close-button').show()}catch(ex){swfu.debug(ex)}}function queueComplete(){}function queueIndexByFileId(file_id){for(i=0;i<fileQueue.length;i++){if(fileQueue[i].id==file_id){return i}}return-1}function createProgressBar(file){var inner_html='<div id="'+file.id+'_progress" class="progress-bar active-upload"><div class="progress"><h4>'+file.name+'</h4>'+'<span id="'+file.id+'_cancel" class="btn20 cancel"><input type="button" value="'+cancel_caption+'" onclick="stopFile(\''+file.id+'\')" /></span>'+'<div class="scale"><div class="inner">'+'<div id="'+file.id+'_percent" class="fill" style="width:0%;"></div>'+'</div></div>'+'<p id="'+file.id+'_status" class="status">'+queued_caption+'</p></div></div>';$('#upload-progress').append(inner_html)}function removeProgressBar(file_id){if($('#'+file_id+'_progress')){var index=queueIndexByFileId(file_id);fileQueue.splice(index,1);$('#'+file_id+'_progress').remove()}}function stopFile(file_id){swfu.cancelUpload(file_id);var index=queueIndexByFileId(file_id);if(fileQueue[index].status!=SWFUpload.FILE_STATUS.COMPLETE){fileQueue[index].status=SWFUpload.FILE_STATUS.CANCELLED;$('#'+file_id+'_status').html(canceled_caption);$('#'+file_id+'_progress').removeClass('active-upload')}$('#'+file_id+'_cancel').html('<input type="button" value="'+close_caption+'" onclick="removeProgressBar(\''+file_id+'\')" />');if($('div.active-upload').length==0){$('#start-button').hide();$('#cancel-button').hide();$('#close-button').show()}}function clearQueue(){try{for(i=0;i<fileQueue.length;i++){stopFile(fileQueue[i].id)}swfu.setButtonText(browse_caption);swfu.setButtonDisabled(false);$('#start-button').hide();$('#cancel-button').hide();$('#close-button').show()}catch(ex){swfu.debug(ex)}}function closeAll(){try{while(fileQueue.length>0){removeProgressBar(fileQueue[0].id)}$('#close-button').hide();$('#control-buttons').hide()}catch(ex){swfu.debug(ex)}}function startUpload(){try{var folder_select=$('#upload-form select[name=folder]').first();if(folder_select.val()){swfu.removePostParam('folder');swfu.addPostParam('folder',folder_select.val())}swfu.setButtonText(wait_caption);swfu.setButtonDisabled(true);swfu.startUpload();$('#start-button').hide()}catch(ex){swfu.debug(ex)}return false}function changeFolder(id){var file=id;var select=$('#sel-'+id);var folder=select.val();if(folder==''){return}if(folder==0){$('#wait-'+file).hide();$('#done-'+file).hide();$('#form-'+file).show()}else{$('#done-'+file).hide();$('#form-'+file).hide();$('#wait-'+file).show();$.ajax({type:'POST',url:'/upload/change_folder/'+folder+'/'+file,cache:false,success:function(data){$('#wait-'+file).hide();$('#form-'+file).hide();$('#done-'+file).show();if(data==0){$('#done-'+id).html(error_caption)}else{$('#done-'+id).html(done_catpion)}},error:function(){}})}}function createFolder(id){var folder_name=$('#folder-'+id).val();if(folder_name!=''){$('#form-'+id).hide();$('#done-'+id).hide();$('#wait-'+id).show();$.ajax({type:'POST',url:'/upload/change_folder/0/'+id+'/'+folder_name,cache:false,success:function(data){$('#wait-'+id).hide();$('#form-'+id).hide();$('#done-'+id).show();if(data==0){$('#done-'+id).html(error_caption)}else{$('#done-'+id).html(done_catpion);$('#sel-'+id+' option:selected').each(function(id,option){option.text='        |--- '+folder_name;option.value=data})}},error:function(){}})}}

