<!--#include file="setup.asp"-->
<!--#include file="pet_config.asp"-->
<!--#include file="pet_conn.asp"-->
<%
top
if Request.Cookies("username")=empty then error("<li>您还未<a href=login.asp>登录</a>论坛")



    dim money,smoney,saveday,allmoney,time1,time2,daikuang,dkdu,daiday,sucmsg
    dim Form_userphoto,Form_FaceUrl,Form_FaceWidth,Form_FaceHeight
    
    Dim rs_pet,sql_pet

	set rs_pet=conn.execute("select money from [user] where username='"&Request.Cookies("username")&"'")
      	
    money=rs_pet("money")

	    

    rs_pet.close
    


            
dim action,petsp,pettoday,newexp,levelpic,thispetsex
if request("action") = "" then
    action = "adopt"
    else
    action = lcase(request("action"))
end if

select case action
    case "delpet"

 sql_pet = "SELECT * FROM mypetdata WHERE username='"&Request.Cookies("username")&"'"
    rs_pet.open sql_pet,conn_pet,1,3
    if rs_pet.eof then
        error("你还没有宠物啊，<a href=petshop.asp>快攒钱去买吧~</a>")
        else


        
        if rs_pet("mypetdead") <> 0 then 
                message="<li>宠物收容所不接受死亡的宠物，先复活它吧~"
				succeed(message&"<meta http-equiv=refresh content=3;url='petmypet.asp'")
            else

                petsp=DEF_PET_basicsp
                pettoday = now()
        
                newexp=rs_pet("mypetexp")-int(rs_pet("mypetexp")*20/100)
                conn_pet.ExeCute("INSERT INTO petdeldata (username, mypet,mypetname,mypetlevel,mypetexp,mypetmaxhp,mypetatk,mypetdef,mypetsex,mypetsx,petdeldate)VALUES ('"&Request.Cookies("username")&"', '"& rs_pet("mypet") &"', '"& rs_pet("mypetname") &"', '"& rs_pet("mypetlevel") &"', '"& newexp &"','"& rs_pet("mypetmaxhp") &"', '"& rs_pet("mypetatk") &"', '"& rs_pet("mypetdef") &"', '"& rs_pet("mypetsex") &"', '"& rs_pet("mypetsx") &"', '"& pettoday &"')")
                conn_pet.ExeCute("DELETE FROM mypetdata WHERE username='"&Request.Cookies("username")&"'")
                message="<li>丢弃完了，宠物已经放在宠物收容所了"
				succeed(message&"<meta http-equiv=refresh content=3;url='petorphanage.asp'")
            
        end if

    end if
    rs_pet.close

    case "alldelpet"

    sql_pet = "SELECT * FROM mypetdata WHERE username='"&Request.Cookies("username")&"'"
    rs_pet.open sql_pet,conn_pet,1,3
    if rs_pet.eof then
            message="<li>你还没有宠物啊，<a href=petshop.asp>快攒钱去买吧~</a>"
        else

        conn_pet.ExeCute("DELETE FROM mypetdata WHERE username='"&Request.Cookies("username")&"'")
        message="<li>丢弃完了，宠物已经去天堂了，你好狠心啊"
		succeed(message&"<meta http-equiv=refresh content=3;url='petorphanage.asp'")

    end if
    rs_pet.close

    case "adoptpet"
        
    sql_pet = "SELECT * FROM mypetdata WHERE username='"&Request.Cookies("username")&"'"
    rs_pet.open sql_pet,conn_pet,1,3
    if not rs_pet.eof then
            message="<li>你已经有一个宠物了，做人不要三心两意啊~"
			succeed(message&"<meta http-equiv=refresh content=3;url='petorphanage.asp'")
        else
        
        petsp=DEF_PET_basicsp
        pettoday = now()

        dim petid,mypet
        petid = request.querystring("petid")
        if petid = "" then petid = 0 end if

        sql_pet = "SELECT * FROM petdeldata WHERE id="&petid
        'response.write sql_pet: response.end
        set rs_petpet = conn_pet.ExeCute(sql_pet)
        if rs_petpet.eof then
                message="<li>你没有成功领养宠物，你要领养的宠物不存在~"
				succeed(message&"<meta http-equiv=refresh content=3;url='petorphanage.asp'")
            else
                mypet = rs_petpet("mypet")
                conn_pet.ExeCute("INSERT INTO mypetdata (username, mypet,mypetname,mypetlevel,mypetexp,mypethp,mypetmaxhp,mypetsp,mypetatk,mypetdef,mypetdead,mypetsex,mypetsx,petregdate,hpitem,spitem,expitem)VALUES ('"&Request.Cookies("username")&"', '"& rs_petpet("mypet") &"', '"& rs_petpet("mypetname") &"', '"& rs_petpet("mypetlevel") &"', '"& rs_petpet("mypetexp") &"', '"& rs_petpet("mypetmaxhp") &"', '"& rs_petpet("mypetmaxhp") &"', '"& petsp &"', '"& rs_petpet("mypetatk") &"', '"& rs_petpet("mypetdef") &"', '0', '"& rs_petpet("mypetsex") &"', '"& rs_petpet("mypetsx") &"', '"& pettoday &"', '0', '0', '0')")
                conn_pet.ExeCute("DELETE FROM petdeldata WHERE id="&petid)
                message="<li>你领养了 "& mypet &" 好好照顾他啊"
				succeed(message&"<meta http-equiv=refresh content=3;url='petorphanage.asp'") 
        end if
        rs_petpet.close

    end if
    rs_pet.close
    
end select


%>
<title>宠物孤儿院</title>
<table border=0 width=<%=dkuan%> align=center cellspacing=1 cellpadding=4 class=a2>
<tr class=a3>
<td height=25>&nbsp;<img src=images/Forum_nav.gif>&nbsp; <%ClubTree%> → 
<a href="petcenter.asp">宠物中心</a> → 宠物孤儿院</td>
</tr>
</table><br>
   
    
<table width="<%=dkuan%>" border="0" align=center cellspacing="0" cellpadding="0">
              <tr> 
                <td width="28%"> <div align="right"> 
                    <table width="90%"  border="0" align="center" cellpadding="3" cellspacing="3">
                      <tr> 
                        <td><div align="center"></div>
<!-- #include file=petnav.asp --></td>
                      </tr>
                    </table>
                    <table height=100%><tr><td></td></tr></table>
                  </div></td>
                <td> <div align="center"> </div>
                  <div align="center"></div>
                  <%if action = "adopt" then%>
                    <TABLE class=text1 cellSpacing=1 cellPadding=3 width=98% align=center border=0>
                      <TR> 
                        <TD colspan="5"> <DIV align=center> 
                            <table width="100%" border="0" align="center" cellpadding="3" cellspacing="1" class=a2>
                              <tr class=a3> 
                                <td width="28%"><div align="center">宠物照片</div></td>
                                <td width="24%"><div align="center">宠物介绍</div></td>
                                <td width="33%"> 
                                  <div align="center">收养宠物</div>
                                  </td>
                              </tr>
<%
sql_pet = "SELECT top 10 * FROM petdeldata ORDER BY mypetlevel DESC"
set rs_petpet = conn_pet.ExeCute(sql_pet)
dim num
num = 0
while not rs_petpet.eof and num < 10
            
levelpic=int(rs_petpet("mypetlevel")/10)
if (levelpic>10) then levelpic=11 end if
if (rs_petpet("mypetsex")=1) then
    thispetsex="雄"
else 
    thispetsex="雌"
end if
%>
<tr class=a3><td width='28%'><div align='center'><IMG src='images/pet/<%=rs_petpet("mypetname")%>/<%=rs_petpet("mypetname")%><%=levelpic%>.gif'></div></td>
<td width='24%'>宠物名字：<%=rs_petpet("mypet")%><br>宠物级别：<%=rs_petpet("mypetlevel")%><br>宠物攻击力：<%=rs_petpet("mypetatk")%><br>宠物防御力：<%=rs_petpet("mypetdef")%><br>宠物性别：<%=thispetsex%><br>宠物前主人：<a href="dispuser.asp?name=<%=rs_petpet("username")%>"><%=rs_petpet("username")%></a></div></td>
<td width='10%'><div align='center'>
<input name='Submit2' type='button' value='领养宠物' onclick="javascript:window.location='petorphanage.asp?action=adoptpet&petid=<%=rs_petpet("id")%>';">
</div></td>
</tr>
<%
rs_petpet.movenext
num = num + 1
wend
rs_petpet.close
%>                               
                            </table>
                          </DIV>
                          </TD>
                      </TR>

                    </TABLE>
                  <%end if%>
                  <%if action = "del" then%>
                  <form action=petorphanage.asp name="name" mtehod=post>
                    <TABLE class=text1 cellSpacing=0 cellPadding=0 width=100% align=center border=0>
                      <TR> 
                        <TD width="57%"> <DIV align=center><img src="images/pet/30.gif"></DIV></TD>
                      </TR>
                      <TR> 
                        <TD><div align="center"><br>
                            <a href="petorphanage.asp?action=delpet">放进孤儿院</a> 
                            <a href="petorphanage.asp?action=alldelpet">彻底丢弃</a></div></TD>
                      </TR>
                    </TABLE>
                  </form>
                  <%end if%>
                  <table height=100%><tr><td></td></tr></table>
                </td>
              </tr>
            </table><%
htmlend
%>
