function getCountries( id, sel ) {
	$.ajax({
		url: 'store-locator/countries',
		cache: false,
		dataType: 'json',
		success: function( obj ) {
			var entries = obj.result.data;
			var els = new Array();
			
			$.each( entries, function ( i, entry ) { 
					var flag = sel == entry.country;
					var el = '<option value="' + entry.country + '"' + ( flag ? ' selected="selected"' : '' ) + '>' + entry.country + '</option>';

					if(entry.country == "Special") {
						$( '#' + id ).append( el );
						
						el = '<option DISABLED>------------------------------</option>';
						$( '#' + id ).append( el );
					} else if ( entry.country != '' && entry.country != null ) {
						els.push( el );
					}					
				} 
			);		
			
			$( '#' + id ).append( els.join("") );
		},
		error: function( h, t, e ) {
			
		}
	});
}

function getCities( country ) {
	$( '#store_locator_preloader' ).css( 'display', 'block' );
	$.ajax({
		url: 'store-locator/cities',
		cache: false,
		dataType: 'json',
		data: 'country=' + country,
		success: function( obj ) {
			$( '#city' ).empty();
			$( '#city' ).append( '<option>Choose your city</option>' );
			var entries = obj.result.data;
			$.each( entries, function ( i, entry ) { 
					var el = '<option>' + entry.city + '</option>';
					$( '#city' ).append( el );
				} 
			);
			$( '#city' ).removeAttr( 'disabled' );
			$( '#store_locator_preloader' ).css( 'display', 'none' );
		}
	} );	
}

function getStores( country, city ) {
	$.ajax( {
		url: 'store-locator/stores',
		cache: false,
		dataType: 'json',
		data: 'country=' + country + '&city=' + city + '&shop_1055=' + shop_1055 + '&shop_1055mm=' + shop_1055mm,
		success: function( obj ) {
			var entries = obj.result.data;
			mapInizialize( obj.result.data );
//			console.log( obj );
		},
		error: function( obj ) {
			alert( 'error' );
		}
	} );
}
			
function submitNameSearch() {
	var minCharNum = 3;
	var nameSearch = $( '#store_name_search' ).attr( "value" );
	
	if( nameSearch.length >= minCharNum ) {
		$.ajax( {
			url: 'store-locator/search-by-name',
			cache: false,
			dataType: 'json',
			data: 'stringSearch=' + nameSearch,
			success: function( obj ) {
				var entries = obj.result.data;
				
				$( "#result_container").css( "display", "none" );
//				deactivateFilter();
			    $( '#store_list_container' ).empty();
				$.each( entries, function ( i, entry ) { 
					populateHTML( entry );
				} );
				
				if($( '#store_list_container' ).html() == "" ) {
					$( '#store_list_container' ).html( '<div class="result"><p class="doorname">No stores found</p></div>' );
				} else {
//					activateFilter();
				}
					
			},
			error: function( obj ) {
				alert( 'error' );
			}
		} );
	} else {
		alert("At least " + minCharNum + " characters required.");
	}
}
