$(document).ready(function () {
	$("#deposit_btn").click(function (event) {
		event.preventDefault();

		$("#errorPrompt").hide();
		$("#errorPrompt").html("");

		var amount = $("input#amount").val();
		var withdraw_id = $("input#withdraw_id").val();

		if (amount === "") {
			$("#deposit_btn").attr("disabled", true);
			return false;
		}
		
		if (withdraw_id === "") {
		    $("#deposit_btn").attr("disabled", true);
		    return false;
		}

		$(".button_spinner").show();

		$("#payment_method").prop("disabled", true);

		$("input#amount_received").prop("disabled", true);

		var form_data = {
		    "payment_method": $("#payment_method option:selected").val(),
		    "amount": amount,
		    "withdraw_id": withdraw_id
		};

		$.ajax({
			url: "../helpers/charges-deposit",
			type: "POST",
			data: form_data,
		}).done(function (response) {
			$(".button_spinner").hide();

			if (response == "success") {
				window.location.href = "process-charges-deposit";
			} else {
				$("#payment_method").prop("disabled", false);
				$("#errorPrompt").show();
				$("#errorPrompt").html(response);
			}
		});

		return false;
	});
});
