function add_to_cart_button(arr,qty,redirect_url){
    jQuery.ajax({
        type: "POST",
        url: 'ajax/cart.php',
        data: 'add_to_cart_button='+arr+'&qty='+qty+'&redirect_url='+redirect_url,
        cache: false,
        success: function(response){
            var object = jQuery.parseJSON(response);
            if(object.success=='ok' && object.redirect_url!=''){window.location.href = object.redirect_url}
            else{cart_reload(object.cid)}
        }
    });
}
function cart_reload(cid){
    jQuery.ajax({
        type: "POST",
        url: 'ajax/cart.php',
        data: 'cart_reload=yes&cid='+cid,
        cache: false,
        success: function(response){
            var object = jQuery.parseJSON(response);
            $('.jq_total_price').html(object.total_price);
            $('.jq_total_weight').html(object.total_weight);
            $('.jq_total_qty').html(object.total_qty);
            $('.jq_cid_qty_'+cid).html(object.cid_qty);
            $('.jq_cid_total_price_'+cid).html(object.cid_total_price);
            
            var cart_layout_country = $("select[name='cart_layout_country'] option:selected").val();
            var cart_layout_delivery_name = $("select[name='cart_layout_delivery_name'] option:selected").val();
            estimated_delivery_price('',cart_layout_country,cart_layout_delivery_name);
        }
    });
}

function estimated_delivery_price(country_id,cart_layout_country,delivery_name){
    var user_country_id = '';
    if(country_id!=''){user_country_id=country_id;}else{user_country_id=cart_layout_country;}
    //alert(user_country_id+' '+delivery_name);
    var cart_weight = $('.jq_total_weight').html();
    jQuery.ajax({
        type: "POST",
        url: "ajax/delivery.php",
        data: 'callback=estimated_delivery_price&country_id='+user_country_id+'&cart_weight='+cart_weight+'&delivery_name='+delivery_name,
        cache: false,
        success: function(response){
            var object = jQuery.parseJSON(response);
            $('.jq_estimated_delivery_price').html(object.estimated_delivery_price)
            //$("select[name='cart_layout_country'] option[rel='"+object.country_code+"']").attr('selected',true);
            //alert($("select[name='cart_layout_country'] option:selected").val());
        }
    });
}
