
function fileQueueError(file, errorCode, message) {
	try {
		var errormsg;
		switch (errorCode) {
		case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
			errormsg = "请不要上传空文件";
			break;
		case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
			errormsg = "文件尺寸超过设定值";
			break;
		case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:
			errormsg = "文件类型不合法";
		default:
			errormsg = message;
			break;
		}
		progress = new FileProgress(file);
		progress.setError();
		progress.setStatus(errormsg);
	} catch (ex) {
		this.debug(ex);
	}
}
//开始上传
function fileDialogComplete(numFilesSelected, numFilesQueued) {
	try {
		if (numFilesSelected > 0) {
			document.getElementById("cancelButton").disabled = false;
			this.startUpload();
		}
	} catch (ex) {
		this.debug(ex);
	}
}
//上传
function uploadProgress(file, bytesLoaded, bytesTotal) {
	try {
		var percent = Math.ceil((bytesLoaded / bytesTotal) * 100);
		var progress = new FileProgress(file);
		progress.setProgress(percent);
		if (percent === 100) {
			progress.setStatus("正在生成文件缩略图...");
		} else {
			progress.setStatus("正在上传请稍后...");
		}
	} catch (ex) {
		this.debug(ex);
	}
}
//上传成功
function uploadSuccess(file, serverData) {
	try {
		addAtt(serverData,file);
		var progress = new FileProgress(file);
		progress.setStatus("文件上传成功");
	} catch (ex) {
		this.debug(ex);
	}
}

function uploadComplete(file) {
	try {
		if (this.getStats().files_queued > 0) {
			this.startUpload();
		} else {
			document.getElementById("cancelButton").disabled = true;
		}
	} catch (ex) {
		this.debug(ex);
	}
}

function uploadError(file, errorCode, message) {
	var msg;
	switch (errorCode) {
		case SWFUpload.UPLOAD_ERROR.HTTP_ERROR:
			msg = 'HTTP错误：'+ message;
			break;
		case SWFUpload.UPLOAD_ERROR.UPLOAD_FAILED:
			msg = '文件上传失败：原因未知';
			break;
		case SWFUpload.UPLOAD_ERROR.IO_ERROR:
			msg = '服务器 I/O 错误';
			break;
		case SWFUpload.UPLOAD_ERROR.SECURITY_ERROR:
			msg = '安全错误';
			break;
		case SWFUpload.UPLOAD_ERROR.UPLOAD_LIMIT_EXCEEDED:
			msg = '单次上传文件数限制为 '+swfu.settings.file_upload_limit+' 个';
			break;
		case SWFUpload.UPLOAD_ERROR.FILE_VALIDATION_FAILED:
			msg = '上传文件校验错误';
			break;
		case SWFUpload.UPLOAD_ERROR.FILE_CANCELLED:
			msg = '上传取消';
			if (this.getStats().files_queued === 0)
			{
				document.getElementById("cancelButton").disabled = true;
			}
			progress.setStatus("上传取消");
			progress.setCancelled();
			break;
		case SWFUpload.UPLOAD_ERROR.UPLOAD_STOPPED:
			msg = '上传终止';
			break;
		default:
			msg = message;
			break;
		}
	alert(msg);
}
function addAtt(id,file) {
	attcontainer = document.createElement("div");
	attcontainer.className = "attachment_show";
	attcontainer.id = "attachment_"+id;
	document.getElementById("uploaded").appendChild(attcontainer);
	document.getElementById("attachment_"+id).innerHTML = '<img src="'+pb_url+'include/upload.inc.php?action=show&id='+id+'&fsid='+fsid+'" /><ul><li>'+file.name+'</li><li><a onclick="insertatt(\'[file='+id+']\')" href="javascript:void(0);">插入</a> | <a onclick="delatt(\''+id+'\')" href="javascript:void(0);">删除</a></li></ul>';
}
/* ******************************************
 *	FileProgress Object
 *	Control object for displaying file info
 * ****************************************** */
function FileProgress(file) {
	this.fileProgressWrapper = document.getElementById("divFileProgress");
	this.fileProgressElement = this.fileProgressWrapper.firstChild;
	this.fileProgressElement.childNodes[0].firstChild.nodeValue = file.name;
}
FileProgress.prototype.setProgress = function (percentage) {
	this.fileProgressElement.className = "progressContainer filegreen";
	this.fileProgressElement.childNodes[2].className = "progressBarInProgress";
	this.fileProgressElement.childNodes[2].style.width = percentage + "%";
};
FileProgress.prototype.setComplete = function () {
	this.fileProgressElement.className = "progressContainer fileblue";
	this.fileProgressElement.childNodes[2].className = "progressBarComplete";
	this.fileProgressElement.childNodes[2].style.width = "";
};
FileProgress.prototype.setError = function () {
	this.fileProgressElement.className = "progressContainer filered";
	this.fileProgressElement.childNodes[2].className = "progressBarError";
	this.fileProgressElement.childNodes[2].style.width = "";
};
FileProgress.prototype.setCancelled = function () {
	this.fileProgressElement.className = "progressContainer";
	this.fileProgressElement.childNodes[2].className = "progressBarError";
	this.fileProgressElement.childNodes[2].style.width = "";
};
FileProgress.prototype.setStatus = function (status) {
	this.fileProgressElement.childNodes[1].innerHTML = status;
};
