function calcAll() {
    var calc_years = parseInt(jQuery("#slider").slider("value") / 10);
    var year_n = "";

    if (calc_years == 1 || calc_years == 21 || calc_years == 31 || calc_years == 41 || calc_years == 51) {
        year_n = "דמה";
    } else if ((calc_years >= 2 && calc_years <= 4) || (calc_years >= 22 && calc_years <= 24) || (calc_years >= 32 && calc_years <= 34) || (calc_years >= 42 && calc_years <= 44) || (calc_years >= 52 && calc_years <= 54)) {
        year_n = "דמהא";
    } else {
        year_n = "כוע";
    }

    jQuery('#calc_years').html(calc_years + " " + year_n);
    jQuery("#sval").html(calc_years);

    var count_per_day = jQuery('#calc_count').val();
    if (count_per_day == "") {
        count_per_day = 0;
    }

    var box_price = jQuery('#calc_price').val();
    if (box_price == "") {
        box_price = 0;
    }

    var tar_count = jQuery('#calc_smols').val();
    var nicotine_count = jQuery('#calc_nic').val();
    
    var sig_result = calc_years * 365 * count_per_day;
    jQuery('#sig_result').html(sig_result + " רע");
    
    var price_result = parseInt((box_price / 20) * sig_result);
    jQuery('#price_result').html(price_result + " נ.");
    
    var tar_result = parseInt(sig_result * tar_count);
    jQuery('#tar_result').html(tar_result + " לד");
    
    var nicotine_result = parseInt(sig_result * nicotine_count);
    jQuery('#nicotine_result').html(nicotine_result + " לד");
}

function checkCount(obj, count) {
	if (parseInt(obj.value) > count) {
		obj.value = count;
	}
}

jQuery(document).ready(function() {
	
	
    jQuery('.inps').keypress(function(e) {
        if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {
            return false;
        }
    });
    
    jQuery('#slider').slider({
        min: 10,
        max: 609,
        step: 1,
        slide: function(event, ui){
            var x = parseFloat(jQuery('.ui-slider-handle').css('left'));
            var width_x = parseFloat(jQuery('.ui-slider-handle').css('width'));
            var width_y = parseFloat(jQuery('#sval').css('width'));
            var y = x - (width_y / 2 - width_x / 2) + 5;
            jQuery('#sval').css('left', y);

            calcAll();
        },
        stop: function(event, ui){
            var x = parseFloat(jQuery('.ui-slider-handle').css('left'));
            var width_x = parseFloat(jQuery('.ui-slider-handle').css('width'));
            var width_y = parseFloat(jQuery('#sval').css('width'));
            var y = x - (width_y / 2 - width_x / 2) + 5;
            jQuery('#sval').css('left', y);

            calcAll();
        }

    });
})
