/* Demo Note:  This demo uses a FileProgress class that handles the UI for displaying the file name and percent complete.
The FileProgress class is not part of SWFUpload.
*/


/* **********************
   Event Handlers
   These are my custom event handlers to make my
   web application behave the way I went when SWFUpload
   completes different tasks.  These aren't part of the SWFUpload
   package.  They are part of my application.  Without these none
   of the actions SWFUpload makes will show up in my application.
   ********************** */
   
function fileDialogComplete(fileSelected) {
	if (fileSelected) {
		$('uploadfrm').down().style.width = $('uploadfrm').down().style.height = "1px"; //hide upload button
		$('tdUploadProgress').show(); //show upload progress
		this.startUpload();
	}
}

function uploadStart(file) {
	try {
		updateDisplay.call(this, file);
	}
	catch (ex) {
		this.debug(ex);
	}
	
}

function uploadProgress(file, bytesLoaded, bytesTotal) {
	try {
		this.customSettings.progressCount++;
		updateDisplay.call(this, file);
	} catch (ex) {
		this.debug(ex);
	}
	
}

function uploadSuccess(file, serverData) {
	try {
		oktoleavepage = true;
		updateDisplay.call(this, file);
		$("form_3").hide();
		$("form_4").show();
	
	} catch (ex) {
		this.debug(ex);
	}
}

function uploadError(file, error_code, message) {
	alert ("Failed to upload: " + message);
}

function updateDisplay(file) {
	var displayElem = this.customSettings.swfUploadProgress;
	
	var divProgess = $('progressbar');
	$('progress_info').update("Estimated Time Remaining: " + SWFUpload.speed.formatTime(file.timeRemaining) + " (" + SWFUpload.speed.formatBPS(file.averageSpeed) + ")" );
	divProgess.setStyle({ 'width': parseInt(file.percentUploaded) + "%" });
	
}
