
function setWH(){
	
	var w=Element.getWidth(document.getElementById("winDiv"));
	var h=Element.getHeight(document.getElementById("winDiv"));
	//var h1=Element.getHeight(document.getElementById("menuDiv"));
	var h1=0
	var h2=Element.getHeight(document.getElementById("toolsDiv"));
	var h3=Element.getHeight(document.getElementById("optionTitle"))+1;
	var h4=Element.getHeight(document.getElementById("fListPage"));
	if (h4==0){h4=25}
	var w1=Element.getWidth(document.getElementById("upLeftDiv"))
	if (w1==0){w1=250}
	
	oBodyDiv.style.height=(h-h1-h2-h3)+"px";
	
	var oBody=document.getElementsByName("optionBody")
	for (var i=0;i<oBody.length;i++){
		oBody[i].style.height=(h-h1-h2-h3)+"px";
		oBody[i].style.width=(w-4)+"px";
	}
	upRightDiv.style.width=(w-w1-18)+"px";
	upRightDiv.style.height=(h-h1-h2-h3-10)+"px";
	upLeftDiv.style.height=(h-h1-h2-h3-10)+"px";
	fListLeft.style.height=(h-h1-h2-h3-10)+"px";

	fListRight.style.height=(h-h1-h2-h3-10)+"px";
	//alert(h1+"|"+h2+"|"+h3+"|"+w1)
	fListRight.style.width=(w-w1-10)+"px";
		
	fListJob.style.width=(w-w1-10)+"px";
	fListJob.style.height=(h-h1-h2-h3-h4-1)+"px";
	//	alert(h5)
}


function fileupClass(){  //上传文件的类
	var _ie7objdiv,_ie7objimg,_ie7path;
	this.upType="1";
		
    this.copyText=function(){  //复制文件上传框
	
		var fObj=document.getElementsByName("file_name");
		if (fObj.length>=15){
			alert("最多只允许一次上传15个文件")
			return false;
		}
		var objTemplate=document.getElementById("file_name");
		var objDiv=document.getElementById("upTextdiv");
		var objCopy=objTemplate.cloneNode(true); //复制行
		objCopy.style.display="block";
		var newObj=objDiv.appendChild(objCopy);
		newObj.onChange=function(){
			upfile.findDiv(this)
		}
		this.addDiv();
	}	
	
	
	this.addDiv=function(){  //创建 DIV
		var tempObj=document.createElement("div");
		var objDiv=document.getElementById("upRightDiv");
		Div=objDiv.appendChild(tempObj);
		Div.className="preview";
		Div.id="preview";
		Div.name="preview";
		Div.innerHTML="<div id='previewimg' name='previewimg' class='previewimg'></div><div  id='previewbutton' name='previewbutton' class='previewbutton'><input type='button' value='删除' id='delimg' name='delimg' disabled='disabled'></div>"
	}
	
	this.findDiv=function(fileObj){ //找到要画图的DIV
		var fObj=document.getElementsByName("file_name");
		var dObj=document.getElementsByName("preview");
		var l=fObj.length;
		if (l!=0){
			for (var i=0;i<l;i++){
				if (fObj[i]==fileObj){
					this.fillDiv(dObj[i],fileObj.value)
				}
			}
		}else{
			this.fillDiv(dObj,fileObj.value)
		}
		
	}
	
	this.fillDiv=function(div,path){  //写入预览图
		div.innerHTML="";
		
		var tempObj=document.createElement("div");
		var imgDiv=div.appendChild(tempObj);
		imgDiv.id="previewimg"
		imgDiv.className="previewimg"
		

		tempObj=document.createElement("div");
		buttonDiv=div.appendChild(tempObj);
		buttonDiv.id="previewbutton";
		buttonDiv.className="previewbutton";
		
		tempObj=document.createElement("input");
		tempObj.type="button"
		button=buttonDiv.appendChild(tempObj);
		button.value="删除";
		button.id="delimg";
		button.name="delimg";
		button.onclick=function(){
			upfile.delfile(this);
		}
		
		imgDiv.title=path;
		if (isIMG(path)){
			
			path="file://"+path.replace(/\\/g,"/")
			tempObj=document.createElement("img");
			newimg=imgDiv.appendChild(tempObj);
			newimg.src=path;
			newimg.width="190";
			
			
			if (ieVer()!=6){
				 _ie7objdiv=imgDiv;
				 _ie7objimg=newimg;
				 _ie7path=path;
				setTimeout("upfile.setIE7img()",100);
			}
		}else{
			imgDiv.innerText=path;
		}
		
		
		
	}

	
	this.setIE7img=function(){  //IE7以上兼容
		
		if (_ie7objimg.fileSize==-1){
			_ie7objdiv.innerHTML="";
			_ie7objdiv.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src =_ie7path;
			 writeFettleLeft(" 提示: 如果你要得到不变形的预览效果, 请把本站点设置为可信任站点.");  //状态栏提示
		}
		
	}
	
	this.delfile=function(button){  //点删除后
		var fObj=document.getElementsByName("file_name");
		var dObj=document.getElementsByName("preview");
		var bObj=document.getElementsByName(button.id);
		var l=bObj.length
		if (l>1){
			for (var i=0;i<l;i++){
				if (bObj[i]==button){
					fObj[i].removeNode(true);
					dObj[i].removeNode(true);
				}
			}
		}else{
			alert("最后一个文件不允许删除");
			
		}
		
	}
	
	this.upSave=function(){
		var fObj=document.getElementsByName("file_name");
		var x=0;
		for (var i=0;i<fObj.length;i++){
			if (fObj[i].value!=""){
				x=1;
			}
			if (this.upType=="1"){
				if (!isIMG(fObj[i].value)){
					alert("只能上传图片");
					return;
				}
			}
		}
		if (fObj.length==0){
			if (fObj.value=="")
			{
				x=0;
			}
		}
		if (x==0){
			alert("你没有选择任何需要上传的文件")
			return false;
		}
		form1.action="filesManage.aspx?type=upfile&upType="+type;
		form1.submit();
		form1.upButton.disabled=true;
		form1.newButton.disabled=true;
		var bObj=document.getElementsByName("delimg");
		var l=fObj.length
		if (l==0){
			fObj.disabled=true;
		}else{
			for (var i=0;i<l;i++){
				fObj[i].disabled=true;
			}
		}
		
		 l=bObj.length;
		 if (l==0){
			bObj.disabled=true;
		}else{
			for ( i=0;i<l;i++){
				bObj[i].disabled=true;
			}
		}
	
	}
	
	this.saveOk=function(str){
		  //alert(str)
		  str=comminute(str,c1,c2)
		 for (var i=0;i<str.length-1;i++){
			 
			 sel.add(str[i][0],str[i][1],str[i][2]);
		 }
		 list.readFiles(list.onPage);
		 alert("上传成功, 新上传的文件已选择");
		
		
	}
	
}


function  selectFile(){  //选择文件的类
	var idlist=new Array();
	
	this.out=function(){  //向页面返回选择好的文件;
		if (idlist.length==0){
			alert("你没有选择文件");
			return  null;
		}
		//[id],[SourceName],[FileName],[FilePath],[FileType],[UpDateTime],[FileSize],[sExName],[nExName],[UpUser] 
		//0         1          2          3            4            5        6          7         8           9
		var fl=list.fList;
		var filepath="";
		var idl="";
		for (var i=1;i<fl.length-1;i++){
			for (var x=0;x<idlist.length;x++){
				if (idlist[x]==fl[i][0]){
					filepath=filepath+fl[i][3]+"/"+fl[i][2]+c1;
					idl=idl+fl[i][0]+",";
					break;
				}
			}
		}
		idl=idl.substr(0,idl.length-1);
		
		var objResponse=new JHttpResponse();
		objResponse.write("idl",idl);
		var out=objAjax.getText("post","filesManage.aspx?type=use",objResponse,null);
		if (out=="0"){
			alert("服务器数据更新失败");
		}else if (out!=""){
			alert(erStr(out));	
		}
		
		
		 window.returnValue= filepath;
		 window.close();
		
		
	}
	
	
	this.del=function(){
		if (idlist.length==0){
			alert("你没有选择文件");
			return  null;
		}
		if (!window.confirm("你将要删除"+idlist.length+"个用户上传的文件,是否继续")){
			  return  null;
	    }
		var objResponse=new JHttpResponse();
		objResponse.write("fileidList",idlist+"");
	
		var out=objAjax.getText("post","filesManage.aspx?type=del",objResponse,null);
		if (out=="1"){
			var objDiv=document.getElementById("selectDiv");
			objDiv.innerHTML="";
			list.readFiles(list.onPage);
			idlist.clear();
			alert("删除操作成功")
		}else if (out=="0"){
			var objDiv=document.getElementById("selectDiv");
			objDiv.innerHTML="";
			list.readFiles(list.onPage);
			idlist.clear();
			alert("从磁盘中删除文件失败\n\n请和服务器管理员联系\n\n确认管理员已授权ASP.NET应用程序可以\n\n删除您网站下UPFILE文件夹下的文件.")
		}else{
			alert(erStr(out))
		}
		
		
	}
	
	this.clearfile=function(){ //从磁盘中清除没有使用过的文件
		if (!window.confirm("您要删除所有未使用过的上传文件,是否继续")){
			  return  null;
	    }
		var out=objAjax.getText("post","filesManage.aspx?type=clear",null,null);
		switch (out)
		{
			case "-1":
				alert("没有找到需要清理的文件")
				break;
			case "1":
				alert("操作成功");
				location.reload();
				break;
			case "0":
				alert("从磁盘中删除文件失败\n\n请和服务器管理员联系\n\n确认管理员已授权ASP.NET应用程序可以\n\n删除您网站下UPFILE文件夹下的文件.");
				location.reload();
				break;
		    default:
				alert(erStr(out))
				break;
		}
	}
	
	this.add=function(path,name,id){
		if (this.islist(id)){
			return;
		}
		idlist[idlist.length]=id;
		var tempObj=document.createElement("div");
		var objDiv=document.getElementById("selectDiv");
		Div=objDiv.appendChild(tempObj);
		Div.id="sDiv";
		Div.name="sDiv";
		Div.className="preview";
		Div.title=name;
		
		tempObj=document.createElement("div");
		imgDiv=Div.appendChild(tempObj);
		imgDiv.id="simgDiv";
		imgDiv.name="simgDiv";
		imgDiv.className="previewimg"

		tempObj=document.createElement("div");
		buttonDiv=Div.appendChild(tempObj);
		buttonDiv.id="sbDiv";
		buttonDiv.name="sbDiv";
		buttonDiv.className="previewbutton";
		
		tempObj=document.createElement("input");
		tempObj.type="button";
		tempObj.value="取消";
		button=Div.appendChild(tempObj);
		button.delid=id;
		button.id="sButton";
		button.name="sButton";
		button.onclick=function(){
			sel.delsetlect(this);
		}
		if (isIMG(name)){
			imgDiv.innerHTML="<img src='"+path+"/x"+name+".jpg'>";
		}else{
			imgDiv.innerText=name;
		}
		
	}
	
	this.delsetlect=function(thisObj){
	    var divObj=document.getElementsByName("sDiv");
		var bObj=document.getElementsByName("sButton");
		if (bObj.length==0){
			divObj.remove.Node(true);
			idlist.clear();
		}else{
			for (var i=0;i<bObj.length;i++){
				if (bObj[i]==thisObj){
					idlist.removeAt(i);
					divObj[i].removeNode(true);
					break;
				}
			}
		}
	
	}
	
	this.islist=function(id){ //判断该图是否已加入选择
		for (var i=0;i<idlist.length;i++)
		{
			if (idlist[i]==id){
				return true;
			}
		}
		return false;
	}
	
}



function listClass(){  //列表文件的类
	this.fList=null;	
	this.onPage=1
	
	this.readFiles=function(page){
		if (page==null){
			page=1
		}
		this.onPage=page;
		var objResponse=new JHttpResponse();
		objResponse.write("fType",type);
		objResponse.write("page",page);
		objResponse.write("pagesize",12);
		//alert(type);
		var out=objAjax.getText("post","filesManage.aspx?type=list",objResponse,null);
		out=comminute(out,c1,c2)
		
		this.fList=out;
		this.display();
		//alert(erStr(out));

		
	}
	
	this.display=function(){
		var pageDiv=document.getElementById("fListPage");
		var fl=this.fList;
		var page=fl[0];
		var wPage=new outPage();
		wPage.obj=pageDiv;
		wPage.mode=0;  //分页显示的格式
		wPage.pageArray=page;
		wPage.run="list.readFiles";
		wPage.create();
		//[id],[SourceName],[FileName],[FilePath],[FileType],[UpDateTime],[FileSize],[sExName],[nExName],[UpUser][userCount] 
		//0         1          2          3            4            5        6          7         8           9     10
		var objDiv=document.getElementById("fListJob");
		objDiv.innerHTML="";
		for (var i=1;i<fl.length-1;i++){
			this.add(fl[i][3],fl[i][2],fl[i][0],fl[i][1]);
		}
		
	}
	
	this.add=function(path,fileName,fileid,sName){
		var tempObj=document.createElement("div");
		var objDiv=document.getElementById("fListJob");
		Div=objDiv.appendChild(tempObj);
		Div.className="preview";
		Div.fid=fileid;
		
		tempObj=document.createElement("div");
		var imgDiv=Div.appendChild(tempObj);
		imgDiv.className="previewimg";
		
		tempObj=document.createElement("div");
		var bDiv=Div.appendChild(tempObj);
		bDiv.className="previewbutton";
		
		tempObj=document.createElement("input");
		tempObj.type="button";
		var bObj=Div.appendChild(tempObj);
		bObj.value="选择";
		bObj.path=path;
		bObj.fName=fileName;
		bObj.fid=fileid;
		
		if (isIMG(fileName)){
			tempObj=document.createElement("img");
			tempObj.src=path+"/x"+fileName+".jpg";
			var imgObj=imgDiv.appendChild(tempObj);
			//imgDiv.innerHTML="<IMG src='"+path+"/x"+fileName+".jpg'>";
		}else{
			//alert(path+"/"+sName);
			imgDiv.innerText=sName;
			bObj.fName=sName;
		}
		Div.title=sName;
		
		bObj.onclick=function(){
			sel.add(this.path,this.fName,this.fid);
		}
		
		Div.onmouseover=function(){
			this.style.backgroundColor="#dfdfff";
			var fl=list.fList;
			//alert(this.fid);
			for (var i=1;i<fl.length;i++){
				
				if (fl[i][0]==this.fid){
					//alert(this.fid);
					var html="文件原名:"+fl[i][1]+"<br>"
					html=html+"文件大小:"+fl[i][6]+"字节<br>"
					html=html+"上传用户:"+fl[i][9]+"<br>"
					html=html+"上传日期:"+fl[i][5]+"<br>"
					html=html+"调用次数:"+fl[i][10]+"<br>"
					var obj=document.getElementById("fileInfo");
					obj.innerHTML=html;
					break;	
				}
			}
		}
		
		Div.onmouseout=function(){
			this.style.backgroundColor="";
		}
		
	}
	
}