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

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

		$("#deposit_btn").attr("disabled", "");

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

		if (amount === "") {
			$(".amount_feedback").html(
				"Amount cannot be empty."
			);
			$(".amount_feedback").show();
			$("input#amount").focus();

			$("#deposit_btn").removeAttr("disabled");
			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;

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

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

		return false;
	});
});
