/* ========================================================================================
	OMNITURE CUSTOM CODE
	Primary Author: Mike Liu (mliu@acumensolutions.com)
	Last update: 01/07/2010

	This code is included on all pages tracked by Travel Channel.  This file sets up variables
	for future use, declares helper functions and globally-set variables.
   ======================================================================================== */


/* ====================== START HELPER FUNCTIONS ========================= */

/*
	FUNCTION removes Vignette template pre-/suffixes.  Example:  "ci.template1.pm" --> "template1"
*/
var strip = function (string) {
	if (!string) {
		return;
	}
	var stripped;
	var tempArray = string.split(".");
	if (tempArray.length <= 2) {
		stripped = tempArray[0];
	} else if (tempArray.length == 3) {
		stripped = tempArray[1];
	} else {
		// unfamiliar pathname structure
	}
	return stripped;
}

/*
	FUNCTION replaces all underscores (_) with spaces, used with buildPageName()
*/
var removeUnderscores = function (string) {
	if (string) {
		return string.replace(/\_/g, ' ');
	} else {
		return;
	}
}

/*
	FUNCTION replaces all plus signs (+) with underscores
*/
var removePlus = function (string) {
	if (string) {
		return string.replace(/\+/g, '_');
	} else {
		return;
	}
}

/*
	FUNCTION converts a string to lower case -- used with most variables to resolve casing conflicts
*/
var lower = function (string) {
	if (string) {
		return string.toLowerCase();
	} else {
		return;
	}
}

/* ====================== END HELPER FUNCTIONS ========================= */


/*
	====================== BEGIN WORKING VARIABLES =========================
	vars: fullURL, url, queryString, qsParams, urlVars
	========================================================================
*/
// Initialize working variables
var temp, url, queryString;

// GET FULL URL including querystring
var fullURL = url = location.href;


try {
	// isolate URL from queryString
	if (fullURL.indexOf("?") > 0) {
		url = fullURL.substring(0, fullURL.indexOf("?"));
		queryString = fullURL.substring(fullURL.indexOf("?")+1);
	}

	// remove trailing '/' from URL and any anchor tags
	temp = url.split("#");
	if (temp.length > 1) {
		url = temp[0];
	}

	if(url.charAt(url.length-1)=="/"){
		url=url.substring(0,url.length-1);
	}

	// decode URL for special chars
	url = removePlus(decodeURIComponent(url));

	// if there is a querystring, read it into a hash table for easier use
	if (queryString) {
		var qsParams = new Array();
		temp = queryString.split("&");
		for (var x in temp) {
			qsParams[temp[x].split("=")[0]] = temp[x].split("=")[1];
		}
		temp = null;
	}

	/* urlVars will be an array with format in the example below
		[http:]/[]/[www.travelchannel.com]/[TV_Shows]/[Anthony_Bourdain]/[SUBCAT2]/[SUBCAT3]/[about.html]
		  0		1			2					3				4			5		  6			 7
	*/
	var urlVars = url.split("/");

	/* ====================== END WORKING VARIABLES ========================= */


	/* === START GLOBAL URL-BASED VARIABLES === */

	/* START PROP11 - page URL (full url minus querystring and/or trailing '/' */
	s.prop11 = url;
	/* END PROP11 */

	/* START PROP14 - hostname GLOBAL */
	s.prop14 = location.hostname;
	/* END PROP14 */

	/* START PROP22 - querystring */
	s.prop22 = queryString;
	/* END PROP22 */

	/* START PAGETYPE - page_not_found */
	if (url.toLowerCase().indexOf("page_not_found") >= 0) {
		s.pageType = "errorPage";
	}
	/* END PAGETYPE */

} catch (e) {

}
/* === END GLOBAL URL-BASED VARIABLES === */



