﻿function setOmnitureVariables()
{
    //Set channel, site type, site section 1
    s.channel="Rice Krispies";
    s.prop8="Rice Krispies";
    s.prop1 = 'Rice Krispies';
    
    //Set the hierarchy variables
    var maxProp = 7;
    var lastString =  s.prop1;
    var count = 1;
    
    //set the hierarchy by splitting up the url
    var uri = parseUri(document.URL);
    var split = uri.directory.split('/');
    for (count=1;count<split.length;count++)
    {
        if(count!=1)
        {
            lastString += ":" + split[count-1];
            eval("s.prop" + (count) + "='" + lastString + "'");
        }
    }
    
    //Set the final hierarchy variables if we didn't go this deep.
    count--;
    while(count <= maxProp)
    {
        eval("s.prop" + (count) + "='" + lastString + "'");            
        count++;
    }
    
    //set the hiearchy
    s.hier1=s.prop7;
    s.prop9=s.prop7;
    
    //set the page name from the aspx part
    if(uri.file!="")
        s.pageName = s.prop7 + ":" + uri.file.split('.')[0]; 
    else
        s.pageName = s.prop7 + ":Home";
}

function setPageNotFound()
{
    s.pageType = 'Page Not Found';
    s.pageName = 'Rice Krispies:Page Not Found';
}

function setPrintEvent(obj,recipeTitle)
{
    linkCode(obj,'events,eVar40','event24',"s.events='event24';s.eVar40='" + recipeTitle + "'",'o','Recipe Printed');
}

function setRatingEvent(obj,rating)
{
    linkCode(obj,'events,eVar39','event26',"s.events='event26';s.eVar39='"+rating+"'",'o','Recipe Rated');
}

var OMNITURE_FUNCTIONS = []
function addOmnitureFunctionToList(fn)
{
    OMNITURE_FUNCTIONS.push(fn);
}
function callFunctions()
{
    while(OMNITURE_FUNCTIONS.length > 0)
        (OMNITURE_FUNCTIONS.shift())();
}

// parseUri 1.2.2
// (c) Steven Levithan <stevenlevithan.com>
// MIT License
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*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
	}
};