// Let's check which button is checked on page load and show the correct form
if ( $(".home .hotelBtn input").is(":checked") ) {
    $("#flight").hide();
    $("#coupon").hide();
    $("#hotel").show();
} else if ( $(".home .couponBtn input").is(":checked") ) {
    $("#flight").hide();
    $("#hotel").hide();
    $("#coupon").show();
} else if ( $(".home .flightBtn input").is(":checked") ) {
    $("#hotel").hide();
    $("#coupon").hide();
    $("#flight").show();
}

// Let's make the whole area of the form selector clickable for easier use
$("#formOption > ul > li > label").click(function () {
	$(this).parent().children("input").click();
});

// Change the form based on radio button's parent LI (for IE)
$(".hotelBtn").click(function(){
	$("#coupon").hide();
	$("#flight").hide();
	$("#hotel").show();
});

$(".flightBtn").click(function(){
	$("#coupon").hide();
	$("#hotel").hide();
	$("#flight").show();
});

$(".couponBtn").click(function(){
	$("#hotel").hide();
	$("#flight").hide();
	$("#coupon").show();
});


// Change the form based on radio button
//$("input[name=formSelect]").change(function () {
//	$("#hotel").toggle();
//	$("#flight").toggle();
//});



// Clear default form values
function clearDefault(elem){ if( elem.value==elem.defaultValue )
elem.value = ''}

function restoreDefault(elem){ if( elem.value=='' ) elem.value =
elem.defaultValue}

$('#toggle').toggle(function(){
	$('#newsletter').stop().animate({ top: "0"}, 200);
}, function() {
	$('#newsletter').stop().animate({ top: "-228px"}, 200);
});

$('.calendar').click(function(){
	$('#newsletter').stop().animate({ top: "-228px"}, 200);
});


// Datepicker
$('.calendar input').datepicker({dateFormat:'mm/dd/y'});
    
    


// Remove the default value from the zip code on submit so it doesnt cause a Mailchimp error 
$(function(){

var defaultVal = $("#zip").val();

$("#signup").click(function(e){

var newVal = $("#zip").val();    
    
    if(defaultVal === newVal)
       {
           $("#zip").val('');
       }
   });    
    
});

// Change the quantity of tickets or rooms
$(function(){
	var quantity = $('#tickets');
	$('#flight .plus').click(function(e){
		if ( isNaN(quantity.val()) | quantity.val()== '') {
		quantity.val('1');
		};
		var newVal = parseInt(quantity.val()) + 1;
		quantity.val(newVal);
	});
	$('#flight .minus').click(function(e){
		if ( isNaN(quantity.val()) | quantity.val()== '') {
		quantity.val('1');
		};
		if ( parseInt(quantity.val()) > 1 ) {
		var newVal = parseInt(quantity.val()) - 1;
		quantity.val(newVal);
		};
	});
});

$(function(){
	var quantity = $('#rooms');
	$('#hotel .plus').click(function(e){
		if ( isNaN(quantity.val()) | quantity.val()== '') {
		quantity.val('1');
		};
		var newVal = parseInt(quantity.val()) + 1;
		quantity.val(newVal);
	});
	$('#hotel .minus').click(function(e){
		if ( isNaN(quantity.val()) | quantity.val()== '') {
		quantity.val('1');
		};
		if ( parseInt(quantity.val()) > 1 ) {
		var newVal = parseInt(quantity.val()) - 1;
		quantity.val(newVal);
		};
	});
});

// Autocommplete
$(function() {
	var availableTags = [
"Calgary (YYC)",
"Montreal (YUL)",
"Ottawa (YOW)",
"Quebec (YQB)",
"Toronto (YYZ)",
"Vancouver (YVR)",
"Atlanta (ATL)",
"Anchorage (ANC)",
"Austin (AUS)",
"Baltimore (BWI)",
"Boston (BOS)",
"Charlotte (CLT)",
"Chicago (MDW)",
"Chicago (ORD)",
"Cincinnati (CVG)",
"Cleveland (CLE)",
"Columbus (CMH)",
"Dallas (DFW)",
"Denver (DEN)",
"Detroit (DTW)",
"Fort Lauderdale (FLL)",
"Fort Myers (RSW)",
"Hartford (BDL)",
"Honolulu (HNL)",
"Houston (IAH)",
"Houston (HOU)",
"Indianapolis (IND)",
"Kansas City (MCI)",
"Las Vegas (LAS)",
"Los Angeles (LAX)",
"Memphis (MEM)",
"Miami (MIA)",
"Minneapolis (MSP)",
"Nashville (BNA)",
"New Orleans (MSY)",
"New York (JFK)",
"New York (LGA)",
"Newark (EWR)",
"Oakland (OAK)",
"Omaha (OMA)",
"Ontario (ONT)",
"Orlando (MCO)",
"Philadelphia (PHL)",
"Phoenix (PHX)",
"Pittsburgh (PIT)",
"Portland (PDX)",
"Raleigh-Durham (RDU)",
"Sacramento (SMF)",
"Salt Lake City (SLC)",
"San Antonio (SAT)",
"San Diego (SAN)",
"San Francisco (SFO)",
"San Jose (SJC)",
"Santa Ana (SNA)",
"Seattle (SEA)",
"St. Louis (STL)",
"Tampa (TPA)",
"Washington D.C. (IAD)",
"Washington D.C. (DCA)",
"Beijing (PEK)",
"Tokyo (HND)",
"London (LHR)",
"Paris (CDG)",
"Hong Kong (HKG)",
"Frankfurt (FRA)",
"Madrid (MAD)",
"Bangkok (BKK)",
"Dubai (DXB)",
"Guangzhou (CAN)",
"Amsterdam (AMS)",
"Singapore (SIN)",
"Sydney (SYD)",
"Tokyo (NRT)",
"Jakarta (CGK)",
"Seoul/Incheon (ICN)"
		];
		$( ".autocomplete" ).autocomplete({
			source: availableTags
		});
	});
	
// Submit only the airport code	
$('#flight').submit(function(){
	var city = $('#from').val();
	apCodePos = city.search('\\(') + 1;
	apCode = city.substr(apCodePos,3);

	var city2 = $('#to').val();
	apCodePos2 = city2.search('\\(') + 1;
	apCode2 = city2.substr(apCodePos2,3);

	if ( apCodePos ) {
		$('#from').val(apCode);
	};
		
	if ( apCodePos2 ) {
		$('#to').val(apCode2);
	};
});

$('#hotel').submit(function(){
	var city = $('#dest').val();
	apCodePos = city.search('\\(') + 1;
	apCode = city.substr(apCodePos,3);
	if ( apCodePos ) {
		$('#dest').val(apCode);
	};
});
