﻿// CallWebServiceMethods.js

// This function calls the Web service method 
// that returns an XmlDocument type.  
// parameters 
// propetyUnitId string
// startDate Date
// endDate Date
function GetDatesForCheckIn(calendarId, pmAccountId, propertyId, propetyUnitId, year, month) {
    AjaxWebService.GetDatesForCheckIn(calendarId, pmAccountId, propertyId, propetyUnitId, year, month, SucceededCallbackWithContext, FailedCallback, "XmlDocument")
}

function GetDatesForCheckOut(propertyId, propetyUnitId, year, month, day, checkInDate) {
    AjaxWebService.GetDatesForCheckOut(propertyId, propetyUnitId, year, month, day, checkInDate, SucceededCallbackWithContext, FailedCallback, "XmlDocument")
}

function GetBlockedStartDate(propetyUnitId, year, month, day) {
    AjaxWebService.GetBlockedStartDate(propetyUnitId, year, month, day, SucceededCallbackWithContext, FailedCallback, "XmlDocument")
}

function GetBlockedEndDate(propetyUnitId, year, month, day, checkInDate) {
    AjaxWebService.GetBlockedEndDate(propetyUnitId, year, month, day, checkInDate, SucceededCallbackWithContext, FailedCallback, "XmlDocument")
}


// This is the callback function invoked if the Web service
// succeeded.
// It accepts the result object, the user context, and the 
// calling method name as parameters.
function SucceededCallbackWithContext(result, userContext, methodName) {
    if (userContext == "XmlDocument") {
        if (methodName == "GetDatesForCheckIn") {
            AvailabilityCalendarContainer.GetDatesForCheckInCallback(result);
        }
        else if (methodName == "GetDatesForCheckOut") {
            var callback = new CheckOutDateCallBack();
            callback.Calendar = myCheckOutCalendar;
            callback.run(result);
        }
        else if (methodName == "GetBlockedStartDate") {
            var callback = new BlockedStartDateCallBack();
            callback.Calendar = myBlockedStartDates;
            callback.run(result);
        }
        else if (methodName == "GetBlockedEndDate") {
            var callback = new BlockedEndDateCallBack();
            callback.Calendar = myBlockedEndDates;
            callback.run(result);
        }
    }
}

// This is the callback function invoked if the Web service
// succeeded.
// It accepts the result object as a parameter.
function SucceededCallback(result, eventArgs) {
}


// This is the callback function invoked if the Web service
// failed.
// It accepts the error object as a parameter.
function FailedCallback(error) {
    alert(error.get_message());
    // Display the error.    
    var errorElem = document.getElementById("ErrorId");
    if (errorElem) {
        errorElem.innerHTML = "Service Error: " + error.get_message();
    }

    AvailabilityCalendarContainer.stop();
}

if (typeof (Sys) !== "undefined") Sys.Application.notifyScriptLoaded();
