String.prototype.trim = function () {
	return this.replace(/^\s*/, "").replace(/\s*$/, "");
}
String.prototype.makeFloat = function () {
	number = this.replace(/[^0-9\.]+/, '');
	if (number.trim() == '') {
		number = 0.00;
	} else {
		number = parseFloat(number);
	}
	return number.toFixed(2);
}

$(function(){
	
	// Step One - General
	$('#general_use_bill').change(function(){
		$('#compare-against-bill').hide();
		$('#compare-against-season').hide();
		if ($(this).val() == '1') {
			$('#compare-against-bill').show();
			$('#compare-against-season').hide();
		} else {
			$('#compare-against-bill').hide();
			$('#compare-against-season').show();
		}
	});
	$('#general_use_bill').change();
	
	$("#general_start_date,#general_end_date").datepicker({ 
		beforeShow: function(input) { 
			return {minDate: (input.id == "general_end_date" ? $("#general_start_date").datepicker("getDate") : null), 
				maxDate: (input.id == "general_start_date" ? $("#general_end_date").datepicker("getDate") : null)}; 
		}, 
		dateFormat: 'd M yy'
		
	});
	
	
	// Step Two - Indoor
	$('#indoor_showers').change(function(){
		if ($(this).val() > 0) {
			$('#indoor-shower-questions').show();
		} else {
			$('#indoor-shower-questions').hide();
		}
	});
	$('#indoor_bath').change(function(){
		if ($(this).val() > 0) {
			$('#indoor-bath').show();
		} else {
			$('#indoor-bath').hide();
		}
	});
	$('#indoor_dishwasher').change(function(){
		if ($(this).val() > 0) {
			$('#indoor-dishwasher').show();
		} else {
			$('#indoor-dishwasher').hide();
		}
	});
	$('#indoor_aircon').change(function(){
		if ($(this).val() > 0) {
			$('#indoor-aircon').show();
		} else {
			$('#indoor-aircon').hide();
		}
	});
	$('#indoor_showers').change();
	$('#indoor_bath').change();
	$('#indoor_dishwasher').change();
	$('#indoor_aircon').change();

	$('#indoor_showers_average,#general_consumption,#indoor_bath_weekly,#indoor_clothes_buckets,#indoor_clothes_loads,#indoor_dish_sink,#indoor_dishwasher_weekly,#indoor_aircon_hours').change(function() {
		$(this).val(String($(this).val()).makeFloat());
	});


	// Step Three - Outdoor
	$('#outdoor_garden').change(function(){
		if ($(this).val() > 0) {
			$('#outdoor-garden').show();
		} else {
			$('#outdoor-garden').hide();
		}
	});
	$('#outdoor_cars').change(function(){
		if ($(this).val() > 0) {
			$('#outdoor-cars').show();
		} else {
			$('#outdoor-cars').hide();
		}
	});
	$('#outdoor_pool').change(function(){
		if ($(this).val() > 0) {
			$('#outdoor-pool').show();
		} else {
			$('#outdoor-pool').hide();
		}
	});
	$('#outdoor_pool_hose').change(function(){
		if ($(this).val() > 0) {
			$('#outdoor-pool-hose').show();
		} else {
			$('#outdoor-pool-hose').hide();
		}
	});
	$('#outdoor_garden').change();
	$('#outdoor_cars').change();
	$('#outdoor_pool').change();
	$('#outdoor_pool_hose').change();
	
});
