/**
 * liveManager.js
 * $Revision: 1.15 $
 * universal tag - liveManager.js 2.0.20100703.1200, Copyright 2010 Tealium.com Inc. All Rights Reserved.
*/
if(typeof cdcPageTimers!="undefined")cdcPageTimers.utloader=new Date();

if (typeof(cdc) == "undefined") cdc = new Object();
if (typeof(cdc.util) == "undefined") cdc.util = new Object();
if (typeof(cdc.util.ensureNamespace) == "undefined"){
    cdc.util.ensureNamespace = function(namespaceStr) {
        if (!namespaceStr) return;
        var parts = namespaceStr.split(".");
        var o = window;
        for (var i = 0; i < parts.length; i++) {
            var aPart = parts[i];
            if (typeof(o[aPart]) != "object") {
                o[aPart] = new Object();
            }
            o = o[aPart];
        }
    }
}

/* Ensure Namespace */
cdc.util.ensureNamespace("cdc.ut.liveManager");
cdc.util.ensureNamespace("cdc.ut.trackEvent");
cdc.util.ensureNamespace("cdc.ut.eventqueue");

/* Global UT config object */
cdc.util.ensureNamespace("cdc.ut.config");

/*
 Method: cdc.ut.config.set()
 
 Description:
	*Page Level Customization*
    Set the properties of <config> object directly on the page. 
	We can On/Off metric call on the page. Need to pass variable name and value to this method for page level customization. Internally this method set this variable and their value to <config> object. 
	Once <cdc.ut.liveManager.ONLOAD()> method invoke then first it checks the config object if any variable/object present there then it updates the same variable/object in to <cdc.ut.liveManager.config> object.
 
 Sample Usage:
	>	cdc.ut.config.set("send",{dop:true,s_code:false});
	>	cdc.ut.config.set({
	>		rs_map_src:"//cdn.tealium.com/deployment_toolkit/cisco/v3/rs_map.js",
	>		trackevent_src:"//cdn.tealium.com/deployment_toolkit/cisco/v3/trackEvent.js",
	>		ntpagetag_src:"//cdn.tealium.com/deployment_toolkit/cisco/v3/ntpagetag.js",  
	>		s_code_ut_src:"//cdn.tealium.com/deployment_toolkit/cisco/v3/s_code_ut.js"
	>	});
 
 Params:
	-	There two parameters reqiured for this method. Need to pass the variable name & value.
	-	a - It holds the two types of value. Either it could be string or object.
	-	b - b value is depend on a, if a holds string type of value then b holds the object otherwise it not hold any value.

*/

cdc.ut.config.set=function(a,b,c){
	c={};
	if(typeof a=="string"){
		c[a]=b;
	}
	else c=a;
	
	for(a in c){
		if(typeof c[a]!="undefined"){
			cdc.ut.config[a]=c[a];
		}
	}
}

/* config overrides */
//cdc.ut.config.set({
//    rs_map_src:"//mike.tealium.com/svn/consulting/universal_tag/v1/cisco.com/cvs/br_ut_30_04082010/WP/Applications/wpx/SitewideAssets/web/fw/m/rs_map.js",
//    trackevent_src:"//mike.tealium.com/svn/consulting/universal_tag/v1/cisco.com/cvs/br_ut_30_04082010/WP/Applications/wpx/SitewideAssets/web/fw/m/trackEvent.js",
//    ntpagetag_src:"//mike.tealium.com/svn/consulting/universal_tag/v1/cisco.com/cvs/br_ut_30_04082010/WP/Applications/wpx/SitewideAssets/web/fw/m/ntpagetag.js",
//    s_code_src:"//mike.tealium.com/svn/consulting/universal_tag/v1/cisco.com/cvs/br_ut_30_04082010/WP/Applications/wpx/SitewideAssets/web/fw/m/s_code_ut.js",
//    s_code_ut_src:"//mike.tealium.com/svn/consulting/universal_tag/v1/cisco.com/cvs/br_ut_30_04082010/WP/Applications/wpx/SitewideAssets/web/fw/m/s_code_ut.js",
//    dop_src:"//mike.tealium.com/svn/consulting/universal_tag/v1/cisco.com/cvs/br_ut_30_04082010/WP/Applications/wpx/SitewideAssets/web/fw/m/dop.js",
//    visualsciences_ut_src: "//mike.tealium.com/svn/consulting/universal_tag/v1/cisco.com/cvs/br_ut_30_04082010/WP/Applications/wpx/SitewideAssets/web/fw/m/visualsciences_ut.js"
//});


/*

Class: cdc.ut.liveManager

Description:
	*Object cdc.ut.liveManager*
	- holds configuration parameters
	- collects data from page
	- loads metric vendor libraries
	- loads trackEvent
	- tries to stop vendor code duplication 

Overview:
	1 At the end of this file is a try / catch block that will run the <cdc.ut.liveManager.ONLOAD> method
		- Either when the jQuery ready event happens (if jQuery is loaded)
		- Or after a 3 second timeout if not.

	2 The <cdc.ut.liveManager.ONLOAD> method first checks a few details of the <cdc.ut.config> object if specified
		- Should probably add a check to not load specific libraries if not going to be used, not just not call them
		- Also ime the no-load didn't work.

	3 Then calls <loadFiles> method in set synchronous order for each other file to load
		-	Files are loaded by adding a script tag to the head
		-	Then a callback function can be triggered,
		-	Calls dop.INIT for dop, nothing for site catalyst
		-	When trackEvent has been loaded then callback functions are triggered it calls <PT()>, then <trackEvent.INIT> (earlier calls <cdc.ut.liveManager.LOAD> I think it tracks if it's been loaded, and evals the callback anything else???)
		-	And then sends a "view" event to <trackEvent.event> sending the params in liveManager.

	4 <PT> parses the page
		-	Saves all meta tag info,
		-	Parses hinav and/or treecrumb if present and uses that for sitearea info if so,
		-	Also has ability to save and pass thru arbitrary name/values in a track object if one is found in the page.
			(Cisco is currently not using this as we're trying to avoid things that require page level content changes, but the capability apparently exists.)

	5 <trackEvent.INIT> steps through the "plugins" in order and runs their _I methods if they have any commands in them (most don't)
		-	Then it runs any events that have been stored in a livemanager queue  (if any).

	6 Plugins are an array of pl[#] object (members of trackEvent)  _I methods <trackEvent.pl[]>
		-	Currently only <trackEvent.pl[3]> has an _I method... it uses this to attach a mousedown listener to the window and it tracks BAM impressions if applicable. 

	See OVERVIEW section in LiveManager for what happens when initial "view" or other event is triggered.
 
 
Properties:
----------
-	q{}				:	Temporary queue object for trackEvent object calls made before the trackEvent library is loaded.
-	filesToLoad[]	:	The list of synchronous libraries to be loaded. This is built in cdc.ut.liveManager.loadFiles. The push order of this array is the order they will be initialized.
-	fileIsLoaded{}	:	*This is just used as a boolean flag?* this is used to make sure <cdc.ut.liveManager.LOAD> only runs once per library.
-	loadedFileCount :	Counter to store the number of libraries loaded synchronously.
-	o				:	Onload flag for the individual loaded synchronous libraries.
-	lmIsLoaded		:	Onload flag for liveManager to ensure the onload is called only once. We attach to the window onload and also set a 3 second timeout for loading in case the window onload is never triggered.
-	i				:	Utility image object for sending immediate tracking from liveManager directly.

*/


cdc.ut.liveManager = {
    q: {},
    filesToLoad: [],
    fileIsLoaded: {},
    loadedFileCount: 0,
    o: 0,
    lmIsLoaded: 0,
    img: [],
    
/*
Method: cdc.ut.liveManager.loadFiles()

Description: 
loadFile is the dom injection routine for creating a new script element in the head of the document.

Sample Usage:
Notice only one param passed in, it is a json object with 5 members. Structure like below:
	>	cdc.ut.liveManager.loadFiles({
	>		nodeIdSuffix:"dop",
	>		fileURL:"//cdn.tealium.com/deployment_toolkit/cisco/v2/release/dop.js?v="+cdc.ut.liveManager.trackingVariables["tag"],
	>		notAsync:1,
	>		callback:"cdc.ut.liveManager.dop.INIT()",
	>		initScript:"cdc.ut.liveManager.dop.ONLOAD()"
	>	});


Params: 
fileInformation	is a json object with 5 members. Each member contains the metric library information.
	
	-	fileInformation.nodeIdSuffix	:	Name of Library (namespace),
	-	fileInformation.fileURL			:	URI location to JS file,
	-	fileInformation.notAsync		:	Synchronous flag(0-async, 1-sync),
	-	fileInformation.callback		:	Code to be evaluated in <cdc.ut.liveManager.LOAD()> when the script element is loaded. Each synchronous file loaded should have a <cdc.ut.liveManager.LOAD> trigger 
											calling back to cdc.ut.liveManager with the appropriate namespace value. Only called in synchronous mode.
	-	fileInformation.initScript		:	Code to be evaluated when the script element is created. 

*/

	loadFiles: function (fileInformation) {
    
		if(fileInformation.notAsync)
		{
			this.filesToLoad.push(fileInformation);
		}
		if(document.createElement)
		{
			var nodeId = "Lm_" + fileInformation.nodeIdSuffix;
			if (!document.getElementById (nodeId))
			{
				try{
					eval(fileInformation.initScript)
				} catch(exceptionObj) {};
				
				var scriptNode = document.createElement('script');
				scriptNode.language = 'javascript';
				scriptNode.type = 'text/javascript';
				scriptNode.src = fileInformation.fileURL;
				scriptNode.id = nodeId;
				document.getElementsByTagName("head")[0].appendChild (scriptNode);
			}
		}
	},

/*
Method: cdc.ut.liveManager.LOAD()
 
Description:
	When <loadFiles()> loads a library synchronously, Then callback function get trigger and call this function.
	looks more like this function is what triggers the callback??


	Sample Usage: 
	try{cdc.ut.liveManager.LOAD("MYLIB")}catch(e){}

	Params: 
	- libraryName : namespace of the library to load
	
	Utility Variables:
	- count : Length of the cdc.ut.liveManager.loadedFileCount
	- aFile : Reference to object passed in the cdc.ut.liveManager.loadFiles call

*/
    
    LOAD: function (libraryName) {
        this.fileIsLoaded[libraryName] = 0;
        var count = this.filesToLoad.length;
        for (var i = this.loadedFileCount; i<count; i++)
		{
            var aFile = this.filesToLoad[i];
            if (this.fileIsLoaded[aFile.nodeIdSuffix] == 0)
			{
                this.fileIsLoaded[aFile.nodeIdSuffix] = ++this.loadedFileCount;
                try
				{
                    eval(aFile.callback);
                } catch(e){
				}
            }else{
				return;
			}
        }
        if(this.loadedFileCount == count && this.o == 0)
		{
			this.o = 1;
		}
    },


/*
Method: cdc.ut.liveManager.bindEvent()

Description:
	Utility addEventListener / attachEvent function.
	The prefix "on" for Internet Explorer attachEvent handling is explicitly added.

Sample Usage: 
cdc.ut.liveManager.bindEvent("window","load",myLoadFunction)
	
Params:
-	domElement	:	Event object
-	eventName	:	Event name
-	callback	:	Event handler
-	useOnPrevix	:	Flag if set to 1 will not prefix the "on" substring to the event name. 
					This is used for any event to attach to that does not start with the prefix "on"

*/    
    
    bindEvent: function(domElement, eventName, callback, dontUseOnPrefix) {
        if(domElement.addEventListener) 
		{
            domElement.addEventListener(eventName, callback, false)
        }
		else if(domElement.attachEvent) 
		{
            domElement.attachEvent(((dontUseOnPrefix == 1)?"":"on")+eventName, callback)
        }
    }
}

/*
 Property: cdc.ut.liveManager.config 
 
 Description:
 *main configuration variable*, sets defaults that can be overridden in page markup by <set()>.

 -	domain					:	Holds cookie domain value (typically cosco.com)
 -	passthru				:	Determine if any unmapped attribute is passed through to Omniture Insight.
 -	sc_acct					:	Default SiteCatalyst account.
 -	sc_test					:	Test mode for SiteCatalyst. In test mode all SiteCatalyst traffic goes to cisco-dev, suite value is sent into prop46.
 -	sc_testaccount			:	Report suite to use for test mode
  -	dop_src					:	Relative path to a dop.js file to use in lieu of the livemanager configuration.
 -	dop_sensor				:	
 -	s_code_src				:	Relative path to a s_code.js file to use in lieu of the livemanager configuration.
 -	s_code_ut_src			:	Relative path to a s_code_ut.js file to use in lieu of the livemanager configuration.
 -	trackevent_src			:	Relative path to a trackEvent.js file to use in lieu of the livemanager configuration.
 -	rs_map_src				:	Relative path to a rs_map.js file to use in lieu of the livemanager configuration.
 -	visualsciences_ut_src	:	Relative path to a visualsciences_ut.js file to use in lieu of the livemanager configuration.
 -	dev_domain				:	Array of the domain list
 -	send					:	Object to turn on individual vendors: s_code and dop
 
 -	ntpagetag_src			:	Disabled for the moment.
 -	ntpagetag_sensor		:	Disabled for the moment.
 -	ntpagetag_sensor_secure	:	Disabled for the moment.
 

 - dop_ is : visual science parameters
 - sc_ is : site catalyst parameters

*/
cdc.ut.liveManager.config = {
    domain: ".cisco.com",
    exit_domain: "cisco.com",
    passthru: true,
    sc_acct: "cisco-us",
    sc_test: false,
    sc_testaccount: "cisco-dev",
    dop_src: "//www.cisco.com/web/fw/m/dop.min.js",
    dop_sensor: "//www.cisco.com/web/fw/tools/mktg_metrics/flashtag.txt?Log=1",
    dop_sensor_secure: "//www.cisco.com/web/fw/tools/mktg_metrics/flashtag.txt?Log=1",
	s_code_src: "//www.cisco.com/web/fw/m/s_code.min.js",
	s_code_ut_src: "//www.cisco.com/web/fw/m/s_code_ut.min.js",
	trackevent_src: "//www.cisco.com/web/fw/m/trackEvent.min.js",
    visualsciences_ut_src: "//www.cisco.com/web/fw/m/visualsciences_ut.min.js",
    rs_map_src: "//www.cisco.com/web/fw/m/rs_map.min.js",
	ntpagetag_src: "//www.cisco.com/web/fw/m/ntpagetag.min.js",
    ntpagetag_sensor: "//cisco-tags.cisco.com/tag/ntpagetag.gif",
    ntpagetag_sensor_secure: "//cisco-tags.cisco.com/tag/ntpagetag.gif",
// to do see if this dev_domain param can be eliminated entirely along with the function below at line 345 that calls it.
    dev_domain: [],
    send: {
        dop: true,
        s_code: true,
        tnt: true,
        ntpagetag: false
    }
}

/*
  Property: lh - Runtime init code (not in function)
  
  Description:
  Adds some values to <config> based on location.hostname 
*/
cdc.ut.liveManager.lh = location.hostname;
/*  
for (cdc.ut.liveManager.i = 0; cdc.ut.liveManager.i < cdc.ut.liveManager.config["dev_domain"].length; cdc.ut.liveManager.i++) {
    if (cdc.ut.liveManager.lh.indexOf(cdc.ut.liveManager.config["dev_domain"][cdc.ut.liveManager.i]) == 0) {
        cdc.ut.liveManager.config.preview = true;
        cdc.ut.liveManager.config.dop_sensor = "//preview.cisco.com/web/fw/tools/mktg_metrics/flashtag.txt?Log=1";
        for(var i in cdc.ut.liveManager.config){
            var j=cdc.ut.liveManager.config[i];
            if(typeof j=="string"&&i.indexOf("_src")>0){
                cdc.ut.liveManager.config[i]=j.replace("www.","preview.");
            }
        }
        break;
    }
}
*/
/*
  Property: localConfig - Runtime init code (not in function)
  
  Description:
  Makes a call to cdc.util.ut.getConfigInfo to retrieve override configuration values for testability
*/
try{
    cdc.ut.liveManager.localConfig = cdc.util.ut.getConfigInfo();
    if(cdc.ut.liveManager.localConfig !== false){
	for(var i in cdc.ut.liveManager.localConfig){
	    if(typeof cdc.ut.liveManager.localConfig[i]!='function'){
		if(i!='send'&&i!='dopconfig'&&i!='ntconfig') cdc.ut.liveManager.config[i] = cdc.ut.liveManager.localConfig[i];
	    }
	}
	//ignore ntconfig and dopconfig
	if(typeof cdc.ut.liveManager.localConfig['dopconfig']!='undefined'&&typeof cdc.ut.liveManager.localConfig.dopconfig['send']!='undefined'&&typeof cdc.ut.liveManager.localConfig.dopconfig.send['dop_sensor']!='undefined'){
	    cdc.ut.liveManager.config.dop_sensor=cdc.ut.liveManager.localConfig.dopconfig.send.dop_sensor;
	}
	
	try{cdc.ut.liveManager.config.dop_sensor=cdc.ut.liveManager.localConfig.dopconfig.send.dop_sensor;}catch(e){}
	try{cdc.ut.liveManager.config.dop_sensor_secure=cdc.ut.liveManager.localConfig.dopconfig.send.dop_sensor_secure;}catch(e){}
	try{cdc.ut.liveManager.config.ntpagetag_sensor=cdc.ut.liveManager.localConfig.ntconfig.send.ntpagetag_sensor;}catch(e){}
	try{cdc.ut.liveManager.config.ntpagetag_sensor_secure=cdc.ut.liveManager.localConfig.ntconfig.send.ntpagetag_sensor_secure;}catch(e){}
	
	//merge send
	if(typeof cdc.ut.liveManager.localConfig['send']!='undefined'){
	    for(var i in cdc.ut.liveManager.localConfig.send){
		if(typeof cdc.ut.liveManager.localConfig.send[i]!='function'){
		    cdc.ut.liveManager.config.send[i] = cdc.ut.liveManager.localConfig.send[i];
		}
	    }
	}
    }
}catch(e){}

cdc.ut.liveManager.storeRequest=function(id,url){
    try{
	if(cdc.ut.liveManager.config.store_requests[id]==true && sessionStorage){
	    var requestCounter = sessionStorage.getItem(id+'_rc');
	    if(!requestCounter){
	        requestCounter = 0;  
	    }
	    sessionStorage.setItem(id+'_r'+requestCounter,url);
	    sessionStorage.setItem(id+'_rc',parseInt(requestCounter)+1);
	}
    }catch(e){}
}

/*
Object: cdc.ut.trackEvent

Description:   
	Creates the trackEvent.event queue
	- for handling <trackEvent.event> calls that come before the trackEvent library is loaded
	- called any time trackEvent is called before the onLoad event
	- uses .t["tag"] which is ut code version id for result sniffing purposes
*/
if(typeof cdc.ut.eventqueue.q=="undefined")cdc.ut.eventqueue.q=[];

cdc.ut.trackEvent = {
    event: function(a, b) {
        var d="";
        for(var c in b){
            d+="&"+c+"="+b[c];
        }
        b["tag"]=cdc.ut.liveManager.trackingVariables["tag"];

        cdc.ut.eventqueue.q.push({a:a,b:b});
    }
};

//FIX flash coded videos to reference cdc.ut.trackEvent instead of trackEvent. this is a timing issue that needs to be handled carefully
/* this line is used for backwards compatibility with flash tracking that tries to access the trackEvent object directly */
var trackEvent = cdc.ut.trackEvent;

/*
Procedure: 
Stripping subdomains (code block not a function).

Description:
used to strip certain subdomains from the basepage dimension, used in setting cdc.ut.liveManager.trackingVariables.basepage value

-	pageLocation	:	pageLocation is holds the page path with hostname.
-	subDomains		:	subDomains is array type property and it holds the list of subdomains.

*/

cdc.ut.liveManager.pageLocation = location.hostname + location.pathname;
cdc.ut.liveManager.du = (document.URL.split("?"))[0];
if(cdc.ut.liveManager.du.indexOf("#")>0&&cdc.ut.liveManager.du.lastIndexOf("/") > cdc.ut.liveManager.du.indexOf("#")){
	cdc.ut.liveManager.pageLocation += location.hash;
}

/* need to investigate use of this array and eliminating it!! ajb */
cdc.ut.liveManager.subDomains = new Array('www.', 'ecmx-wip.', 'ecmx-staging.', 'ecmx-active.', 'wwwin-tools-stage.', 'cco-rtp-1.', 'dev-stage.', 'tools-stage.', 'wwwin-tools-dev.');

for (cdc.ut.liveManager.i = 0; cdc.ut.liveManager.i < cdc.ut.liveManager.subDomains.length; cdc.ut.liveManager.i++){
	cdc.ut.liveManager.pageLocation = cdc.ut.liveManager.pageLocation.replace(cdc.ut.liveManager.subDomains[cdc.ut.liveManager.i], '');
}

if (cdc.ut.liveManager.pageLocation.lastIndexOf('/') == cdc.ut.liveManager.pageLocation.length - 1){
	cdc.ut.liveManager.pageLocation = cdc.ut.liveManager.pageLocation.substring(0, cdc.ut.liveManager.pageLocation.length - 1);
}

/*
Properties: cdc.ut.liveManager.trackingVariables

Description: 
-	Holds main page tracking variables.
-	tag, basepage, elementtype, title, url, property, referrer, linktrack are set as default variables. these variable contains page level information.
-	As per the HTML page additional variable are set. These variables contains meta tags information and few page level data.


Examples:
http://cdc-site-dev.cisco.com:2013/API-examples/base-cdc-page.shtml

*These are set as defaults variables*
- tag					:	"ut2.2.20100128.00000.8625082555471705"
- basepage			:	"localhost/univeral_tagging/API-examples/base-cdc-page.shtml"
- elementtype			:	"page"
- title				:	"Universal Tagging - API Examples - Support IA path - Cisco Systems"
- url					:	"http://localhost/univeral_tagging/API-examples/base-cdc-page.shtml"
- property			:	"Cisco"
- referrer			:	"http://localhost/univeral_tagging/API-examples/"
- linktrack			:	"linkpage"

*Additinal variables set according to page*

- d_h1				:	"products/cisco products/cisco interfaces and modules/cisco physical security modules for routers/cisco integrated storage system module"
- d_h2				:	"products"
- d_h3				:	"products/cisco products"
- d_h4				:	"products/cisco products/cisco interfaces and modules"
- d_h5				:	"products/cisco products/cisco interfaces and modules/cisco physical security modules for routers"
- d_lc				:	"en-us"
- hinav				:	"index"
- loc					:	"http://localhost/univeral_tagging/API-examples/base-cdc-page.shtml"

- meta.accesslevel	:	"guest"
- meta.acronym		:	"iss"
- meta.concept		:	"cisco integrated storage system module"
- meta.contenttype	:	"cisco.com#us#postsales"
- meta.country		:	"us"
- meta.doctype		:	"tsd products support model home"
- meta.iapath			:	"products/cisco products/cisco interfaces and modules/cisco physical security modules for routers/cisco integrated storage system module"
- meta.language		:	"en"
- meta.locale			:	"us"
- meta.synonym		:	"video storage"
- meta.title			:	"cisco integrated storage system module - support"

- prevpage			:	""
- repeat				:	"Repeat"
- sa_source			:	"meta.iapath"
- site				:	"products"
- sitearea			:	"cisco.com#products#cisco products#cisco interfaces and modules#cisco physical security modules for routers#cisco integrated storage system module"
- suite				:	"cisco-us,cisco-usprodinterfaces"
- treecrumb			:	""
- vid					:	""

*/

cdc.ut.liveManager.trackingVariables = {
    //base variables
    basepage: cdc.ut.liveManager.pageLocation,
    property: "Cisco",
    tag: "ut2.0.20100823.1200",
    title: document.title,
    url: document.URL,
    referrer: eval("document." + "referrer"),
    linktrack: "linkpage",
    elementtype: "page"
};
cdc.ut.liveManager.trackingVariables["loc"] = "http://" + cdc.ut.liveManager.trackingVariables["basepage"];
/*
Method: cdc.ut.liveManager.getCookieData()

Description:
- Read prev page cookie information.

Params:
-	cookieName : Cookie name

Utility Variables:
- equalindex	: Contains the index for cookiename=.
- colenIndex	: Contains the index of semicolen;
*/

cdc.ut.liveManager.getCookieData = function(cookieName) {
    var equalIndex = document.cookie.indexOf(cookieName + "=");
    var colenIndex = "";
    if (equalIndex > -1) 
	{
        colenIndex = document.cookie.indexOf(";", equalIndex + 1);
        colenIndex = (colenIndex > 0)? colenIndex : document.cookie.length;
        colenIndex = (colenIndex > equalIndex)? document.cookie.substring(equalIndex + cookieName.length + 1, colenIndex) : ""
    }
    return colenIndex;
};

cdc.ut.liveManager.getPrevpage = function(){
    var x=eval("document."+"referrer");
    
    x = x.replace(/^https:\/\/|^http:\/\//,"");
    x = x.replace(/^www\./,"");
    var a = x.split("?");
    x = a[0];
    if(x.length > 255){
        x = x.substring(0,255);
    }
    return x;
}

cdc.ut.liveManager.trackingVariables["prevpage"] = cdc.ut.liveManager.getPrevpage();


/*
Method:cdc.ut.liveManager.presend()

Description:
-	Referring site tracking function called in line.
-	If a name-value pair for referring_site, position, campaign, keyword, creative or country is in this page's URL querystring, this lets visual sciences know.
-	The check for existence of "referring_site" is case insensitive.

Additional Variables:
-	referringSiteName is Array of referring site names to check for. The order is important as it's the hierarchy order for sitecatalyst
-	searchString is the search string value.
-	a,b,d are utility variables.
- e is a utility array to store the campaign values that will be joined and sent to sitecatalyst
-	c - 1st life as utility variable, reincarnated as the tag sent to VS

*/

cdc.ut.liveManager.presend=function(){
    try {
		var referringSiteName = ["campaign", "country_site", "position", "referring_site", "creative", "keyword"];
		var searchString = location.search;
		if(searchString == ""){
			var du=document.URL;
			var i1=du.indexOf("#");
			var i2=du.indexOf("?");
			if(i2>i1){
				searchString = "?" + (du.split("?"))[1];
			}
		}
		searchString = searchString.toLowerCase();
		cdc.ut.liveManager.searchString = searchString;
        var a, b, c, d, e=[];

        for(a=0; a < referringSiteName.length; a++)
		{
            if(searchString.indexOf(referringSiteName[a]) > 0)
			{                
                a = searchString.substring(1).split('&');
                b={};
                for (d = 0; d < a.length; d++) 
				{
                    c = a[d].split("=");
                    b[c[0]] = unescape(c[1]);
                }
                
				c = "&tag=" + cdc.ut.liveManager.trackingVariables["tag"] + "&vs_basepage=" + escape(cdc.ut.liveManager.trackingVariables["basepage"]) + "&vs_elementtype=page&vs_event=campaign&vs_url=" + escape(document.URL);
                
				for (d = 0; d < referringSiteName.length; d++) 
				{
                    if (typeof b[referringSiteName[d]] != "undefined")
					{
						c += "&" + referringSiteName[d] + "=" + escape(b[referringSiteName[d]]);
						e.push(escape(b[referringSiteName[d]]));
					}
                }
                
                d=document.cookie;
                var d1=d.indexOf("CP_GUTC"),d2=d.indexOf(";",d1),vid="";
                if(d2>d1&&d1>=0){
                    vid=d.substring(d1+8,d2);
                }
				c+="&vs_vid="+vid;
				
				var g=cdc.ut.liveManager.config.dop_sensor.split(",");
				var idx=0;
				for(var f=0;f<g.length;f++){
	                idx=cdc.ut.liveManager.img.push(new Image());
	                cdc.ut.liveManager.img[idx-1].src = g[f] + c;    
				}

				break;
            }
        }
    } catch(e) {}    
}

if (typeof lm_libloadedflag == "undefined") {
    cdc.ut.liveManager.presend();
}

/*
Method: cdc.ut.liveManager.ONLOAD()

Description:
-	Main ONLOAD handler of liveManager.
-	This queues the cdc.ut.liveManager.loadFiles calls
-	Ensures we load the libraries after the document body is loaded,
-	The supporting libraries are loaded when this handler is invoked.

Notes:
- Avoids repeat loading of Site Catalyst code
- If there is already the instance of an s_account variable (SiteCatalyst) the s_code_ut.js is not loaded and the s_code send flag is set to false to allow the existing implementation to handle the SiteCatalyst tracking.

Sample Usage: 
cdc.ut.liveManager.ONLOAD();

 Additional Variables Used:
 -	<cdc.ut.liveManager.lmIsLoaded> : onload flag used to ensure the cdc.ut.liveManager.ONLOAD handler is loaded only once.
 */

cdc.ut.liveManager.ONLOAD = function() {
    /* cdc.ut.config overrides */
    if(typeof cdc.ut.config!="undefined"){
        for(a in cdc.ut.config){
            if(typeof cdc.ut.config[a]!="function"){
                b=a.split(".");
                if(b.length==2&&typeof cdc.ut.liveManager.config[b[0]][b[1]]!="undefined"){
					cdc.ut.liveManager.config[b[0]][b[1]]=cdc.ut.config[a];
				}else if(b.length==1&&typeof cdc.ut.liveManager.config[b[0]]!="undefined"){
					cdc.ut.liveManager.config[b[0]]=cdc.ut.config[a];
				}
            }            
        }

        if(typeof cdc.ut.config["tag"]!="undefined"){
			cdc.ut.liveManager.t["tag"]=cdc.ut.config["tag"];
		}
		
        if(typeof cdc.ut.config["noload"]!="undefined"&&(cdc.ut.config["noload"]=="true"||cdc.ut.config["noload"]==true)){
			cdc.ut.liveManager.lmIsLoaded=1;
		}
    }
    
    /* ensure liveManager only loads the onload directives only once */
    if (cdc.ut.liveManager.lmIsLoaded == 1){
		return;
	}
	
    cdc.ut.liveManager.lmIsLoaded = 1;

    /* load rs_map support */
    if(cdc.ut.liveManager.config['rs_map_src'] != ''){
	cdc.ut.liveManager.loadFiles({
	    nodeIdSuffix: "rs_map",
	    fileURL: cdc.ut.liveManager.config["rs_map_src"]+"?v=" + cdc.ut.liveManager.trackingVariables["tag"],
	    notAsync: 0
	});
    }

    /* load legacy visualsciences support (conditionally based on URL) */
    var disableLoading = {
	flag: 0,
	loc: document.URL,
	url:[
		"mike.tealium.com",
		"/en/US/docs/",
		"/cisco/software/"
	],
	test:function(){
		for(var i=0;i<this.url.length;i++){
			if(this.loc.indexOf(this.url[i])>-1){
				this.flag = 1;
				break;
			}
		}
	}
    }
    disableLoading.test();

    if(!disableLoading.flag && cdc.ut.liveManager.config['visualsciences_ut_src'] != ''){
        cdc.ut.liveManager.loadFiles({
            nodeIdSuffix: "vs",
            fileURL: cdc.ut.liveManager.config["visualsciences_ut_src"]+"?v="+cdc.ut.liveManager.trackingVariables["tag"],
            notAsync: 1
        });
    }
    
    /* load new visualsciences support */
    if(cdc.ut.liveManager.config['dop_src'] != ''){
	cdc.ut.liveManager.loadFiles({
	    nodeIdSuffix: "dop",
	    fileURL: cdc.ut.liveManager.config["dop_src"]+"?v=" + cdc.ut.liveManager.trackingVariables["tag"],
	    notAsync: 1,
	    callback: "cdc.ut.liveManager.dop.INIT()"
	});
    }
    
    /* load sitecatalyst support - if s_code.js is already loaded on the page, do not load again unless we are on a webex page */
    if ((typeof s_account == "undefined") || (s.visitorNamespace == "webex")){
        var src=cdc.ut.liveManager.config["s_code_ut_src"];
    /* use s_code_ut_src as default, but if from one of below theaters use s_code_src instead */
        var lp=(""+location.pathname).toLowerCase();
        var m=(new RegExp(/\/web\/\w{2}\//)).exec(lp);
        if(m!=null){
            m=m.toString();
            if(m.indexOf("/web/us/")==-1&&m.indexOf("/web/fw/")==-1)src=cdc.ut.liveManager.config["s_code_src"];
        }
	if(src != ''){
	    cdc.ut.liveManager.loadFiles({
	        nodeIdSuffix: "s_code",
	        fileURL: src+"?v=" + cdc.ut.liveManager.trackingVariables["tag"],
	        notAsync: 1
	    });
	}
    }else{
        /* set the following flag to false when testing with no data to be sent to sitecatalyst or s_account is defined */
        cdc.ut.liveManager.config.send["s_code"] = false;        
    }

    /* load ntpagetag support */
    if(cdc.ut.liveManager.config['ntpagetag_src'] != ''){
	if(typeof NTPT_IMGSRC == "undefined"){
	    cdc.ut.liveManager.loadFiles({
	    	nodeIdSuffix: "ntpagetag",
		fileURL: cdc.ut.liveManager.config["ntpagetag_src"]+"?v=" + cdc.ut.liveManager.trackingVariables["tag"],
		notAsync: 1,
		callback: "NTPT_UT.init()",
		initScript: "NTPT_NOINITIALTAG='true'"
	    });
	}
    }

    /* load trackEvent support */
    if(cdc.ut.liveManager.config['trackevent_src'] != ''){
	cdc.ut.liveManager.loadFiles({
	    nodeIdSuffix: "trackEvent",
	    fileURL: cdc.ut.liveManager.config["trackevent_src"]+"?v=" + cdc.ut.liveManager.trackingVariables["tag"],
	    notAsync: 1,
	    callback: "cdc.ut.liveManager.getPageData();cdc.ut.trackEvent.INIT();if(typeof cdcPageTimers!='undefined')cdcPageTimers.utsent=new Date();cdc.ut.trackEvent.event('view',cdc.ut.liveManager.trackingVariables)"
	});
    }

    if(typeof cdcPageTimers!="undefined")cdcPageTimers.utloaded=new Date();

    /* BazaarVoice Integration Functionality - ratingsDisplayed callback 
    ratingsDisplayed = function(totalReviewCount, avgRating, totalRatingOnlyCount, buyAgainPercentage) {
        if (totalReviewCount > 0 || totalRatingOnlyCount > 0) {
            cdc.ut.trackEvent.event("custom", {
                bv_event: "bv_ratingdisplayed",
                bv_reviewcount: totalReviewCount,
                bv_avgrating: avgRating,
                bv_rating_only: totalRatingOnlyCount,
                bv_buyagain: buyAgainPercentage
            });
        }
    }

     BazaarVoice Integration Functionality - pageChanged callback 
    pageChanged = function(pageName, pageStatus) {
        cdc.ut.trackEvent.event("custom", {
            bv_event: "bv_pagechanged",
            bv_page: pageName,
            bv_status: pageStatus
        });
    }
    */    
}

/*
 Method: ONERROR

 Description:
*Custom error handler*
    - adds value of error message to cdc.ut.liveManager.error,
    - sets cdc.ut.liveManager.erf flag to guarantee only first error processed
    - this function is then attachaed to the window.error handler
    -  not sure why needed???
    
 Sample Usage:
 This is triggered if there is an error. Does nothing if it's been called already.

 Params:
  - a - error string object
  - b - url of the invoking error
  - c - error line number
 
 Additional Variables Used:
  - cdc.ut.liveManager.erf - error flag
  - cdc.ut.liveManager.error - error message
*/
cdc.ut.liveManager.ONERROR = function(a, b, c) {
    if (cdc.ut.liveManager.erf != 1) 
	{
        cdc.ut.liveManager.error = (typeof a == "string") ? (a + "-" + c) : "Unknown";
        cdc.ut.liveManager.erf = 1
    }
}

/* Attach cdc.ut.liveManager.ONERROR to the window.error event */
cdc.ut.liveManager.bindEvent(window, "error", cdc.ut.liveManager.ONERROR);

/*
Method: cdc.ut.liveManager.getPageData()

Description:
-	This is a callback method of trackEvent.js. 
-	First <cdc.ut.liveManager.loadFiles()> method load the trackEvent library in the head section of the page. 
-	Once trackEvent.js is loaded then it load the callback methods through <cdc.ut.liveManager.LOAD()> method. 
	try{cdc.ut.liveManager.LOAD("trackEvent")}catch(e){}
-	<cdc.ut.liveManager.LOAD()> method calls <cdc.ut.liveManager.getPageData()> method. This method analyzes page data to find site area and more and stores them in <t> object.

Details:
-	Collects data from meta tags that aren't in the ignore list (ignores description, keywords, date, pubdate, pushdate, docRequest, synonym)
-	Looks for site area in hinav
-	Looks for site area in treecrumb
-	If an object called track is in page the info is caputred here
-	Uses site area from meta.iapath if present, then hinav or treecrumb if no iapath and these exist, records which was used.


Utility Variables:
-	metaElementsList:	Variable that hold the all meta tags information on the page. It contains the values of meta attributes name & content
-	divElementsList	:	Variable that hold the all div tags information on the page.
-	contentArr		:	Array variable holds divElementsList contents which contains class 'hinav'.
-	linkArr			:	Array varibale holds the name of link from contentArr elements.
-	startIndex		:	Hold the start position of given value.
-	endIndex		:	Hold the end position of given value.

*/

cdc.ut.liveManager.getPageData = function() {

/* Meta data variables to be read and loaded into the cdc.ut.liveManager.trackingVariables object. Meta data keys that exist in the ex object are ignored */    
    var ignoredMetaTagList = {
        description: 1,
        keywords: 1,
        date: 1,
        pubdate: 1,
        pushdate: 1,
        docRequest: 1,
        synonym: 1
    }
    var metaElementsList = document.getElementsByTagName("meta");

    for(var b = 0; b < metaElementsList.length; b++)
	{
        if (metaElementsList[b].name && metaElementsList[b].name != "" && typeof ignoredMetaTagList[metaElementsList[b].name] == "undefined")
		{
            cdc.ut.liveManager.trackingVariables["meta." + metaElementsList[b].name.toLowerCase()] = metaElementsList[b].content.toLowerCase()
        }
    }

/* 

Description:
Dom parsing for the hinav value. The parsed value is added to the cdc.ut.liveManager.trackingVariables["hinav"] attribute 

Utility Variables:
-	divElementsList	:	It is a DOM Object and it is holding all DIV tag information on the page.
-	contentArr		:	It is an Array type variable and it is holding the content of div which contains the class name 'hinav'.
-	divContent		:	It is obejct type utility variable. It holds the string value for div which contains the class name 'hinav'.
-	linkArr			:	It is array type utility variable. Arrya elements holds the name of the href link.
-	startIndex		:	Utility variable holds the position of this symbol '>' in the specified string.
-	endIndex		:	Utility variable holds the position of this symbol '<' in the specified string.

*/
    var divElementsList = document.getElementsByTagName("div");
    var contentArr = [];
    for(var c = 0; c < divElementsList.length; c++)
	{
        if (divElementsList[c].className == "hinav")
		{
			var divContent = divElementsList[c].innerHTML.split("<a");
            
			for (var f = 0; f < divContent.length; f++)
			{
                if (divContent[f].indexOf('class="parent"') > -1 || divContent[f].indexOf('class="selected"') > -1)
				{
					contentArr.push(divContent[f]);
				}
            }

            var linkArr = [];
            for (var e = 0; e < contentArr.length; e++)
			{
                contentArr[e] = (contentArr[e].split("&amp;")).join("&");
                contentArr[e] = contentArr[e].toLowerCase();
                var startIndex = contentArr[e].indexOf(">");
                var endIndex = contentArr[e].indexOf("<", f);
                linkArr.push(contentArr[e].substring(startIndex + 1, endIndex));
            }
            cdc.ut.liveManager.trackingVariables["hinav"] = linkArr.join("/");
            break;
        }
    }


/*
	
Description:
-	Dom parsing for the nav-treecrumb value. The parsed value is added to the cdc.ut.liveManager.trackingVariables["treecrumb"] attribute.

Utility Variable:
-	listObject		:	This a DOM object for all List elemets on the markup page. 
-	parsedValue		:	Array contains the name of nav-treecrumb.
-	domClassName	:	Contains the class name of each list item.
-	domClassId		:	Contains the parent node ID of each list item. 
-	tagEndPos		:	Holds the position of symbol '>' in specified string.
-	tagStartPos		:	Holds the position of symbol '<' in specified string.

*/

    if (typeof document.getElementById("nav-treecrumb") != "undefined") 
	{
        var listObject = document.getElementsByTagName("li");
        var parsedValue = [];
        for (c = 0; c < listObject.length; c++) 
		{
            var domClassName = listObject[c].className;
            var domClassId = listObject[c].parentNode.id;
            
			if (domClassId == "nav-treecrumb") 
			{
                domClassId = listObject[c].innerHTML;
                if(domClassId){
					var tagEndPos = domClassId.indexOf('>');
					var tagStartPos = domClassId.indexOf('<', f);
					domClassId = domClassId.substring(tagEndPos + 1, tagStartPos);
					parsedValue.push((domClassId.split("&amp;")).join("&"))
				}
            }
            
			if (domClassName == "crumb-selected") 
			{
				break
			}
        }
        cdc.ut.liveManager.trackingVariables["treecrumb"] = parsedValue.join("/")
    }

/*
Description: 
Page level variables (not currently used). If an object named track exists on the page, its attributes will be read and added to the cdc.ut.liveManager.trackingVariables object.
*/
    
	if (typeof track != "undefined") 
	{
        for (var a in track) 
		{
            if (typeof a != "function") 
			{
				cdc.ut.liveManager.trackingVariables[a] = track[a];
			}
        }
    }

/*
Description: 
Sets the sitearea and sa_source values off either the meta.iapath, hinav or treecrumb values. This is used for measurement to determine which pages have an iapath. For those that don't they will be categorized by either the hinav or treecrumb value in that order.

Utility Variable:
- elements	:	An array type of variable holds name of meta.iapath element, hinav dom ID and treecrumb dom ID.
*/

    var elements = ["meta.iapath", "hinav", "treecrumb"];
    for (f = 0; f < elements.length; elements++) 
	{
        if (typeof cdc.ut.liveManager.trackingVariables[elements[f]] != "undefined") 
		{
            cdc.ut.liveManager.trackingVariables["sitearea"] = cdc.ut.liveManager.trackingVariables[elements[f]];
            cdc.ut.liveManager.trackingVariables["sa_source"] = elements[f];
            break;
        }
    }

/*
Description: 
- livePerson keycode reader.
*/

    if(typeof lpMTagConfig != "undefined" && typeof lpMTagConfig.sessionVar != "undefined")
	{
		lpMTagConfig.sessionVarBackup = new Array();
        lpMTagConfig.sessionVarBackup = lpMTagConfig.sessionVar;
    }
}


/*
Method: cdc.ut.liveManager.getRSMapFileData()

Description:
- Analyzes the content in the rs_map.js file to determine SiteCatalyst Report Suite Values <t>

Details:
- Reads data from the ut_rs_map variable declared in the rs_map.js
- Looks for filter match in the url which matches to a SiteCatalyst report suites or an "exclude" directive

Sample Usage:
- This is called by trackEvent.js during the plugin that determines SiteCatalyst report suite.

Utility Variables:
- docURL = contains the URL of document.

*/

cdc.ut.liveManager.getRSMapFileData = function() {
    if (typeof ut_rs_map != "undefined") 
	{
        var docURL = document.URL;
        for (i in ut_rs_map) 
		{
            if (typeof ut_rs_map[i] == "string") 
			{
                if (docURL.indexOf(i) > -1) 
				{
					return ut_rs_map[i];
				}
            }
        }
    }
    return "";
}

/*
	Code Block: Calling cdc.ut.liveManager.ONLOAD 
		- Try to call the cdc.ut.liveManager.ONLOAD handler when the jQuery document.ready is invoked.
		- If the handler fails, catch the error and attach to the window.load event, and also set a 3 second timeout to call cdc.ut.liveManager.ONLOAD.
		- These two are used to guarantee the cdc.ut.liveManager.ONLOAD function is invoked. 
*/
try {
    jQuery(document).ready(function() {
	if(typeof cdcPageTimers!='undefined')cdcPageTimers.utready=new Date();
        cdc.ut.liveManager.ONLOAD();
    })
} catch(e) {
    cdc.ut.liveManager.bindEvent(window, "load", cdc.ut.liveManager.ONLOAD);
    setTimeout("cdc.ut.liveManager.ONLOAD", 3000);
}

var lm_libloadedflag = 1;



/*
Method: cdc.ut.liveManager.debugThis()

Description: 
- Debug script that creates a pixel request containing a debug message

Sample Usage: 
cdc.ut.liveManager.DB("my debug message");

Params: 
- debugMsg - incoming debug message

Utility Variables: 
- imgObj - local utility image object

*/

cdc.ut.liveManager.debugThis = function(debugMsg, imgObj) {
    imgObj = new Image();
    imgObj.src = "//cdn.tealium.com/track.gif?tag=ut2.0&msg=" + debugMsg;
}

cdc.ut.liveManager.t = cdc.ut.liveManager.trackingVariables;
cdc.ut.liveManager.A = cdc.ut.liveManager.loadFiles;
cdc.ut.liveManager.l = cdc.ut.liveManager.filesToLoad;

for(var i=0; i<cdc.ut.liveManager.filesToLoad.length; i++){
    cdc.ut.liveManager.filesToLoad[i].a=cdc.ut.liveManager.filesToLoad[i].nodeIdSuffix;
    cdc.ut.liveManager.filesToLoad[i].b=cdc.ut.liveManager.filesToLoad[i].fileURL;
    cdc.ut.liveManager.filesToLoad[i].c=cdc.ut.liveManager.filesToLoad[i].notAsync;
    cdc.ut.liveManager.filesToLoad[i].d=cdc.ut.liveManager.filesToLoad[i].initScript;
    cdc.ut.liveManager.filesToLoad[i].e=cdc.ut.liveManager.filesToLoad[i].callback;
}

cdc.ut.liveManager.cleanCookies=function(){
    var dc=document.cookie;
    var a=dc.split("; ");
    for(var i=0;i<a.length;i++){
		var b=a[i].split("=");
		//expire cookies that have a space in them
		if((b[0].indexOf("dgad_")==0) && (b[0].indexOf(" ")>-1)){
		    document.cookie = b[0] + "=;path=/;domain=.cisco.com;expires=Thu, 31 Dec 2009 00:00:00 GMT";
		    b[0]=(b[0].split(" ")).join("_");
		    document.cookie = b[0] + "=" + b[1] + ";path=/;domain=.cisco.com;";	
			//reset dgad cookies to session
		}else if(b[0].indexOf("dgad_")==0){
		    document.cookie = b[0] + "=;path=/;domain=.cisco.com;expires=Thu, 31 Dec 2009 00:00:00 GMT";
		    document.cookie = b[0] + "=" + b[1] + ";path=/;domain=.cisco.com;";	    
		}
    }

    
	if(dc.length > 3500){
		var cObj = {};
		cdc.util.ensureNamespace("cdc.ut.cdcLargeCookies");
		dc = dc.split("; ");
		// create an object of large cookies over 250k to be tracked later
		for(var i=0;i<dc.length;i++){
			var j=dc[i].split("=");
			cObj[j[0]] = j[1];
			if(j[1].length > 250) {
				cdc.ut.cdcLargeCookies[j[0]]=j[1].length;
			}
		}
		cdc.ut.cdcLargeCookies["cdc_ut"] = 0;
		cdc.ut.cdcLargeCookies["mbox"] = 0;
		cdc.ut.cdcLargeCookies["dgad"] = 0;
		cdc.ut.cdcLargeCookies["sc"] = 0;
		cdc.ut.cdcLargeCookies["utm"] = 0;
		
		for(var i in cObj){
			if(typeof cObj[i] != "function"){
				if((i=="cdc_ut") || (i=="mbox") || (i.indexOf("dgad_")==0) || (i.indexOf("s_")==0) || (i.indexOf("__utm")==0)) {
					var cClass = i;
					//create useable class names
					if (cClass.indexOf("dgad_") == 0) {
						cClass = "dgad";
					}	
					if (cClass.indexOf("s_") == 0) {
						cClass = "sc";
					}	
					if (cClass.indexOf("__utm") == 0) {
						cClass = "utm";
					}	

				
					if((typeof cdc.ut.cdcLargeCookies[i]!='undefined') && (cdc.ut.cdcLargeCookies[i]!= 0)) { 
						cdc.ut.cdcLargeCookies[i]+=':d';  
						// always send for large cookies already in largeCookies obj
					} else {	
						// send total size of each cookie class
						cdc.ut.cdcLargeCookies[cClass] += cObj[i].length;
					}
					document.cookie=i+"=;path=/;domain=.cisco.com;expires=Thu, 31 Dec 2009 00:00:00 GMT";
				}								
			}
		}
	}
};
try{cdc.ut.liveManager.cleanCookies();}catch(e){};

