function add_item(ref, qty) { if (qty > 0) { $('#result').load('/cart/cart.php?y=1&a=add_item&o[0][r]=' + ref + '&o[0][q]=' + qty + ' #cart', null, function(t, s, r){ if (s == 'success') {// alert(t); self.location = 'shop.php?a=get_cart';} else alert('An unknown error has occurred. Please, try again.'); }); } else { alert('This quantity is not valid!'); } } function remove_item(item_id) { if (!$('#' + item_id)) return; $('#' + item_id).attr('value', 0); $('#cart form').submit(); } function update_cart() { $('#cart form').submit(); } function empty_cart() { $('#result').load('/cart/cart.php?y=1&a=empty_cart #cart', null, function(t, s, r){ if (s == 'success') alert(t); else alert('An unknown error has occurred. Please, try again.'); }); } function get_index(ajax) { if (ajax) { $('#cart').load('/cart/cart.php?x=1&a=get_index #cart', null, function(t, s, r){ if (s != 'success') alert('An unknown error has occurred. Please, try again.'); }); } else { self.location = 'shop.php?a=get_index'; } } function get_cart(ajax) { if (ajax) { $('#cart').load('/cart/cart.php?x=1&a=get_cart #cart', null, function(t, s, r){ if (s != 'success') alert('An unknown error has occurred. Please, try again.'); }); } else { self.location = 'shop.php?a=get_cart'; } // com veure el carret en un popup // var w = window.open('cart//cart/cart.php?x=1&a=get_cart', 'cart', 'dependent=yes,scrollbars=1,status=1,toolbar=0,resizable=0,location=0,width=350,height=200,top=25,left=25'); } function get_order(ajax) { if (ajax) { $('#cart').load('/cart/cart.php?x=1&a=get_order #cart', null, function(t, s, r){ if (s != 'success') alert('An unknown error has occurred. Please, try again.'); }); } else { self.location = 'shop.php?a=get_order'; } } function send_order(ajax) { var e = document.forms[0].elements; if (e['b_name'].value == '') {alert('Si us plau, ompli el camp "Nom".');return;} if (e['b_vat_id'].value == '') {alert('Si us plau, ompli el camp "N.I.F.".');return;} if (e['b_address'].value == '') {alert('Si us plau, ompli el camp "Adreça".');return;} if (e['b_zip'].value == '') {alert('Si us plau, ompli el camp "Codi Postal".');return;} if (e['b_city'].value == '') {alert('Si us plau, ompli el camp "Població".');return;} if (e['b_email'].value == '') {alert('Si us plau, ompli el camp "Correu electrònic".');return;} if (ajax) { //$('#cart').load('/cart/cart.php?x=1&a=send_order #cart', null, function(t, s, r){ // if (s != 'success') alert('An unknown error has occurred. Please, try again.'); //}); $.ajax({ type: 'POST', url: 'shop.php?x=1&a=send_order', data: $("#cart form").serialize(), cache: false, success: function(html){ $('#cart').append(html); } }); } else { $('#cart form').submit(); } } function confirm_order(ajax) { if (!document.forms[0].elements['confirm'].checked) { alert('Si us plau, confirmi que ha llegit les condicions de venda.'); return; } if (ajax) { $('#cart').load('/cart/cart.php?x=1&a=confirm_order #cart', null, function(t, s, r){ if (s != 'success') alert('An unknown error has occurred. Please, try again.'); }); } else { $('#cart form').submit(); } } function change_item(obj, img) { var val = obj[obj.selectedIndex].value; document.images[img].src = 'cart/img/' + val + '.jpg'; for (var i = 0;i < prods.length;i++) { if (prods[i][0] == val) { $('#' + img).innerHTML = prods[i][1]; break; } } } function toggle_ship_to() { $('#cart div.ship_to').toggle('normal'); } var prods = [ ['P001','100,00'], ['P002','200,00'], ['P003','300,00'], ['P004','400,00'] ];