function getCookie(name) {
    var matches = document.cookie.match(new RegExp(
        "(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)"
    ))
    return matches ? decodeURIComponent(matches[1]) : undefined
}
function randRange(data) {
       var newTime = data[Math.floor(data.length * Math.random())];
       return newTime;
}
function lastpack(numpack) {
    var minNumPack = 12; // Минимальное количество упаковок
    var lastClass = $('.lastpack'); // Объект
   var numpackCookie = getCookie("lastpack");
    var timeArray = new Array(2000, 13000, 15000, 7000, 6000, 11000);

    if(numpackCookie == undefined) {
        document.cookie = numpack;
    } else {
        var numpack =  numpackCookie;
    }
    
    if (numpack > minNumPack) {
        numpack--;
        document.cookie = "lastpack="+numpack;
        lastClass.text(numpack);   
    } else {
        lastClass.text(minNumPack);
    }
    clearInterval(timer);
    timer = setInterval(lastpack, randRange(timeArray), numpack);
}

var timer = setInterval(lastpack, 0, 50);
$(document).ready(function () {
    $('.scroll').click(function () {
        $("html, body").animate({scrollTop: $("#order_form").offset().top - 100}, 1500);
        return false;
    });
});
$(document).ready(function() {
    $('.change-package-selector').on('change', (function() {
        $('.item-gift').hide();
        $('.' + $(this).val() + '_pack').show();
        $('.change-package-selector2 [value="' + $(this).val() + '"]').prop("selected", true);

        var package_id = $(this).val();
     //   set_package_prices(package_id);
    }));
});