/****************************************************
		PGA.com Drupal Omniture Implementation
	This file is responsible for appending data about the page to the necessary Omniture variables.
	The code will live as an include inside of the s_code.js provided by Omniture.

********************************************************/

/*****A LIST OF CHANNELS*************

Homepage *
News & Events *
Courses *
Instruction *
Equipment *
Travel *

*****END: A LIST OF CHANNELS****************/


// When this function is called, the page data that is stored is set to the Omniture variables.
function populateMetricsData() {

	// page's full URL
	var fullURL = window.location.href;

	var pathname = window.location.pathname;
	var url_pieces = pathname.split('/');
	var yearx;
	// if a better solution is known to this big, ugly block of code below, please implement
	if(fullURL.indexOf('2000') >= 0){yearx = 2000;}
	else if(fullURL.indexOf('2001') >= 0){yearx = 2001;}
	else if(fullURL.indexOf('2002') >= 0){yearx = 2002;}
	else if(fullURL.indexOf('2003') >= 0){yearx = 2003;}
	else if(fullURL.indexOf('2004') >= 0){yearx = 2004;}
	else if(fullURL.indexOf('2005') >= 0){yearx = 2005;}
	else if(fullURL.indexOf('2006') >= 0){yearx = 2006;}
	else if(fullURL.indexOf('2007') >= 0){yearx = 2007;}
	else if(fullURL.indexOf('2008') >= 0){yearx = 2008;}
	else if(fullURL.indexOf('2009') >= 0){yearx = 2009;}
	else if(fullURL.indexOf('2010') >= 0){yearx = 2010;}
	else if(fullURL.indexOf('2011') >= 0){yearx = 2011;}
	else if(fullURL.indexOf('2012') >= 0){yearx = 2012;}
	else if(fullURL.indexOf('2013') >= 0){yearx = 2013;}
	else if(fullURL.indexOf('2014') >= 0){yearx = 2014;}
	else if(fullURL.indexOf('2015') >= 0){yearx = 2015;}
	else if(fullURL.indexOf('2016') >= 0){yearx = 2016;}
	else if(fullURL.indexOf('2017') >= 0){yearx = 2017;}
	else if(fullURL.indexOf('2018') >= 0){yearx = 2018;}
	else if(fullURL.indexOf('2019') >= 0){yearx = 2019;}
	else if(fullURL.indexOf('2020') >= 0){yearx = 2020;}

	// prepares the URL to be parsed
	// PGA main site path name code. Also strips dev environment-specific paths from the path name.
	// var micro is set up to account for each individual micro site
	if (fullURL.indexOf('/pga/') >= 0) {
		var pn = window.location.pathname.replace('pga/',''); // strip the /pga/ from the front.
		var micro = '';
	} else if (fullURL.indexOf('/pga_ph2/') >= 0) {
		var pn = window.location.pathname.replace('pga_ph2/',''); // strip the /pga_ph2/ from the front.
		var micro = '';
	// PGA Championship path name code
	} else if (fullURL.indexOf('/pgachampionship/') >= 0) {
		var pn = window.location.pathname.replace('pgachampionship/' + yearx + '/','');
		var micro = 'pga championship - ' + url_pieces[2] + ' - ';
		s.prop5 = 'pga championship - ' + url_pieces[2];
		s.prop8 = 'pga championship';
	// Ryder Cup path name code
	} else if (hostName == 'www.rydercup.com' || hostName == 'authoring.rydercup.com') {
		if (fullURL.indexOf('/europe/') >= 0) {
			var pn = window.location.pathname.replace(yearx + '/europe/','');
		} else if (fullURL.indexOf('/usa/') >= 0) {
			var pn = window.location.pathname.replace(yearx + '/usa/','');
		} else {
			var pn = window.location.pathname.replace(yearx + '/','');
		}
		var micro = 'ryder cup - ' + url_pieces[1] + ' - ' + url_pieces[2] + ' - ';
		s.prop5 = 'ryder cup - ' + url_pieces[1] + ' - ' + url_pieces[2];
		s.prop8 = 'ryder cup';
	// Senior PGA path name code
	} else if (fullURL.indexOf('/seniorpga/') >= 0) {
		var pn = window.location.pathname.replace('seniorpga/' + yearx + '/','');
		var micro = 'senior pga - ' + url_pieces[2] + ' - ';
		s.prop5 = 'senior pga - ' + url_pieces[2];
		s.prop8 = 'senior pga';
	// Grand Slam path name code
	} else if (fullURL.indexOf('/grandslam/') >= 0) {
		var pn = window.location.pathname.replace('grandslam/' + yearx + '/','');
		var micro = 'grand slam - ' + url_pieces[2] + ' - ';
		s.prop5 = 'grand slam - ' + url_pieces[2];
		s.prop8 = 'grand slam';
	// Open Championship path name code
	} else if (fullURL.indexOf('/openchampionship/') >= 0) {
		var pn = window.location.pathname.replace('openchampionship/' + yearx + '/','');
		var micro = 'open championship - ' + url_pieces[2] + ' - ';
		s.prop5 = 'open championship - ' + url_pieces[2];
		s.prop8 = 'open championship';
	// Merchandise path name code
	} else if (fullURL.indexOf('/merchandise/') >= 0) {
		var pn = window.location.pathname.replace('merchandise/' + yearx + '/','');
		var micro = 'merchandise - ' + url_pieces[2] + ' - ';
		s.prop5 = 'merchandise - ' + url_pieces[2];
		s.prop8 = 'merchandise';
	// National Championship path name code
	} else if (fullURL.indexOf('/nationalchampionship/') >= 0) {
		var pn = window.location.pathname.replace('nationalchampionship/' + yearx + '/','');
		var micro = 'national championship - ' + url_pieces[2] + ' - ';
		s.prop5 = 'national championship - ' + url_pieces[2];
		s.prop8 = 'national championship';
	// Teach and Coaching Summit path name code
	} else if (fullURL.indexOf('/summit/') >= 0) {
		var pn = window.location.pathname.replace('summit/' + yearx + '/','');
		var micro = 'summit - ' + url_pieces[2] + ' - ';
		s.prop5 = 'summit - ' + url_pieces[2];
		s.prop8 = 'summit';
	// All other cases
	} else {
		var pn = window.location.pathname;
		var micro = '';
	}
	// query sting
	var qs = window.location.search.substring(1);
	// hash
	var lh = window.location.hash.substring(1);

	var urlParams = getUrlVars();

	//s.server = eVar29 : Site Domain
	s.server = hostName.replace("www.","").replace("drupalp1pgadev1.","").replace("drupalp1pgaint1.","").replace("devauthoring.","").replace("authoring.","");
	
	// establish path_array
	// strip the .cfm extension from the PGA microsites path_array
	var path_array = pn.substring(1).replace('index','').replace('.php','').replace('.cfm','').split('/');
	
	//event26 : Page Views
	s.events = "event26";

	// Default to Homepage values
	s.pageName = '';
	s.channel = 'home';
	
	// prop32 code mixed in with s.channel
	/*
		Page Type Values:
		video ('v')
		blog ('b')
		game ('g')
		interactive ('it')
		content ('c')
		index ('in')
		ecom ('e')
		signup ('s')
		section front ('sf')
		other ('o')
	*/
	// set up s.channel
	var chn = '';
	switch(path_array[0]) {
		case '':
			chn = micro + 'home';
			if (document.title.indexOf('PGA.com') >= 0) {
				s.prop32 = 'index';
			} else {
				s.prop32 = 'section front';
			}
			break;
		case 'index':
		case 'home':
			chn = micro + 'home';
			s.prop32 = 'index';
			break;
		// news is also a part of many of the PGA Microsites
		case 'news': 
			chn = micro + 'news';
			if (path_array[1]){
				s.prop32 = 'content';
			} else {
				s.prop32 = 'section front';
			}
			break;
		case 'golf-courses': 
			chn = micro + 'courses';
			if (path_array[1]){
				s.prop32 = 'content';
			} else if (path_array[1] == 'worlds-most-beautiful-courses' && !path_array[2] ||
						path_array[1] == 'details') {
				s.prop32 = 'other';
			} else if (path_array[1] == 'search') {
				s.prop32 = 'search';
			} else {
				s.prop32 = 'section front';
			}
			break;
		case 'golf-equipment':
			chn = micro + 'equipment';
			if (!path_array[1]){
				s.prop32 = 'section front';
			} else if (path_array[1] == 'feature' ||
						path_array[1] == 'brand' ||
						path_array[1] == 'type'){
				s.prop32 = 'content';
			} else if (path_array[1] == 'search'){
				s.prop32 = 'search';
			} else {
				s.prop32 = 'video';
			}
			break;
		case 'golf-instruction':
			chn = micro + 'instruction';
			if(path_array[1] == 'feature' ||
				path_array[1] == 'golf-101' ||
				path_array[1] == 'golf-glossary' ||
				path_array[1] == 'golf-etiquette'){
				s.prop32 = 'content';
			} else if (path_array[1] == 'find-instructor'){
				s.prop32 = 'search';
			} else if (!path_array[1]){
				s.prop32 = 'section front';
			} else {
				s.prop32 = 'video';
			}
			break;
		case 'golf-travel': 
			chn = micro + 'travel';
			s.prop32 = 'content';
			break;
		case 'pga-america': 
			chn = micro + 'pga of america';
			if (path_array[1] == 'find-professionals') {
				s.prop32 = 'search';
			} else {
				s.prop32 = 'content';
			}
			break;
		case 'user':
			chn = micro + 'no section available';
			s.prop32 = 'signup';
			break;
		case 'users':
			chn = micro + 'no section available';
			s.prop32 = 'other';
			break;
		case 'professionals':
			chn = micro + 'instruction';
			s.prop32 = 'other';
			break;
		case 'about':
			chn = micro + 'about';
			s.prop32 = 'content';
			break;
		case 'search':
			chn = micro + 'search';
			s.prop32 = 'search';
			break;
		/* ****************************************
		***Begin PGA Microsite specific channels***
		***************************************** */
		case 'players':
			chn = micro + 'players';
			if (path_array[1]){
				s.prop32 = 'content';
			} else if (path_array[1] == 'index') {
				s.prop32 = 'section front';
			}
			break;
		case 'scoring':
			chn = micro + 'scoring';
			if (path_array[1]){
				s.prop32 = 'other';
			} else if (path_array[1] == 'index') {
				s.prop32 = 'section front';
			}
			break;
		case 'multimedia':
			chn = micro + 'multimedia';
			if (path_array[1] == 'photo'){
				s.prop32 = 'content';
			} else if (path_array[1] == 'video' ||
						path_array[1] == '3d'){
				s.prop32 = 'video';
			} else if (path_array[1] == 'index') {
				s.prop32 = 'section front';
			}
			break;
		case 'course':
			chn = micro + 'course';
			if (path_array[1]){
				s.prop32 = 'content';
			} else if (path_array[1] == 'tour') {
				s.prop32 = 'other';
			} else if (path_array[1] == 'index') {
				s.prop32 = 'section front';
			}
			break;
		case 'event':
			chn = micro + 'event';
			if (path_array[1]){
				s.prop32 = 'content';
			} else if (path_array[1] == 'index') {
				s.prop32 = 'section front';
			}
			break;
		case 'history':
			chn = micro + 'history';
			if (path_array[1]){
				s.prop32 = 'content';
			} else if (path_array[1] == 'past_winners') {
				s.prop32 = 'other'
			} else if (path_array[1] == 'index') {
				s.prop32 = 'section front';
			}
			break;
		case 'contact':
			chn = micro + 'contact';
			if (path_array[1]){
				s.prop32 = 'other';
			} else if (path_array[1] == 'index') {
				s.prop32 = 'section front';
			}
			break;
		case 'mobile':
			chn = micro + 'mobile';
			if (path_array[1]){
				s.prop32 = 'content';
			} else if (path_array[1] == 'index') {
				s.prop32 = 'section front';
			}
			break;
		case 'hospitality':
			chn = micro + 'hospitality';
			if (path_array[1]){
				s.prop32 = 'content';
			} else if (path_array[1] == 'index') {
				s.prop32 = 'section front';
			}
			break;
		/* ****************************************
		****End PGA Microsite specific channels****
		***************************************** */
		default:
			chn = 'no section available';
	} //end switch for channel
	s.channel = chn;

	// Set Level 2 Site Section Variable - s.prop28
	var p28 = '';
	if(path_array[1] != null) {
		switch(path_array[1]) {
			case 'balls-apparel':
				p28 = 'balls and apparel';
				break;
			case 'details':
				p28 = 'browse by state';
				break;
			case 'drivers-woods':
				p28 = 'drivers';
				break;
			case 'find-instructor':
				p28 = 'instructor';
				break;
			case 'golf-tv-schedule':
				p28 = 'golf on tv';
				break;
			case 'irons-hybrids':
				p28 = 'irons';
				break;
			case 'brand':
				p28 = 'brand';
				break;
			case 'type':
				p28 = 'type';
				break;
			case 'training-technology':
				p28 = 'training and techonology';
				break;
			case 'worlds-most-beautiful-courses':
				p28 = 'beautiful courses';
				break;
			case 'leaders':
				p28 = 'leaders';
				break;
			case 'apprentice-assistant-professional':
				p28 = 'apprentice assistant professional';
				break;
			case 'juniors':
				p28 = 'juniors';
				break;
			case 'hospitality':
				p28 = 'hospitality';
				break;
			case 'advisory':
				p28 = 'advisory';
				break;
			case 'contests-promotions':
				p28 = 'contests promotions';
				break;
			case 'terms':
				p28 = 'terms of use';
				break;
			case 'privacy':
				p28 = 'privacy policy';
				break;
			case 'mobile':
				p28 = 'mobile';
				break;
			/* ********************************************
			***Begin PGA Microsite specific sub-channels***
			********************************************* */
			case 'photo':
				p28 = 'photo';
				break;
			case 'video':
				p28 = 'video';
				break;
			case 'tour':
				p28 = 'tour';
				break;
			case 'iphone':
				p28 = 'iphone';
				break;
			/* ********************************************
			****End PGA Microsite specific sub-channels****
			********************************************* */
			default:
				p28 = 'no sub-section available';
		} //end switch
		s.prop28 = p28;
	} else {
		s.prop28 = p28 = 'no sub-section available';
	}//end Level 2 Site Section

	// Handle Searches. We only count everything if the search is a new search, if it is a pagination then we only count s.prop1
	// path_array[0] = 'search' means that we are using site search!
	// (path_array[0] == 'golf-courses' && path_array[1] == 'search') means we are using course search
	if ((path_array[0] == 'search') ||
		(path_array[0] == 'golf-courses' && path_array[1] == 'search' && fullURL.indexOf('?') >= 0) ||
		(path_array[0] == 'golf-instruction' && path_array[1] == 'find-instructor' && fullURL.indexOf('?') >= 0)  ||
		(path_array[0] == 'golf-instruction' && path_array[1] == 'search' && fullURL.indexOf('?') >= 0) ||
		(path_array[0] == 'golf-equipment' && path_array[1] == 'search' && fullURL.indexOf('?') >= 0) ||
		(path_array[0] == 'pga-america' && path_array[1] == 'find-professionals' && fullURL.indexOf('?') >= 0)) {

		if (urlParams['page'] != null) {
			s.prop1 = ((urlParams['page']*1)+1);
		} else {
			s.prop1 = 1; // Search Results Page
		}
		
		// track # of Search Results
		// prop27 : # Search Results
		var s_count = document.getElementById('search_count');
		if (fullURL.indexOf('apachesolr_search') >= 0) {
			if (s_count) {
				var strSearchCount = s_count.innerHTML;
				var strSearchCount2 = strSearchCount.split('of '); 
				var strSearchCount3 = strSearchCount2[1].split('results');
				s.prop27 = strSearchCount3[0];
			} else { 
				s.prop27 = 'zero';
			}
		} else if (fullURL.indexOf('search') >= 0 ||
					fullURL.indexOf('find-instructor') >= 0 ||
					fullURL.indexOf('find-professionals') >= 0 ||
					(fullURL.indexOf('golf-equipment') >= 0 && fullURL.indexOf('search') >= 0)){
			if (s_count) {
				var strSearchCount = s_count.innerHTML;
				if (strSearchCount.indexOf('of') >= 0){
					var strSearchCount2 = strSearchCount.split('of '); 
					var strSearchCount3 = strSearchCount2[1].split(')');
					s.prop27 = strSearchCount3[0];
				} else {
					s.prop27 = 'zero';
				}
			} else { 
				s.prop27 = 'zero';
			}
		}// End prop27 code

		s.events = s.events + ',event27'; // Internal Searches

		if (path_array[0] == 'search') {
			s.prop2 = 'site search'; // Search Type
			if (document.getElementById('edit-keys')){
				var search_field = document.getElementById('edit-keys');
				s.prop39 = search_field.getAttribute('value').replace('+',' ').toLowerCase();
			}
		} else {
			s.prop2 = 'course search'; // Search Type
			s.prop39 = (urlParams['searchbox'] ? urlParams['searchbox'].replace('+',' ').toLowerCase() : urlParams['search'].replace('+',' ').toLowerCase()) // Internal Search Terms
			// if the search is 'instructor search' or 'equipment search', then prop3 does not get set
			if (path_array[1] == 'find-instructor' ||
				(path_array[0] == 'golf-equipment' && path_array[1] == 'search') ||
				path_array[1] == 'find-professionals'){

			} else {
				s.prop3 = ''+urlParams['distance']+':'+urlParams['price_range']+':'+urlParams['course_type']; // Search Filters
				s.prop3 += (urlParams['has_professional'])?':1':':0';
			}// end prop3 conditional
		}
		
		if ((path_array[0] == 'golf-instruction' && path_array[1] == 'find-instructor') ||
			(path_array[0] == 'pga-america' && path_array[1] == 'find-professionals')) {
			s.prop2 = 'instructor search'; // Search Type
		} else if (path_array[0] == 'golf-instruction' && path_array[1] == 'search') {
			s.prop2 = 'video instruction search'; // Search Type
			// Checks to see if 'edit-search' exists and gets the value out of the field
			if (document.getElementById('edit-search')) {
				var search_bar = document.getElementById('edit-search');
				s.prop39 = search_bar.getAttribute('value').replace('+',' ').toLowerCase();
			}
			// Identifies the selected option in the 'Problem Area' search option
			if (document.getElementById('edit-tid')) {
				var problem_area = document.getElementById('edit-tid');
				var selection = problem_area.selectedIndex;
				var options = problem_area.getElementsByTagName('option');
				s.prop3 = options[selection].innerHTML.replace('&lt;','<').replace('&gt;','>').replace('&amp;','&');
			}
		} else if (path_array[0] == 'golf-equipment') {
			s.prop2 = 'equipment search'; // Search Type
		}
		s.prop32 = 'search'; // override prop32 code to change to search
	} // Search Page

	// Handle User Course Review
	if ((path_array[0] == 'golf-courses' && path_array[1] == 'details')) {
		// If there is a hash, then we are skipping the call to s.t()
		if (lh) {
			s.logThis = false;
		}
	} // User Course Review

	// Trip for User Sign up
	if ((path_array[0] == 'user' && path_array[1] == 'register')) {
		// Change the page type.
		s.prop32 = 'signup';
	} // User Sign up


	//////////////////////////////
	// Start Jason's added code //
	//////////////////////////////

	//s.pageType : Pages Not Found
	if (document.title.indexOf("Page not found") >= 0) {
		s.pageType = "errorPage";
	}

	//prop26 : URL
	s.prop26 = fullURL.split("?");
	var queryStr = s.prop26[1];
	var prop26_aid = s.prop26[0].replace("http://","");
	s.prop26 = prop26_aid.replace(".cfm","");

	// additional code for prop32: Page Type
	var typePage = "";
	switch(s.prop32) {
		case "video":
			typePage = "v";
			break;
		case "blog":
			typePage = "b";
			break;
		case "game":
			typePage = "g";
			break;
		case "interactive":
			typePage = "it";
			break;
		case "content":
			typePage = "c";
			break;
		case "index":
			typePage = "in";
			break;
		case "ecom":
			typePage = "e";
			break;
		case "signup":
			typePage = "s";
			break;
		case "search":
			typePage = "se";
			break;
		case "section front":
			typePage = "sf";
			break;
		default:
			typePage = "o";
	}
	
	var buzUnitCode = "pga";
	s.prop30 = buzUnitCode;
	if (s.pageType) {
		buzUnitCode = "404:" + buzUnitCode;
	}
	var buc_p32 = buzUnitCode + ":" + typePage;
	//find third level domain
	var allDomainLevels = hostName.split(".");
	var currentDomainLevel = allDomainLevels.length - 3;
	var thirdLevelDomain = (currentDomainLevel >= 0 ? allDomainLevels[currentDomainLevel] : "");
	// if the domain is ryder cup, replace the third level domain with ryder cup
	thirdLevelDomain = (fullURL.indexOf("rydercup") >= 0 ? "rydercup" : thirdLevelDomain.replace("www",""));
	//if s.pageName has more than 100 char, use only 5 first char of 3rd level domain
	//if s.pageName still has more than 100 char, truncate from the beginning of pathname
	if (thirdLevelDomain == "") {
		var pageNameLen = buc_p32.length + 2 + pathname.length;
		if (pageNameLen <= 100) {
			s.pageName = buc_p32 + ":" + pathname;
			// (fullURL.indexOf('rydercup') >= 0 ? "ryder cup" : "") + ":" + 
		} else {
			var r_len = pageNameLen - 100;
			s.pageName = buc_p32 + ":" + pathname.substring(r_len);
		}
	} else {
		var pageNameLen = buc_p32.length + 1 + thirdLevelDomain.length + 2 + pathname.length;
		if (pageNameLen <= 100) {
			s.pageName = buc_p32 + ":" + thirdLevelDomain + ":" + pathname;
		} else {
			if (thirdLevelDomain.length <= 5) {
				var r_len = pageNameLen - 100;
				s.pageName = buc_p32 + ":" + thirdLevelDomain + ":" + pathname.substring(r_len);
			} else {
				thirdLevelDomain = thirdLevelDomain.substring(0,5);
				pageNameLen = buc_p32.length + 1 + thirdLevelDomain.length + 2 + pathname.length;
				if (pageNameLen <= 100) {
					s.pageName = buc_p32 + ":" + thirdLevelDomain + ":" + pathname;
				} else {
					var r_len = pageNameLen - 100;
					s.pageName = buc_p32 + ":" + thirdLevelDomain + ":" + pathname.substring(r_len);
				}
			}
		}
	}

	if (s.pageType == 'errorPage') {
		s.pageName = "404:" + fullURL;
	}
	
	s.pageName = s.pageName.replace("index","").replace(".cfm","").replace(".php","");

	if (micro == null){
		//prop34 = eVar34 : Authentication State
		/*
		s.prop34="anonymous"
		s.prop34="reg:not logged in"
		s.prop34="reg:logged in"
		*/
		s.prop34 = "anonymous";
		//check for isRegistered cookie
		var regCookie = getCookie("isRegistered");
		if (regCookie != null && regCookie != "") {
			if (regCookie == 1) {
				s.prop34 = "reg:not logged in";
				// name, value, expires, path, domain, secure
				setCookie("isRegistered",1,365,"/",".pga.com","");
			}
		}

		//check for is_logged_in cookie
		var loginCookie = getCookie("is_logged_in");
		if (loginCookie != null && loginCookie != "") {
			if (loginCookie == "TRUE") {
				s.prop34 = "reg:logged in";
				// name, value, expires, path, domain, secure
				setCookie("isRegistered",1,365,"/",".pga.com","");
			}
		}
	}

	function setCookie(name, value, expires, path, domain, secure){
		// set time, it's in milliseconds
		var today = new Date();
		today.setTime(today.getTime());
		/*
		if the expires variable is set, make the correct
		expires time, the current script below will set
		it for x number of days, to make it for hours,
		delete * 24, for minutes, delete * 60 * 24
		*/
		if (expires){
			expires = expires * 1000 * 60 * 60 * 24;
		}
		var expires_date = new Date(today.getTime() + (expires));
		document.cookie = name + "=" +escape( value ) +
		((expires) ? ";expires=" + expires_date.toGMTString() : "") +
		((path) ? ";path=" + path : "") +
		((domain) ? ";domain=" + domain : "") +
		((secure) ? ";secure" : "");
	}

	//custom function: get a cookie variable
	function getCookie(c_name) {
		if (document.cookie.length > 0) {
			c_start = document.cookie.indexOf(c_name + "=");
			if (c_start != -1) {
				c_start = c_start + c_name.length + 1;
				c_end = document.cookie.indexOf(";",c_start);
				if (c_end == -1) {
					c_end = document.cookie.length;
				}
				return unescape(document.cookie.substring(c_start,c_end));
			}
		}
		return "";
	}

	//event28 : Registration
	if (document.referrer.indexOf("/user/register") >= 0 && s.prop34 == "reg:logged in") {
		s.events = s.events + ",event28";
	}

	//event37 : Login
	if (document.referrer.indexOf("/user/login") >= 0 && s.prop34 == "reg:logged in") {
		s.events = s.events + ",event37";
	}

	//prop36 : Registration Age and Zip Code
	if (typeof(Drupal) == 'undefined'){

	} else {
		if (Drupal.settings.user_info != null && Drupal.settings.user_info.profile_zip != null && Drupal.settings.user_info.profile_birthday != null) {
			var zip = Drupal.settings.user_info.profile_zip;
			var bday_day = Drupal.settings.user_info.profile_birthday.day;
			var bday_month = Drupal.settings.user_info.profile_birthday.month;
			var bday_year = Drupal.settings.user_info.profile_birthday.year;
			var d = new Date();
			var current_day = d.getDate();
			var current_month = d.getMonth();
			var current_year = d.getFullYear();
			
			if (current_month - bday_month > 0) {
				s.prop36 = current_year - bday_year + "|N/A|" + zip;
			} else if (current_month - bday_month == 0) {
				if (current_day - bday_day >= 0) {
					s.prop36 = current_year - bday_year + "|N/A|" + zip;
				} else {
					s.prop36 = current_year - bday_year - 1 + "|N/A|" + zip;
				}
			} else {
				s.prop36 = current_year - bday_year - 1 + "|N/A|" + zip;
			}
		}
	}

	/////////////////////////////////////////////
	// Start the mapping
	/////////////////////////////////////////////

	// Process the hierarchy
	s.hier1 = 'sports|pga|' + s.prop30 + '|' + s.server + ((s.channel)?'|'+s.channel:'') + ((s.prop28)?'|'+s.prop28:''); //Site Hierarchy
	// sports | pga | pga | pga.com | site section level 1 | site section level 2
	// pga.com will likely have to be made dynamic (not hard-coded) to account for micro-sites
	// site section level 1 is s.channel
	// site section level 2 is s.prop28

	// Mirrored Variables
	s.eVar1 = s.prop1;
	s.eVar2 = s.prop2;
	s.eVar3 = s.prop3;
	s.eVar4 = s.prop4;
	s.eVar5 = s.prop5;
	s.eVar8 = s.prop8;
	s.eVar26 = s.pageName; 
	s.eVar27 = s.channel; 
	s.eVar29 = s.server; 
	s.eVar28 = s.prop28; 
	s.eVar30 = s.prop30; 
	s.eVar32 = s.prop32;
	s.eVar34 = s.prop34; 
	s.eVar36 = s.prop36; 
	s.eVar38 = s.prop38; 
	s.eVar39 = s.prop39;
	s.eVar40 = s.prop40; 
	s.eVar41 = s.prop29;
}

/*******************************/
/* John's Custom Functions.
/*******************************/


// Modified SuperTab function
var stab = 0;
function omniture_HandleSuperTab(event){
	var s=s_gi(s_account);
	s.linkTrackVars='events,prop4,eVar4';
	s.linkTrackEvents='event3';
	s.events = 'event3'
	s.prop4=s.eVar4=event.data.tab.toLowerCase();
	s.tl(this,'o', 'super-t tab click');

}

function omniture_HandleCourseReview(theCourse) {
	var s=s_gi(s_account);
	s.linkTrackVars='events,eVar2';
	s.linkTrackEvents = s.events = 'event1'
	s.eVar2=theCourse.toLowerCase();
	s.tl(this,'o', 'course review');
}

function getUrlVars() {
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}

jQuery(function($){
	// captures every link in the super tabs div and applies the omniture_HandleSuperTab function to it.
	function omniture_AddSuperTabOnClicks() {
		if (document.getElementById("quicktabs-3")){
			var super_tabs = document.getElementById("quicktabs-3").firstChild;
			var super_tabs_links = super_tabs.getElementsByTagName("a");
			for (var x = 0; x < super_tabs_links.length; x++){
				var super_tab = super_tabs_links[x].innerHTML;
				
				$('#quicktabs-tab-3-'+x).bind('click', {tab: super_tab}, omniture_HandleSuperTab);
			}
		}
	}
	
	omniture_AddSuperTabOnClicks();
});

