<%@ Language=VBScript %>
<%
selectedserverid=0'默认首选的服务器ID
isagentpd=False
If session("agentusername")<>"" Then Response.Redirect "/agent/admvps2.asp?username="&session("agentusername")&"&id="&Request.QueryString ("id")
If session("username")="" Then
If Application("hpsystem")=false  And Application("canuseorder")=true and Request.ServerVariables("HTTP_FreeHostAPI")<>"7i24.com" Then Response.Redirect "order.asp?type=云服务器产品&id="&Request.QueryString ("id")
	ef=True
	ec="请您先登陆会员区。"
ElseIf Request.QueryString ("id")="" Then
	ef=True
	ec="请选择产品！"
ElseIf Instr(1, Request.QueryString ("id"), "'", 1)>0 then
	ef=True
	ec="非法产品ID！"
ElseIf not IsNumeric(Request.QueryString ("id"))  Then
	ef=True
	ec="产品ID应该是数字！"
end if
if not ef then
Set conn=Server.CreateObject("ADODB.Connection")
	conn.Open Application("FreeHostDBlink")
	Set dsHost = Server.CreateObject("ADODB.Recordset")

agentname=session("agentname")
if session("AgnRunasUser")=True then 
	Set dsagent = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Agent where username='"&agentname&"'"
		dsagent.Open Sql,conn,1,1
if Not dsagent.eof then
Set dsagnettype = Server.CreateObject("ADODB.Recordset")	
Sql="Select * from FreeHost.FreeHost_Agent_pers where agenttype='"&dsagent("agenttype")&"'" 
		dsagnettype.Open Sql,conn,1,1
if Not dsagnettype.eof Then
canshowagnpric=True
Else
canshowagnpric=false
End if
end If
dsagent.close
end If

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

'弹性部分1
if not ef then
if dshost("cancloud")=true then
	ef=True
	ec="弹性购买产品请用另一个购买界面"
end if
end If

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

if not ef then
%>
<!--#include virtual="/inc-freehost-function/htmlwrite.asp"--><%=htmlwrite("html2")%>
　云服务器自助开通
<%=htmlwrite("html3")%>
<br>
<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;
			<%If isagentpd=false Then%>
			var url = "/api/checkvpsname.asp?";
			<%else%>
			var url = "/api/checkvpsname.asp?isagentpd=yes&pdid=<%=dsHost("id")%>&";			
			<%end if%>						
			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>
<form action="selfvps2.asp" method="post" name="autoopen">
  <table 
            width="600" border=1 align=left cellpadding=0 cellspacing=0 bordercolorlight=#cccccc bordercolordark=#fbfbfb>
    <tbody>
      <tr>
        <td width="18%" height="40" valign=middle bgcolor=#9E9E9E>&nbsp; <font color="#FFFFFF">填写资料：</font></td>
        <td width="34%" bgcolor=#ffffff>　产品名：        </td>
        <td width="48%" bgcolor=#ffffff>　<%=VPStype%>
</td>
      </tr>
      <tr>
        <td width="18%" rowspan="5" valign=middle bgcolor=#EEEEEE>&nbsp;</td>
        <td width="34%" height="40" bgcolor=#ffffff><font color="#000000">　云服务器自命名：</font>
          <input name="vpsname" type="text" id="vpsname" size="10" maxlength="14" onBlur=checkusername(this.value) onFocus=Iusername()></td>
        <td width="48%" bgcolor=#ffffff>
          <div id="divusername">　</div>
</td>
      </tr>
      <tr>
        <td height="50" bgcolor=#ffffff><font color="#000000">　云服务器　密码：</font>
          <input name="VPSpassword" type="password" id="VPSpassword" size="10" maxlength="14"></td>
        <td width="48%" height="50" bgcolor=#ffffff>(3至14个字母或数字)</td>
      </tr>
      <tr>
        <td height="50" bgcolor=#ffffff><font color="#000000">　有效期限：</font></td>
        <td height="50" bgcolor=#ffffff><select name="year"  onChange="chusrm(this.options[this.options.selectedIndex].value)">
            <option value="0" selected>请您选择</option>
            <%if dsHost("cantest")="y" then%>
            <option value="999">试用<%if Application("VPStestHour")>0 then%><%=Application("VPStestHour")%>小时<%else%><%=Application("testtime")%>天<%end if%></option>
            <%end if%>
            <%if dsHost("canday")="y" then%>
            <option value="<%=PAY_DAY%>">一天</option>
            <%end if%>
            <%if dsHost("canweek")="y" then%>
            <option value="<%=PAY_WEEK%>">一周</option>
            <%end if%>
			<%if dsHost("canmonth")="y" then%>
            <option value="<%=PAY_Month%>">一个月</option>
            <%end if%>
            <%if dsHost("canseason")="y" then%>
            <option value="<%=PAY_Season%>">三个月</option>
            <%end if%>
            <%if dsHost("canhalfyear")="y" then%>
            <option value="<%=PAY_halfyear%>">半年</option>
            <%end if%>
            <option value="1">一年</option>
            <option value="<%=PAY_2year%>">两年</option>
            <option value="<%=PAY_3year%>">三年</option>
            <option value="<%=PAY_4year%>">四年</option>
            <option value="<%=PAY_5year%>">五年</option>
          </select>
            <input type="hidden" name="id" value="<%=Request.QueryString ("id")%>">
            <%
usermoney=dsHost("usermoney")
if agentname<>"n" then
	Set dsendmoney = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Agent_user_price where prtype='云服务器产品' and username='"&agentname&"' and id="&dsHost("id")&""
		dsendmoney.Open Sql,conn,1,1
if not dsendmoney.eof then
usermoney=dsendmoney("usermoney")
end if
dsendmoney.close
end If

if canshowagnpric then%>
  　　 <font color=red>(代理成本价格
  <%
	Set dsagnpri = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_Agent_price where prtype='云服务器产品' and username='"&agentname&"' and id="&dsHost("id")&""
		dsagnpri.Open Sql,conn,1,1
if dsagnpri.eof then
usermoney=dsHost("usermoney")*dsagnettype("pers")
else
usermoney=dsagnpri("usermoney")
end if
dsagnpri.close
%>
  )</font>
  <%End if%>
  <%
If canshowagnpric And isAgnHostSer then%>
  (<font color=red>当前此产品为独立模式产品</font>)
  <%
usermoney=0
End if%>
  <input name="moneynow" type="text" value="" size="7" readonly="true" style="BORDER-RIGHT: 0px; BORDER-TOP: 0px; BORDER-LEFT: 0px; BORDER-BOTTOM: 0px" ></td>
      </tr>
      <%if isAgnHostSer=False And isagentpd=false then%>
      <tr>
        <td height="50" bgcolor=#ffffff>　请选择机房：</td>
        <td height="50" bgcolor=#ffffff><%
	Set dsX = Server.CreateObject("ADODB.Recordset")	
		Sql="Select * from FreeHost.FreeHost_ServerVPSlist where agent1='n' order by orderbyid desc"
if isAgnHostSer then Sql="Select * from FreeHost.FreeHost_ServerVPSlist where agent1='"&agentname&"' order by orderbyid desc"
		dsX.Open Sql,conn,1,1
If dsX.Eof Then%>
        默认机房
          <%else%>
          <select name="ServerlistID" id="ServerlistID">
            <%while not dsX.Eof%>
            <%if dsHost("ServerlistID")=dsX("id") or dsHost("ServerlistID2")=dsX("id") or dsHost("ServerlistID3")=dsX("id") or dsHost("ServerlistID4")=dsX("id") or dsHost("ServerlistID5")=dsX("id") then%>
            <option value="<%=dsX("id")%>" <%if dsX("id")=selectedserverid then%>selected<%end if%>><%=dsX("netby")%></option>
            <%end if%>
            <%
dsX.movenext
wend%>
          </select>
          <%end if%>
        </td>
      </tr>
      <%end if%>
      <tr>
        <td height="40" colspan="2" bgcolor=#ffffff>　
            <input name="openX" type="submit" value="马上实时开通" onClick="document.autoopen.openX.value ='请等待不要重复刷新！....';document.autoopen.openX.disabled=true;document.autoopen.submit()"></td>
      </tr>
    </tbody>
  </table>
  <p><br>
  </p>
</form>
<script language="JavaScript" type="text/JavaScript">
//document.openX.moneynow.value=<%=usermoney%>;
function chusrm(s)
{

	document.all.moneynow.value=Math.round((s*<%=usermoney%>))+' 元';

	if (s==999)
	{
	document.all.moneynow.value='0'+' 元';
	
	}
}
</script>
<%=htmlwrite("html4")%>
<%end if
if ef then
Response.Redirect "e.asp?e="&ec
end if%>
