var _gaq = _gaq || [];
/* Track product clicks */
function linkCode(obj, category, product, linkName, value)
{
	/* Get unique order ID - Unique per session */
	var d = new Date();
	var order = d.valueOf(); 
	_gaq.push(['_addTrans',
	  order, // order ID - required
	  'OTC Tracking',
	  value,   // total - required
	  0,
	  0
	]);
	_gaq.push(['_addItem',
	  order,
	  string_to_slug(product)+'-click',
	  product,          
	  category,
	  value,
	  '1'
	]);
	_gaq.push(['_trackTrans']);
	return true;
}
function customPageView(type,channel,region,account)
{
	_gaq.push(['_setCustomVar', 1,"Page Type",type,3]);
	if(channel)
	{
		_gaq.push(['_setCustomVar', 2,"Channel",channel,3]);
	}
	if(region)
	{
		_gaq.push(['_setCustomVar', 3,"Region",region,3]);
	}
	if(account)
	{
		_gaq.push(['_setCustomVar', 4,"Account",account,3]);
	}
}
/* Compatibility until all references removed */
function addProductsToArray()
{
	if(console) console.log("addProductsToArray is depreciated");
	return true;
}

function string_to_slug(str) {
  str = str.replace(/^\s+|\s+$/g, ''); // trim
  
  // remove accents, swap ñ for n, etc
  var from = "ÀÁÄÂÈÉËÊÌÍÏÎÒÓÖÔÙÚÜÛàáäâèéëêìíïîòóöôùúüûÑñÇç·/_,:;";
  var to   = "aaaaeeeeiiiioooouuuuaaaaeeeeiiiioooouuuunncc------";
  for (var i=0, l=from.length ; i<l ; i++) {
    str = str.replace(new RegExp(from[i], "g"), to[i]);
  }

  str = str.replace(/[^a-zA-Z0-9 -]/g, '') // remove invalid chars
  	.replace(/\s+/g, '-') // collapse whitespace and replace by -
    .toLowerCase();
  return str;
}

function s_region_change(obj,field)
{
	var f = document.filterForm[field].options[document.filterForm[field].selectedIndex];
	var link = f.value;
	var name = f.text;
	
	if (link)
	{	
		_gaq.push(['_trackEvent','Filter Change','Region',name]);
		window.location = link;
	}
}


function s_city_change(obj, field)
{
	var f = document.filterForm[field].options[document.filterForm[field].selectedIndex];
	var link = f.value;
	var name = f.text;
	
	if (link)
	{	
		_gaq.push(['_trackEvent','Filter Change','City',name]);	
		window.location = link;
	}
}

function s_filter_change(obj, field)
{
	var f = document.filterForm[field].options[document.filterForm[field].selectedIndex];
	var link = f.value;
	var name = f.text;
	
	if (link)
	{	
		_gaq.push(['_trackEvent','Filter Change','Filter',name]);
		window.location = link;
	}
}
