<?php session_start();  ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>CoolDrivePass : Emission Calculator</title>
<script type="text/JavaScript">
<!--

 function CheckSelects( ) {
		if( document.getElementsByName("SelectYear")[0].value == "0" )
		{
			alert( "Please select a year" );
			return false;
		}
		if( document.getElementsByName("SelectMake")[0].value == "0" )
		{
			alert( "Please select a make" );
			return false;
		}
		if( document.getElementsByName("SelectModel")[0].value == "0" )
		{
			alert( "Please select a model" );
			return false;
		}
		return true
	}
	
function Load()
{
	MM_preloadImages('/images/buttons/buttons_color_02.gif','/images/buttons/buttons_color_03.gif','/images/buttons/buttons_color_04.gif','/images/buttons/buttons_color_05.gif');
	if( document.getElementsByName('SelectYear')[0].value != "0" )
	{
		showMakes(document.getElementsByName('SelectYear')[0].value)
	}
}

function reload(form)
{
	var val=form.cat.options[form.cat.options.selectedIndex].value;
	self.location='index.php?year=' + val ;
}

function reload1(form)
{
	var val=form.cat.options[form.cat.options.selectedIndex].value;
	var make=form.subcat.options[form.subcat.options.selectedIndex].value;
	self.location='index.php?year='+ val +'&make=' + make ;
}


//-->
</script>


<style type="text/css">


a:link {
	color: #999999;
	text-decoration: none;
}
a:visited {
	text-decoration: none;
	color: #999999;
}
a:hover {
	text-decoration: underline;
	color: #999999;
}
a:active {
	text-decoration: none;
	color: #999999;
}

</style></head>

<?php
/* Connection to MySQL Database*/
	  $host="server358.mysite4now.com";
      $user="cooladmin";
      $password="chillme";
	  $database="emissions";
	  //Connection
	  $cxn = mysqli_connect($host,$user,$password,$database);
	 
	 
	  $year_query="SELECT DISTINCT car_year_id,car_year
				   FROM car_years
				   ORDER BY car_year_id DESC";

	$year_result = mysqli_query($cxn,$year_query);
	
	 
	

	$year=$_GET['year'];
	$make=$_GET['make']; 
	if(isset($year) and strlen($year) > 0){

	$make_quer=mysqli_query($cxn,"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=mysqli_query($cxn,"SELECT CAR_ID,MODEL
							FROM car_emissions
							WHERE MAKE_TYPE_ID =".$make.
							" AND CAR_YEAR_ID =".$year.
							" ORDER BY MODEL"
						    );
	} 
?>


<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onLoad="Load()">
<p align="center">
  <!-- ImageReady Slices (layouts3.ai) -->
</p>
<div align="center">
  
  <table id="Table_02" width="674" border="0" cellpadding="0" cellspacing="0">
    
    <!-- InstanceBeginEditable name="MainRegion" -->
    <tr>
      
      <td align="right" valign="top">
        <table width="99%" border="0" cellpadding="0" cellspacing="0">
            <tr>
              <td width="64%" align="left" valign="bottom">
			  
			  <h3>Calculate your Emissions:</h3>
			  </td>
			  <td><img src="/images/chopped/gages_2.jpg" width="284" height="324"> </td>
            </tr>
            <tr valign="bottom">
              <td colspan="2" align="left" valign="top">
		      
              <form action="../offsetters_cool/car_result.php" method="POST" name="carselform" onSubmit="return CheckSelects()">
                  <table width="600" border="0">
                    <tr>
                      <td width="150">Year:</td>
                      <td width="440">
									<script src="getMakes.js"></script>
                                    <?php 
										echo "<select name='cat' onchange=\"reload(this.form)\"><option value=''>Select a year:</option>";
										while($noticia2 = mysqli_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>";}
     									}			
										echo "</select>";
									?>		
									 
								</td>
							</tr>
							<tr>
								<td width="150">Make:</td>
								<td width="440">
									<div id="makeList">
										<?php	
												////////// Starting of second drop downlist /////////
												echo "<select name='subcat' onchange=\"reload1(this.form)\"><option value=''>Choose a make:</option>";
												while($noticia = mysqli_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>";}
												}
												echo "</select>";
		     							?>
										</div>
								</td>
							</tr>
							<tr>
								<td width="150">Model:</td>
								<td width="440">
									<div id="modelList">
										<?php	
												////////// Starting of third drop downlist /////////
												echo "<select name='modelsubcat'><option value=''>Choose a model:</option>";
												while($noticia3 = mysqli_fetch_array($model_quer)) {
												echo "<option value='$noticia3[CAR_ID]'>$noticia3[MODEL]</option>";
												}
												echo "</select>";
		     							?>
									
										</div>
								</td>
                    </tr>
                    <tr>
                      <td>KM/Year:</td>
                      <td><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>
                      <span style="font-size: 10px; font-style: italic;">an average driver drives 20,000 Km per year.</span> </td>
                  </tr>
                  </table>
				  
				  <table width="600" border="0">
				  	<tr>
						<td width="150">How many years would you like to offset your emissions for?</td>
						
						<td width="440" valign="bottom">
							<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>
				  
                  <br>
                  <input type="Submit" name="submitBttn" value="Calculate Emissions">
                </form>
				
				<p><strong>Can&rsquo;t find your car? </strong></p>
				<p>Use our <a href="../offsetters_cool/backup_calc.php">backup calculator</a> to estimate your emissions based on engine size.<br>
				  or<br>
			    <a href="mailto:info@cooldrivepass.com">Contact us</a>&nbsp;and we will find and send you the  calculations for your vehicle.</p>
				<p>&nbsp;</p>
				<p><span class="style5">The statistics used  by CoolDrivePass were taken from the Fuel Consumption Guide published by  Natural Resources Canada, and were reproduced with the permission of the  Minister of Public Works and Government Services Canada. <br>
The fuel consumption of your vehicle  may differ from its published rating, depending on factors such as driving  style, vehicle acceleration, driving speed, the overall age and operating  condition of the vehicle, temperature, weather, traffic and road conditions. In  addition, power-driven accessories (e.g., air conditioning) that are installed  in your vehicle will also affect your fuel use.<br>
The fuel consumption ratings are  presented in accordance with vehicle make, model, engine size, type of  transmission, and fuel type. Annual fuel consumption and CO2  estimates are based on the Government of Canada&rsquo;s used ratio of 45% city to 55%  highway driving.</span> <br>
			    </p></td>
			    
            </tr>
            
          </table>
      </div></td>
     
    </tr>
    <tr>
      <td colspan="3" align="left" valign="top">
    </tr>
    </table>
  
</body>
</html>