var el; function showCart() { path = '/cart.html?tmp='+(new Date().getTime()); jQuery.ajax({ type:'POST', dataType:'html', data: jQuery('#orderFormFrm').serialize(), success: function(html) { $('#cartShortView').html(''); $('#cartShortView').append(html); }, failure: function() { $('#itemsView').html('Błąd pobierania informacji o koszyku'); }, url: path}); } function notify(msg) { getNotifier(); if( !el.is(":visible") ) { el.fadeIn('fast'); } if(msg.style) { el.addClass(msg.style); } if(el.find('.inner').length) { el.find('.inner').html(msg.body); } else { el.html(msg.body); } var delay = 0; if(msg.delay) { delay = msg.delay; } el.delay(delay).fadeOut(800); } function getNotifier() { if(!el) { el = $('#notifier'); } el.removeClass() .click(function() {el.stop().hide().css('opacity',1)}) .addClass('jsNone') .css('top',$(window).height()/2+$(window).scrollTop()-(el.height()/2)) .css('left',$(window).width()/2-(el.width()/2)); } function startIndicator() { getNotifier(); html = 'Czekaj...
'; if(el.find('.inner').length) { el.find('.inner').html(html); } else { el.html(html); } el.stop(true, true); el.fadeIn('fast'); } function stopIndicator() { if(el) { el.fadeOut(800); } } var rv = -1; var ua = navigator.userAgent; var re = new RegExp("Trident\/([0-9]{1,}[\.0-9]{0,})"); if (re.exec(ua) != null) { rv = parseFloat(RegExp.$1); } var isIe8 = (rv == 4); var lastclick=0; function addToCart(id,pfx) { clicktime = new Date().getTime(); if(isIe8 && clicktime-lastclick <=100) { return false; } lastclick = clicktime; startIndicator(); path='/cart/add.html'; try { ile = $('#'+(pfx?pfx:'')+'buyNow_'+id+' input[name=qty]').val(); } catch(e) { ile = 1; } var failed=false; jQuery.ajax({ type:'POST', dataType:'json', data: 'products_id='+id+'&qty='+ile, success: function(data, textStatus) { if(data.style=='jsSuccess' || data.max==0 ) { notify(data); } else { failed = true; showCartOptions(data); } }, complete: function() { showCart(); if(!failed) { stopIndicator(); } }, url: path}); } function reloadItems() { path = '/order_items.html'; jQuery.ajax({ type:'POST', dataType:'html', success: function(data, textStatus) { $('#itemsView').html(''); $('#itemsView').append(data); }, failure: function() { $('#itemsView').html('Błąd pobierania informacji o zamówieniu'); }, url: path}); } function modifyItem(id,del) { startIndicator(); var modParam = ''; if( !del ) { modParam += '&modify=1'; } path='/order_update_item.html'; ile = $('#frm_'+id+' input[name=qty]').val(); jQuery.ajax({ type:'POST', dataType:'json', data: 'products_id='+id+'&qty='+ile+modParam, success: function(data, textStatus) { reloadItems(); notify(data); showCart(); stopIndicator(); }, failure: function() { stopIndicator(); }, url: path}); } function incQty(id) { val = parseInt($('#'+id).val()); val++; $('#'+id).val(val); } function decQty(id) { val = parseInt($('#'+id).val()); val--; if( val <= 0 ) val = 1; $('#'+id).val(val); } function acceptableDialog(txt) { if($('#cartOptions').length) { $('#cartOptions').remove(); } stopIndicator(); $(document.body).append( '
'+ '
'+ txt+'
'+ 'Zamknij'+ '
'+ '
'); $('#closeCartOptions').click(function(){ $('#cartOptions').remove(); return false; }); getNotifier(); el = $('#notifier'); $('#cartOptions') .css('top',$(window).height()/2+$(window).scrollTop()-(el.height()/2)) .css('left',$(window).width()/2-(el.width()/2)) .css('display','block') .fadeIn(); } function showCartOptions(data) { if($('#cartOptions').length) { $('#cartOptions').remove(); } if(data.max) { stopIndicator(); $(document.body).append( '
'+ '
'+ 'W sklepie '+numSuff(data.max,['dostępna jest', 'dostępne są', 'dostępnych jest'])+' '+data.max+' opakowa'+numSuff(data.max,['nie', 'nia', 'ń'])+' tego produktu.
'+ 'Dodaj całą dostępną ilośćAnuluj'+ '
'+ '
'); $('#addMaxToCart').click(function(){ $.ajax({ url: "/cart/add_max.html?products_id="+data.productId, success: function(html) { showCart(); $('#cartOptions').remove(); } }); return false; }); } else { notify(data); } $('#closeCartOptions').click(function(){ $('#cartOptions').remove(); return false; }); $('#cartOptions') .css('top',el.position().top) .css('left',el.position().left) .css('display','block') .fadeIn(); } function showOrderOptions() { $('#orderOptions') .css('top',$(window).height()/2-($('#orderOptions').height()/2)) .css('left',$(window).width()/2-($('#orderOptions').width()/2)) .css('display','block') .html( '
'+ ''+ '
') .fadeIn('fast').click(function() {$('#orderOptions').hide()}); $(window).stop().scrollTo( '#header', 800 ); } function submitOrderForm() { $('#orderForm').append(''); $('#orderFormSbmt').click(); } $(document).ready(function() { $('.buyNowForm').submit(function(){ $(this).find('.confirmBuy').click(); return false; }); });