<?php
include_once("inc/conn.php");
include_once("inc/function.php");
login_check();

$query=$db->query("Select id from {$web_dbtop}game28 where kj=0 Order by id asc");
if($rs=$db->fetch_array($query)){
	$kgqh=$rs["id"];
}

$query=$db->query("Select id from {$web_dbtop}game28_auto where uid=".intval($_COOKIE["usersid"])." Order by id desc");
if($rs=$db->fetch_array($query)){
	echo "<script language=javascript>location.href='luckautodetail.php';</script>";
	exit;
}

if($_GET["act"] =="autostart"){
	if(!$_POST["tbID"]){
		echo "<script language=javascript>alert('对不起,请先添加投注模式！');location.href='luckmodel.php';</script>";
		exit;
	}
	if($_POST["tbStartNO"]<($kgqh+1)){
		echo "<script language=javascript>alert('对不起,开始期数必须大于当前期数两期！');history.go(-1);</script>";
		exit;
	}
	if($_POST["tbStartNO"]>$_POST["tbEndNO"]){
		echo "<script language=javascript>alert('对不起,结束期数不能小于开始期数！');history.go(-1);</script>";
		exit;
	}
	if(($_POST["tbEndNO"]-$_POST["tbStartNO"])>3000){
		echo "<script language=javascript>alert('对不起,最大总自动投注期数为3000期！');history.go(-1);</script>";
		exit;
	}
	if($_POST["tbMinG"]<0){
		echo "<script language=javascript>alert('对不起,帐户".$web_moneyname."最小值不能小于0！');history.go(-1);</script>";
		exit;
	}
	if($_POST["tbMaxG"]<0){
		echo "<script language=javascript>alert('对不起,帐户".$web_moneyname."最大值不能小于0！');history.go(-1);</script>";
		exit;
	}
	$db->query("INSERT INTO {$web_dbtop}game28_auto (startNO,endNO,minG,maxG,autoid,uid) VALUES (".intval($_POST["tbStartNO"]).",".intval($_POST["tbEndNO"]).",".intval($_POST["tbMinG"]).",".intval($_POST["tbMaxG"]).",".intval($_POST["tbID"]).",".intval($_COOKIE["usersid"]).")");
	for($i = 0; $i < count($_POST["sID"]); $i ++){
		$db->query("update {$web_dbtop}game28_auto_tz set winid=".intval($_POST["sWinModel"][$i]).",lossid=".intval($_POST["sLossModel"][$i])." where id =".intval($_POST["sID"][$i]));
	}
	echo "<script language=javascript>alert('自动投注设置成功！');location.href='luckautodetail.php';</script>";
	exit;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<HTML xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>幸运28-游戏中心-<?=$web_name;?></title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<meta name="keywords" content="<?=$web_keywords;?>" />
<meta name="description" content="<?=$web_description;?>" />
<META http-equiv=X-UA-Compatible content=IE=EmulateIE7>
<link href="style/default.css" rel="stylesheet" type="text/css" />
</head>
<?php include_once("top.php");?>
<script language="javascript">
qiehuan(2);
document.getElementById("qh_con2").getElementsByTagName('li')[0].className="current";
</script>
<DIV class="wrapper">
	<DIV class="page_content">
		<DIV class="webgame-info-title">
		  <UL>
			<LI><A href="luck.php">幸运28首页</A></LI>
			<LI><A href="luckhelp.php">幸运28规则</A></LI>
			<LI><A href="luckmylist.php">我的投注记录</A></LI>
			<LI><A href="luckmodel.php">投注模式编辑</A></LI>
			<LI class="current"><A href="luckautoset.php">自动投注</A></LI>
			<LI><A href="luckdirection.php">幸运28走势图</A></LI>
		  </UL>
		</DIV>
		<DIV class="webgame-info">
			<DIV class="webgame-info-tabs">
			  <table width="940" height="27" border="0" align="center" cellpadding="0" cellspacing="0">
            <tr>
              <td width="12"><img src="images/game2_03.jpg" width="12" height="27" /></td>
              <td background="images/game2_04.jpg" class="font14">自动投注设置:</td>
              <td width="13"><img src="images/game2_06.jpg" width="13" height="27" /></td>
            </tr>
          </table>
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td height="5"></td>
              </tr>
            </table>
			<form action="?act=autostart" method="post" onsubmit="return ChkSetAuto()">
            <table width="940" border="0" align="center" cellpadding="0" cellspacing="0">
              <tr>
                <td bgcolor="#248301"><table width="100%" border="0" align="center" cellpadding="4" cellspacing="1">
                  <tr>
                    <td width="25%" height="28" align="right" bgcolor="#FFFFFF">请选择使用的投注模式：</td>
                    <td bgcolor="#FFFFFF">
                    <select name="tbID">
					<?
					$query=$db->query("Select * from {$web_dbtop}game28_auto_tz where uid=".intval($_COOKIE["usersid"])." Order by tzid asc");
					while($rs=$db->fetch_array($query)){
					?>
					  	<option label="<?=$rs["tzname"]?>" value="<?=$rs["id"]?>"><?=$rs["tzname"]?></option>
					<?
					}
					?>
					</select></td>
                  </tr>
                  <tr>
                    <td height="28" align="right" bgcolor="#FFFFFF">自动投注开始期数：</td>
                    <td bgcolor="#FFFFFF"><input type="text" name="tbStartNO" id="tbStartNO" value="<?=$kgqh+2?>" />开始期数必须大于当前期数（<?=$kgqh+1?>） </td>
                  </tr>
                  <tr>
                    <td height="28" align="right" bgcolor="#FFFFFF">自动投注结束期数：</td>
                    <td bgcolor="#FFFFFF"><input type="text" name="tbEndNO" id="tbEndNO" value="<?=$kgqh+3001?>" />最大总自动投注期数为3000期 </td>
                  </tr>
                  <tr>
                    <td height="28" align="right" bgcolor="#FFFFFF">帐户<?=$web_moneyname?>最小值：</td>
                    <td bgcolor="#FFFFFF"><input name="tbMinG" type="text" id="tbMinG" value="0" />当帐户<?=$web_moneyname?>小于此数时自动停止投注。</td>
                  </tr>
                  <tr>
                    <td height="28" align="right" bgcolor="#FFFFFF">帐户<?=$web_moneyname?>最大值：</td>
                    <td bgcolor="#FFFFFF">
                      <input type="text" name="tbMaxG" id="tbMaxG" value="0" />当帐户<?=$web_moneyname?>大于此数时自动停止投注。</td>
                  </tr>
                  <tr>
                    <td height="85" colspan="2" align="center" bgcolor="#FFFFFF" class="rf"><table width="100%" border="0" cellpadding="0" cellspacing="3">
                        <tr>
                          <td width="23%" align="center" class="rf">投注模式</td>
                          <td width="24%" align="center" class="rf">投注<?=$web_moneyname?></td>
                          <td width="28%" align="center" class="rf">赢后使用的投注模式</td>
                          <td width="25%" align="center" class="rf">输后使用的投注模式</td>
                        </tr>
						<?
						$i=0;
						$query_f=$db->query("Select * from {$web_dbtop}game28_auto_tz where uid=".intval($_COOKIE["usersid"])." Order by tzid asc");
						while($rs_f=$db->fetch_array($query_f)){
						?>
                        <tr>
						  <td align="center"><input type="hidden" name="sID[]" id="sID<?=$i;?>" value="<?=$rs_f["id"]?>" /><?=$rs_f["tzname"]?></td>
						  <td align="center"><?=$rs_f["tzpoints"]?></td>
						  <td align="center"><select name="sWinModel[]" id="sWinModel<?=$i;?>">
							<?
							$query=$db->query("Select * from {$web_dbtop}game28_auto_tz where uid=".intval($_COOKIE["usersid"])." Order by tzid asc");
							while($rs=$db->fetch_array($query)){
							?>
								<option label="<?=$rs["tzname"]?>" value="<?=$rs["id"]?>"><?=$rs["tzname"]?></option>
							<?
							}
							?>
							</select>
						  </td>
                          	<td align="center"><select name="sLossModel[]" id="sLossModel<?=$i;?>">
							<?
							$query=$db->query("Select * from {$web_dbtop}game28_auto_tz where uid=".intval($_COOKIE["usersid"])." Order by tzid asc");
							while($rs=$db->fetch_array($query)){
							?>
								<option label="<?=$rs["tzname"]?>" value="<?=$rs["id"]?>"><?=$rs["tzname"]?></option>
							<?
							}
							?>
							</select>
							</td>
                        </tr>
						<?
							$i++;
						}
						?>
                     </table>
                      <br />
                      <input name="image" type="image" id="btnSubmit" src="images/28-submit.gif" width="115" height="29" border="0" />&nbsp;<img src="images/28-back28.gif" width="115" height="29" border="0" class="pointer" onclick="javascript:history.back()" /></td>
                  </tr>
                  <tr>
                    <td height="28" colspan="2" align="left" valign="top" bgcolor="#FFFFFF"><p>设置方法：<br />
                      1．选择投注模式<br />
                      2．设置自动投注开始与结束的期号<br />
                      3．设置帐户<?=$web_moneyname?>最小值<br />
                      4．确认并开始自动投注后，系统将会在你指定的期数内帮您自动投注，不论你的离线或在线都会持续运 行直到期数终止或您关闭为止。<br />
                      5．银行内所存<?=$web_moneyname?>不能用于投注											</p></td>
                  </tr>
                  
                </table></td>
              </tr>
            </table>
			</form>
			<script type="text/javascript">
			<!--
			function ChkSetAuto(){
				var s = parseInt("");
				var starLuckNO = parseInt(document.getElementById("tbStarLuckNO").value);
				var endLuckNO = parseInt(document.getElementById("tbEndLuckNO").value);
				var minMoney = parseInt(document.getElementById("tbMinMoney").value);
				if(ChkInt(starLuckNO,1,10)==false || starLuckNO < s){
					alert("开始投注期数格式错误！");
					return false;
				}
				if(ChkInt(endLuckNO,1,10)==false || endLuckNO > s+2999 || endLuckNO <= starLuckNO){
					alert("结束投注期数格式错误！");
					return false;
				}
				if(ChkInt(minMoney,1,10,"[0-9]+")==false){
					alert("<?=$web_moneyname?>最小值格式错误！");
					return false;
				}
				document.getElementById("btnSubmit").disabled=true;
			}
			function ResetModel(t){
				for(i=0;i<t;i++){
					document.getElementById("sWinModel"+i).selectedIndex = GetSIndex("sWinModel"+i,document.getElementById("sID"+i).value);
					document.getElementById("sLossModel"+i).selectedIndex = GetSIndex("sLossModel"+i,document.getElementById("sID"+i).value);
				}
			}
			function GetSIndex(obj,v){
				var l = document.getElementById(obj).options.length;
				for(o=0;o<l;o++){
					if(document.getElementById(obj).options[o].value == v){
						return o;
					}
				}
				return 0;
			}
			ResetModel('<?=$i?>');
			-->
			</script>
			</DIV>
			<DIV class=cl></DIV>
		</DIV>
		<DIV class="area960-b h5px"></DIV>
	<!--Flink End-->
	<div class="blank10"></div>
	<!--Footer Start-->
<?php include_once("footer.php");?>
</DIV>