$(function() {
	var $from = $('input#partenza');
	var $to = $('input#arrivo');

	function setto() {
		$to.addClass('everywhere');
		$to.val(search_all_value);
	}

	function unsetto() {
		$to.val('');
		$to.removeClass('everywhere');
	}

	$from.keypress(function(ev) {
		if(!$to.val()) setto();
	});

	$to.focus(function(ev) {
		if($to.val() == search_all_value) unsetto();
	})
	.blur(function(ev) {
		if($from.val() && !$to.val()) setto();
	});

	var $sd = $('input#SearchDirect');
	if($sd.checkbox) {
		$sd.checkbox({empty: '/img/empty.png'});
		var $img = $sd.parent().find('img');
		$sd.removeAttr('checked');
		$img.attr('title', search_allflights);
		$img.click(function(ev) {
			var chk = ($sd.attr('checked') != true)
			$img.attr('title', chk ? search_directflights : search_allflights);
			$img.tooltip({
				delay: 0,
				showURL: false,
				showBody: " - ",
				left: -100
			});
		});
		$img.tooltip({
			delay: 0,
			showURL: false,
			showBody: " - ",
			left: -100
		});
	}
});

