$(document).ready(function(){
	//Drag Element
//auto hide calculator

$('#popWrapper').hide();

$("#popWrapper").draggable();

//Show Calculator

$('#showWindow').click(function(){
		$('#popWrapper').show();
	});

//Close window

$('.closepopup').click(function(){
		$('#popWrapper').hide();
	});


//Calculations
var interest = parseFloat($("#intRate").val());
var price = parseInt($('#price').val());
var months = parseFloat($('#months').val());
	$('#calculate').click(function(){
		if(parseInt($('#price').val()) <= 1499 && parseFloat($('#months').val()) <= 0.06579)
		{	
		alert('This monthly payment plan is only available when you purchase for R1500 to R2500');
		
		}
		else if(parseInt($('#price').val()) <= 2499 && parseFloat($('#months').val()) == 0.05193){
			alert('This monthly payment plan is only available when you purchase for R2500 onwards');
			}
			else{
				if($('#deposit').val() == ""){
			var res = parseInt($('#price').val())*parseFloat($('#months').val());
			var roundedOff = Math.ceil(res/10)*10;	
			if(isNaN(res)){
			alert('Wrong value!');
			}
			else{
				
		$('#result').val(roundedOff.toFixed(2));
		}
			}
		else{

	var deposit = parseInt($('#price').val())- parseInt($('#deposit').val());
		
			//var deposit = parseInt($('#price').val())- parseInt($('#deposit').val());
		var res = deposit*parseFloat($('#months').val());
		var roundedOff = Math.ceil(res/10)*10;	
		if(isNaN(res)){
			alert('Wrong value!');
			}
			else{
		$('#result').val(roundedOff.toFixed(2));
		}
		}
				
				}
		{
		
			}
			
	
		
		});
	
		$('#clear').click(function(){
			
			$('#price').val('');
			$('#deposit').val('');
			$('#result').val('00.00')	
		
			});

})
