<%
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>Add Certificate</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:3px;}
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:22px;
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{
padding-left:14px;
background:url("images/button_left.gif") no-repeat 0 0;
}
button em{
font-style:normal;padding-right:14px;
background:url("images/button.gif") no-repeat 100% 0;
}
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_cert':	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 bits = $("bits").value;
	var country = encodeURIComponent($("country").value);
	var state = encodeURIComponent($("state").value);
	var locality = encodeURIComponent($("locality").value);
	var organization = encodeURIComponent($("organization").value);
	var unit = encodeURIComponent($("unit").value);
	var certName = encodeURIComponent($("certName").value);
	var email = encodeURIComponent($("email").value);
	var password = encodeURIComponent($("password").value);
	if(filename.length == 0 || filepath.length == 0 || bits.length == 0 || country.length == 0 || state.length == 0 || locality.length == 0 || organization.length == 0 || unit.length == 0 || certName.length == 0 || email.length == 0)
	{
		alert("<%=LANG['str_field_empty']%>");
		return false;
	}
	if(filename.search(/[\\\/\<\>\:\?\"\'\|]/i) != -1)
	{
		alert("<%=LANG['str_invalid_certname']%>");
		return false;
	}
	paramStr = "filename="+filename+"&filepath="+filepath+"&bits="+bits+"&country="+country+"&state="+state+"&locality="+locality+"&organization="+organization+"&unit="+unit+"&certName="+certName+"&email="+email+"&password="+password+"&r="+Math.random();
	ajaxRequest("admin_create_cert",paramStr);
}

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

<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>
<td><%=LANG["str_cert_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_keysize"]%>:</td>
<td><select id="bits"><option value="1024">1024 bits</option><option value="2048" selected>2048 bits</option><option value="4096">4096 bits</option></select></td>
</tr>
<tr>
<td><%=LANG["str_countrycode"]%>:</td>
<td><input id="country" type="text" style="width:80px;" maxlength="2"></td>
</tr>
<tr>
<td><%=LANG["str_fullstate"]%>:</td>
<td><input id="state" type="text" style="width:240px;"></td>
</tr>
<tr>
<td><%=LANG["str_locality"]%>:</td>
<td><input id="locality" type="text" style="width:240px;"></td>
</tr>
<tr>
<td><%=LANG["str_organization"]%>:</td>
<td><input id="organization" type="text" style="width:240px;"></td>
</tr>
<tr>
<td><%=LANG["str_orgunit"]%>:</td>
<td><input id="unit" type="text" style="width:240px;"></td>
</tr>
<tr>
<td><%=LANG["str_serveraddr"]%>:</td>
<td><input id="certName" type="text" style="width:240px;"></td>
</tr>
<tr>
<td><%=LANG["str_contactmail"]%>:</td>
<td><input id="email" type="text" style="width:240px;"></td>
</tr>
<tr>
<td><%=LANG["str_password2"]%>:</td>
<td><input id="password" type="password" style="width:240px;"></td>
</tr>
<tr><td colspan="2" align="center" height="55">
<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 
%>