$(function() {
	function format(expr) {
		
		if (expr.img){
			return "<img src=\"" + expr.img + "\" alt=\"Angry face\" />" + " "  + expr.oras + ","+  expr.mata + " &lt;" + expr.to + "&gt " + expr.etc;
		}else{
			return expr.oras + " &lt;" + expr.to + "&gt " + expr.etc;
		}
	}
	$("#from").autocomplete('index.php?page=16', {
		minChars: 3,
		multiple: false,
		width: 280,
		parse: function(data) {
			return $.map(eval(data), function(row) {
				if ( typeof row != 'undefined' )
				{
					if (row.mata){
						return {	
						data: row,
						value: row.oras,
						result: row.oras + ", " + row.mata + " (" + row.to + ")"	}	
					}else{
						return {	
						data: row,
						value: row.oras,
						result: row.oras +  " (" + row.to + ")"	}	
					}
				}
			});
		},
		formatItem: function(item) {
			return format(item);
		}
	})
	$("#to").autocomplete('index.php?page=16', {
		minChars: 3,
		multiple: false,
		width: 280,
		parse: function(data) {
			return $.map(eval(data), function(row) {
				if ( typeof row != 'undefined' )
				{
					if (row.mata){
						return {	
						data: row,
						value: row.oras,
						result: row.oras + ", " + row.mata + " (" + row.to + ")"	}	
					}else{
						return {	
						data: row,
						value: row.oras,
						result: row.oras +  " (" + row.to + ")"	}	
					}
				}
				
			});
		},
		formatItem: function(item) {
		return format(item);
		}
	})
});