//Site Specific Functions
function removeSlashesFromDirectoryNames(orginalPath) {

	var newPath = orginalPath;
	var knownProblems = new Array("iht-/-tax-planning");
	var fixes = new Array("iht-tax-planning");
	
	/* Sample Usage
	var knownProblems = new Array("iht-/-tax-planning");
	var fixes = new Array("iht-tax-planning"); */

	
	for (i = 0; i < knownProblems.length; i++) {
		newPath = newPath.replace(knownProblems[i], fixes[i]);
	}
	
	return newPath;

}


/* */
function reversePrimaryNavigation(originalNav) {
	
	var newNav = originalNav;
	var knownProblems = new Array("IHT / Tax Planning");
	var fixes = new Array("iht-tax-planning");
	
	for (i = 0; i < knownProblems.length; i++) {
		newNav = newNav.replace(knownProblems[i], fixes[i]);
	}
	
	newNav = newNav.replace(/ /gi, "-");
	
	var originalOrder = newNav.split(",");
	var newOrder = originalOrder.reverse();

	
	return newOrder;
}


function currentPage(currentURL, fileName, siteRoot) {
	
	var currentPage;
	
	if (currentURL == siteRoot) {
		currentPage = "homepage";
	} else if (currentURL.indexOf(".article") > -1) {
		currentPage = "article";
	} else if (currentURL == "http://www.moneymarketing.co.uk/directory/" || currentURL == "http://www.moneymarketing.co.uk/directory") {
		currentPage = "directoryhome";
	} else if (currentURL.indexOf("searchResults.aspx") > -1) {
		currentPage = "searchresults";
	} else if (currentURL.indexOf("MP_SearchResults.aspx") > -1) {
		currentPage = "eventsearchresults";
	} else if (currentURL.indexOf("pubindex.aspx") > -1) {
		currentPage = "publicationindex";
	} else if (currentURL.indexOf(".issue") > -1) {
		currentPage = "issue";
	} else if (currentURL.indexOf("events") > -1 && currentURL.indexOf(".details") > -1 ) {
		currentPage = "eventdetails";
	} else if (currentURL.indexOf("events") > -1 && currentURL.indexOf(".booking") > -1 ) {
		currentPage = "eventbooking";
	} else if (currentURL.indexOf("events") > -1 && currentURL.indexOf(".thank-you") > -1 ) {
		currentPage = "eventbookingconfirmation";
	} else if (currentURL.indexOf("CompanySearchResults") > -1 ) {
		currentPage = "directorysearchresults";
	} else if (currentURL.indexOf(".details") > -1 ) {
		currentPage = "directorydetail";
	} else if (currentURL.indexOf("/directory/") > -1 ) {
		currentPage = "directoryother";			
	} else if (currentURL.indexOf("pagenotfound.aspx") > -1) {
		currentPage = "error";	
	} else if (getFileName() == "index") {
		currentPage = "sectionpage";
	} else {
		currentPage = "unknown";	
	}
	
	return currentPage;
}



//intialise a few variables

/* CHANGE THIS BETWEEN TEST AND LIVE */
var rootURL = "http://www.moneymarketing.co.uk/";
var sitePrefix = "mm";


/* -- From here this is the same on all sites -- */

currentURL = window.location.href;
currentFileName = getFileName();
scprop1="";		//Editorial Search Terms
scprop2="";		//Number of Search Results
scprop3="";		//Content Title	
scprop4="";		//Content ID
scprop5="";		//Content Type
scprop6="";		//Site Section
scprop7="";		//Site Sub Section
scprop8="";		//Site Sub Section 2
scprop9="";		//Site Sub Section 3
scprop10="";	//Event Search Terms
scPageName="default"; 
scChannel="default";
scHier1=sitePrefix + ":" +"default";
scHier2="default";
user_id	= getMeta("CelerityGuidID");

var page = currentPage(currentURL, currentFileName, rootURL);


//if user is logged in then record thier user_id
if (user_id != "0")	{
	s.eVar29 = user_id;
}


//alert(page);

switch (page) {

	/*------ HOME PAGE -----*/
	case "homepage":
		scPageName="home";
		scChannel="home";
		scHier1=sitePrefix + ":" + "home";
		
		break;
	
	/*------ SECTION PAGE -----*/
	case "sectionpage": 
	
		var levels = removeSlashesFromDirectoryNames(getDirectory()).split("/");
		var levelsNumber = levels.length - 2;		
		
		//deal with pageName
		var scPageName = levels[1] + ":";
		if (levelsNumber > 1) {
		
			scPageName = "";
			for (i = 1; i <= levelsNumber; i++) {
				scPageName = scPageName + levels[i] + ": "; 
			}
		}
		scPageName = scPageName + "home";
		
		//deal with props 6 - 9
		switch (levelsNumber) {
		
			case 1: 
			
				scprop6 = sitePrefix;
				scprop7 = scprop6 + ":" + levels[1];
				scprop8 = scprop7 + ":" + "section home";
				scprop9 = scprop8;
				scHier1 = scprop7;
				break;
				
			case 2: 
				
				scprop6 = sitePrefix;
				scprop7 = scprop6 + ":" + levels[1];
				scprop8 = scprop7 + ":" + levels[2];
				scprop9 = scprop8 + ":" + "section home";
				scHier1 = scprop9;
				break;
				
			case 3:
				scprop6 = sitePrefix;
				scprop7 = sitePrefix + ":" + levels[1];
				scprop8 = scprop7 + ":" + levels[2];
				scprop9 = scprop8 + ":" + levels[3] + ":" + "section home";
				scHier1 = scprop9;
				break;
				
			case 4:
				scprop6 = sitePrefix;
				scprop7 = sitePrefix + ":" + levels[1];
				scprop8 = scprop7 + ":" + levels[2];
				scprop9 = scprop8 + ":" + levels[3] + ":" + "section home";
				scHier1 = scprop9;
				break;
		}
		
		
		scChannel = levels[1];

		
		break;
	
	/*------ ARTICLE PAGE -----*/
	case "article":
	
			scprop3 = getHeadline();
			scprop4 = fileNameWithoutExtension(getFileName());
			scprop5 = sitePrefix + " " + getMeta("section")
			
			var primaryNavigation = reversePrimaryNavigation(getMeta("primarynavigation"));
			
			//deal with pageName
			var scPageName = primaryNavigation[0] + ":" + scprop3;
			if (primaryNavigation.length > 1 ) {
				scPageName = "";
				for (i = 0; i < primaryNavigation.length; i++) {
					scPageName = scPageName + primaryNavigation[i] + ": "; 
				}
				scPageName = scPageName + scprop3;
			}

			//check for comment
			if (currentURL.indexOf("#commentsubmitted") > -1) {
			
				s.events="event17";
				
			}
			
			//deal with props 6 - 9
			switch (primaryNavigation.length) {
		
				case 1: 
					
					scprop6 = sitePrefix
					scprop7 = scprop6 + ":" + primaryNavigation[0];
					scprop8 = scprop7  + ":" + "article";
					scprop9 = scprop8;
					scHier1 = scprop7 + ":articles";
					
					break;
					
				case 2: 
					scprop6 = sitePrefix
					scprop7 = scprop6 + ":" + primaryNavigation[0];
					scprop8 = scprop7 + ":" + primaryNavigation[1];
					scprop9 = scprop8 + ":" + "article";
					scHier1 = scprop7 + ":articles";
					
					break;
				case 3:
					scprop6 = sitePrefix
					scprop7 = scprop6 + ":" + primaryNavigation[0];
					scprop8 = scprop7 + ":" + primaryNavigation[1];
					scprop9 = scprop8 + ":" + primaryNavigation[2] + ":" + "article";
					scHier1 = scprop9 + ":articles";
					
					break;
				case 4:
					scprop6 = sitePrefix
					scprop7 = scprop6 + ":" + primaryNavigation[0];
					scprop8 = scprop7 + ":" + primaryNavigation[1];
					scprop9 = scprop8 + ":" + primaryNavigation[2] + ":" + "article";
					scHier1 = scprop9 + ":articles";
					
					break;
			}
			
			scChannel = primaryNavigation[0];
	
	
		break;
		
		/*------ EDITORIAL SEARCH RESULTS PAGE -----*/
		case "searchresults": 
			scPageName = "Search Results";
			scChannel = "Search";
			scHier1 = sitePrefix + ":" + "Search";
			
			scprop2 = "1"; //TODO: Abacus need to provide numbers of search results so this can be populated.
				
			var keywords = getURLParam("qkeyword");
				
			if (keywords) {
				scprop1 = keywords;
			} else {	
				var cmd_value = getURLParam("cmd");
				if(cmd_value == "gotopage") {
					scPageName = "Search Results:" + getURLParam("val");
				} else {
					scPageName = "Search Results:Unknown";
				}
			
			}
		break;
		
		/*------ Directory ------*/
		case "directoryhome":
		
			scChannel = "directory";
			scPageName = "directory:home";
			scHier1 = sitePrefix + ":" + "directory:home";
			
			scprop6 = sitePrefix;
			scprop7 = scprop6 + ":directory";
			scprop8 = scprop7 + ":home";
			scprop9 = scprop8;
			
		break;
		
		case "directorysearchresults":
		
			scChannel = "directory";
			scPageName = "directory:search results";
			scHier1 = sitePrefix + ":" + "directory:search results";
			
			scprop6 = sitePrefix;
			scprop7 = scprop6 + ":directory";
			scprop8 = scprop7 + ":search results";
			scprop9 = scprop8;
			
		break;
		
		case "directorydetail":
		
			scChannel = "directory";
			scPageName = "directory:details:" + getEventName();
			scHier1 = sitePrefix + ":" + "directory:details";
			
			scprop3 = getEventName();
			scprop4 = fileNameWithoutExtension(getFileName());
			scprop5 = sitePrefix + " directory entry";			
			
			scprop6 = sitePrefix;
			scprop7 = scprop6 + ":directory";
			scprop8 = scprop7 + ":details";
			scprop9 = scprop8;
			
		break;
		
		case "directoryother":
		
			scChannel = "directory";
			
			scprop6 = sitePrefix;
			scprop7 = scprop6 + ":directory";
			
			if (currentURL.indexOf("/get-listed") > -1 ) {
			
				scPageName = "directory:get listed";
				scHier1 = "directory:get listed";
				
				scprop8 = scprop7 + ":get listed";
				scprop9 = scprop8;
				
			} else if (currentURL.indexOf("/contact-us") > -1 ) {
			
				scPageName = "directory:contact us";
				scHier1 = "directory:contact us";
				
				scprop8 = scprop7 + ":contact us";
				scprop9 = scprop8;
				
			} else if (currentURL.indexOf("/thank-you") > -1 ) {
			
				scPageName = "directory:thank you";
				scHier1 = "directory:thank you";
				
				scprop8 = scprop7 + ":thank you";
				scprop9 = scprop8;
				
			} else if (currentURL.indexOf(".contact") > -1 ) {
			
				scPageName = "directory:contact company";
				scHier1 = "directory:contact company";
				
				scprop8 = scprop7 + ":contact company";
				scprop9 = scprop8;
			
			} else if (currentURL.indexOf(".amend") > -1 ) {
			
				scPageName = "directory:amend entry";
				scHier1 = "directory:amend entry";
				
				scprop8 = scprop7 + ":amend entry";
				scprop9 = scprop8;
				
			} else {
				
				scPageName = "directory:unknown";
				scHier1 = "directory:unknown";
				
				scprop8 = scprop7 + ":unknown";
				scprop9 = scprop8;
				
			}
			
		
			
		break;
		
		
		/*------ Event Search Results -----*/
		case "eventsearchresults":
			scPageName = "Event Search Results";
			scChannel = "Events";
			scHier1 = sitePrefix + ":" + "Events:Search";
			
			scprop2 = "1";
			scprop10 = "default"; //TODO: the event search results page does not include the keywords in the URL. It must be held in a cookie.  
		
		break;
		
		/*------ Issue -----*/
		case "issue":
		
		//deal with pageName
		scChannel = "issues";
		scPageName = "issues:" + stripUnwantedCharacters(getDirectory(), "");
		scHier1 = sitePrefix + ":" + "Issues";
		
		scprop6 = sitePrefix;
		scprop7 = scChannel;
		scprop8 = scPageName;
		scprop9 = scPageName;
		
		break;
		
		/*----- EVENT DETAILS -----*/
		case "eventdetails":
			var eventName = getEventName();
		
			scChannel = "events";
			scPageName = "events:" + eventName;
			scHier1 = sitePrefix + ":" + "Events:Details";
			
			scprop3 = eventName;
			scprop4 = fileNameWithoutExtension(getFileName());
			scprop5 = "events";
			scprop6 = sitePrefix;
			scprop7 = scChannel;
			scprop8 = scprop6;
			scprop9 = scprop6;
			
			s.eVar18 = eventName;
			//s.eVar20 = organiserName; TODO: Should be set to event organiser name but cannot be done at the moment.  There is no occurence of the organiser name before the advertising script block.  need this added as a meta-tag.
			
		break;
		
		/*----- EVENT BOOKING -----*/
		case "eventbooking":
	
			//TODO - work out whether the confirmation differs from the form
	
		var eventName = getEventName();
		
			scChannel = "events";
			scHier1 = sitePrefix + ":" + "Events:Booking";
			scPageName = "events:booking:" + eventName;
			
			scprop3 = eventName;
			scprop4 = fileNameWithoutExtension(getFileName());
			scprop6 = sitePrefix;
			scprop7 = scChannel;
			scprop8 = scprop6;
			scprop9 = scprop6;
			
			s.events="event12";
		
		break;
		
		/*----- EVENT BOOKING CONFIRMATION -----*/
		case "eventbookingconfirmation":
			
			scChannel = "events";
			scPageName = "events:booking:confirmation"; // + eventName; **TODO: Can't get this yet
			scHier1 = sitePrefix + ":" + "Events:BookingConfirmation";
			
			scprop6 = sitePrefix;
			scprop7 = scChannel;
			scprop8 = scprop6;
			scprop9 = scprop6;
			
			s.events = "event12";
			
		break;
		
		/*----- ERROR PAGE -----*/
		case "error":
		
			scChannel = "Errors";
			scPageName = "ErrorPage";
			scHier1 = sitePrefix + ":" + "errors";
			s.pageType = "errorPage";
			scprop6 = sitePrefix;
			scprop7 = "errors";
			
		break;
		
		/*------ Unknown ------- */
		case "unknown":
		
			scPageName = getFileName();
			scChannel = stripUnwantedCharacters(getDirectory(), "~");
		
		break;
		
		/*------ Catch All ----- */
		default:
		scPageName = getFileName();
		scChannel = stripUnwantedCharacters(getDirectory(), "~");
		
		
	
} //End of Switch


if (typeof site_area != "undefined") { 

	if (site_area.length > 0) {
		scHier2 = site_area.replace(/\./g, ":");
	} else {
		scHier2 = sitePrefix + ":unknown:" + scHier1;
	}
}

mc_page = cleanForSiteCatalyst(sitePrefix + " " + scPageName);


//---------- set the actual SC variables ------------------



/* You may give each page an identifying name, server, and channel on
the next lines. */

//the following are set on all pages
s.pageName = cleanForSiteCatalyst(sitePrefix + " " + scPageName);
s.channel= cleanForSiteCatalyst(sitePrefix +  " " + scChannel);
s.hier1= cleanForSiteCatalyst(scHier1);
s.hier2= cleanForSiteCatalyst(scHier2);

s.prop1=cleanForSiteCatalyst(scprop1); //Search Terms
s.prop2=cleanForSiteCatalyst(scprop2); //Number search results
s.prop3=cleanForSiteCatalyst(sitePrefix + " " + scprop3);
s.prop4=cleanForSiteCatalyst(sitePrefix + " " +  scprop4);
s.prop5=cleanForSiteCatalyst(scprop5);
s.prop6=cleanForSiteCatalyst(scprop6);
s.prop7=cleanForSiteCatalyst(scprop7);
s.prop8=cleanForSiteCatalyst(scprop8);
s.prop9=cleanForSiteCatalyst(scprop9);
s.prop10=cleanForSiteCatalyst(scprop10);


/* Conversion Variables */
s.state=""
s.zip=""
//s.events=""
s.products=""
s.purchaseID=""
/************* DO NOT ALTER ANYTHING BELOW THIS LINE ! **************/

//alert("scprop6: " + scprop6 + "\n" + "scprop7: " + scprop7 + "\n" + "scprop8: " + scprop8 );
var s_code=s.t();if(s_code)document.write(s_code)