<%@ Language=VBScript %>
<!--#include virtual="/inc-freehost-function/FreeHostFunctionMain.asp"-->
<%
isagentpd=False
If session("agentusername")="" Then
	ef=True
	ec="授权非法，有可能是超时造成的。"
ElseIf Request("username")=""  or RegExpTest("[^A-Za-z0-9]",Request("username")) Then
	ef=True
	ec="请输入用户名！"
ElseIf Request("id")="" Then
	ef=True
	ec="请选择产品！"
ElseIf not IsNumeric(Request("id"))  Then
	ef=True
	ec="ID应该是数字！"
end if
if not ef then
Set conn=Server.CreateObject("ADODB.Connection")
	conn.Open Application("FreeHostDBlink")
	Set ds = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_USER where  (agent1='"&session("agentusername")&"' or agent2='"&session("agentusername")&"') and username='"&Request("username")&"'"
				if Instr(1,sql, ";", 1)>0 or Instr(1,sql, "--", 1)>0 then
Response.Write "非法字符！"
Response.End
end if
		ds.Open Sql,conn,1,1
if ds.eof then
	ef=True
	ec="用户不存在!"
end if
end if

if not ef then
  Set dsagent = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_AGENT where username='"&ds("agent1")&"'"
		if Instr(1,sql, ";", 1)>0 or Instr(1,sql, "--", 1)>0 then
Response.Write "非法字符！"
Response.End
end if
		dsagent.Open Sql,conn,1,3
If dsagent.Eof Then
		ef=True
		ec="代理会员名不存在或密码出错了！"
end if
end if

if not ef then
	Set dsHostlist = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_vpsProductlist where  id='"&Request("id")&"'"
			if Instr(1,sql, ";", 1)>0 or Instr(1,sql, "--", 1)>0 then
Response.Write "非法字符！"
Response.End
end if
	dsHostlist.Open Sql,conn,1,1
if dsHostlist.Eof then
	ef=True
'	ec="产品不存在！"
else
If dsHostlist ("isagentpd")=True Then isagentpd=true'代理的产品
'读取月付
PAY_DAY=dsHostlist("PAY_DAY")
PAY_WEEK=dsHostlist("PAY_WEEK")
PAY_Month=dsHostlist("PAY_Month")
PAY_Season=dsHostlist("PAY_Season")
PAY_halfyear=dsHostlist("PAY_halfyear")
PAY_Nextyear=dsHostlist("PAY_Nextyear")
PAY_2year=dsHostlist("PAY_2year")
PAY_3year=dsHostlist("PAY_3year")
PAY_4year=dsHostlist("PAY_4year")
PAY_5year=dsHostlist("PAY_5year")

ServerlistID=dsHostlist ("ServerlistID")
if ds("agent1")<>"n" then
	Set agnserverid = Server.CreateObject("ADODB.Recordset")	
	Sql="Select * from FreeHost.FreeHost_vpsProductlist_AGN where id='"&dsHostlist ("id")&"' and agent1='"&ds("agent1")&"'"
	agnserverid.Open Sql,conn,1,1
dim isAgnHostSer
if not agnserverid.Eof then
if agnserverid ("ServerlistID")<>0 then
ServerlistID=agnserverid ("ServerlistID")
isAgnHostSer=true
else
isAgnHostSer=false
end if
end if
end if'isagn

end if
end if

if not ef then
'	vpstype=dsHostlist("vpstype")
	Set newname_vps = Server.CreateObject("ADODB.Recordset")	
Sql="Select * from FreeHost.FreeHost_vpsProductlist_AGN where agent1='"&session("agentusername")&"' and id='"&dsHostlist("id")&"'"
		newname_vps.Open Sql,conn,1,1
if not newname_vps.eof then
info=newname_vps("info")
vpstype=newname_vps("vpstype")
end if
newname_vps.close
end if

'if not ef then
'	Set dsServerlist = Server.CreateObject("ADODB.Recordset")	
	'	Sql="Select * from FreeHost.FreeHost_Servervpslist where id='"&dsHostlist("ServerlistID")&"'"
		'dsServerlist.Open Sql,conn,1,1
'if dsServerlist.Eof then
	'ef=True
	'ec="服务器为空！"
'end if
'end if

if not ef then
	Set dsagnettype = Server.CreateObject("ADODB.Recordset")	
Sql="Select * from FreeHost.FreeHost_Agent_pers where agenttype='"& session("agenttype")&"'"
		dsagnettype.Open Sql,conn,1,1
if dsagnettype.Eof then
	ef=True
	ec="代理类型折扣为空，请先设置它！"
end if
end if


if not ef then

	Set dsagnpri = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Agent_price where prtype='云服务器产品' and username='"&session ("agentusername")&"' and id="&dsHostlist("id")&""
		dsagnpri.Open Sql,conn,1,1
if dsagnpri.eof then
myrealcost=dsHostlist("usermoney")*dsagnettype("pers")
else
myrealcost=dsagnpri("usermoney")
end if
dsagnpri.close

	Set dsendmoney = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Agent_user_price where prtype='云服务器产品' and username='"&session("agentusername")&"' and id="&dsHostlist("id")&""
		dsendmoney.Open Sql,conn,1,1
'		response.write sql
if dsendmoney.eof then
usermoney=dsHostlist("usermoney")
else
usermoney=dsendmoney("usermoney")
end if
dsendmoney.close

myrealcost=Clng(FormatNumber(myrealcost,0,-1,0,0))'四舍五入'2011-8-29
'usermoney=Clng(FormatNumber(usermoney,0,-1,0,0))'四舍五入


%>
<!--#include virtual="/inc-freehost-function/htmlwrite.asp"--><%=htmlwrite("html5")%>
 　开通云服务器
 <%=htmlwrite("html6")%>
<script>
function Createregxml()
{
	try{
		regxml = new ActiveXObject("Microsoft.XMLHTTP");
	}catch(e){
		try{

		regxml = new ActiveXObject("Msxm12.XMLHTTP");
		}catch(E){
		    regxml = false;
		}
	}
	
	if(!regxml && typeof XMLHttpRequest != 'undefined')
	{
	 regxml =new XMLHttpRequest();
	}
	return regxml;
}

function returnI()
{
	if(regxml.readyState == 4)
	{
	    var Data = regxml.responseText;
		if( Data == "ok")
		{
		  var divobj = document.getElementById("divusername");  
		   divobj.innerHTML = "<font color=greed>√</font>可以使用检查通过。";
		}
		else
		{
		   var divobj = document.getElementById("divusername");
		   divobj.style.display = "block";
		   divobj.innerHTML = "<font color=red>×</font>这个云服务器名已经被注册了，请换一个";
		}
	}
}

function checkabc(tempstr)
{
	ptempstr=new String("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
	for(i=0;i<tempstr.length;i++)
	{
		if(ptempstr.indexOf(tempstr.charAt(i))==-1)
		{
			return false;
		}
	}
	
	return true;
}
function checkusername(name)
{
	if (name.length>14 |name.length<3)
	{
	   var divobj = document.getElementById("divusername");
       divobj.innerHTML = "<font color=red>X</font>云服务器名长度需要在3-14之间!";

	}
	else
	{
		if(checkabc(name))
		{
			regxml = Createregxml();
			regxml.onreadystatechange=returnI;
			var url = "/api/checkvpsname.asp?";
			regxml.open("GET",url+"vpsname="+name);
			regxml.send(null);

			 
		}
		else
		{
		   var divobj = document.getElementById("divusername");
		   divobj.innerHTML = "<font color=red>×</font>云服务器名名只能包含数字和字母";
		}
	}
}
function Iusername()
{
		  var divobj = document.getElementById("divusername");
		  divobj.innerHTML = "提醒：3-14个数字和字母。";
}

</script> 
<br>
用户名：<%=ds("username")%> <br>
余额：
<%if trim(lcase(Request("username")))<>trim(lcase(session("agentusername"))) then%>
<%=ds("usermoney")%>
<%else%>
<%=dsagent("usermoney")%>
<%End if%>
元 <br>
电子邮件：<a href=mailto:<%=ds("email")%>><font color="#000000"><%=ds("email")%></font></a> <br>
QQ：<%=ds("qq")%> <br>
中文名：<%=ds("truename")%> <br>
联系地址：<%=ds("address")%> <br>
电话：<%=ds("tel")%> <br>
注册ip：<%=ds("regip")%> <br>
注册时间：<%=ds("regtime")%>
              <form action="admvps3.asp" method="post" name="autoopen">
 <table width="100%"  border="0" cellspacing="1" bgcolor="#000000">
   <tr>
     <td width="9%" height="56" rowspan="2" bgcolor="#FAFAFA"><p><br>
　<br>
　<br>      
     <table 
            width="700" border=1 align=center cellpadding=0 cellspacing=0 bordercolorlight=#cccccc bordercolordark=#fbfbfb>
         <tr>
           <td height="40" align="right" bgcolor=#ffffff>有效期限：</td>
           <td colspan="2" bgcolor=#ffffff><input type="radio" name="year" value="999"  onClick="document.autoopen.usermoney.value =0;" <%if Clng(Request("year"))=999 then%>checked<%end if%>>
试用<%if Application("VPStestHour")>0 then%><%=Application("VPStestHour")%>小时<%else%><%=Application("testtime")%>天<%end if%>
<input type="radio" name="year" value="<%=PAY_DAY%>" onClick="document.autoopen.usermoney.value =Math.round(<%=PAY_DAY*usermoney%>);" <%if Clng(Request("year"))=PAY_DAY then%>checked<%end if%>>
一天
<input type="radio" name="year" value="<%=PAY_WEEK%>" onClick="document.autoopen.usermoney.value =Math.round(<%=PAY_WEEK*usermoney%>);" <%if Clng(Request("year"))=PAY_WEEK then%>checked<%end if%>>
一周
<input type="radio" name="year" value="<%=PAY_Month%>" onClick="document.autoopen.usermoney.value =Math.round(<%=PAY_Month*usermoney%>);" <%if Clng(Request("year"))=PAY_Month then%>checked<%end if%>>
一个月
<input type="radio" name="year" value="<%=PAY_Season%>" onClick="document.autoopen.usermoney.value =Math.round(<%=PAY_Season*usermoney%>);" <%if Clng(Request("year"))=PAY_Season then%>checked<%end if%>>
一季
<input type="radio" name="year" value="<%=PAY_halfyear%>" onClick="document.autoopen.usermoney.value =Math.round(<%=PAY_halfyear*usermoney%>);" <%if Clng(Request("year"))=PAY_halfyear then%>checked<%end if%>>
半年
<input type="radio" name="year" value="1" checked onClick="document.autoopen.usermoney.value =1*<%=usermoney%>;" <%if Clng(Request("year"))=1 then%>checked<%end if%>>
一年
<input type="radio" name="year" value="<%=PAY_2year%>" onClick="document.autoopen.usermoney.value =Math.round(<%=PAY_2year%>*<%=usermoney%>);" <%if Clng(Request("year"))=PAY_2year then%>checked<%end if%>>
两年
<input type="radio" name="year" value="<%=PAY_3year%>" onClick="document.autoopen.usermoney.value =Math.round(<%=PAY_3year%>*<%=usermoney%>);" <%if Clng(Request("year"))=PAY_3year then%>checked<%end if%>>
三年
<input type="radio" name="year" value="<%=PAY_4year%>" onClick="document.autoopen.usermoney.value =Math.round(<%=PAY_4year%>*<%=usermoney%>);" <%if Clng(Request("year"))=PAY_4year then%>checked<%end if%>>
四年
<input type="radio" name="year" value="<%=PAY_5year%>" onClick="document.autoopen.usermoney.value =Math.round(<%=PAY_5year%>*<%=usermoney%>);" <%if Clng(Request("year"))=PAY_5year then%>checked<%end if%>>
五年 </td>
         </tr>
         <tr>
           <td height="40" align="right" bgcolor=#ffffff><input name="id" type="hidden" size="8" value="<%=dsHostlist("id")%>">
    将要开通的产品为：</td>
           <td colspan="2" bgcolor=#ffffff>　<b><%=dsHostlist("vpstype")%>
               <%if vpstype<>"" then%>
(<%=vpstype%>)
<%end if%>
           </b> </td>
         </tr>
         <tr>
           <td height="40" align="right" bgcolor=#ffffff>成本价格：</td>
           <td colspan="2" bgcolor=#ffffff>　<%=myrealcost%> 元/年 我的零售价格:<%=usermoney%> 元 /年</td>
         </tr>
         <tr>
           <td height="40" align="right" bgcolor=#ffffff>　扣款选择：</td>
           <td colspan="2" bgcolor=#ffffff>　
             <%if trim(lcase(Request("username")))<>trim(lcase(session("agentusername"))) then%>
             <input name="chmoney" type="checkbox" id="chmoney" value="y">
             <font color="#FF0000">从用户金额中扣除</font>(不选将以成本价扣除代理自己的钱) 价格：
             <input name="usermoney" type="text" id="usermoney" value="<%=usermoney%>" size="4" maxlength="4">
元<br>
<%else%>
<input name="usermoney" type="hidden" value="0">
<%end if%></td>
         </tr>
<%if isAgnHostSer=false then%>		 
         <tr>
           <td height="40" align="right" bgcolor=#ffffff>
　请选择机房：

　 </td>
           <td colspan="2" bgcolor=#ffffff>　
             <%
	Set dsX = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Servervpslist order by id asc"
		dsX.Open Sql,conn,1,1
If dsX.Eof Then%>
服务器列表为空.
<%else%>
<select name="ServerlistID" id="ServerlistID">
  <%while not dsX.Eof%>
  <%if dsHostlist("ServerlistID")=dsX("id") or dsHostlist("ServerlistID2")=dsX("id") or dsHostlist("ServerlistID3")=dsX("id") or dsHostlist("ServerlistID4")=dsX("id") or dsHostlist("ServerlistID5")=dsX("id") then%>
  <option value="<%=dsX("id")%>"><%=dsX("netby")%></option>
  <%end if%>
  <%
dsX.movenext
wend%>
</select>
<%end if
If Not isagentpd then'不是代理产品时再执行
%>
<input name="installos" type="checkbox" id="installos" value="yes" checked>
开通后马上自动预装操作系统<%end if%></td>
         </tr>
<%end if%>
         <tbody>
           <tr>
             <td width="21%" height="40" align="right" bgcolor=#ffffff>云服务器名：</td>
             <td width="20%" bgcolor=#ffffff>　<input name="vpsname" type="text" id="vpsname" value="<%if Request("vpsname")="" then%><%=ds("username")%><%else%><%=Request("vpsname")%><%end if%>" size="10" maxlength="14" onBlur=checkusername(this.value) onFocus=Iusername()>              </td>
             <td width="59%" bgcolor=#ffffff><%If isagentpd Then%>
               <div id="divusername">(3至14个字母或数字)</div>
               <%else%>
(3至14个字母或数字)
<%End if%></td>
           </tr>
           <tr>
             <td height="40" align="right" bgcolor=#ffffff><%Randomize
id=left(md5(CLng((100000000 - 20 + 7850) * Rnd + 100)&now),8)%>
    云服务器密码：      </td>
             <td colspan="2" bgcolor=#ffffff>　<input name="VPSpassword" type="text" id="VPSpassword" value="<%if Request("VPSpassword")="" then%><%=id%><%else%><%=Request("VPSpassword")%><%end if%>" size="10" maxlength="14">
              (3至14个字母或数字)</td>
           </tr>
           <tr align="center">
             <td height="40" colspan="3" bgcolor=#ffffff><input name="openX" type="submit" value="下一步" onClick="document.autoopen.openX.value ='请等待不要重复刷新！....';document.autoopen.openX.disabled=true;document.autoopen.submit()">
               <input name="username" type="hidden" size="30" value="<%=ds("username")%>"></td> 
            </tr>
         </tbody>
       </table>
<br>
　
<br>
<br>
     </p>
      </td>
   </tr>
 </table>
</form>
<%=htmlwrite("html7")%>
<%end if
if ef then
Response.Redirect "e.asp?e="&ec
end if%>
