$(document).ready(function(){
   	
	// $("p").css("color", "red");
	
	$('#donation-amt').keyup(function() {
		// Set some variables
	    var amt = Number($('#donation-amt').val());
	        var total = 0;
	        var fee = 0;
	        var newtotal = (amt * 1.029) + .3;
	        newtotal = newtotal.toFixed(2);

	        // Repeat the calculations until the error
	        // is less than a (rounded) penny
	    do {
	            total = newtotal;
	            newtotal = amt + (total * .029) + .3;
	            newtotal = newtotal.toFixed(2);
	    } while (total != newtotal);

	        fee = total - amt;

	        // Assign the values
	        $('#trans-fee').val(fee.toFixed(2));
	    	$('#total-amt').val(total).css("background", "#f5df88");
			$('#donation-amt').css("background", "none");
			$('#amount').val(total);
			
			$('#include-fee').attr("disabled","").attr("checked","checked");
			$('#donate-now').attr("disabled","");
			$('.disabled').css("color","#000");
			
	});
	
	$('#include-fee').click(function() {
		
		var donation = $('#donation-amt').val();
		var total = $('#total-amt').val();
		
		if ($(this).is(':checked')) {
			$('#total-amt').css('background','#f5df88');
			$('#donation-amt').css('background', 'none');
			$('#amount').val(total);
		} else {
			$('#donation-amt').css('background','#f5df88');
			$('#total-amt').css('background', 'none');
			$('#amount').val(donation);
		}
	});
	
	
	$('#donate-now').click(function(){
		$('#process').submit();
	});
	
	$('#donation-amt').keyup();
});