$(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); } }); }); $(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'); $('#number_product_cart').html(json['total_number']); $('#price-total').html(json['price']); $('html, body').animate({scrollTop: 0}, 'slow'); } } }); }