$(document).ready(function()
{
	$('#pDate').datepicker({ minDate: 0, dateFormat: 'dd/mm/yy', firstDay: 1, showOtherMonths: true, selectOtherMonths: true	});
	$('#dDate').datepicker({ minDate: 0, dateFormat: 'dd/mm/yy', firstDay: 1, showOtherMonths: true, selectOtherMonths: true	});
	// When a pickup date is selected make the minDate for dropoff this date
    $('#pDate').change(function () 
	{
		var date_tmp = $('#pDate').val().split("/");
	    var date_help = $('#dDate').val();
        $('#dDate').datepicker('option', { minDate: new Date(date_tmp[2], date_tmp[1]-1, date_tmp[0]) }); 
	    $('#dDate').val(date_help);
    });

	// When a dropoff date is selected make the maxDate for pickup this date
    $('#dDate').change(function () 
	{
		var date_tmp = $('#dDate').val().split("/");
	    var date_help = $('#pDate').val();
        $('#pDate').datepicker('option', { maxDate: new Date(date_tmp[2], date_tmp[1]-1, date_tmp[0]) }); 
	    $('#pDate').val(date_help);
    });
	
	$('#pickup').autocomplete({
							source: "/post/getLocations.php",
							minLength: 2,
							select: function( event, ui ) {
								$("#ploc_id").val(ui.item.id);
								$("#dloc_id").val(ui.item.id);
								$("#dropoff").val(ui.item.label);
								$("#country_id").val(ui.item.country_code);
							}
						   })
							.focus(function() {
								if($( this ).val() == "Type an airport, city or town.")
   		 							$( this ).val( "" );
  							});
	$('#dropoff').autocomplete({
							source: function( request, response ) {
											$.getJSON( "/post/getLocations.php", {
											term: extractLast( request.term ),
											country_id: function() { return $("#country_id").val() }
											}, response );
							},
							minLength: 2,
							select: function( event, ui ) {
								$("#dloc_id").val(ui.item.id);
							}
						   })
							.focus(function() {
								if($( this ).val() == "Type an airport, city or town.")
   		 							$( this ).val( "" );
  							});


});
function split( val ) {
	return val.split( /,\s*/ );
}
function extractLast( term ) {
	return split( term ).pop();
}

function clearbox(el)
{
}

function clearDropOffbox(el)
{
}

function bookmarksite(title, url)
{
	if (document.all)
		window.external.AddFavorite(url, title);
	else if (window.sidebar)
		window.sidebar.addPanel(title, url, "")
}

