<?php
include "var.php";
$con = mysqli_connect($DBHOST,$DBUSER,$DBPASS,$DBNAME) or die("Some error occurred during connection " . mysqli_error($con));  
mysqli_query($con, "SET CHARACTER SET 'utf8'");

ob_start();
session_start();
$GETlang = @mysqli_fetch_array(mysqli_query($con, "select * from `lang` where `default`='1' limit 0,1"));
$lang2 = $GETlang['id'];
$lang = "";
if(isset($_GET['lang'])){ $lang = $_GET['lang']; }

$slang = "";
if(isset($_SESSION['lang'])){ $slang = $_SESSION['lang']; }

if($slang == "")
{
	$_SESSION['lang'] = $lang2;
}
if($lang !== "")
{
	$_SESSION['lang'] = $lang;
}
$defaultlang = $_SESSION['lang'];
$globaldata = @mysqli_fetch_array(mysqli_query($con, "select * from `lang` where `id`='$defaultlang' limit 0,1"));
?>
<!DOCTYPE html>
<html>
<head>
<title><?=base64_decode($globaldata['title'])?></title>
<?
$langsql = "SELECT * FROM `lang` order by id ASC";
$langres = mysqli_query($con, $langsql);
$totallang = @mysqli_num_rows($langres);

include "header.php";
?>
		<div style="background: #EEE; margin-bottom: 0px; margin-top: 0px;">
			<a href='<?=$domain?>'
				style='text-decoration: none; color: inherit'>
				<h3 style="padding: 20px; margin-top: 0px;" align='center'>
					<?=$homepage_title?><br>
<?
if ($totallang > 1)
{
			while($languages = mysqli_fetch_array($langres))
			{
			$isdefault = "";
			if($languages['id'] == $defaultlang)
			{
				$isdefault = '<img src="mrhbaa/img/primary.png" border="0" title="اللغة الافتراضية: '.$languages['lang'].'">';
			}
			echo "<a href='?lang=".$languages['id']."'><img src='img/".$languages['icon']."' title='".$languages['lang']."'></a>&nbsp;".$isdefault."&nbsp;&nbsp;";
			}
}
?>
				</h3> </a>
		</div>
<div class="container">
<form action="quiz.php" method="post">
<?
$result44 = mysqli_query($con, "SELECT * FROM quiz where live=1 AND lang='$defaultlang' ");
$num44 = @mysqli_num_rows($result44);
$total_groups = ceil($num44/$items_per_group);
?>
<script type="text/javascript">

$(document).ready(function() {
	var track_load = 0;
	var loading  = false;
	var total_groups = <?php echo $total_groups; ?>;
	
	$('#results').load("autoload_process.php", { tony: "<?=$defaultlang?>", 'group_no':track_load}, function() {track_load++;});
	
	$(window).scroll(function() {
		
		if($(window).scrollTop() + $(window).height() == $(document).height())
		{
			
			if(track_load <= total_groups && loading==false)
			{
				loading = true;
				$('.animation_image').show();

				$.post('autoload_process.php',{ 'tony': "<?=$defaultlang?>", 'group_no': track_load}, function(data){
									
					$("#results").append(data);

					$('.animation_image').hide();
					
					track_load++;
					loading = false; 
				
				}).fail(function(xhr, ajaxOptions, thrownError) {
					
					alert(thrownError);
					$('.animation_image').hide();
					loading = false;
				
				});
				
			}
		}
	});
});
</script>
<div id="results">
</div>
<div class="animation_image" style="display:none" align="center"><img src="img/loading.gif"></div>
</form>
</div>
<?
include "footer.php";
?>
</body>