function showCart() {
path = '/cart.html?tmp='+(new Date().getTime());
new Request.HTML({
url: path,
onSuccess: function(html) {
$('cartShortView').set('text','');
$('cartShortView').adopt(html);
},
onFailure: function() {
$('cartShortView').set('text', 'Błąd pobierania informacji o koszyku');
}}).send();
}
function notify(msg) {
el = $('notifier');
el.innerHTML = msg.body;
el.morph('.'+msg.style);
if( msg.style == 'jsSuccess' ) {
el.setStyle('background-image', 'url(/images/okno2_ok_kolorowy.gif)');
}
if( msg.style == 'jsFailure' ) {
el.setStyle('background-image', 'url(/images/okno2_error.gif)');
}
var hideEl = function(){ new Fx.Morph(this, {duration: 1000}).start({opacity: [1,0]}); };
hideEl.delay(msg.delay, el);
el.erase('class');
}
function startIndicator() {
el = $('notifier');
el.setStyle('display','block');
el.morph('.waiting');
el.innerHTML = 'Czekaj...
';
el.setStyle('background-image', 'url(/images/okno2_load.gif)');
el.setStyle('top', Window.getScrollTop()+250+'px');
new Fx.Morph(el, {duration: 500}).start({opacity: [0,1]});
}
function addToCart(id) {
startIndicator();
path='/cart/add.html';
ile = $('buyNow_'+id).qty.value;
new Request.JSON({
url: path,
onSuccess: function(result) {
showCart();
notify(result);
},
onFailure: function() {
showCart();
}
}).send('products_id='+id+'&qty='+ile);
}
function reloadItems() {
path = '/order_items.html';
new Request.HTML({
url: path,
onSuccess: function(html) {
$('itemsView').set('text','');
$('itemsView').adopt(html);
},
onFailure: function() {
$('itemsView').set('text', 'Błąd pobierania informacji o zamówieniu');
}}).send();
}
function modifyItem(id,del) {
startIndicator();
var modParam = '';
if( !del ) {
modParam += '&modify=1';
}
path='/order_update_item.html';
ile = $('frm_'+id).qty.value;
new Request.JSON({
url: path,
onSuccess: function(result) {
reloadItems();
showCart();
notify(result);
},
onFailure: function() {
reloadItems();
showCart();
}
}).send('products_id='+id+'&qty='+ile+modParam);
}
function incQty(id) {
val = parseInt($(id).value);
val++;
$(id).value = val;
}
function decQty(id) {
val = parseInt($(id).value);
val--;
if( val <= 0 )
val = 1;
$(id).value = val;
}
function showOrderOptions() {
el = $('orderOptions');
if( el.getStyle('display') != 'block' || el.getOpacity()==0) {
el.setStyle('display','block');
el.innerHTML =
'