$(document).ready(function () {
	$('input.confirmGiftAid').click(function (e) {
		e.preventDefault();
		var id = this.id;
		confirm(id, 
				function () {
					//alert('yes');
					// set value of gift aid hidden field to 'giftaid'
					$('input[name=giftaid]').val('giftaid');
					$('#form'+id).submit();
				}, 
				function () {
					//alert('no');
					$('#form'+id).submit();
				}
		);
	});
});

function confirm(id, callbackYes, callbackNo) {
	$('#giftaid-popup'+id).modal({
		close:false,
		position: ["45%","35%"],
		overlayId:'modalBackground', 
		opacity: 80, 
		onShow: function (dialog) {

			// if the user clicks "yes"
			dialog.data.find('.yes').click(function () {
				// call the callback
				if ($.isFunction(callbackYes)) {
					callbackYes.apply();
				}
				// close the dialog
				$.modal.close();
			});
			
			// if the user clicks "yes"
			dialog.data.find('.no').click(function () {
				// call the callback
				if ($.isFunction(callbackNo)) {
					callbackNo.apply();
				}
				// close the dialog
				$.modal.close();
			});
		}
	});
}