<?PHP
// !! This is public end of the site -> will be viewable to everyone, regardless of log in or not.
ob_start(); 	// Buffer so was can redirect if needed
session_start();
require_once(__DIR__.'/../phplib/sql_config.php'); // Sql login data
require_once(__DIR__.'/../phplib/header_footer.php'); // Require for header and footer

// Check if user already logged in, if so, forward directly to Home
if( isset($_SESSION['auth']) && $_SESSION['auth']==1) 
{
	header("Location: home.php");
	die('You are already logined in. Continue -> <a href=\"Home.php\">Home</a>'); // For no 'Refresh' browsers		
}

// load DB
$link = SqlUtil::newDbConnection();



// if a user has a REMEMBER COOKIE set, check their hash & validate them, or clear their cookie
// user hash is a salted form of their parameters
if(isset($_COOKIE['rp_rem']) && isset($_COOKIE['rp_usr']))  {
    // forward users to login_action for processing
    header('Location: ajax/loginVerify.php');
    return;
}
// NOTE: users must login once every 14 days, to prevent a session from lasting indefinately


// Array of pertinant error messages
$err_msg = Array();
$err_msg['username'] = 'Invalid Username or Password';


/** Parse user registration pass through, if present **/
$jsonUser = null;
if(isset($_GET['ic']) || isset($_GET['e']) || isset($_GET['n']) ) {

	$inviteCode = $_GET['ic'];
	$email      = $_GET['e'];
	$names      = explode(' ',$_GET['n'],2);
	
	if( $inviteCode && $email ) {
	    $user = array('invite_code' => $inviteCode, 'email'=>$email, 'fname'=>$names[0],'lname'=>$names[1]); // form field names
	    $jsonUser = json_encode($user);
	}
}


?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<style>
span.img_copyright  {
    color: white;
    display: block;
    float: left;
    left: 312px;
    position: relative;
    top: 334px;
    width: 150px;
}
</style>


<?PHP require_once(__DIR__.'/../phplib/common_head.php'); ?>
<title>RunPartner.com</title>

<!-- Target scripts -->
<script type="text/javascript">
    // ready Ext on load
    Ext.onReady(function() {

    	// do we already have a start slide set?
    	var search = window.location.search;
    	var startSlide = 1;
    	if(search) {
    		var matches = search.split(/s=(\d)/);
    		if(matches.length>1) {
    			startSlide = matches[1];
    		}
    	}

    	// append URL if needed with random
//    	if(startSlide===false) {
//    		var count = Ext.select('#main-carousel img').elements.length;
//    		startSlide = Math.ceil(Math.random()*count); //[1-count]
//    		window.history.pushState(new Object(), document.title, window.location.href + "?s=" + startSlide); // add to URL for Google
//        }

        
		// Warmup Carousel
		new Ext.ux.Carousel('main-carousel', {
			itemSelector: 'img',
		    interval: 5,
		    transitionDuration: 1.5,
		    transitionEasing: 'easeOut',
		    startSlide: (startSlide-1),
		    autoPlay: true,
		    showPlayButton: true,
		    pauseOnNavigate: false,
			freezeOnHover: false,
		    transitionType: 'carousel', // ( carousel | fade )
		    navigationOnHover: false,
		    wrap: true       
		});
        
        // If this is passthrough from old registration page, setup and trigger form
        var userObj = <?=($jsonUser) ? $jsonUser:0;?>;
        if( userObj!==0 ) {
            var win = rp.site.user.registration.Register();
            win.loadUser( userObj );
        }
    },this,{single: true});

</script>

</head>
<?php
//Run  Header - need to send title and body id to generate navigation
do_html_header('RunPartner', 'pageUpfront');

// if user is coming in on IE6, put up warning
require_once(__DIR__.'/../phplib/Browser.class.php');
$browser = new Browser();
if( $browser->getBrowser() == Browser::BROWSER_IE && $browser->getVersion() <=7 ) {
	echo '<div class="bad-browser">You are running <b>'.$browser->getBrowser().' '.$browser->getVersion().'</b> which is <u>no longer supported</u> by RunPartner<br/>Please upgrade or install a newer browser (<a href="https://www.google.com/chrome">Google Chrome</a>) to use RunPartner.</div>';
}
else 
{
?>

<body id = "pageUpfront">
	<!-- Pass through login form to preserve browsers creds -->
	<div id="hiddenLoginFormDiv">
		<form method="post" action="loginForward.php" id="hiddenLoginForm">
			<input autocomplete="on" type="text" id="email" name="email" value=""/>
			<input autocomplete="on" type="password" id="password" name="password" value=""/>
			<input autocomplete="on" type="hidden" id="remember_me" name="remember_me" value="" style="display:none;"/>
		</form>
	</div>
	<!--Begin Content-->
	<div id="bodybox" style="z-index:99; background-color:white;">
		<div id="mainsmallbox">
			<div id="center_channel" style="margin-bottom:10px;margin-left:3px;margin-top:3px;">
			<div id="main">
				<div class="moduleBox leftBox" style="width:780px;">
					<!-- Register Button -->
					<button class="green-button" style="z-index:100;position:absolute;top:324px;right:88px;" onclick="rp.site.user.registration.Register();">Join</button>
					<!-- Main Carousel -->
			        <div id="main-carousel" style="padding: 0px; height: 348px; width: 780px; background-color: #E6E6E0;">
			        	<!-- Initial hide to prevent all visible -->
			    		<img width="780" height="348" style="display:none;" src="<?=RpCfg::cdnHost()?>/img/index-carousel/1.png" title=""/>
			    		<img width="780" height="348" style="display:none;" src="<?=RpCfg::cdnHost()?>/img/index-carousel/2.png" title=""/>
			    		<img width="780" height="348" style="display:none;" src="<?=RpCfg::cdnHost()?>/img/index-carousel/3.png" title=""/>
			    		<img width="780" height="348" style="display:none;" src="<?=RpCfg::cdnHost()?>/img/index-carousel/4.png" title=""/>
			        </div>
                </div>
               </div>
			</div>
		</div>
		
		<?PHP require_once(__DIR__.'/../phplib/board/index_promo_board.php'); ?>

</div>

<?PHP require_once(__DIR__.'/../phplib/board/index_partners_board.php'); ?>

<?php
}
//Run  Footer - empty pass
do_html_footer();
?>
</body>
</html>