<?php include 'functions.php'; ?>
<?php 
	if (isset($_POST["mode"])) {
		if ($_POST["mode"] == "chapter") { 
			$x = $_POST;
			$totalverses = $_POST['totalverses'];
			$surahnumber = $_POST['chapter'];
			$lastdisplayedverse = $_POST['lastdisplayed'];
			$x = 1; $y = 20; $z = $lastdisplayedverse + 1;
			while ($x < 21) {
				if ($z <= $totalverses) { $w[$x] = printoneayat($surahnumber, $z); } else { exit; }
				$z++;
				$x++; 
			}
			exit;
		}
		if ($_POST["mode"] == "search") {
			$searchterm = $_POST['searchterm'];
			$lastdisplayedverse = $_POST['lastdisplayed'];
			$w = $searcharray = json_decode ($_POST['searcharray'], true);
			$totalverses = count($searcharray);	
			$x = 0; $y = 19; $z = $lastdisplayedverse;
			while ($x < 20) {
				if ($z < $totalverses) {
					//echo $w -> "0";
					echo '<div class="resultnumber">'.($z + 1).'</div>'; printoneayat($w[$z]["surah"], $w[$z]["verse"], $searchterm);
				} 
				else { exit; }
				$z++;
				$x++; 
			}
			exit;
		}
	} ?>