
/* tools/driveway_sealer_calculator.js */

 var MMH;
if (typeof MMH === 'undefined') {
	MMH = {};
}
(function () {
	MMH.Calculator.DrivewaySealer = {
		init: function() {
			/* Load the params, if any */
			var params =location.href.toQueryParams();
			if(params.length) {
				$('length').value = params['length'].replace("%20"," ");
			} if(params.width) {
				$('width').value = params['width'].replace("%20"," ");
			} if(params.parking_spaces) {
				$('total_parking_spaces').value = params['parking_spaces'].replace("%20"," ");
			}
		},
		validationRules: { 
			js_validate_area: { is_float: true, is_present: true, message: 'Please enter a width and length in feet' },
			js_validate_parking_spaces: { is_float: true, is_present: true, message: 'Please enter the total parking spaces' }
		},
		calculate_by_area: function() {
			PAIL_SQUARE_FEET_COVERAGE = 400; 
			
			/* Calculations */
			area = MMH.Calculator.getArea($('width'), $('length'));
			number_of_pails = area / PAIL_SQUARE_FEET_COVERAGE;
			number_of_pails = Math.ceil(number_of_pails);
			
			/* Update the UI */
			$('pail_amount').innerHTML = number_of_pails;
			$('square_feet_amount').innerHTML = area.toFixed(0);
			$('parking_spaces_result').hide();
			$('square_feet_result').show();
		},
		calculate_by_parking_spaces: function() { 
			PAIL_PER_PARKING_SPACE = 2;
			 
			/* Calculations */
			number_of_pails = parseFloat($('total_parking_spaces').value) / PAIL_PER_PARKING_SPACE;
			number_of_pails = Math.ceil(number_of_pails);

			/* Update the UI */
			$('pail_amount').innerHTML = number_of_pails;
			$('parking_spaces_amount').innerHTML = $('total_parking_spaces').value;
			$('square_feet_result').hide();
			$('parking_spaces_result').show();
		}
	};
})();
