﻿var s_account = "timecom";

    ferrari.TimeOmniture = function () {
        s_time.channel = 'cover store';
        s_time.prop16 = 'cover store';
        s_time.prop17 = location.href;
        s_time.pageName = "undefined page";

        /* Helper functions */
        function clearAllVars() {
            s.events = "";
            s.products = "";
        }

        function concatCommaVar(cvar, value) {
            if (s[cvar] != undefined && s[cvar] != '')
                s[cvar] += "," + value;
            else
                s[cvar] = value;
        }

        function addEvent(event) {
            this.concatCommaVar("events", event)
        }

        function addProduct(product) {
            this.concatCommaVar("products", product)
        }

        function setPurchaseID(purchaseID) {
            s.purchaseID = purchaseID;
        }

        function getProductName(product) {
            return product.IssueDate + " " + product.Name + " (" + product.SKU + ")";
        }

        function enumOrderProducts(order, action) {
            for (var i = 0; i < order.LineItems.length; i++) {
                var item = order.LineItems[i];

                action(item);

                for (var j = 0; j < item.ChildLineItems.length; j++)
                    action(item.ChildLineItems[j]);
            }
        }

        /**** EVENT HANDLERS ****/

        this.productViewed = function (product) {
        }

        this.textSearch = function (searchTerm, location) {
            s_time.prop18 = searchTerm;
            // s_time.prop19 = '100'; // search count
        }

        this.categorySelect = function (categoryName, location) {
        }

        this.birthdaySearch = function (birthdate) {
        }

        this.productSearchSelect = function (product) {
        }

        this.productAddToCart = function (product) {
        }

        this.productRemoveFromCart = function (product) {
        }

        this.proceedToCheckout = function (products) {
        }

        this.orderPlaced = function (order) {
        }

        this.pageView = function () {
            if (ferrari.analytics.getTimePageName)
                s_time.pageName = ferrari.analytics.getTimePageName();

            s_time.pageName = 'cover store|' + s_time.pageName;

            if (typeof (omnitureHookFunction) == "function")
                omnitureHookFunction();

            var s_code = s_time.t();
            if (s_code)
                document.write(s_code);
        }
    };
