var r = "传输: {0}% 已完成";
var s = "您的文件已经上传完成";
var t = "上传失败";
var m2 = "";
var _speedtxt = " 估计还需时{1}:{2}:{3}";
function progressBar() {
	this.totalSize = 100;
	this.sizeCompleted = 0;
	this.percentDone = "0%";
	this._speed = 0;
	this.setSize = function (totalSize, size, _speed, leftHours, leftMinutes, leftSeconds) {

		var oProgressInfo = document.getElementById("progressInfo");
		var oProgress = document.getElementById("progress");
		//var TimeInfo = document.getElementById("timeinfo");
		if (oProgress == null || oProgressInfo == null)
			return;
		if (totalSize <= 0)
			return;
		this.totalSize = totalSize;
		this.sizeCompleted = size;
		this._speed = _speed;
		if (size < 0)
			this.sizeCompleted = 0;
		else if (size > this.totalSize)
			this.sizeCompleted = this.totalSize;
		if (this.sizeCompleted >= 20480)//如果已上传的文件已超过20M限制，则取消上传
		{
			document.write("上传的文件大小已超过限制");
			alert("上传的文件大小已超过20M限制，请压缩后再上传。");
			location.href = "upload.aspx";
			return;
		}
		var sizeLeft = 0;
		var progressInfoText = "";
		var MInfoText = "";
		var TimeInfoText = "";
		sizeLeft = this.totalSize - this.sizeCompleted;

		this.percentDone = Math.round(size / this.totalSize * 100) + "%";
		oProgress.style.width = (size / this.totalSize) * 300; //300为100%的宽度

		if (sizeLeft > 0) {
			progressInfoText = r.replace("{0}", Math.round(size / this.totalSize * 100));

			TimeInfoText = _speedtxt.replace("{0}", this._speed);
			TimeInfoText = TimeInfoText.replace("{1}", leftHours);
			TimeInfoText = TimeInfoText.replace("{2}", leftMinutes);
			TimeInfoText = TimeInfoText.replace("{3}", leftSeconds);
		}
		else//上传完成
			progressInfoText = s;

		oProgressInfo.innerHTML = progressInfoText + TimeInfoText;

		//TimeInfo.innerHTML = TimeInfoText;
	}
	this.UploadError = function () {
		var oProgressInfo = document.getElementById("progressInfo");
		var oProgress = document.getElementById("progress");
		if (oProgressInfo != null)
			oProgressInfo.innerHTML = t;
		if (oProgress != null)
			oProgress.style.width = "0";
	}
	this.UploadComplete = function () {
		var oProgressInfo = document.getElementById("progressInfo");
		var oProgress = document.getElementById("progress");
		if (oProgressInfo != null)
			oProgressInfo.innerHTML = s;
		if (oProgress != null)
			oProgress.style.width = "100%";
	}
}

var iTimerID = null;
var xmlHttp = XmlHttpPool.pick();
var url = "progress.aspx?UploadID=" + UploadID;
var pb = new progressBar();
function LoadProgressInfo() {
	try {
		xmlHttp.open("GET", url + "&t=" + Math.random(), true);
		xmlHttp.send(null);
		xmlHttp.onreadystatechange = function () {
			LoadData(xmlHttp);
		}
	}
	catch (e) {
		alert("connection error");
	}
}

function LoadData(xmlhttp) {
	if (xmlhttp.readyState == 4) {
		iTimerID = window.setTimeout("LoadProgressInfo()", 1000);
		try {
			eval(xmlhttp.responseText);
		}
		catch (e) {
			alert("connection error");
		}
	}
}

function ClearTimer() {
	if (iTimerID != null) {
		window.clearTimeout(iTimerID);
		iTimerID = null;
	}
}

function UploadCancel() {
	location.href = "upload.aspx";
}

function SetUploadModel() {
	if (document.getElementById("File1").value == "") {
		alert("上传的文件不能为空");
		return false;
	}
	var uValue = document.getElementById("File1").value;
	//检查文件类型是否合法
	if (uValue.toString().lastIndexOf(".") <= 0) {
		alert("不允许上传没有扩展名的文件");
		return false;
	}
	//检查上传路径是否合法
	if (uValue.toString().length < 6) {
		alert("请选择要上传的文件");
		return false;
	}
	var isSupport = false;
	var uType = uValue.toString().substr(uValue.toString().lastIndexOf(".")).toLowerCase();
	var supportType = ".asp|.aspx|.bat|.cmd|.com|.exe|.dll|.vbs";
	var types = supportType.split('|');
	for (var j = 0; j < types.length; j++) {
		if (types[j] == uType) {
			alert("不允许上传" + uType + " 这种格式");
			return false;
			break;
		}
	}
	var divProgress = document.getElementById("progressInfo");
	if (divProgress.innerText)
		document.getElementById("progressInfo").innerText = "准备上传中...";
	else
		divProgress.textContent = "准备上传中...";
	document.getElementById("Status").style.display = "inline";
	document.getElementById("Interface").style.display = "none";
	return true;
}
