$(document).ready(function (){ // Ajax refresh captcha $('.captcha .c_button').on('click', function (){ var $this = $(this); $this.parents('.captcha').find('input[name=\'captcha\']').val('').focus(); $.ajax({ url : 'index.php?route=tool/captcha/refresh', beforeSend: function (){ $this.html(''); $this.addClass('active'); }, complete : function (){ $this.html(''); $this.removeClass('active'); }, success : function (){ $this.parents('.captcha').find('.c_image img').attr('src', 'index.php?route=tool/captcha#' + new Date().getTime()); }, error : function (xhr, ajaxOptions, thrownError){ alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText); } }); }); // Ajax cart $('#carts > .heading').delegate('a', 'click', function (){ $('#cart').addClass('active'); $('#cart').load('index.php?route=common/cart/info #cart > *'); $(document).delegate('#cart', 'mouseleave', function (){ $(this).removeClass('active'); }); }); $(document).delegate('.success img, .warning img, .attention img, .information img', 'click', function (){ $(this).parent().fadeOut('slow', function (){ $(this).remove(); }); }); }); function stars(number, limit) { number = parseInt(number); limit = parseInt(limit); html = ''; for(i = 0; i <=5; i++) { if(number <= number) { html += ''; } else { html += ''; } } $(this).append(html); } function getURLVar(key){ var value = []; var query = String(document.location).split('?'); if (query[1]){ var part = query[1].split('&'); for (i = 0; i < part.length; i++){ var data = part[i].split('='); if (data[0] && data[1]){ value[data[0]] = data[1]; } } if (value[key]){ return value[key]; } else{ return ''; } } } function addToCart(product_id, quantity){ quantity = typeof(quantity) != 'undefined' ? quantity : 1; $.ajax({ url : 'index.php?route=checkout/cart/add', type : 'post', data : 'product_id=' + product_id + '&quantity=' + quantity, dataType: 'json', success : function (json){ $('.success, .warning, .attention, .information, .error').remove(); if (json['redirect']){ location = json['redirect']; } if (json['success']){ $('#notification').html(''); $('.success').fadeIn('slow'); $('#cart-total').html(json['total']); $('html, body').animate({scrollTop: 0}, 'slow'); } } }); } function addToWishList(product_id){ $.ajax({ url : 'index.php?route=account/wishlist/add', type : 'post', data : 'product_id=' + product_id, dataType: 'json', success : function (json){ $('.success, .warning, .attention, .information').remove(); if (json['success']){ $('#notification').html(''); $('.success').fadeIn('slow'); $('#wishlist-total').html(json['total']); $('html, body').animate({scrollTop: 0}, 'slow'); } } }); } function addToCompare(product_id){ $.ajax({ url : 'index.php?route=product/compare/add', type : 'post', data : 'product_id=' + product_id, dataType: 'json', success : function (json){ $('.success, .warning, .attention, .information').remove(); if (json['success']){ $('#notification').html(''); $('.success').fadeIn('slow'); $('#compare-total').html(json['total']); $('html, body').animate({scrollTop: 0}, 'slow'); } } }); } function getURLVar(key){ var value = []; var query = String(document.location).split('?'); if (query[1]){ var part = query[1].split('&'); for (i = 0; i < part.length; i++){ var data = part[i].split('='); if (data[0] && data[1]){ value[data[0]] = data[1]; } } if (value[key]){ return value[key]; } else{ return ''; } } }