
/********************************
 * Analytics.js
 * 
 * Specialized functions to enable
 * third party analytics.
 */

function OmnitureSelectedSkuCodeContainer() {}
OmnitureSelectedSkuCodeContainer.SelectedSkuCode = '';
OmnitureSelectedSkuCodeContainer.UpsellSkuCode = '';

function TrackingImageButtonClick()
{
	var tracker = new OmnitureProcessor(s_gi(s_account)); 
	tracker.events = '';
	
	for(var omniItem in this.OmniProperties)
	{
		try{
		tracker.SetProperty(omniItem, this.OmniProperties[omniItem]);
		}catch(err)
		{
		}
	}

	tracker.SendLink(this);
}

function InjectFormSubmit(element)
{
	if(element && document.forms['aspnetForm'])
	{
		formFunction = document.forms['aspnetForm'].onsubmit;
		
		document.forms['aspnetForm'].onsubmit = function onsubmit(event)
			{
			
				var result = false;
				if(typeof(formFunction) == 'object' || formFunction())
				{
					result = true;
					TrackingImageButtonClick.call(element);
				}
				
				document.forms['aspnetForm'].onsubmit = formFunction;
				
				return result;
			}
	}
}

/* Omniture custom link tracking */
function ExternalTracker()
{
	this.omniTracker = typeof(s_account) != 'undefined' && s_account && typeof(s_gi) != 'undefined' ? s_gi(s_account) : null;
}

ExternalTracker.prototype.DoTracking = function(object, trackValue)
{
	if(this.omniTracker)
	{
		this.omniTracker.tl(object,'o', trackValue);
	}
}

ExternalTracker.prototype.DoEvent = function(object, eventScript)
{
	if(this.omniTracker)
	{
		try
		{
			//replace 'this' in the eventScript with object'
			eval(eventScript.replace(/this/g, 'object'));
		}catch(err)
		{
		}
	}
}

/* page event processing for Omniture */
function OmnitureProcessor(analyticsObject)
{
	this.omniTracker = analyticsObject;
	this.actionComplete = false;
}

OmnitureProcessor.prototype.IsFinished = function()
{
	return this.actionComplete;
}

OmnitureProcessor.prototype.AddEvent = function(eventList, clearEvents)
{
	if(this.omniTracker)
	{
		if(clearEvents)
		{
			this.omniTracker.events = '';
		}
		
		if(this.omniTracker.events && this.omniTracker.events != '')
		{
			this.omniTracker.events += ',' + eventList;
		}
		else
		{
			this.omniTracker.events = eventList;
		}
	}
}

OmnitureProcessor.prototype.AddEventValOnce = function(eventName, clearEvents)
{
	if(this.omniTracker)
	{
	    var eventValOnce = this.omniTracker.getValOnce ( eventName, eventName, 0);
	    if ( eventValOnce )
	    {
		    if(clearEvents)
		    {
			    this.omniTracker.events = '';
		    }
		
		    if(this.omniTracker.events && this.omniTracker.events != '')
		    {
			    this.omniTracker.events += ',' + eventName;
		    }
		    else
		    {
			    this.omniTracker.events = eventName;
		    }
		}
	}
}

OmnitureProcessor.prototype.Send = function()
{
	if(this.omniTracker)
	{
		try{
			
			var retVal = this.omniTracker.t();
			return retVal;
		}catch(err)
		{
		}
	}
	else
	{
		return null;
	}
}

OmnitureProcessor.prototype.SendLink = function(element)
{
	if(this.omniTracker)
	{
		if(this.omniTracker.events == 'scCheckout')
		{
			this.omniTracker.linkTrackVars='events,products,eVar18';
			this.omniTracker.linkTrackEvents='scCheckout';
		}
		else if(this.omniTracker.events == 'scAdd')
		{
			this.omniTracker.linkTrackVars='events,products,prop25,eVar10,eVar18,eVar21';
			this.omniTracker.linkTrackEvents='scAdd';
		}
		else if(this.omniTracker.events == 'event8')
		{
			this.omniTracker.linkTrackVars='events,prop24,eVar29';
			this.omniTracker.linkTrackEvents='event8';
		}
		else if(this.omniTracker.events == 'event15')
		{
			this.omniTracker.linkTrackVars='events';
			this.omniTracker.linkTrackEvents='event15';
		}
		else if(typeof(this.omniTracker.eVar7) != 'undefined' && this.omniTracker.eVar7 != '')
		{
			this.omniTracker.linkTrackVars='eVar7,';
			var selfServiceType = this.omniTracker.eVar7.toLowerCase();
			if (selfServiceType.search(/promo graphic/) != -1 || selfServiceType.prop7 == 'text link')
			{
				this.omniTracker.linkTrackVars += 'eVar2';
			}
			if (selfServiceType == 'menu')
			{
				this.omniTracker.linkTrackVars += 'eVar20';
			}
			if (selfServiceType == 'related categories')
			{
				this.omniTracker.linkTrackVars += 'eVar34';
			}
			if (selfServiceType == 'left nav')
			{
				this.omniTracker.linkTrackVars += 'eVar31';
			}
			if (selfServiceType == 'browse')
			{
				this.omniTracker.linkTrackVars += 'eVar32';
			}
			if (selfServiceType == 'func')
			{
				this.omniTracker.linkTrackVars += 'eVar11';
			}
			if (selfServiceType == 'items per page')
			{
				this.omniTracker.linkTrackVars += 'eVar33';
			}
			if (selfServiceType == 'sort order')
			{
				this.omniTracker.linkTrackVars += 'eVar27';
			}
			if (selfServiceType == 'form submission')
			{
				this.omniTracker.linkTrackVars += 'eVar5';
			}
			if (selfServiceType == 'pd sizing pair')
			{
				this.omniTracker.linkTrackVars += 'eVar41';
			}
			if (selfServiceType == 'not done shopping')
			{
				this.omniTracker.linkTrackVars += 'eVar37';
			}
		}
		 
		try
		{
			var retVal = this.omniTracker.tl(window.location.href, 'o', 'OnClickEvent');
			this.actionComplete = true;
		}
		catch(err)
		{
			this.actionComplete = true;
		}
	}
}

OmnitureProcessor.prototype.SetProducts = function(productList)
{
	if(this.omniTracker)
	{
		this.omniTracker.products = productList;
	}
}

OmnitureProcessor.prototype.SetPurchaseID = function(poNumber)
{
	if(this.omniTracker)
	{
		this.omniTracker.purchaseID = poNumber;
	}
}

OmnitureProcessor.prototype.SetState = function(state)
{
	if(this.omniTracker)
	{
		this.omniTracker.state = state;
	}
}

OmnitureProcessor.prototype.SetZip = function(zip)
{
	if(this.omniTracker)
	{
		this.omniTracker.zip = zip.substring(0,5);
	}
}

OmnitureProcessor.prototype.SetProperty = function(property, value)
{
	if(this.omniTracker)
	{
		eval('this.omniTracker.' + property + ' = value'); 
	}
}

OmnitureProcessor.prototype.SetPageName = function(name)
{
	if(this.omniTracker)
	{
		this.omniTracker.pageName = name;
	}
}

OmnitureProcessor.prototype.SetReferrer = function(name)
{
	if(this.omniTracker)
	{
		this.omniTracker.referrer = name;
	}
}

OmnitureProcessor.prototype.SetChannel = function(channel)
{
	if(this.omniTracker)
	{
		this.omniTracker.channel = channel;
	}
}

OmnitureProcessor.prototype.ClearProperties = function()
{
	if(this.omniTracker)
	{
		for(var i=1; i < 47; i++)
		{
			eval('this.omniTracker.prop' + i + ' = \'\'');
			eval('this.omniTracker.eVar' + i + ' = \'\'');
		}
		this.omniTracker.channel = this.omniTracker.hier1 = this.omniTracker.hier1 = '';
		this.omniTracker.purchaseID = this.omniTracker.campaign = '';
		this.omniTracker.state = this.omniTracker.zip = '';
	}
}