// JavaScript Document


	
var setcookie = "N";
var doreplace = "N";
var ruleset = "None";
var continueeval = "Y";
var referrer = "Nothing";
var overridevariablevalue = "Nothing";
	

// Examine cookie
var curCookie = document.cookie.split("; ");
    for (var i=0; i < curCookie.length; i++) 
	{
	
        var crumb = curCookie[i].split("=");
        var name = crumb[0];
		var value = crumb[1];
		// Found a Hubshout Cookie
		if (name == "HubCookie") 
		{	

			// Pull values from the HubCookie
			var cookvalue = value.split("|");
			
			overridevariablevalue = cookvalue[0];

				if (overridevariablevalue != "Nothing")
				{
					value = overridevariablevalue;
					
			
			// We found our variable name.. Now look at values.
			if (name = "frtracker")
			{
				
					// We found a value match. Set doreplace to Y...
					if (value == "googleppc")
					{
					 overridevariablevalue = value;
					 doreplace = "Y";
					 ruleset = "V";
					 setcookie = "Y";
					 continueeval = "N";							 
					}
						
			}

				}
				
			referrer = cookvalue[1];	
				if (referrer != "Nothing")
				{
					var str = referrer;
					
				}
			// This was set to Y in the template because that is used later, but we DONT want to rewrite the cookie here.	
			setcookie = "N";			
		}
	}
	


// Only do this if HubCookie was NOT found...
if (continueeval == "Y")
	{	
	//Examine URL string
	var searchString = document.location.search;
	searchString = searchString.substring(1);
	
	var nvPairs = searchString.split("&");
	for (i = 0; i < nvPairs.length; i++)
		{
	     	var nvPair = nvPairs[i].split("=");
	     	var name = nvPair[0];
	     	var value = nvPair[1];	
	
			
			
			// We found our variable name.. Now look at values.
			if (name = "frtracker")
			{
				
					// We found a value match. Set doreplace to Y...
					if (value == "googleppc")
					{
					 overridevariablevalue = value;
					 doreplace = "Y";
					 ruleset = "V";
					 setcookie = "Y";
					 continueeval = "N";							 
					}
						
			}

		}				
	
	}
		
	
// Only do this if HubCookie was NOT found AND URL string evaluation failed to find anything...
if (continueeval == "Y")
	{

	//Examine referrer
	
	var str = document.referrer;
	
	
	}	
	


	
// START myscript FUNCTION
	
function myscript() {

	//Start Rewrite			
			
				
				
								
				
				
				var newtext = document.body.innerHTML;	
						
											if (ruleset == "V")	
							{
							
									if (overridevariablevalue == "googleppc")
										{
										newtext = newtext.replace("877-FIT-2021","877-418-5394");
										newtext = newtext.replace("877-FIT-2021","877-418-5394");
										newtext = newtext.replace("877-FIT-2021","877-418-5394");
										newtext = newtext.replace("877-FIT-2021","877-418-5394");
										}
																						
							}
							
						if (ruleset == "R")	
							{	
																			
							}

					document.body.innerHTML = newtext;			
				
						
				// alert('5');	
					
	//End Rewrite
	
	
	if (setcookie == "Y")
		{
		// Set cookie
		// We need to add a PATH substatement here to specify the ROOT directory for landing pages in directories...
		
		days=30; // number of days to keep the cookie
		myDate = new Date();
		myDate.setTime(myDate.getTime()+(days*24*60*60*1000));

		// Build a HubCookie value that includes the overridevariablevalue | referrer for later processing if they come back.
		document.cookie = 'HubCookie=' + overridevariablevalue + '|' + referrer + '; path=/; expires=' + myDate.toGMTString();		
		}
	
}  

// END myscript function



/*
function onloadhandler()
	{
	window.onLoad = myscript();
	}
*/






if (doreplace == "Y")
	{

		//Get browser and Page - Delay if IE and FindaLocation due to Google map conflict
		var browser=navigator.appName;
		var sPath = window.location.pathname;
		var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);		
		if (browser=="Microsoft Internet Explorer" && sPage == "FindaLocation.aspx")
			{
			setTimeout('myscript();', 5);
			}			
			else
			{
			setTimeout('myscript();', 5);
			}	
	
	}  // End If DoReplace is Y
	

	


	

