/*
	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)){
			if(location.host.indexOf("gocitykids")>-1){
				mtvn.btg.config.ReportSettings.Omniture["account"] = 'viaparents,vianickgocity';
				mtvn.btg.config.ReportSettings.Omniture["dynamicAccountList"] = 'devviaparents=gocitykids-d.mtvi.com,gocitykids-q.mtvi.com';
				mtvn.btg.config.ReportSettings.Omniture["linkInternalFilters"] = 'javascript:,parentsconnect.com';
			}else if(location.host.indexOf("3dpregnancy")>-1){
				mtvn.btg.config.ReportSettings.Omniture["account"] = 'viaparents,via3dpregnancy';
				mtvn.btg.config.ReportSettings.Omniture["dynamicAccountSelection"] = 'false';
			}else if(location.host.indexOf("babynamesworld")>-1){
				mtvn.btg.config.ReportSettings.Omniture["account"] = 'viaparents,viabnw';
				mtvn.btg.config.ReportSettings.Omniture["dynamicAccountSelection"] = 'false';
			}else if(location.host.indexOf("wikiparenting")>-1){
				mtvn.btg.config.ReportSettings.Omniture["account"] = 'viaparents,viawikiparenting';
				mtvn.btg.config.ReportSettings.Omniture["dynamicAccountSelection"] = 'false';
			}else if(location.host.indexOf("petnamesworld")>-1){
				mtvn.btg.config.ReportSettings.Omniture["account"] = 'viaparents,viapetnamesworld';
				mtvn.btg.config.ReportSettings.Omniture["dynamicAccountSelection"] = 'false';
			}else{
				//PC Proper
				var suiteName="viaparents,viapc";
			
				if (location.pathname.indexOf("NotFound")!=-1){
					suiteName="viaparentsdev";
				}
			
				mtvn.btg.config.ReportSettings.Omniture["account"] = suiteName;
				mtvn.btg.config.ReportSettings.Omniture["dynamicAccountList"] = 'viaparentsdev=parentsconnect-d.mtvi.com,parentsconnect-q.mtvi.com';
				mtvn.btg.config.ReportSettings.Omniture["linkInternalFilters"] = 'javascript:,parentsconnect.com';
			}
			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){}
}
function parentsPicksNominateEvent()
{
	try{
		linkName="/Nominate/";
		if(parent)linkName+=parent.dispatcher.getAttribute("hier1");
		dispatcher.setAttribute("linkType","o");
		dispatcher.setAttribute("lnk",true);
		dispatcher.setAttribute("linkName",linkName);
		dispatcher.sendCall();	
	}catch(e){}
}
function parentsPicksThanksEvent()
{
	try{
		if(parent){
			linkName=parent.location.pathname;
			siteId = (linkName.indexOf("gocitykids")>-1)?"pclocal":"pc";
			dispatcher.setAttribute("pageName", "/Nomination Thanks/"+siteId+linkName);
			dispatcher.setAttribute("hier1", "Nomination Thanks/"+siteId+linkName);
			dispatcher.setAttribute("channel", siteId);
			dispatcher.sendCall();
		}
	}catch(e){}
}
function parentsPicksVoteEvent(nomineeName)
{
	try{
		linkName="/Vote/";
		linkName+=dispatcher.getAttribute("hier1")+"/"+nomineeName;
		dispatcher.setAttribute("linkType","o");
		dispatcher.setAttribute("lnk",true);
		dispatcher.setAttribute("linkName",linkName);
		dispatcher.sendCall();	
	}catch(e){}
}
function parentsPicksVotedFacebookShareEvent()
{
	try{
		linkName="/ShareMyVoteOnFacebook/";
		linkName+=dispatcher.getAttribute("hier1");
		dispatcher.setAttribute("linkType","o");
		dispatcher.setAttribute("lnk",true);
		dispatcher.setAttribute("linkName",linkName);
		dispatcher.sendCall();	
	}catch(e){}
}
function parentsPicksVotedTwitterShareEvent()
{
	try{
		linkName="/ShareMyVoteOnTwitter/";
		linkName+=dispatcher.getAttribute("hier1");
		dispatcher.setAttribute("linkType","o");
		dispatcher.setAttribute("lnk",true);
		dispatcher.setAttribute("linkName",linkName);
		dispatcher.sendCall();	
	}catch(e){}
}
function parentsPicks10CategoryVotedEvent()
{
	try{
		linkName="/Vote/AllTenCategory";
		dispatcher.setAttribute("linkType","o");
		dispatcher.setAttribute("lnk",true);
		dispatcher.setAttribute("linkName",linkName);
		dispatcher.sendCall();	
	}catch(e){}
}
function parentsPicksOnlinePromoInteractiveEvent(type,category,city,nomineeName)
{
	picksVendorBaseEvent("/OnlinePromotion/InteractiveBadge/",type+"/",category+"/",city+"/",nomineeName);
}
function parentsPicksOnlinePromoFacebookEvent(type,category,city,nomineeName)
{
	picksVendorBaseEvent("/OnlinePromotion/FacebookShare/",type+"/",category+"/",city+"/",nomineeName);
}
function parentsPicksOnlinePromoTwitterEvent(type,category,city,nomineeName)
{
	picksVendorBaseEvent("/OnlinePromotion/TwitterShare/",type+"/",category+"/",city+"/",nomineeName);
}
function parentsPicksOnlinePromoSMSEvent(type,category,city,nomineeName)
{
	picksVendorBaseEvent("/OnlinePromotion/SMS/",type+"/",category+"/",city+"/",nomineeName);
}
function parentsPicksOnlinePromoNewsletterEvent(type,category,city,nomineeName)
{
	picksVendorBaseEvent("/OnlinePromotion/NewsLetter/",type+"/",category+"/",city+"/",nomineeName);
}
function parentsPicksOfflinePromoBusinessCardEvent()
{
	picksVendorBaseEvent("/OfflinePromotion/BusinessCardsDownload","","","","");
}
function parentsPicksOfflinePromoTableTentEvent()
{
	picksVendorBaseEvent("/OfflinePromotion/TableTentsDownload","","","","");
}
function parentsPicksOfflinePromoDecalEvent()
{
	picksVendorBaseEvent("/OfflinePromotion/DecalDownload","","","","");
}
function parentsPicksOfflineFlyerEvent()
{
	picksVendorBaseEvent("/OfflinePromotion/FlyerDownload","","","","");
}
function picksVendorBaseEvent(eventType,type,category,city,nomineeName)
{
	try{
		linkName = eventType + type + category + city + nomineeName;
		dispatcher.setAttribute("linkType","o");
		dispatcher.setAttribute("lnk",true);
		dispatcher.setAttribute("linkName",linkName);
		dispatcher.sendCall();	
	}catch(e){}
}

function pageNameAppend(newValue)
{
	try{
		if(parent){
			linkName=parent.location.pathname;
			siteId = (linkName.indexOf("gocitykids")>-1)?"pclocal":"pc";
			dispatcher.setAttribute("pageName", siteId+location.pathname+" - "+newValue);
			dispatcher.setAttribute("hier1", siteId+location.pathname+"/"+newValue);
			dispatcher.setAttribute("channel", siteId);
			dispatcher.sendCall();
		}
	}catch(e){}
}
function facebookShareEvent(pageID)
{
	try{
		linkName="/FacebookShare/"+pageID;
		linkName+=dispatcher.getAttribute("hier1");
		dispatcher.setAttribute("linkType","o");
		dispatcher.setAttribute("lnk",true);
		dispatcher.setAttribute("linkName",linkName);
		dispatcher.sendCall();	
	}catch(e){}
}
function twitterShareEvent(pageID)
{
	try{
		linkName="/Twitter/"+pageID;
		linkName+=dispatcher.getAttribute("hier1");
		dispatcher.setAttribute("linkType","o");
		dispatcher.setAttribute("lnk",true);
		dispatcher.setAttribute("linkName",linkName);
		dispatcher.sendCall();	
	}catch(e){}
}
function buyLink(itemID)
{
	try{
		linkName="/GiftGuideBuyLink/"+itemID;
		linkName+=dispatcher.getAttribute("hier1");
		dispatcher.setAttribute("linkType","o");
		dispatcher.setAttribute("lnk",true);
		dispatcher.setAttribute("linkName",linkName);
		dispatcher.sendCall();	
	}catch(e){}
}
function loveIt(itemTitle)
{
	try{
		linkName="/LoveIt";
		dispatcher.setAttribute("linkType","o");
		dispatcher.setAttribute("lnk",true);
		dispatcher.setAttribute("linkName",linkName);
		dispatcher.setAttribute("eVar6",itemTitle);
		dispatcher.setAttribute("events","event5");
		dispatcher.sendCall();	
	}catch(e){}
}
function leaveIt(itemTitle)
{
	try{
		linkName="/LeaveIt";
		dispatcher.setAttribute("linkType","o");
		dispatcher.setAttribute("lnk",true);
		dispatcher.setAttribute("linkName",linkName);
		dispatcher.setAttribute("eVar6",itemTitle);
		dispatcher.setAttribute("events","event5");
		dispatcher.sendCall();	
	}catch(e){}
}
