function mmSetupAtlas()
{
    atlasSearch.universalTracking = 'true';
    atlasSearch.universalTrackingExclusionList = ['totaljobs.com'];


    if (atlasSearch.referrerURL != '')
    { atlasSearch.referrerInfo.referrerType = 'Non-search'; }

    if (atlasSearch.locationURL.indexOf(atlasSearch.paidSearchParam) != -1)
    { atlasSearch.referrerInfo.paid = 'paid'; }

    if (atlasSearch.locationURL.indexOf(atlasSearch.emailParam) != -1)
    { atlasSearch.referrerInfo.referrerType = 'Email'; }

    updateReferrerInfo(atlasSearch);

    if (atlasSearch.referrerInfo.referrerType == 'Search' && atlasSearch.referrerInfo.paid == 'non_paid') {
        var atlassearchactionRequest = new Image();
        atlassearchactionRequest.src = atlasSearch.protocol + 'switch.atdmt.com/action/' + atlasSearch.actionTag + '/v3/atc1.' + atlasSearch.referrerInfo.referrerType + '/atc2.' + atlasSearch.referrerInfo.referrerDetail + '/atc3.' + atlasSearch.referrerInfo.paid + '/atc4.' + atlasSearch.referrerInfo.keywordType + '/keyword.' + escape(atlasSearch.referrerInfo.keyword) + '/fullReferrer.' + escape(atlasSearch.referrerURL) + '/landingPageURL.' + escape(atlasSearch.locationURL);
    }
    else if (atlasSearch.universalTracking == 'true') {

        if (window.location.hostname != '')
        { atlasSearch.universalTrackingExclusionList.push(window.location.hostname); }

        atlasSearch.referrerhostname = atlasSearch.referrerURL;

        if (atlasSearch.referrerhostname.indexOf('?') != -1)
        { atlasSearch.referrerhostname = atlasSearch.referrerhostname.substring(0, atlasSearch.referrerhostname.indexOf('?')) }

        atlasSearch.requestRequired = 'true';

        for (i = 0; i < atlasSearch.universalTrackingExclusionList.length; i++) {
            if (atlasSearch.referrerhostname.indexOf(atlasSearch.universalTrackingExclusionList[i]) != -1)
            { atlasSearch.requestRequired = 'false'; }
        }

        if (atlasSearch.requestRequired == 'true' && atlasSearch.referrerInfo.referrerType != 'Email') {
            var atlassearchactionRequest = new Image();
            atlassearchactionRequest.src = atlasSearch.protocol + 'switch.atdmt.com/action/' + atlasSearch.actionTag + '/v3/atc1.' + atlasSearch.referrerInfo.referrerType + '/atc2.' + atlasSearch.referrerInfo.referrerDetail + '/atc3.' + atlasSearch.referrerInfo.paid + '/atc4.' + atlasSearch.referrerInfo.keywordType + '/keyword.' + escape(atlasSearch.referrerInfo.keyword) + '/fullReferrer.' + escape(atlasSearch.referrerURL) + '/landingPageURL.' + escape(atlasSearch.locationURL);
        }

        if (atlasSearch.requestRequired == 'true' && atlasSearch.referrerInfo.referrerType == 'Email') {
            var atlassearchactionRequest = new Image();
            atlassearchactionRequest.src = atlasSearch.protocol + 'switch.atdmt.com/action/' + atlasSearch.existingCustomerActionTag + '/v3/atc1.' + atlasSearch.referrerInfo.referrerType + '/atc2.' + atlasSearch.referrerInfo.referrerDetail + '/atc3.' + atlasSearch.referrerInfo.paid + '/atc4.' + atlasSearch.referrerInfo.keywordType + '/keyword.' + escape(atlasSearch.referrerInfo.keyword) + '/fullReferrer.' + escape(atlasSearch.referrerURL) + '/landingPageURL.' + escape(atlasSearch.locationURL);
        }

    }
}


function atlasSearchObject() {
    this.actionTag = '';
    this.protocol = protocolFinder();
    this.paidSearchParam = '';
    this.brandTerms = new Array();
    this.referrerInfo = { 'referrerType': 'DirectType', 'referrerDetail': 'na', 'paid': 'non_paid', 'keywordType': 'na', 'keyword': 'na' };
    this.universalTracking = '';
    this.universalTrackingExclusionList = new Array();
    this.locationURL = window.location + '';
    this.referrerURL = document.referrer + '';
    this.engines = new Array();
    this.engines['google'] = { 'name': 'Google Search', 'referrerURLSubstring': 'google', 'keywordStart': 'q=', 'keywordEnd': '&' };
    this.engines['yahoo'] = { 'name': 'Yahoo Search', 'referrerURLSubstring': 'search.yahoo.co', 'keywordStart': 'p=', 'keywordEnd': '&' };
    this.engines['live'] = { 'name': 'MSN Live', 'referrerURLSubstring': 'search.live.co', 'keywordStart': 'q=', 'keywordEnd': '&' };
    this.engines['ask'] = { 'name': 'Ask.com', 'referrerURLSubstring': 'ask.com/web?q=', 'keywordStart': 'q=', 'keywordEnd': '&' };
    this.engines['msn'] = { 'name': 'MSN', 'referrerURLSubstring': 'search.msn.co', 'keywordStart': '', 'keywordEnd': '&' };
    this.engines['aol'] = { 'name': 'AOL Search', 'referrerURLSubstring': 'search.aol.co', 'keywordStart': 'query=' };
    this.engines['miva'] = { 'name': 'Miva Search', 'referrerURLSubstring': 'miva' };
}


function updateReferrerInfo(atlasSearchObjectInstance) {
    for (var i in atlasSearchObjectInstance.engines) {
        var selectedEngine = atlasSearchObjectInstance.engines[i];

        if (atlasSearchObjectInstance.referrerURL.indexOf(selectedEngine.referrerURLSubstring) != -1) {
            atlasSearchObjectInstance.referrerInfo.referrerType = 'Search';
            atlasSearchObjectInstance.referrerInfo.referrerDetail = selectedEngine.name;
            var keywordString = 'unknown - not provided by engine';
            if (selectedEngine.keywordStart) {
                if (atlasSearchObjectInstance.referrerURL.indexOf(selectedEngine.keywordStart) != -1)
                { keywordString = atlasSearchObjectInstance.referrerURL.substring(atlasSearchObjectInstance.referrerURL.indexOf(selectedEngine.keywordStart) + selectedEngine.keywordStart.length); }
            }

            if (selectedEngine.keywordEnd) {
                if (keywordString.indexOf(selectedEngine.keywordEnd) != -1)
                { keywordString = keywordString.substring(0, keywordString.indexOf(selectedEngine.keywordEnd)); }
            }

            if (keywordString != 'unknown - not provided by engine') {
                atlasSearchObjectInstance.referrerInfo.keywordType = 'Non_Brand';
                for (j = 0; j < atlasSearchObjectInstance.brandTerms.length; j++) {
                    var brand_term = atlasSearchObjectInstance.brandTerms[j];
                    if (keywordString.indexOf(brand_term) != -1)
                    { atlasSearchObjectInstance.referrerInfo.keywordType = 'Brand'; }
                }

            }

            atlasSearchObjectInstance.referrerInfo.keyword = keywordString;
            atlasSearchObjectInstance.referrerInfo.atlasClickURL = selectedEngine.clickTag;

            //alert('SUCCESS! - Engine: ' + referrerInfo.engineName + ' keyword:' + referrerInfo.keyword + '<br>');	
        }
    }
}


//****************ATLAS CODE - DO NOT MODIFY******************************************


//This array defines how transaction properties map to Atlas properties.  More than one transaction property can link to a single Atlas property.  By default the standard atlas properties are mapped, but this can be changed to included custom mappings, e.g. 'qty' : 'atm1'.  In addition, this code allows new metrics and categories to be added if and when enhancements to Atlas tracking are made.

var variableMappings = {
			'atm1' : 'atm1',
			'atm2' : 'atm2',
			'atm3' : 'atm3',
			'atm4' : 'atm4',
			'atm5' : 'atm5',
			'atm6' : 'atm6',
			'atc1' : 'atc1',
			'atc2' : 'atc2',
			'atc3' : 'atc3',
			'atc4' : 'atc4',
			'atc5' : 'atc5',
			'atc6' : 'atc6'
			};


function protocolFinder()
{
	var protocol = 'http://';
	if(window.location.protocol == 'https:')
	{protocol = 'https://';}

	return protocol;
}



function atlasObject()
{
	this.actionTags = new Array(defaultActionTag);
	this.transaction = new orderObject();
	this.extendedData = '';
	this.createRequest = createAtlasRequest;
	this.protocol = protocolFinder();
	
}

function createAtlasRequest()
{
	transactionData = this.transaction.URLFragment();

	for(i=0;i<this.actionTags.length;i++)
	{
		document.write('<s'+'cript language="JavaScript" src="'+this.protocol+'switch.atdmt.com/jaction/'+this.actionTags[i]+'/v3/'+transactionData+encodeURI(this.extendedData)+'"></s'+'cript>');
	}

}

function orderObject()
{
	this.ID = ''
	this.Summary = new Object();
	this.Line = new Array('');
	this.URLFragment = v3DataString;
	
}

function v3DataString()
{
	var components = new Array();	

	for(i=0;i<this.Line.length;i++)
	{
		if(this.Line[i])
		{
		var linex = this.Line[i];
		var fragments = new Array();

		for(var j in linex)
		{
		 	if(variableMappings[j]){fragments.push(variableMappings[j]+'.'+linex[j]);}
		
		}

		var orderString = '['
		for(k=0;k<fragments.length;k++)
		{
			orderString += encodeURI(fragments[k]);
			if(k != fragments.length-1){orderString += '/';}
		}
		orderString += ']';
		components.push(orderString);
		}
	}
	
	var transID = (this.ID!='')?'ato.'+encodeURI(this.ID)+'/':'';
	
	var summaryData = new Array();

	for(var l in this.Summary)
	{if(variableMappings[l])
	{summaryData.push(variableMappings[l]+'.'+this.Summary[l]);}
	}

	var summaryString = ''	

	for(m=0;m<summaryData.length;m++)
	{summaryString += encodeURI(summaryData[m])+'/';}
	
	var completeString = transID;
	for(n=0;n<components.length;n++)
	{completeString += components[n]+'/';}

	completeString += summaryString;

	return completeString;
}

