<?php
include('config/config.php');
include('includes/classes/class.Vote.php');

$objVote=new Vote();
?>
<!doctype html>  
<html dir="ltr" lang="en-US">
	
	<head>
		<title>Voting Advice Application</title>
		<!-- generic demo style -->
		<link rel="stylesheet" href="./css/reset.css" />
		<link rel="stylesheet" href="./css/demo.css" />
		<!-- scripts -->
		<link rel="stylesheet" href="css/jquery-ui.css">
		<script src="js/jquery-1.10.2.js"></script>
        <script src="js/jquery-ui.js"></script>
        
        <script>
		  $(function() {
			$("#accordion").accordion({
			  collapsible: true,
    		  active: false,
    		  heightStyle: 'content'
			});
		  });
		 </script>
		<!-- shiv me up baby! -->
		<!--[if lt IE 9]>
			<script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script>
		<![endif]-->
		  <style>
			html{
				width:100%;
				height:100%;
			}
			
			body{
				width:100%;
				height:100%;
			}
			
			#header{
				width:100%;
			}
			
			#container
			{
			  width:100%;	
			}
			
			#footer{
				width:100%;
			}
        </style>
         
	</head>	
    <body>
		<div id="header">
			<div id="header-wrapper">
				<h1>Voting Advice Application</h1>
				<h2>An Advice Application</h2>
				<p><a href="index.php">Home</a> | <a href="statistics/index.php">Statistics</a></p>
			</div>
			<div class="gradient">&nbsp;</div>
		</div>
		<div id="container">
		 <div id="wrapper">
			<h2 id="introduction">Prioritize Questions</h2>
             
             <div id="accordion" style="width:80%; float:left;">
             <?php
			  $questionData=$objVote->loadQuestions();
			  if($questionData)
			  { 
			    foreach($questionData as $question)
				{
			  ?>
                <h3><?php echo $question->Heading;?></h3>
                 <div>
                  <p><?php echo $question->Question;?></p>
                 </div> 
             <?php
				}
			  }
			 ?>
             </div>
             
             <?php
			 $attemptQuest=array();
			 $attemptQuest=$_SESSION['QuestionAttempt'];
			 $top=0;
			 for($i=0;$i<sizeof($attemptQuest);$i++)
			 {
				 if($i==0)
				 {
					 $top+=20;
				 }
				 else
				 {
					 $top+=5;
				 }
			 ?>
              <div style="float:right; margin-right:150px; margin-top:<?php echo $top;?>px">
               <span class="checkbox"><input type="checkbox" name="check" id="rate<?php echo $attemptQuest[$i];?>" onClick="priorityUpdate('<?php echo $attemptQuest[$i];?>', this.id)" style="cursor:pointer;"/></span>
              </div>
             <?php
			 }
			 ?>
             <div class="clearfix"></div>
             
             <hr/>            
            <div style="text-align:right;">
			  <a href="result.php" class="large blue button next" data-action="next" onClick="next()">Finish</a> 
			</div>
			<div class="clearfix"></div>
	    </div>
	  </div> 	
		<div id="footer">
			<div class="gradient">&nbsp;</div>
			<div id="footer-wrapper">
				<p>&copy; <a href="https://klaus-uwe.me">Klaus-Uwe Mitterer</a> 2014</p>
			</div>
		</div>

	</body>
</html>

<script>
function priorityUpdate(questionId, checkBoxId)
{
	var statusVal = $('#'+checkBoxId).val();
	if(statusVal=='on')
	{
	 priorityStatus=1;
	}
	else
	{
		priorityStatus=0;
	}
	
	var dataString = "questionId="+questionId+"&priorityStatus="+priorityStatus;
	
	$.ajax({
		type: "POST",
		url: "includes/ajax/status.php",
		data: dataString,
		success: function(msg) {
			if(msg=="1")
			{
			  $('#'+checkBoxId).val(msg);
			}
			else
			{
				alert("Priority Not Set");
			}
		}
	});
}
</script>
