// JavaScript Document

$(function(){

		function checkDates(dateText, inst) {
			$dateFrom = $("#d1").datepicker( "getDate" );
			$dateTo = $("#d2").datepicker( "getDate" );
			
			if ($dateTo!=null && $dateFrom!=null && ($dateTo < $dateFrom) ) 
			{
				$('#cars .errormessage').html("Drop-off date has to be later than Pick-up date.<br /> Please correct the dates. ");
				//alert("Drop-off date has to be later than Pick-up date. Please correct dates. ")
			}
			else
				$('#cars .errormessage').html("");
			
			
		}

		// Datepicker
		$('#d1').datepicker({
			minDate: 0, 
			onClose: checkDates
		});
		
		$('#d2').datepicker({
			minDate: 0,
			onClose: checkDates
		});		
		
		
		/*
		// temporarily commented until finding airport codes autocomplete function 
		// configure autocpmplete to get city / state  from geonames
		$("#crc").autocomplete({
			source: function(request, response) {
				$.ajax({
					url: "http://ws.geonames.org/searchJSON",
					dataType: "jsonp",
					data: {
						featureClass: "P",
						style: "full",
						maxRows: 12,
						country: 'US',
						//name_startsWith: request.term
						name_startsWith: function () { return $("#crc").val() }

					},
					success: function(data) {
						response($.map(data.geonames, function(item) {
							return {
								// label: item.name + (item.adminName1 ? ", " + item.adminName1 : "") + ", " + item.countryName,
								//value: item.name + (item.adminName1 ? ", " + item.adminName1 : "") + ", " + item.countryName
								label: item.name + (item.adminName1 ? ", " + item.adminCode1 : "") + ", " + item.countryCode,
								value: item.name + (item.adminName1 ? ", " + item.adminCode1 : "") + ", " + item.countryCode
							}
						}))
					}
				})
			},
			minLength: 2,
			select: function(event, ui) {
				//log(ui.item ? ("Selected: " + ui.item.label) : "Nothing selected, input was " + this.value);
			},
			open: function() {
				$(this).removeClass("ui-corner-all").addClass("ui-corner-top");
			},
			close: function() {
				$(this).removeClass("ui-corner-top").addClass("ui-corner-all");
			}
		});
		
		*/
	

		
	});