<?php
session_start();

/* Connection to MySQL Database*/
$host = "server358.mysite4now.com";
$user = "cooladmin";
$password = "chillme";
$database = "emissions";

mysql_select_db($database, mysql_connect($host, $user, $password));

$year_query = "SELECT DISTINCT car_year_id, car_year FROM car_years ORDER BY car_year_id DESC";
$year_result = mysql_query($year_query);

$year=$_GET['year'];
$make=$_GET['make'];

if(isset($year) and strlen($year) > 0) {
	$make_quer=mysql_query("SELECT	MAKE_TYPE, MAKE_TYPE_ID, consumption, emission FROM car_emissions WHERE CAR_YEAR_ID = ".$year." GROUP BY MAKE_TYPE");
}

if(isset($make) and strlen($make) > 0) {
	$model_quer=mysql_query("SELECT CAR_ID, MODEL FROM car_emissions WHERE MAKE_TYPE_ID = ".$make." AND CAR_YEAR_ID = ".$year." ORDER BY MODEL");
}
?>
<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.autocomplete.js"></script>
	<script type="text/javascript" src="jquery.rounded.js"></script>
	<script type="text/javascript" src="car.js"></script>
	<script type="text/javascript" src="plane.js"></script>
	
	<link rel="stylesheet" type="text/css" href="screen.css" />
	<link rel="stylesheet" type="text/css" href="jquery.autocomplete.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'); height:20px; background-repeat:no-repeat;">&nbsp;</div>
			<div id="chooser">
				<a href="#" id="car">Vehicle</a>
				<a href="#" id="plane">Air</a>
			</div>
			
			<div id="planeForm"<?php if(isset($_GET['calc']) && $_GET['calc'] != 'air') { echo " style=\"display:none;\""; } elseif(!isset($_GET['calc'])) { echo " style=\"display:none;\""; } ?>>
				<form action="plane_result.php" method="post" onsubmit="return formValidator()">
					<fieldset>
						<table width="435">
							<tr>
								<td><div class="label"><label>Is your trip</label></div></td>
								<td align="right">
									<label><input name="routing" type="radio" value="oneway" <?php echo (($_SESSION['routing'] == "oneway") ? 'checked="checked"' : "" ) ?> /> One way</label>
									<label><input name="routing" type="radio" value="return" <?php echo (($_SESSION['routing'] != "oneway") ? 'checked="checked"' : "" ) ?> /> Return</label>
								</td>
							</tr>
						
							<tr>
								<td><div class="label"><label>Origin</label></div></td>
								<td align="right"><input name="origin" id="origin" class="ajax align_right" type="text" value="<?php echo $_SESSION['origin'] ?>" size="24" class="textfield" /></td>
							</tr>
						
							<tr>
								<td><div class="label"><label>Destination</label></div></td>
								<td align="right"><input name="destination[]" class="ajax align_right" type="text" value="<?php echo $_SESSION['destination'][0]; ?>" size="24" class="textfield" /></td>
							</tr>
							
							<tr>
								<td><div class="label"><label>Number of travellers</label></div></td>
								<td align="right"><input name="passengers" id="passengers" type="text" value="<?php echo isset($_SESSION['passengers']) ? $_SESSION['passengers'] : '1' ?>" size="5" class="align_right" /></td>
							</tr>
						</table>
						
						<input class="submit" type="image" value="calculate" src="calculate.jpg" style="margin-left:10px;" />
					</fieldset>
				</form>
			</div>
			
			<div id="carForm"<?php if(isset($_GET['calc']) && $_GET['calc'] != 'car') { echo " style=\"display:none;\""; } ?>>
				<form action="car_result.php" method="POST" name="carselform" onsubmit="return CheckSelects();">
					<fieldset>
						<table width="435">
							<tr>
								<td><div class="label"><label>Year</label></div></td>
								<td align="right">
									<select name="cat" onchange="reload(this.form)">
										<option value="">Select a year</option>
						                <?php 
						                while($noticia2 = mysql_fetch_array($year_result)) {
						                	if($noticia2['car_year_id']==@$year) {
						                		echo "<option selected value='$noticia2[car_year_id]'>$noticia2[car_year]</option>"."<BR>";
						                	} else {
						                		echo "<option value='$noticia2[car_year_id]'>$noticia2[car_year]</option>";
						                	}
						                }
										?>
									</select>
								</td>
							</tr>
							
							<tr>
								<td><div class="label"><label>Make</label></div></td>
								<td align="right">
									<select name="subcat" onchange="reload1(this.form)">
										<option value="">Choose a make:</option>
										<?php	
										while($noticia = mysql_fetch_array($make_quer))	{
											if($noticia['MAKE_TYPE_ID']==@$make) {
												echo "<option selected value='$noticia[MAKE_TYPE_ID]'>$noticia[MAKE_TYPE]</option>"."<BR>";
											} else {
												echo "<option value='$noticia[MAKE_TYPE_ID]'>$noticia[MAKE_TYPE]</option>";
											}
										}
										?>
									</select>								
								</td>
							</tr>
							
							<tr>
								<td><div class="label"><label>Model</label></div></td>
								<td align="right">
									<select name="modelsubcat">
										<option value="">Choose a model:</option>
										<?php
										while($noticia3 = mysql_fetch_array($model_quer)) {
											echo "<option value='$noticia3[CAR_ID]'>$noticia3[MODEL]</option>";
										}
										?>
									</select>
								</td>
							</tr>
							
							<tr>
								<td><div class="label"><label>KM/Year</label></div></td>
								<td align="right">
				            		<select name="kmselect">
				                        <option value="3000">3,000</option>
				                        <option value="5000">5,000</option>
				                        <option value="10000">10,000</option>
				                        <option value="12000">12,000</option>
				                        <option value="16000">16,000</option>
				                        <option value="20000" selected>20,000</option>
				                        <option value="24000">24,000</option>
				                        <option value="32000">32,000</option>
				                        <option value="40000">40,000</option>
				                        <option value="45000">45,000</option>
				                        <option value="50000">50,000</option>
				                        <option value="60000">60,000</option>
				                        <option value="80000">80,000</option>
				                        <option value="100000">100,000</option>
				                        <option value="110000">110,000</option>
				                        <option value="120000">120,000</option>
				                        <option value="140000">140,000</option>
				                        <option value="160000">160,000</option>
				                  	</select>								
								</td>
							</tr>
							
							<tr>
								<td><div class="label"><label>Years of offsetting</label></div></td>
								<td align="right">
									<select name="xyears">
										<option value="1">1 Year</option>
										<option value="2">2 Years</option>
										<option value="3">3 Years</option>
										<option value="4">4 Years</option>
										<option value="5">5 Years</option>	
							  		</select>								
								</td>
							</tr>
						</table>

						<input class="submit" type="image" value="calculate" name="submitBttn" src="calculate.jpg" style="margin-left:10px;" />
					</fieldset>
				</form>
			</div>
			<div style="background-image:url('bottom-corners.jpg'); background-position:bottom; background-repeat:no-repeat;">&nbsp;</div>			
		</div>		
	</div>
	
	<script type="text/javascript">
		$('.label').corner();
		
		$('a#car').click(function(){
			$('#carForm').show();
			$('#planeForm').hide();
		});
		
		$('a#plane').click(function(){
			$('#planeForm').show();
			$('#carForm').hide();
		});
	</script>	
</body>

</html>