/* Release 5.1 */

/* 
 * ua.vsTracking.js
 * 
 * Created: Oct 2010
 * Author: Rob O'Brien
 * Release: 5.1
 * 
 * Dependencies:
 * ua.js
 * 
 * Visual Sciences Tracking for all UAL properties. Allows external pages
 * to add custom tracking items to a queue, which is submitted to the 
 * server when the page is unloaded from the browser. 
 * 
 */

ua.vsTracking = (new function() {
	var parent = this,
		activateVS = true, /* When true, page-level tracking will make calls to the United-hosted sensor */
		dataSubmitted = [], /* Used to prevent a double submission */
		v_startTime = new Date(), 
		thisHref = document.location.href,
		thisReferrer = document.referrer,
		defaultTagScope = 'unload',
		linkClicked = '',
		clientName = '',
		pageTitle = '',
		customItems = [],
		debug = false,
		trackingImageBase = '//www.united.com/ual/asset/vs.gif?Log=1',
		trackingImageSrc = '',
		protocol = (document.location.protocol.indexOf('https') > -1) ? 'https:' : 'http:',
		storageCookie = 'vs_data',
		hostNameArr = [],
		hostName = '',
		len = 0,
		i = 0,
		customFunctions = [];


	/* Set current host name for use with the storageCookie */
	hostNameArr = ua.url._location.hostname.split('.');
	len = hostNameArr.length;
	for (i=len-2; i<len; i++) {
	    hostName += '.' + hostNameArr[i];
	}
				
	/* TODO Let's understand why sVS40Vars is needed & remove if possible (has references in sendData) */
	var sVS40Vars = "vs_R40_Booking_AA_Multiplier,vs_R40_Booking_AA_Origin,vs_R40_Booking_AA_Lowest_Offer,vs_R40_Booking_AA_Accepted_Offer,vs_R40_Booking_AA_AcceptedPrice,vs_R40_Booking_AA_NumPassengers_Accepted_Offer,v_aaAccepted,vs_R40_MyItins_AA_Multiplier,vs_R40_MyItins_AA_Origin,vs_R40_MyItins_AA_Lowest_Offer,vs_R40_MyItins_AA_Accepted_Offer,vs_R40_MyItins_AA_AcceptedPrice,vs_R40_MyItins_AA_NumPassengers_Accepted_Offer,vs_R40_Booking_PL_Accepted_Stations,vs_R40_MyItins_PL_Accepted_Stations,vs_R40_Booking_EPU_PricePerPassenger,vs_R40_Booking_EPU_NumPassengers_Paying_For_EPU,vs_R40_MyItins_EPU_PricePerPassenger,vs_R40_MyItins_EPU_NumPassengers_Paying_For_EPU,vs_R40_Booking_Conf_AA_Price,vs_R40_Booking_Conf_PL_Price,vs_R40_Booking_Conf_EPU_Price,vs_R40_Booking_Conf_TI_Price,vs_R40_Booking_Conf_Currency,vs_R40_MyItins_Conf_AA_Price,vs_R40_MyItins_Conf_PL_Price,vs_R40_MyItins_Conf_EPU_Price,vs_R40_MyItins_Conf_TI_Price,vs_R40_MyItins_Conf_Currency";

	/* @PUBLIC Getter and Setter for VS Tracking Active, used to turn on/off activity  */
	this.setActive = function(which) {
		activateVS = which;
		return activateVS;
	};
	
	this.isActive = function() {
		return activateVS;
	};
	
	/* Override isActive for specific domains */
	if (thisHref.indexOf('/www.united.com/') !== -1) { this.setActive(true); }
	else if (thisHref.indexOf('/travel.united.com/') !== -1) { this.setActive(true); }
	else if (thisHref.indexOf('/www.ua2go.com/') !== -1) { this.setActive(true); }

	/* Take care of some default values */
	if (!ua.utils.isArray(window.vsCustomItems)) { window.vsCustomItems = []; }
	
	/* @PUBLIC Make certain variables available to the world */
	//this.isActive = isActive;
	this.customItems = customItems;

	/* 
	 * @PRIVATE 
	 * If we're working with Webkit prior to version 534, we first store the vsQuery 
	 * to a cookie on page unload (within sendData) and we then extract that value at 
	 * runtime on the following page. This seems to be the only way to overcome Safari's 
	 * native limitations on HTTP calls during unload (XHR also works, but not cross-domain).
	 */
	var handleDataCookie = (function() {
		var vs_data = ua.utils.getCookie(storageCookie);
		if (vs_data.length > 0) {
			var imgSrc = protocol + trackingImageBase + vs_data;
			var trackingImage = new Image();
			trackingImage.src = imgSrc;
			ua.utils.deleteCookie(storageCookie,'/',hostName);
		}
	}());
	
	/* @PUBLIC Getter and Setter for Client Name (primarily used for Partners) */
	this.setClientName = function(str){
		clientName = str;
		return clientName;
	};
	
	this.getClientName = function(){
		return clientName;
	};
	
	/* @PUBLIC Getter and Setter for Page Title */
	this.setPageTitle = function(str){
		if (typeof str === 'undefined') {
			return null;
		}
		pageTitle = window.webAnalyticsPageTitle = str; /* webAnalyticsPageTitle for backwards compatibility */
		return pageTitle;
	};
	
	this.getPageTitle = function(){
		return new String(pageTitle);
	};
	
    /* @PUBLIC - When a link is clicked, the full link object will be passed to this function
     * and we can grab anything we would like from it. Currently, we only harvest the href for
     * tracking purposes.
     */
	this.getClickInfo = function(linkObj) {
		linkClicked = linkObj[0].href;
		return true;
	};
	
    /* @PUBLIC - Tracking of custom items/actions within a page. 
     * Example: ua.vsTracking.addTag('Tag Name','Tag Value');
     */
    this.addTag = function(name,value,tagScope) {
		if (typeof tagScope !== 'string') { 
			tagScope = defaultTagScope; 
		}
		if (!ua.utils.isArray(customItems[tagScope])) {
			customItems[tagScope]= [];
		} 
		customItems[tagScope].push([String(name),String(value)]);
		return true;
    };
	
	/* @PUBLIC Getter tag for custom tags */
	this.getTags = function(tagScope){
		if (typeof tagScope === 'string') {
			return customItems[tagScope];
		}
		else {
			return customItems;
		}
	};
	
	/* @PUBLIC - Merge an existing array of tags into an existing tagScope.
     * 
     * This is especially helpful when a temporary tag array is created and
     * only added to the main tagScope array as a whole.
     * Example: 
     *    vsTempTags = [];
     *    vsTempTags.push([thisName1,thisValue1]);
     *    vsTempTags.push([thisName2,thisValue2]);
     *    ua.vsTracking.mergeTags(vsTempTags,'Tag Scope');
     */
	this.mergeTags = function(tagArray,tagScope) {
		if (typeof tagScope !== 'string') { 
			tagScope = defaultTagScope;
		}
		if (!ua.utils.isArray(customItems[tagScope])) {
			customItems[tagScope]= [];
		} 
		customItems[tagScope] = customItems[tagScope].concat(tagArray);
		return true;
    };
	
	/* @PUBLIC - Add function references to custom tagging items which
	 * are to be executed prior to sendData(). See ua.utils.attachEvent()'s
	 * comments for further use (similar functionality)
	 * 
	 * Usage: ua.vsTracking.addFunction(Function,[Parameter Array]);
	 * Example: ua.vsTracking.addFunction(showAlert,[anyVar,"I can't believe it's not butter!"]);
	 * 
	 */
	this.addFunction = function(func,paramArray,tagScope) {
		var functionObj = {};
		
		if (typeof tagScope !== 'string') { 
			tagScope = defaultTagScope;
		}
		
		/* Make sure we have an array to store the functions */
		if (!ua.utils.isArray(customFunctions[tagScope])) {
			customFunctions[tagScope] = [];
		}
		
		/* If there are parameters, apply them to the function */
		if (ua.utils.isArray(paramArray)) { 
			functionObj = ua.utils.applyFunction(func,this,paramArray); 
		} else { 
			functionObj = func; 
		}
		
		/* Finally, add the function to the array for later execution */
		customFunctions[tagScope].push(functionObj);
		return true;
	};
	
	/* @PUBLIC 
	 * For IE6 thru IE8 (current), if a user navigates away from a page before 
	 * the 'load' event has occurred, the 'unload' event will not execute at all. 
	 * So, we need to add this fix method in order to trigger sendData(). It does 
	 * not trigger properly with page refreshes or browser closing.
	 * http://blog.moxiecode.com/2008/04/08/unload-event-never-fires-in-ie/
	 */
	this.fixUnload = function() {
		/* If the page is still loading, then fake the unload event */
		if (document.readyState === 'interactive') {
			window.stopFix = function() {
				/* Prevent memory leak */
				document.detachEvent('onstop', stop);

				/* Submit VS server call */
				ua.vsTracking.sendData();
			};

			/* Fire unload when the currently loading page is stopped */
			document.attachEvent('onstop', window.stopFix);
	
			/* Remove onstop listener after a while to prevent the unload function
			 * to execute if the user presses cancel in an onbeforeunload
			 * confirm dialog and then presses the stop button in the browser
			 */ 
			window.setTimeout(function() {
				document.detachEvent('onstop', window.stopFix);
			}, 0);
		}
	};
	
	/* @PUBLIC - I have a theory that the tracking pixel may not get requested prior to
	 * page unload in a scenario where other images are in the process of being loaded,
	 * since they can cause blocking of new images. Calling this method prior to invoking 
	 * the tracking pixel is an attempt to cancel the other images, then allow the pixel 
	 * to load freely. This assumes that currently loading assets are not already aborted 
	 * when 'beforeunload' is executed by the browser.
	 */
	var cancelPageLoad = function() {
		if (window.stop !== undefined) {
			window.stop();
		}
		else if (typeof document.execCommand !== 'undefined') {
			document.execCommand("Stop", false) ;
		}
	};

	/* @PUBLIC - Use this as the launching pad to execute all unload/beforeunload
	 * functionality. We ensure all custom functions are executed FIRST (in order to
	 * compile custom data/tags), then we call sendData() to make the vs.gif call
	 * back to the server
	 */
	this.run = function(tagScope,callback) {
		if (typeof tagScope !== 'string') { 
			tagScope = defaultTagScope;
		}
		if (typeof callback !== 'function') { 
			callback = null;
		}
		
		if (!ua.utils.isArray(customFunctions[tagScope])) {
			customFunctions[tagScope] = [];
		}
		
		/* First, run any customFunctions which have been queued */
		while(customFunctions[tagScope].length > 0) {
			try {
				(customFunctions[tagScope].shift())();
			} catch(e1) {
				/* Just in case someone throws us a bad function. We don't want to interrupt all others */
				/* alert('Error: ' + e1); */
			}
		}
		
		/* Then, send the server request */
		parent.sendData(tagScope,callback);
	};
	
	/* @PUBLIC
     * Send the tracking data to the server. We build a query string based
     * upon multiple data and custom tags, then call a tracking image with 
     * the query string attached. The "tagScope" allows us to build multiple
     * sets of custom items within a single page for multiple, separate submissions 
     * to the server. However, we limit only one submission per tagScope to
     * prevent duplicate data from being sent.
     */
    this.sendData = function(tagScope,callback) {
	    var vsQuery = '',
			v_endTime = new Date(),
			i = 0,
			bFound = false,
			pageTitle = parent.getPageTitle().trim(),
			debug = false,
			useCookie = false,
			visitorID_pre = '',
			visitorID_post = '',
			executeStart = (new Date).getTime(),
			trackingImage = new Image(),
			delayedFor = 0;
		
		/* Try-Catch is lame. But, it's only for testing while we figure out low 
		 * accuracy rates (and it only adds 1-2ms to execution time)
		 */ 
		try {
			/* If VS Tracking isn't active, we'll abort immediately */
			if (!parent.isActive()) {
				return;
			}
			
			/* Are we in debug mode? */
			if (ua.utils.getCookie('vsDebug') === 'true') {
				debug = true;
			}
			
			/* Set default value for tag scope, if not passed in */
			if (typeof tagScope !== 'string' || tagScope.trim().length < 1) {
				tagScope = defaultTagScope;
			}
			
			/* Make sure the tag array is defined */
			if (!ua.utils.isArray(customItems[tagScope])) {
				customItems[tagScope] = [];
			}
			
			/* Just in case this gets executed more than once per page */
			if (dataSubmitted[tagScope]) {
				return;
			}
			
			/* If we're using the default tagScope (during unload), we'll also
			 * force-stop the page load (just in case it's still active) to 
			 * ensure no other images are still loading, thus potentially 
			 * blocking our tracking pixel.
			 */ 
			if (tagScope === defaultTagScope) {
				//cancelPageLoad();
			}
			
			/* STEP 1/4 - Assemble string of standard values */
			
			/* If the page title hasn't been set, but the legacy webAnalyticsPageTitle is
             * present, we'll fall back to it.
             */
			if (pageTitle.length === 0 && typeof window.webAnalyticsPageTitle === 'string') {
				pageTitle = parent.setPageTitle(window.webAnalyticsPageTitle);
			}
			
			if (pageTitle.length === 0) {
				pageTitle = document.title;
				
				/* If we're using a default page title AND we have a 
                 * country defined, let's append it to the page title.
                 */
				if (typeof vsCountry === 'string') {
					pageTitle = vsCountry + ' ' + pageTitle;
				}
			}
			
			/* 
			 * Sometimes, an individual page will pre-escape the page title.
			 * Just in case it's double-escaped, we double unescape it. Less
			 * performant than other options, but more reliable.
			 * http://jsperf.com/encode-unencode/
			 */
			pageTitle = unescape(unescape(pageTitle));
			vsQuery += "&v_pn=" + escape(pageTitle);
			
			if (window.vsErrorString) {
				if (window.vsErrorString !== '') {
					window.vsErrorString = unescape(unescape(window.vsErrorString));
					vsQuery += "&v_errorString=" + escape(window.vsErrorString);
				}
			}
			
			/* Make sure we're backwards-compatible with the old window.vsLinkClicked variable
			 * If the local "linkClicked" is not defined, we'll try for "window.vsLinkClicked"
			 */
			if (linkClicked.length === 0) {
				if (typeof window.vsLinkClicked === 'string') {
					linkClicked = window.vsLinkClicked;
				}
			}
			
			if (linkClicked !== '') {
				/* Unescape the URL to make sure we can split on the correct characters */
				linkClicked = unescape(linkClicked);
				
				var q = linkClicked.split('?');
				
				/* Determine the protocol of the link we're about to visit. If non-secure, 
				 * override the default value of 'https'. It's important to default to https
				 * because the user may leave the page without clicking a link, in which case
				 * we cannot determine whether the destination is secure or not. Our goal is
				 * to prevent SSL warnings on the next page 100% of the time, while allowing
				 * non-secure vs.gif calls as often as possible to reduce server load.
				 * Update: Defaulted to non-secure until we can evaluate effect on servers
				 */
				/*
				 var isNonSecure = new RegExp(/^(http:)/);
				 if (isNonSecure.test(q[0])) {
				 parent.protocol = 'http:';
				 }
				 */
				if (q[1]) {
					/* Get all Name/Value pairs from the QueryString */
					var pairs = q[1].split('&');
					for (i = 0; i < pairs.length; i++) {
						/* Get the Name from given Name/Value pair */
						var keyval = pairs[i].split('=');
						
						if (keyval[0] === "navSource" && keyval[1].length >= 1) {
							vsQuery += "&v_pc=" + escape(keyval[1]);
						}
						
						if (keyval[0] === "linkTitle" && keyval[1].length >= 1) {
							vsQuery += "&v_ln=" + escape(keyval[1]);
						}
					}
				}
			}
			
			if (window.vsIsLoggedIn) {
				if (vsIsLoggedIn) {
					vsQuery += "&v_loggedIn=true";
				}
				else {
					vsQuery += "&v_loggedIn=false";
				}
			}
			
			var rememberProfile = ua.utils.getCookie("rememberProfile");
			if (rememberProfile.length > 0) {
				var v_parsedValue = rememberProfile.split("||");
				var v_mpLevel = v_parsedValue[3];
				vsQuery += "&v_els=" + escape(v_mpLevel);
			}
			
			var UALLocaleCookie = ua.utils.getCookie("UALLocaleCookie");
			if (UALLocaleCookie.length > 0) {
				var vs_locale = UALLocaleCookie;
				vsQuery += "&v_locale=" + escape(vs_locale);
			}
			
			/* STEP 2/4 - Append vsQuery with custom name/values
			 *
			 * We want to transition to ua.vsTracking.addTag(), but there are individual pages which refer
			 * to window.vsCustomItems, so let's make sure we merge the two before proceeding.
			 *
			 */
			if (window.vsCustomItems.length > 0) {
				customItems[tagScope] = customItems.concat(window.vsCustomItems);
			}
			
			if (customItems[tagScope].length > 0) {
				for (i = 0; i < customItems[tagScope].length; i++) {
					if (customItems[tagScope][i][0].length >= 1 && customItems[tagScope][i].length === 2) {
						if (window.s40_vs_fix_switch) {
							if (sVS40Vars.indexOf(customItems[tagScope][i][0]) > -1) {
								if (vsQuery.indexOf(customItems[tagScope][i][0]) > -1) {
									bFound = true;
								}
								else {
									bFound = false;
								}
							}
						}
						
						if (!bFound) {
							vsQuery += "&" + escape(customItems[tagScope][i][0]) + "=" + escape(customItems[tagScope][i][1]);
							bFound = false;
						}
					}
				}
			}
			
			/* STEP 3/4 - Add Screen Dimensions, URI & Timestamp */
			
			vsQuery += "&v_duration=" + (v_endTime - v_startTime); // Duration on page
			vsQuery += "&v_timestamp=" + v_startTime.getTime(); // Current timestamp
			if (screen.width) {
				vsQuery += "&v_res=" + screen.width + "x" + screen.height; // Screen Dimensions
			}
			
			vsQuery += "&v_uri=" + escape(thisHref); // URI
			
			if (thisReferrer.length > 0) {
				if (thisReferrer.indexOf("//www.united.com") === -1 && thisReferrer.indexOf("//www.ua2go.com") === -1 && thisReferrer.indexOf("//travel.united.com") === -1) {
					vsQuery += "&v_referrer=" + escape(thisReferrer); // referring URI
				}
			}
			
			/* STEP 4/4 - Request tracking image */
			trackingImageSrc = protocol + trackingImageBase + vsQuery;
			
			/* Save the cookie value as it exists when the tracking image is called for accurate testing */
			visitorID_pre = ua.utils.getCookie('v1st');
			
			/* 
			 * Webkit doesn't allow HTTP requests during unload and beforeunload.
			 * This is a known bug, which has been fixed in version 534:
			 * https://bugs.webkit.org/show_bug.cgi?id=19922#c21
			 * http://en.wikipedia.org/wiki/Safari_version_history#Windows
			 *
			 * Update: Unfortunately, even 534 has a bug. It allows HTTP requests,
			 * but does not send cookie headers with that request. Can't find bug
			 * report for this, but is fixed in the r79501 nightly.
			 * Example: http://www.united.com/ual/asset/SendCookiesUnload.html
			 *
			 * Changing back to useCookie for all versions of Webkit.
			 *
			 * If necessary, we store vsQuery in a session cookie and extract it on
			 * the next page with handleDataCookie()
			 *
			 */
			//if ($.browser.webkit && parseInt($.browser.version) <= 533 && tagScope == defaultTagScope) {
			(function($){
				if ($.browser.webkit && tagScope === defaultTagScope) {
					useCookie = true;
				}
			}(jQuery));
			
			if (useCookie) {
				ua.utils.setCookie(storageCookie, vsQuery, null, '/', hostName);
			}
			else {
				/* 
				 * It's important to set the event handler prior to setting the image's src.
				 * http://www.thefutureoftheweb.com/blog/image-onload-isnt-being-called 
				 */
				var waitingForLoad = true;
				ua.utils.attachEvent(trackingImage,'load',function(){
					waitingForLoad = false;
					if (debug) {
						var temp = ((new Date).getTime()) - executeStart;
						alert('trackingImage loaded in ' + temp + 'ms');
					}
				});
				
				trackingImage.src = trackingImageSrc;
				
				/* 
				 * Stall until the image has been returned, but only for X milliseconds.
				 * In testing, some browsers do not allow the image to complete while
				 * the loop executes. Therefore, we should be very careful about how high
				 * the threshold for breaking is. Enough time to allow the request to 
				 * come back, but not so long that it hinders other browsers.
				 */
				while (!trackingImage.complete && waitingForLoad) { 
					delayedFor = ((new Date).getTime()) - executeStart;
					if (delayedFor >= 250) {
						break;
					}
				}
			}
			
			/* Now get the cookie value after the call is made. Is it the same? */
			visitorID_post = ua.utils.getCookie('v1st');
			
			dataSubmitted[tagScope] = true;
			
			if (debug) {
				var cookieCheck = '', executeEnd = (new Date).getTime();
				
				var execTime = executeEnd - executeStart;
				
				if (visitorID_pre === visitorID_post) {
					cookieCheck = visitorID_post;
				}
				else {
					cookieCheck = visitorID_post + ' (Error - previous value: ' + visitorID_pre + ')';
				}
				
				alert('Tracking Image (vs.gif) has been called.\n\n' + trackingImageSrc 
					+ '\n\nCookie (v1st): ' + cookieCheck 
					+ '\n\nExecution Time: ' + execTime + 'ms (delayed ' + delayedFor + 'ms for image load)'
					);
					
				ua.utils.setCookie('vsImageCounter', Math.floor(ua.utils.getCookie('vsImageCounter')) + 1, null,'/', hostName);
			}
			
			/* Execute optional callback function */
			if (typeof callback === 'function') {
				callback();
			}
		}
		catch(vsErr) {
			trackingImage.src = '//www.united.com/ual/asset/vs.gif?Log=1&v_error=FatalError_sendData&v_errorDetail=' + escape(vsErr.message);
		}
		return false;
    }; // end sendData()
}());


/* Add ua.vsTracking.run() to the unload routines. 
 * 
 * IE 6-8 will not execute 'unload' unless 'load' has been
 * executed, which is a problem for large page which take some time to 
 * load. 'beforeunload', however, does execute in this scenario.
 * 
 * FireFox 3.5+ (and even worse in FF 4) abort image requests when 
 * initiated from within beforeunload. So, we make a special exception.  
 * 
 */
if ($.browser.mozilla) {
	ua.utils.attachEvent(window, 'unload', ua.vsTracking.run);
}
else {
	ua.utils.attachEvent(window, 'beforeunload', ua.vsTracking.run);
}


/* Add click listener to all links in order to track URI parameters. 
 * We use $.click() to target all inline links and $.delegate() to target 
 * dynamically created links. Using both will lead to overlap -- 2 events 
 * for some links. But, this is necessary because neither of them seem
 * to target all links alone. The getClickInfo() method is so simplistic
 * that running it twice shouldn't be a big deal. Also, since much of the
 * page content is generated after the 'load' event, we delay $.click() 
 * for 500ms to make sure we include things like the jdMenu dropdowns (which
 * are missed by $.delegate() for an unknown reason) 
 */
(function($){
	$(window).load(function(){
		setTimeout(function(){
			$("a").click(function(){
			    ua.vsTracking.getClickInfo($(this));
			});
		},500);
	});
	
	$("body").delegate("a", "click", function(){
	    ua.vsTracking.getClickInfo($(this));
	});
}(jQuery));


/* 
 * Don't know what these are for - legend has it that they were added by Business as a "temporary fix"
 * for something. I've updated them to use the new ua.vsTracking.addTag(), but let's really 
 * figure out what it's for and remove if possible.  
 */
if (window.s40_vs_fix_switch) {
    if (s40_vs_fix_switch === "MyItinsAA") {
		ua.vsTracking.addTag("vs_R40_MyItins_AA_Multiplier",vs_R40_Booking_AA_Multiplier.substring(0, 1));
		ua.vsTracking.addTag("vs_R40_MyItins_AA_Origin",vs_R40_Booking_AA_Origin);
		ua.vsTracking.addTag("vs_R40_MyItins_AA_Lowest_Offer",vs_R40_Booking_AA_Lowest_Offer);

		//v_aaAccepted 
		(function($) { 
			$('.isComon').each(function (i) {
				if ($(this).attr("checked") === true) {
					ua.vsTracking.addTag("vs_R40_MyItins_AA_Accepted_Offer",$(this).attr("id"));
					ua.vsTracking.addTag("vs_R40_MyItins_AA_AcceptedPrice",$(this).attr("amount"));
				}
			});
		}(jQuery));

		ua.vsTracking.addTag("vs_R40_MyItins_AA_NumPassengers_Accepted_Offer",passengerOfferCount[0]);
		ua.vsTracking.addTag("v_aaAccepted",passengerOfferCount[0]);
	}
}


(function(){
	if (ua.url.hasOwnProperty('vsDebug')) { 
		if (ua.url.vsDebug === 'true') {
			ua.utils.setCookie('vsDebug', 'true',1,'/','.united.com');
		}
		else {
			ua.utils.deleteCookie('vsDebug');
		}
	}	
}());
