//Setup QuickQuote Events
Event.observe(window, 'load', function() {
	$('RoundTripTab', 'OneWayTab', 'OpenJawTab').each(function(button){
		Event.observe(button.id, 'click', quickQuoteToggleType);
	});
	$('AirRTSearch', 'AirOWSearch', 'AirOJSearch').each(function(button){
		Event.observe(button.id, 'mouseover', toggleSearch);
		Event.observe(button.id, 'mouseout', toggleSearch);
	});
	$$('.Airports').each( function(item) {
		Event.observe(item, 'click', function(){
			window.open('/city_codes.php', 'Airports',"menubar=no,resizable,scrollbars=1,status=no,width=600,height=500");
		});
	});
});

function toggleSearch(event) {
	id = (event.target) ? event.target.id : event;
	if($(id).on) {
		$(id).src = $(id).src.replace('search_on.gif','search.gif');
		$(id).on = false;
	} else {
		$(id).src = $(id).src.replace('search.gif','search_on.gif');
		$(id).on = true;
	}
}

function quickQuoteCloseCalendars() {
	$$('.datepicker').each(function(cal){cal.hide();})
}

function quickQuoteToggleType(event) {
	quickQuoteCloseCalendars();
	id = (event.target) ? event.target.id.replace('Tab','') : event.replace('Tab','');
	
	if(id == 'OpenJaw') {
		window.location = 'http://casatravel.techtrav.com';
	} else {
		$('RoundTrip', 'OneWay', 'OpenJaw').each(function(qq){(qq.id == id)?Effect.Appear(qq,{duration:0.5}):qq.hide()});
		$('RoundTripTab', 'OneWayTab', 'OpenJawTab').each(function(tab){(tab.id == id+'Tab')?tab.addClassName('On'):tab.removeClassName('On')});
	}
}
function initquickQuoteCalendars(lang) {
	new DatePicker({
		relative : 'AirRTInboundDate',
		language : lang,
		disablePastDate : true,
		disableFutureDate : false,
		externalControl : 'AirRTInboundCalendarTab',
		showDuration : 0.2,
		enableCloseEffect : false,
		keepFieldEmpty : true
	});
	new DatePicker({
		relative : 'AirRTOutboundDate',
		language : lang,
		disablePastDate : true,
		disableFutureDate : false,
		externalControl : 'AirRTOutboundCalendarTab',
		showDuration : 0.2,
		enableCloseEffect : false,
		keepFieldEmpty : true
	});
	new DatePicker({
		relative : 'AirOWOutboundDate',
		language : lang,
		disablePastDate : true,
		disableFutureDate : false,
		externalControl : 'AirOWOutboundCalendarTab',
		showDuration : 0.2,
		enableCloseEffect : false,
		keepFieldEmpty : true
	});
	new DatePicker({
		relative : 'AirOJOutboundDate',
		language : lang,
		disablePastDate : true,
		disableFutureDate : false,
		externalControl : 'AirOJOutboundCalendarTab',
		showDuration : 0.2,
		enableCloseEffect : false,
		keepFieldEmpty : true
	});
	new DatePicker({
		relative : 'AirOJInboundDate',
		language : lang,
		disablePastDate : true,
		disableFutureDate : false,
		externalControl : 'AirOJInboundCalendarTab',
		showDuration : 0.2,
		enableCloseEffect : false,
		keepFieldEmpty : true
	});
}

//copy value from the id to destination
function getAirSelectionId(text, li) {
    document.getElementById('HotelDestination').value = li.id;
}

//Functions
function quickQuoteInit(type, tripType, lang) {
	initquickQuoteCalendars(lang);
	quickQuoteToggleType(tripType+'Tab');
	new Ajax.Autocompleter('AirRTOutboundFrom', 'AirRTOutboundFromAutoComplete', '/ajax/air_cities.php', {
		paramName: 'city', 
		minChars: 3, 
		afterUpdateElement : function(text, li){document.getElementById('AirRTOutboundFrom').value = li.id;}
	});
	new Ajax.Autocompleter('AirRTOutboundTo', 'AirRTOutboundToAutoComplete', '/ajax/air_cities.php', {
		paramName: 'city', 
		minChars: 3, 
		afterUpdateElement : function(text, li){document.getElementById('AirRTOutboundTo').value = li.id;}
	});
	new Ajax.Autocompleter('AirOWOutboundFrom', 'AirOWOutboundFromAutoComplete', '/ajax/air_cities.php', {
		paramName: 'city', 
		minChars: 3, 
		afterUpdateElement : function(text, li){document.getElementById('AirOWOutboundFrom').value = li.id;}
	});
	new Ajax.Autocompleter('AirOWOutboundTo', 'AirOWOutboundToAutoComplete', '/ajax/air_cities.php', {
		paramName: 'city', 
		minChars: 3, 
		afterUpdateElement : function(text, li){document.getElementById('AirOWOutboundTo').value = li.id;}
	});
}
