<%
include("language.html")
if _SESSION["username"] ~= nil and _SESSION["currentpath"] ~= nil then
%>
<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="cache-control" content="no-cache, must-revalidate" />
<link rel="stylesheet" href="css/bulma.min.css" type="text/css">
<link rel="stylesheet" href="css/allfonts.min.css" type="text/css">
<link rel="stylesheet" href="css/style.css?v=3" type="text/css" />
<head>
<title>Search Files</title>
</head>
<script language="javascript" src="include/common.js?v=8"></script>
<script language="javascript">
var EXPTag = "session expired";
var now_dir = "/";
var selectedRow = null;
var lastObj = null;
var searching = false;
var searchfor = "";
var searchin = "";
var download_url = "";
var searchStack = new Array();
var deletelock = false;
var enable_online_edit = "<%=c_CanOnlineEdit()%>";


function ajaxResponse()
{
	if (xmlhttp.readyState == 4)
	{
		ajaxlock = false;
		if (xmlhttp.status == 200)
		{
			try
			{
				switch(page)
				{
					case 'searchdir':		showlist();break;
					case 'rmfile':			rmfile();break;
					case 'checkdownload':	checkdownload_Result();break;
					case 'weblink':			weblink();break;
					case 'weblink_update':	weblink_update_result();break;
				}
			}
			catch(e)
			{
					//alert("<%=LANG['error_ajax']%>");
			}
			finally
			{
				//$("waitingdiv").style.display = "none";

				$("weblinkDiv_mask2").style.display = "none";
			}
		}
		else
		{
			//$("waitingdiv").style.display = "none";
			//alert("<%=LANG['error_ajax']%>");

		}
	}

	if(page == "rmfile")
	{
		deletelock = false;
	}
}

function sess_expire()
{
	alert("<%=LANG['session_expire']%>");
	top.window.location = "login.html";
}

function showlist()
{
	//$("waitingdiv").style.display = "";
	try
	{
		var result = trim(xmlhttp.responseText);
		if(result == EXPTag)
		{
			sess_expire();
			return;
		}

		var xmldoc = xmlhttp.responseXML;
		var row = xmldoc.getElementsByTagName("rowdata");
		var rownum = row.length;
		var tr = null;
		selectedRow = null;
		now_dir = xmlFieldValue(xmldoc,"nowdir");

		for(var i=0; i < rownum; i++)
		{
			try
			{
				var myrow = row[i];
				f_img = "";
				f_size = xmlFieldValue(myrow,"size");
				f_name = decodeURIComponent(xmlFieldValue(myrow,"name"));
				f_dir = xmlFieldValue(myrow,"dir");

				if(f_dir != 1)
				{
					var matched = false;
					var filename = f_name.toLowerCase();
					if(searchfor.indexOf("*") != -1)
					{
						matched = true;
						var strArray = searchfor.split("*");
						for(var k=0;k<strArray.length;k++)
						{
							if(trim(strArray[k]) != "" && filename.indexOf(strArray[k]) == -1)
							{
								matched = false;
								break;
							}
						}
					}
					else
					{
						if(filename.indexOf(searchfor) != -1)
							matched = true;
					}
					if(matched == true)
					{
						tr = document.createElement("tr");
						$("maintable").appendChild(tr); 

						if(isIE)
						{
							tr.onclick = function()
							{
								do_list_click(this,-1);
							}
							tr.oncontextmenu = function()
							{
								do_list_click(this,-1,1);
							}
							tr.ondblclick = function()
							{
								do_list_dblclick(this,-1);
							}
						}
						else
						{
							tr.setAttribute('onclick','do_list_click(this,-1);');
							tr.setAttribute('oncontextmenu','do_list_click(this,-1,1);');
						}
						tr.setAttribute('class','listtr01');
						tr.setAttribute('className','listtr01');
						
						var tmpcell = document.createElement("td"); 
						var tmpcell2 = document.createElement("td"); 
						var tmpcell3 = document.createElement("td");
						tmpcell.setAttribute('id',"tr_"+i);
						tmpcell.setAttribute('class','paddingtd');
						tmpcell.setAttribute('className','paddingtd');
						tmpcell.setAttribute('name',htmlencode(f_name));
						tmpcell.setAttribute('path',htmlencode(now_dir));
						tmpcell.setAttribute('fsize',f_size);
						tmpcell.innerHTML = htmlencode(f_name);
						tr.appendChild(tmpcell); 
						//tmpcell2.innerHTML = htmlencode(now_dir);
						tmpcell2.innerHTML = htmlencode(now_dir.substr(0,38)+(now_dir.length > 38 ? "...":""));
						tmpcell2.setAttribute('title',htmlencode(now_dir));
						tmpcell2.setAttribute('class','paddingtd');
						tmpcell2.setAttribute('className','paddingtd');
						tr.appendChild(tmpcell2);
					}
				}
				else
				{
					searchStack.push(now_dir+"/"+f_name);
				}
				
				lastsortcol = -1;
				
			}
			catch(e){}
		}
	}
	catch(e)
	{
		stopSearch();
		//$("waitingdiv").style.display = "none";
		var result = trim(xmlhttp.responseText);
		if(result == EXPTag)
		{
			sess_expire();
			return;
		}
	}

	//$("waitingdiv").style.display = "none";
	if(lastArrow != null)
		lastArrow.style.backgroundImage="";

	if(searchStack == null || searchStack.length <= 0)
	{
		stopSearch();
		return;
	}
	
	var reqdir = searchStack.pop();
	if(reqdir != null && reqdir != "")
	{
		ajaxRequest("searchdir","searchin="+urlEncode(reqdir)+"&r="+Math.random());
		$("searchin").value = htmlencode(reqdir);
	}
}


function do_list_click(obj, cellindex, rightmouse)
{
	var row_index = 0;

	if(cellindex >= 0)
		row_index = cellindex;
	else if(cellindex == -2)
		row_index = row_filenum*obj.parentNode.rowIndex+obj.cellIndex;
	else
		row_index = obj.rowIndex-1;

	if(rightmouse == 1)
	{
		if(deletelock == false && searching == false)
		{
			var evt = getEvent();
			$("menu_div").style.visibility = ""; 
			if(evt.clientY > 380)
				$("menu_div").style.top = evt.clientY - 100;
			else
				$("menu_div").style.top = evt.clientY - 30;
			
			if(evt.clientX > 520)
				$("menu_div").style.left = evt.clientX - 150;
			else
				$("menu_div").style.left = evt.clientX;
		}
	}

	if(selectedRow != $("maintable").rows[row_index])
	{
		if(lastObj != null)
			lastObj.className = "listtr01";
		selectedRow = $("maintable").rows[row_index];
		obj.className = "listtr02";
		lastObj = obj;
	}
	else
	{
		if(rightmouse == 1)
			return false;
		if(!isIE)
		{
			downloadFile();
			if(lastObj != null)
			{
				lastObj.className = "listtr01";
				lastObj = null;
			}
			selectedRow = null;		
		}
	}

	return false;
}

function do_list_dblclick(obj,cellindex)
{
	var row_index = 0;
	if(cellindex >= 0)
		row_index = cellindex;
	else if(cellindex == -2)
		row_index = row_filenum*obj.parentNode.rowIndex+obj.cellIndex;
	else
		row_index = obj.rowIndex-1;
	selectedRow = $("maintable").rows[row_index];
	downloadFile();
	return false;
}

function closeEditor()
{
	try
	{
		var iframeWindow = $("texteditor").contentWindow;
		var bResult = iframeWindow.do_exitQuery();
		return bResult;
	}
	catch(e)
	{
	}

	return true;
}

function checkvideo() 
{
    return !!document.createElement('video').canPlayType;
}

function checkaudio() 
{
    return !!document.createElement('audio').canPlayType;
}

function checkFilePermission(url)
{
	var xmlhttpObj = isIE ? new ActiveXObject('Microsoft.XMLHTTP'):new XMLHttpRequest();
	xmlhttpObj.open("GET",url,false);
	xmlhttpObj.send("");

	var result = trim(xmlhttpObj.responseText);
	if(result == EXPTag)
	{
		sess_expire();
		return false;
	}
	else if(result != "")
	{
		alert(result);
		return false;
	}
	else
	{
		return true;
	}
}

function downloadFile_ext()
{
	if(selectedRow == null)
	{
		alert("<%=LANG['error_nofile']%>");
		return;
	}

	if(selectedRow.cells[1].innerHTML != "<%=LANG['list_directory']%>")
	{
		var f_name = selectedRow.cells[0].getAttribute("name");
		var filename = urlEncodeSpecial(htmldecode(f_name));
		var f_path = selectedRow.cells[0].getAttribute("path");
		var pathname = urlEncodeSpecial(htmldecode(f_path));
		var filesize = selectedRow.cells[0].getAttribute("fsize");
		download_url = "/?download&filename="+filename+"&nowpath="+pathname+"&r="+Math.random();
		if(isIE)
			checkDownload("checkdownload.html?filename="+filename+"&filesize="+filesize+"&r="+Math.random());
		else
			ajaxRequest("checkdownload","filename="+filename+"&filesize="+filesize+"&r="+Math.random());
	}
}

function downloadFile()
{
	if(selectedRow == null)
	{
		alert("<%=LANG['error_nofile']%>");
		return;
	}

	if(selectedRow.cells[1].innerHTML != "<%=LANG['list_directory']%>")
	{
		var f_name = selectedRow.cells[0].getAttribute("name");
		var filename = urlEncodeSpecial(htmldecode(f_name));
		var f_name2 = htmldecode(f_name);
		var f_ext = getExtention(f_name2);
		var f_path = selectedRow.cells[0].getAttribute("path");
		var pathname = urlEncodeSpecial(htmldecode(f_path));
		var filesize = selectedRow.cells[0].getAttribute("fsize");
		var checkfileURL = "checkdownload.html?filename="+filename+"&nowpath="+pathname+"&filesize="+filesize+"&r="+Math.random();

		if((isIphone || isWindowsPhone || isAndroid) && window.screen.width < 1024)
		{
			download_url = "/?download&filename="+filename+"&nowpath="+pathname+"&r="+Math.random();
			if(isIE)
				checkDownload("checkdownload.html?filename="+filename+"&filesize="+filesize+"&r="+Math.random());
			else
				ajaxRequest("checkdownload","filename="+filename+"&filesize="+filesize+"&r="+Math.random());

			return;
		}

		if(!isIE && f_ext == "pdf")
		{
			if(checkFilePermission(checkfileURL) )
			{
				var frametag = new Date().getTime();
				var pdf_url = encodeURIComponent("/?download&filename="+filename+"&nowpath="+pathname+"&r="+Math.random());
				showMessagebox("<span title='"+htmlencode(f_name)+"'>"+htmlencode(f_name.substr(0,75))+(f_name.length > 75 ? "...":"")+"</span>","<iframe src='/pdfjs-dist/web/viewer.html?file="+pdf_url+"' width=1024 height=680 border=0 frameborder=0 id='modify"+frametag+"'></iframe>", null, 1024, 680);
			}
		}
		else if(checkvideo() && (f_ext == "mp4" || f_ext == "mov") )
		{
			if(checkFilePermission(checkfileURL) )
			{
				var frametag = new Date().getTime();
				showMessagebox("<span title='"+htmlencode(f_name)+"'>"+htmlencode(f_name.substr(0,75))+(f_name.length > 75 ? "...":"")+"</span>","<iframe src='videoplayer.html?dir="+pathname+"&filename="+filename+"&width=1000&height=600&r="+Math.random()+"' width=1024 height=620 border=0 frameborder=0 id='modify"+frametag+"'></iframe>", null, 1024, 620);
			}
		}
		else if(checkaudio() && (f_ext == "mp3" || f_ext == "m4a" || f_ext == "ogg" || f_ext == "wav") )
		{
			if(checkFilePermission(checkfileURL) )
			{
				var frametag = new Date().getTime();
				showMessagebox("<span title='"+htmlencode(f_name)+"'>"+htmlencode(f_name.substr(0,45))+(f_name.length > 45 ? "...":"")+"</span>","<iframe src='audioplayer.html?dir="+pathname+"&filename="+filename+"&r="+Math.random()+"' width=620 height=320 border=0 frameborder=0 id='modify"+frametag+"'></iframe>", null, 620, 320);
			}
		}
		else if(enable_online_edit == "1" && (f_ext == "txt" || f_ext == "cpp" || f_ext == "c" || f_ext == "h" || f_ext == "hpp" || f_ext == "lua" || f_ext == "sh"  || f_ext == "java"  || f_ext == "xml" || f_ext == "html" || f_ext == "htm" || f_ext == "js" || f_ext == "css" || f_ext == "php" || f_ext == "jsp" || f_ext == "asp" || f_ext == "pl" || f_ext == "py" || f_ext == "sql" || f_ext == "vb" || f_ext == "rb" || f_ext == "go" || f_ext == "pas" || f_ext == "json" || f_ext == "cs" || f_ext == "resx" || f_ext == "cxx" || f_ext == "pm" || f_ext == "vbs") )
		{
			if(checkFilePermission(checkfileURL) )
			{
				var frametag = new Date().getTime();
				showMessagebox("<span title='"+htmlencode(f_name)+"'>"+htmlencode(f_name.substr(0,75))+(f_name.length > 75 ? "...":"")+"</span>","<iframe src='editor.html?dir="+pathname+"&filename="+filename+"&r="+Math.random()+"' width=1024 height=680 border=0 frameborder=0 id='texteditor'></iframe>",closeEditor,1024,680);
			}
		}
		else if(f_ext == "doc" || f_ext == "docx" || f_ext == "xls" || f_ext == "xlsx" || f_ext == "ppt" || f_ext == "pptx" || f_ext == "docm" || f_ext == "dot" || f_ext == "dotx" || f_ext == "pptm" || f_ext == "pot" || f_ext == "potx" || f_ext == "xlsm" || f_ext == "xlt" || f_ext == "xltx")
		{
			if(checkFilePermission(checkfileURL) )
			{
				window.open("/empty.html?download&filename="+filename+"&nowpath="+pathname+"&r="+Math.random()+"/"+f_name2, "_blank");
			}
		}
		else
		{
			download_url = "/?download&filename="+filename+"&nowpath="+pathname+"&r="+Math.random();
			if(isIE)
				checkDownload("checkdownload.html?filename="+filename+"&filesize="+filesize+"&r="+Math.random());
			else
				ajaxRequest("checkdownload","filename="+filename+"&filesize="+filesize+"&r="+Math.random());
		}
	}
}

function checkDownload(url)
{
	var xmlhttpObj = isIE ? new ActiveXObject('Microsoft.XMLHTTP'):new XMLHttpRequest();
	xmlhttpObj.open("GET",url,false);
	xmlhttpObj.send("");

	var result = xmlhttpObj.responseText;
	if(result == EXPTag)
	{
		sess_expire();
	}
	else if(result != "")
	{
		alert(result);
	}
	else
	{
		top.window.open(download_url,"_self"); 
	}
}

function checkdownload_Result()
{
	var result = trim(xmlhttp.responseText);
	if(result == EXPTag)
	{
		sess_expire();
	}
	else if(result != "")
	{
		alert(result);
	}
	else
	{
		top.window.open(download_url,"_self"); 
	}
}

function deleteFile()
{
	if(selectedRow == null)
	{
		alert("<%=LANG['error_nofile']%>");
		return;
	}

	var f_name = selectedRow.cells[0].getAttribute("name");
	var filename = urlEncode(htmldecode(f_name));
	var f_path = selectedRow.cells[0].getAttribute("path");
	var pathname = urlEncode(htmldecode(f_path));
	if(confirm("<%=LANG['delete_confirm']%> "+f_name+" ?\r\n") )
	{
		ajaxRequest("rmfile","nowpath="+pathname+"&nowfile="+filename);
		deletelock = true;
	}
}

function rmfile()
{
	var result = trim(xmlhttp.responseText);
	if(result == EXPTag)
	{
		sess_expire();
		return;
	}
	else if(result == "1")
	{
		try
		{
			selectedRow.parentNode.removeChild(selectedRow);
			top.ajaxRequest("dir",'r='+Math.random());
		}
		catch(e){}
	}
	else
	{
		alert(result);
	}
	deletelock = false;
}

function editFile()
{
	if(selectedRow == null)
	{
		alert("<%=LANG['error_nofile']%>");
		return;
	}

	if(selectedRow.cells[1].innerHTML == "<%=LANG['list_directory']%>")
	{
		alert("<%=LANG['error_edit']%>");
		return;
	}
	else
	{
		var f_name = selectedRow.cells[0].getAttribute("name");
		var filename = urlEncode(htmldecode(f_name));
		var f_path = selectedRow.cells[0].getAttribute("path");
		var pathname = urlEncode(htmldecode(f_path));
		var frametag = new Date().getTime();

		if(isIphone || isWindowsPhone || isAndroid)
		{
			showMessagebox("<span title='"+htmlencode(f_name)+"'>"+htmlencode(f_name).substr(0,24)+(f_name.length > 24 ? "...":"")+"</span>","<iframe src='editor.html?dir="+pathname+"&filename="+filename+"&r="+Math.random()+"' width=370 height=380 border=0 frameborder=0 id='texteditor'></iframe>",closeEditor,370,380);
		}
		else
		{
			showMessagebox("<span title='"+htmlencode(f_name)+"'>"+htmlencode(f_name).substr(0,55)+(f_name.length > 55 ? "...":"")+"</span>","<iframe src='editor.html?dir="+pathname+"&filename="+filename+"&r="+Math.random()+"' width=1024 height=680 border=0 frameborder=0 id='modify"+frametag+"'></iframe>",closeEditor,1024,680);
		}
	}
}

function openFolder()
{
	if(selectedRow == null)
	{
		alert("<%=LANG['error_nofile']%>");
		return;
	}

	var f_path = selectedRow.cells[0].getAttribute("path");
	var pathname = urlEncode(htmldecode(f_path));

	top.ajaxRequest("chdir","dir="+pathname);
	top.closewindow();
}

function selectTime()
{
	var strMyDate = "";
	var strMyTime = "";

	var timevalue = top.$("expiretime").value;
	if(timevalue != "")
	{
		var timeArray = timevalue.split(" ");
		strMyDate = timeArray[0];
		strMyTime = timeArray[1];
	}
	var frametag = new Date().getTime();
	showMessagebox("<%=LANG['str_selecttime']%>","<iframe src='select_time.html?mydate="+strMyDate+"&mytime="+strMyTime+"&seeds=" + Math.random() +"' width=280 height=285 border=0 frameborder=0 id='modify"+frametag+"'></iframe>",selectTime_callback,280,285);
}

function selectTime_callback(str)
{
	if(str != "" && str != null)
		top.$("expiretime").value = str;
}

function formatLimitNumber(numbervalue)
{
	top.$("downloadlimit").value = numbervalue.replace(/\D/g,'');
}

function clearTime()
{
	top.$("expiretime").value = "";
}

function CopyWeblink()
{
	if(window.clipboardData)
	{
		window.clipboardData.setData("Text", $("weblink_text").value);
	}
	else
	{
		try
		{
			if(isFirefox || (isSafari && !isChrome))
			{
				$("ffcopy").value = $("weblink_text").value;
				$("ffcopy").select();
				$("ffcopy").setSelectionRange(0, $("ffcopy").value.length);
				document.execCommand("copy");
				$("ffcopy").value = "";
			}
			else
			{
				var copy = function (e) {
					e.preventDefault();
					if(e.clipboardData)
						e.clipboardData.setData("text/plain", $("weblink_text").value);
				}
				window.addEventListener("copy", copy);
				document.execCommand("copy");
				window.removeEventListener("copy", copy);
			}
		}
		catch(e){}
	}
}

function showDownloadUrl()
{
	if(selectedRow == null)
	{
		alert("<%=LANG['error_edit']%>");
		return;
	}

	if(selectedRow.cells[1].innerHTML != "<%=LANG['list_directory']%>")
	{
		$("weblinkDiv_mask").style.display = "";
		var f_name = htmldecode(selectedRow.cells[0].getAttribute("name"));
		var f_path = htmldecode(selectedRow.cells[0].getAttribute("path"));
		var windowWidth = 530;
		var textareaWidth = 460;
		var inputWidth = 320;

		if(isIphone || isWindowsPhone || isAndroid)
		{
			windowWidth = 390;
			textareaWidth = 330;
			inputWidth = 220;
		}

		showMessagebox("<%=LANG['weblink_title']%>","<table width='100%' border='0' cellpadding='2' cellspacing='3'><tr><td style='padding-left:10px;padding-top:15px;' colspan=2><input type='checkbox' id='enable_weblink' onclick='top.window.frames[1].clickWeblink();' tabindex='34'> <b><%=LANG['enable_weblink']%></b></td></tr><tr><td style='padding-left:10px;' colspan=2><textarea id='weblink_text' style='width:"+textareaWidth+"px;height:85px;word-break:break-all;' spellcheck='false' disabled tabindex='35'> </textarea><button id='btn_copylink' onclick='CopyWeblink();' class='button is-small' style='margin-left:2px;padding:3px;'  title='<%=LANG['item_copy']%>' disabled><img src='images/copy.png'></button></td></tr><tr><td style='padding-left:10px;width:140px;'><%=LANG['str_expire_on']%>:</td><td><input id='expiretime' type='text' value='' disabled onclick='selectTime();' style='width:150px;' readonly tabindex='36'> <img src='images/clean.gif' align='absmiddle' id='btn_clear_date' onclick='clearTime();' title='Clean' style='border: 1px solid #666; padding:1px; cursor:pointer; vertical-align:middle;' tabindex='37'> <%=LANG['str_optional']%></td></tr><tr><td style='padding-left:10px; width:110px;'><%=LANG['password']%></td><td><input id='downloadpass' type='text' maxlength='30' value='' disabled style='width:150px;' tabindex='39'> <img src='images/password.gif' onclick='generateRandom();' title='<%=LANG['str_generate_pass']%>' style='border: 1px solid #666; padding:1px; cursor:pointer; vertical-align:middle;'>  <%=LANG['str_optional']%></td></tr><tr><td style='padding-left:10px; width:110px;'><%=LANG['str_download_limit']%>:</td><td><input id='downloadlimit' type='text' maxlength='6' value='' disabled onkeyup='formatLimitNumber(this.value);' onafterpaste='formatLimitNumber(this.value);' style='width:150px;' tabindex='38'> 1-999999 <%=LANG['str_optional']%></td></tr><tr><td style='padding-left:6px;'><input type='checkbox' id='enable_sendmail' tabindex='40' onclick='enableSendMail();' value='1' disabled> <%=LANG['str_sendmail']%>:</td><td><input id='mail_address' type='text' maxlength='100' tabindex='41' onblur=\"if(this.value=='') this.value='<%=LANG['str_multiple_emails']%>'\" onclick=\"if(this.value =='<%=LANG['str_multiple_emails']%>' ) this.value=''\" value='<%=LANG['str_multiple_emails']%>' style='width:"+inputWidth+"px;color:#898989;' disabled></td></tr><tr><td style='padding-left:30px;'><%=LANG['str_senderemail']%>:</td><td><input id='sender_mail_address' type='text' maxlength='80' tabindex='42' style='width:180px; color:#898989;' disabled> <%=LANG['str_optional']%></td></tr><tr><td style='padding-left:30px;'><%=LANG['str_field_message']%> <%=LANG['str_optional']%>:</td><td><textarea id='mail_message' style='width:"+inputWidth+"px;height:35px' maxlength='300' tabindex='43' disabled></textarea> </td></tr><tr><td colspan=2 height=20></td></tr><tr align='center'><td colspan=2><button id='btn_submit' type='submit' onclick='top.window.frames[1].update_weblink();' tabindex='44' class='button is-info is-small'><%=LANG['create_submit']%></button>&nbsp;&nbsp;&nbsp;<button id='btn_cancel' onclick='top.closewindow();' tabindex='45' class='button is-small'><%=LANG['create_cancel']%></button></td></tr></table>", top.window.frames[1].closeWindow, windowWidth, 400);

		top.$("enable_weblink").focus();

		ajaxRequest("weblink","operation=get&filename="+urlEncode(f_name)+"&nowdir="+urlEncode(f_path) );

		if(isIE)
		{
			top.$("enable_weblink").onclick = function(){clickWeblink();};
			top.$("expiretime").onclick = function(){selectTime();};
			top.$("btn_clear_date").onclick = function(){clearTime();};
			top.$("btn_submit").onclick = function(){update_weblink();};
			top.$("btn_cancel").onclick = function(){top.closewindow();};
		}
	}
	else
	{
		alert("<%=LANG['error_edit']%>");
	}
}

function closeWindow()
{
	$("weblinkDiv_mask").style.display = "none";
}

function enableSendMail()
{
	if(top.$("enable_sendmail").checked)
	{
	<% if enable_sendmessage == true then %>
		top.$("mail_address").disabled = false;
		top.$("sender_mail_address").disabled = false;
		top.$("mail_message").disabled = false;
	<% else %>
		alert("<%=LANG['str_no_smtpconfig']%>");
	<% end %>
	}
	else
	{
		top.$("mail_address").disabled = true;
		top.$("sender_mail_address").disabled = true;
		top.$("mail_message").disabled = true;
	}
}

function update_weblink()
{
	var f_name = htmldecode(selectedRow.cells[0].getAttribute("name"));
	var f_path = htmldecode(selectedRow.cells[0].getAttribute("path"));
	var expiretime = htmldecode(top.$("expiretime").value);
	var downloadlimit = htmldecode(top.$("downloadlimit").value);
	var downloadpass = htmldecode(top.$("downloadpass").value);
	var sendmail = (top.$("enable_sendmail").checked ? "yes":"");

	var mailaddress = htmldecode(top.$("mail_address").value);
	var sender_mailaddress = htmldecode(top.$("sender_mail_address").value);
	var mail_message = htmldecode(top.$("mail_message").value);
	var localaddress = location.protocol + "//" + location.host + "/";
	var hostname = location.hostname;

	if(top.$("enable_weblink").checked)
	{
		ajaxRequest("weblink_update","filename="+urlEncode(f_name)+"&nowdir="+urlEncode(f_path)+"&sendmail="+sendmail+"&mailaddress="+urlEncode(mailaddress)+"&sender_mailaddress="+urlEncode(sender_mailaddress)+"&mail_message="+urlEncode(mail_message)+"&hostname="+urlEncode(hostname)+"&localaddress="+urlEncode(localaddress)+"&expiretime="+urlEncode(expiretime)+"&downloadlimit="+urlEncode(downloadlimit)+"&downloadpass="+urlEncode(downloadpass)+"&r="+Math.random());

		$("weblinkDiv_mask2").style.display = "";
	}
	top.closewindow();
}

function weblink_update_result()
{
	var result = xmlhttp.responseText;
	if(trim(result) == "Error: sending email")
	{
		alert("<%=LANG['send_email_error']%>");
	}
	else if(trim(result) == "Error: no permission")
	{
		alert("<%=LANG['make_weblink_error']%>");
	}
	else if(trim(result) == "operation successful")
	{
		alert("<%=RESULT_STR[1]%>");
	}

	$("weblinkDiv_mask2").style.display = "none";
}

function clickWeblink()
{
	var f_name = htmldecode(selectedRow.cells[0].getAttribute("name"));
	var f_path = htmldecode(selectedRow.cells[0].getAttribute("path"));

	if(top.$("enable_weblink").checked)
	{
		ajaxRequest("weblink","operation=add&filename="+urlEncode(f_name)+"&nowdir="+urlEncode(f_path) );
	}
	else
	{
		ajaxRequest("weblink","operation=del&filename="+urlEncode(f_name)+"&nowdir="+urlEncode(f_path) );
	}
}

function weblink()
{
	var result = xmlhttp.responseText;
	try
	{
		if(trim(result) == "")
		{
		}
		else if(trim(result) == "noperm")
		{
			alert("<%=LANG['make_weblink_error']%>");

			top.$("enable_weblink").checked = false;
			top.$("weblink_text").value = "";
			top.$("weblink_text").disabled = true;
			top.$("btn_copylink").disabled = true;
			top.$("expiretime").disabled = true;
			top.$("downloadlimit").disabled = true;
			top.$("downloadpass").disabled = true;
			top.$("enable_sendmail").disabled = true;
			top.$("mail_address").disabled = true;
			top.$("mail_message").disabled = true;
		}
		else if(trim(result) == "banned")
		{
			alert("<%=RESULT_STR[-3]%>");

			top.$("enable_weblink").checked = false;
			top.$("weblink_text").value = "";
			top.$("weblink_text").disabled = true;
			top.$("btn_copylink").disabled = true;
			top.$("expiretime").disabled = true;
			top.$("downloadlimit").disabled = true;
			top.$("downloadpass").disabled = true;
			top.$("enable_sendmail").disabled = true;
			top.$("mail_address").disabled = true;
			top.$("mail_message").disabled = true;
		}
		else if(trim(result) == "deleted")
		{
			top.$("enable_weblink").checked = false;
			top.$("weblink_text").value = "";
			top.$("weblink_text").disabled = true;
			top.$("btn_copylink").disabled = true;
			top.$("expiretime").disabled = true;
			top.$("downloadlimit").disabled = true;
			top.$("downloadpass").disabled = true;
			top.$("enable_sendmail").disabled = true;
			top.$("mail_address").disabled = true;
			top.$("mail_message").disabled = true;
		}
		else
		{
			var f_name = htmldecode(selectedRow.cells[0].getAttribute("name"));
			var filename = urlEncodeSpecial(f_name);

			top.$("enable_weblink").checked = true;
			top.$("weblink_text").disabled = false;
			top.$("btn_copylink").disabled = false;
			top.$("expiretime").disabled = false;
			top.$("downloadlimit").disabled = false;
			top.$("downloadpass").disabled = false;
			top.$("enable_sendmail").disabled = false;
			//top.$("mail_address").disabled = false;

			var localaddress = location.href.replace(/\#/g,"");

			var strWebLink = trim(result);
			if(result.indexOf("\r\n") != -1)
			{
				var resultArray = result.split("\r\n");
				strWebLink = resultArray[0];
				if(resultArray[1] >= 0)
					top.$("downloadlimit").value = resultArray[1];
				else
					top.$("downloadlimit").value = "";

				if(resultArray[2] >= 0)
					top.$("expiretime").value = translateTime(resultArray[2]);
				else
					top.$("expiretime").value = "";

				if(resultArray[3] != null && resultArray[3] != "")
					top.$("downloadpass").value = resultArray[3];
				else
					top.$("downloadpass").value = "";

			}

			top.$("downloadlimit").style.color = "#000000";
			top.$("expiretime").style.color = "#000000";

			if(top.$("downloadlimit").value == "0")
				top.$("downloadlimit").style.color = "#FF0000";

			if(top.$("expiretime").value != "")
			{
				if(compareDate(top.$("expiretime").value) == true)
					top.$("expiretime").style.color = "#FF0000";
			}
			top.$("weblink_text").value = localaddress + "?download&weblink="+strWebLink+"&realfilename="+filename;
		}
	}
	catch(e){}
}

function startSearch()
{
	if(trim($("searchfor").value) == "")
	{
		alert("<%=LANG['str_search_tip']%>");
		$("searchfor").focus();
		return;
	}
	searching = true;
	searchfor = htmldecode($("searchfor").value.toLowerCase());
	searchin = htmldecode($("searchin").value);
	$("btn_start").disabled = true;
	$("btn_stop").disabled = false;
	searchStack = null;
	searchStack = new Array();
	if(isIE)
		RemoveRow("maintable");
	else
		clear("maintable");
	ajaxRequest("searchdir","searchin="+urlEncode(searchin)+"&begin=1&searchfor="+urlEncode(searchfor)+"&r="+Math.random());
	$("searchdiv").style.display = "";
}


function menuMouseOver(obj)
{
	obj.style.color="#FFFFFF";
	obj.style.backgroundColor="#1665CB";
	obj.style.cursor="pointer"; 
}

function menuMouseOut(obj)
{
	obj.style.backgroundColor="#FFFFFF";
	obj.style.color="#000000";
}


function stopSearch()
{
	searching = false;
	$("btn_start").disabled = false;
	$("btn_stop").disabled = true;
	$("searchin").value = htmlencode(searchin);
	searchStack = null;
	$("searchdiv").style.display = "none";
}

top.cancelTimerCallback = function()
{
	stopSearch();
}
</script>
</head>
<body style="margin:0px;padding:5px;">


<div id="weblinkDiv_mask" style="position:absolute; z-index:1000; top:0px; left:0px; width:100%; height:100%; background:#777; filter:alpha(opacity=60); opacity:0.60; display:none;" align="center">
</div>

<div id="weblinkDiv_mask2" style="position:absolute; z-index:1000; top:0px; left:0px; width:100%; height:100%; background:#777; filter:alpha(opacity=60); opacity:0.60; display:none;" align="center">
<div style="position:absolute; top:20%; left:40%; width:300px; height:100px;"><img src="images/loading2.gif" border="0">
<H2><b><%=LANG["update_tip"]%></b></H2></div></div>

<div id="menu_div" style="position:absolute; visibility:hidden; background-color:#FFF; width:178px;" onclick="return false;">
	<div class="menu_out">
	<div class="menu_in">
    <li style="margin-top:6px;" onmouseover="menuMouseOver(this)" onmouseout="menuMouseOut(this)" onclick="downloadFile_ext();">
		<span class="icon"><i class="fas fa-download"></i></span>&nbsp;&nbsp;<%=LANG["item_download"]%>
	</li>
    <li style="margin-top:6px;" onmouseover="menuMouseOver(this)" onmouseout="menuMouseOut(this)" onclick="deleteFile();">
		<span class="icon"><i class="fas fa-trash"></i></span>&nbsp;&nbsp;<%=LANG["item_delete"]%>
	</li>
	<li style="margin-top:6px;" onmouseover="menuMouseOver(this)" onmouseout="menuMouseOut(this)" onclick="showDownloadUrl();">
		<span class="icon"><i class="fas fa-link"></i></span>&nbsp;&nbsp;<%=LANG["item_geturl"]%>
	</li>
	<li style="margin-top:6px;" onmouseover="menuMouseOver(this)" onmouseout="menuMouseOut(this)" onclick="editFile();">
		<span class="icon"><i class="fas fa-edit"></i></span>&nbsp;&nbsp;<%=LANG["item_edit"]%></li>
	</li>
	<li style="margin-top:6px;" onmouseover="menuMouseOver(this)" onmouseout="menuMouseOut(this)" onclick="openFolder();">
		<span class="icon"><i class="far fa-folder-open"></i></span>&nbsp;&nbsp;<%=LANG["item_openfolder"]%></li>
	</li>
	</div>
	</div>
</div>


<div style="width:100%; padding-top:2px; overflow-x:hidden;">
<table width="100%" border="0" cellpadding="3" cellspacing="2">
<tr>
<td style="vertical-align:middle;" width="20%"><%=LANG["str_searchfor"]%>:</td>
<td style="vertical-align:middle;"><input type="text" id="searchfor" style="width:60%" autocomplete="off">&nbsp;&nbsp;<%=LANG["str_searchfor_tip"]%></td>
<td align="left"><button id="btn_start" onclick="startSearch();" style="width:90px;" class='button is-info is-small'><%=LANG["str_search"]%></button></td>
</tr>
<tr>
<td colspan=3 height=3></td>
</tr>
<tr>
<td style="vertical-align:middle;"><%=LANG["str_searchin"]%>:</td>
<td style="vertical-align:middle;"><input type="text" id="searchin" style="width:92%" value="<%=specialhtml_encode(_GET["searchin"])%>"></td>
<td align="left"><button id="btn_stop" onclick="stopSearch();" style="width:90px;" disabled class='button is-small'><%=LANG["str_app_stop"]%></button></td>
</tr>
</table>
</div>

<div style="width:100%; padding-top:5px; overflow-x:hidden;">
<table id="listhead" width="100%" border="0" cellpadding="0" cellspacing="0" style="table-layout:fixed;">
<tr>
<td width="55%" align="center" onmouseover="className='listhead2';" onmouseout="className='listhead';" class="listhead" onmousedown="sortTable(this,'listtable', 0, 'listname');"><%=LANG["thread_name"]%></td>
<td width="45%" align="center" onmouseover="className='listhead2';" onmouseout="className='listhead';" class="listhead" onmousedown="sortTable(this,'listtable', 1);"><%=LANG["goto_path"]%></td>
</tr>
</table>
</div>

<div id="listview_div" style="width:100%; height: 350px; overflow:auto; overflow-x:hidden; border:1px solid #999; border-top:0px; background-color:#FFF;">
<table id="listtable" width="100%" border="0" cellpadding="0" cellspacing="0" style="table-layout:fixed;">
<thead><tr height="0">
<td width="55%"></td>
<td width="45%"></td>
</tr></thead>
<tbody id="maintable"></tbody>
</table>
</div>

<div id="searchdiv" style="display:none;">
<%=LANG["str_searching"]%> <img src="images/loading3.gif" border="0" align="absmiddle">
</div>

<div id="waitingdiv" style="display:none;">
</div>

<script>
$("searchfor").focus();

document.oncontextmenu=function(){
	var evt = getEvent();
	var element = evt.srcElement || evt.target;
	if((element.tagName =="INPUT" || element.tagName == "TEXTAREA"))
		return true; 
	else
		return false; 
}

document.onclick=function(){
	$("menu_div").style.visibility = "hidden";
	$("menu_div").style.top = 0; 
	$("menu_div").style.left = 0; 
}

if(isOpera)
	document.onkeypress = searchKeyDown;
else
	document.onkeydown = searchKeyDown;


function searchKeyDown(e)
{
	if(!e){	// if IE
		e=event;
	}

	var use = false;
	var opened = false;

	if (V_Key[e.keyCode])
		letter=V_Key[e.keyCode];
	else
		letter=String.fromCharCode(e.keyCode);	
	var low_letter= letter.toLowerCase();

	if(letter == "Tab")
	{
		return false;
	}
}

</script>
<input id="ffcopy" style="position:absolute; left:-100px; outline:none; border:0px; color:rgba(0,0,0,0.0); background-color:transparent;">
</body>
</html>

<% 
else
	print("<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>")
	print("<script>alert('"..LANG["session_expire"].."');top.window.location = 'login.html';</script>")
end 
%>
<noscript><H2><%=LANG["error_nojavascript"]%></H2></noscript>