﻿var PromotionalCode = 
{
    promo: {}
}

// AJAX call to get promo object by giving code
function getPromocode(code, subTotal, successCallback, errorCallback)
{
    jQuery.ajax({
        url: "/Handlers/ShoppingCart.ashx",
        global: false,
        type: "POST",
        data: ({ action: "getPromo", code: code, subTotal: subTotal }),
        dataType: "json",
        success: function(response)
        {
            PromotionalCode.promo = response;
            
            // check whether we define callback function
            if (successCallback)
            {
                // it is defined then call it with response
                successCallback(response);
            }
        },
        error: function(XMLHttpRequest, textStatus, errorThrown)
        {
            // reset the promo
            PromotionalCode.promo = {};
            
            // check whether we define callback function
            if (errorCallback)
            {
                // it is defined then call it with error
                errorCallback(textStatus);
            }
        }
    });
}

