$j( document ).ready( function() {
	$j( 'input#different-dropoff' ).click( function() {
    	$j( 'tr#dropoff-row' ).toggle();
    } );
	
	$j( 'select.pickup-date' ).change( function() {
        $j( 'input#pickUpDate' ).val( $j( 'select#carhire-pickupyear' ).val() + '-' + $j( 'select#carhire-pickupmonth' ).val() + '-' + $j( 'select#carhire-pickupday' ).val() );
    } );
	$j( 'select.dropoff-date' ).change( function() {
        $j( 'input#dropOffDate' ).val( $j( 'select#carhire-dropoffyear' ).val() + '-' + $j( 'select#carhire-dropoffmonth' ).val() + '-' + $j( 'select#carhire-dropoffday' ).val() );
    } );

	$j( 'p.pricelink.search a' ).click( function() {
		$j( 'div#pre-loading-carhire' ).show();
	} );
	
	$j( 'form#carhire-search-form' ).submit( function() {
		$j( 'div#pre-loading-carhire' ).show();
	} )
	
    Calendar.setup( {
        align      : "br",
        inputField : "pickUpDate",
        ifFormat : "%Y-%m-%d",
        button : "carHirePickUpCalTrigger",
        firstDay : 1,
        weekNumbers : false,
        range: [dateRangeStart, dateRangeEnd],
        onUpdate: updatePickUp
    } );
    Calendar.setup( {
        align      : "br",
        inputField : "dropOffDate",
        ifFormat : "%Y-%m-%d",
        button : "carHireDropOffCalTrigger",
        firstDay : 1,
        weekNumbers : false,
        range: [dateRangeStart, dateRangeEnd],
        onUpdate: updateDropOff
    } );

    updatePickUp();
    updateDropOff();
} );

function updatePickUp()
{
	var _date = $j( 'input#pickUpDate' ).val().split( '-' );
	$j( 'select.pickup-date.year' ).val( _date[0] );
	$j( 'select.pickup-date.month' ).val( _date[1] );
	$j( 'select.pickup-date.day' ).val( _date[2] );
}
function updateDropOff()
{
    var _date = $j( 'input#dropOffDate' ).val().split( '-' );
    $j( 'select.dropoff-date.year' ).val( _date[0] );
    $j( 'select.dropoff-date.month' ).val( _date[1] );
    $j( 'select.dropoff-date.day' ).val( _date[2] );
}
