var upload=function(ID,ShowID,upServer,Max){
	/*公共变量*/
	var isLoaded;//是否上传
	var fileList;//附件列表
	var fileListCont;
	var fileSizeCont;//附件列表的大小
	var fileOldCont;
	var _codeNumber = 0;
	/*不支持*/
	var fileCount;//附件个数
	/*对象初始化*/
	var initUploadX=function(num){
		fileList=new Array();
		fileListCont=document.createElement("div");
		fileListCont.className="icon_attached";
		fileListCont.title = "您最多可以添加"+(Max-1)+"个附件";
		fileListCont.style.zIndex = 200;
		fileOldCont=document.createElement("div");
		fileOldCont.className="upLoadFile";
		fileSizeCont=document.createElement("div");
		fileSizeCont.className="upLoadFile";
		$(ID).appendChild(fileListCont);
		$(ShowID).appendChild(fileOldCont);
		$(ShowID).appendChild(fileSizeCont);
		fileCount=0;
		addInput(0);
	}
	/*添加input*/
	addInput=function(i){
		if(fileList[i]){
			fileListCont.removeChild(fileList[i]);
		}else{
			fileCount++;
		}
			
			fileList[i]=document.createElement("input");
			fileList[i].type="file";
			fileList[i].name="uploadFile[" + _codeNumber+"].file";
			fileList[i].size="1";
			fileList[i].className="attached";
			fileList[i].onchange=arrangeInput;
			fileList[i].onkeypress=function(){this.blur()};
			fileList[i].onpaste=function(){this.blur()};
			fileListCont.appendChild(fileList[i]);
			_codeNumber++;
	}
	arrangeInput=function(){
		if(fileCount >= Max){
			addInput((fileList.length - 1));
			alert("您最多只能添加"+(Max-1)+"个附件！");
			return false;
		}
		for(var i=0;i<fileList.length;i++){
			if(fileList[fileList.length - 1].value==fileList[i].value && fileList[i].value != '' && ((fileList.length - 1)!= i)){
				addInput((fileList.length - 1));
				alert("文件已选，请勿重复选择同一个文件！");
				return false;
			}
			//要求的附件可以不上传，但是之后不能再点击添加附件
			//if(!chkFileType2(fileList[i].value)) {
			//  fileListCont.removeChild(fileList[i]);
				//return false;
			// }
			//if(!chkAttachSize2(fileList[i].value)){
			//	fileListCont.removeChild(fileList[i]);
			//	return false; 
			// }
		}
			displayFileSelected();
			addInput(fileList.length);
	}
	displayFileSelected=function(){
		fileSizeCont.innerHTML="";
		var p=document.createElement("p");
		for(var i=0;i<fileList.length;i++){
			
			//限制文件类型、大小fileList[i].value----文件的路径名称
			
			if(!checkFileSize2(fileList[i].value,i) || !chkFileType2(fileList[i].value,i)){
			    return ;
			}
			else if(fileList[i].value!=""){
					var span=document.createElement("span");
					span.appendChild(document.createTextNode((fileList[i].value.substr(fileList[i].value.lastIndexOf("\\")+ 1)+" ").truncate(40,"...")));
					var alink=document.createElement("a");
					alink.href="#removeAtt";
					alink.value=i;
					alink.onclick=function(){deleteInput(this.value)};
					alink.appendChild(document.createTextNode("删除"));
					span.appendChild(alink);
					p.appendChild(span);
			}
		}
		try{window.parent.indexPage.mainResize.reFrame();}catch(exp){}
		fileSizeCont.appendChild(p);
	}
	deleteInput=function(id_t){
		fileListCont.removeChild(fileList[id_t]);
		fileList.splice(id_t,1);
		fileCount -= 1;
		displayFileSelected();
	}
	this.setCount = function(oldNum_t){
		fileCount = oldNum_t;
	}
	this.getCount = function(){
		return fileCount;
	}
	this.getOldCont = function(){
		return fileOldCont;
	}
	
	//文件类型
 chkFileType2 = function(strFileName,id_t) {
	if(strFileName == "")
		return false;
	var t = strFileName.lastIndexOf(".");
	var s = strFileName.substring(t,strFileName.length);
    var dot = ".exe";
	if(s.toLowerCase() == dot){
	deleteInput(id_t);
		alert('此文档禁止上传');
		
		return false;
	}
	return true;
}	
//附件的大小
  chkAttachSize2 = function(strFileName,id_t){
 		 var maxsize = 10 * 1024;     //定义允许文件的大小，单位KB，请根据需要自行修改！
         var fso,f = "";
         fso = new ActiveXObject("Scripting.FileSystemObject");
        try
        {
         
         f = fso.getFile(strFileName);
         if(Math.round(f.Size/1024) > maxsize) {
             alert ("抱歉！您选择的文件大小超过了10M 的限制！");
             deleteInput(id_t);
             return false;
           }
        }catch(e)
        {	
            alert("该文件不支持");
            deleteInput(id_t);
            return false;
        }
        return true;
  }	
  	initUploadX();
}
//限制文件上传大小
function checkFileSize2(strFileName,id_t){
			 var img = new Image();
			  var maxsize = 10 * 1024;  
			 img.src = strFileName;
			 if(strFileName.fileSize/1024 > maxsize) {//当然这里得到的文件大小，最好还是在提交的时候来检查，因为加载图片还是需要时间的，所以不能保证一定得到，这里就简写了
		     	alert("上传图片大小请保持在200KB以内!");
		     	 deleteInput(id_t);
		     	return false;
		      }
		      return true;
	 }	
