function checkoutInit(url) {
	$ipsp('checkout').scope(function() {
		this.setCheckoutWrapper('#checkout_wrapper');
		this.addCallback(__DEFAULTCALLBACK__);
		this.action('show', function(data) {
			$('#checkout_loader').remove();
			$('#checkout').show();
		});
		this.action('hide', function(data) {
			$('#checkout').hide();
		});
		this.action('resize', function(data) {
			$('#checkout_wrapper').width($('#payment_cont .modal-body').width()).height(data.height);
		});
		this.loadUrl(url);
	});
};

$(document).ready(function() {
    $('.formBr>label').on('click', function() {
      $(this).next().val('');
    });
});
  
$(document).on('click', '.btn-payment-old', function (e) {
	var thisObj = $(this);
	var vinValue = $('#new_form_form_name').val();
	if(vinValue) {
		
		var url = thisObj.data('url')+'?vin='+vinValue;
		var email = '';
		if(thisObj.data('email')) {
			email = thisObj.data('email');
		}
		$.ajax({
			url: url,
			dataType: 'json',
			data: {ajax_r: 1, email: email},
			type: 'post',
			beforeSend:function(){
				thisObj.addClass('loading');
			},
			success: function (result)
			{
				$('.model-payment-body').html(result.popupContent);
				if(result.payForm==1) {
					var button = $ipsp.get("button");
					button.setMerchantId(result.paymentData.app_id);
					button.addParam('order_id', result.paymentData.order_id);
					button.addParam('response_url', result.paymentData.returnUrl);
	//				button.addParam('server_callback_url', result.paymentData.server_callback_url);
					button.setAmount(result.paymentData.price, 'USD', true);
					button.addField({
							label:'Your email',
							name:'email',
							value:result.paymentData.email,
							required:true,
							placeholder:'Enter Your email',
							valid:{
								'pattern':'^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$'
							}
						});
					button.setHost('pay.fondy.eu');
					checkoutInit(button.getUrl());
				} else {

				}

				$('#payment_cont').modal('show');

				thisObj.removeClass('loading');
			},
			error : function (xhr, textStatus, errorThrown) {

				thisObj.removeClass('loading');
			},
			complete : function (){
				thisObj.removeClass('loading');
			}
		});

	} else {
		alert('VIN should be filled');
	}

});
