// HITBOX HELPER - v2.1 // infuz
// v2.1 -- 2008.08.01
//  - Updated URL regex to parse out the deep link parts
function hbxHelper2(opt) {
	// Set defaults
	opt.url			= !opt.url			? location.href	: opt.url;				// The absolute URL string to parse
	opt.client		= !opt.client		? ""			: opt.client + "/";		// Client name
	opt.site		= !opt.site			? ""			: opt.site + "/";		// Site name
	opt.campaign	= !opt.campaign		? ""			: opt.campaign;			// Campaign string (for hbx.cmp setting)
	opt.root		= !opt.root			? ""			: opt.root;				// Alternate root to use
	opt.defaultDoc	= !opt.defaultDoc	? ""			: opt.defaultDoc;		// Name of default page name to use when none in URL
	opt.category	= !opt.category		? ""			: opt.category;			// Used to further categorize the mlc
	opt.pagePrefix	= !opt.pagePrefix	? ""			: opt.pagePrefix + "+";	// Prefix to prepend to the page name
	opt.pageSuffix	= !opt.pageSuffix	? ""			: "+" + opt.pageSuffix;	// Suffix to append to the page name
	opt.pageName	= !opt.pageName		? ""			: opt.pageName;			// Force the page name to this value
	
	// This RegExp captures a URL's parts
	// [0] - input string
	// [1] - absolute url without query or in-page anchors
	// [2] - absolute url path without page name or query
	// [3] - request protocol
	// [4] - server name
	// [5] - path to the resource without page name or query
	// [6] - the last part of the URL before the query (usually the page name)
	// [7] - deep-link path, without leading "#"
	// [8] - in-page anchor name, without leading "#"
	// [9] - query string, without the leading question mark
	var reUrl = /^((([^:]*):\/\/([^\/?]+)(?:\/?((?:[^\/?#]+\/)*)))([^\/?#]*))(?:#(?:(?:\/([^?]*))|([^?]*)))?(?:\?((?:(?:[^&=]+(?:[=][^&]*)?)\&?)*))?$/g;
	var result = reUrl.exec(opt.url);
	
	// Get the path from the URL (using an alternate root, if given)
	var path =
		result[2].indexOf(opt.root) == 0			// Check if the specified root is in the URL
			? result[2].substr(opt.root.length)		// If so, exclude the root from the path
			: result[5];							// Otherwise, use the path from the RegExp
	
	// Extract the page name
	var page =
		opt.pageName.length							// Check if we are forcing the page name to the given value
			? opt.pageName							// Use the page name override
			: !result[6].length						// If there is not a page reference (i.e. www.site.com, etc.)
				? opt.defaultDoc					// Then use the opt.defaultDoc name instead
				: result[6].replace(/\.html$/, "");	// Otherwise, remove the ".html" extension if it exists
			
	// TODO: Add logic to use deep-links
	
	// Set the Hitbox values
	this.pn = opt.pagePrefix + page + opt.pageSuffix;
	this.mlc = opt.site + path + opt.category + ";/" + opt.client + opt.site + path + opt.category;
	this.cmp = opt.campaign;
}

// HITBOX HELPER - v1.0 // infuz
function hbxHelper(clientID, siteID, requestPath, campaign, homePage) {
	var pagePath = requestPath;
	var pageFolder = "/";
	var hbxpn = pagePath;
	var pageParentIndex = pagePath.lastIndexOf("/");
	if (pageParentIndex != -1) {
		pageFolder += pagePath.substring(0, pageParentIndex);
		hbxpn = pagePath.substring(pageParentIndex + 1, pagePath.length);
	}
	pageFolder += (pageFolder == "/" ? homePage : "");
	var mlc1 = siteID + pageFolder;
	var mlc2 = clientID + siteID + pageFolder;

	// SET DEFAULTS (match hbx props)
	this.pn = hbxpn;
	this.mlc = mlc1 + ";" + mlc2;
	this.cmp = campaign;
}
