var Payment = new Object;

Payment.init = function() {
	var id = $('payment__method').value;	
	Payment.setMethod(id);
}

Payment.setMethod = function(id) {
	$('payment__method').value = id;
	if(id == 3) {
		$$('.row_advance').each(function(e){ e.hide(); })
		$$('.row_full').each(function(e){ e.show(); })
	} else {
		$$('.row_advance').each(function(e){ e.show(); })
		$$('.row_full').each(function(e){ e.hide(); })
	}
}

Payment.validateCard = function() {
	var resp = function(req) {
		var rsp = req.responseJSON;
		Navi.lock = false;
		$('res_loading').hide();
		if (rsp.valid) {
			Reservation.submitBooking();
		} else {
			Validate.showError('payment_card_error',$('card_error_txt').value);
			//alert('Dane karty są nieprawidłowe.');
		}
	}
	
	var pars = Form.serialize('res_form');
	
	var url = 'validatecard'
	var url = url.replace('http://localhost/','');
	var url = Global.get('link_path')+url;		
				
	var myAjax = new Ajax.Request(url,{ method: 'post',parameters: pars,evalScripts: true,onComplete:resp});		
	//Navi.timeout = Navi.showLoading.delay(0.3);
	if($('res_loading')) { $('res_loading').show(); }
	Navi.lock = true;
}

