function RemoveIllegalHitboxCharacters( sString ) 
{
	var rxWhiteSpace = /\s/g;
	var rxIllegal = /[&"'#$%^\*:!\\<>~;\[\]\{\}]/g;
	var sReturn = sString.replace(rxWhiteSpace,"+");
	sReturn = sReturn.replace(rxIllegal,"");

	return sReturn;
}

//For setting of PEC variable on Writeback collect account and Add Account pages.
function RemoveDigits( sString )
{
	var rxDigits = /\w/g;
	return sString.replace(rxDigits,'x');
}


//function GetContentGroup( sContentType , nLocal)
//{
//	var sContentTypeClean = RemoveIllegalHitboxCharacters(sContentType);
//	var sReturn = "/"+ sContentTypeClean;
//	
//	if (nLocal == 1) {
//		var sDivisionNameClean = RemoveIllegalHitboxCharacters(getCookieVal("DivName"));
//		var sMarketNameClean = RemoveIllegalHitboxCharacters(getCookieVal("MktName"));
//		
//		if(sDivisionNameClean != "" && sMarketNameClean != "")
//		{
//			sReturn += ";/" + sMarketNameClean + "/" + sContentTypeClean
//			sReturn += ";/" + sDivisionNameClean + "/" + sMarketNameClean + "/" + sContentTypeClean
//		}
//	}

//	return sReturn;
//}

function GetContentGroup(sPrimary , sSecondary)
{
	var sReturn = "";
	if (getCookieVal("DivName") != '')
	{
		sReturn += "/" + RemoveIllegalHitboxCharacters(getCookieVal("DivName"));
		sReturn += "/" + RemoveIllegalHitboxCharacters(getCookieVal("MktName"));
	}
	
	if(sPrimary != null && sPrimary != '')
		sReturn += "/" + RemoveIllegalHitboxCharacters(sPrimary);
	if(sSecondary != null && sSecondary != '')
		sReturn += "/" + RemoveIllegalHitboxCharacters(sSecondary);
		
//	alert("GetContentGroup=" + sReturn);
	return sReturn;
}

function GetHBXSuffix()
{
	// getCookieVal requires CookieHelper.js
	var sSuffix = getCookieVal("HBXPageNameSuffix");
	sSuffix = sSuffix == false ? "" : "+-+" + sSuffix;
	return sSuffix;
}

function SetPageTitle(interimVal)
{
	var sPageTitle = (hbx.pn == "PUT+PAGE+NAME+HERE" || hbx.pn == undefined) ? document.title.replace(" ","+") : hbx.pn;
	var sInterim = interimVal == undefined ? "" : "+-+" + interimVal;
	var sSuffix = GetHBXSuffix();

	if(hbx.pn != false)
	{
		hbx.pn = sPageTitle + sInterim + sSuffix;
	}
}

function GetSegment()
{
	var sSegment = "++";	// Clear all previous segments
	if(getCookieVal("Hash") != "")
		sSegment += "2"; //switched the --2,3 to --3,2 per bug #5000 
	else
		sSegment += "3";
	
	var iHFStatus = getCookieVal("HFStatus");
	
	//Hitbox Code for defining Segment based on HFStatus
	if(iHFStatus == "1")
		sSegment += ",6";
	else if(iHFStatus == "2")
		sSegment += ",4";
	else if(iHFStatus == "3")
		sSegment += ",5";
		
	var sBFStatus = GetCookie("BuyFlow","BFStatus");
	
	if(sBFStatus == "InBuyFlow")
		sSegment += ",8";
	else if(sBFStatus == "InWritebackArea")
		sSegment += ",8,9";
	else if(sBFStatus == "InWritebacks")
		sSegment += ",8,9,10";
	else if(sBFStatus == "FailedWriteback")
		sSegment += ",8,9,11";
		
	return sSegment;
}

function GetLocChange()
{
	var sResult = "";

	var sLocGUID = GetCookie("Serviceability","GUID");
	var sPrevLocGUID = GetCookie("Serviceability","PrevGUID");
	
	if(sLocGUID != false || sPrevLocGUID != false)
	{
		if(sLocGUID != sPrevLocGUID)
		{
			sLocType = GetCookie("Serviceability","LocalizationTypeID");
			switch(sLocType)
			{
				case "1":
					sResult = "Address Type-In (DST Footprint)";
					break;
				case "2":
					sResult = "DST Account (Address)";
					break;
				case "3":
					sResult = "Zip Code";
					break;
				case "4":
					sResult = "Zip Code - User Picked Franchise";
					break;
				case "5":
					sResult = "DST Account (FranchiseMapID) - After G2B Failure";
					break;
				case "9":
					sResult = "Address Type-In (CSG Footprint)";
					break;
				case "10":
					sResult = "CSG Account (FranchiseMapID)";
					break;
				default :
					sResult = "Unknown";
					break;
			}
			
			sResult += " | " + document.title;
			
			SetCookie("Serviceability", "PrevGUID", sLocGUID);
		}
	}

	return sResult;
}

function trackInternal(hbxLink)
{
	_hbLink(hbxLink);
}

