/*global s, window, document, namespace, setTimeout, WPOL */
/* Override any s_code.js default settings here */
s.currencyCode = "AUD";
/* Populate Site Specific Variables */
s.server = window.location.host;
s.prop1 = "SD";
s.prop2 = "Dir";
s.prop3 = "WP";
namespace('WPOL').OmnitureVariables = {
LINK_TRACK_VARS : 'linkTrackVars',
LINK_TRACK_EVENTS : 'linkTrackEvents',
PAGENAME : 'pageName',
EVENTS : 'events',
PROP26 : 'prop26',
PROP26 : 'prop26',
PROP37 : 'prop37',
PROP39 : 'prop39',
PROP40 : 'prop40',
EVAR23 : 'eVar23',
EVAR34 : 'eVar34',
EVAR36 : 'eVar36',
EVAR42 : 'eVar42',
EVAR46 : 'eVar46',
EVAR49 : 'eVar49'
};
/* End of SiteCatalyst Variables */
function create_new_tracker(s) {
var i, s_new = {};
for (i in s) {
if (s.hasOwnProperty(i)) {
s_new[i] = s[i];
}
}
s_new.referrer = window.location;
return s_new;
}
// Used to build the s.pageName and s.hier1 properties
function addValue(current, value, separator) {
if (value === null || value === undefined) {
return current;
}
return (current + separator + value);
}
// Constructs the full page name
function buildName(s) {
var pageName = addValue("", s.prop1, "");
pageName = addValue(pageName, s.prop2, ":");
pageName = addValue(pageName, s.prop3, ":");
pageName = addValue(pageName, s.channel, ":");
pageName = addValue(pageName, s.prop4, ":");
pageName = addValue(pageName, s.prop5, ":");
pageName = addValue(pageName, s.pageName, ":");
return pageName;
}
function sendOmnitureEvent(omnitureValues, element1, element2, element3) {
if (WPOL.flags.omnitureReady) {
var s_new = create_new_tracker(s);
for (var key in omnitureValues) {
if (omnitureValues.hasOwnProperty(key)) {
s_new[key] = omnitureValues[key];
}
}
if (omnitureValues[WPOL.OmnitureVariables.PAGENAME]) {
s_new[WPOL.OmnitureVariables.PAGENAME] = buildName(s_new);
}
s_new.tl(element1, element2, element3);
}
}
//Utility method, retrieves customer name from href element
function getSubscriberNameFromHrefElement(hrefElement) {
return hrefElement.name;
}
/* Site specific doPlugins functions */
function s_prePlugins(s) {
/* this gets run before standard doPlugins routines */
}
function s_postPlugins(s) {
/* this gets run after standard doPlugins routines */
}
// Constructs the hierarchy property
function buildHierarchy(s) {
var hierarchy = addValue("", s.prop1, "");
hierarchy = addValue(hierarchy, s.prop2, "|");
hierarchy = addValue(hierarchy, s.prop3, "|");
hierarchy = addValue(hierarchy, s.channel, "|");
hierarchy = addValue(hierarchy, s.prop4, "|");
hierarchy = addValue(hierarchy, s.prop5, "|");
return hierarchy;
}
// Used to post process the properties, after the page
// specific ones have been added
function postProcessProperties(s) {
s.eVar1 = s.prop1;
s.eVar2 = s.prop2;
s.eVar3 = s.prop3;
s.eVar4 = s.channel;
s.eVar5 = s.prop4;
s.eVar15 = s.prop5;
s.pageName = buildName(s);
s.hier1 = buildHierarchy(s);
}
// internal:  Call omniture to report tracking events
// These are overridden values that will replace the standard 's Object' property
function reportTrackingEvent(obj, s, subscriberName, eventName, eventType, eventDesc) {
var omnitureValues = [];
// link track vars tell omniture which eVar and sProp values to emit as parameters in the url submitted to Omniture
omnitureValues[WPOL.OmnitureVariables.LINK_TRACK_VARS] = 'prop26,eVar36,events,eVar37';
omnitureValues[WPOL.OmnitureVariables.LINK_TRACK_EVENTS] = eventName;
omnitureValues[WPOL.OmnitureVariables.EVENTS] = eventName;
omnitureValues[WPOL.OmnitureVariables.PROP26] = subscriberName;
omnitureValues[WPOL.OmnitureVariables.EVAR36] = subscriberName;
sendOmnitureEvent(omnitureValues, obj, eventType, eventDesc);
}
// internal:  Event reporting: email links
function reportEmailLink(obj, s, subscriberName, description) {
reportTrackingEvent(obj, s, subscriberName, "event42", "o", description);
}
// internal:  Event reporting: web-site links
function reportWebSiteLink(obj, s, subscriberName, description) {
reportTrackingEvent(obj, s, subscriberName, "event6", "e", description);
}
// internal:  Event handler: map links
function reportMapLink(obj, s, subscriberName, description) {
reportTrackingEvent(obj, s, subscriberName, "event8", "o", description);
}
// internal:  Event reporting: more info links
function reportMoreInfoLink(obj, s, subscriberName) {
reportTrackingEvent(obj, s, subscriberName, "event9", "o",
"Results More Info Link");
}
// internal:  Event reporting: HYC more info links
function reportHYCLink(obj, s, subscriberName) {
reportTrackingEvent(obj, s, subscriberName, "event15", "o", "HYC Link");
}
// internal:  Event reporting: show more link
function reportShowMoreLink(obj, s, subscriberName, description) {
reportTrackingEvent(obj, s, subscriberName, "event17", "o", description);
}
// external: Event handler: email links
function handleEmailLinkOnClick(s, hrefElement, description) {
reportEmailLink(hrefElement, s, getSubscriberNameFromHrefElement(hrefElement), description);
}
// external: Event handler: web-site links
function handleWebSiteLinkOnClick(s, hrefElement, description) {
reportWebSiteLink(hrefElement, s, getSubscriberNameFromHrefElement(hrefElement), description);
}
// external: Event handler: more-info links
function handleShowMoreLink(s, hrefElement, description) {
reportShowMoreLink(hrefElement, s, getSubscriberNameFromHrefElement(hrefElement), description);
}
// external: Event handler: map links
function handleMapLinkOnClick(s, hrefElement, description) {
reportMapLink(hrefElement, s, getSubscriberNameFromHrefElement(hrefElement), description);
}
// external: Event handler: share menu item links
function handleShareMenuItemClick(s, hrefElement, subscriberName) {
reportTrackingEvent(hrefElement, s, subscriberName, "event44", "o",
"Results Share Clicks");
}
// external: Event handler: digital contact links
function handleDigitalContactLinkClick(s, hrefElement, subscriberName, eventType, productType) {
var omnitureValues = [];
omnitureValues[WPOL.OmnitureVariables.LINK_TRACK_VARS] = 'eVar23,eVar36,eVar37,events';
omnitureValues[WPOL.OmnitureVariables.LINK_TRACK_EVENTS] = 'event26';
omnitureValues[WPOL.OmnitureVariables.EVENTS] = 'event26';
omnitureValues[WPOL.OmnitureVariables.EVAR36] = subscriberName;
omnitureValues[WPOL.OmnitureVariables.EVAR23] = eventType;
sendOmnitureEvent(omnitureValues, hrefElement, 'e', productType);
}
// internal: Event handler: thumbnail image clicks
function handleThumbnailImageClick(s, element, subscriberName, eventNumber, productType) {
var omnitureValues = [];
omnitureValues[WPOL.OmnitureVariables.LINK_TRACK_VARS] = 'eVar36,eVar37,events';
omnitureValues[WPOL.OmnitureVariables.LINK_TRACK_EVENTS] = eventNumber;
omnitureValues[WPOL.OmnitureVariables.EVENTS] = eventNumber;
omnitureValues[WPOL.OmnitureVariables.EVAR36] = subscriberName;
sendOmnitureEvent(omnitureValues, element, 'o', productType);
}
// internal: Event handler: WP image gallery thumbnail image clicks
function handleInternalThumbnailImageClick(s, element, subscriberName) {
handleThumbnailImageClick(s, element, subscriberName, 'event20', 'WP Image Gallery');
}
// internal: Event handler: Youtube thumbnail image clicks
function handleYoutubeThumbnailImageClick(s, element, subscriberName) {
handleThumbnailImageClick(s, element, subscriberName, 'event35', 'Youtube Video Gallery');
}
function handleSaveCookieListClick(element) {
sendOmnitureEvent([], element, 'o', 'Save Cookie List Clicks');
}
function handleClaimCookieListClick(element) {
sendOmnitureEvent([], element, 'o', 'Claim Cookie List');
}
// external: Event handler: addThis item links
function handleExternalShareMenuItemClick(s, hrefElement, subscriberName, description) {
reportTrackingEvent(hrefElement, s, subscriberName, "event44", "e", "Share Click - " + description);
}
// no longer needed?
function handleFeedbackFormSubmission(s, ratingText, who, initial, where, brgIndicator) {
function tildeIfBlank(value) {
return (!value || value.replace(/^\s+|\s+$/g, '').length === 0) ? "~" : value;
}
var omnitureValues = [];
omnitureValues[WPOL.OmnitureVariables.LINK_TRACK_VARS] = 'prop37,prop39';
omnitureValues[WPOL.OmnitureVariables.PROP37] =  brgIndicator + "_" + ratingText;
omnitureValues[WPOL.OmnitureVariables.PROP39] = (tildeIfBlank(who) + "_" + tildeIfBlank(initial) + "|" + tildeIfBlank(where));
sendOmnitureEvent(omnitureValues, this, "o", 'Guided Feedback Submit');
}
// external:
function handleLocationSuggestionLinkTracking(s, location) {
var omnitureValues = [];
omnitureValues[WPOL.OmnitureVariables.LINK_TRACK_VARS] = 'events,eVar42';
omnitureValues[WPOL.OmnitureVariables.LINK_TRACK_EVENTS] = 'event24';
omnitureValues[WPOL.OmnitureVariables.EVENTS] = "event24";
omnitureValues[WPOL.OmnitureVariables.EVAR42] =  location;
sendOmnitureEvent(omnitureValues, this, "o", 'Location Disambiguation Link');
}
// external:
function handleSearchSubmission(s, who, location) {
function tildeIfBlank(value) {
return (!value || value.replace(/^\s+|\s+$/g, '').length === 0) ? "~" : value;
}
var omnitureValues = [];
omnitureValues[WPOL.OmnitureVariables.LINK_TRACK_VARS] = 'events,prop39,prop40,eVar46,eVar49';
omnitureValues[WPOL.OmnitureVariables.LINK_TRACK_EVENTS] = "event29";
omnitureValues[WPOL.OmnitureVariables.EVENTS] = "event29";
omnitureValues[WPOL.OmnitureVariables.PROP39] = tildeIfBlank(who).toLowerCase();
omnitureValues[WPOL.OmnitureVariables.EVAR49] =  omnitureValues[WPOL.OmnitureVariables.PROP39];
omnitureValues[WPOL.OmnitureVariables.PROP40] =  tildeIfBlank(location).toLowerCase();
omnitureValues[WPOL.OmnitureVariables.EVAR46] =  omnitureValues[WPOL.OmnitureVariables.PROP40];
sendOmnitureEvent(omnitureValues, true, "o", 'Search Submit');
}
// NOTE: This is an on-click event that is supposed to look like a page load event, hence the call to .t() and postProcessProperties()
function handleAsPageLoadEventForOmniture(s, pageName, channel) {
var s_new = create_new_tracker(s);
s_new.pageName = pageName;
if (channel) {
s_new.channel = channel;
}
postProcessProperties(s_new);
s_new.t();
}
// external:
function handleSendToMobileTracking(s, subscriberName, pageName, event) {
var omnitureValues = [];
omnitureValues[WPOL.OmnitureVariables.LINK_TRACK_VARS] = "events,eVar36";
omnitureValues[WPOL.OmnitureVariables.LINK_TRACK_EVENTS] = event;
omnitureValues[WPOL.OmnitureVariables.EVENTS] = event;
omnitureValues[WPOL.OmnitureVariables.EVAR36] = subscriberName;
omnitureValues[WPOL.OmnitureVariables.PAGENAME] = pageName;
sendOmnitureEvent(omnitureValues, this, 'o', pageName);
}
// external:
function handleSendToMobileFormLoad(s, subscriberName) {
handleSendToMobileTracking(s, subscriberName, 'Send to Mobile Form', 'event39');
}
// external:
function handleSendToMobileSuccess(s, subscriberName) {
handleSendToMobileTracking(s, subscriberName, 'STM Success', 'event40');
}
// external:
function handleSendToMobileError(s, subscriberName) {
handleSendToMobileTracking(s, subscriberName, 'STM Error', 'event41');
}
// external:
function handleClickOnMyListListing(s, element, subscriberName) {
var omnitureValues = [];
omnitureValues[WPOL.OmnitureVariables.LINK_TRACK_VARS] = "events,eVar36,prop26";
omnitureValues[WPOL.OmnitureVariables.LINK_TRACK_EVENTS] = 'event11';
omnitureValues[WPOL.OmnitureVariables.EVENTS] = 'event11';
omnitureValues[WPOL.OmnitureVariables.EVAR36] = subscriberName;
omnitureValues[WPOL.OmnitureVariables.PROP26] = subscriberName;
sendOmnitureEvent(omnitureValues, element, 'o', 'My Listing Clicks');
}
function handleClickOnSendMyListButton(s, element) {
var omnitureValues = [];
omnitureValues[WPOL.OmnitureVariables.LINK_TRACK_VARS] = 'events';
omnitureValues[WPOL.OmnitureVariables.LINK_TRACK_EVENTS] = 'event12';
omnitureValues[WPOL.OmnitureVariables.EVENTS] = 'event12';
sendOmnitureEvent(omnitureValues, element, 'o', 'My Listing Email');
}
function handleClickOnAddToMyList(s, hrefElement, subscriberName) {
reportTrackingEvent(hrefElement, s, subscriberName, "event43", "o", "Add to My List Clicks");
}
function handleClickOnRecentSearch(s, element, label) {
var omnitureValues = [];
var eventName = label === 'Recent Locations' ? 'Recent Location Search Clicks' : 'Recent Name Search Clicks';
omnitureValues[WPOL.OmnitureVariables.LINK_TRACK_VARS] = 'events';
omnitureValues[WPOL.OmnitureVariables.LINK_TRACK_EVENTS] = 'event32';
omnitureValues[WPOL.OmnitureVariables.EVENTS] = 'event32';
sendOmnitureEvent(omnitureValues, element, 'o', eventName);
}

