(function($){var defaults={speed:1000,container:'',switcher:'',divError:'',dataType:'json',colorbox:false,hidden:true};$.fn.zagielCalc=function(o){var that=$(this);o=$.extend({},defaults,o||{});o.priceSpan=$('span[id^=product-price]:first');this.container=null;o.product2=$(document).find("#zagiel-product2");o.productProgress=$(document).find(".zprogress");o.container=$(this);o.switcher=$(document).find(".toggleCalc");o.form=$("#zagiel_calc_form");o.calculate=$("#calcButton");o.progress=$("#zagielProgress > div");o.progress.hide();o.divError=$(this).find(".error");if(!o.colorbox&&o.hidden)o.container.hide();if(!o.colorbox)o.switcher.bind("click",function(){toggleCalc();return false});else{}$('input[id^=bundle]').bind("change",function(){updatePrice()});$('input[id^=options]').bind("change",function(){updatePrice()});o.calculate.bind("click",function(){updateForm();return false});o.form.bind("submit",function(){updateForm()});function toggleCalc(){o.container.slideToggle(o.speed,function(){updateForm()})}function updatePrice(){$('#wartoscTowarow').val(clearPrice(o.priceSpan));$.ajax({type:'POST',url:o.symulatorUrl,data:o.form.serialize(),context:o.form,beforeSend:function(){o.productProgress.show()},success:function(data){if(data.error){}else{o.product2.find(".ilosc-rat").html(data.liczbaRat+"&nbsp;x&nbsp;");o.product2.find(".wysokosc-raty").html(data.wysokoscMiesiecznejRaty);o.product2.show(o.speed)}},error:function(){},complete:function(){o.productProgress.hide()},dataType:"json"})}function clearPrice(priceSpan){var p=priceSpan;while(p.length>0){prevP=p;p=p.children()}p=prevP.html();return p.replace('&nbsp;',' ')}function updateForm(){if(o.container.css('display')!='none'){$.ajax({type:'POST',url:o.symulatorUrl,data:o.form.serialize(),context:o.form,beforeSend:function(){progressShow();o.divError.hide();$("#klauzula").hide()},success:function(data){if(data.error){o.divError.html(data.error);o.divError.show();$("#wysokoscRaty").val('');$("#kosztyKredytu").val('');$("#klauzula").html('')}else{$("#wartoscTowarow").val(data.kwotaKredytu);$("#wplataWlasna").val(data.wplataWlasna);$("#wysokoscRaty").val(data.wysokoscMiesiecznejRaty);$("#kosztyKredytu").val(data.kosztKredytu);$("#klauzula").html(data.klauzula);$("#klauzula").show()}},error:function(){errorHandle()},complete:function(){progressHide()},dataType:"json"})}}function progressShow(){o.progress.show()}function progressHide(){o.progress.hide()}function errorHandle(){}updatePrice()}})(jQuery);
