var iPlayEvent = 0;
var cPlayIcon = "";
var lPosicionVideo = 0;
var lDuracionVideo = 0;

var lTimerTimeAvance = null;

function Pag_Play_PlayVideo(iIndice) {
	iPlayEvent = iIndice;
	// Mostrar el video que se seleccione
	try {
		objVideo.close();
	} catch(ex) {}
	try {
//		objVideo.open("igmp://" + getValue(CFG_DirEquipo, DEF_DirEquipo) + ":8208", null);
		objVideo.open("igmp://127.0.0.1:8208", null);
		iModoPlay = 1;
	} catch(ex) {
		alert("Pag_Play_PlayVideo: " + ex);
	}
	SendMsg("STOP", null);
	cPlayIcon = "play_playing.png";
	Pag_Play_Show();
	lPosicionVideo = 0;
	lDuracionVideo = 0;
	SendMsg("PLAY " + cValoresExplor[iPlayEvent][3], RefreshPlayDuration);
	lTimerPageHide = setTimeout("Pag_Play_Hide()",5000);
}

function Pag_Play_Show() {
//	var dFecha = new Date(cValoresExplor[iPlayEvent][1].substr(1,4),cValoresExplor[iPlayEvent][1].substr(5,2),cValoresExplor[iPlayEvent][1].substr(8,2),cValoresExplor[iPlayEvent][1].substr(11,5),0,0);
	var dFecha = new Date(cValoresExplor[iPlayEvent][1]);
	Page_Show("Pag_Play",
		 '<table id="Pag_Play" cellpadding="0" cellspacing="0">'
		+'<tr height="103px" id="Pag_Play_Icono" style="background-position: 600px 40px; background-image: url(' + cPlayIcon + '); background-repeat: no-repeat;">'
		+'	<td width="55px"/>'
		+'	<td width="590px"/>'
		+'	<td width="55px"/>'
		+'</tr>'
		+'<tr height="350px" valign="top">'
		+'	<td width="55px"/>'
		+'	<td id="Pag_Play_Form" width="590px" align="center"/>'
		+'	<td width="55px"/>'
		+'</tr>'
		+'<tr height="67px">'
		+'	<td width="55px"/>'
		+'	<td width="590px" height="67px" style="background-image: url(fondo_canal.png); background-repeat: no-repeat;">'
		+'		<table width="550px" height="67px" cellpadding="0" cellspacing="0" style="table-layout: fixed">'
		+'			<tr height="33px"><td width="30px"/><td id="Pag_Play_Tiempo" width="90px" class="font15">' + FormatearHora(lPosicionVideo) + '<td id="Pag_Play_Duracion" width="90px" class="font15">(' + FormatearHora(lDuracionVideo) + ')</td><td align="right" class="font15">' + FormatearFecha(dFecha) + '</td></tr>'
		+'			<tr height="33px"><td width="30px"/><td id="Pag_Play_Evento" colspan="3" class="font15" style="white-space: nowrap; text-overflow: ellipsis; overflow: hidden;">' + cValoresExplor[iPlayEvent][0] + '</td></tr>'
		+'		</table>'
		+'	</td>'
		+'	<td width="55px"/>'
		+'</tr>'
		+'</table>');
	SendMsg("POSITION", RefreshPlayPosition);
}

function Pag_Play_Hide() {
	Page_Show("Pag_Play", "");
	if (lTimerTimeAvance != null) {
		clearTimeout(lTimerTimeAvance);
	}
}

function Pag_Play_Close() {
	Pag_Canal_Show(iNumCanal, true);
	Pag_Explor_Restore();
}

var RefreshPlayDuration = function(data) {
	try {
		lDuracionVideo = parseInt(data);
		document.getElementById("Pag_Play_Duracion").innerHTML = "(" + FormatearHora(lDuracionVideo) + ")";
		RefreshPlayPosition(lPosicionVideo);
	} catch(ex) {}
}

var RefreshPlayPosition = function(data) {
	try {
		if (lTimerTimeAvance != null) {
			clearTimeout(lTimerTimeAvance);
			lTimerTimeAvance = null;
		}
		lPosicionVideo = parseInt(data);
		document.getElementById("Pag_Play_Tiempo").innerHTML = FormatearHora(lPosicionVideo);
		if ((cPaginaVisible == "Pag_Play") && (cPlayIcon == "play_playing.png")) {
			if (lPosicionVideo < lDuracionVideo) {
				lTimerTimeAvance = setTimeout("RefreshPlayPosition(" + (lPosicionVideo + 1) + ")",1000);
			} else {
				cPlayIcon = "play_pause.png";
				Pag_Play_Show();
			}
		}
	} catch(ex) {}
}

function Pag_Play_KeyDown(keyChar) {
	try {
		switch (keyChar) {
		case KEY_0: case KEY_1:
		case KEY_2: case KEY_3:
		case KEY_4: case KEY_5:
		case KEY_6: case KEY_7:
		case KEY_8: case KEY_9:
			Pag_Play_FWDTime_Show(String.fromCharCode(keyChar));
			return 0;
		case KEY_UP:
		case KEY_DOWN:
		case KEY_CHUP:
		case KEY_CHDN:
		case KEY_RIGHT:
		case KEY_LEFT:
		case KEY_OK:
			return 0;
		case KEY_STOP:
			iPlayEvent = 0;
			SendMsg("STOP", null);
			Pag_Play_Close();
			return 0;
		case KEY_PAUSE:
			SendMsg("PAUSE", null);
			cPlayIcon = "play_pause.png";
			Pag_Play_Show();
			lTimerPageHide = setTimeout("Pag_Play_Hide()",5000);
			return 0;
		case KEY_PLAY:
			SendMsg("RESUME", null);
			cPlayIcon = "play_playing.png";
			Pag_Play_Show();
			lTimerPageHide = setTimeout("Pag_Play_Hide()",5000);
			return 0;
		case KEY_HELP:
			Pag_Play_Show();
			lTimerPageHide = setTimeout("Pag_Play_Hide()",5000);
			return 0;
		case KEY_BACK:
			Pag_Play_Hide();
			return 0;
		case KEY_FWD:
		case KEY_RWD:
			Pag_Play_FWDTime_Show("3");
			return 0;
		}
	} catch(ex) {
		alert("Pag_Play_KeyDown: " + ex);
	}
	return 1;
}
