<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?PHP
	session_start(); // Initialize session data
	if(! isset($_SESSION['useBT'])){ #If started in the middle go to 1st page
		header("Location: index.php");
	}

	if($_SERVER['REQUEST_METHOD'] == 'POST') {
		if(isset($_POST['sitesUse'])){ //Result selected
			$siteTypes = $_POST['sitesUse'];
			$_SESSION['sitesUse'] = $siteTypes;
			header("Location: pg6.php");
		}
	}
	else{
		echo "<table style=\"width: 800px\" align=\"center\">
			<tr><td><h1 class=\"auto-style1\">BitTorrent Search Engine/Site Survey&nbsp;</h1></td></tr>
			<tr><td style=\"height: 21px\"></td></tr>";
		echo "<table style=\"width: 800px\" align=\"center\">
			<tr><td><p>Which of the following BitTorrent sites (search engines) <strong>do you use</strong>
			(select all that apply)?<p>";

		echo "<form name=\"sitesUseForm\" method=\"post\" action=\"pg5.php\" onsubmit=\"return checkForm()\">";
			
		$num = count($_SESSION['sitesKnow']); //No of elements in array
		for($i = 0; $i < $num; $i++){
			$tmpStr = "<input name=\"sitesUse[]\" type=\"checkbox\" style=\"width: 40px\" class=\"radio\"";
			$tmpStr = $tmpStr. "value=\"" . $_SESSION['sitesKnow'][$i] . "\"/>" . $_SESSION['sitesKnow'][$i] . "<br />";
			echo $tmpStr;
		}
		
		echo "<div class=\"auto-style2\"><input name=\"Next\" type=\"submit\" value=\"Next >>\" /></div>
			</form>
			<p class=\"auto-style3\">Progress 5/8</p></td></tr>
			<tr><td>&nbsp;</td></tr>
			</table>";			
	}
?>

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<link rel="stylesheet" type="text/css" href="css.css" />
<title>BitTorrent Search Engine Survey</title>
<style type="text/css">
.auto-style1 {
	text-align: center;
}
.auto-style2 {
	text-align: right;
}
.auto-style3 {
	text-align: center;
	font-size: small;
}
</style>

<script type="text/javascript">

function checkForm()
{
    //Check whether Other is selected
    var multiSites = document.sitesUseForm.elements["sitesUse[]"];
    var count = multiSites.length;
    if (count == undefined) //Only 1 element
    {
        if (document.sitesUseForm["sitesUse[]"].checked)
        {
			return true;
        }
    }
	else
	{
    	for(var i = 0; i < count; i++)
    	{
        	if (multiSites[i].checked)
        	{
            	return true;
        	}
    	}
	}
    alert("Please select at least one site that you use.");
    return false;
}
</script>

</head>

<body>
</body>

</html>
