/* This Javascript file is used to build the pgt_metadata object on each page for Omniture/ADBP use. */

/* Functions */
function getTourName(tour){ 
	var name; 
	switch(tour) { 
		case "s": 
			name = "Champions Tour";
			break;
		case "h":
			name = "Nationwide Tour";
			break;
		default: 
			name = "PGA Tour";
	}
	return name;
}

function getSpecialTournamentName(theID){ 
	var name; 
	switch(theID) {
		case "/r011/": 
			name = "THE PLAYERS Championship";
			break;
		case "/r027/": 
			name = "The Barclays";
			break;
		case "/r028/": 
			name = "BMW Championship";
			break;
		case "/r060/": 
			name = "THE TOUR Championship";
			break;
		case "/r470/": 
			name = "Accenture Match Play Championship";
			break;
		case "/r473/": 
			name = "Cadillac Championship";
			break;
		case "/r476/": 
			name = "Bridgestone Invitational";
			break;
		case "/r489/": 
			name = "HSBC Champions";
			break;
		case "/r505/": 
			name = "Deutsche Bank Championship";
			break;
		case "/r500/": 
			name = "The Presidents Cup";
			break;				
		default: name = "";
	}
	return name;
}
/* END Functions */

/*404 - PAGE NOT FOUND*/
if(document.title == "PGATOUR.com - Page Not Found"){
	var pgt_metadata = {
		section: ["error",""],
		template_type: "error",
		content_type: "none"
	};
}

/* Sub-Domains */

/* TOUR REPORT */
else if(window.location.href.match('^(.*)tourreport.pgatour.com/.*/?')){
	var pgt_metadata = {
		section: ["tour report",""],
		template_type: "blog",
		content_type: "blog read"
	};
}

/* WORLD GOLF CHAMPIONSHIPS */
else if(window.location.pathname.match('^/wgc_index.html$') || window.location.href.match('^(.*)worldgolfchampionships.com/(index.html)?$')){
	var pgt_metadata = {
		section: ["World Golf Championships",""],
		template_type: "section front",
		content_type: "none"
	};
}

/* CHARITY WEBSITE */
else if(window.location.href.match('^(.*)together.pgatour.com/.*/?')){
	var pgt_metadata = {
		section: ["charity",""],
		template_type: "other",
		content_type: "none"
	};
}

/* GALLERIES */
else if(window.location.href.match('^(.*)galleries.pgatour.com/.*/?')){
	var pgt_metadata = {
		section: ["galleries",""],
		template_type: "other",
		content_type: "none"
	};
}

/* WORLD CUP */
else if(window.location.href.match('^(.*)worldcup.pgatour.com/.*/?')){
	var pgt_metadata = {
		section: ["world cup",""],
		template_type: "other",
		content_type: "none"
	};
}

/* END Sub-Domains */


/* PGA Tour, Champions Tour, and Nationwide Tour Sites */

/* PGA TOUR, CHAMPIONS TOUR, AND NATIONWIDE TOUR HOME PAGES */
else if(window.location.pathname.match('^/(index.html)?$')){
	var pgt_metadata = {
		section: ["PGA Tour homepage",""],
		template_type: "index",
		content_type: "none",
		tour: "PGA Tour"
	};
}
else if(window.location.pathname.match('^/[rsh]/(index.html)?$')){
	var tournamentID = window.location.pathname.match('^/[rsh]/(index.html)?$');
	var tourName = getTourName(tournamentID[0].charAt(1));
	var pgt_metadata = {
		section: [tourName+" homepage",""],
		template_type: "index",
		content_type: "none",
		tour: tourName
	};
}

/* TOURNAMENT PAGE, TOURNAMENT LEADERBOARD, AND MAIN LEADERBOARD */
else if (window.location.pathname.match('^/tournaments/.*/?') || window.location.pathname.match('^/leaderboards/current/.*/?') || window.location.pathname.match('^/[rsh]/leaderboard/.*/?')) {
	var tournamentID = (window.location.pathname.match('^/[rsh]/leaderboard/.*/?')) ? window.location.pathname.match('/[rsh]/') : window.location.pathname.match('/[rsh][0-9]{3}/|/presidentscup/');
	var tourName = getTourName(tournamentID[0].charAt(1));
	var tournamentName = "";
	var tournID = "";
	/*Set tournament name*/
	if(document.getElementById("tourTournSubHead")){
		var divTags = document.getElementById("tourTournSubHead").getElementsByTagName("div");
		for(i = 0; i < divTags.length; i++){
			if(divTags[i].className == "tourTournSubName"){
				tournamentName = divTags[i].innerHTML; 
				break;
			}
		}
	}
	/*else if(typeof euphony != "undefined"){
		tournamentName = euphonyTournamentName;
	}*/
	else{
		/* The Presidents Cup is only exception since the URL doesn't have the tournament's ID of r500 in it. So change tournamentID's value to Presidents Cup's actual ID before moving on. */
		if(tournamentID[0] == "/presidentscup/"){
			tournamentID[0] = "/r500/";
		}
		tournamentName = getSpecialTournamentName(tournamentID[0]);
	}
	
	/*Initialize the object*/
	var pgt_metadata = {
		template_type: "other",
		content_type: "none",
		tour: tourName,
		tournament: tournamentName+" ("+tournamentID[0].replace(/\//g,"")+")"
	};
	
	/*Set section*/
	if(window.location.pathname.match('leaderboard')){
		pgt_metadata.section = ["leaderboard",tournamentName];
	}
	else if(tournamentID[0] == "/r470/" || tournamentID[0] == "/r473/" || tournamentID[0] == "/r476/" || tournamentID[0] == "/r489/"){
		pgt_metadata.section = ["World Golf Championships",tournamentName];
	}
	else{
		pgt_metadata.section = ["tournaments",tournamentName];
	}
}

/* CHARLES SCHWAB CUP */
else if(window.location.pathname.match('^/charlesschwabcup/.*/?')){
	var pgt_metadata = {
		section: ["tournament","Charles Schwab Cup"],
		template_type: "section front",
		content_type: "none",
		tour: "Champions Tour"
	};
}

/* SHOT TRACKER */
else if(window.location.pathname.match('^/shottracker/.*/?')){
	var pgt_metadata = {
		section: ["shot tracker",""],
		template_type: "interactive",
		content_type: "none",
		tour: "PGA Tour",
		tournament: CURRENT_TOUR_NAME
	};
}

/* INDIVIDUAL PLAYERS PAGE */
else if((window.location.pathname.match('^/players/.*/?')) && (window.location.pathname.indexOf('scorecards') == -1)) {
	var tourName = getTourName(tour);
	var pgt_metadata = {
		section: ["players",full_name+" ("+id_path.replace(/\//g,"")+")"],						
		template_type: "other",
		content_type: "none",
		tour: tourName,
		player: full_name+" ("+id_path.replace(/\//g,"")+")"
	};	
}

/* 2011 PLAYER PAGE REDESIGN - INDIVIDUAL PLAYERS PAGE */
else if((window.location.pathname.match('^/golfers/[0-9]{6}/.*/?'))) {
	var tourName = getTourName(tour);
	var pgt_metadata = {
		section: ["players",full_name+" ("+id_path.replace(/\//g,"")+")"],						
		template_type: "other",
		content_type: "none",
		tour: tourName,
		player: full_name+" ("+id_path.replace(/\//g,"")+")"
	};	
}

/* MAIN SCHEDULE PAGES AND MAIN PLAYER PAGES */
else if(window.location.pathname.match('^/[rsh]/schedule/.*/?') || window.location.pathname.match('^/[rsh]/players/.*/?')){
	var tournamentID = window.location.pathname.match('/[rsh]/');
	var tourName = getTourName(tournamentID[0].charAt(1));
	var pgt_metadata = {
		section: ["tournaments",""],
		template_type: "section front",
		content_type: "none",
		tour: tourName
	};	
	
	if(window.location.pathname.match('players')){
		pgt_metadata.section = ["players",""];
	}
	else{
		pgt_metadata.section = ["tournaments",""];
	}
}

/* 2011 PLAYER PAGE REDESIGN - PLAYER DIRECTORY PAGES */
else if(window.location.pathname.match('^/golfers/[-a-zA-Z]+[/|(/index.html)]?')){
	var tournamentID = '';
	if(window.location.pathname.match('pgatour')){
		tournamentID = 'r';
	}
	else if(window.location.pathname.match('champions-tour')){
		tournamentID = 's';
	}
	else if(window.location.pathname.match('nationwide-tour')){
		tournamentID = 'h';
	}
	var tourName = getTourName(tournamentID);
	var pgt_metadata = {
		section: ["players",""],
		template_type: "section front",
		content_type: "none",
		tour: tourName
	};
}

/* FEDEXCUP MAIN PAGES, AND SUB PAGES */
else if(window.location.pathname.match('^/fedexcup/.*/?')){
	var pgt_metadata = {
		section: ["fedexcup",""],
		template_type: "section front",
		content_type: "none",
		tour: "PGA Tour"
	};
	if(window.location.pathname.match('^/fedexcup/[a-zA-z0-9]+/.*/?')){
		var subSection = document.getElementById("tourStoryHeadline").firstChild.innerHTML;
		pgt_metadata.section = ["fedexcup",subSection];
		pgt_metadata.template_type = "other";
	}
}

/* VIDEO PAGES */
else if(window.location.pathname.match('^/video/(index.html)?$')){
	var pgt_metadata = {
		section: ["video",""],
		template_type: "video",
		content_type: "none",
		tour: "PGA Tour"
	};
}
else if(window.location.pathname.match('^/video/[rsh]/.*/?')){
	var tournamentID = window.location.pathname.match('/[rsh]/');
	var tourName = getTourName(tournamentID[0].charAt(1));
	/*var subSection = oVideoChannel.title;*/
	var pgt_metadata = {
		section: ["video",""],
		template_type: "video",
		content_type: "none",
		tour: tourName
	};	
	/*if(subSection){
		pgt_metadata.section = ["video",subSection];
	}*/
}
else if (window.location.pathname.match('/praxis')) {
	var videoPlayerConfigData;
	var omniSectionName = 'Praxis Video Player';
	var omniTour = '';
	var omniPID = '';
	var omniTID = '';

	try {
		videoPlayerConfigData = tourLeaderboardURL(); /*videoPlayerConfigData[1]=year, [2]=tournament, [3]=player*/
		if (videoPlayerConfigData.length != 4) { throw "InvalidArrayLengthException" }
		omniTour = videoPlayerConfigData[2].charAt(0);
		omniPID = videoPlayerConfigData[3];
		omniTID = videoPlayerConfigData[2];
	} 
	catch (e) {}

	var pgt_metadata = {
		section: ["video","omniSectionName"],
		template_type: "video",
		content_type: "none",
		tour: omniTour,
		tournament: omniTID,
		player: omniPID
	};
}

/* NEWS ARCHIVE PAGES */
/*else if(window.location.pathname.match('^/story/archive/[rsh]/./?')){
	var tournamentID = window.location.pathname.match('/[rsh]/');
	var tourName = getTourName(tournamentID[0].charAt(1));
	var pgt_metadata = {
		section: ["news",""],
		template_type: "section front",
		content_type: "none",
		tour: tourName
	};
}*/

/* ARTICLE PAGES */
else if(window.location.pathname.match('^/[0-9]{4}/.*/?') || window.location.pathname.match('^/[rsh]/[0-9]{4}.*/?')){
	var tournamentID = (window.location.pathname.match('/[rsh][0-9]{3}/')) ? window.location.pathname.match('/[rsh][0-9]{3}/') : window.location.pathname.match('/[rsh]/');
	var pgt_metadata = {
		section: ["news",PGAArticleTitle],
		template_type: "content",
		content_type: "article read",
		article: {
			title: PGAArticleTitle,
			date: PGAArticleDate,
			author: PGAArticleAuthor
		}
	};
	if(tournamentID != null){
		var tourName = getTourName(tournamentID[0].charAt(1));
		pgt_metadata.tour = tourName;
	}
}

/* MAIN STATS PAGE, INDIVIDUAL STATS SECTIONS, AND STATS SUB-SECTIONS PAGES */
else if(window.location.pathname.match('^/[rsh]/stats/.*/?')){	
	var tournamentID = window.location.pathname.match('/[rsh]/');
	var tourName = getTourName(tournamentID[0].charAt(1));
	var pgt_metadata = {
		section: ["stats",""],
		template_type: "section front",
		content_type: "none",
		tour: tourName
	};	
	
	if(window.location.pathname.match('^/[rsh]/stats/filter/.*/?')){
		var statsNum = window.location.search.match('[0-9]{1}');
		var statsSubSection = stats_reports_2[statsNum-1].title;
		pgt_metadata.section = ["stats",statsSubSection];
		pgt_metadata.template_type = "other";
		pgt_metadata.stats = statsSubSection;
	}
	else if(window.location.pathname.match('^/[rsh]/stats/info/.*/?')){
		var statsNum = window.location.search.match('[0-9]{3,5}');
		var statsSubSection = "";
		var statsAvail = "";
		for(a = 0; a < stats_reports_2.length; a++){
			for(b = 0; b < stats_reports_2[a].subCats.length; b++){
				for(c = 0; c < stats_reports_2[a].subCats[b].availStats.length; c++){
					if(statsNum == stats_reports_2[a].subCats[b].availStats[c].statID){
						statsSubSection = stats_reports_2[a].title;
						statsAvail = stats_reports_2[a].subCats[b].availStats[c].title;
						break;
					}
				}
			}
		}
		pgt_metadata.section = ["stats",statsSubSection];
		pgt_metadata.template_type = "other";
		pgt_metadata.stats = statsAvail;
	}
	else if(window.location.pathname.match('^/[rsh]/stats/current/.*/?')){
		pgt_metadata.section = ["stats","FedExCup Projected Points"];
		pgt_metadata.template_type = "other";
		pgt_metadata.stats = "FedExCup Projected Points";
	}
}

/* FANTASY */
else if(window.location.pathname.match('^/fantasy/.*/?')){
	var pgt_metadata = {
		section: ["fantasy",""],
		template_type: "section front",
		content_type: "none",
		tour: "PGA Tour"
	};
}

/* FANZONE */
else if(window.location.pathname.match('^/FanZone/.*/?')){
	var pgt_metadata = {
		section: ["fanzone",""],
		template_type: "section front",
		content_type: "none"
	};
	if(window.location.pathname.match('twitter')){
		pgt_metadata.section = ["fanzone","twitter"];
		pgt_metadata.template_type = "other";
	}
}

/* MULTIMEDIA PAGES */
else if(window.location.pathname.match('^/multimedia/.*/?')){
	var pgt_metadata = {
		section: ["multimedia",""],
		template_type: "other",
		content_type: "none"
	};
	var regex = new RegExp('^/multimedia/([a-z]+)/');
	var subSection = regex.exec(window.location.pathname);
	if(subSection != null){
		pgt_metadata.section = ["multimedia",subSection[1]];
	}
}

/* IPHONE AND ANDROID PAGES */
else if(window.location.pathname.match('^/iphone/$|^/android/$')){
	var subSection = window.location.pathname.replace(/\//g,"");
	var pgt_metadata = {
		section: ["multimedia",subSection],
		template_type: "other",
		content_type: "none"
	};
}

/* PHOTO PAGES */
else if(window.location.pathname.match('^/photos/')){	
	var pgt_metadata = {
		section: ["photos",""],
		template_type: "section front",
		content_type: "none"
	};
	if(window.location.search){
		var tournamentID = (window.location.search.match('/[rsh][0-9]{3}/')) ? window.location.search.match('/[rsh][0-9]{3}/') : window.location.search.match('/[rsh]/');
		var tourName = getTourName(tournamentID[0].charAt(1));
		pgt_metadata.section = ["photos",""];
		pgt_metadata.template_type = "other";
		pgt_metadata.tour = tourName;
	}
}

/* SEARCH */
/*else if(window.location.pathname.match('^/search/./?')){
	var pgt_metadata = {
		section: ["search",""],
		search: {
			number_results: searchDataObj.getTotalNumberResult(),
			article_number_results: searchDataObj.getArticleNumberResult(),
			video_number_results: searchDataObj.getVideoNumberResult(),
			audio_number_results: searchDataObj.getAudioNumberResult(),
			term: searchTerm
		},
		template_type: "search_results",
		content_type: "none"
	};	
}*/

/* TOURLIFE TRAVEL AND INSTRUCTION */
else if(window.location.pathname.match('^/tourlife/.*/?')){
	var pgt_metadata = {
		template_type: "section front",
		content_type: "none"
	};
	var regex = new RegExp('^/tourlife/(.+)/');
	var sectionName = regex.exec(window.location.pathname);
	pgt_metadata.section = [sectionName[1],""];
}

/* MEMBER SERVICES REGISTRATION AND LOGIN */
else if(window.location.pathname.match('^/member_services/.*/?')){
	var pgt_metadata = {
		section: ["member services",""],
		template_type: "other",
		content_type: "none"
	};
	if(window.location.pathname.match('registration.html')){
		pgt_metadata.section = ["member services","register"];
	}
	else if(window.location.pathname.match('login.html')){
		pgt_metadata.section = ["member services","login"];
	}
}

/* Q SCHOOL */
else if(window.location.pathname.match('^/qschool/.*/?')){
	var pgt_metadata = {
		section: ["Q School",""],
		template_type: "other",
		content_type: "none"
	};
	if(window.location.pathname.match('^/qschool/(index.html)*$')){
		pgt_metadata.template_type = "section front";
	}
	else if(window.location.pathname.match('leaderboard')){
		pgt_metadata.section = ["Q School","leaderboard"];
	}
}

/* LIVE PRESSER AND LIVE VIDEO */
else if(window.location.pathname.match('^/livepresser/.*/?|^/live-video/.*/?')){
	var pgt_metadata = {
		section: ["video",""],
		template_type: "video",
		content_type: "none"
	};
}

/* GAMES */
else if(window.location.pathname.match('^/games/.*/?')){
	var pgt_metadata = {
		section: ["games",""],
		template_type: "other",
		content_type: "none"
	};
}

/* TV TIMES */
else if(window.location.pathname.match('^/tv-times/.*/?')){
	var pgt_metadata = {
		section: ["tv times",""],
		template_type: "other",
		content_type: "none"
	};
}

/* KODAK CHALLENGE */
else if(window.location.pathname.match('^/kodakchallenge/.*/?')){
	var pgt_metadata = {
		section: ["kodak challenge",""],
		template_type: "other",
		content_type: "none"
	};
}

/* LIVE GOLF */
else if(window.location.pathname.match('^/livegolf/.*/?')){
	var pgt_metadata = {
		section: ["live golf",""],
		template_type: "other",
		content_type: "none"
	};
}

/* COMPANY PAGES */
else if(window.location.pathname.match('^/company/.*/?')){
	var pgt_metadata = {
		section: ["company",""],
		template_type: "other",
		content_type: "none"
	};
}

/* POLL SERVER */
else if(window.location.pathname.match('^/POLLSERVER/.*/?')){
	var pgt_metadata = {
		section: ["poll",""],
		template_type: "other",
		content_type: "none"
	};
}

/* NEW TOUR REPORT PAGE HOSTED ON THE PGATOUR.COM SERVER */
else if(window.location.pathname.match('^/tourreport/(index.html)?$')){
	var pgt_metadata = {
		section: ["tour report",""],
		template_type: "blog",
		content_type: "blog read"
	};
}

/* OTHER PAGES THAT DO NOT SATISFY ONE OF THE PRECEDING CONDITIONS */
else {
	if(!window.location.pathname.match('^/search/.*/?|^/story/archive/[rsh]/.*/?')){		
		var pgt_metadata = {
			section: ["other",""],
			template_type: "other",
			content_type: "none"
		};
	}
}

/* END PGA Tour, Champions Tour, and Nationwide Tour Sites */
