Type.registerNamespace('Vehix.Omniture');
Vehix.Omniture.BehaviorEventBuilder = function()
{
	this._events = null;
	this._vars = new Vehix.Collections.Dictionary();
	this._products = null;
	this._trackingEvents = false;
	this._trackingProducts = false;
}
Vehix.Omniture.BehaviorEventBuilder.prototype =
{
	_appendTo : function(list,value,delimiter)
	{
		if(list == null || list == 'None')
		{
			list = '';
		}
		if(typeof(list) != 'undefined' && list != null && list.length > 0)
		{
			list += delimiter;
		}
		list += value;
		return list;
	},
	addEvent : function(name)
	{
		this._events = this._appendTo(this._events,name,',');
		this._trackingEvents = true;	
		return this;
	},
	addVar : function(id,value)
	{
		this._vars.add(id,value);
		return this;		
	},
	addProduct : function(category,name,quantity,price,event)
	{
		if(typeof(category) == 'undefined' || category == null)
		{
			category = '';
		}
		if(typeof(name) == 'undefined' || name == null)
		{
			name = '';
		}
		if(typeof(quantity) == 'undefined' || quantity == null)
		{
			quantity = '';
		}
		if(typeof(price) == 'undefined' || price == null)
		{
			price = '';
		}
		if(typeof(event) == 'undefined' || event == null)
		{
			event = '';
		}
		var product = category +';'+ name;
		if(quantity != '' | price != '' | event != '')
		{
			product += ';' + quantity;
		}
		if(price != '' | event != '')
		{
			product += ';' + price;
		}
		if(event != '')
		{
			product += ';' + event;
		}			
		this._products = this._appendTo(this._products,product,',');
		this._trackingProducts = true;
		return this;
	},
	track : function(element)
	{	
		if(typeof(s_account) != 'undefined')
		{
			var ls = new s_gi(s_account);
			if(this._events != null)
			{
				ls.events = this._events;
				ls.linkTrackEvents = this._events;
			}
			if(this._vars != null)
			{
				for(var v = this._vars.getEnumerator();v.moveNext();)
				{
					ls.linkTrackVars = this._appendTo(ls.linkTrackVars,'eVar'+ v.get_key(),',');
					eval('ls.eVar'+ v.get_key() +'=\''+ v.get_current() +'\'');
				}
				if(this._trackingProducts)
				{
					ls.linkTrackVars = this._appendTo(ls.linkTrackVars,'products',',');
				}
				if(this._trackingEvents)
				{
					ls.linkTrackVars = this._appendTo(ls.linkTrackVars,'events',',');
				}
			}
			if(this._products != null)
			{
				ls.products = this._products;
			}
			ls.tl(element,'o',this._products);
		}
		return this;
	},
	trackObjectID : function(element,objectID)
	{	
		if(typeof(s_account) != 'undefined')
		{
			var ls = new s_gi(s_account);
			if(this._events != null)
			{
				ls.events = this._events;
				ls.linkTrackEvents = this._events;
			}
			if(this._vars != null)
			{
				for(var v = this._vars.getEnumerator();v.moveNext();)
				{
					ls.linkTrackVars = this._appendTo(ls.linkTrackVars,'eVar'+ v.get_key(),',');
					eval('ls.eVar'+ v.get_key() +'=\''+ v.get_current() +'\'');
				}
				if(this._trackingProducts)
				{
					ls.linkTrackVars = this._appendTo(ls.linkTrackVars,'products',',');
				}
				if(this._trackingEvents)
				{
					ls.linkTrackVars = this._appendTo(ls.linkTrackVars,'events',',');
				}
			}
			if(this._products != null)
			{
				ls.products = this._products;
			}
			ls.tl(element, 'o', objectID);
		}
		return this;
	}
}
Vehix.Omniture.BehaviorEventBuilder.registerClass('Vehix.Omniture.BehaviorEventBuilder');

function OmnitureTrackingClick(productName)
{
  OmnitureTrackingGeneralClick(null, null, productName);
}

function OmnitureTrackingSellerIdClick(id, productName)
{    
  OmnitureTrackingGeneralClick(id, 'eVar8', productName);
}

function OmnitureTrackingGeneralClick(id, eVar, productName)
{    
  var ls = new s_gi(s_account);
	if(s)
		ls.pageName = s.pageName;
  ls.events = 'purchase';
  var eVarTracking = '';
  var productTracking = '';
  if (id)
  {
    eval('ls.' + eVar + ' = "' + id + '";');
    eVarTracking = eVar + ',';
    productTracking = ';'+ id + ':';
  }
  else
  {
    productName = ";" + productName;
  }
  ls.products = productTracking + productName + ' Click Through';
  ls.linkTrackVars = 'events,' + eVarTracking + 'products';
  ls.linkTrackEvents = 'purchase';
  ls.tl(this, 'o', ls.products);
  //  alert('DEBUG: ls.eVar8 =' + ls.eVar8 + " ls.products=" + ls.products + " ls.linkTrackVars=" + ls.linkTrackVars);
}

function NadaOmnitureClickThrough()
{
	var ls = new s_gi(s_account);
	ls.events='purchase';
	ls.products = ';Buy a NADA Price Guide Click Through';
	ls.linkTrackVars = 'events,products';
	ls.linkTrackEvents = 'purchase';
	ls.tl(this,'o',ls.products);
}

