function remove_coockie(val,n) {
	c = $.cookie('restaurant_alias').split('|');
	var nc = [];
	for(x in c) {
		if(c[x] != val) {
			nc.push(c[x]);
		}
	}
	$.cookie('restaurant_alias',nc.join('|'), { expires: 365});
	$('#cook_'+n).remove();
	proces_rest_alias();
}

function proces_rest_alias(event){
	if(!$("#restaurant_alias").is(':visible')) {
		tr = '<table width="100%" cellpadding="0" cellspacing="0">';
		c = $.cookie('restaurant_alias').split('|');
		for(i=0; i<c.length; i++) {
			tr +="<tr id='coock_"+i+"'><td class='del'><img src='images/close.png' onclick='remove_coockie(\""+c[i]+"\","+i+");' /></td><td width='100%' class='alias'>"+c[i]+"</td></tr>";
		}
		tr += '</table>';
		$('#restaurant_alias').css('display','block').show().html(tr).css({'width':$('#restaurant_name').width()+5+'px', top: $('#restaurant_name').position().top+$('#restaurant_name').height()+5+'px'});
		$('td.alias').click(function(){ 
			$('#restaurant_name').val($(this).text());
			$('#restaurant_alias').hide();
		});
	}
}

$(document).ready(function() {

	if ($.cookie('restaurant_alias')) {
		if($.cookie('restaurant_alias').indexOf('|') != -1) {
			$('#restaurant_name').focus(proces_rest_alias).blur(
				function(event){
					setTimeout(function(){$('#restaurant_alias').hide()},300)
				}
			).click(proces_rest_alias);
		} else {
			$('#restaurant_name').val($.cookie('restaurant_alias'));
			$('#restaurant_name').focus(function(){
				$('#restaurant_name').select();
			}).blur(function(){
				setTimeout(function(){$('#restaurant_alias').hide()},300)
			});
		}
	}
	if($("#status").size()) {
		$.facebox($("#status").html());
		$('#facebox .content').css({'border':'none','height':'auto','padding':'5px 5px 5px 5px'});
	}
});

