$package("com.qn.io");

com.qn.io.File = function (path){
	this.path = path;
}

com.qn.io.File.prototype = new js.lang.BaseObject();
com.qn.io.File.prototype.async = true;
com.qn.io.File.prototype.result = null;
com.qn.io.File.prototype.returnValue = false;
com.qn.io.File.prototype.parent = null;
com.qn.io.File.prototype.filename = null;
com.qn.io.File.prototype.target = null;
com.qn.io.File.prototype.desc = null;
com.qn.io.File.prototype.fileId = null;
com.qn.io.File.prototype.userId = null;
com.qn.io.File.prototype.onload = null;
com.qn.io.File.prototype.onerror = null;
com.qn.io.File.prototype.score = 0;
com.qn.io.File.prototype.shareName = null;
com.qn.io.File.prototype.host = null;
com.qn.io.File.prototype.windowType = 0;
com.qn.io.File.prototype.baseUrl = "/view?module=fileService&action=";

com.qn.io.File.prototype.getHttp = function(){
	if(!this.http){
		this.http = new js.net.HttpConnection();
		this.http.method = "POST";
		this.http.owner = this;
	}
	this.http.async = this.async;
	this.http.onerror = function(http){
		if(browser.progress) browser.progress.hide();
		this.owner.returnValue = false;
		var error = http.responseText;
		if(!error) browser.messageBox("Network or service error.");
		else if(this.owner.onerror)
			this.owner.onerror(error);
		else browser.messageBox(error);
	}
	this.http.onload = function(http){
		var data = this.owner.processResponse(http.responseText);
		if(!data.errorMsg)
			this.owner.returnValue = true;
		if(!data.errorMsg && this.owner.onload) this.owner.onload(data);
	}
	if(browser.progress) browser.progress.start(props("Loading......"));
	return this.http;
}

com.qn.io.File.prototype.processResponse = function(responseText){
	if(browser.progress) browser.progress.hide();
	var data;
	try{eval('data='+responseText);}catch(e){data=new Array();};
	if(data.errorMsg)
		if(this.onerror)
			this.onerror(data.errorMsg);
		else
			browser.messageBox(data.errorMsg);
	else if(!data.errorMsg){
		if(this.__action>=0){
			browser.sendMessage(null, 810, this.__action, this);
		}
	}
	return data;
}

com.qn.io.File.prototype.onerror = function(errorMsg){
	browser.messageBox(errorMsg);
}
com.qn.io.File.prototype.list = function(exts, isListDirs,startRecord){
	this.async = true;
	var __this = this;
	var http = this.getHttp();
	var url = this.baseUrl + "dir";

	var params = "path=" + js.util.Utils.prototype.encodeString(this.path);
	if(exts){
		params += "&exts="+exts;
	}
	if(isListDirs==true){
		params += "&islistdirs="+isListDirs;
	}	
	if(startRecord!=null){
		params += "&recno="+startRecord;
	}	
	http.onload = function(http){
		if(browser.progress) browser.progress.hide();
		this.owner.doListed(http.responseText);
	}
	http.open(url);
	http.send(params);
}

com.qn.io.File.prototype.doListed = function(responseText){
	var data = this.processResponse(responseText);
	if(!data) return;
	if(data.errorMsg) return;

	this.result = new js.lang.Array();
	var file;
	for(var i=0; i<data.length; i++){
		file = new com.qn.io.File();
		file.fillData(data[i]);
		this.result.addItem(file);
	}
	if(this.onload)
		this.onload(this.result);
}

com.qn.io.File.prototype.fillData = function(data){
	this.parent = data.parent;
	this.target = data.target;
	this.type = data.type;
	this.filename = data.name;
	this.lastModified = data.lastModified;
	this.size = data.size;
	this.bigIcon = data.bigIcon;
	this.smallIcon = data.smallIcon;
	this.absoluteIP = data.absoluteIP;
	this.isShared = data.isShared;
	this.desc = data.desc;
	this.userId = data.userId;
	this.fileId = data.fileId;
	this.realPath = data.realPath;
	this.link = data.link;
	this.adMode = data.adMode;
	this.isPass = data.isPass;
}

com.qn.io.File.prototype.mkdir = function(){
	this.async = false;
	var __this = this;
	var http = this.getHttp();
	var url = this.baseUrl + "createNewFolder";
	var params = "path="+js.util.Utils.prototype.encodeString(this.path);
	this.__action = 0;//new
	http.open(url);
	http.send(params);
	return this.returnValue;
}

com.qn.io.File.prototype.getSizeDisp = function(){
	if(!this.isFile()) return "";
	var ft = new js.util.Format();
	return ft.formatBytes(this.getSize());
}

com.qn.io.File.prototype.getIsPassDisp = function(){
	if(this.isPass==2 || this.isPass==5)
		return props("Abuse");
	else return "";
}

com.qn.io.File.prototype.getLastModifiedDisp = function(){
	if(this.getLastModified()==0) return "";
	var ft = new js.util.Format();
	var dt = new js.util.Date(this.getLastModified());
	return dt.formatDateTime(props("dateTimeFormat"));
}
com.qn.io.File.prototype.getAbsoluteIPDisp = function(){
	if(this.getIsPassDisp()!="") return this.getIsPassDisp();
	if(!this.absoluteIP || this.absoluteIP<=0) return "";
	return this.absoluteIP;
}

com.qn.io.File.prototype.getDescDisp = function(){
	if(!this.desc) return "";
	return this.desc;
}

com.qn.io.File.prototype.getAttributes = function(){
	this.async = true;
	var __this = this;
	var http = this.getHttp();
	var url = this.baseUrl + "getAttributes";
	var params = "fileId="+this.fileId;


	http.onload = function(http){
		var data = __this.processResponse(http.responseText);
		if(!data.errorMsg){
			__this.fillData(data);
			if(__this.onload)
				__this.onload(data);
		}
	}
	http.open(url);
	http.send(params);
}

com.qn.io.File.prototype.deleteFile	= function(fileIds){
	if(!fileIds || fileIds.length==0) return;
	this.async = false;
	var __this = this;
	var http = this.getHttp();
	var url = this.baseUrl + "delete";
	var params = "fileIds=" + fileIds;
	this.__action = 2;//delete
	http.open(url);
	http.send(params);
	return this.returnValue;
}
com.qn.io.File.prototype.recovery = function(fileIds){
	if(!fileIds || fileIds.length==0) return;
	this.async = false;
	var __this = this;
	var http = this.getHttp();
	var url = this.baseUrl + "recovery";
	var params = "fileIds=" + fileIds;
	this.__action = 6;//recovery
	http.open(url);
	http.send(params);
	return this.returnValue;
}


com.qn.io.File.prototype.deleteOnExist = function(){
	return true;
}

com.qn.io.File.prototype.editSave = function(){
	this.async = false;
	var __this = this;
	var http = this.getHttp();
	var url = this.baseUrl + "editSave";
	var params = "fileId="+js.util.Utils.prototype.encodeString(this.fileId);
	params += "&desc="+js.util.Utils.prototype.encodeString(this.desc);
	http.open(url);
	http.send(params);
}
com.qn.io.File.prototype.renameTo = function(newParent, newName){
	this.async = false;
	var __this = this;
	var http = this.getHttp();
	var url = this.baseUrl + "rename";
	this.__action = 1;//rename
	var params = "fileId="+js.util.Utils.prototype.encodeString(this.fileId);
	params += "&newParent="+js.util.Utils.prototype.encodeString(newParent);
	params += "&newName="+js.util.Utils.prototype.encodeString(newName);
	http.open(url);
	http.send(params);
	if(this.returnValue){
		this.parent = newParent;
		this.filename = newName;
	}
	return this.returnValue;
}

com.qn.io.File.prototype.move = function(fileIds, newPath){
	this.async = false;
	var __this = this;
	var http = this.getHttp();
	var url = this.baseUrl + "move";
	this.__action = 1;//rename
	var params = "fileIds="+js.util.Utils.prototype.encodeString(fileIds);
	params += "&newPath="+js.util.Utils.prototype.encodeString(newPath);
	http.open(url);
	http.send(params);
	return this.returnValue;
}
com.qn.io.File.prototype.getRealPath = function(){
	if(this.isShortUrl())
		return this.realPath;
	else return "";
}

com.qn.io.File.prototype.getShortUrl = function(){
	if(this.isShortUrl())
		return this.link;
	else return "";
}

com.qn.io.File.prototype.getLink = function(){
	return this.link;
}

com.qn.io.File.prototype.getDownLink = function(){
	return this.link;
}

com.qn.io.File.prototype.getLinkUrl = function(){
	return "/explorer/getLink/" + this.userId + "/" + this.fileId + ".html";
}

com.qn.io.File.prototype.getAdMode = function(){
	if(!this.adMode) return "";
	return this.adMode;
}

com.qn.io.File.prototype.validateFilename = function(filename){
	var regex = /[/\\\\<>*:?|\"]/;
    if (regex.test(filename)) return false;
    else return true;
}



com.qn.io.File.prototype.searchList = function(params,startRecord){

}

com.qn.io.File.prototype.setAsync = function(async){
	this.async = async;
	this.getHttp().async = async;
}

com.qn.io.File.prototype.clone = function(){
	var newfile = new com.qn.io.File();
	newfile.setPath(this.getPath());
	newfile.setTarget(this.getTarget());
	newfile.type = this.type;
	newfile.lastModified = this.lastModified;
	newfile.size = this.size;
	newfile.bigIcon = this.bigIcon;
	newfile.smallIcon = this.smallIcon;
	newfile.windowType = this.windowType;
	return newfile;
}

com.qn.io.File.prototype.setTarget = function(target){
	this.target= target;
}

com.qn.io.File.prototype.getTarget = function(){
	if(!this.target)
		return this.getPath();
	return this.target;
}

com.qn.io.File.prototype.canRead = function(){
	return true;
}
com.qn.io.File.prototype.canWrite = function(){
	return true;
}
/*com.qn.io.File.prototype.renameTo = function(filename){
	var __this = this;
	this.__action = 1;//rename

	this.getHttp().OpenURL = com.qn.io.File.prototype.OPEN_URL+"?ds=" + "tomos.filesystem.File.renameTo";
	this.GetDataSet().Close();
	this.GetDataSet().Fields.Clear();
	this.GetDataSet().Params.Clear();
	var param1 = new js.db.Param("path", this.Path, "String");
	var param2 = new js.db.Param("rename", filename, "String");
	this.GetDataSet().Params.Add(param1);
	this.GetDataSet().Params.Add(param2);
	this.GetDataSet().OnAfterOpen = function(){
		__this.ReturnValue = true;
		__this.Result = this;
		__this.__OldPath = __this.GetPath();
		__this.SetPath(__this.GetParent()+"/"+filename);
		__this.SetFileName(filename);
		if(!__this.IsFileShortcut() && !__this.IsDirShortcut())
			__this.Target = __this.GetPath();
		Browser.SendMessage(null, 810, __this.__Action, __this);//WM_FILESYSTEMCHANGE.rename
		if(__this.Onload)
			__this.Onload(__this.Result);
	}
	this.GetDataSet().Open();
	return this.ReturnValue;
}*/

com.qn.io.File.prototype.createShortcut = function(target, icon, windowtype){
	var __this = this;
	this.__Action = 0;//new
	this.GetDataSet().OpenURL = com.qn.io.File.prototype.OPEN_URL+"?datasource=" +"tomos.filesystem.File.createShortcut";
	this.GetDataSet().Close();
	this.GetDataSet().Fields.Clear();
	this.GetDataSet().Params.Clear();
	var param1 = new js.db.Param("path", this.GetPath(), "String");
	var param2 = new js.db.Param("target", target, "String");
	var param3 = new js.db.Param("icon", icon, "String");
	var param4 = new js.db.Param("windowtype", windowtype, "String");
	this.GetDataSet().Params.Add(param1);
	this.GetDataSet().Params.Add(param2);
	this.GetDataSet().Params.Add(param3);
	this.GetDataSet().Params.Add(param4);
	this.GetDataSet().OnAfterOpen = function(){
		__this.ReturnValue = true;
		__this.Result = this;
		var filename = __this.GetPath();
		var file = new com.qn.io.File(filename);
		if(__this.IsFile())
			file.Type = 3;
		else
			file.Type = 2;
		file.SetTarget(target);
		file.BigIcon = icon;
		file.WindowType = windowtype;
		Browser.SendMessage(null, 810, __this.__Action, file);//WM_FILESYSTEMCHANGE.new
		if(this.Owner.Onload)
			this.Owner.Onload(this.Owner.Result);
	}
	this.GetDataSet().Open();
	return this.ReturnValue;
}
com.qn.io.File.prototype.createShare = function(sharename, permissions, desc, point, cash,sharetype){
	var __this = this;
	this.GetDataSet().OpenURL  = com.qn.io.File.prototype.OPEN_URL+ "?datasource=" +"tomos.filesystem.File.createShare";
	this.GetDataSet().Close();
	this.GetDataSet().Fields.Clear();
	this.GetDataSet().Params.Clear();
	var param1 = new js.db.Param("path", this.GetTarget(), "String");
	var param2 = new js.db.Param("sharename", sharename, "String");
	var param3 = new js.db.Param("permissions", permissions, "String");
	var param4 = new js.db.Param("desc", desc, "String");
	var param5 = new js.db.Param("point", point, "String");
	var param6 = new js.db.Param("cash", cash, "String");
	var param7 = new js.db.Param("sharetype", sharetype, "String");
	this.GetDataSet().Params.Add(param1);
	this.GetDataSet().Params.Add(param2);
	this.GetDataSet().Params.Add(param3);
	this.GetDataSet().Params.Add(param4);
	this.GetDataSet().Params.Add(param5);
	this.GetDataSet().Params.Add(param6);
	this.GetDataSet().Params.Add(param7);
	this.GetDataSet().OnAfterOpen = function(){
		__this.ReturnValue = true;
		if(__this.IsFile())
			__this.Type = 5;
		else
			__this.Type = 6;
		this.Owner.Result = this;
		if(this.Owner.Onload)
			this.Owner.Onload(this.Owner.Result);
	}
	this.GetDataSet().Open();
	return this.ReturnValue;
}

com.qn.io.File.prototype.deleteShare = function(sharename){
	var __this = this;
	this.GetDataSet().OpenURL  = com.qn.io.File.prototype.OPEN_URL+ "?datasource=" +"tomos.filesystem.File.deleteShare";
	this.GetDataSet().Close();
	this.GetDataSet().Fields.Clear();
	this.GetDataSet().Params.Clear();
	var param1 = new js.db.Param("sharename", sharename, "String");
	this.GetDataSet().Params.Add(param1);
	this.GetDataSet().OnAfterOpen = function(){
		__this.ReturnValue = true;
		if(__this.IsShareFile()){
			__this.Type = 0;
		}
		else{
			__this.Type = 1;
		}
		this.Owner.Result = this;
		if(this.Owner.Onload)
			this.Owner.Onload(this.Owner.Result);
	}
	this.GetDataSet().Open();
	return this.ReturnValue;
}

com.qn.io.File.prototype.cut = function(src, target){
	this.GetDataSet().OpenURL  = com.qn.io.File.prototype.OPEN_URL+ "?datasource=" +"tomos.filesystem.File.cut";
	this.__Action = 3;
	this.Copy(src, target);
	this.__Action = 4;
}

com.qn.io.File.prototype.copy = function(src, target){
	var __this = this;
	if(this.__Action!=3){
		this.__Action = 4;
		this.GetDataSet().OpenURL  = com.qn.io.File.prototype.OPEN_URL+ "?datasource=" +"tomos.filesystem.File.copy";
	}
	this.GetDataSet().Close();
	this.GetDataSet().Fields.Clear();
	this.GetDataSet().Params.Clear();
	var param1 = new js.db.Param("path", src, "String");
	var param2 = new js.db.Param("target", target, "String");
	this.GetDataSet().Params.Add(param1);
	this.GetDataSet().Params.Add(param2);
	this.__BuildPriceInfo();

	this.GetDataSet().OnAfterOpen = function(){
		__this.ReturnValue = true;
		__this.Result = this;
		if(__this.__Action==3){
            var filenames = src.split(";");
			for(var i=0; i<filenames.length-1; i++){
				Browser.SendMessage(null, 810, 2, new com.qn.io.File(filenames[i]));//WM_FILESYSTEMCHANGE.delete
			}
		}
//		Browser.SendMessage(null, 810, 0, new com.qn.io.File(target));//WM_FILESYSTEMCHANGE.new
		if(this.Owner.Onload)
			this.Owner.Onload(this.Owner.Result);
	}
	this.GetDataSet().Open();
	return this.ReturnValue;
}

com.qn.io.File.prototype.setFilename = function(filename){
	this.filename = filename;
}

com.qn.io.File.prototype.getFilename = function(filename){
	if(!filename){
		if(this.filename)
			return this.filename;
		else
			filename = this.getPath();

	}
	if(!filename) return;
	var pos = filename.lastIndexOf("/");
	if(pos==-1)
		pos = filename.lastIndexOf("\\");
	if(pos!=-1)
		filename = filename.substring(pos+1);
	return filename;
}

com.qn.io.File.prototype.getParent = function(){
	if(this.parent)
		return this.parent;
	else {
		var path = this.getPath();
//		if(this.getFilename()!=null)
//			path = path.replaceLast(path, this.getFilename());
		var pos = path.lastIndexOf("/");
		if(pos!=-1)
			path = path.substring(0, pos);
		return path;
	}
}
com.qn.io.File.prototype.getPath = function(){
	if(!this.path)
		return this.parent + "/" + this.filename;
	else {
		var path = this.path;
		if(path && path!=""){
			if("/"==path.substring(path.length-1)){
				path = path.substring(0, path.length-1);
			}
		}
		return path;
	}
}
com.qn.io.File.prototype.setPath = function(path){
	this.path = path;
}

com.qn.io.File.prototype.getDisplayName = function(){
	var filename = this.getFilename();
	var ext = com.qn.io.File.prototype.getExtName(filename);
	if("sht"==ext || "sfd"==ext || "share"==ext){
		return com.qn.io.File.prototype.getFrontName(filename)
	}
	else return filename;	
}

com.qn.io.File.prototype.getDesc = function(){
	var desc = this.desc;
	if(!desc)
		desc = this.getDisplayname();
	return desc;
}
com.qn.io.File.prototype.readText = function(filename){
	var __this = this;
	if(filename)
		this.SetPath(filename);
	if(!this.HttpConnection)
		this.HttpConnection = new js.net.HttpConnection();
	this.HttpConnection.Async = this.Async;
	this.HttpConnection.Owner = this;
	this.HttpConnection.Onload = function(http){
		__this.ReturnValue = true;
		this.Owner.Result = http.responseText;
		if(this.Owner.Onload)
			this.Owner.Onload(this.Owner.Result);
	}
	this.HttpConnection.Onerror = function(http){
		__this.ReturnValue = false;
		this.Owner.Result = null;
		var error = http.responseText;
		if(this.Owner.Onerror)
			this.Owner.Onerror(error);
		else Browser.MessageBox(error);
	}
	this.HttpConnection.Open(com.qn.io.File.prototype.READTEXT_URL);
	this.HttpConnection.Instance.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
	this.HttpConnection.Send(com.qn.io.File.prototype.__BuildPriceUrl("filename="+this.GetPath()));
	return this.ReturnValue;
}

com.qn.io.File.prototype.writeText = function(text, filename){
	var __this = this;
	if(filename){
		this.SetPath(filename);}
	if(!this.HttpConnection)
		this.HttpConnection = new js.net.HttpConnection();
	this.HttpConnection.Async = this.Async;
	this.HttpConnection.Owner = this;
	this.HttpConnection.Onload = function(http){
		__this.ReturnValue = true;
		__this.Result = http.responseText;
		if(!http.responseText || http.responseText==""){
			if(__this.Onload)
				__this.Onload(__this.Result);
		}
		else {
			__this.ReturnValue = false;
			if(__this.Onerror)
				__this.Onerror(__this.Result);
			else Browser.MessageBox(__this.Result);
		}
	}
	this.HttpConnection.Onerror = function(http){
		__this.ReturnValue = false;
		this.Owner.Result = null;
		var error = http.responseText;
		if(this.Owner.Onerror)
			this.Owner.Onerror(error);
		else Browser.MessageBox(__this.Result);
	}
	this.HttpConnection.Open(com.qn.io.File.prototype.WRITE_URL);
//	this.HttpConnection.Instance.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded;");
//	this.HttpConnection.Send("filename="+this.Path+"&context="+text);
	this.HttpConnection.Send(this.GetPath()+"&context="+text);
	return this.ReturnValue;
}
com.qn.io.File.prototype.OPEN_URL = "/servlet/DataSet";
com.qn.io.File.prototype.READ_URL = "/servlet/ReadFileStream";
com.qn.io.File.prototype.READTEXT_URL = "/servlet/ReadFileText";
com.qn.io.File.prototype.WRITE_URL = "/servlet/WriteFileText";

com.qn.io.File.prototype.read = function(){
	var url = this.baseUrl + "read&userId=" + this.userId + "&fileId=" + this.fileId;
	return url;
}
com.qn.io.File.prototype.write = function(value){
	return true;
}
com.qn.io.File.prototype.size = 0;

com.qn.io.File.prototype.getSize = function(){
	return this.size;
}
com.qn.io.File.prototype.close = function(){
	return true;
}
com.qn.io.File.prototype.getPathSeparator = function(){
	return "/";
}
com.qn.io.File.prototype.createNewFile = function(){
	var __this = this;
	this.GetDataSet().OpenURL  = com.qn.io.File.prototype.OPEN_URL+ "?datasource=" +"tomos.filesystem.File.createNewFile";
	this.__Action = 0;//new
	this.BuildPathParams();
	this.GetDataSet().Open();
	return this.ReturnValue;
}

com.qn.io.File.prototype.exists = function(){
	var __this = this;
	var dataset = this.GetDataSet();
	dataset.OpenURL  = com.qn.io.File.prototype.OPEN_URL+ "?datasource=" +"tomos.filesystem.File.exists";
	dataset.Close();
	dataset.Fields.Clear();
	dataset.Params.Clear();
	var param1 = new js.db.Param("path", this.GetPath(), "String");
	dataset.Params.Add(param1);
	dataset.OnAfterOpen = function(msg){
		if(msg=="true")
			__this.ReturnValue = true;
		else
			__this.ReturnValue = false;
		if(__this.Onload) __this.Onload(__this.ReturnValue);
	}
	this.GetDataSet().Open();
	return this.ReturnValue;
}

com.qn.io.File.prototype.type = 0;
com.qn.io.File.prototype.getType = function(){
	return this.Type;
}
com.qn.io.File.prototype.getTypeName = function(){
	var name = "unknown";
	if(this.Type==0) name = props("File") 
	else if(this.Type==1) name = props("Folder"); 
	else if(this.Type==2) name = props("DirShortcut"); 
	else if(this.Type==3) name = props("FileShortcut"); 
	else if(this.Type==4) name = props("Share"); 
	else if(this.Type==5) name = props("File"); 
	else if(this.Type==6) name = props("Folder"); 
	else if(this.Type==19) name = props("Group Share"); 
	else if(this.Type==20) name = props("My Groups"); 
	else if(this.Type==21) name = props("Group"); 
	else if(this.Type==22) name = props("Member"); 
	else if(this.Type==22) name = props("Manager"); 
	else if(this.Type==24) name = props("Creator"); 
	else if(this.Type==11) name = props("My Friends"); 
	else if(this.Type==12) name = props("Category"); 
	else if(this.Type==13) name = props("Friend"); 

	return name;
}


com.qn.io.File.prototype.isDirectory = function(){
	return this.type==1;
}

com.qn.io.File.prototype.isFile = function(){
	return this.type==0;
}

com.qn.io.File.prototype.isShortUrl = function(){
	return this.type==80;
}

com.qn.io.File.prototype.isShareFile = function(){
	return this.type==5;
}

com.qn.io.File.prototype.isShareDirectory = function(){
	return this.type==6;
}

com.qn.io.File.prototype.isFileShortcut = function(){
	return this.type==3;
}

com.qn.io.File.prototype.isDirShortcut = function(){
	var idx = -1;
	var target = this.getTarget();
	if(target)
		idx = target.indexOf("http:");
	return this.type==2 && idx==-1;
}

com.qn.io.File.prototype.isShare= function(){
	return this.type==4;
}

com.qn.io.File.prototype.isHidden = function(){
	return true;
}
com.qn.io.File.prototype.lastModified = 0;

com.qn.io.File.prototype.getLastModified = function(){
	return this.lastModified;
}


com.qn.io.File.prototype.sort = function(files, attrname, ascend, datatype){
	if(files){
		var	sortfunc;
		if(datatype=="NUMBER")
			sortfunc = new Function("m, n", "if(!isNaN(n['"+attrname+"'])&&!isNaN(n['"+attrname+"'])) return n['"+attrname+"']-m['"+attrname+"'];" + "if(n['"+attrname+"']<m['"+attrname+"'])return -1;else if(n['"+attrname+"']>=m['"+attrname+"']) return 1; return 0;");
		else
			sortfunc = new Function("m, n", "if(n['"+attrname+"']<m['"+attrname+"'])return -1;else if(n['"+attrname+"']>=m['"+attrname+"']) return 1; return 0;");
		files.sort(sortfunc);
		if(!ascend)
			files.reverse();
	}
}

com.qn.io.File.prototype.mkdirs = function(){
	return true;
}
com.qn.io.File.prototype.setLastModified = function(langtime){
	this.lastModified = langtime;
	return true;
}
com.qn.io.File.prototype.setReadOnly = function(readonly){
	return true;
}
com.qn.io.File.prototype.getCondensationName = function (type){ //get Condensation name
	var filename =  this.GetDisplayName();
	if(type==0||type==5){
		filename = filename.substring(0,filename.lastIndexOf("."))+".rar";
		if(filename.length >14)
			filename = filename.substring(0,10)+"...";
	}else{
		filename = filename+".rar";
	}
	return filename;
}

com.qn.io.File.prototype.getExtName = function(filename){
	if(!filename) return;
	var ext = null;
	var pos = filename.lastIndexOf(".");
	if(pos!=-1)
		ext = filename.substring(pos+1);
	return ext;
}
com.qn.io.File.prototype.getFrontName = function(filename){
	var fnt = null;
	var pos = filename.lastIndexOf(".");
	if(pos!=-1)
		fnt = filename.substring(0, pos);
	else
		fnt = filename;
	return fnt;
}

com.qn.io.File.prototype.getBigIcon = function(){
	if(com.qn.io.File.prototype.isImageFile(this.getFilename()))
		return this.read();
	else
		return this.getIcon(this.bigIcon, com.qn.io.File.SYSBIGICON);
}

com.qn.io.File.prototype.getSmallIcon = function(){
	return this.getIcon(this.smallIcon, com.qn.io.File.SYSSMALLICON);
}

com.qn.io.File.prototype.getIcon = function(defIcon, sysIconList){
	var imagesrc;
	if(defIcon)
		imagesrc = defIcon;
	else{
		if(this.isFile() || this.isFileShortcut() || this.isShareFile()){
/*			var app = Browser.Registry.GetFileProgram(this.GetTarget());
			if(app)
				imagesrc = app.BigIcon;
			else*/
				imagesrc = sysIconList.file;
		}
		else if(this.isDirShortcut()||this.isDirectory() || this.isShareDirectory()){
			imagesrc = sysIconList.folder;
		}
		else if(this.isShortUrl()){
			imagesrc = sysIconList.link;
		}
		else if(this.isShare()){
			imagesrc = sysIconList.share;
		}

	}
	if(imagesrc)
		if(imagesrc.indexOf("http:")==-1 && imagesrc.substring(0, 1)!="/")
			imagesrc = imagePath + imagesrc;
	return imagesrc;
}

com.qn.io.File.prototype.getTypeIcon = function(){
	if(this.bigIcon || this.smallIcon) return null;
	if(this.isShareFile() || this.isShareDirectory())
		return imagePath + com.qn.io.File.SYSTYPEICON.share;
	if(this.isFileShortcut() || this.isDirShortcut())
		return imagePath + com.qn.io.File.SYSTYPEICON.shortcut;
}

com.qn.io.File.SYSSMALLICON = {"file": "file/file48.png", "folder": "file/folder.png", "share": "file/share48.png", "link": "file/link.png"};
com.qn.io.File.SYSBIGICON = {"file": "file/file48.png", "folder": "file/folder.png", "share": "file/share48.png"};
com.qn.io.File.SYSTYPEICON = {"share": "file/share.png", "shortcut": "file/shortcut.png"};

com.qn.io.File.prototype.isImageFile = function(filename){
   var exname = com.qn.io.File.prototype.getExtName(filename);
   if(exname)
	  exname = exname.toLowerCase();
   return (exname=="jpg" || exname=="png" || exname=="jpeg" || exname=="bmp" || exname=="gif");
}
