
function fileQueueError(file, errorCode, message) {
	try {
		var imageName = "error.gif";
		var errorName = "";
		if (errorCode === SWFUpload.errorCode_QUEUE_LIMIT_EXCEEDED) {
			errorName = "You have attempted to queue too many files.";
		}
		if (errorName !== "") {
			alert(errorName);
			return;
		}
		switch (errorCode) {
		case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
			imageName = "zerobyte.gif";
			break;
		case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
			imageName = "toobig.gif";
			break;
		case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
		case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:
		default:
			alert(message);
			break;
		}
	} catch (ex) {
		this.debug(ex);
	}
}

function fileDialogComplete(numFilesSelected, numFilesQueued) {
	try {
		if (numFilesQueued > 0) {
			this.startUpload();
			var ele = $(this.customSettings.progress_div);
			ele.update('<img id="upl_progress_bar" src="/img/_admin/progress_bar.gif" border="0" width="200" height="16" alt="Loading" />');
		}
	} catch (ex) {
		this.debug(ex);
	}
}
	
function uploadProgress(file, bytesLoaded) 
{
	try {
		var percent  = Math.ceil((bytesLoaded / file.size) * 100);
		if (percent < 100) {
			$(this.customSettings.status_div).update("Uploading... "+percent+'%');
			$(this.customSettings.filename_div).update("");
		}
	} catch (ex) {
		this.debug(ex);
	}
}

function uploadSuccess(file, serverData) 
{
	try {
		var response = serverData.evalJSON(); // response should be JSON
		var upl_type = response.upl_type;
		if(upl_type == 'preview') {
			$('previewFilenameDiv').update(response.name);
			$('previewThumbDiv').update('');
			$('previewThumbDiv').className = 'upload_complete';
		} else {
			$('fileFilenameDiv').update(response.name);
			$('fileThumbDiv').update('');
			$('fileThumbDiv').className = 'upload_complete';
		}
		// set upload id to form
		var bindToFld = response.bindToFld;
		$(response.bindToFld).value = response.upl_id;
		// for testing
		// alert(  bindToFld +": "+  $(bindToFld).value  );
	} catch (ex) {
		this.debug(ex);
	}
}

function uploadSuccessJourney(file, serverData) 
{
	try {
		var response = serverData.evalJSON(); // response should be JSON
		$('previewFilenameDiv').update('');//response.name);
		$('previewThumbDiv').update('');
		$('previewThumbDiv').className = 'upload_complete';
		$('previewThumbDiv').update('<img src="/img/_journeys/preview.php?file='+response.preview+'" border="0" width="200" height="200" alt="Preview" />');
	} catch (ex) {
		this.debug(ex);
	}
}

function uploadComplete(file) {
	try {
		/*  I want the next upload to continue automatically so I'll call startUpload here */
		if (this.getStats().files_queued > 0) {
			this.startUpload();
		} else {
			$(this.customSettings.status_div).update("Upload received.");
			$(this.customSettings.progress_div).update('');
		}
	} catch (ex) {
		this.debug(ex);
	}
}
	
function uploadError(file, errorCode, message) {
	var imageName =  "error.gif";
	var progress;
	try {
		switch (errorCode) {
		case SWFUpload.UPLOAD_ERROR.FILE_CANCELLED:
			try {
				$(this.customSettings.status_div).update("Cancelled.");
			}
			catch (ex1) {
				this.debug(ex1);
			}
			break;
		case SWFUpload.UPLOAD_ERROR.UPLOAD_STOPPED:
			try {
				$(this.customSettings.status_div).update("Stopped.");
			}
			catch (ex2) {
				this.debug(ex2);
			}
		case SWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED:
			imageName = "uploadlimit.gif";
			break;
		default:
			alert(message);
			break;
		}
	} catch (ex3) {
		this.debug(ex3);
	}

}