/** * IconEden 2.5 shopping cart javascript */var addToCart=function(){$self=$(this);$.ajax({type:'GET',url:$(this).attr('href'),mode:'abort',port:'cart',dataType:'json',cache:false,success:function(data,textStatus){if(data.result){var item=data.item;if(data.reloadCart){document.location=document.location;return;}else if(typeof iconCart[item.id]!='undefined')return;_iconSpec=$self.attr('rel');_href=$self.attr('href');_href=_href.replace('add','remove');$self.hide();if($self.attr('id')=='big-add-cart'){$('#button-set').hide();if($('#full-remove').size())$('#full-remove').show();else{$('#button-set').after('<a href="'+_href+'" id="full-remove" rel="'+_iconSpec+'">Remove from Cart</a>');}$('.'+_iconSpec).hide();}if(iconCart.length==0){$('#cart-inside p:first').remove();$('#cart-inside').append('<h3>Your shopping cart<\/h3>');$('#cart-inside').append('<dl class="cart-list clearfix"><\/dl>');$('.cart-list').append('<dt><b>Total</b></dt>'+'<dd class="cart-price">0</dd>'+'<dd class="remove-cart">&nbsp;</dd>');$('.cart-list').after('<p>Please click the button below to complete your payment. You will be able to download your purchased products after 2-5 hours, the download link will be expired after 5 download times.</p>'+'<a href="'+baseUrl+'icon/checkout'+'" id="process">Process the payment</a>');}iconCart[item.id]=item;$rowTotal=$('.cart-list dt:last');$newItem=$('<dt><a href="'+baseUrl+'icon/'+item.key+'.html">'+item.name+'<\/a><\/dt>'+'<dd class="cart-price">$'+item.price+'<\/dd>'+'<dd class="remove-cart"><a href="'+baseUrl+'icon/cart/remove/'+item.key+'" title="Remove from cart" class="remove" rel="'+item.key+'">Remove<\/a><\/dd>').insertBefore($rowTotal);$('a[href*=/cart/remove]').click(removeFromCart);totalPrice=0;for(id in iconCart)totalPrice+=parseInt(iconCart[id].price);$($rowTotal).next().html('<b>$'+totalPrice+'<\/b>');}else{alert('Error '+data.code+' : '+data.message);}},beforeSend:function(){$('#load').fadeIn();$self.hide();},complete:function(){$('#load').fadeOut();}});return false;};var removeFromCart=function(){$self=$(this);$rel=$self.attr('rel');$currentRow=$('a.remove[rel="'+$rel+'"]');while(!$currentRow.is('dd'))$currentRow=$currentRow.parent();$.ajax({type:'GET',url:$(this).attr('href'),mode:'abort',port:'cart',dataType:'json',cache:false,success:function(data,textStatus){if(data.result){var item=data.item;_iconPrice=iconCart[item.id].price;_iconSpec=iconCart[item.id].key;delete iconCart[item.id];_lnkRemoveFromCart=$('a[rel="'+$rel+'"]');_href=_lnkRemoveFromCart.attr('href');_href=_href.replace('remove','add');_lnkRemoveFromCart.show().css('display','');$currentRow.prev().remove();$currentRow.prev().remove();$currentRow.remove();_buynowUrl=_href.replace('add','buy');if($('#full-remove').size()){$('#full-remove').hide();if($('#button-set').size())$('#button-set').show();else{$('#full-remove').before('<ul id="button-set"><\/ul>');$('#button-set').append('<li id="full-price">$'+_iconPrice+'<\/li>');$('#button-set').append('<li id="full-add"><a id="big-add-cart" href="'+_href+'" rel="'+_iconSpec+'">Add to cart<\/a><\/li>');$('#button-set').append('<li id="full-buy"><a id="big-buy-now" href="'+_buynowUrl+'">Buy it now<\/a><\/li>');$('#big-add-cart').unbind('click').bind('click',addToCart);}$('#big-add-cart').removeClass();$('a.'+_iconSpec).each(function(){__href=$(this).attr('href');__href=__href.replace('remove','add');$(this).attr('href',__href).show().css('display','');});}$('.'+_iconSpec).show().css('display','');totalPrice=0;for(id in iconCart)totalPrice+=parseInt(iconCart[id].price);if(!totalPrice){$('#cart-inside h3:first').remove();$('#cart-inside p').remove();$('#process').remove();$('.cart-list').remove();$('#cart-inside').append('<p>Your shopping cart is empty.</p>');$('#cart-wrap2').append('<p>Your shopping cart is empty.</p>');$('#agreement-wrapper').remove();iconCart=[];}else{$('.cart-list').each(function(){$rowTotal=$('dt:last',this);$rowTotal.next().html('<b>$'+totalPrice+'<\/b>');});}}else{alert('Error '+data.code+' : '+data.message);}},beforeSend:function(){$('#load').fadeIn();$self.hide();},complete:function(){$('#load').fadeOut();}});return false;};$(document).ready(function(){$('a[href*=/cart/add]').click(addToCart);$('a[href*=/cart/remove]').click(removeFromCart);});
