/********************************************************************************/
/* SiteCatalyst code version: H.20.3.                                                                                                          */
/* Copyright 1997-2009 Omniture, Inc. More info available at                                                                      */
/* http://www.omniture.com                                                                                                                       */
/********************************************************************************/

//Updated 2/10/11 - Removed domains from dynamic account selection since new DB Vista rule will be taking care of report suite routing based on domain. The dynamic account list is still used to route traffic to the devtyco report suite for the QA and DEV servers.


//Updated 11/4/10 - Removed historic report suites in dyanamic account list, and added file download extensions

// Setting the page name to the URL - it is all we have at this point
s.pageName = document.title
var TE_pageRe = new RegExp("^(.+) - Tyco Electronics$","ig");
 // check the page name to see if it ends with Tyco Electronics
if (TE_pageRe.test(s.pageName))
{
	// matched, so now replace s_pageName with just the value at the begining
	s.pageName=s.pageName.replace(TE_pageRe, "$1");
}
 TE_pageRe = new RegExp("^(.+) - TE$","ig");
 // check the page name to see if it ends with TE
if (TE_pageRe.test(s.pageName))
{
	// matched, so now replace s_pageName with just the value at the begining
	s.pageName=s.pageName.replace(TE_pageRe, "$1");
}
s.server=""
s.channel=""
s.pageType=""
s.prop1=""
s.prop2=""
s.prop3=""
s.prop4=""
s.prop5=""
/* Conversion Variables */
s.campaign=""
s.state=""
s.zip=""
s.events=""
s.products=""
s.purchaseID=""
s.eVar1=""
s.eVar2=""
s.eVar3=""
s.eVar4=""
s.eVar5=""
s.eVar7=""

/************************** CONFIG SECTION **************************/
/* You may add or alter any code config here. */
s.charSet="UTF-8"
/* Conversion Config */
s.currencyCode="USD"
/* Link Tracking Config */
s.trackDownloadLinks=true
s.trackExternalLinks=true
s.trackInlineStats=true
s.linkDownloadFileTypes="exe,zip,wav,mp3,mp4,mov,mpg,avi,wmv,doc,docx,pdf,xls,xlsx,ppt,pptx,tar,gz,tif,tiff,tgz.dwg"
s.linkLeaveQueryString=false
s.linkTrackVars=""
s.linkTrackEvents=""

s.cookieDomainPeriods="2"

/* Used to determine whether user left a particular domain in our control to another domain in our control, 
   for example leaving tycoelectronics.com to go to elotouch.com domain */
var TE_baseHostName = new String(window.location.hostname);
var TE_hostNameArray
/* split the hostname into pieces, want to get the primary domain */
TE_hostNameArray = TE_baseHostName.split(".");

/* walk the hostname right to left and find the index of the first non-suffix part, i.e. not com, or co, etc.  The key is
that all suffixes are three or less characters, so we can stop checking for whether it is a suffix once the length is > than three, 
will collect the  entire name if every part of the hostname is  3 characters long or less*/
var firstIndex = 0;
for( i=TE_hostNameArray.length-1; i >= 0; i--){
	var tmpString = new String(TE_hostNameArray[i]);
	if( tmpString.length > 3){
		firstIndex = i;
		i=0;
	}
}

/* put the pieces of the hostname back together left to right  */
TE_baseHostName = "";
for( i=firstIndex; i < TE_hostNameArray.length; i++){
	TE_baseHostName = TE_baseHostName + TE_hostNameArray[i]
	if( i < TE_hostNameArray.length-1){
		TE_baseHostName = TE_baseHostName + '.'
	}

}
// add the shortened hostname to the s_linkInternalFilters so that when we go to pages in that same overall domain
// SiteCatalyst doesn't report it as an exit.
s.linkInternalFilters="javascript:,"+TE_baseHostName

/*Below code is TE specific code for reading trackinguuid cookie and send it as an evar for every page visits/events/custom links
 * Existing TE_GetCookie method can not be used since every page using the TE_sitecatalyst_H.js may not have te_scripts.js included.
 */
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 "NA";
}
/* Plugin Config */
s.usePlugins=true
function s_doPlugins(s) {
	
	s.eVar15="D=g" /* For the Vista rule to fix exit links and file download tracking*/
	
	/* Add calls to plugins here */
	/****  TE SPECIFIC CODE. SEND THE TRACKINGUUID TO SC****/
	if(s.linkTrackVars.length==0 || s.linkTrackVars=="None"|| s.linkTrackVars=="eVar2")
		s.linkTrackVars="eVar2,eVar15";
	else
		s.linkTrackVars+=",eVar2,eVar15";
	var ewtCookie=getCookie("TECewt7");	
	if( ewtCookie!="NA")
		s.eVar2=ewtCookie;
    if (s.campaign == null || s.campaign == "") {
		s.campaign = s.getQueryParam('s_cid');
	}
	if(s.getQueryParam('int_cid')!=null && s.getQueryParam('int_cid').length>0){
		s.eVar7 = s.getQueryParam('int_cid');
		s.linkTrackVars+=",eVar7";
	}	
	/*Populate s.prop50 for campaign page pathing*/
	if(s.campaign !=null && s.campaign.length>0){
		s.prop50=s.pageName+":"+s.campaign;
		s.eVar4=s.campaign;
		/****BELOW IS NOT SITECATALYST LOGIC AND NEEDS TO BE TAKEN CARE DURING SC UPGRADE.****/
		/*This code writes the campaign ID to session cookie for RN*/
		document.cookie="s_cid="+s.campaign+";path=/;";
	}
	else {
		s.prop50=s.pageName
	}
	
}
s.doPlugins = s_doPlugins;

/****************************************************************/
/*     reset the s_account dynamically                                                                         */
/*                                                                                                                            */
/****************************************************************/
s.dynamicAccountSelection=true; 
s.dynamicAccountList=
"devtyco,tycodev=dev.te,qa.te,localhost,50.17.76.138;"+
"tycoeglobal=.";


s.dynamicAccountMatch=window.location.host+window.location.pathname;

/************************** End SiteCatalyst *************************/

var TE_SiteCatalyst = {};
    TE_SiteCatalyst.trackEvent = function(eventDetails) {
        if (s) {
            // if we're here, the 's' object exists
            // set our event type...default is 'o'
            var type = (eventDetails.type !== undefined && eventDetails.type.length > 0) ? eventDetails.type : 'o';
            var linkTrackVars = [];
            // check for custom events, if we have them, handle them
            if (eventDetails.events !== undefined && eventDetails.events.length > 0) {
                s.linkTrackEvents = eventDetails.events;
                s.events = eventDetails.events;
                linkTrackVars.push("events");
            }
            // check our eVars (this object can contain any combination of eVars and sprops as well as their various values) and process them.
            if (eventDetails.eVars !== undefined && eventDetails.eVars.length > 0) {
                if (eventDetails.eVars.indexOf(",,") !== -1) {
                    var evars = eventDetails.eVars.split(",,");
                    var len = evars.length;
                    //for (var e in evars) {
                    for (var iCnt = 0; iCnt < len;iCnt++) {
                        var str = evars[iCnt];
                        if (str.indexOf("::") !== -1) {
                            // we have a name=value pair...handle it
                            try {
                                var eVarName = str.split(String("::"))[0];
                                var eVarValue = str.split(String("::"))[1];
                                // assign our value to our eVar (or sProp) within 's' 
                                s[eVarName] = eVarValue;
                                // push our eVar name into our linkTrackVars object
                                linkTrackVars.push(eVarName);
                            } catch (e) {
                                // do nothing...
                            }
                        } else {
                            // set the eVar value to the event title
                            s[evars[iCnt]] = eventDetails.title ;
                            // push our eVar name into our linkTrackVars object
                            linkTrackVars.push(evars[iCnt]);
                        }
                    }
                } else {
                    var str = eventDetails.eVars;
                    if (str.indexOf("::") !== -1) {
                        // we have a name=value pair...handle it
                        try {
                            var eVarName = str.split(String("::"))[0];
                            var eVarValue = str.split(String("::"))[1];
                            // assign our value to our eVar (or sProp) within 's' 
                            s[eVarName] = eVarValue;
                            // push our eVar name into our linkTrackVars object
                            linkTrackVars.push(eVarName);
                            //alert("tracking : " + eVarName + " with value : " + eVarValue);
                        } catch (e) {
                            // do nothing...
                        }
                    } else {
                        // set the eVar value to the event title
                        s[str] = eventDetails.title ;
                        // push our eVar name into our linkTrackVars object
                        linkTrackVars.push(str);
                    }
                }
            }
            // make sure campaign and page name are captured with this link...
            linkTrackVars.push("campaign");
            linkTrackVars.push("pageName");
            s.linkTrackVars = linkTrackVars.join();
            s.tl('false', type, eventDetails.title);
            return;
        }
    };
