<?php 
// $body_class = "not_time"; 
$page_class = 'pp';
?>
<?php include('../includes/pp-header.php'); ?>

<body class="pp">
	<main class="container">
		<script type="text/javascript">
			var contestOpen = false;
			var startDate = '06/15/2015';
			var endDate = '08/29/2015';
			var sDate = new Date(startDate);
			var eDate = new Date(endDate);


			// first run

// testing (for 7:55 am start instead of 5:55)
var startTimeHour = "7";

// 5:55pm

// var startTimeHour = "17";
var startTimeMinute = "55";
// testing (for 10:15 close instead of 17:15)
var endTimeHour = "10";

// 9:15pm
// var endTimeHour = "21";
var endTimeMinute = "15";

var today = new Date();
	
//returns hour (0 - 23)
var nowHours = today.getHours();
var nowMinutes = today.getMinutes();

// get day of week ( 0 - 6, 0 = sunday, 6 = Saturday)
var theDayOfTheWeek = today.getDay();
// displayClosed();
if (today >= sDate && today <= eDate)
{	
	// if day not sunday
	if (theDayOfTheWeek != 0)
	{
		// if time now between start and end
		if ((nowHours > startTimeHour || (nowHours == startTimeHour && nowMinutes > startTimeMinute)) && (nowHours < endTimeHour || (nowHours == endTimeHour && nowMinutes < endTimeMinute)))
		{
			displayOpen();
			contestOpen = true;
		}
		else
		{
			displayClosed();
 			contestOpen = false;
		}
	}
	else
	{
		displayClosed();
		contestOpen = false;
	}
}
else
{
	displayClosed();
	contestOpen = false;
}

setInterval(function()
{
	console.log("running setInterval");
	// contest dates
	today = new Date();
	
	//returns hour (0 - 23)
	nowHours = today.getHours();
	nowMinutes = today.getMinutes();

	// get day of week ( 0 - 6, 0 = sunday, 6 = Saturday)
	theDayOfTheWeek = today.getDay();
	

	console.log("Currently it is " + nowHours + ":" + nowMinutes + " on the " + theDayOfTheWeek +'th day of the week');
	if (today >= sDate && today <= eDate)
	{	
		console.log("Date is between " + sDate + " and " + eDate);
		// if day not sunday
		if (theDayOfTheWeek != 0)
		{
			console.log("Day of the week is correct")
			// if time now between start and end
			if ((nowHours > startTimeHour || (nowHours == startTimeHour && nowMinutes > startTimeMinute)) && (nowHours < endTimeHour || (nowHours == endTimeHour && nowMinutes < endTimeMinute)))
			{
				console.log("contest should be open")
				contestOpen = true;
				displayOpen();
			}
			else
			{
			
				displayClosed();
				contestOpen = false;
				console.log("contest closed - time of day")

			}
		}
		else
		{
			console.log("contest closed - must be sunday")
			
			displayClosed();
			contestOpen = false;

		}
	}
	else
	{
		console.log("contest closed - outside of dates");
		
		contestOpen = false;
		displayClosed();

	}	
}, 300000);



function displayOpen()
{
	// remove existing and replace
	$('h1').remove();
	$('h2').remove();
	$('h6').remove();
	$('.enter').remove();

	$('.container').append('<h1 class="pinkText">WE\'RE CELEBRATING OUR NEW EXTENDED HOURS BY GIVING YOU A CHANCE TO WIN!</h1><h2 class="yellowText">ENTER HERE EACH DAY YOU SHOP BETWEEN 6PM AND 9PM AND YOU COULD WIN ONE OF MANY PARK PLACE GIFT CARDS VALUED AT UP TO $250!</h2><h6 class="yellowText">*ONE ENTRY PER PERSON, PER DAY</h6>');
	contestOpen = true;
}
function displayClosed()
{
	// remove existing and replace
	$('h1').remove();
	$('h2').remove();
	$('h6').remove();
	$('.enter').remove();
	$('.container').append("<h1 class='lightBlueText'>WE\'RE CELEBRATING OUR NEW EXTENDED HOURS BY GIVING YOU A CHANCE TO WIN!</h1><h2 class='yellowText'>COME BACK HERE WHILE YOU\'RE SHOPPING BETWEEN 6PM AND 9PM FROM JUNE 15TH - AUGUST 29TH, 2015 TO ENTER FOR YOUR CHANCE TO WIN ONE OF MANY PARK PLACE GIFT CARDS VALUED AT UP TO $250!</h2>");
	contestOpen = false;
}
	// // contest dates
	// var startDate = '06/15/2015';
	// var endDate = '08/29/2015';

	// var today = new Date();
	// var sDate = new Date(startDate);
	// var eDate = new Date(endDate);


	// //returns hour (0 - 23)
	// var nowHours = today.getHours();
	// var nowMinutes = today.getMinutes();

	// // get day of week ( 0 - 6, 0 = sunday, 6 = Saturday)
	// var theDayOfTheWeek = today.getDay();

	// // set up variables
	
	// // testing (for 7:55 am start instead of 5:55)
	// // var startTimeHour = "7";
	
	// // 5:55pm

	// var startTimeHour = "17";
	// var startTimeMinute = "55";

	// // 9:15pm
	// var endTimeHour = "21";
	// var endTimeMinute = "15";

	
	// if (today >= sDate && today <= eDate)
	// {	
	// 	// if day not sunday
	// 	if (theDayOfTheWeek != 0)
	// 	{
	// 		// if time now between start and end
	// 		if ((nowHours > startTimeHour || (nowHours == startTimeHour && nowMinutes > startTimeMinute)) && (nowHours < endTimeHour || (nowHours == endTimeHour && nowMinutes < endTimeMinute)))
	// 		{
	// 			// window.location.replace("intro.php");
	// 			document.write("<h1 class='pinkText'>WE\'RE CELEBRATING OUR NEW EXTENDED HOURS BY GIVING YOU A CHANCE TO WIN!</h1>");
	// 			document.write("<h2 class='yellowText'>ENTER HERE EACH DAY YOU SHOP BETWEEN 6PM AND 9PM AND YOU COULD WIN ONE OF MANY PARK PLACE GIFT CARDS VALUED AT UP TO $250!</h2>");
	// 			document.write("<h6 class='yellowText'>*ONE ENTRY PER PERSON, PER DAY</h6>");
	// 			var flag = true;
	// 		}
	// 		else
	// 		{
	// 			// document.write("Sorry, contest isn't open yet - hours.");
	// 			document.write("<h1 class='lightBlueText'>WE\'RE CELEBRATING OUR NEW EXTENDED HOURS BY GIVING YOU A CHANCE TO WIN!</h1>");
	// 			document.write("<h2 class='yellowText'>COME BACK HERE WHILE YOU\'RE SHOPPING BETWEEN 6PM AND 9PM TO ENTER FOR YOUR CHANCE TO WIN ONE OF MANY PARK PLACE GIFT CARDS VALUED AT UP TO $250!</h2>");
	// 		}
	// 	}
	// 	else
	// 	{
	// 		// document.write("Sorry, contest isn't open yet - day of week.");
	// 		document.write("<h1 class='lightBlueText'>WE\'RE CELEBRATING OUR NEW EXTENDED HOURS BY GIVING YOU A CHANCE TO WIN!</h1>");
	// 		document.write("<h2 class='yellowText'>COME BACK HERE WHILE YOU\'RE SHOPPING BETWEEN 6PM AND 9PM TO ENTER FOR YOUR CHANCE TO WIN ONE OF MANY PARK PLACE GIFT CARDS VALUED AT UP TO $250!</h2>");
	// 	}
	// }
	// else
	// {
	// 	document.write("<h1 class='lightBlueText'>WE\'RE CELEBRATING OUR NEW EXTENDED HOURS BY GIVING YOU A CHANCE TO WIN!</h1>");
	// 	document.write("<h2 class='yellowText'>COME BACK HERE WHILE YOU\'RE SHOPPING BETWEEN 6PM AND 9PM FROM JUNE 15TH - AUGUST 29TH, 2015 TO ENTER FOR YOUR CHANCE TO WIN ONE OF MANY PARK PLACE GIFT CARDS VALUED AT UP TO $250!</h2>");
	// }
</script>

	</main>
	
	<footer class="clearfix">
		<script type="text/javascript">
			$(document).ready(function()
			{
				// first run
				if (contestOpen == true)
					$('footer').append("<div class='textCenter buttonPad alignBottom enter'><a href='contest_page1.php' class='button'>ENTER NOW</a></div>");	
			})
			
			setInterval(function()
			{			
				if (contestOpen == true)
					$('footer').append("<div class='textCenter buttonPad alignBottom enter'><a href='contest_page1.php' class='button'>ENTER NOW</a></div>");
			}, 300000 );
		</script>
	</footer>

</body>
</html>
