<?php
$querypolls = "SELECT * FROM polls_questions WHERE q_id='$q_id' AND active='yes'";
$resultpolls = mysql_query ($querypolls) or die (mysql_error());
if(mysql_num_rows($resultpolls)>0){
	$linepolls = mysql_fetch_array($resultpolls);
	$querypollsclosed=$querypolls ." AND start_active<=SYSDATE() AND end_active>=SYSDATE()";
	?> 
	<script type="text/javascript">
	//<![CDATA[
	function PollsPopup( url, name, widgets, openerUrl )
	{
		var host = location.hostname;
		var popupWin = window.open( url, name, widgets );
		
		if ( popupWin && popupWin.opener ) {
		if ( openerUrl )
		{
		popupWin.opener.location = openerUrl;
		popupWin.focus();
		}
		popupWin.opener.top.name = "opener";
		}
	}
	//]]>
	</script>
	
	
	<table width="100%" border="0" cellspacing="0" cellpadding="3">
		<tr>
			<td class="boxHeaderTd">Polls</td>
		</tr>
	</table>
	<table width="100%" cellpadding="0" cellspacing="0" border="0" class="loginTd">
		<tr>
			<td align="center">
				<form name="form_poll_<?php echo $q_id;?>" method="post" action="<?php if(isset($target) && $target<>""){echo "$pathcentral/";}else{echo $path;}?>polls_action.php" target="polls">
				<table cellspacing="0" cellpadding="0" width="100%" border="0">
					<tr>
						<td align="center"><span class="small10"><?php echo $linepolls["q_en"];?></span></td>
					</tr>
					<tr> 
						<td class="small10"><hr size="1" noshade="noshade"/></td>
					</tr>
					
					<tr align="center">
						<td class="small10">
							<? 	
							$queryans = "SELECT * FROM  polls_answers WHERE q_id='$linepolls[q_id]' ORDER BY order_seq ASC";
							$resultans = mysql_query ($queryans);
							$NumberOfFieldsans=mysql_num_rows($resultans);
							if ($NumberOfFieldsans <> 0){
								?>
								<table  border="0" align="center" cellpadding="0" cellspacing="2">
									<?php 
									while($lineans = mysql_fetch_array($resultans)){ 
										?>
										<tr>
											<td align="right">
											<?php 
												if(mysql_num_rows(mysql_query ($querypollsclosed))>0){?><input type="radio" value="<?php echo $lineans["a_id"]; ?>" name="a_id"/><?php }?></td>
											<td align="left" class="small10"><?php echo $lineans["a_en"]; ?></td>
										</tr>
										<?php 
									}
									?>  
								</table>
								<?php 
							}
							else{
								?>
								No Answers configured yet!!
								<?php 
							}
							?>
						</td>
					</tr>
					<tr align="center">
						<td> </td>
					</tr>
					<tr align="center">
						<td><hr size="1" noshade="noshade"/></td>
					</tr>
					<tr align="center">
						<td>
							<table border="0" cellspacing="0" cellpadding="0">
								<tr>
									<td>
										<input name="q_id" type="hidden" id="q_id" value="<?php echo $linepolls["q_id"];?>"/>
										<?php 
										if(mysql_num_rows(mysql_query ($querypollsclosed))>0){
											?>
											<input name="imageField2" type="image" src="<?php echo $path;?>images/icons/button_vote.gif" onclick="PollsPopup('','polls','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=300,height=500')"/>
											<?php 
										}
										else{
											?>
											<span class="small10">Poll Closed | </span>
											<?php 
										}
										?>
									</td>
									<td>&nbsp;<a href="javascript: window.open('<?php if(isset($target) && $target<>""){echo "$pathcentral/";}else{echo $path;}?>polls_action.php?q_id=<?php echo $linepolls["q_id"];?>','','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=300,height=500'); void('');" class="small10">Results</a></td>
								</tr>
							</table>
						</td>
					</tr>
				</table>
				</form> 
			</td>
		</tr>
	</table>
	<table width="100%" border="0" cellspacing="0" cellpadding="0">
		<tr> 
			<td bgcolor="#CCCCCC"><img src="<?php echo $path;?>images/navigation/spacer.gif" alt="css-img" width="1" height="3"/></td>
		</tr>
	</table>
	<?php 
}?>