function autoComplete(inputfield, formular){
	$( inputfield ).autocomplete({
		source: function( request, response ) {
			var cat = $('#categorie').val();
			$.ajax({
				url: "/include/functions/productsearch_json.php",
				dataType: "json",
				data: {
					string: request.term,
					cat: cat
				},
				success: function( data ) {
					if( data ){
						response( $.map( data.wordoffer, function( item ) {
							return {
								label: item,
								value: item
							}
						}));
					}
				}
			});
		},
		minLength: 4,
		select: function( event, ui ) {
			$( inputfield ).value = ui.item.value;
			$(formular).find(inputfield)[0].value = ui.item.value;
			$( formular ).submit();
		},
		open: function() {
			$( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" );
		},
		close: function() {
			$( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );
		}
	}).keypress(function(e) {
		if (e.keyCode === 13)
		{
			$(formular).submit();
		}
	});
}

function resizePicturesHeight(name, max_height){
	$(name).each(function(i) {
		if($(this).height() > max_height){
			var h = max_height;
			var w = Math.ceil($(this).width() / $(this).height() * max_height);
		}
		$(this).css({ height: h, width: w });
	});
}
