﻿/*  ##########################################################################
'	##########################################################################

' 	site_catalyst_utilities.js

'	Author(s)
'	Guy Whitfield, GW, guy.whitfield@akqa.com

' 	Copyright 2009 AKQA.  All rights reserved.

'   This is a small class for utility functions for use with Omniture Site Catalyst

	##########################################################################
	##########################################################################
*/

function trackLinkName(e) {
    //Convert click into crossbrowser JQuery event of type e
    var evn = new jQuery.Event(e);
        if(evn){ 
        var linkName = evn.type.lid;
        
        if (linkName){
	        s_objectID=linkName;
	        sc_trackLink(linkName);
	    }
	}	
}

/** @author James Head
 *
 * Utility method to fire of 'upsell banner impressions' tracking.
 * -- Drills in to class name to determine which products are shown in the side panel, and logs.
 * -- Special case code for the dual view banner for Movies & Sports packs.
 */
function trackSummaryUpSellBannerImpressions() {
    var upSells = $(".upsellContainer");
    for (var i = 0; i < upSells.length; i++) {
        var logString = upSells[i].className;
        logString = logString.replace("upsellContainer ", "");
        if (logString.indexOf("SportsMoviesDual") > -1) {
            logString = logString.replace("upsell", "upsell_SPORTS_");
        }
        sc_trackInternalAdView(logString);

        var dualPackTest = upSells[i].className;
        dualPackTest = dualPackTest.replace("upsellContainer ", "");
        if (dualPackTest == "upsellSportsMoviesDualLarge") {
            dualPackTest = dualPackTest.replace("upsell", "upsell_MOVIES_");
            sc_trackInternalAdView(dualPackTest);
        }
    }
}

/** @author James Head
* Logs a form submission error with site catalyst if the offer code looks invalid.
*/
function trackFormInvalidOfferCode() {
    var value = $('.offerCodeTextBox').get(0).value;
    if (!offerCodeLooksValid(value)) {
        s.sendFormEvent('e', s.pageName, 'OFFER_CODE', 'OFFER_CODE:INVALID:' + value);
    }
}

/** @author James Head
* helper method for offer code validation.
*/
function offerCodeLooksValid(value) {
    var regex = /^\w+$/
    return value.match(regex);
}