<?php include('plane.inc.php'); ?>
<html>
<head>
	<title>Offsetters: Carbon Offset Calculator</title>
	<script type="text/javascript" src="jquery-1.2.3.pack.js"></script>
	<script type="text/javascript" src="jquery.rounded.js"></script>
	
	<link rel="stylesheet" type="text/css" href="screen.css" />
</head>

<body>
	<div id="faux">
		<div id="copy">
			<img src="logo.jpg" />
			<h1>Purchase Carbon Offsets</h1>
		</div>
	
		<div id="container">
			<div style="background-image:url('top-corners.jpg'); background-repeat:no-repeat;">&nbsp;</div>
			
			<?php if($error) { ?>
			<p><?php echo $error; ?></p>
			<?php } else { ?>
			<div id="resultsPlane">
				<h3>Origin</h3>
				<p><?php echo $origin; ?></p>
				
				<?php if(sizeof($_POST['destination'] > 1)) { ?>
				<?php
				for($i = 0; $i < sizeof($_POST['destination']); $i++) {
						//echo '<h3>Destination #'.($i+1).'</h3>';
						echo '<h3>Destination</h3>';
						if($i == 0) {
							$distance = round(distance($orglat, $orglong, $deslat[$i], $deslong[$i], "K"));
							$total_distance = $total_distance + $distance;
							echo '<p>'.$destination[$i].'</p>';
							echo '<p>'.$distance.' km';
						} else {
							$distance = round(distance($deslat[$i-1], $deslong[$i-1], $deslat[$i], $deslong[$i], "K"));
							$total_distance = $total_distance + $distance;				
							echo ''.$destination[$i].''.$distance.' km';
						}
					}
				} else {
					echo '<h3>Destination</h3>';
					echo '<p>'.$destination[0].''.distance($orglat, $orglong, $deslat[0], $deslong[0], "K").'</p>';
				}
				?>
				
				<h3>Number of travellers</h3>
				<p><?php echo $_POST['passengers']; ?> <span style="font-weight: normal">passenger(s)</span> <?php echo $_SESSION['flight']; ?> trip</p>
				
				<h3>Total distance traveled</h3>
				<p><?php echo ($route * $total_distance); ?> km</p>
	
				<?php
				$cton += round(emission($route * $total_distance) / 1000, 3);
				$number = $_POST['passengers'] * $cton * 20;
				?>
				
				<h3>Total trip emissions</h3>
				<p><?php echo round(emission($route * $total_distance)); ?> kg of CO2e</p>
				
				<h3>Total offset cost to make your trip climate friendly</h3>
				<p><span id="total">$<?php echo number_format($number, 2, '.', ''); ?></span>CDN</p>
				
				<?php if ($_SESSION['passengers'] > 1) { ?>
				<p>$<?php echo number_format($number / $_SESSION['passengers'], 2, '.', ''); ?> CDN per person</p>
				<?php } ?>
			
				<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_blank" id="left-form">
				 	<input type="hidden" name="cmd" value="_xclick"/>
					<input type="hidden" name="business" value="offsetters@gmail.com"/>
					<input type="hidden" name="item_name" value="Whistler EcoPath - Carbon Offset"/>
					<input type="hidden" name="currency_code" value="CAD"/>
					<input type="hidden" name="amount" value="<?php echo $number; ?>" />
					<input class="submit" type="image" src="offsetnow.png">
				</form>
				<a href="index.php" title="Recalculate"><img src="recalculate.png" /></a>
			</div>
			<?php } ?>
			<div style="background-image:url('bottom-corners.jpg'); background-repeat:no-repeat;">&nbsp;</div>
		</div>
	</div>
</body>
</html>