/* SiteCatalyst Helper Functions */

/* Account variable set in s_code.js */
function _scGetAccount() {
	return s_account;
}

/* Client-Side Form Error */
function _scTrackFormError(errorMessage) {

	var sc=s_gi(_scGetAccount());
	sc.prop6=sc.eVar6=s.prop6;
	sc.prop14=sc.eVar14=errorMessage;
	sc.events="event19";
	sc.t();
	sc.events="";
	sc.prop14=sc.eVar14="";
}

/* Client-Side Form Complete Event - requires s.prop6 set previously */
function _scTrackFormComplete(fieldValues) {

	if(s.prop6) {
		var sc=s_gi(_scGetAccount());
		sc.prop6=sc.eVar6=s.prop6;
		if(fieldValues){
			sc.prop20=sc.eVar20=fieldValues;
		}
		sc.events="event18";
		sc.t();
		sc.events="";
	}
}

/* Simultaneous Form Start and Complete */
function _scTrackFormStartComplete(fieldValues) {

	if(s.prop6) {
		var sc=s_gi(_scGetAccount());
		sc.prop6=sc.eVar6=s.prop6;
		if(fieldValues){
			sc.prop20=sc.eVar20=fieldValues;
		}
		sc.events="event17,event18";
		sc.t();
		sc.events="";
	}
}

function _scTrackMediaStart(videoName) {

	var sc=s_gi(_scGetAccount());
	sc.linkTrackVars="prop16,eVar16,prop21,eVar21,events";
	sc.linkTrackEvents="event14,event16";
	sc.prop16=sc.eVar16="click:media-start:"+videoName;
	sc.prop21=sc.eVar21=videoName;
	sc.events="event14,event16";
	sc.tl(document.URL,"o","click:media-start:"+videoName);
	sc.events="";
}

function _scTrackMediaComplete(videoName) {

	var sc=s_gi(_scGetAccount());
	sc.linkTrackVars="prop16,eVar16,prop21,eVar21,events";
	sc.linkTrackEvents="event15,event16";
	sc.prop16=sc.eVar16="click:media-complete:"+videoName;
	sc.prop21=sc.eVar21=videoName;
	sc.events="event15,event16";
	sc.tl(document.URL,"o","click:media-complete:"+videoName);
	sc.events="";
}

/* Generic Link Tracking */
function _scTrackClick(linkName) {

	var sc=s_gi(_scGetAccount());
	sc.linkTrackVars="prop16,eVar16,events";
	sc.linkTrackEvents="event16";
	sc.prop16=sc.eVar16="click:"+linkName;
	sc.events="event16";
	sc.tl(document.URL,"o","click:"+linkName);
	sc.events="";
}

/* Track Selection click */
function _scTrackSelection(linkName) {

	var sc=s_gi(_scGetAccount());
	sc.linkTrackVars="prop15,eVar15,events";
	sc.linkTrackEvents="event16";
	sc.prop15=sc.eVar15="click:"+linkName;
	sc.events="event16";
	sc.tl(document.URL,"o","click:"+linkName);
	sc.events="";
}

function _scTrackCoverageNeeded(itemList) {

	var sc=s_gi(_scGetAccount());
	sc.linkTrackVars="prop7,eVar7,events";
	sc.linkTrackEvents="event16";
	sc.prop7=sc.eVar7=itemList;
	sc.events="event16";
	sc.tl(document.URL,"o","click:"+itemList);
	sc.events="";
}

/* Assumes 1 new product view at a time */
function _scTrackProductViewed(prod1) {

	var sc=s_gi(_scGetAccount());
	sc.products=";"+prod1;
	sc.events="prodView,event4";
	sc.pageName=s.pageName;
	sc.t();
	sc.events="";
	sc.products="";
}


/* vpi - jteng */

/* track mailto clicks */
function _scTrackEmail(mailto) {
    _scTrackClick(mailto + '_' + s.pageName);
    window.open('mailto:' + mailto);
}

/* track page print */
function _scTrackPrint(page) {
    window.print();
    _scTrackClick('Print_' + page);
}

/* assuming jquery is in play : set up email tracking & print tracking*/
if (typeof $ == 'function' && typeof _scTrackEmail == 'function') {
    $(function() {
        $('a[href^=mailto]').each(function() {
            var oText = this.innerText;
            var obj = this.href.split(':');
            if (obj[1] != undefined && obj[1].length > 0) {
                this.href = 'javascript: _scTrackEmail(\'' + obj[1] + '\');';
                this.innerText = oText;
            }
        });
    });
}

if (typeof $ == 'function' && typeof _scTrackPrint == 'function') {
    $(function() {
        $('a[href*=window.print()]').each(function() {
            this.href = 'javascript: _scTrackPrint(s.pageName)';
        });
    });
}
