<!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['cTypes'])){ //Result selected
			$contentTypes = $_POST['cTypes'];
			if (array_search("Other", $contentTypes)){
				$contentTypes[count(contentTypes) - 1] = $_POST['Other'];
			}
            elseif (count($contentTypes) == 1){
				if ($contentTypes[0] == "Other"){
					$contentTypes[0] = $_POST['Other'];
				}
            }
			$_SESSION['cTypes'] = $contentTypes;
			header("Location: pg3.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 multiTypes = document.cTypeForm.elements["cTypes[]"];
    var count = multiTypes.length;
	if (multiTypes[count - 1].checked){
		if (document.cTypeForm.Other.value == "") //If so textbox can't be empty
		{
			alert('Please specify "Other" type of content(s).');
			return false;
		}
		else
		{
			return true;
		}
	}
	for(var i = 0; i < count - 1; i++)
	{
		if (multiTypes[i].checked)
		{
			return true;
		}
	}
	alert("Please select at least one type of content that you download/search.");
	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>What types of content <strong>do you search/download </strong>(select all that apply)?</p>
		<p>
		<form name="cTypeForm" method="post" action="pg2.php" onsubmit="return checkForm()">
			<input name="cTypes[]" type="checkbox" style="width: 40px" class="radio" value="Movies"/>Movies<br />
			<input name="cTypes[]" type="checkbox" style="width: 40px" class="radio" value="TV"/>TV shows or documentaries<br />
			<input name="cTypes[]" type="checkbox" style="width: 40px" class="radio" value="MusicVideo"/>Music Video<br />
			<input name="cTypes[]" type="checkbox" style="width: 40px"  class="radio" value="Anime"/>Anime<br />
			<input name="cTypes[]" type="checkbox" style="width: 40px"  class="radio" value="Porn"/>Porn<br />
			<input name="cTypes[]" type="checkbox" style="width: 40px"  class="radio" value="Music"/>Music<br />
			<input name="cTypes[]" type="checkbox" style="width: 40px"  class="radio" value="AudioBooks"/>Audio Books<br />
			<input name="cTypes[]" type="checkbox" style="width: 40px"  class="radio" value="Games"/>Games<br />
			<input name="cTypes[]" type="checkbox" style="width: 40px"  class="radio" value="Software"/>Software<br />
			<input name="cTypes[]" type="checkbox" style="width: 40px"  class="radio" value="eBooks"/>e-Books<br />
			<input name="cTypes[]" type="checkbox" style="width: 40px"  class="radio" value="Pictures"/>Pictures<br />
			<input name="cTypes[]" 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 2/8</p>
		</td>
	</tr>
	<tr>
		<td>
		&nbsp;</td>
	</tr>
</table>
</body>

</html>
