<?php
$sql="SELECT * from {$tablepre}bbs_poll where pid=".$TitleID." and (tptype=1 or tptype=2) order by ID asc";
$rs=mysql_query($sql);
$row = mysql_fetch_array($rs);
$tpnumrows = mysql_num_rows($rs);

if ($tpnumrows!=0){
   $dt=DateDiff("DAY",$getnow,$row["pttime"]);
   $begindate=$row["bgtime"];
   $enddate=$row["edtime"];
   $dis="";
   if ($dt<0){
   $dis="disabled";
   }
	
   $tpty=$row["tptype"];
   if ($tpty==1){
        $tptype=1;
        $tptype1="radio";
		$pollname="tp[]";
		}
   else{
        $tptype=2;
        $tptype1="checkbox";
		$pollname="tp[]";
   }
   $pollstr="<form name=tppoll action=poll.php?tptype=".$tptype."&pollid=".$TitleID." method=post style=\"MARGIN-BOTTOM: 0px;\">"; 
   $strsql="SELECT * from {$tablepre}bbs_poll where pid=".$TitleID." and tptype is null order by ID asc";
   $rsa=mysql_query($strsql);
   $rowa = mysql_fetch_array($rsa);
   $i=0;
   do{
     $i++;
     $Pollwrite=$Pollwrite."<input name=\"".$pollname."\" type=".$tptype1." value=".$rowa["ID"].">".$rowa["tpnl"]."(共<font color=red><span id=s".$i."></span></font>票)<br>";
   }
   while ($rowa = mysql_fetch_array($rsa));
   $Pollwrite=$pollstr.$Pollwrite."&nbsp;投票总数：<font color=red><span id=s".($i+1)."></span></font>票<br>&nbsp;<input type=\"button\" onclick=\"Star(this.form,1);\" value=\"投票\" id=\"vote_submit\" ".$dis.">&nbsp;</form><br>&nbsp;开始投票 ".$begindate." 结束投票 ".$enddate;
}
echo $Pollwrite;
?>
<script type="text/javascript">
//无刷新投票
Star(document.tppoll,0);
var ft;
//创建组件
function createobj(){
 if (window.ActiveXObject){
         ft=new ActiveXObject("Microsoft.XMLHTTP");
     }
     else if (window.XMLHttpRequest){
         ft=new XMLHttpRequest();
     }
}
//调用并返回结果
function Star(frm,ty){
createobj();
var idlist=0; 
objs = document.getElementsByName('tp[]');
if(ty==1){
document.getElementById('vote_submit').disabled='disabled';
for(i=0;i<objs.length;i++){   
  if(objs[i].checked == true){   
     idlist=idlist+"|"+ objs[i].value;          
    }     
  }
}
var geturl="poll.php?tptype=<?=$tptype?>&pollid=<?=$TitleID?>&vote="+idlist;
ft.open("POST",geturl,false); 
ft.send(null); 
var strResult = unescape(ft.responseText);
for(var j=1;j<<?=$i+2?>;j++){
document.getElementById("s"+j).innerText =strResult.split(" ")[j-1];
}
}
//定时刷新
window.setInterval("Star(document.tppoll,0);",50000);
</script>