/*
	sendLinkEvent(lnkname)
	lnkname:	identifier name for link reported
*/
function sendLinkEvent(lnkname){
	sendAnalyticsEvent(null,lnkname);
}
function sendAnalyticsEvent(str,lnkname){ 
	try {
		
		if(com.mtvi.util.isDefined(dispatcher)){
			if(com.mtvi.util.isDefined(com.mtvi.reporting.Account)){
				if(com.mtvi.util.isDefined(lnkname)){					
					obj = {};
					if(com.mtvi.util.isDefined(str)){ 
						obj.name=str;
						omniSetOverrides(obj, "append");
					}else{ 
						obj.name=com.mtvi.reporting.Account.name;
						omniSetOverrides(obj, null);
					}					
					delete obj;
					dispatcher.sendLinkEvent({linkType:"o",lnk:true,linkName:lnkname});
				}else{
					if(com.mtvi.util.isDefined(str))
						omniSetOverrides({name:str}, "append");
					else
						omniSetOverrides({name:com.mtvi.reporting.Account.name}, null);
					dispatcher.sendCall();
				}
			}
		}
	} catch(e){}
}
function omniSetOverrides(or,acctNameAction){
	try{
		var ro = {};
		for(i in or){
			var tmpi=i.replace(/s_/,"");
			tmpi=(tmpi=="account")? "name" : tmpi;
			ro[tmpi]=or[i];
			
			if(tmpi=="name"){
				if(acctNameAction){
					if(acctNameAction=="append"){
						var pattern = new RegExp("^"+ro[tmpi]+"$|^"+ro[tmpi]+",|,"+ro[tmpi]+"$|,"+ro[tmpi]+",");
						if(!pattern.test(com.mtvi.reporting.Account.name))
							com.mtvi.reporting.Account.name += ',' + ro[tmpi]; 
					}else if(acctNameAction=="overwrite")
						com.mtvi.reporting.Account.name = ro[tmpi]; 
				}
				ro[tmpi]= com.mtvi.reporting.Account.name;
			}
		}
		ro.dynamicAccountSelection = true;
		ro.dynamicAccountList="devviaparents=peanut-d.mtvi.com,peanut-q.mtvi.com",
		ro.linkInternalFilters = "javascript:,parentsconnect.com";
		ro.trackExternalLinks = true;
		ro.trackDownloadLinks = true;
		if(com.mtvi.util.isDefined(dispatcher)) dispatcher.setAccountVars(ro);
	}catch(e){}
}
function resetParamsToDefault(){
	try {
		if(com.mtvi.util.isDefined(dispatcher)){
			com.mtvi.reporting.Account={
				name:'viaparents,viapc',
				dynamicAccountSelection:true,
				dynamicAccountList:'devviaparents=parentsconnect-jd.mtvi.com,parentsconnect-jq.mtvi.com',
				linkInternalFilters:'javascript:,parentsconnect.com',
				trackExternalLinks: true,
				trackDownloadLinks: true			
			};
			dispatcher.setAttribute("pageName", pageName);
			dispatcher.setAttribute("hier1", pageName);
			dispatcher.setAttribute("channel", siteID);
			dispatcher.setAttribute("prop2",searchterm);
			dispatcher.setAttribute("prop3",source);
			dispatcher.setAttribute("prop4",ct);
			dispatcher.setAttribute("prop5",xid);
			dispatcher.setAttribute("prop6",com.mtvi.config.qs.tID);
			dispatcher.setAttribute("prop7",com.mtvi.config.qs.game);
			dispatcher.setAttribute("prop42",com.mtvi.config.qs.sem?com.mtvi.config.qs.sem:"");
			dispatcher.setAttribute("eVar2",searchterm);
			dispatcher.setAttribute("eVar3",com.mtvi.config.qs.searchtype?com.mtvi.config.qs.searchtype:"");
			dispatcher.setAttribute("eVar5",xid);
			dispatcher.setAttribute("campaign",com.mtvi.config.qs.sem?com.mtvi.config.qs.sem:com.mtvi.config.qs.source?com.mtvi.config.qs.source:com.mtvi.config.qs.xid?com.mtvi.config.qs.xid:"");
			if(xid.length>0)dispatcher.setAttribute("events","event2");
		}
	} catch(e){}
}
function PCLinkTracking(linkName)
{
	linkName="/linkTracking/"+linkName;
	dispatcher.setDefaultData();
	dispatcher.setAttribute("linkType","o");
	dispatcher.setAttribute("lnk",true);
	dispatcher.setAttribute("linkName",linkName);
	dispatcher.sendCall();
}
function emailConfirmedTracking(){
	try{
		if(com.mtvi.util.isDefined(dispatcher)){
			if(com.mtvi.util.isDefined(com.mtvi.reporting.Account)){
				resetParamsToDefault();
				var ro={};
				ro.name = com.mtvi.reporting.Account.name;
				if(xid.length>0)
					ro.events = "event1,event2";
				else ro.events = "event1";
				dispatcher.setAccountVars(ro);
				dispatcher.sendCall();
			}
		}
	}catch(e){}
}