// Metrics Report
var s_clickLocation=""; var s_action=""; var s_contentType=""; var s_contentID=""; var s_userID=""; var _reportImg; var _reportMetricsURL;

function initReporting(){ 
	_reportImg=new Image(1,1); 
	}

function sendReporting(){
	if (! _reportImg) return;
	var argv = sendReporting.arguments;

	var cl;var a; var ct; var ci; var uid;

	// force with explicit for plugin JS
	if ( argv.length ) {
		 cl = argv[0]; a=argv[1]; ct=argv[2]; ci=argv[3]; uid=argv[4];
	}

	// no argz :: moz flash, sets them globally
	else {
		cl  = s_clickLocation;
		a   = s_action;
		ct  = s_contentType;
		ci  = s_contentID;
		uid = s_userID;

	}
	
	_dispatchReport( cl,a,ct,ci,uid);
}


// communicates with reporting tool
// clickLocation, action, contentType, contentID, userID
var findNonNum = /\D/;
function _dispatchReport ( cl,a,ct,ci,uid ) {
  var userId = uid + '';
  if (userId != null && userId != 'null' && findNonNum.test(userId)) {userId = 'u:' + userId;}
	var i= _getReportMetricsURL() + "?" + "clickLocation=" + escape(cl) + "&action=" + a + "&contentType=" + escape(ct) + "&contentID=" + escape(ci) + "&userID=" + userId + "&random=" + new Date().getTime();
	 
	_reportImg.src=i;
}


// build complete URL using config metadata
function _getReportMetricsURL() {

	if ( _reportMetricsURL == null ) {

		var _r = com.cisco.dms.vp.ui.videoPortalConfigurationMetadata.configuration.resources;

		_reportMetricsURL =
						location.protocol + "//" +
						( _r.metricsReportServer == null ? location.host :  null ) + ":" +
						_r.metricsReportPort  + _r.metricsReportURL

	}

return _reportMetricsURL;
}

