document.write("<script language=\"JavaScript\" for=\"MediaPlayer\" event=\"PlayStateChange(NewState)\">playStateChange(NewState);<\/script>");

var hasValidDuration = false;
var chkLive = '<<@VODONLY@>>';
var isLive = false;
if (chkLive == 'hidden' || getvar_parent('mediaUrl') != ''){
	isLive = true;
}
var pid = getvar_parent('i');
var uid = getvar_parent('u');
var trackingUrl = decodeURIComponent(getvar_parent('trackingUrl'));
var trackingID = getvar_parent('trackingID');
var eventID = getvar_parent('eventID');
var webDirectoryID = getvar_parent('webDirectoryID');
var streamPointID = -1;
var postCount = 0;
var lowBandwidth = 0;
var highBandwidth = 0;
var averageBandwidth = 0;
var lowFrameRate = 0;
var highFrameRate = 0;
var averageFrameRate = 0;
var redirFrmLoc = 'index.htm';
var cookieUpdRate = '<<@CLIENTSIDE_REFRESH@>>';
if(getvar_parent('trackingInterval') != '')
{
	cookieUpdRate = getvar_parent('trackingInterval');
}
var dataUpdRate = '<<@SERVERSIDE_REFRESH@>>';
var statsFULL = 1;
var clipFinished = false;
var mediaLength = 0;
var openerReloaded = false;
var playing = true;
var makeFinalPost = true;
var playerType = 1; //1 = ms, 2 = real
var clipStartTime = '';
var clipEndTime = '';
var viewingEndTime = '';
var viewingStartTime = '';
var videoStartTime = '';
var clipDuration = '';
cookieUpdRate = Math.floor(cookieUpdRate * 1000);
dataUpdRate = Math.floor(dataUpdRate * 1000);

window.onunload = function()
{
	try
	{
		window.top.opener.location.reload(1);
	}
	catch (e)
	{
	}
}

function playStateChange(NewState)
{
	try
	{
		playerType = 1;
		if (playing && NewState != 3)
		{
			makeFinalPost = true;
		}
		playing = (NewState == 3);
		if(NewState == 8)
		{
			clipFinished = true;
		}
	}
	catch (e)
	{
	}
}

function getcookie(cookiename) {
	var cookiestring=""+document.cookie;
	var index1=cookiestring.indexOf(cookiename);
	if (index1==-1 || cookiename=="") return "";
	var index2=cookiestring.indexOf(';',index1);
	if (index2==-1) index2=cookiestring.length;
	return unescape(cookiestring.substring(index1+cookiename.length+1,index2));
}

function conv_jsTime2Sql(time_ms){
	tempJs = parseInt(time_ms); 
	t = new Date(tempJs);
	tDay = t.getDay(); // actual day
	tMonth = new String(t.getMonth() + 1); // js 0-11 for months
	tDate = new String(t.getDate());
	tYear = new String(t.getFullYear());
	tHours = new String(t.getHours());
	tMinutes = new String(t.getMinutes());
	tSeconds = new String(t.getSeconds());
	if (tMinutes < 10) tMinutes = new String('0' + tMinutes);
	if (tSeconds < 10) tSeconds = new String('0' + tSeconds);
	tMTemp = tMonth + '/' + tDate + '/' + tYear + ' ' + tHours + ':' + tMinutes + ':' + tSeconds;
	var sqlTime = new String(tMTemp);
	return(sqlTime);
}

function writeCookie_CurPos(f) {
	if (playing || makeFinalPost)
	{
		makeFinalPost = false;
		var oldClipEndTime = clipEndTime;
		if (mediaLength == 0) 
		{
			if(ie)
				mediaLength = self.document.MediaPlayer.currentMedia.duration;
			else
				mediaLength = '505';
		}
		var initClipPos = 0;
		clipStartTime = initClipPos;
		var getWindowsPos = 0;
		if(ie)
		{
			var targetClip = self.document.MediaPlayer.controls;
			getWindowsPos = targetClip.currentPosition;
		}
		else
		{
			var currentDate = new Date();
			getWindowsPos = (currentDate - videoStartTime) / 1000;
		}
		getWindowsPos = Math.floor(getWindowsPos);
		if (clipFinished)
		{
			getWindowsPos = Math.floor(mediaLength)
			if (!openerReloaded)
			{
				try
				{
					window.top.opener.location.reload(1);
				}
				catch (e)
				{
				}
				openerReloaded = true;
			}
		}
		clipEndTime = getWindowsPos;
		var cookieDate = new Date();
		var cookieDate_ms = cookieDate.getTime();
		viewingEndTime = cookieDate_ms;
		var viewerProg = clipEndTime;
		var viewerTime = viewingEndTime;
		var startTime = viewingStartTime;
		viewerT = conv_jsTime2Sql(viewerTime);
		startT = conv_jsTime2Sql(startTime);
		postCount++;
		var currentBandwidth = self.document.MediaPlayer.Network.bandWidth;
		if ((currentBandwidth < lowBandwidth || lowBandwidth == 0) && currentBandwidth != 0)
		{
			lowBandwidth = currentBandwidth;
		}
		if (currentBandwidth > highBandwidth)
		{
			highBandwidth = currentBandwidth;
		}
		if (currentBandwidth > 0)
		{
			averageBandwidth = ((averageBandwidth * (postCount - 1)) + currentBandwidth) / postCount;
		}
		
		var currentFrameRate = 0;
		var winVistaCheck = navigator.userAgent.indexOf("NT 6.")
		if (winVistaCheck == -1)
		{
			var currentFrameRate = self.document.MediaPlayer.Network.frameRate;
			if ((currentFrameRate < lowFrameRate || lowFrameRate == 0) && currentFrameRate != 0)
			{
				lowFrameRate = currentFrameRate;
			}
			if (currentFrameRate > highFrameRate)
			{
				highFrameRate = currentFrameRate;
			}
			if (currentFrameRate > 0)
			{
				averageFrameRate = ((averageFrameRate * (postCount - 1)) + currentFrameRate) / postCount;
			}
		}
		
		var framesSkippedCheck = 0;
		if (winVistaCheck == -1)
		{
			framesSkippedCheck = self.document.MediaPlayer.network.framesSkipped;
		}
		
		if (trackingUrl != '')
		{
			var redirectUrl = trackingUrl +
				'?trackingID=' + encodeURIComponent(trackingID) +
				'&presentationID=' + encodeURIComponent(pid) + 
				'&eventID=' + encodeURIComponent(eventID) + 
				'&viewerID=' + encodeURIComponent(uid) +
				'&viewingStartTime=' + encodeURIComponent(viewingStartTime) +
				'&viewingEndTime=' + encodeURIComponent(viewingEndTime) +
				'&clipStartTime=' + encodeURIComponent(clipStartTime) + 
				'&clipEndTime=' + encodeURIComponent(clipEndTime) +
				'&lastDateTracked=' + encodeURIComponent(new Date()) +
				'&isFinished=' + encodeURIComponent(clipFinished) +
				'&clipDuration=' + encodeURIComponent(mediaLength) +
				'&isLive=' + encodeURIComponent(isLive) +
				'&baseURL=' + encodeURIComponent('http://accordent.PowerStream.NET/008/00102/070726dg2a/') +
				'&lowBandwidth=' + encodeURIComponent(lowBandwidth) +
				'&highBandwidth=' + encodeURIComponent(highBandwidth) +
				'&averageBandwidth=' + encodeURIComponent(averageBandwidth) +
				'&bitrate=' + encodeURIComponent(self.document.MediaPlayer.Network.bitRate) +
				'&bufferingCount=' + encodeURIComponent(replaceZeroWithEmptyString(self.document.MediaPlayer.Network.bufferingCount)) +
				'&bufferingTime=' + encodeURIComponent(replaceZeroWithEmptyString(self.document.MediaPlayer.Network.bufferingTime)) +
				'&lowFrameRate=' + encodeURIComponent(lowFrameRate) +
				'&highFrameRate=' + encodeURIComponent(highFrameRate) +
				'&averageFrameRate=' + encodeURIComponent(averageFrameRate) +
				'&framesSkipped=' + encodeURIComponent(replaceZeroWithEmptyString(framesSkippedCheck)) +
				'&lostPackets=' + encodeURIComponent(replaceZeroWithEmptyString(self.document.MediaPlayer.Network.lostPackets)) +
				'&receivedPackets=' + encodeURIComponent(replaceZeroWithEmptyString(self.document.MediaPlayer.Network.receivedPackets)) +
				'&recoveredPackets=' + encodeURIComponent(replaceZeroWithEmptyString(self.document.MediaPlayer.Network.recoveredPackets)) +
				'&playerType=' + encodeURIComponent(playerType) +
				'&versionInfo=' + encodeURIComponent(self.document.MediaPlayer.versionInfo) +
				'&postCount=' + postCount +
				'&webDirectoryID=' + webDirectoryID +
				'&streamPointID=' + streamPointID;
			document.getElementById('trackingImage').src = redirectUrl;
		}
	}
}

function writeCookie_Close() {
	var initClipPos = 0;
	clipStartTime = initClipPos;
	var targetClip = self.document.MediaPlayer.controls;
	var getWindowsPos = targetClip.currentPosition;
	getWindowsPos = Math.floor(getWindowsPos);
	clipEndTime = getWindowsPos;
	var cookieDate = new Date();
	var cookieDate_ms = cookieDate.getTime();
	viewingEndTime = cookieDate_ms;
	var viewerProg = clipEndTime;
	var viewerTime = viewingEndTime;
	var startTime = viewingStartTime;
	viewerT = conv_jsTime2Sql(viewerTime);
	startT = conv_jsTime2Sql(startTime);
	closeButtonHit();
}

function closeButtonHit() {
	
}

function load_window(){
	
}

function exit_window(){
	window.setTimeout("window.top.close()",1000);
	writeCookie_Close();
}

function init_Load(){
	tempInit = new Date();
	initTimeStamp = tempInit.getTime();
	viewingStartTime = initTimeStamp;
	chkFrames();
}

function actualTimeViewed() {
	initTm = viewingStartTime;
	curTm = viewingEndTime;
	timeVw = Math.ceil( (curTm - initTm)/1000 );
	return(timeVw);
}

function clearIntval() {
	clock_timer = window.clearInterval(clock_timer);
}

function chkFrames(){
	if (document.getElementById('trackingImage')) {
		clock_timer = window.setInterval("writeCookie_CurPos()",cookieUpdRate);
		currentPID = window.setInterval("getContentID()", cookieUpdRate);
	} else {
		window.location = redirFrmLoc;
	}
}

function getContentID()
{
    var vid = self.document.MediaPlayer;
    var pl = vid.currentPlaylist;
    var plItem;
    var entryIndex;
    var attrName;
    var attrVal;
        
    if(streamPointID < 0)
    {
        if(vid.playState == 3)
        {
            for (var i=0; i < pl.count; i++)
            {            
                if (vid.currentmedia.isIdentical(pl.item(i)))
                {
                    entryIndex = i;
                }
            }
            plItem = pl.item(entryIndex);            
            streamPointID = plItem.getItemInfo('ID');            
        }
    }   
}

function ck_Duration() {
	var ckDuration = 0;
    var state;
	var vid = self.document.MediaPlayer;
	state = vid.PlayState;
	if (state == 3) ckDuration = 1;
	return(ckDuration);
}

function getDuration() {
	var currentDuration;
	if(ie)
	{
		var state;
		var vid = self.document.MediaPlayer;
		state = vid.PlayState;
		if (state == 3) currentDuration = vid.currentMedia.duration;
	}
	else
	{
		currentDuration = '505';
	}
	return(currentDuration);
}

function getError() {
	var curError;
	var vid = self.document.MediaPlayer;
	curError = vid.error.errorCount;
	return(curError);
}

function updateChp(){
	if (window.top.chapters && window.top.chapters.sync){
		var targetClip = self.document.MediaPlayer.controls;
		var curTime = targetClip.currentPosition;
		window.top.chapters.genSync(curTime);
	}
}

var init = 0;

function errorFxn(errCnt){
	window.clearInterval(idTmr);
}


var diplayDuration = '';

function getDurationCk() {
	if(!window.top.video) 
	{
		window.clearInterval(idTmr);
		document.write('Media files does not exist...');
		self.document.cookie = 'pres_error=1';
	} 
	else if (window.top.video.MediaPlayer) 
	{
		var chkError = window.top.video.getError();
		if (chkError == 0)
		{
			var durationChk = 0; 
			durationChk = window.top.video.ck_Duration();
			if (durationChk > 0) 
			{
				window.clearInterval(idTmr);
				setDurationCookie();
				hasValidDuration = true;
				diplayDuration = durationChk;
			}

		} 
		else 
		{
			errorFxn(chkError);
		}
	}
	else
	{
		if (videoStartTime == '')
		{
			videoStartTime = (new Date()).getTime();
		}
		window.clearInterval(idTmr);
		setDurationCookie();
		hasValidDuration = true;
		diplayDuration = '505';
	}

	if(hasValidDuration)
	{
		if(pid != '' && uid != '')
		{
			var myurl;
			if (clipEndTime == '')
			{
				myurl = 'clear.asp?pid=' + pid + '&uid=' + uid + '&trackingUrl=' + trackingUrl;
			}
			else
			{
				myurl = 'track.asp?pid=' + pid + '&uid=' + uid + '&trackingUrl=' + trackingUrl;
			}
		}
	}
}
	
function getMediaDurationScan(){
	init_Load();
	if(isLive)
	{
		clipDuration = 999999999;
	} 
	else 
	{
		idTmr = window.setInterval('getDurationCk()',50);
	}
}

function setDurationCookie(){
	window.clearInterval(idTmr);
	var localClipDuration = getDuration();
	var localClipDuration = Math.floor(localClipDuration);
	clipDuration = localClipDuration;
	return(localClipDuration);
}

var nowTime = new Date();
nowTime = new String(nowTime.getTime());

function getvar_parent(el, case_sensitive) { //el=str, case_sensitive=bool
	var rs="";
	if(!case_sensitive) rs="i";
	var urls = new String(window.parent.location);
	var re = new RegExp( "\\?[\\w\\W]*"+ el +"=([^\\&\\?#]*)", rs );
	var arr = re.exec(urls);
	if(arr && arr.length>1) return arr[1];
	else return '';
}

clipDuration = 0;

function replaceZeroWithEmptyString(intValue)
{
	if (intValue == 0)
	{
		return "";
	}
	else
	{
		return intValue;
	}
}
