<!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['features'])){ //Result selected
			$featureTypes = $_POST['features'];
			if (array_search("Other",$featureTypes)){
				$featureTypes[count($featureTypes) - 1] = $_POST['Other'];
			}
            elseif (count($featureTypes) == 1){
                if ($featureTypes[0] == "Other"){
                    $featureTypes[0] = $_POST['Other'];
                }
            }
			$_SESSION['features'] = $featureTypes;
			header("Location: pg4.php");
		}
	}
?>

<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 multiFeatures = document.featuresForm.elements["features[]"];
	count = multiFeatures.length;
	if (multiFeatures[count - 1].checked){
		if (document.featuresForm.Other.value == "") //If so textbox can't be empty
		{
			alert('Please specify "Other" feature(s).');
			return false;
		}
		else
		{
			return true;
		}
	}
	for(var i = 0; i < count - 1; i++)
	{
		if (multiFeatures[i].checked)
		{
			return true;
		}
	}
	alert("Please select at least one feature that you use.");
	return false;
}
</script>

</head>

<body>
<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>
	<tr>
		<td>
<p>Which of the following features on a BitTorrent search engine <strong>do you use</strong> (select all that apply)?</p>
		<p>
		<form name="featuresForm" method="post" action="pg3.php" onsubmit="return checkForm()">
			<input name="features[]" type="checkbox" style="width: 40px"  class="radio" value="Search"/>Search<br />
			<input name="features[]" type="checkbox" style="width: 40px"  class="radio" value="SearchCloud"/>Search Cloud<br />
			<input name="features[]" type="checkbox" style="width: 40px"  class="radio" value="Top"/>Top or most popular torrents<br />
			<input name="features[]" type="checkbox" style="width: 40px"  class="radio" value="Browse"/>Browse torrents<br />
			<input name="features[]" type="checkbox" style="width: 40px"  class="radio" value="Resent"/>Recent/latest Torrents<br />
			<input name="features[]" type="checkbox" style="width: 40px"  class="radio" value="Other"/>Other – please specify&nbsp;&nbsp;
				<input name="Other" type="text" style="width:200px" maxlength="128"/><br />

			<br />
			<div class="auto-style2">
			<input name="Next" type="submit" value="Next >>" /></div>
		</form>
		<p class="auto-style3">Progress 3/8</p>
		</td>
	</tr>
	<tr>
		<td>
		&nbsp;</td>
	</tr>
</table>
</body>

</html>
