﻿bringmelunch.location = Class.create({
    office: "",
    address1: "",
    address2: "",
    address3: "",
    postcode: "",
    lat: 0,
    lng: 0,

    initialize: function() {
    }
});

bringmelunch.customerInfo = Class.create({
    customerName: "",
    phoneNumber: "",
    discountCode: "",
    emailOptIn: false,
    
    initialize: function() {
    }
});

bringmelunch.custLocation = {
    setBuffetLocation: function(location, onFnComplete, onFnError) {
        new Ajax.Request("/Services/AjaxLocation.aspx", {
            method: 'post',
            parameters: { type: "SetBuffetLocation",
                location: JSON.stringify(location)
            },
            onSuccess: onFnComplete,
            onFailure: function(result) { onFail( result.responseText.evalJSON() ); }
        });
    },
    saveDeliveryDetails: function(custInfo, location, onFnComplete, onFnError) {
        new Ajax.Request("/Services/AjaxLocation.aspx", {
            method: 'post',
            parameters: { type: "SaveDeliveryDetails",
                custinfo: JSON.stringify(custInfo), location: JSON.stringify(location)
            },
            onSuccess: onFnComplete,
            onFailure: function(result) { onFail(result.responseText.evalJSON()); }
        });
    },
    searchBuffets: function(location, onFnComplete, onFnError) {
        new Ajax.Request("/Services/AjaxLocation.aspx", {
            method: 'post',
            parameters: { type: "SearchBuffets",
                location: JSON.stringify(location)
            },
            onSuccess: function(result) { onFnComplete(result.responseText.evalJSON()); },
            onFailure: function(result) { onFail( result.responseText.evalJSON() ); }
        });
    }
}

