
function setWH(){
	
	var w=Element.getWidth(document.getElementById("winDiv"));
	var h=Element.getHeight(document.getElementById("winDiv"));
	var h1=Element.getHeight(document.getElementById("menuDiv"));
	//alert(h1);
	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.exType="";
	
	
	this.GetExType=function(){ //获取可以上传的文件类型
	    var out=objAjax.getText("post","filesManage.aspx?type=exNameList",null,null);
	    //alert(out);
	    this.exType=out;
	    
	}
	
		
    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="";
			try{
				_ie7objdiv.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src =_ie7path;
			   writeFettleLeft(" 提示: 如果你要得到不变形的预览效果, 请把本站点设置为可信任站点.");  //状态栏提示
			}catch(E){
			   writeFettleLeft(" 提示: 如果你要在IE8下得到良好的预览效果, 请把本站点设置为可信任站点.");  //状态栏提示
			}
		}
		
	}
	
	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.readExName=function(v){
	    v=v.split(".");
	    var exn=v[v.length-1];
		if (v.length==1){
			 exn="-1";
		}
	    if (exn==""| exn==null){
	        exn="-1";
	    }
	    return exn.toLowerCase();
	}
	
	this.upSave=function(){
		var fObj=document.getElementsByName("file_name");
		var x=0;
		var eList=","+this.exType+",";
		eList=eList.toLowerCase();
		for (var i=0;i<fObj.length;i++){
			if (fObj[i].value!=""){
				x=1;
			}
			var exn=this.readExName(fObj[i].value);
			//alert(exn);
			if(this.exType!="" & exn!="-1"){
			        if (eList.indexOf(","+exn+",")==-1){
			            alert("只能上传下列类型的文件：\n"+this.exType);
			            return;
			        }
			}
			
			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+"&fileSize="+fileSize;
		//alert(form1.action);
		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]);
			  sendupFileXml(str[i][0],str[i][1]);		
		 }
		 list.readFiles(list.onPage);
		 if (mode=="m"){
		    alert("上传成功, 新上传的文件已选择");
		 }
		 sel.out();
		
		
	}
	
}


function  selectFile(){  //选择文件的类
	var idlist=new Array();
	
	
	this.createAllImg=function(){
    	parent.win.pCreate("p-createMimg","","",true);
	}
	
	
	this.setImgFormat=function(){
	     parent.win.pCreate("p-imgSetup","","",true);
	}
	
	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 if (out=="-1"){
    		alert("有的文件不存在");
		}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)){
			tempObj=document.createElement("img");
			
			var imgObj=imgDiv.appendChild(tempObj);
			imgObj.src=path+"/x"+name+".jpg";
			imgObj.onmouseover=function(){
				var obj=this.parentNode;
				var h=Element.getHeight(obj);
				var w=Element.getWidth(obj);
				var w1=Element.getWidth(this);
				var h1=Element.getHeight(this);
				if ((w/h)>(w1/h1)){
					this.style.cssText="height:"+h+"px;width:auto;";
				}else{
					this.style.cssText="height:auto;width:"+w+"px;";
					 h1=Element.getHeight(imgObj);
					obj.style.paddingTop=((h-h1)/2);
				}
				
			}
		
			
		}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.setImgWidth=0;
	
	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);
		//alert(out);
		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] [fileTitle],[fileCBS] 
		//0         1          2          3            4            5        6          7         8           9     10         11       12           
		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],fl[i][11]);
		}
		
	}
	
	this.add=function(path,fileName,fileid,sName,fileTitle){
		//alert(fileName);
		if (fileTitle==null){
			filtTitle="";
		}
		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);
			imgObj.onload=function(){
				var obj=this.parentNode;
				var h=Element.getHeight(obj);
				var w=Element.getWidth(obj);
				var w1=Element.getWidth(this);
				list.setImgWidth=1;
				if (w==0){
					
					this.onmouseover=function(){
						var obj=this.parentNode;
						var h=Element.getHeight(obj);
						var w=Element.getWidth(obj);
						var w1=Element.getWidth(this);
						var h1=Element.getHeight(this);
						if ((w/h)>(w1/h1)){
							this.style.cssText="height:"+h+"px;width:auto;";
						}else{
							this.style.cssText="height:auto;width:"+w+"px;";
							 h1=Element.getHeight(this);
							obj.style.paddingTop=((h-h1)/2);
						}
					}
					return;
				}

				var h1=Element.getHeight(this);
				if ((w/h)>(w1/h1)){
					this.style.cssText="height:"+h+"px;width:auto;";
				}else{
					this.style.cssText="height:auto;width:"+w+"px;";
					 h1=Element.getHeight(this);
					obj.style.paddingTop=((h-h1)/2);
				}
			
			}
			
			if (this.setImgWidth==1){
				imgObj.onmouseover=function(){
						var obj=this.parentNode;
						var h=Element.getHeight(obj);
						var w=Element.getWidth(obj);
						var w1=Element.getWidth(this);
						var h1=Element.getHeight(this);
						if ((w/h)>(w1/h1)){
							this.style.cssText="height:"+h+"px;width:auto;";
						}else{
							this.style.cssText="height:auto;width:"+w+"px;";
							 h1=Element.getHeight(this);
							obj.style.paddingTop=((h-h1)/2);
						}
					}
			}
			
			
			
		}else{
			imgDiv.innerText=sName;
			bObj.fName=sName;
		}
		Div.title=sName+"\n"+fileTitle;
		
		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);
		//[id],[SourceName],[FileName],[FilePath],[FileType],[UpDateTime],[FileSize],[sExName],[nExName],[UpUser][userCount][fileTitle],[fileCBS] 
		//0         1          2          3            4            5        6          7         8           9     10         11       12           13

			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>"
					if (fl[i][7]==".jpg" |fl[i][7]==".jpeg"|fl[i][7]==".gif"){
						html=html+"图片标题:"+fl[i][11]+"<br>"	
						html=html+"图片说明:"+fl[i][12]+"<br>"	
					}
					
					if (fl[i][7]==".jpg" |fl[i][7]==".jpeg"){
						var v=fl[i][13].split("|");
						html=html+"<br>"
						for (var x=0;x<v.length;x++){
							v1=v[x].split(":");
							if (v1[1]!="" & v1[1]!=" x "){
								html=html+"<font color='#5050ff'>"+v[x]+"</font><br>";
							}
						}
					}
					
					var obj=document.getElementById("fileInfo");
					obj.innerHTML=html;
					break;	
				}
			}
		}
		
		Div.onmouseout=function(){
			this.style.backgroundColor="";
		}
		
	}
	
}
function sendupFileXml(obj,hobj)
{
     try
       {  
            var nowTitle=hobj.split('.');
            var objResponse=new JHttpResponse();
	        objResponse.write("url",obj+"/"+hobj);
            var out=objAjax.getText("post","../sysSetup/sendxml.aspx?type=readUrl",objResponse,null);
        }
        catch(err)
        {
        }
}
  