$(document).ready(function() {
	// Parking calculator
	 $(function() {
		$('#TextBox1').datetimepicker();
		$('#TextBox2').datetimepicker();
	
		$('#calculate').click(function() {
			var start = $('#TextBox1').val();
			var end = $('#TextBox2').val();
			var days = 0;
			var amount = 0;
			var differenceInHours = (Date.parse(end) - Date.parse(start))/1000/60/60;
			if (differenceInHours > 24){
				var val = (differenceInHours / 24);
				days = Math.floor(val);
				differenceInHours = ( differenceInHours - ( days * 24 ) );
			};
			if(days < 1){
				if ( differenceInHours < 0.5){ $('#amount').html("R"+ amount); }
				else if (differenceInHours > 0.5 && differenceInHours <= 1){ $('#amount').html("R" + (10 + amount)); }
				else if (differenceInHours > 1 && differenceInHours <= 2){ $('#amount').html("R" + (12 + amount)); }
				else if (differenceInHours > 2 && differenceInHours <= 3){ $('#amount').html("R" + (15 + amount)); }
				else if (differenceInHours > 3 && differenceInHours <= 4){ $('#amount').html("R" + (20 + amount)); }
				else if (differenceInHours > 4 && differenceInHours <= 5){ $('#amount').html("R" + (24 + amount)); }
				else if (differenceInHours > 5 && differenceInHours <= 6){ $('#amount').html("R" + (29 + amount)); }
				else if (differenceInHours > 6 && differenceInHours <= 8){ $('#amount').html("R" + (32 + amount)); }
				else if (differenceInHours > 8 && differenceInHours <= 12){ $('#amount').html("R" + (42 + amount)); }
				else if (differenceInHours > 12 && differenceInHours <= 14){ $('#amount').html("R" + (50 + amount)); }
				else if (differenceInHours > 14 && differenceInHours <= 24){ $('#amount').html("R" + (80 + amount)); }
			}else if ( days >= 1 ){
				
				if (days > 1){
					cash = ( days * 80);
					amount = (cash);
				}else{
					amount = 80;
				}
				if (differenceInHours > 0 && differenceInHours <= 1){ $('#amount').html("R" + (10 + amount)); }
				else if (differenceInHours > 1 && differenceInHours <= 2){ $('#amount').html("R" + (12 + amount)); }
				else if (differenceInHours > 2 && differenceInHours <= 3){ $('#amount').html("R" + (15 + amount)); }
				else if (differenceInHours > 3 && differenceInHours <= 4){ $('#amount').html("R" + (20 + amount)); }
				else if (differenceInHours > 4 && differenceInHours <= 5){ $('#amount').html("R" + (24 + amount)); }
				else if (differenceInHours > 5 && differenceInHours <= 6){ $('#amount').html("R" + (29 + amount)); }
				else if (differenceInHours > 6 && differenceInHours <= 8){ $('#amount').html("R" + (32 + amount)); }
				else if (differenceInHours > 8 && differenceInHours <= 12){ $('#amount').html("R" + (42 + amount)); }
				else if (differenceInHours > 12 && differenceInHours <= 14){ $('#amount').html("R" + (50 + amount)); }
				else if (differenceInHours > 14 && differenceInHours <= 24){ $('#amount').html("R" + (80 + amount)); }else{
					$('#amount').html("R" + (amount));
				}
			};
		});
	});
	$(function() {
		$('#TextBox1l').datetimepicker();
		$('#TextBox2l').datetimepicker();
	
		$('#calculatel').click(function() {
			var start = $('#TextBox1l').val();
			var end = $('#TextBox2l').val();
			var days = 0;
			var amount = 0;
			var differenceInHours = (Date.parse(end) - Date.parse(start))/1000/60/60;
			
			if (differenceInHours > 24){
				var val = (differenceInHours / 24);
				days = Math.ceil(val);
				//console.log(days);
				differenceInHours = (differenceInHours - (days * 24));
				if( days <= 3 && days != 0){
					amount = ( days * 80);
				}
				else if( days > 3 && days <= 6) 
				{
					days = Math.round(days);
					days = (days - 3);
					var total = ( days * 60 );
					amount = (total + 240);
					
					
				}else if( days >= 7 ){
					days = (days - 6);
					var total = ( days * 30 );
					amount = (total + 420);
					//console.log(total);
				}
				
				if(differenceInHours < 1 ){
					$('#amountl').html("R"+ amount );
				}
			}
			
			if(days < 1){
			if ( differenceInHours < 0.5){ $('#amountl').html("R"+ amount); }
			else if (differenceInHours > 0.5 && differenceInHours <= 1){ $('#amountl').html("R" + (10 + amount)); }
			else if (differenceInHours > 1 && differenceInHours <= 2){ $('#amountl').html("R" + (12 + amount)); }
			else if (differenceInHours > 2 && differenceInHours <= 3){ $('#amountl').html("R" + (15 + amount)); }
			else if (differenceInHours > 3 && differenceInHours <= 4){ $('#amountl').html("R" + (20 + amount)); }
			else if (differenceInHours > 4 && differenceInHours <= 5){ $('#amountl').html("R" + (24 + amount)); }
			else if (differenceInHours > 5 && differenceInHours <= 6){ $('#amountl').html("R" + (29 + amount)); }
			else if (differenceInHours > 6 && differenceInHours <= 8){ $('#amountl').html("R" + (32 + amount)); }
			else if (differenceInHours > 8 && differenceInHours <= 12){ $('#amountl').html("R" + (42 + amount)); }
			else if (differenceInHours > 12 && differenceInHours <= 14){ $('#amountl').html("R" + (50 + amount)); }
			else if (differenceInHours > 14 && differenceInHours <= 24){ $('#amountl').html("R" + (80 + amount)); }
			}else{						 
				$('#amountl').html("R"+ amount);
			};
			
		});
	});
});
