var loaded = 1;

var igScotiabankForm = document.getElementById("ig-scotiabank-form");
var placeOrderButton = document.getElementById("place_order");
var scotiaPaymentForm = document.getElementById("scotia-payment-form");
var scotiaHostedFrame = document.getElementById("ig-scotiabank-hosted-frame");
var hasSubmittedScotiaForm = false;
// Checkout templates can vary by theme/plugins, so guard node access before using gateway elements.

if (igScotiabankForm) {
	igScotiabankForm.scrollIntoView();
}

if (placeOrderButton) {
	placeOrderButton.disabled = true;
}

if (scotiaPaymentForm) {
	// Keep hosted-form submission one-shot to avoid duplicate gateway session starts.
	if (!hasSubmittedScotiaForm) {
		hasSubmittedScotiaForm = true;
		scotiaPaymentForm.submit();
	}
}

if (scotiaHostedFrame) {
	scotiaHostedFrame.onload = function() {

	jQuery( function($) {
        
		// Targeting checkout checkout payment and Review order table like Woocommerce does.
		var a = ".woocommerce-checkout-payment, .woocommerce-checkout-review-order-table";
		var $targets = $(a);
		var canUnblock = typeof $.fn.unblock === "function";

		// Themes/plugins can change checkout blocking behavior, so only unblock when blockUI is actually active.
		if (canUnblock && $targets.length > 0) {
			var isBlocked = $targets.data("blockUI.isBlocked");

			if (1 == isBlocked) {
				$targets.unblock();
			}
		}

		if (igScotiabankForm) {
			igScotiabankForm.style.display = "none";
		}

	});

	if ( "none" == scotiaHostedFrame.style.display ) {

		scotiaHostedFrame.style.display = "block";
	}
};
}
