<%
include("language.html")
%>
<noscript><center><H2><%=LANG["error_nojavascript"]%></H2></center></noscript>
<%
if _SESSION["logined"] ~= nil then
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Create Key</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="css/style.css" rel="stylesheet" type="text/css" />
<style type="text/css">
html, body {height: 100%;}
a {text-decoration:none;}
a,a:visited {color:#000;background:inherit;}
img {border:0px;}
<%if _COOKIE["admin_lang"] == "schinese" or _COOKIE["admin_lang"] == "tchinese" or _COOKIE["admin_lang"] == "japanese" then%>
body,td,span {margin:0;padding:0;font:12px/20px Verdana, Geneva, Arial, Helvetica, sans-serif;}
<%else%>
body,td,span {margin:0;padding:0;font:11px/20px Verdana, Geneva, Arial, Helvetica, sans-serif;}
<%end%>
input,select,textarea{margin:4px;}
input,textarea{background-color:expression((this.disabled && this.disabled==true)?"#D4D0C8":"")}
td{line-height:24px;padding:2px;padding-left:10px;}

button{
border:none;background:none;padding:0;
margin:0;width:auto;overflow:visible;text-align:center;
white-space:nowrap;height:24px;line-height:24px;
cursor:pointer;
color:#000;
margin-left:2px;
margin-top:2px;
}
button span, button em{
display:block;height:24px;line-height:22px;margin:0;
}	
button span{
font-size:8pt;
padding-left:12px;
background:url("images/button_left.gif") no-repeat 0 0;
}
<%if _COOKIE["admin_lang"] == "schinese" or _COOKIE["admin_lang"] == "tchinese" or _COOKIE["admin_lang"] == "japanese" then%>
button em{
font-style:normal;padding-right:14px;
background:url("images/button.gif") no-repeat 101% 0;
}
<%else%>
button em{
font-style:normal;padding-right:10px;
background:url("images/button.gif") no-repeat 100% 0;
}
<%end%>
button:hover{
filter:alpha(opacity=60);
opacity:0.60;
color:#5488C9;
}
button span:hover{
filter:alpha(opacity=60);
opacity:0.60;
color:#5488C9;
}
.buttonhover{
filter:alpha(opacity=60);
opacity:0.60;
color:#5488C9;
}

</style>

<script language="javascript" src="include/common.js"></script>
<script language="javascript">
var ajaxlock = false;
var xmlhttp,page,post;
xmlhttp = isIE ? new ActiveXObject('Microsoft.XMLHTTP'):new XMLHttpRequest();

function ajaxRequest(pagename,poststring,method)
{
	if(ajaxlock == false)
	{	
		delete xmlhttp;
		xmlhttp = isIE ? new ActiveXObject('Microsoft.XMLHTTP'):new XMLHttpRequest();

		ajaxlock = true;
		page = pagename;
		post = poststring;

		if(method == "GET")
			xmlhttp.open("GET",page+".html"+post);
		else
			xmlhttp.open("POST",page+".html");

		xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		xmlhttp.onreadystatechange = ajaxResponse;
		if(method != "GET")
			xmlhttp.send(post);
		else
			xmlhttp.send("");
		$("waitingdiv").style.display = "";
	}
}

function ajaxResponse()
{
	ajaxlock = false;
	$("waitingdiv").style.display = "none";
	if (xmlhttp.readyState == 4)
	{
		if (xmlhttp.status == 200)
		{
			try
			{
				switch(page)
				{
					case 'admin_create_key':	doSubmit_result();break;
				}
			}
			catch(e)
			{
				alert("<%=LANG['error_ajax']%>");
			}
		}
		else
		{
			alert("<%=LANG['error_ajax']%>");
		}
	}
}


function chooseDirectory()
{
	showMessagebox("<%=LANG['str_choosedir']%>","<iframe src='admin_dir_selector.html' width=580 height=500 border=0 frameborder=0></iframe>",callback_return,580,500);
}

function callback_return(value)
{
	if(value != null)
		$("filepath").value = value;
	$("filename").focus();
}

function doSubmit()
{
	var paramStr = "";
	var filename = encodeURIComponent($("filename").value);
	var filepath = encodeURIComponent($("filepath").value);
	var password = encodeURIComponent($("password").value);
	if(filename.length == 0 || filepath.length == 0)
	{
		alert("<%=LANG['str_field_empty']%>");
		return false;
	}
	if(filename.search(/[\\\/\<\>\:\?\"\'\|]/i) != -1)
	{
		alert("<%=LANG['str_invalid_keyname']%>");
		return false;
	}
	//if(password.search(/[\\\/\<\>\:\?\"\'\|]/i) != -1)
	//{
	//	alert("<%=LANG['str_invalid_pass']%>");
	//	return false;
	//}
	paramStr = "filename="+filename+"&filepath="+filepath+"&password="+password+"&r="+Math.random();
	ajaxRequest("admin_create_key",paramStr);
}

function doSubmit_result()
{
	var result = xmlhttp.responseText;
	if(result == "0" || result == 0)
	{
		alert("<%=LANG['str_createkey_fail']%>");
	}
	else
	{
		top.closewindow($("filename").value+"||"+$("filepath").value+"||"+$("password").value);
	}
}
</script>
<html>
<body leftmargin="20" topmargin="10" marginwidth="0" marginheight="0" style="background-color:#E6E6E6;">

<div id="waitingdiv" style="position:absolute; z-index:100; 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:20%; width:250px; height:100px;"><img src="images/loading2.gif" border="0">
<H2><b><%=LANG["title_updating"]%></b></H2></div></div>

<table cellSpacing="0" cellPadding="0" border="0" width="100%">
<tr>
<tr><td colspan="2" align="center" height="20"> 
</td></tr>
<tr>
<td><%=LANG["str_key_name"]%>:</td>
<td><input id="filename" type="text" style="width:240px;"></td>
</tr>
<tr>
<td><%=LANG["str_outputdir"]%>:</td>
<td><input id="filepath" type="text" style="width:170px;"><button onclick='chooseDirectory();'><span><em><%=LANG["button_choose"]%></em></span></button></td>
</tr>
<tr>
<td><%=LANG["str_keypassword"]%>:</td>
<td><input id="password" type="password" style="width:240px;"></td>
</tr>
<tr>
<tr><td colspan="2" align="center" height="20"> 
</td></tr>
<tr>
<tr><td colspan="2" align="center" height="40">
<button type='submit' onclick='doSubmit();'><span><em><%=LANG["button_submit"]%></em></span></button>&nbsp;
<button onclick='top.closewindow();'><span><em><%=LANG["button_cancel"]%></em></span></button>
</td></tr>
</table>

<script type="text/javascript">
$("filename").focus();

</script>
</body>
</html>

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