/* for use on benicar.com production only
*/

function gaTrack() {
  var that=this;
  //begin user editable
  this.account="UA-22695570-16";
  this.onsitedoms="";
  this.downloadtypes="xls,doc,pdf,txt,csv,zip";
  this.trackevents=true;
  //end user editable
  this.GA={};
  this.fpcdom=document.domain;
}
gaTrack.prototype.gaIsOnsite = function(host){
	if (host.length>0){
		host=host.toLowerCase();
		if (host==window.location.hostname.toLowerCase()){
			return true;
		}
		if (typeof(this.onsitedoms.test)=="function"){
			return this.onsitedoms.test(host);
		}
		else if (this.onsitedoms.length>0){
			var doms=this.gaSplit(this.onsitedoms);
			var len=doms.length;
			for (var i=0;i<len;i++){
				if (host==doms[i]){
					return true;
				}
			}
		}
	}
	return false;
}
gaTrack.prototype.gaTypeMatch = function(pth, qry, typelist){
  var type=pth.substring(pth.lastIndexOf(".")+1,pth.length);
  var types=this.gaSplit(typelist);
  var tlen=types.length;  
  for (var i=0;i<tlen;i++){
	if (type==types[i]){
	  return types[i];
	}
  }
  return false;
}
gaTrack.prototype.gaEvt = function(evt,tag){
  var e=evt.target||evt.srcElement;
  while (e.tagName&&(e.tagName!=tag)){
	e=e.parentElement||e.parentNode;
  }
  return e;
}
gaTrack.prototype.gaBind = function(event,func){
  if ((typeof(func)=="function")&&document.body){
	if (document.body.addEventListener){
	  document.body.addEventListener(event, func.wtbind(this), true);
	}
	else if(document.body.attachEvent){
	  document.body.attachEvent("on"+event, func.wtbind(this));
	}
  }
}
gaTrack.prototype.gaET = function(){
  var e=(navigator.appVersion.indexOf("MSIE")!=-1)?"click":"mousedown";
  this.gaBind(e,this.gaDownload);
  this.gaBind(e,this.gaOffsite);
}
gaTrack.prototype.gaSplit = function(list){
  var items=list.toLowerCase().split(",");
  var len=items.length;
  for (var i=0;i<len;i++){
	items[i]=items[i].replace(/^\s*/,"").replace(/\s*$/,"");
  }
  return items;
}
//Track clicks to download links.
gaTrack.prototype.gaDownload = function(evt){
  evt=evt||(window.event||"");
  if (evt&&((typeof(evt.which)!="number")||(evt.which==1))){
	var e=this.gaEvt(evt,"A");
	if (e.href){
		var hn=e.hostname?(e.hostname.split(":")[0]):"";
		var qry=e.search?e.search.substring(e.search.indexOf("?")+1,e.search.length):"";
	 var dtype=this.gaTypeMatch(e.pathname,qry,this.downloadtypes);
		if (this.gaIsOnsite(hn)&&dtype){
			var pth=e.pathname?((e.pathname.indexOf("/")!=0)?"/"+e.pathname:e.pathname):"/";
			var ttl="";
			var text=document.all?e.innerText:e.text;
			var img=this.gaEvt(evt,"IMG");
			if (img.alt){
			  ttl=img.alt;
			}
			else if (text){
			  ttl=text;
			}
			else if (e.innerHTML){
			  ttl=e.innerHTML;
			}
				this.gaTrackEvent("Downloads", e.pathname, "Auto-Tracked Events");
		}
	}
  }
}
//Track clicks to links leading offsite.
gaTrack.prototype.gaOffsite = function(evt){
  evt=evt||(window.event||"");
  if (evt&&((typeof(evt.which)!="number")||(evt.which==1))){
	var e=this.gaEvt(evt,"A");
	if (e.href){
		var hn=e.hostname?(e.hostname.split(":")[0]):"";
		var pr=e.protocol||"";
		if ((hn.length>0)&&(pr.indexOf("http")==0)&&!this.gaIsOnsite(hn)){
		  var qry=e.search?e.search.substring(e.search.indexOf("?")+1,e.search.length):"";
		  var pth=e.pathname?((e.pathname.indexOf("/")!=0)?"/"+e.pathname:e.pathname):"/";
		  	if (e.href.match(/.*(sankyo|daiichi|welcol|welchol|benicar|tribenzor|azor|dsi|livingwithdryness|evoxac|rightfitforme|bpunderpressure|center4consumerism|2reasons1|tworeasonsone|savingsthatlast).*/))
			this.gaTrackEvent("Cross-DSI Clicks", e.href, "Auto-Tracked Events");
				else
			this.gaTrackEvent("Offsite Clicks", e.href, "Auto-Tracked Events");
		}
	}
  }
}
gaTrack.prototype.gaAdv = function(){
  if (this.trackevents&&(typeof(this.gaET)=="function")){

	if (window.addEventListener){
	  window.addEventListener("load",this.gaET.wtbind(this),false);
	}
	else if (window.attachEvent){
	  window.attachEvent("onload",this.gaET.wtbind(this));
	}
  }
}
Function.prototype.wtbind = function(obj){
  var method=this;
  var temp=function(){
	return method.apply(obj,arguments);
  };
  return temp;
}
//cookie read/write
gaTrack.prototype.writeCookie = function(name, value, expires) {
	var today = new Date();
	today.setTime(today.getTime());
	if (expires) expires = expires * 1000 * 60;
	var expires_date = new Date( today.getTime() + (expires) );
		document.cookie = name + "=" +escape( value ) +
		( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + ";path=/;domain=" + this.fpcdom;
}
gaTrack.prototype.readCookie = function(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
gaTrack.prototype.gaMeta = function(){
	this.WT = {};
	this.DCSext = {};
	var elems;
	if (document.documentElement)
		elems=document.getElementsByTagName("meta");
	else if (document.all)
		elems=document.all.tags("meta");
	if (!exists(elems)) return;
		var length=elems.length;
		for (var i=0;i<length;i++){
			var name=elems.item(i).name;
			var content=elems.item(i).content;
			var equiv=elems.item(i).httpEquiv;
			if (name.length>0 && name.toUpperCase().indexOf("GA.")==0)
					this.GA[name.substring(3)]=content;
		}
}
//builds a relative uri for custom content drilldown & goal tracking
gaTrack.prototype.gaBuildURL = function() {
	this.ti = "";
		if (exists(this.GA.contentgroup) && this.GA.contentgroup)
			this.ti += "/" + this.GA.contentgroup;
		if (exists(this.GA.contentsubgroup) && this.GA.contentsubgroup)
			this.ti += "/" + this.GA.contentsubgroup;
	this.ti += window.location.pathname;
		if (exists(this.GA.autogoalname) && this.GA.autogoalname && exists(this.GA.autogoalstep) && this.GA.autogoalstep)
			this.ti += "/" + this.GA.autogoalname + '_' + this.GA.autogoalstep;
		if (exists(this.GA.goalname) && this.GA.goalname && exists(this.GA.goalstep) && this.GA.goalstep)
			this.ti += "/" + this.GA.goalname + '_' + this.GA.goalstep;
}
//call this function directly to track any conversion events
gaTrack.prototype.gaTrackGoal = function(goalname, goalstep) {
if (!exists(goalname) || !exists(goalstep)) return;
	this.GA.goalname = goalname;
	this.GA.goalstep = goalstep;
	this.gaBuildURL();
		_gaq.push(['_trackPageview', this.ti]);
	this.GA = {};
}
//helper function to track a single event
gaTrack.prototype.gaTrackEvent = function(category, action, label) {
		_gaq.push(['_trackEvent', category, action, label]);
}
//page tracking calls
gaTrack.prototype.gaTrackPage = function() {
	_gaq.push(['_setAccount', this.account]);
	_gaq.push(['_setDomainName', this.fpcdom]);
	_gaq.push(['_setAllowLinker', true]);
	_gaq.push(['_setAllowHash', false]);
		this.gaMeta();
		this.gaBuildURL();
	_gaq.push(['_trackPageview', this.ti]);
		this.GA = {};
}

function exists(A) { return (typeof A != 'undefined') }

// init custom tracker obj
var _taq = new gaTrack();

document.write("<script type='text/javascript'>var _gaq = _gaq || []; _taq.gaTrackPage() </script>");
document.write("<script type='text/javascript'> (function() {\
	var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;\
	ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';\
	var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })();</script>");

//activate listeners
_taq.gaAdv();
