<?php if($_SERVER["HTTPS"] != "on") { header("Location: https://" . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]); exit(); } ?>
<?php error_reporting(E_ALL); ?>
<?php include 'functions.php'; ?>
<?php /* 1: SET: HTML Meta, Location Array */ include 'header.php'; ?>
<?php /* 2: PRINT HTML -> HEADER */ 	{ ?><!DOCTYPE html><head>
	<?php $ak = $GLOBALS["alkitab"]; $ak["loc"] = $GLOBALS["alkitab"]["location"]; $ak["meta"] = $GLOBALS["alkitab"]["htmlmeta"]; ?>
	<meta http-equiv="Cache-control" content="no-store">
	<meta name="viewport" content="width=device-width, initial-scale=1.0" id="viewportMeta" />
	<link rel="stylesheet" href="/dist/script_css/fonts_<?php echo (server() == "q.com")?'local.css':'live.css'; ?>" charset="UTF-8" type="text/css" />
	<link rel="stylesheet" href="/dist/script_css/style.css<?php echo '?ver='.filemtime('dist/script_css/style.css'); ?>" charset="UTF-8" type="text/css" />
	<script src="/dist/script_css/scripts.js<?php echo '?ver='.filemtime('dist/script_css/scripts.js'); ?>" charset="UTF-8" type="text/javascript"></script>
	<!-- Primary Meta Tags -->
	<title><?php echo $ak["meta"]["title"]; ?></title>
	<meta name="title" content="<?php echo $ak["meta"]["title"]; ?>">
	<meta name="description" content="<?php echo $ak["meta"]["desc"]; ?>">
	<meta name="keywords" content="<?php echo $ak["meta"]["kywrds"]; ?>">
	<meta charset="utf-8">
	<!-- Google / Search Engine Tags -->
	<meta itemprop="name" content="<?php echo $ak["meta"]["title"]; ?>">
	<meta itemprop="description" content="<?php echo $ak["meta"]["desc"]; ?>">
	<meta itemprop="image" content="<?php echo $ak["meta"]["img"]; ?>">
	<!-- Open Graph / Facebook -->
	<meta property="og:type" content="book">
	<meta property="og:url" content="<?php echo $ak["meta"]["fulluri"]; ?>">
	<meta property="og:title" content="<?php echo $ak["meta"]["title"]; ?>">
	<meta property="og:description" content="<?php echo $ak["meta"]["desc"]; ?>">
	<meta property="og:image" content="<?php echo $ak["meta"]["img"]; ?>">
	<meta property="og:image:type" content="image/png" />
	<meta property="og:image:width" content="1200" />
	<meta property="og:image:height" content="630" />
	<meta property="og:image:alt" content="Quranic Text" />
	<!-- Twitter -->
	<meta property="twitter:card" content="summary_large_image">
	<meta property="twitter:domain" content="<?php echo server(); ?>">
	<meta property="twitter:url" content="<?php echo $ak["meta"]["fulluri"]; ?>">
	<meta property="twitter:title" content="<?php echo $ak["meta"]["title"]; ?>">
	<meta property="twitter:description" content="<?php echo $ak["meta"]["desc"]; ?>">
	<meta property="twitter:image" content="<?php echo $ak["meta"]["img"]; ?>">
	<meta property="twitter:image:width" content="1200" />
	<meta property="twitter:image:height" content="630" />
	<meta property="twitter:image:alt" content="Quranic Text" />
	<!-- Whatsapp -->
	<meta property="og:image" content="<?php echo $ak["meta"]["imgsq"]; ?>">
	<meta property="og:image:width" content="1200" />
	<meta property="og:image:height" content="1200" />
	<!-- Other -->
	<meta name="robots" content="index">
	<meta name="googlebot" content="index">
	<meta name="language" content="Arabic">
	<!-- Icons and Color -->
	<link rel="apple-touch-icon" sizes="180x180" href="/dist/img/apple-touch-icon.png">
	<link rel="icon" type="image/png" sizes="32x32" href="/dist/img/favicon-32x32.png">
	<link rel="icon" type="image/png" sizes="192x192" href="/dist/img/android-chrome-192x192.png">
	<link rel="icon" type="image/png" sizes="16x16" href="/dist/img/favicon-16x16.png">
	<link rel="manifest" href="/dist/img/site.webmanifest">
	<link rel="mask-icon" href="/dist/img/safari-pinned-tab.svg" color="#191919">
	<link rel="shortcut icon" href="/dist/img/favicon.ico">
	<meta name="msapplication-TileColor" content="#191919">
	<meta name="msapplication-TileImage" content="/dist/img/mstile-144x144.png">
	<meta name="msapplication-config" content="/dist/img/browserconfig.xml">
	<meta name="theme-color" content="#191919">
	</head><?php } ?>
<?php /* 3: PRINT HTML -> BODY */ 			{ ?><body class="the_body"><?php echo images("hidden");
			if			( is_error() ) { echo the_masthead(); echo error(1); echo images("surahend"); }
			elseif 	(!is_home()) {
				echo the_masthead("menu"); include "optionspanel.php";
				echo '<!-- #INDEXCONTENT --><div id="indexcontent"><!-- .AYAATCNTR ST --><div class="ayaatcntnr">';
				echo "<div class='playpausestop' style='display:none'><div class='playallicons playall'></div><div class='playallicons pauseall'></div><div class='playallicons stopall'></div><br></div>";
				//echo "<select id='ttsvoices'></select>";
				if			(is_chapter() || !empty($GLOBALS["fullsurah"])) {
					$totalverses = $ak["loc"]["totalverses"];
					printsurahnames($ak["loc"][0]);
					echo '<input type="hidden" name="totalverses" id="totalverses" value="'.$totalverses.'">';
					if ($totalverses < 11 || !empty($GLOBALS["fullsurah"])) { printfullsurah($ak["loc"][0]); }
					else { info4ajax ($ak["loc"][0], $totalverses); $x = 1; while ($x < 11) { printoneayat($ak["loc"][0], $x); $x++; } }
				}
				elseif 	(is_svpttrn()) {
					printsurahnames($ak["loc"][0]);
					printoneayat($ak["loc"][0], $ak["loc"][1]);
				}
				elseif 	('/'.sanitizeURI() == "/_translated") { echo mapverses(); }
				elseif 	('/'.sanitizeURI() == "/_topics") { echo topics(); }
				elseif 	(is_search()) { 
					$searcharray = buildsearcharray($ak["loc"][0]);
					if (!is_array($searcharray)) { echo error(2); }
					elseif (is_array($searcharray)) {
						$totalverses = count($searcharray);
						printsearchterm("search", $ak["loc"][0], $totalverses);
						if ($totalverses < 11) { printsearchresult($searcharray, $ak["loc"][0]); }
						else {
							$json = json_encode($searcharray);
							info4ajax ($ak["loc"][0], $totalverses);
							$x = 0;
							while ($x < 10) {
								echo '<div class="resultnumber">'.($x + 1).'</div>';
								printoneayat( $searcharray[$x]["surah"], $searcharray[$x]["verse"], $ak["loc"][0]);
								$x++;
							}
						}
					}
				}
				elseif 	(is_rngpttrn()) {
					$w = $currsur = $ak["loc"][0]; $x = $currver = $ak["loc"][1];
					$y = $ak["loc"][2]; $z = $ak["loc"][3]; $a = $y.$z;
					if ($w == $y) { $samesurahrange = 1; } else { $samesurahrange = 0; }
					printsearchterm("range", "null", $ak["loc"]);
					while ($currsur <= $y) { $currsurver = quran_data($currsur, "verses");
						while ($currver <= $currsurver) { $b = $currsur.$currver;
							if ($currsur >! $y && $b <= $a) { printoneayat($currsur, $currver); $currver++; }
							else { goto endloop; }
						}
						$currsur++; $currver = 1;
					}
					endloop:
					if ($ak["loc"][3] < quran_data($ak["loc"][2], "verses")) {
						$totalverses = quran_data($ak["loc"][2], "verses");
						info4ajax ($ak["loc"][2], $totalverses, $ak["loc"][3]);
					}
				}
				echo "</div><!-- .AYAATCNTR ST -->";
				if ( !empty($totalverses) ) {
					if	(is_chapter() && $totalverses > 10 ) { echo loadmore_btn_inpt ("chapter"); }
					if 	(is_search() && $totalverses > 10 ) { echo loadmore_btn_inpt ("search"); }
					if 	(is_rngpttrn() && $totalverses > 10 ) { echo loadmore_btn_inpt ("range"); }
				}
				echo images("surahend");
				echo '<div id="othermeanings" class="myclass"><div class="othermeanings"></div></div>';
				echo "</div><!-- #INDEXCONTENT -->";
			}
			else { echo the_masthead("menu"); include "optionspanel.php"; } ?>
			<!-- #BOOKCHAPTERS -->
			<div id="bookchapters" <?php if ( is_home() ) { echo "style='top: 100px;'"; }?>>
				<div class="titlediv"><img class="mainimg" alt="Bimillah Ar Rahman Ar Raheem seal" src="/dist/img/bismillah.svg"><div class="engbismillah">CONSTITUTION OF THE ONE WHO IS<br>THE NOURISHER, THE SAFE-KEEPER</div></div>
				<br><hr size="1" color="#03b17b"><br>
				<div class="btncntnr"><div class="namebtncnt"><?php echo surah_names(); ?></div></div><br><br>
				<hr>
				<?php include 'read_me.html'; ?>
			</div>
			<!-- #BOOKCHAPTERS -->
			<div id="cookiecons"><small>This website tracks non-personal-identification cookies for saving options you may set.</small></div>
			<br>
			<script>/* Unhide About section */ $('.about').on('click', function(event) { document.getElementById("about").style.height = "unset"; } ); </script>
			<script>/* Scroll Show/Hide Masthead and OtherMeanings */
				var prevScrollpos = window.pageYOffset; window.onscroll = function() {
				 var currentScrollPos = window.pageYOffset; if (prevScrollpos > currentScrollPos) { document.getElementById("masthead").style.top = "0px"; <?php if ($ak["loc"] !== "Home" && $ak["loc"] !== "Error") { ?> document.getElementById("othermeanings").style.display = "none"; <?php } ?> } else { document.getElementById("masthead").style.top = "-70px"; <?php if ($ak["loc"] !== "Home" && $ak["loc"] !== "Error") { ?> document.getElementById("othermeanings").style.display = "none"; <?php } ?> } prevScrollpos = currentScrollPos; }
			 </script>
			<script>/* Ajax Search */
				$(document).ready(function() {
					var timeout = null; // declare the variable timeout
					$("#keyboardInputInitiator0").keyup(function() {
						clearTimeout(timeout); // clear time out
						timeout = setTimeout(function () {
							if( ($("#keyboardInputInitiator0").val().length > 1) && (!$.isNumeric($("#keyboardInputInitiator0").val())) ) { the_ajax_search(); $( "#ajax_search" ).css("display", "block"); window.scrollTo(0, 0); } // call ajax
							else if($("#keyboardInputInitiator0").val().length < 2) { $( ".searchresult" ).remove(); $( "#ajax_search" ).css("display", "none"); }
						}, 500);
					});
					function the_ajax_search() { // ajax function initialization
						var data = $("#keyboardInputInitiator0").val(); // get data while typing keywords in the box
						$.ajax({ type: 'POST', async: true, url: "/ajax_search.php", data: { data }, beforeSend: function () { }, success: function (data) {
							$('div#ajax_search').html(data); } /* show data when returning */
						});
					}
				});
			</script>
			<script>/* Loadmore All */ <?php if (!empty($totalverses)) if ($totalverses > 10) { ?>
				$(document).ready(function() {
					$("[id^=loadmore]").click(function() {
						$("#loaderanim").removeClass("hide");
						var remainingverses = $("#remainingverses").val();
						var lastdisplayed = parseInt( $("#lastdisplayedverse").val() );
						var footer_scripts = '/dist/script_css/footer_scripts.js<?php echo "?ver=".filemtime("dist/script_css/footer_scripts.js"); ?>';
						<?php  if ( is_chapter() )	{ $args = "mode: 'chapter',  totalverses: '".$totalverses."', chapter: '".$ak["loc"][0]."'"; } ?>
						<?php  if ( is_search() ) 	{ $args = "mode: 'search', totalverses: '".$totalverses."', searchterm: '".$ak["loc"][0]."', searcharray: '".$json."'"; } ?>
						<?php  if ( is_rngpttrn() )	{ $args = "mode: 'chapter',  totalverses: '".$totalverses."', chapter: '".$ak["loc"][2]."'"; } ?>
						$.ajax({ type: "POST",	url: "/loadmore.php",
							data: { <?php echo $args; ?>, lastdisplayed: lastdisplayed },
							cache: false,
							success: function(data) {
								$('input[id=lastdisplayedverse]').val( lastdisplayed + 20 );
								if ( (remainingverses - 20 ) < 1 ) { $('input[id=remainingverses]').val("MAX"); $("[id^=loadmore]").remove(); $("#loaderanim").remove(); }
								else { $('input[id=remainingverses]').val( $("#remainingverses").val() - 20 ); }
								$("#loaderanim").addClass("hide");
								$('.ayaatcntnr').append(data);
								reloadJs("footer_scripts");
							},
							error: function(xhr, status, error) { console.error(xhr); }	
						});
					});
				}); <?php } ?>
			</script>
			<script>/* Switch Translations on Off on Click */
				$("[id^=switchtranslate_]").on('click', function(event) { var thisis = $(this).attr('id').substring(16); if( $(this).prop('checked') ) { $('.trans_' + thisis ).css('display', 'block'); } else { $('.trans_' + thisis ).css('display', 'none'); } });
			</script>
			<script>/* Stop All Read Aloud */
				$(document).ready(function() { if ('speechSynthesis' in window) { $('body').data('playing', 'stopped'); window.speechSynthesis.cancel(); } });
			</script>
			<script  id="footer_scripts" type="text/javascript" src="/dist/script_css/footer_scripts.js<?php echo '?ver='.filemtime('dist/script_css/footer_scripts.js'); ?>" charset="UTF-8"></script>
			<script>/* Set Cookies for options */
				$('input[type="checkbox"]').change(function () {
					var checkboxName = $(this).attr('name');
					var checkboxValue = $(this).prop('checked') ? 'checked' : '';
					document.cookie = checkboxName + '=' + checkboxValue + '; expires=Fri, 31 Dec 9999 23:59:59 GMT; path=/';
				});
			</script>			
		</body><?php
	} ?>
</html>