﻿

// BEGIN OMNITURE FUNCTIONS
function get_omni_account_number() {
    var acct = "";
    // Override acct number if site is staging, demo or beta (even if it is at rl domain)
    if (location.host.indexOf("stage") != -1 || location.host.indexOf("demo") != -1 || location.host.indexOf("beta") != -1 || location.host.indexOf("sitewire") != -1) {
        // Omniture Account Number (test)
        if (location.host.indexOf("sitewire") != -1) {
            acct = "drolivegardenswtest";
        }
        else {
            acct = "drolivegardendemo";
        }
    }
    else if (location.host.indexOf("olivegarden.com") != -1) {
        acct = "drolivegarden";
    }
    else if (location.host.indexOf("olivegarden.ca") != -1) {
        acct = "drolivegardencanada";
    }

    if (location.search == '?check_omni_acct') alert(acct);
    return acct;
}


function get_omni_content_cat_do_not_use() {
    var cat = "";
    // The info below needs to be updated per Olive Garden
    if (location.host.indexOf('gift.olivegarden') != -1 || location.host.indexOf('store.olivegarden') != -1 || location.host.indexOf('webfodder') != -1 || location.host.indexOf('65.121.22.155') != -1) {
        cat = "Marketplace";
    }
    else if (location.host.indexOf('locator_VE') != -1 || location.host == 'locator.olivegarden.com' || location.host == 'locator.olivegarden.ca' || location.host.indexOf('where2getit') != -1) {
        cat = "Locator";
    }
    else if (location.host == 'menus.olivegarden.com') {
        cat = "Menus";
    }
    else if (location.host.indexOf("bluehornet.com") != -1 || location.host == 'freshcatch.olivegarden.com') {
        if (location.href.indexOf('invite') != -1) {
            cat = "Invite Your Friends";
        }
        else {
            cat = "Club";
        }
    }
    else if (location.host.indexOf('hospitaliano.olivegarden') != -1) {
        //log("statement executed");
        cat = "Newsletter";
        //log("cat is:" + cat);
    }
    else {
        var content_categories = new Object;
        content_categories['contact_us'] = "Contact Us";
        content_categories['company'] = "Company";
        content_categories['employment'] = "Employment";
        content_categories['community'] = "Community";
        content_categories['our_locations'] = "Our Locations";
        content_categories['press'] = "Press";
        content_categories['sitemap'] = "Site Map";
        content_categories['search'] = "Search";
        content_categories['culinary'] = "Our Culinary Inspiration";
        content_categories['menus'] = "Our Menu";
        content_categories['wines'] = "Our Wines";
        content_categories['recipes'] = "Recipes";
        content_categories['marketplace'] = "Gift Cards";
        content_categories['policy'] = "Privacy Policy";
        content_categories['legal'] = "Legal Notices";

        var top_level_directory;
        top_level_directory = js_pathparts[1];
        //log("Log:" + top_level_directory);
        if (content_categories[top_level_directory]) {
            //log("statement executed");
            cat = content_categories[top_level_directory];
            //log("cat is:" + cat);
        }
        else if (js_pathparts[1].indexOf('Default') != -1 || js_pathparts[1].indexOf('default') != -1 || js_pathparts[1] == '') {
            cat = "Home Page";
        }
        else if (js_pathparts[2] == "") {
            cat = "Root";
        }
        else {
            cat = "Other";
        }
    }
    if (location.search == '?check_omni_cat') alert(cat);
    return cat;
}

// END OMNITURE FUNCTIONS

//Omniture Hierarchy
var string_omni_hier = "";
if (location.search.indexOf('server_path') != -1) {
    js_server_path = new String(location.search);
    js_server_path.replace("server_path=", "");
    var js_pathparts = js_server_path.split("/");
}
else {
    var js_server_path = location.pathname.replace('.asp', '');
    var js_pathparts = js_server_path.split("/");
}

// Uses the ParseUri function to get the hierarchy from the url for Omniture
// For Recipes and Menus, the category and server path is used to display hierarchy.
// i.e www.olivegarden.com/menus/menu/?server_path=/menus/dinner/appetizers/ 
// /menus/dinner/appetizers is shown as the hierarchy
function get_omni_hier() {
    var cat = get_omni_content_cat();
    parseUri.options.strictMode = true;
    var hier = "";
    var items = parseUri(location);
    hier = items.path;

    if (cat == "Recipes") { if (location.search.indexOf("category") != "-1") { if (items.queryKey["category"] != "") { hier = items.directory + items.queryKey["category"]; } } }
    if (cat == "Our Menu") { if (location.search.indexOf("server_path") != "-1") { if (items.queryKey["server_path"].length > 0) { hier = items.queryKey["server_path"]; } } }
    if (hier.substring(hier.length - 1, hier.length) == "/") { hier = hier + "default"; }
    hier = hier.replace(".asp", "");
    if (hier.substring(0, 1) == "/") { hier = hier.substring(1, hier.length); } return hier;
}

function parseUri(str) {
    var o = parseUri.options,
		m = o.parser[o.strictMode ? "strict" : "loose"].exec(str),
		uri = {},
		i = 14;

    while (i--) uri[o.key[i]] = m[i] || "";

    uri[o.q.name] = {};
    uri[o.key[12]].replace(o.q.parser, function($0, $1, $2) {
        if ($1) uri[o.q.name][$1] = $2;
    });

    return uri;
};

parseUri.options = {
    strictMode: false,
    key: ["source", "protocol", "authority", "userInfo", "user", "password", "host", "port", "relative", "path", "directory", "file", "query", "anchor"],
    q: {
        name: "queryKey",
        parser: /(?:^|&)([^&=]*)=?([^&]*)/g
    },
    parser: {
        strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
        loose: /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
    }
};





