var ajaxGateway;

/* Set the ajax gateway to that used by the current website */
function initAjaxGateway(localAjaxGateway) {
    ajaxGateway = localAjaxGateway;
}

/* Makes AJAX call to add item(s) to basket */
function addToBasket(eventListingId, hiPriceId, form) {
    var quantityStr = form.getInputs('text', 'quantity')[0].value;
    var quantity = 1;
    if (! isNaN(quantityStr) && ! quantityStr.length==0) {
        quantity = quantityStr;
    }
    // Create a proxy to pass the relevant form to the success method
    var callbackProxy = function(data) {
        addToBasketSuccessful(data, quantity)
    }
    // Get the submit button from the ticket form
    var addToBasketButton  = form.getInputs('submit','submit')[0];
    showAddToBasketContainer(addToBasketButton, 2, 1);
    // Add tickets
    ajaxGateway.addOrderItem(eventListingId, hiPriceId, quantity, document.URL, { callback:callbackProxy });
    // Clear the quantity input
    form.getInputs('text','quantity')[0].clear();
    return false;
}

/* User will continue shopping after adding an item to the basket */
function continueShopping() {
    shrinkSuccessContainer();
}