/*
 *  Local application object
 */
var AvailabilityRequest = {
    departureDate: null,
    returnDate: null,
    //baseServiceUrl: 'http://localhost/BookingService/BookingService.svc',     //  Development
    baseServiceUrl: '../BookingService/BookingService.svc',                     //  Deployed version
    serviceCallVerb: 'POST',
    serviceCallDataType: 'json',
    serviceCallContentType: 'application/json',
    AvailabilityRequestDiv: null,
    AvailabilityResponseDiv: null,
    LastRequestsDiv: null
};

/*
 *      Ajax
 */
var error;
//  Show the service call error
AvailabilityRequest.handleAjaxError = function (jqXHR, textStatus, errorThrown) {
    error = jqXHR;
    loading.hide();
    if (jqXHR.responseText) {
        errorModal.show(jqXHR.responseText);
    } else {
        errorModal.show(errorThrown);
    }

};

/*
    Initialize the objects when the dom is ready
*/
$(function () {

   $('#dp-return').datepicker({ autoclose: true }).on('changeDate', function (e) {

        if (e.target.name === 'departure') {
            AvailabilityRequest.departureDate = e.date;
        }

        if (e.target.name === 'return') {
            AvailabilityRequest.returnDate = e.date;
        }
    });

    //  Load jquery objects
    AvailabilityRequest.AvailabilityRequestDiv = $('#availability-request');
    AvailabilityRequest.AvailabilityResponseDiv = $('#availability-response');
    AvailabilityRequest.LastRequestsDiv = $('#last-requests');
});


