function markError(msg){
	try { 
		Ext.getCmp('upProgress').updateProgress(0); 
		Ext.getCmp('upProgress').hide(); 
		Ext.getCmp('originalImageName').reset(); 
		Ext.getCmp('originalImageName').markInvalid(msg); 
		//Ext.getCmp('btn_addFile').disable();
	} catch(e){ alert(e); } 
}

function fileQueued(file) {
	try {	
		Ext.getCmp('originalImageName').setValue(file.name);
		uploadNewFile(true);
	} catch(e){ alert(e); }
}

function uploadStart(){ Ext.getCmp('upProgress').show();	return true; }

function uploadProgress(file, bytesLoaded, bytesTotal){ 
	try { 
		var bytes=bytesLoaded/bytesTotal; 
		var percent = Math.ceil((bytesLoaded / bytesTotal) * 100); 
		Ext.getCmp('upProgress').updateProgress(bytes,percent+'%'); 
	} catch(e){}
}

function uploadSuccess(file, serverData) { 
	Ext.getCmp('upProgress').hide(); 
	try { 
		if (serverData=='error') markError('Upload error: probably file is too big for the server.');
		else {
			Ext.getCmp('imageName').setValue(serverData); 
			joinGroupSubmit();
		}
	} catch(e){}
}

function fileQueueError(file, errorCode, message) {
	try {
		if (errorCode === SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED) {
			alert("You have attempted to queue too many files.\n" + (message === 0 ? "You have reached the upload limit." : "You may select " + (message > 1 ? "up to " + message + " files." : "one file.")));
			markError('You have attempted to queue too many files.');
			return;
		}
		switch (errorCode) {
			case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:	markError('File is too big'); break;
			case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:				markError('Cannot upload Zero Byte files.');	break;
			case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:				markError('Invalid File Type.');	break;
			default: if (file !== null) markError('Unhandled Error');  break;
		}
	} catch(e){ alert(e); }
}

function uploadError(file, errorCode, message) {
	Ext.getCmp('upProgress').hide(); 
	try {
		switch (errorCode) {
		case SWFUpload.UPLOAD_ERROR.HTTP_ERROR		: markError('Error Code: HTTP Error<br>File name: '+file.name+'<br>Message: '+message); break;
		case SWFUpload.UPLOAD_ERROR.UPLOAD_FAILED	: markError('Error Code: Upload Failed<br>File name: '+file.name+'<br>File size: '+file.size+'<br>Message: '+message); break;
		case SWFUpload.UPLOAD_ERROR.IO_ERROR		: markError('Error Code: IO Error<br>File name: '+file.name+'<br>Message: '+message); break;
		case SWFUpload.UPLOAD_ERROR.SECURITY_ERROR: markError('Error Code: Security Error<br>File name: '+file.name+'<br>Message: '+message); break;
		case SWFUpload.UPLOAD_ERROR.FILE_CANCELLED: /* this is not an error! */ break;
		default: markError('Unhandled upload error. Code: '+errorCode); break;	
		}
	} catch(e){ alert(e); }
}
