/*exported odModuleExtender */
/**
 * Allows us to inherit and override modules.  
 * The process to override a module is described here https://docs.orderdynamics.net/projects/OrderDynamics/Dev%20Wiki/Override%20Angular%20Controllers%20Services%20and%20Directives.aspx.
 */
var odModuleExtender = function (child, parent) {
    //copy properties that are directly at the parent level to the child
    for (var prop in parent) {
        if (parent.hasOwnProperty(prop)) {
            child[prop] = parent[prop];
        }
    }

    //setting up the construction of child with inherited parent
    function Extender() {
        this.constructor = child;
    }
    Extender.prototype = parent.prototype;
    child.prototype = new Extender();
};

;
/*exported GlobalConstants */
'use strict';

/**
 * These are the default constants that can be overridden per site in the siteConstants.js file that exists for every merchant site
 */
var GlobalConstants = (function() {

    var platformConstants = {
        rootUrl: '', // Do not set this.  Each merchant site should set their own if needed

        //templates, this is a list of ASP.NET MVC endpoints that return the view needed for each Angular Directive
        //You should find in the Angular directive a template:UrlBuilder.buildUrl that points to one of these, by finding the ASP.NET MVC controller/actionmethod you can see the view
        productPersonalizationUrl: '/ProductSpa/ProductPersonalization',
        productPersonalizationQuestionsUrl: '/ProductSpa/ProductPersonalizationQuestions',
        shoppingCartTemplateUrl: '/ShoppingCartSpa/ViewCart',
        shoppingCartModalTemplateUrl: '/ShoppingCartSpa/CartModal',
        cartItemsListingTemplateUrl: '/ShoppingCartSpa/CartItemsListing',
        cartItemDetailsTemplateUrl: '/ShoppingCartSpa/CartItemDetails',
        cartSummaryTemplateUrl: '/ShoppingCartSpa/Summary',
        checkoutContactTemplateUrl: '/CheckoutSpa/Contact',
        checkoutCreditCardTemplateUrl: '/CheckoutSpa/CreditCard',
        checkoutGiftCardTemplateUrl: '/CheckoutSpa/GiftCard',
        checkoutPaymentTabTemplateUrl: '/CheckoutSpa/PaymentTab',
        checkoutCreateAccountTemplateUrl: '/CheckoutSpa/CreateAccount',
        checkoutReceiverTemplateUrl: '/CheckoutSpa/Receiver',
        checkoutTemplateUrl: '/CheckoutSpa/ViewCheckout',
        checkoutShippingMethodTemplateUrl: '/CheckoutSpa/ShippingMethod',
        checkoutShippingRateTemplateUrl: '/CheckoutSpa/ShippingRate',
        checkoutButtonTemplateUrl: '/ShoppingCartSpa/CheckoutButton',
        shippingEstimateTemplateUrl: '/ShoppingCartSpa/ShippingEstimate',
        appliedDynamicPromotionsTemplateUrl: '/ShoppingCartSpa/AppliedDynamicPromotions',
        PayPalSubmitCartUrl: '/Checkout/SubmitCart',
        CheckOutPaypalTemplateUrl: '/CheckoutSpa/PayPal',
        submitPayPalExpressUrl: '/shoppingcart/SubmitPayPalExpress',
        addressValidateModalUrl: '/AddressSpa/ValidateModal',
        checkoutPageUrl: '/Checkout',
        homePageUrl: '/',
        signInPageUrl: '/Account/SignIn',
        mainPageMyAccountUrl: '/Account',
        productConfig: '/ProductSpa/ProductConfig',
        couponTemplateUrl: '/CouponSpa/Coupon',
        confirmPageTemplateUrl: '/ConfirmSpa/ViewConfirm',
        confirmShippingTemplateUrl: '/ConfirmSpa/Shipping',
        confirmViaTemplateUrl: '/ConfirmSpa/Via',
        confirmContactTemplateUrl: '/ConfirmSpa/Contact',
        confirmItemsListingTemplateUrl: '/ConfirmSpa/ItemsListing',
        addressLookupModalUrl: '/AddressSpa/LookupModal',
        productDescriptionTemplateUrl: '/ProductSpa/ProductDescription',
        productImageTemplateUrl: '/ProductSpa/ProductImage',
        productTabsTemplateUrl: '/ProductSpa/ProductTabs',
        addressAutocompleteTemplateUrl: '/AddressSpa/AddressAutocomplete',
        shoppingCartUrl: '/ShoppingCart',
        wishListUrl: '/WishList',
        productAddToCartTemplateUrl: '/ProductSpa/ProductAddToCart',
        productDetailTemplateUrl: '/ProductSpa/ProductDetail',
        createAccountTemplateUrl: '/AccountSpa/CreateAccount',
        countryListTemplateUrl: '/AddressSpa/CountryList',
        addressFormTemplateUrl: '/AddressSpa/Form',
        confirmationPageUrl: '/confirm',
        giftCardGrayImageUrl: '/Content/images/giftCardGrey.png',
        giftCardImageUrl: '/Content/images/giftCard.png',
        storeStockLocatorTemplateUrl: '/Stores/StoreStockLocator',

        //API
        //these are a list of WEB API end points, usually used in Angular services, ou should find in the Angular service (possibly elsewhere) a UrlBuilder.buildUrl pointing to one of these.
        addItemToShoppingCartUrl: '/api/ShoppingCart/addItem',
        restoreItemToShoppingCartUrl: '/api/ShoppingCart/restoreItem',
        removeItemFromShoppingCartUrl: '/api/ShoppingCart/removeItem',
        updateShoppingCartItemUrl: '/api/ShoppingCart/updateItem',
        updatePricingBonusItemUrl: '/api/ShoppingCart/updatePricingBonusItem',
        updateDynPromoBonusItemUrl: '/api/ShoppingCart/updateDynPromoBonusItem',
        shoppingCartApiUrl: '/api/ShoppingCart',
        getItemQuestionsUrl: '/api/ShoppingCart/GetAnsweredPersonalizationQuestionsForItem',
        udpateItemQuantityUrl: '/api/ShoppingCart/UpdateItemQuantity',
        checkoutApiUrl: '/api/Checkout',
        submitCartApiUrl: '/api/Checkout/SubmitCart',
        checkOrderStatusApiUrl: '/api/Checkout/CheckOrderStatus',
        addCreditCardPaymentUrl: '/api/Checkout/AddCreditCardPayment',
        getCreditCardTypesApiUrl: '/api/Checkout/GetCreditCardTypes',
        addPayPalOptionUrl: '/api/Checkout/AddPayPalOption',
		threeDsVerifyApiUrl: '/api/Checkout/VerifyThreeDs',
		requireCSCValidationApiUrl:'/api/Checkout/RequireCSCValidation',
        getGiftCardSettingsApiUrl: '/api/Checkout/GetGiftCardSettings',
        getOrderFormGiftcardsApiUrl: '/api/Checkout/GetOrderFormGiftcards',
        getOrderFormPaymentsApiUrl: '/api/Checkout/GetOrderFormPayments',
        getGiftCardBalanceApiUrl: '/api/Checkout/GetGiftCardBalance',
        addGiftCardsToOrderFormApiUrl: '/api/Checkout/AddGiftCardsToOrderForm',
        addReceiverMiscInfoToOrderFormApiUrl: '/api/Checkout/AddReceiverMiscInfoToOrderForm',
        addAddressDataToOrderFormApiUrl: '/api/Checkout/AddAddressDataToOrderForm',
        getShippingCountriesUrl: '/api/ShoppingCart/GetShippingCountries',
        getShippingRatesUrl: '/api/ShoppingCart/GetShippingRates',
        getShoppingCartDynamicPromotionsUrl: '/api/ShoppingCart/GetShoppingCartDynamicPromotions',
        updateShippingAddressUrl: '/api/ShoppingCart/UpdateShippingAddress',
        updateShippingRateUrl: '/api/ShoppingCart/UpdateShippingRate',
        orderConfirmApiUrl: '/api/Confirm',
        GetOrderApiUrl: '/api/Confirm/GetOrder',
        productApiUrl: '/api/Product',
        getProductApiUrl: '/api/Product/GetProduct',
        getProductConfigApiUrl: '/api/Product/GetProductConfig',
        voteProductReviewApiUrl: '/api/Product/VoteProductReview',
        globalAddressServiceApiUrl: '/api/GlobalAddressService',
        validateAddressUrl: '/api/GlobalAddressService/ValidateAddress',
        lookupAddressUrl: '/api/GlobalAddressService/LookupAddress',
        addressFormServiceApiUrl: '/api/AddressForm',
        getCountryInfosApiUrl: '/api/AddressForm/GetCountryInfos',
        getDefaultCountryApiUrl:'/api/AddressForm/GetDefaultCountry',
        getCountryProvincesUrl: '/api/AddressForm/GetCountryProvinces',
        createAccountUrl: '/api/Account/CreateAccount',
        addCouponToShoppingCartUrl: '/api/ShoppingCart/AddCoupon',
        listCouponsUrl: '/api/ShoppingCart/ListCoupons',
        removeCouponFromShoppingCartUrl: '/api/ShoppingCart/RemoveCoupon',
        submitAffirmUrl: '/api/Checkout/SubmitAffirm',
        //----------------------Errors--------------------------

        errorCodeUnauthorized: 401,
        errorCodeServerError: 500,

        // -------------------- Website API --------------------
        websiteApiUrl: '/api/website',
        // Gets website data such as ID and currency symbol
        getWebsiteData: '/api/website/getWebsiteData',


        //other

        //IFrame source for 3DS checkout
        threeDsNotifierUrl: '/3DSNotifier.axd',
        //used in checkoutsvc to Send a request to service to check if 3ds successfully processed.
        threeDsVerifierUrl: '/3DSVerifier.axd',

        //element identifier for the element the Angular cart app hangs off.
        CartAppId: 'appCart',

        //element identifier for the element the Angular Product app hangs off.
        ProductAppId: 'appProduct',

        //element identifier for the element the Angular model cart app hangs off.
        CartModalId: 'shoppingCartModal',

        //span id where carthelper injects item quantity
        CartSmallBadgeId: 'shoppingCartSmallBadge',
        //span id where carthelper injects item quantity
        CartLargeBadgeId: 'shoppingCartLargeBadge',

        AddToCartButtonIdPrefix: 'btnAddToCart',
        AddToCartButtonClassIdentifier: 'btn-add-to-cart-product-detail',

        delimiter: ';;',
        shippingTotalId: 'shippingTotal',
        spinnermodalId: 'spinnermodal',
        spinnerfadeId: 'spinnerfade',
        spinnertextId: 'spinnertext',

        //---------------- Regex ---------------------
        emailRegex: /[-0-9a-zA-Z.+_]+@[-0-9a-zA-Z.+_]+\.[a-zA-Z]{2,4}/,
        phoneNumberRegex: /^[-,\d,\s]+$/,

        timesToCheckSubmitedOrder: 5,

        //custom configuration

        disableAjaxRequestCache: false,
        disableLocationServices: false
    };

    //constructor
    function GlobalConstants(siteConstants) {

        var getConstant = function(name) {
            if (siteConstants && siteConstants[name] !== undefined) {
                return siteConstants[name];
            }
            return platformConstants[name];
        };

        //copy all the properties from platformConstants to the GlobalConstants, 
        //but if we have an override - choose and override first, 
        //if no - chose platform value
        for (var p in platformConstants) {
            if (platformConstants.hasOwnProperty(p)) {
                this[p] = getConstant(p);
            }
            }

        //overrides can have custom properties not available in platform, we should add them as well
        for (var c in siteConstants) {
            if (siteConstants.hasOwnProperty(c) && !this.hasOwnProperty(c)) {
                this[c] = siteConstants[c];
            }
        }
    }

    return GlobalConstants;
})();;
/*exported GlobalLocalization */
'use strict';

/**
 * These are the default localization  that can be overridden per site.
 */
var GlobalLocalization = (function () {
    
    //constructor
    function GlobalLocalization(siteLocalizations) {

        //copy all localization to the platform
        for (var c in siteLocalizations) {
            if (siteLocalizations.hasOwnProperty(c)) {
                this[c] = siteLocalizations[c];
            }
        }
    }

    return GlobalLocalization;
})();;
/*exported platformSpecExecutor */
'use strict';

/**
 * Executes specs for platform.
 * You can disable spec by calling disableSpec function.
 * You should provide a valid spec name.
 */
var platformSpecExecutor = (function() {

    var disabledSpecs = [];

    var executeSpec = function (specName, spec) {

        //if spec is not in disabled specs list - execute spec
        if (disabledSpecs.indexOf(specName) === -1) {
            spec();
            return true;
        }
        //otherwise - return false - not executed.
        return false;
    };

    var disableSpec = function (specName) {
        disabledSpecs.push(specName);
    };

    return {
        executeSpec: executeSpec,
        disableSpec: disableSpec
    };

})();;
'use strict';

/**
 * IE8 does not fully support trim and indexOf functions. So here we add them in if they do not exist.
 */
$(document).ready(function () { // jshint ignore:line
    //indexOf function
    if (!Array.prototype.indexOf) {
        Array.prototype.indexOf = function (elt /*, from*/) {
            var len = this.length >>> 0; // jshint ignore:line
            var from = Number(arguments[1]) || 0;
            from = (from < 0) ? Math.ceil(from) : Math.floor(from);
            if (from < 0) {
                from += len;
            }

            for (; from < len; from++) {
                if (from in this && this[from] === elt) {
                    return from;
                }
            }
            return -1;
        };
    }
    //trim function
    if (typeof String.prototype.trim !== 'function') {
        String.prototype.trim = function() {
            return this.replace(/^\s+|\s+$/g, '');
        };
    }
});;
