/* ---------------------------------------------------------------------------------------- */
var CP_gaVER = '1_1';
/* ---------------------------------------------------------------------------------------- */

	/* Lib structure:
		CP_GAlib - required
		Additional plug-in objects currently included
		 - CP_AutoEvents - autotagging of events
		NOTE: .google-analytics.com/ga.js is loaded by gas.js which is loaded at the end of this script file
		Therefore, only this file needs to be loaded in the HTML pages
		Do not load .google-analytics.com/ga.js on the HTML
	*/
var CP_GAvicor = (function (strCurTracker) {

	instance = this;
	this.dl  = document.location;
	
	var _oCPlib = new CP_GAlib(strCurTracker);
	this._oCPlib = _oCPlib;

	this.currentPageName = '';
	
	this._init = function() {
		this.oCONFIG = {
			PERIOD			: '.',
			PROD_HOST_DOMAIN: this.dl.hostname, // No leading period @@ - vicr.com does not (yet) appear in hostnames report.
			QA_HOST_DOMAIN	: 'wwwtriage.vicorpower.com', 	// No leading period @@
			QA_HOST_REGEXP	: /(cmtria\d*|storetri\d*|triage\d*|qa|dev)\./i, 
			COOKIE_DOMAIN	: _oCPlib.getDomainName(), 	// No leading period
			PROD_WPID		: 'UA-23718549-1',
			DEV_WPID		: 'UA-23718549-2',
			BOTS_WPID		: 'UA-23718549-3',
			WPID_USED		: null,
			DELAY_SEND_PATHS: null,
			EXTERNAL_FOLDER : '/external/',
			INTERNAL_USER_COOKIE 
							: 'InternalUser', 
			DOWNLOADS_FOLDER: '/downloads/',
			MAILTO_FOLDER  	: '/mailto/',
			SOCIAL_MEDTHODS	: 'se',	// 'se' = use _trackSocial and _trackEvents - see _trackMailto call below for notes
			DEBUG_MODE		: null
		};

		document.CP_DelaySend = document.CP_DelaySend || 
								(this.oCONFIG.DELAY_SEND_PATHS && this.oCONFIG.DELAY_SEND_PATHS.test(this.dl.pathname));
		
		this.oCONFIG.COOKIE_DOMAIN = this.oCONFIG.PERIOD + this.oCONFIG.COOKIE_DOMAIN

		this.oPAGES = {};
		this.oSEGMENTS = {};
		this.oLEVELS = new Array();

			// Configure all CV slots in one place
		this.oSLOTS = {	
			version 	: {slot:5, scope:3, key:'UAver'}
		}

		
		this.intDomainHash = _oCPlib.getDomainHash(this.oCONFIG.COOKIE_DOMAIN);
	};
	
	this.validatePages = function(pageIdOrVirtualName) {
		if ((pageIdOrVirtualName && pageIdOrVirtualName.substring(0,1) == '/') || !pageIdOrVirtualName) 
			return pageIdOrVirtualName;
			
		var validPageName = this.oPAGES[pageIdOrVirtualName];
		
		if (validPageName) 
			return validPageName;
		else {
			_oCPlib.consoleLog('Illegal Page Value: ' + pageIdOrVirtualName, 'CRITICAL ERROR');
			return pageIdOrVirtualName;
		}
	}

	this.onEveryPage = function(pageIdOrVirtualName, anchor, sSegment) {
			// if this is not a virtual page name or page Id
		if (!pageIdOrVirtualName) {
			// var dl = document.location;
			pageIdOrVirtualName = this.dl.pathname + this.dl.search + this.dl.hash;
		}

		_oCPlib.consoleLog(	'onEveryPage ' + pageIdOrVirtualName);

		pageIdOrVirtualName = this.validatePages(pageIdOrVirtualName);
		
		sSegment = sSegment || this.oSEGMENTS[pageIdOrVirtualName]

		pageIdOrVirtualName = unescape(pageIdOrVirtualName);
		
		this.currentPageName = pageIdOrVirtualName;

		_oCPlib.sendUAstringAndCodeVersion(this.oSLOTS.version, CP_gaVER, -1);	// -1 = strip from front if UA string too long
		
		if (anchor) pageIdOrVirtualName = this.trackVPNEvents(pageIdOrVirtualName, anchor);
		
		_oCPlib.sendPage(pageIdOrVirtualName, sSegment);
	};
	
	

	
	this.trackVPNEvents = function(pageName, anchor) {
		if (pageName.indexOf(this.oCONFIG.DOWNLOADS_FOLDER) == 0) 
			_oCPlib.sendEvent(	'Resources', 
									this.dl.pathname + this.dl.search, 
									anchor.href.replace(/https?:\/\//, ''),  
									1
								);

		if (anchor)
			_oCPlib.consoleLog(['Event:' + pageName,instance.currentPageName, anchor.href].join(', '));
		
		return pageName;
	};
	
	
	this.onDivDisplay = function(pageIdOrVirtualName, sSegment) {
		_oCPlib.consoleLog(	'onDivDisplay ' + pageIdOrVirtualName);
		this.onEveryPage(pageIdOrVirtualName, null, sSegment);
	};
		
	this.cssQueryHandler = function(jQobject, anchor) {
		var elm;
		var SL = instance.oCONFIG.SPECIAL_LINKS;
		for (elm in SL.cssSelectors) {
			var selector = SL.cssSelectors[elm];
			if (jQobject.closest(selector).length == 1 || jQobject.hasClass(selector)) {
				var action = SL.actions[elm];
				break;
			}
		}
		
		if (action && 'Custom' == action) {
			try {
				var ptn = '([^ ]*)';
					//  + ' gac_ gaa_ gal_ gav_' guarantees matches & error checking not needed
				var classList = jQobject.attr('class') + ' gac_ gaa_ gal_ gav_';
				var category = classList.match('gac_' + ptn)[1].replace(/_/g, ' ');
				action = classList.match('gaa_' + ptn)[1].replace(/_/g, ' ');
				var label = classList.match('gal_' + ptn)[1].replace(/_/g, ' ');
				var val = classList.match('gav_' + ptn)[1].replace(/_/g, ' ');
				
					// if action class is gaa_text, replace it with the displayed text value
				if ('text' == action) action = jQobject.text();
					// if label class is gal_href, replace it with the displayed text value
				if ('href' == label) label = anchor.href.replace(/https?:\/\//, '');
				
				if (category) {
					_oCPlib.sendEvent(category, action, label, val);
					return true;
				}
			} catch (e) {}
		}
		
	};
	
	this._init();
	if (typeof CP_SegmentVisitor !== 'undefined') this.oVkiVisitorSegmentor = new CP_SegmentVisitor(_oCPlib, this.oSLOTS, this.oLEVELS);

	
		// Cookie enforces DEBUG_MODE = true.  Rather err on the side of false than loose data.
	this.oCONFIG.DEBUG_MODE = ('.' + this.oCONFIG.PROD_HOST_DOMAIN).search(this.oCONFIG.COOKIE_DOMAIN) == -1;
	this.oCONFIG.DEBUG_MODE = _oCPlib.isDebugging(this.oCONFIG.DEBUG_MODE);
	
	this.oCONFIG.IN_PROD = 	('.' + this.oCONFIG.PROD_HOST_DOMAIN).search(this.oCONFIG.COOKIE_DOMAIN) !== -1
							&& (document.location.port == '')
							&& !this.oCONFIG.QA_HOST_REGEXP.test(this.dl.hostname)
							&& document.location.hostname !== this.oCONFIG.QA_HOST_DOMAIN
							&& /vicorpower\.com$/i.test(document.location.hostname);
							
	if (_oCPlib.isBot())
		this.oCONFIG.WPID_USED = this.oCONFIG.BOTS_WPID;
	else if (this.oCONFIG.IN_PROD && !this.oCONFIG.DEBUG_MODE) 
		this.oCONFIG.WPID_USED = this.oCONFIG.PROD_WPID;
	else	// Testing Account  
		this.oCONFIG.WPID_USED = this.oCONFIG.DEV_WPID;

		// All settings must be configured before any other code is called
	_gas.push(	[_oCPlib.curTrackerName + '_setAccount', this.oCONFIG.WPID_USED],
				[_oCPlib.curTrackerName + '_setDomainName', this.oCONFIG.COOKIE_DOMAIN],
				[_oCPlib.curTrackerName + '_setAllowHash', true],
				[_oCPlib.curTrackerName + '_trackVimeo', 'force'], 
				[_oCPlib.curTrackerName + '_trackYouTube', 'force', [25,50,75,90]]
			);
			
	_gas.push([_oCPlib.curTrackerName + '_trackForms']);	
	_gas.push([_oCPlib.curTrackerName + '_trackOutboundLinks']);	
	_gas.push([_oCPlib.curTrackerName + '_trackMailto', 'mailto', this.oCONFIG.SOCIAL_MEDTHODS]);	
	
		// new optional argument to override category 'Download'
	_gas.push([_oCPlib.curTrackerName + '_trackDownloads', null, 'downloads']);
			
});	


var CP_GAlib = (function (strCurTracker) {

	var instance = this;
	this.curTrackerName = (strCurTracker ? strCurTracker + '.' : '');	// the tracker this instance will use

	var strHost = document.location.host;
	
	this.currentPageName = '';
	
	/**
	 *  Checks query string or  manually created cookie to test for  debugging mode
	 *  Ensures cookie is created if in deubugging mode
	 * @privileged
	 */
	this.isDebugging = function(debugMode) {
		var isDbgCookie = debugMode || (document.location.search.search(/[&?]debug(ging)?=yes/i) !== -1);
		if (isDbgCookie) this.createCookie('debugging', 'yes', 0);
		return (isDbgCookie || (document.cookie.search(/debug(ging)?=yes/i) !== -1));
	}

	this.isBot = function() {
		var nua = 'string' == typeof UA_TEST ? UA_TEST : navigator.userAgent;
		return (/(bot|agent|crawler|spider|Keynote|Webmetrics|Browsermob)/i).test(nua);
	}
	
	/**
	 *  Call _setVar if using a GA _track* function
	 *  	because it must not be called before functions that need to check ga's cookies and 
	 *	such functions will have run before any _track'ing functions run
	 *  Only needs to be called once in 2 years 
	 * 	so setInternalFunction is set to an empty function.  This also prevents recursive call looping when it calls gaPush
	 *  Also checks to see if _setVar had already set the __utmv cookie so it does not have to call it on each pageview, (once for each tracker!)
	 *  This means that the __utmv cookie will not be refreshed unless _setCustomVar is called for a Visitor level CV
	 *  If setInternalUser is used, no other use can be made of _setVar
	 * @param (string) GA function  called in gaPush, eg _setAllowAnchor, _trackTrans, _trackPageview etc
	 * @public
	 */
	this.setInternalUser = function(f) {
		if (f.substr(0, 6) == '_track') {
			this.setInternalUser = function (){};
			
			c = oCustom.oCONFIG.INTERNAL_USER_COOKIE;
			if (c && this.readCookie(c) && !this.readCookie('__utmv', c + '\\|', this.intDomainHash)) 
				this.gaPush(['_setVar', c]);
		}
	}
	
	this.consoleLog = function (s, sCritical) { 
		try {
			var isDebugging = this.isDebugging();
			if ((isDebugging)) {
				if (typeof(console) !== 'undefined' && typeof(console.log) !== 'undefined') console.log(s); 
				if (sCritical) alert(sCritical + ': ' + s);
			}
		} 
		catch(e) {}
	} 
	
	this.getDomainName = function(strURL) {
		strURL = strURL || document.location.hostname;
		
			// extract the host name since full url may have been provided
		strURL = strURL.match(/^(?:https?:\/\/)?([^\/:]+)/)[1];	// this cannot error unless running as file://
		
		if(strURL.match(/(\d+\.){3}(\d+)/) || strURL.search(/\./) == -1) return strURL;	// ipaddress

		try {
			strURL = strURL.match(/(([^.\/]+\.[^.\/]{2,3}\.[^.\/]{2})|(([^.\/]+\.)[^.\/]{2,4}))(\/.*)?$/)[1];
		} catch (e) {
				// custom or local dns name like sub.mylaptop in which case return the whole hostname part of strURL
		}
		return  strURL;
	};
	
	this.isHostExternal = function(strURL) {
		this.consoleLog(strURL + ' && ' + strHost + ' && ' + (strURL.indexOf(strHost)) 
						+ ' && ' + (strHost.indexOf(strURL))
						+ ' && ' + (this.getDomainName(strURL).indexOf(strHost)));
						
		var isExternal =	(strURL.indexOf(strHost) == -1) 
						&&	(strHost.indexOf(strURL) == -1)
						&&	(this.getDomainName(strURL).indexOf(this.getDomainName(strHost)) == -1); 
						
		this.consoleLog(isExternal);
		
		return isExternal
	};

	this.sendPage = function(pageIdOrVirtualName, visitorSegmentId) {

		var strHref = '';
		var dl = document.location;
		
		visitorSegmentId = visitorSegmentId || document.visitorSegmentId;
			// if document.visitorSegmentId is set, process it.  Must be done before _trackPageview so that the value can be sent with the page.
		if (visitorSegmentId && typeof(_oCPlib.oVkiVisitorSegmentor) !== 'undefined' ) {
			_gas.push(function () {
				_oCPlib.oVkiVisitorSegmentor.setNewVisitorLevel(visitorSegmentId);
			});
		}

			// Determine what the page name will be based on whether 
			//	a Virtual Page Name was provided in document.pageIdOrVirtualName
		if (pageIdOrVirtualName) {
			strHref = pageIdOrVirtualName;
		} else {
			if (document.pageIdOrVirtualName)
				strHref = document.pageIdOrVirtualName;
			else
				strHref = dl.pathname + dl.search + dl.hash;
		}
		
		this.currentPageName = strHref;
		_gas.push([this.curTrackerName + '_trackPageview', strHref]);
		_gas.push(['_trackPageLoadTime']);

		return true;
	};
	
	this.sendEvent = function(category, action, label, value) {
		value = value || 1;
		value = Math.round(value);	// decimal values not supported
		_gas.push([this.curTrackerName + '_trackEvent', category, action, label, value]);
	}
	
	/**
	 *  Reads  cookies, requires domain hash
	 *  
	 * @private
	 * @param {string} name cookie name
	 * @param {string} optional value or regexp as string to match value
	 * @param {string or int}  Domain Hash for __utm cookie and if danger of there being another __utm* cookie set.  Value returned includes domain hash
	 * @returns	value of the cookie, or null if cookie not set
	 * @type mixed
	 * @example obj.readCookie('__utmb', '', 1) to get value of __utmb cookie with setAllowHash = false
	 */
	 
	this.readCookie = function(cookieName, expression, intDomainHash) {
		try {
			expression = expression || '';
			intDomainHash = intDomainHash ? intDomainHash + '\.' : '';
			var ptn = new RegExp(cookieName + '=(' + expression + intDomainHash + '.*?)(; |$)');
			return document.cookie.match(ptn)[1];
		} catch (e) {return null;}
	}

	/**
	 *  Creates cookie
	 *  
	 * @private
	 * @param {string} name cookie name
	 * @param {string} value cookie value
	 * @param {string} mins mins until cookie expires
	 * @param {string} cookieDomain optional - domain to set the cookie for
	 */
	 
	this.createCookie = function(name, value, mins, cookieDomain) {
		var domain = "";
		var expires = "";
		
		if (mins) {
			var date = new Date();
			date.setTime(date.getTime()+(mins*60*1000));
			var expires = " expires="+date.toGMTString() + ";";
		}
		
		if (typeof(cookieDomain) != 'undefined')
			domain = " domain=" + cookieDomain + "; ";
		
		document.cookie = name + "=" + value + ";" + expires + domain + "path=/";
	}
	
	/**
	 *  Sets a custom variable with a concatenation of this file's version number and the user agent string
	 *  The User Agent string may be longer than allowed when encoded so remove some strings that are less important 
	 *	to prevent truncation
	 *
	 * @private
	 * @param {object} oSlot member of the oCONFIG.oSLOTS object defining the slot, scope and Key of the variable
	 * @param {string} ver of this code file 
	 * @param {string} [posTruncate]  If val is too long, prevent whole value from being lost and indicate from where val must be truncated. 1 is from start, -1 from end and 0 from middle. See @progressiveStripper
	 */
	this.sendUAstringAndCodeVersion = function (oSlot, ver, posTruncate) {
		var ver_nua = navigator.userAgent;
		ver_nua = 'string' == typeof UA_TEST ? UA_TEST : ver_nua;
		ver_nua = ver_nua + '|' + ver ;
		this.consoleLog(ver_nua);
		
		var useRE2use = [/compatible(; )?/i, '', 
						 /like\s?/i, '', 
						 /[()]/g, '', 
						 /  /g, ' ', 
						 /Windows/g, 'Win', 
						 /[\/;]/g, '_'
						 ];
		posTruncate = posTruncate || -1; 
		ver_nua = progressiveStripper(ver_nua, 64-encodeURIComponent(oSlot.key).length, true, posTruncate, useRE2use);
/*
 		nua = nua.replace(/compatible(; )?/i, '')
		nua = nua.replace(/like\s?/i, '')
		nua = nua.replace(/[()]/g, '')
		nua = nua.replace(/  /g, ' ');
		nua = nua.replace(/Windows/g, 'Win');
		nua = nua.replace(/[\/;]/g, '_');
 */
		this.setCustomVar(oSlot, ver_nua, posTruncate);
	};
		
	
	/**
	 *  Sets a Page, Session or Visitor level Custom Variable using a member of the oCONFIG.oSLOTS object
	 *  Decodes the value and if the unecoded key+value is > 64, truncates the value to prevent the variable from being droppped
	 *
	 * @private
	 * @param {object} oSlot member of the oCONFIG.oSLOTS object defining the slot, scope and Key of the variable
	 * @param {string} val 
	 * @param {string} [posTruncate]  If val is too long, prevent whole value from being lost and indicate from where val must be truncated. 1 is from start, -1 from end and 0 from middle. See @progressiveStripper
	 */
	this.setCustomVar = function(oSlot, val, posTruncate) {
		oSlot.key = encodeURIComponent(oSlot.key);
		posTruncate = posTruncate || 1;	
		val = progressiveStripper(val, 64-oSlot.key.length, true, posTruncate, false);
		
		var aPush = ['_setCustomVar', oSlot.slot, safeDecode(oSlot.key), val, oSlot.scope];
		this.consoleLog(aPush.join('|'));
		_gas.push(aPush);		
	};
	

	/**
	 *  Decodes a value using decodeURIComponent
	 *  Likely an encodeURIComponent'd  value that has been truncated so deals with bad trunction
	 *  Needs to be extended to do truncation and to prevent double encoding/decoding
	 * @private
	 * @param {string} val to decode
	 */
	var safeDecode = function(val) {
		var decodedValue = val;
		while (decodedValue == val)
			try { return (decodedValue = decodeURIComponent(val)); 
			} catch (e) { decodedValue = val = val.substr(0, val.length-1); }	
	};
	
	/**
	 *  Progressively picks out characters from val while the length of the encoded string is <= length
	 *	Picks out spaces, followed by periods and finally vowels
	 *  Returns the decoded string regardless of it's length
	 * @private
	 * @param {string} val to decode
	 * @param {integer} maxLen of val (or encodeURIComponent(val) if encoded == true)
	 * @param {boolean} encoded [true] if length applies to encodeURIComponent(val). Default is true 
	 * @param {integer} posTruncate [0] 1=retain start of string -1 retain end, 0 retain start & end - strip from centre
	 * @param {mixed} useRE [true] Use internal RegExp array, provide and override or don't use any. Default is true.  If array is provided, must be in the format [RegExp, replacement string, ....]
	 */
	var progressiveStripper = function(val, length, encoded, posTruncate, useRE) {
		instance.consoleLog([val, length, encoded, posTruncate, useRE].join(' @ '));
		
		if ('undefined' == typeof encoded) encoded = true;
		if ('undefined' == typeof useRE) useRE = true;
		
		val = safeDecode(val);	// start decoded to ensure val's not already encoded
		var val2use = encoded ? encodeURIComponent(val) : val;
		
		if (useRE) {
			var aryRE = [/\.[0-9.]+/g, '', /\s/g, '', /\./g, '', /[aei]/g, '', /[ou]/g, ''];
			if ('object' == typeof useRE)
				useRE = useRE.concat(aryRE);
			else	
				useRE = aryRE;
			
			for (var re = 0; (re < useRE.length && val2use.length > length); re+=2) {
				val = val.replace(useRE[re], useRE[re+1]);
				val2use = encoded ? encodeURIComponent(val) : val;
				instance.consoleLog(val);
			}

		}
		var maxLength = Math.min(val.length, length);
		while (val2use.length > length) {
			if (!posTruncate) {	// 0 is from centre of string
				var halfLength = parseInt(maxLength/2);
				val = val.substr(0, halfLength-(halfLength%2?1:0)) + 
					  val.substr(val.length-halfLength+(halfLength%2?0:1), val.length);
			}
			else if (1 == posTruncate)  // from start
				val = val.substr(0, maxLength) 
			else if (-1 == posTruncate)  // from end
				val = val.substr(1, maxLength)

			val2use = encodeURIComponent(val);
			instance.consoleLog(val2use.length + ':' + val);
			maxLength--;
		}
		instance.consoleLog(val2use.length + ':' + val2use);
		val = safeDecode(val2use)
		instance.consoleLog(val);
		return val;
	}
	
	this.setVar = function(value) {
		_gas.push([this.curTrackerName + '_setVar', value]);
	}
	
	this.setTracker = function() {
		if (!this.curPageTracker) this.curPageTracker = _gat._getTrackerByName(this.curTrackerName);
	};
	
	
	this.getCustomVisitorValue = function(varParams) {
		this.setTracker();
		if (this.curPageTracker) 
			var customVisitorValue = this.curPageTracker._getVisitorCustomVar(varParams.slot);
		else
			var customVisitorValue = this.getVisitorCustomVarFromCookie(varParams.slot);
			
		return customVisitorValue;
	};
	
	this.getVisitorCustomVarFromCookie = function(slot) {
		var cookie = this.readCookie('__utmv', '', this.intDomainHash);
		if (cookie) {
			var re = new RegExp(slot + '=(.*)=1,');
			cookie = cookie.match(re);
		
			if (cookie) cookie = cookie[1];
		}
		return cookie;
	};
	
	
	this.getDomainHash = function(domainOrHash) { 
		
		if (typeof domainOrHash == 'number') 
			return domainOrHash;
			
		var strDomainName = domainOrHash || this.getDomainName();
		
		if (strDomainName == "none")
			return 1;
			
		fromGaJs_h =  function (e) {
			return undefined == e || "-" == e || "" == e
		};
		fromGaJs_s = 
			function (e) {
					var k = 1,
					a = 0,
					j, i;
					if (!fromGaJs_h(e)) {
						k = 0;
						for (j = e.length - 1; j >= 0; j--) {
							i = e.charCodeAt(j);
							k = (k << 6 & 268435455) + i + (i << 14);
							a = k & 266338304;
							k = a != 0 ? k ^ a >> 21 : k
						}
					}
					return k
				};
		return fromGaJs_s(strDomainName) ; 
	}
	

	/** -------------- Start _gas extension ------------------------------
	 * Triggers the Mailto Link Tracking on the page
	 * BK: might want to store the virutal page name if one was used for use as the opt_pagePath argument to _trackSocial
	 * @this {object} GA Helper object (because implemented via _gas.push(['_addHook', '_trackMailto', _trackMailto]);
	 * @param {string} catOverride Optional override of default category 'mailto'
	 * @param {string} methods Override Optional override of default methods 's' (_trackSocial ) Methods can contain 's' &/or 'e' (_trackEvent) to use either or both
	 * @param {string} socActionOverride  Optional override of default action  'send' for _trackSocial
	 */
	 
	function _trackMailto(catOverride, methods, socActionOverride) {
			this._addEventListener(
			window,
			'mousedown',
			function(e) {
				var l = e.target;
				while (l.nodeName !== 'A' && l.nodeName !== 'BODY' )
					l = l.parentNode;
					
				if (l.nodeName == 'A' &&
					(l.protocol == 'mailto:') )
				{
					var path = l.href.substring(7);
					
					methods = (methods || 's').toLowerCase();
								
					if (sindexOf.call(methods, 's') !== -1) 
						_gas.push(['_trackSocial', (catOverride || 'mailto'), (socActionOverride || 'send'), 
							path,
							document.location.pathname + document.location.search + document.location.hash
							]);
					
					if (sindexOf.call(methods, 'p') !== -1) 
						_gas.push(['_trackPageview', path]);
					
					if (sindexOf.call(methods, 'e') !== -1) 
						_gas.push(['_trackEvent', (catOverride || 'Mailto'), 
							path,
							document.location.pathname + document.location.search + document.location.hash
							]);
				}
			}
		);
	}

	_gas.push(['_addHook', '_trackMailto', _trackMailto]);

	// --------------------------------------------
	
});


var _gas = _gas || [];
(function() {
    var triage = /(cmtria\d*|storetri\d*|triage\d*|qa|dev)\./i.test(document.location.hostname) ? 'triage' : '';
    gaLoc = 'http://www' + triage + '.vicorpower.com';
    if ('https:' == document.location.protocol) gaLoc = 'https://sso' + triage + '.vicorpower.com';
    var ga = document.createElement('script');
    ga.type = 'text/javascript';
    ga.async = true;
    ga.src = gaLoc + '/secure_website_template/js/gas.js';
    var s = document.getElementsByTagName('script')[0]; 
    s.parentNode.insertBefore(ga, s);
})();

	// don't run in an iframe
if (window == window.top) {
	var oCP_GAvicor;
		// don't run if the first call to onEveryPage() has already run on this page - if this is just a reload of the file on the same page
	if (!oCP_GAvicor) {
		oCP_GAvicor = new CP_GAvicor();
		if (!document.CP_DelaySend) oCP_GAvicor.onEveryPage();
	}
	else 
		if (!document.CP_DelaySend) {
			oCP_GAvicor.onEveryPage();
			try {console.log('Script previously loaded.')} catch (e) {}
		}
}

/*
Changes:
ver 1.0:
  - added BOTS_WPID		: 'UA-23718549-3',
  - adding isBot() and calling isBot() to see if traffic data must be sent to BOTS_WPID
  - added tracking user agent string and code version numbers to custom variable 5
  - added if (!oCP_GAvicor) check to ensure that page is not reported twice if this file is loaded twice
  - Downloads, Outbound and Video tracking
*/

