jQuery(document).ready(function(){


/* слайдер скорости интернет */
jQuery("#slider").slider({
	min: 0,
	max: 30000,
	values: [0,30000],
	range: true,

	stop: function(event, ui) {
		jQuery("input#min_cost").val(jQuery("#slider").slider("values",0));
		jQuery("input#max_cost").val(jQuery("#slider").slider("values",1));
    },
    slide: function(event, ui){
		jQuery("input#min_cost").val(jQuery("#slider").slider("values",0));
		jQuery("input#max_cost").val(jQuery("#slider").slider("values",1));
    }
});

jQuery("input#min_cost").change(function(){
	var value1=jQuery("input#min_cost").val();
	var value2=jQuery("input#max_cost").val();
    if(parseInt(value1) > parseInt(value2)){
		value1 = value2;
		jQuery("input#min_cost").val(value1);
	}
	jQuery("#slider").slider("values",0,value1);	
});

	
jQuery("input#max_cost").change(function(){
	var value1=jQuery("input#min_cost").val();
	var value2=jQuery("input#max_cost").val();
	if (value2 > 30000) { value2 = 30000; jQuery("input#max_cost").val(30000)}
	if(parseInt(value1) > parseInt(value2)){
		value2 = value1;
		jQuery("input#max_cost").val(value2);
	}
	jQuery("#slider").slider("values",1,value2);
});

/* слайдер площади страны */
jQuery("#slider_area").slider({
	min: 0,
	max: 20000000,
	values: [0,20000000],
	range: true,
	stop: function(event, ui) {
		jQuery("input#min_area").val(jQuery("#slider_area").slider("values",0));
		jQuery("input#max_area").val(jQuery("#slider_area").slider("values",1));
    },
    slide: function(event, ui){
		jQuery("input#min_area").val(jQuery("#slider_area").slider("values",0));
		jQuery("input#max_area").val(jQuery("#slider_area").slider("values",1));
    }
});

jQuery("input#min_area").change(function(){
	var value1=jQuery("input#min_area").val();
	var value2=jQuery("input#max_area").val();
    if(parseInt(value1) > parseInt(value2)){
		value1 = value2;
		jQuery("input#min_area").val(value1);
	}
	jQuery("#slider_area").slider("values",0,value1);	
});

	
jQuery("input#max_area").change(function(){
	var value1=jQuery("input#min_area").val();
	var value2=jQuery("input#max_area").val();
	if (value2 > 20000000) { value2 = 20000000; jQuery("input#max_area").val(20000000)}
	if(parseInt(value1) > parseInt(value2)){
		value2 = value1;
		jQuery("input#max_area").val(value2);
	}
	jQuery("#slider_area").slider("values",1,value2);
});

/* слайдер Простота ведения бизнеса */
jQuery("#slider_doing_business").slider({
	min: 0,
	max: 100,
	values: [0,100],
	range: true,
	stop: function(event, ui) {
		jQuery("input#min_doing_business").val(jQuery("#slider_doing_business").slider("values",0));
		jQuery("input#max_doing_business").val(jQuery("#slider_doing_business").slider("values",1));
    },
    slide: function(event, ui){
		jQuery("input#min_doing_business").val(jQuery("#slider_doing_business").slider("values",0));
		jQuery("input#max_doing_business").val(jQuery("#slider_doing_business").slider("values",1));
    }
});

jQuery("input#min_doing_business").change(function(){
	var value1=jQuery("input#min_doing_business").val();
	var value2=jQuery("input#max_doing_business").val();
    if(parseInt(value1) > parseInt(value2)){
		value1 = value2;
		jQuery("input#min_doing_business").val(value1);
	}
	jQuery("#slider_doing_business").slider("values",0,value1);	
});

	
jQuery("input#max_doing_business").change(function(){
	var value1=jQuery("input#min_doing_business").val();
	var value2=jQuery("input#max_doing_business").val();
	if (value2 > 100) { value2 = 100; jQuery("input#max_doing_business").val(100)}
	if(parseInt(value1) > parseInt(value2)){
		value2 = value1;
		jQuery("input#max_doing_business").val(value2);
	}
	jQuery("#slider_doing_business").slider("values",1,value2);
});

/* слайдер Ожидаемая продолжительность жизни */
jQuery("#slider_life_expectancy").slider({
	min: 0,
	max: 100,
	values: [0,100],
	range: true,
	stop: function(event, ui) {
		jQuery("input#min_life_expectancy").val(jQuery("#slider_life_expectancy").slider("values",0));
		jQuery("input#max_life_expectancy").val(jQuery("#slider_life_expectancy").slider("values",1));
    },
    slide: function(event, ui){
		jQuery("input#min_life_expectancy").val(jQuery("#slider_life_expectancy").slider("values",0));
		jQuery("input#max_life_expectancy").val(jQuery("#slider_life_expectancy").slider("values",1));
    }
});

jQuery("input#min_life_expectancy").change(function(){
	var value1=jQuery("input#min_life_expectancy").val();
	var value2=jQuery("input#max_life_expectancy").val();
    if(parseInt(value1) > parseInt(value2)){
		value1 = value2;
		jQuery("input#min_life_expectancy").val(value1);
	}
	jQuery("#slider_life_expectancy").slider("values",0,value1);	
});

	
jQuery("input#max_life_expectancy").change(function(){
	var value1=jQuery("input#min_life_expectancy").val();
	var value2=jQuery("input#max_life_expectancy").val();
	if (value2 > 100) { value2 = 100; jQuery("input#max_life_expectancy").val(100)}
	if(parseInt(value1) > parseInt(value2)){
		value2 = value1;
		jQuery("input#max_life_expectancy").val(value2);
	}
	jQuery("#slider_life_expectancy").slider("values",1,value2);
});

/* слайдер индекс миролюбия */
jQuery("#slider_peace_index").slider({
	min: 0,
	max: 4,
	values: [0,4],
	range: true,
	step: 0.1,
	stop: function(event, ui) {
		jQuery("input#min_peace_index").val(jQuery("#slider_peace_index").slider("values",0));
		jQuery("input#max_peace_index").val(jQuery("#slider_peace_index").slider("values",1));
    },
    slide: function(event, ui){
		jQuery("input#min_peace_index").val(jQuery("#slider_peace_index").slider("values",0));
		jQuery("input#max_peace_index").val(jQuery("#slider_peace_index").slider("values",1));
    }
});

jQuery("input#min_peace_index").change(function(){
	var value1=jQuery("input#min_peace_index").val();
	var value2=jQuery("input#max_peace_index").val();
    if(parseInt(value1) > parseInt(value2)){
		value1 = value2;
		jQuery("input#min_peace_index").val(value1);
	}
	jQuery("#slider_peace_index").slider("values",0,value1);	
});

	
jQuery("input#max_peace_index").change(function(){
	var value1=jQuery("input#min_peace_index").val();
	var value2=jQuery("input#max_peace_index").val();
	if (value2 > 4) { value2 = 4; jQuery("input#max_peace_index").val(4)}
	if(parseInt(value1) > parseInt(value2)){
		value2 = value1;
		jQuery("input#max_peace_index").val(value2);
	}
	jQuery("#slider_peace_index").slider("values",1,value2);
});

/* слайдер индекс счастья */
jQuery("#slider_happiness_index").slider({
	min: 0,
	max: 50,
	values: [0,50],
	range: true,
	stop: function(event, ui) {
		jQuery("input#min_happiness_index").val(jQuery("#slider_happiness_index").slider("values",0));
		jQuery("input#max_happiness_index").val(jQuery("#slider_happiness_index").slider("values",1));
    },
    slide: function(event, ui){
		jQuery("input#min_happiness_index").val(jQuery("#slider_happiness_index").slider("values",0));
		jQuery("input#max_happiness_index").val(jQuery("#slider_happiness_index").slider("values",1));
    }
});

jQuery("input#min_happiness_index").change(function(){
	var value1=jQuery("input#min_happiness_index").val();
	var value2=jQuery("input#max_happiness_index").val();
    if(parseInt(value1) > parseInt(value2)){
		value1 = value2;
		jQuery("input#min_happiness_index").val(value1);
	}
	jQuery("#slider_happiness_index").slider("values",0,value1);	
});

	
jQuery("input#max_happiness_index").change(function(){
	var value1=jQuery("input#min_happiness_index").val();
	var value2=jQuery("input#max_happiness_index").val();
	if (value2 > 50) { value2 = 50; jQuery("input#max_happiness_index").val(50)}
	if(parseInt(value1) > parseInt(value2)){
		value2 = value1;
		jQuery("input#max_happiness_index").val(value2);
	}
	jQuery("#slider_happiness_index").slider("values",1,value2);
});

/* слайдер Число жителей */
jQuery("#slider_population").slider({
	min: 0,
	max: 1400000000,
	values: [0,1400000000],
	range: true,
	stop: function(event, ui) {
		jQuery("input#min_population").val(jQuery("#slider_population").slider("values",0));
		jQuery("input#max_population").val(jQuery("#slider_population").slider("values",1));
    },
    slide: function(event, ui){
		jQuery("input#min_population").val(jQuery("#slider_population").slider("values",0));
		jQuery("input#max_population").val(jQuery("#slider_population").slider("values",1));
    }
});

jQuery("input#min_population").change(function(){
	var value1=jQuery("input#min_population").val();
	var value2=jQuery("input#max_population").val();
    if(parseInt(value1) > parseInt(value2)){
		value1 = value2;
		jQuery("input#min_population").val(value1);
	}
	jQuery("#slider_population").slider("values",0,value1);	
});

	
jQuery("input#max_population").change(function(){
	var value1=jQuery("input#min_population").val();
	var value2=jQuery("input#max_population").val();
	if (value2 > 1400000000) { value2 = 1400000000; jQuery("input#max_population").val(1400000000)}
	if(parseInt(value1) > parseInt(value2)){
		value2 = value1;
		jQuery("input#max_population").val(value2);
	}
	jQuery("#slider_population").slider("values",1,value2);
});

/* слайдер максимальная высота */
jQuery("#slider_peak_height").slider({
	min: 0,
	max: 10000,
	values: [0,10000],
	range: true,
	stop: function(event, ui) {
		jQuery("input#min_peak_height").val(jQuery("#slider_peak_height").slider("values",0));
		jQuery("input#max_peak_height").val(jQuery("#slider_peak_height").slider("values",1));
    },
    slide: function(event, ui){
		jQuery("input#min_peak_height").val(jQuery("#slider_peak_height").slider("values",0));
		jQuery("input#max_peak_height").val(jQuery("#slider_peak_height").slider("values",1));
    }
});

jQuery("input#min_peak_height").change(function(){
	var value1=jQuery("input#min_peak_height").val();
	var value2=jQuery("input#max_peak_height").val();
    if(parseInt(value1) > parseInt(value2)){
		value1 = value2;
		jQuery("input#min_peak_height").val(value1);
	}
	jQuery("#slider_peak_height").slider("values",0,value1);	
});

	
jQuery("input#max_peak_height").change(function(){
	var value1=jQuery("input#min_peak_height").val();
	var value2=jQuery("input#max_peak_height").val();
	if (value2 > 10000) { value2 = 10000; jQuery("input#max_peak_height").val(10000)}
	if(parseInt(value1) > parseInt(value2)){
		value2 = value1;
		jQuery("input#max_peak_height").val(value2);
	}
	jQuery("#slider_peak_height").slider("values",1,value2);
});

/* слайдер ВВП на душу населения */
jQuery("#slider_vvp").slider({
	min: 0,
	max: 140000,
	values: [0,140000],
	range: true,
	stop: function(event, ui) {
		jQuery("input#min_vvp").val(jQuery("#slider_vvp").slider("values",0));
		jQuery("input#max_vvp").val(jQuery("#slider_vvp").slider("values",1));
    },
    slide: function(event, ui){
		jQuery("input#min_vvp").val(jQuery("#slider_vvp").slider("values",0));
		jQuery("input#max_vvp").val(jQuery("#slider_vvp").slider("values",1));
    }
});

jQuery("input#min_vvp").change(function(){
	var value1=jQuery("input#min_vvp").val();
	var value2=jQuery("input#max_vvp").val();
    if(parseInt(value1) > parseInt(value2)){
		value1 = value2;
		jQuery("input#min_vvp").val(value1);
	}
	jQuery("#slider_vvp").slider("values",0,value1);	
});

	
jQuery("input#max_vvp").change(function(){
	var value1=jQuery("input#min_vvp").val();
	var value2=jQuery("input#max_vvp").val();
	if (value2 > 140000) { value2 = 140000; jQuery("input#max_vvp").val(140000)}
	if(parseInt(value1) > parseInt(value2)){
		value2 = value1;
		jQuery("input#max_vvp").val(value2);
	}
	jQuery("#slider_vvp").slider("values",1,value2);
});

/* слайдер длина автодорог */
jQuery("#slider_length_roads").slider({
	min: 0,
	max: 7000000,
	values: [0,7000000],
	range: true,
	stop: function(event, ui) {
		jQuery("input#min_length_roads").val(jQuery("#slider_length_roads").slider("values",0));
		jQuery("input#max_length_roads").val(jQuery("#slider_length_roads").slider("values",1));
    },
    slide: function(event, ui){
		jQuery("input#min_length_roads").val(jQuery("#slider_length_roads").slider("values",0));
		jQuery("input#max_length_roads").val(jQuery("#slider_length_roads").slider("values",1));
    }
});

jQuery("input#min_length_roads").change(function(){
	var value1=jQuery("input#min_length_roads").val();
	var value2=jQuery("input#max_length_roads").val();
    if(parseInt(value1) > parseInt(value2)){
		value1 = value2;
		jQuery("input#min_length_roads").val(value1);
	}
	jQuery("#slider_length_roads").slider("values",0,value1);	
});

	
jQuery("input#max_length_roads").change(function(){
	var value1=jQuery("input#min_length_roads").val();
	var value2=jQuery("input#max_length_roads").val();
	if (value2 > 7000000) { value2 = 7000000; jQuery("input#max_length_roads").val(7000000)}
	if(parseInt(value1) > parseInt(value2)){
		value2 = value1;
		jQuery("input#max_length_roads").val(value2);
	}
	jQuery("#slider_length_roads").slider("values",1,value2);
});

/* слайдер цена Airbnb */
jQuery("#slider_airbnb").slider({
	min: 0,
	max: 100000,
	values: [0,100000],
	range: true,
	stop: function(event, ui) {
		jQuery("input#min_airbnb").val(jQuery("#slider_airbnb").slider("values",0));
		jQuery("input#max_airbnb").val(jQuery("#slider_airbnb").slider("values",1));
    },
    slide: function(event, ui){
		jQuery("input#min_airbnb").val(jQuery("#slider_airbnb").slider("values",0));
		jQuery("input#max_airbnb").val(jQuery("#slider_airbnb").slider("values",1));
    }
});

jQuery("input#min_airbnb").change(function(){
	var value1=jQuery("input#min_airbnb").val();
	var value2=jQuery("input#max_airbnb").val();
    if(parseInt(value1) > parseInt(value2)){
		value1 = value2;
		jQuery("input#min_airbnb").val(value1);
	}
	jQuery("#slider_airbnb").slider("values",0,value1);	
});

	
jQuery("input#max_airbnb").change(function(){
	var value1=jQuery("input#min_airbnb").val();
	var value2=jQuery("input#max_airbnb").val();
	if (value2 > 100000) { value2 = 100000; jQuery("input#max_airbnb").val(100000)}
	if(parseInt(value1) > parseInt(value2)){
		value2 = value1;
		jQuery("input#max_airbnb").val(value2);
	}
	jQuery("#slider_airbnb").slider("values",1,value2);
});

/* слайдер цена Авиаперелета */
jQuery("#slider_skyscanner").slider({
	min: 0,
	max: 100000,
	values: [0,100000],
	range: true,
	stop: function(event, ui) {
		jQuery("input#min_skyscanner").val(jQuery("#slider_skyscanner").slider("values",0));
		jQuery("input#max_skyscanner").val(jQuery("#slider_skyscanner").slider("values",1));
    },
    slide: function(event, ui){
		jQuery("input#min_skyscanner").val(jQuery("#slider_skyscanner").slider("values",0));
		jQuery("input#max_skyscanner").val(jQuery("#slider_skyscanner").slider("values",1));
    }
});

jQuery("input#min_skyscanner").change(function(){
	var value1=jQuery("input#min_skyscanner").val();
	var value2=jQuery("input#max_skyscanner").val();
    if(parseInt(value1) > parseInt(value2)){
		value1 = value2;
		jQuery("input#min_skyscanner").val(value1);
	}
	jQuery("#slider_skyscanner").slider("values",0,value1);	
});

	
jQuery("input#max_skyscanner").change(function(){
	var value1=jQuery("input#min_skyscanner").val();
	var value2=jQuery("input#max_skyscanner").val();
	if (value2 > 100000) { value2 = 100000; jQuery("input#max_skyscanner").val(100000)}
	if(parseInt(value1) > parseInt(value2)){
		value2 = value1;
		jQuery("input#max_skyscanner").val(value2);
	}
	jQuery("#slider_skyscanner").slider("values",1,value2);
});





// фильтрация ввода в поля
	jQuery('input').keypress(function(event){
		var key, keyChar;
		if(!event) var event = window.event;
		
		if (event.keyCode) key = event.keyCode;
		else if(event.which) key = event.which;
	
		if(key==null || key==0 || key==8 || key==13 || key==9 || key==46 || key==37 || key==39 ) return true;
		keyChar=String.fromCharCode(key);
		
		if(!/\d/.test(keyChar))	return false;
	
	});


});



