$(function(){
	var slider = document.getElementById("foreign_range");
    var output = document.getElementById("foreign_value");
    output.innerHTML = commify(slider.value);
    
    slider.oninput = function() {
        output.innerHTML = commify(this.value);
        $('#foreign_list_fm input[name=price]').val(this.value);
    }
    
	$(".choice_foreign").click(function(e){
		 //e.preventDefault();
		 if ( chk_aos_version2() ) { // APP 인 경우
			 window.mamap_aos.layerOn(0);
		 }
		 
		 $('.foreign_filter_layer').scrollTop(0);
		 $('body').addClass('not_scroll');
		 $(".foreign_filter_layer").show();
	 });
	 $(".foreign_filter_close").click(function(e){
		 e.preventDefault();
		 if ( chk_aos_version2() ) { // APP 인 경우
			 window.mamap_aos.layerOff(0);
		 }
		 
		 $('body').removeClass('not_scroll');
		 $(window).scrollTop(0);
		 $(".foreign_filter_layer").hide();
	});
	 
	 $('div.course_sel div.foreign_filter_item').click(function(e){
			e.preventDefault();
			let str = '';
			if ( $(this).hasClass('on') ) {
				$(this).removeClass('on');
			} else {
				$(this).addClass('on');
			}

			$.each($('div.course_sel div.foreign_filter_item'), function(k,v){ 
				if ( $(this).hasClass('on') ) {
					if ( str != '' ) {
						str += ',' + $(this).data('code');
					} else {
						str += $(this).data('code');
					} 
				}
			});
			//console.log(str);
			$('#foreign_list_fm input[name=course]').val(str);
		});

		$('div.massager_sel div.foreign_filter_item').click(function(e){
			e.preventDefault();
			let str = '';
			if ( $(this).hasClass('on') ) {
				$(this).removeClass('on');
			} else {
				$(this).addClass('on');
			}

			$.each($('div.massager_sel div.foreign_filter_item'), function(k,v){ 
				if ( $(this).hasClass('on') ) {
					if ( str != '' ) {
						str += ',' + $(this).data('code');
					} else {
						str += $(this).data('code');
					} 
				}
			});
			//console.log(str);
			$('#foreign_list_fm input[name=massager]').val(str);
		});

		$('div.shop_info_sel div.foreign_filter_item').click(function(e){
			e.preventDefault();
			let str = '';
			if ( $(this).hasClass('on') ) {
				$(this).removeClass('on');
			} else {
				$(this).addClass('on');
			}

			$.each($('div.shop_info_sel div.foreign_filter_item'), function(k,v){ 
				if ( $(this).hasClass('on') ) {
					if ( str != '' ) {
						str += ',' + $(this).data('code');
					} else {
						str += $(this).data('code');
					} 
				}
			});
			//console.log(str);
			$('#foreign_list_fm input[name=shop_info]').val(str);
		});
		
		$(document).on('click', '.foreign_filter_del a', function(e) {
			e.preventDefault();
			$('label.filter_container').find('input[type=checkbox]').prop('checked', false);
			
			$('div.foreign_filter_item').removeClass('on');
			$('#foreign_range').val(600000);
			$('#foreign_value').text('600,000');
			$('#foreign_list_fm input[name=price]').val(0);
			$('#foreign_list_fm input[name=course]').val('');
			$('#foreign_list_fm input[name=massager]').val('');
			$('#foreign_list_fm input[name=shop_info]').val('');
			
		});
		
		$(document).on('click', 'div.foreign_filter_ok', function(e) {
			e.preventDefault();
			e.stopPropagation();
			
			var path = location.pathname;
			if ( path == '/f_map' ) {
				$('#foreign_list_fm').attr('action', '/f_map');
							
			} else {
				$('#foreign_list_fm').attr('action', '/f_list');
			}
			
			$('#foreign_list_fm').submit();
		});
		
		$('div.foreign_topmenu_course').click(function(e){
	          e.preventDefault();
	          var path = location.pathname;
	          var host = location.host;
	      	
	          var tcourse = $(this).data('tcourse')
	          //console.log(tcourse);
	          
	          $('#foreign_list_fm input[name=top_course]').val(tcourse);
	          $('#foreign_list_fm input[name=course]').val('');
	          $('#foreign_list_fm input[name=massager]').val('');
	          $('#foreign_list_fm input[name=shop_info]').val('');
	          
	          if ( tcourse ) {
	        	  if ( tcourse.indexOf('_c') >= 0 ) {
	        		  var tmp_str = tcourse.replace('_c', '');
	        		  $('#foreign_list_fm input[name=course]').val(tmp_str);
	        	  } else if ( tcourse.indexOf('_s') >= 0 ) {
	        		  var tmp_str = tcourse.replace('_s', '');
	        		  $('#foreign_list_fm input[name=shop_info]').val(tmp_str);
	              }  
	          } 
	          
	          if ( path == '/f_map' ) {
	        	  $('#foreign_list_fm').attr('action', '/f_map');
	          } else {
	        	  $('#foreign_list_fm').attr('action', '/f_list');
	          }
	          $('#foreign_list_fm').submit();
	      });
		
		$(document).on('click', '.foreign_cur_loc_move', function(e) {
	  		e.preventDefault();
	  		e.stopPropagation();

	  		var path = location.pathname;
	  		var c_x = getCookie('cur_loc_x');
			var c_y = getCookie('cur_loc_y');
			
			if ( c_x == '' || c_y == '' ) {
				if ( path == '/map' ) {
		  	  		cur_move_link('/f_map');
		        } else {
		      		cur_move_link('/f_list');
		        }
			} else {
				$('#foreign_list_fm input[name=cur_loc_x]').val(c_x);
			    $('#foreign_list_fm input[name=cur_loc_y]').val(c_y);
			    $('#foreign_list_fm input[name=c_x]').val(c_x);
			    $('#foreign_list_fm input[name=c_y]').val(c_y);
				    
			    if ( path == '/f_map') {
			    	$('#foreign_list_fm').attr('action', '/f_map');
			    } else {
			    	$('#foreign_list_fm').attr('action', '/f_list');
			    }
				$('#foreign_list_fm').submit();
			}
	  		
	  	});
});


