// JavaScript Document
			
			// function reduceTotal(JQuery targetElement, float reductionAmount)
			function reduceTotal(targetElement, reductionAmount) {
				newTotal =  parseFloat(targetElement.html()) - parseFloat(reductionAmount);
				newTotal = Math.round(newTotal*100)/100;
				targetElement.html(newTotal);
			}

			function calculateElectricityEmissions() {		
				amount = $("#electricity_amount").val();
				periodMultiplier = $("input[@name='electricity_period_multiplier']:checked").val();
				locationMultiplier = $("#electricity_location_multiplier").val();
				var emissions = (amount * periodMultiplier * locationMultiplier) / 1000;
				$('#hidden-electricity-period').val($("input[@name='electricity_period_multiplier']:checked").attr('id'));
				
				if ( emissions > 0 ) {
					displayElectricityEmissions( emissions, $("#totalElectricityEmissions") );
					$("#add_electricity").disabled = false;
					$("#add_electricity").attr('disabled', false);
					$("#totalEmissionsSection").css("display", "block");
				}
			}
			
			// displayElectricityEmissions(float emissionAmount, JQuery displayElement)
			function displayElectricityEmissions( emissionAmount, displayElement ) {
				emissionAmount = Math.round(emissionAmount*100)/100;
				displayElement.html( emissionAmount );
				$("#hidden-electricity-emissions").val(emissionAmount);
				
				$("#hidden-electricity-province").val($("#electricity_location_multiplier option:selected").text());	
			}







				// this is all the stuff that runs once the DOM for the page is ready, like onLoad but without the wait for images.
				$(document).ready(function(){
					
					// add the code to delete an entry from the summary list on clicking the delete link.
					$(".delete_entry").click( function() {
						// check the user really wants to do that.
						var answer = confirm("Delete this entry?");
						if (answer) {
							// hide the record from the page.
							$(this).parent().parent().hide();

							reduceTotal($("#electricity-emissions-total"), parseFloat($(this).parent().prev().html()));

							// setup the URL to the PHP page that will actually remove the record from the DB.
							deleteURL = "./includes/delete-db-record.php?action=deleterecord&table=emissions&id=" + $(this).attr('id');

							// do an AJAX call in the background to delete the DB record.
							$.get(deleteURL);
							updateTotalDisplay();
							showHideTable($("#electricity-summary"), $("#electricity-emissions-total"));
						}
						});

					// setup watch for events that should trigger recalculation
					
					$("input[@name='electricity_period_multiplier']").click(function(){
						calculateElectricityEmissions();
					});

					$("#electricity_amount").blur( function() {
						calculateElectricityEmissions();
						});

					$("#electricity_period_multiplier").change( function() {
						calculateElectricityEmissions();
						});	

					$("#electricity_location_multiplier").change( function() {
						calculateElectricityEmissions();
						});	

					showHideTable($("#electricity-summary"), $("#electricity-emissions-total"));

				}); // $(document).ready ENDS
