	// VKI - Erik Vold, Brian Katz 080319
	// Required to segment visitors for Google Analytics
	// Called from GA script blocks on all pages.
	// Removing this file will cause Javascript errors on all pages that call the segmentVisitor() function

//List the custom levels for this application here:
	// Levels may NOT:
	// 	be an empty string
	//	be duplicated
	//	contain dots
var segmentHelperObj = {};
segmentHelperObj.visitorSegmentationLvls = new Array(
'No Action',				
'No Action-Travel Agent',	// Has logged in but not performed a "Lead" action
'No Action-Wholesaler',		// Has arrived at their page and returned to the rest of the site or has 
							// logged in but not performed a "Lead" action
'Lead-Brochure',			// Dan, this is yet to be discussed with Stafania but is intended to 
							// to distinguish between those who have merely clicked the download pdf link
							// where true Leads have made some commitment and divulged at least an email address.
'Lead',
'Lead-Travel Agent',		// Logged in and performed a "Lead" action
'Lead-Wholesaler',			// Logged in and performed a "Lead" action
'Conversion', 
'Conversion-Travel Agent',
'Conversion-Wholesaler'
);

	// ###########################################################################
	// Once development is completed and before the changes go live, this must be set to false
	// If it is not set to false and an unknown segment level is requested on the page, 
	// 	an alert box will display to the client.
segmentHelperObj.debuggingMode = false;
	// ###########################################################################
	
	
segmentHelperObj.getCookie = function(cookie_name){
  	var results = document.cookie.match( '(^|;) ?'+cookie_name+'=([^;]*)(;|$)' );
	
  	if (results)
    	return ( unescape(results[2]) );
  	else
    	return null;
};

segmentHelperObj.cleanGoogle_utmvCookie = function(){
  	var results = segmentHelperObj.getCookie('__utmv');

	if (results)
	{
		return results.replace(/^\.?(([A-Za-z]|[0-9])*\.)*/,"");
	}
	else
	{
		return null;
	}
	
};
	
segmentHelperObj.trimStr = function(str){
		var whitespace=' \n\r\t\f\x0b\xa0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u2028\u2029\u3000';
		for(var i=0;i<str.length;i++){
			if(whitespace.indexOf(str.charAt(i)) === -1){
				str = str.substring(i);
				break;
			}
		}
		for(i=str.length-1;i>=0;i--){
			if(whitespace.indexOf(str.charAt(i)) === -1){
				str = str.substring(0, i + 1);
				break;
			}
		}
		return whitespace.indexOf(str.charAt(0)) === -1 ? str : '';
};

var segmentVisitor = function(inputSegmentationLvl)
{
	// grab the GA cookie var that stores the custom visitors segment type, and trim whitespace
	var currentSegmentationLvl = segmentHelperObj.cleanGoogle_utmvCookie(); //'__utmv'

	// ###########################################################################
	// Dan, I added this in for you to see the cookie set by segmentVisitor
	// REMOVE WHEN YOU ARE DONE TESTING
//if (segmentHelperObj.debuggingMode && (inputSegmentationLvl != 'No Action' || inputSegmentationLvl != 'null'))
//	alert("__utmv segmentVisitor=" + segmentHelperObj.cleanGoogle_utmvCookie() + ". Trying to set it to:" + inputSegmentationLvl); 
	// ###########################################################################

	
	
	// if the current value is null (ie: not found) then stop and do nothing.
	if(currentSegmentationLvl==null) currentSegmentationLvl = "";

	var numOfLevels = segmentHelperObj.visitorSegmentationLvls.length;
	var currentSegmentationIndex = numOfLevels;
	var newSegmentationIndex = numOfLevels;

	var tempSegmentationLvlLabel = "";
	
	//trim whitespace and covert to all upper case
	currentSegmentationLvl = (segmentHelperObj.trimStr(currentSegmentationLvl)).toUpperCase();
	var newSegmentationLvl = (segmentHelperObj.trimStr(inputSegmentationLvl)).toUpperCase();
	
	// loop through the segmentation lvls from lowest to highest
	for(var i=0;i<numOfLevels;i++){
		tempSegmentationLvlLabel = (segmentHelperObj.visitorSegmentationLvls[i]).toUpperCase();
		
		// is the current lvl equal to this lvl?
		if(currentSegmentationLvl === tempSegmentationLvlLabel){
			currentSegmentationIndex = i;
		}
		
		// is the new lvl equal to this lvl?
		if(newSegmentationLvl === tempSegmentationLvlLabel){
			newSegmentationIndex = i;
		}
		
		// are we done yet?
		if(currentSegmentationIndex < numOfLevels && newSegmentationIndex < numOfLevels){
			break;
		}
	}
	
	if(newSegmentationIndex == numOfLevels)
	{
		// check if we are in debugging mode
		if(segmentHelperObj.debuggingMode){
			alert('Segment Error: requested visitor level not in list of levels!. Please continue');
		}
		
		// make sure that the function isDefined first
		if(pageTracker._setVar){
			pageTracker._setVar('ERROR');
		}
	}
	// if the new lvl is greater than the current lvl OR the new level was found but the current level could not be found,
	// then call _setVar()
	else if(newSegmentationIndex < numOfLevels && (newSegmentationIndex > currentSegmentationIndex || currentSegmentationIndex == numOfLevels))
	{
		// make sure that the function isDefined first
		if(pageTracker._setVar){
			pageTracker._setVar(inputSegmentationLvl);
		}
	}

	// ###########################################################################
	// Dan, I added this in for you to see the cookie set by segmentVisitor
	// REMOVE WHEN YOU ARE DONE TESTING
//if (segmentHelperObj.debuggingMode && (segmentHelperObj.cleanGoogle_utmvCookie() != 'No Action' || segmentHelperObj.cleanGoogle_utmvCookie() != 'null') 
//		alert("__utmv segmentVisitor cookie is now:" + segmentHelperObj.cleanGoogle_utmvCookie()); 
	// ###########################################################################
};

var pageTracker = _gat._getTracker("UA-442998-1"); 	

if (document.location.href.indexOf('e-cubed.info') != -1)
	pageTracker._setDomainName("e-cubed.info");
else
	pageTracker._setDomainName("rockymountaineer.com");	// = track root domain and its subdomains

pageTracker._initData();

if (document.strTrackPageView) {
	pageTracker._trackPageview(document.strTrackPageView);
} else {
	pageTracker._trackPageview();
}

segmentVisitor('No Action');








function fGooAnTagPdfs() {
//	This javascript tags file downloads and external links in Google Analytics.
//	You need to be using the Google Analytics New Tracking Code (ga.js) 
//	for this script to work.
//	To use, call this file on all pages just above the closing body tag
//	(since all hrefs must have loaded before this script starts looking for them)

//	All outbound links and links to non-html files should now be automatically tracked.
//
//	This script has been provided by Goodwebpractices.com
//	Thanks to ShoreTel, MerryMan and Colm McBarron
//
//	www.goodwebpractices.com
//	VKI has made changes as indicated below.

if (document.getElementsByTagName) {
        // Initialize external link handlers
        var hrefs = document.getElementsByTagName("a");
        for (var l = 0; l < hrefs.length; l++) {
				// try {} catch{} block added by erikvold VKI
			try{
	                //protocol, host, hostname, port, pathname, search, hash
	                if (hrefs[l].protocol == "mailto:") {
	                        startListening(hrefs[l],"click",trackMailto);
	                } else if (hrefs[l].hostname == location.host) {
	                        var path = hrefs[l].pathname + hrefs[l].search;
													// updated by erikvold VKI added \? in second group:
	                        var isDoc = path.match(/\.(?:pdf)($|\&|\?)/);
	                        if (isDoc) {
	                                startListening(hrefs[l],"click",trackExternalLinks);
	                        }
	                } else {
	                        startListening(hrefs[l],"click",trackExternalLinks);
	                }
			}
			catch(e){
					continue;
			}
        }
}
} fSafeAddOnload(fGooAnTagPdfs)

function startListening (obj,evnt,func) {
        if (obj.addEventListener) {
                obj.addEventListener(evnt,func,false);
        } else if (obj.attachEvent) {
                obj.attachEvent("on" + evnt,func);
        }
}

function trackMailto (evnt) {
        var href = (evnt.srcElement) ? evnt.srcElement.href : this.href;
        var mailto = "/mailto/" + href.substring(7);
        if (typeof(pageTracker) == "object") pageTracker._trackPageview(mailto);
}

function trackExternalLinks (evnt) {
        var e = (evnt.srcElement) ? evnt.srcElement : this;
        while (e.tagName != "A") {
                e = e.parentNode;
        }
        var lnk = (e.pathname.charAt(0) == "/") ? e.pathname : "/" + e.pathname;
        if (e.search && e.pathname.indexOf(e.search) == -1) lnk += e.search;
        if (e.hostname != location.host) lnk = "/external/" + e.hostname + lnk;
        if (typeof(pageTracker) == "object") pageTracker._trackPageview(lnk); 
} 

/*
      var isDoc = path.match(/\.(?:doc|eps|jpg|png|svg|xls|ppt|pdf|xls|zip|txt|vsd|vxd|rar|exe|wma|mov|avi|wmv|mp3)($|\&)/);
*/

function sendPageView(strTrackPageView, strSegmentationLvl) {
	if (strTrackPageView)
		pageTracker._trackPageview(strTrackPageView);
	else
		pageTracker._trackPageview();

	if (strSegmentationLvl)
		segmentVisitor(strSegmentationLvl);
}