if(typeof MTVi!="undefined"){if(typeof MTVi.reporting=="undefined"){MTVi.reporting={};}}
MTVi.reporting.Dispatcher=new function(){
	this.version="2.0";
	try{this.widget=MTVi.reporting.Widget;}catch(e){}
	this.send=function(){
		try{
			if(MTVi.util.isDefined(this.widget.un)){this.widget.t();}
		}catch(e){try{MTVi.logger.JsError(e);}catch(e){}}
	};
	this.getNewRepeat=function(){
		try{
			return this.widget.getNewRepeat();
		}catch(e){}
	};
	this.setAccountVars=function(o){
		try{
			this.widget.setAccount(o.account);
			this.widget.setAttribute("dynamicAccountSelection",o.dynamic);
			this.widget.setAttribute("dynamicAccountList",o.list);
			this.widget.setAttribute("linkInternalFilters",o.filters);
		}catch(e){}
	};
	this.setValues=function(o){
		try{
			for(var i in o){this.widget.setAttribute(i,o[i]);}
		}catch(e){}
	};
	this.config=function(){//when call should not be automatic
		try{this.setAccountVars(MTVi.reporting.Config);}catch(e){}
		try{this.setValues(MTVi.reporting.Map());}catch(e){}
	};
	this.sendCall=function(){
		try{
			this.setAccountVars(MTVi.reporting.Config);
			try{this.setValues(MTVi.reporting.Map());}catch(e){}
			try{this.setValues(MTVi.config.SectionSetup);}catch(e){}
			this.send();
		}catch(e){try{MTVi.logger.JsError(e);}catch(e){}}
	};
	this.setThirdPartyData=function(){
		try{
			var pn=location.href;
			pn=pn.replace(/^.*www\.(.*)\.com/g,"");
			pn=pn.replace(/^.*(.*)\.com/g,"");
			pn=MTVi.config.Get.channel+pn;
			this.widget.setAttribute("pageName","/"+pn);
			this.widget.setAttribute("hier1",pn);
			this.widget.setAttribute("channel",MTVi.config.Get.channel);
			this.widget.setAttribute(MTVi.config.Get.site,MTVi.config.Get.channel);
		}catch(e){try{MTVi.logger.JsError(e);}catch(e){}}
	};
	this.sendThirdPartyCall=function(){
		try{
			this.setAccountVars(MTVi.config.Get);
			this.setThirdPartyData();
			try{this.setValues(MTVi.reporting.Map());}catch(e){}
			this.send();
		}catch(e){try{MTVi.logger.JsError(e);}catch(e){}}
	};
	this.sendLinkEvent=function(name){
		try{
			var hier2=this.widget.getAttribute("hier2");
			this.widget=MTVi.reporting.Widget;
			this.config();
			this.setValues({linkType:"o",lnk:true,linkName:name,hier2:""});
			this.send();
			this.widget.setAttribute("hier2",hier2);
		}catch(e){try{MTVi.logger.JsError(e);}catch(e){}}
	};
	this.getBaseUrl=function(acc){
		try{
			this.config();
			var vendorUrl=".112.2o7.net/b/ss/"; // hardcoded in h_code
			if(acc != null){
				return("http"+(this.widget.ssl?'s':'')+"://"+acc+vendorUrl+acc+"/1/");
			}else{
				return("http"+(this.widget.ssl?'s':'')+"://"+this.widget.un+vendorUrl+this.widget.un+"/1/");
			}
		}catch(e){try{MTVi.logger.JsError(e);}catch(e){}}
	};
	this.sendFailedSearch=function(v){
		try{
			if(MTVi.util.isDefined(v)){
				var aImg;
				this.config();		
				var un_parts= this.widget.un.split(",");
				for(x=0;x<un_parts.length;x++){
					aImg=document.createElement('img')
					aImg.src=this.getBaseUrl(un_parts[x])+"EMAIL?pageName=FAILED+SEARCH&v4="+v;
					aImg.id="failedSearchCall_"+x;
					document.getElementsByTagName('body')[0].appendChild(aImg);
					almg=null;
				}
			}
		}catch(e){try{MTVi.logger.JsError(e);}catch(e){}}
	};
	this.setAttribute=function(k,v){this.widget.setAttribute(k,v);};
	this.getAttribute=function(k){return this.widget.getAttribute(k);};
	try{if(MTVi.util.isDefined(MTVi.config.Get.remote)){this.sendThirdPartyCall();}}catch(e){}
	try{if(MTVi.util.isDefined(MTVi.config.sendReportingCall)){this.sendCall();}}catch(e){}
};
