// JavaScript Document
//var _imgHost="img_ancho\/";
var _imgHost= "http:\/\/fsi.dmmotion.com\/10158\/img\/ancho\/"
//var _imgHost= "http:\/\/desarrollo-cstv.nspmotion.com\/10158\/img\/";

var selectedItem 		= [0, 0, 0];
var Destacados;
var selCanalera 		= new selection();
var selItem 			= new selection();
var selectedChannel 	= 0;
var nombreCustomList 	= "Favoritos";
var currentChannel 		= new Array(2);
var totalImpressions	= 0;
var Uvistos				= 0;
var favoritoInexistente = null;
var adLastView = new Date(), adInterval = 120000;
var isSafari = "";
var isOnreadyMedia = false;

function geid(x) {
	return document.getElementById(x);
}

showComents(false);
function insertPos(oId, params, w, h) {
	var oHl = geid(oId);
	if (typeof(oHl)!="undefined") {
		var newDiv = document.createElement("iframe");
		newDiv.style.width=w+"px";
		newDiv.style.height=h+"px";
		newDiv.frameBorder="0";
		newDiv.marginWidth="0px";
		oHl.innerHTML = "";
		
		var num_ord=Math.round(Math.random()*100000000);

		//newDiv.setAttribute("src",_imgHost+"iframe.htm?params="+escape(params)+"&ord="+escape(num_ord));
		newDiv.setAttribute("src",_imgHost+"iframe.htm?ord="+escape(num_ord));

		oHl.insertBefore(newDiv, null);
	}
}

function onPlayerInit(PyIndex) {
	geid("selCanales").style.visibility = "visible";
	
	// Inicialización
	geid("ADMPlayer").style.left = '0px';
	
	var player = admtv.Players[PyIndex];
	var customList = player.getCustomlist().length; 	//Favoritos -> CUSTOM LIST.
	var fVars= "PyIndex="+PyIndex;
	
	geid("ADMVotacion").innerHTML = genSWFcode("SWFBolsamaniaVotar", 450, 110, _imgHost+"votar.swf", fVars, "window");
	geid("Titulocanalera").innerHTML = "Canales:";
	geid("ADMVideosRelacionadosTexto").innerHTML = "<div class='imgFlecha'></div><div class='videosrelacionadosTexto'>Programas:</div>";
	
	geid("ADMBuscar").innerHTML= "<span class='buscar'>Buscador de videos</span><span class='buscarIn'><input name='admtv_term' id='admtv_term' disabled='disabled' style='width:420px; height:15px; top:0px; font-size:12px;' maxlength='160' type='text'/>&nbsp;&nbsp;<input name='admtv_term_bt' type='button' id='admtv_term_bt' style='width:70px; height:20px; font:Arial; font-size:11px;' value='Buscar'  /></span>";
	geid("admtv_term").disabled = false;
	geid("admtv_term").onkeypress = function (e) {
			if (typeof(e)=="undefined") e = event;
		buscarVideoInput(e, player.Id);
	}
	geid("admtv_term_bt").disabled = false;
	geid("admtv_term_bt").onclick = function () { buscarVideo(player.Id);}
	
	geid("ADMMasVistosCabecera").innerHTML = "<span class='imgFlecha'></span><span class='MasVotadosTitulo'>Mas vistos</span>";
	geid("ADMMasVotadosCabecera").innerHTML = "<span class='imgFlecha'></span><span class='MasVotadosTitulo'>Mas votados</span>";
	
	player.onContentChange = function (evObj) {
		var now = new Date();
		if (now-adLastView > adInterval) {
			adLastView = now;
			insertPos('banner72890', 'hueco=ESbm_seccionTV728&tipo_peticion=1', 728, 90);
		}
			
		var ItemId = this.getCurrentItemData();
		var Item = this.getItemById(ItemId.ChannelId, ItemId.PlaylistId, ItemId.Id)

		var ev = geid("ADMEstasViendo");
		var r = Item.Title.replace(/&/g, '&amp;');
		ev.innerHTML = textEllipsis(r, 35,true);
		initSelection(ItemId.Id);
		traerComents(ItemId, PyIndex);
		UpdateVotes(PyIndex)
   	} 
	
	player.onSearchFinished = function (evObj) {mostrarResultados(evObj, this.Id);}
	
	player.onMostViewedFetched = function (mv) {
		mostrarTop(mv, this.Id, geid("ADMMasVistos"),false);
	}
	
	player.onTopRatedFetched = function (ms) {
		mostrarTop(ms, this.Id, geid("ADMMasVotados"),true);
	}	
	
	player.onCommentsFetched = function (co) {mostrarComments(PyIndex,co); }
	
	if (typeof(player.startBy) != "undefined") {
		selectedItem = [
			player.getChannelIndexById(player.startBy[0]),
			(player.startBy[1]) ? player.getPlaylistIndexById(player.startBy[0], player.startBy[1]) : 0,
			(player.startBy[1] && player.startBy[2]) ? player.getItemIndexById(player.startBy[0], player.startBy[1], player.startBy[2]) : 0
		];
	}
	
	player.getMostViewed(5, 3); // ultimo mes
	player.getTopRated(5, 3);	// ultimo mes
	
	if(customList >0){
		//Tiene lista de favoritos HAY QUE AGREGAR El canal nombreCustomList;
		favoritoInexistente = false;
		showCanales(PyIndex, true);
	}else{
		//NO Tiene lista de favoritos NO SE AGREGA CANAL
		favoritoInexistente = true;
		showCanales(PyIndex, false);
	}
}


function initSelection(ItemId){
	try{		
		var oDiv = geid("td1"+ItemId);

		if(oDiv != null ) selItem.sel(["td1"+ItemId,"td2"+ItemId],["itemBg"]);
		else setTimeout("initSelection("+ItemId+")",500);		
	}catch(e) { setTimeout("initSelection("+ItemId+")",500); }	
 }

//Si se agrega un item por primera vez, que genere de nuevo el select de la canalera.

function onAddCustomList(rDTOAgregado,PyIndex) {
	if (favoritoInexistente) {	
		var player = admtv.Players[PyIndex];
    	var sel = geid("selCanales");
		var it = player.Content.Channels.length + 1;
		for (var i = 0; i<it; i++) {
			if(  i == (it - 1)  ) {
				//si es el ultimo
				sel.options[i] = new Option(nombreCustomList, i, false, (selectedChannel==i));
			} else {
				sel.options[i] = new Option(player.Content.Channels[i].Title, i, false, (selectedChannel==i));
			}
		}
		favoritoInexistente = false;
	}
 }

function showCanales(PyIndex, customList) {
	var player = admtv.Players[PyIndex];
	var sel = geid("selCanales");
	
	if(customList){
		var it = player.Content.Channels.length + 1;
		for (var i = 0; i<it; i++) {
			if( i == (it - 1) ){ sel.options[i] = new Option(nombreCustomList, i, false, (selectedChannel==i));} //si es el ultimo + 1 que agregue Favoritos.
			else{ sel.options[i] = new Option(player.Content.Channels[i].Title, i, false, (selectedChannel==i));}
		}
	}else{
		var it = player.Content.Channels.length ;
		for (var i = 0; i<it; i++) {
			var op = new Option(player.Content.Channels[i].Title, i, false, (selectedChannel==i));
			sel.options[i] = op;
		}
	}
	
	sel.disabled = false;
	sel.onchange = function () {
		selectedChannel = this.options[this.selectedIndex].value;
		setCurrentChannel(this.options[this.selectedIndex].text, nombreCustomList);
		showPlaylists(PyIndex,customList);
		geid("ADMVideosRelacionadosTexto").innerHTML = "<div class='imgFlecha'></div><div class='videosrelacionadosTexto'>Programas:</div>";
	}
	showPlaylists(PyIndex,customList);
 }

function showPlaylists(PyIndex, customList) {
	var oEl = geid("ADMPlayList");
    var player = admtv.Players[PyIndex];
	var u = '';
	
	if(selectedChannel == (parseInt(player.Content.Channels.length) )) {
		//es favoritos, No genero playlist. Solo muestro los items de addCustomList 
		showItems(PyIndex, null,true)
	} else {
		//no es favorito, genero las playlist.
		var u = "";
		if (selectedChannel != -1) {
			u+= showPlaylistContent(PyIndex, player.Content.Channels[selectedChannel]);
		} else {
			var it = player.Content.Channels.length;
			for (var i = 0; i<it; i++) {
				u+= showPlaylistContent(PyIndex, player.Content.Channels[i]);
			}
		}
		oEl.innerHTML = u;
	}
 }

function showPlaylistContent (PyIndex, ch) {
	var u = "";
	var it = ch.Playlists.length;
	for (var i = 0; i<it; i++) {
		var jt = ch.Playlists[i].Items.length;
		for (var j = 0; j<jt; j++) {
			u += generateItem(PyIndex, ch.Id, ch.Playlists[i].Id, ch.Playlists[i].Items[j].Id);
		}
	}
	return u;
 }

function showItems(PyIndex, PlIndex,customList) {
	var oHe = geid("ADMVideosRelacionadosTexto");
	var player = admtv.Players[PyIndex];
	var oEl = geid("ADMPlayList");
	oHe.style.display = "";
	var u = '';
	if (customList) {
		var it = player.getCustomlist().length;
		var its = player.getCustomlist();	
		oHe.innerHTML = '<div class="imgFlecha"></div><div class="videosrelacionadosTexto">Programas:</div>';
		if(it > 0) {
			for (var i = 0; i<it; i++) {u += generateItemCustomList(PyIndex,i,its[i] ); }
		}else{	u="<br>&nbsp; No hay videos en "+nombreCustomList+".";}
	}else{	
		var it = player.Content.Channels[selectedChannel].Playlists[PlIndex].Items.length;
		oHe.innerHTML = '<div class="imgFlecha"></div><div class="videosrelacionadosTexto">Programas:</div><div onclick="showPlaylists('+PyIndex+');restoreTitle();" style="width: 30px; height: 20px; position:absolute; left:470px;top:3px;color:#0033CC;font-family:Verdana,Arial,Helvetica,sans-serif;font-size:10px;font-weight:bold; cursor:pointer;text-decoration:underline"  />Volver</div>';
		
		for (var i = 0; i<it; i++){
			u += generateItem(PyIndex, player.Content.Channels[selectedChannel].Id, player.Content.Channels[selectedChannel].Playlists[PlIndex].Id, player.Content.Channels[selectedChannel].Playlists[PlIndex].Items[i].Id);
		}
	}
	oEl.innerHTML = u;
 }

function generateItemCustomList(PyIndex,indexItem, item) {
	var player = admtv.Players[PyIndex];
	var item = player.getItemById(item.ChannelId, item.PlaylistId, item.Id);
	var assetId = "ADM_AS_"+item.Id;
	var oncl =  "onclick='admtv.Players["+PyIndex+"].playCustomVideo("+indexItem+"); selItem.sel([\"td1"+item.Id+"\",\"td2"+item.Id+"\"],[\"itemBg\"]);'";	
	var u = "<table id='"+assetId+"'  "+oncl+ " border='0' cellspacing='0' cellpadding='0'><tr id='tdbg"+item.Id+"' height='40' style='cursor:pointer'";
	u += ">";
	u += "<td width='410' id='td1"+item.Id+"' >";
	u += "<span  class='itemsTitulo'>"+textEllipsis(item.Title, 25,true)+"<\/span><br \/>";
	var t="";
	if(isNaN(item.StartDateMS) == false) t = formatDate(item.StartDateMS); else t="";
	u += "<span class='itemsDuracion'>&nbsp;"+t+"<\/span><br>";
	u += "<span style='padding-left:10px;'>Visto: </span><span class='itemsVisto'>"+item.Impressions+" &nbsp;veces<\/span><br>";
	u += "<span style='padding-left:10px; font-weight:bolder; color:#913233' onclick='admtv.Players["+PyIndex+"].removeFromCustomlist("+indexItem+");showItems("+PyIndex+", "+null+","+true+")' onmouseover='this.style.color=\"red\";'   onmouseout='this.style.color=\"#913233\";'>Eliminar</span>";
	u += "<\/td>";
	u += "<td width='60'  style='padding:5px;' id='td2"+item.Id+"'><img src='"+admtv.getThumbnailURL(player.Content.Id, item, "m")+"' width='70' height='50' \/><\/td>";
	u += "<\/tr><\/table>";
	totalImpressions += item.Impressions;
	return u;
 }

function generateItem(PyIndex, ChId, PlId, ItId) {
	var player = admtv.Players[PyIndex];
	var channel = player.getChannelById(ChId);
	var playlist = player.getPlaylistById(ChId, PlId);
	var item = player.getItemById(ChId, PlId, ItId);
	var assetId = "ADM_AS_"+item.Id;
	
	totalImpressions = 0;
	
	for(var i in item.Assets){
		totalImpressions += item.Assets[i].Impressions;
	}
	
    var oncl =  "onclick='admtv.Players["+PyIndex+"].playVideo({ChannelId:"+channel.Id+", PlaylistId:"+playlist.Id+", Id:"+item.Id+"}); selItem.sel([\"td1"+item.Id+"\",\"td2"+item.Id+"\"],[\"itemBg\"]);'";	
	
	var u = "<table id='"+assetId+"'  "+oncl+ " border='0' cellspacing='0' cellpadding='0'><tr id='tdbg"+item.Id+"' height='40' style='cursor:pointer;'";
	u += ">";
	u += "<td width='410' id='td1"+item.Id+"' >";
	u += "<span  class='itemsTitulo'>"+textEllipsis(item.Title, 45,true)+"<\/span><br \/>";
	var t="";
	if(isNaN(item.StartDateMS) ==false) t = formatDate(item.StartDateMS); else t="";
	u += "<span class='itemsDuracion'>&nbsp;"+t+"<\/span><br>";
	u += "<span style='padding-left:10px;'>Visto: </span><span class='itemsVisto'>"+totalImpressions+" &nbsp;veces<\/span><br>";
	u += "<\/td>";
	u += "<td width='60'  style='padding:5px;' id='td2"+item.Id+"'><img src='"+admtv.getThumbnailURL(player.Content.Id, item, "m")+"' width='70' height='50' \/><\/td>";
	u += "<\/tr><\/table>";
	return u;
 }

function generarTop1(PyIndex, ChIndex, PlIndex, ItIndex, estado) {
	var player 		=   admtv.Players[PyIndex];
	var thisCanal 	= admtv.Players[PyIndex].Content.Channels[ChIndex];
	var thisPlaylist = thisCanal.Playlists[PlIndex];
	var thisItem 	= thisPlaylist.Items[ItIndex];
	var t="";
	if(isNaN(thisItem.StartDateMS) ==false) t = formatDate(thisItem.StartDateMS); else t="";
	var fecha 		= new Date(t);
	var item 		= player.getItemById(ChIndex, PlIndex, ItIndex);

	totalImpressions = 0;
	if(estado){
		for (var i in thisItem.Assets) totalImpressions += thisItem.Assets[i].Impressions;
	}else{
		totalImpressions = thisItem.Impressions
	}
	
	var oncl =  "onclick='admtv.Players["+PyIndex+"].playVideo({ChannelId:"+thisCanal.Id+", PlaylistId:"+thisPlaylist.Id+", Id:"+thisItem.Id+"}); selItem.sel([\"td1"+thisItem.Id+"\",\"td2"+thisItem.Id+"\"],[\"itemBg\"]);'";
	
	var u = "<table "+oncl+"  border='0' cellspacing='0' cellpadding='0'><tr id='tdbg"+thisItem.Id+"' height='40' style='cursor:pointer;'";
	u += ">";
	u += "<td width='410' id='td1"+thisItem.Id+"' >";
	u += "<span  class='itemsTitulo'>"+textEllipsis(thisItem.Title, 25,true)+"<\/span><br \/>";
	var t="";
	if(isNaN(thisItem.StartDateMS) ==false) t = formatDate(thisItem.StartDateMS); else t="";
	u += "<span class='itemsDuracion'>&nbsp;"+t+"<\/span><br>";
	u += "<span style='padding-left:10px;'>Visto: </span><span class='itemsVisto'>"+totalImpressions+" &nbsp;veces<\/span><br>";
	u += "<\/td>";
	u += "<td width='60'  style='padding:5px;' id='td2"+thisItem.Id+"'><img src='"+admtv.getThumbnailURL(player.Content.Id, thisItem, "m")+"' width='70' height='50' \/><\/td>";
	u += "<\/tr><\/table>";
	return u;
}

// Función para saber la Impresión de los Items
function checkImpression(PyIndex){
	var player 	= admtv.Players[PyIndex];
	var it 		= player.Content.Channels.length + 1;
	for (var i = 0; i<it; i++) {
		var thisCanal = admtv.Players[PyIndex].Content.Channels[i];
	}	
 }

//seteo el canal actual y el canal custom para luego comprobar si el seleccionado es el custom desde vote.swf
function setCurrentChannel(cc, customName){
	currentChannel[0] = cc;
	currentChannel[1] = customName;
 }

function getCurrentChannel(){
	return currentChannel;
 }

function UpdateVotes(PyIndex){	
	var player = admtv.Players[PyIndex];
	var mov2 = "SWFBolsamaniaVotar";
	
	var swfObj2 = (navigator.appName.indexOf("Microsoft") != -1) ? window[mov2] : document[mov2];
	
	if(typeof(swfObj2)== "undefined")
	{	setTimeout("UpdateVotes()", 100)}else{
	var ItemId = player.getCurrentItemInfo();
	var Item = player.getItemById(ItemId[0], ItemId[1], ItemId[2]);	
	var voteDto = Item.RangeVoting;
	swfObj2.update(player.Content.Id, ItemId[0], ItemId[1], Item ,voteDto);
	}
 }

//Clase de seleccion.
function selection(){
	var lastSel= null;
	this.sel = function(arrDiv,arrStyles){
		if (lastSel){	
			for (var i = 0 ; i < lastSel.length ; i++ ){ 
				try{	for(var j = 0 ; j < arrStyles.length; j++ ){	geid(lastSel[i]).className = arrStyles[i];}	}	catch (e){}
			}
		}
		
		for (i = 0 ; i < arrDiv.length ; i++ ){
			try{
				for( j = 0 ; j < arrStyles.length; j++ ){
					geid(arrDiv[i]).className = arrStyles[j]+"_S";
				}
			}catch (e){}				
		}
		lastSel = arrDiv ; 
	}
}

function restoreTitle(){
	geid("ADMVideosRelacionadosTexto").innerHTML = "<div class='imgFlecha'></div><div class='videosrelacionadosTexto'>Programas:</div>";
 }

function mostrarResultados(sr, id) {
	var PyIndex = admtv.getPlayerIndexById(id);
	var it = sr.length;
	var u = (it>0) ? "" : "No se encontraron v&iacute;deos.";
	for (var i=0; i<it; i++) {
	
			u += generateItem(PyIndex, sr[i]["ChannelId"], sr[i]["PlaylistId"], sr[i]["Id"]) ;//generateItem(PyIndex, chIndex, plIndex, itIndex);
    	     
	}
	geid("ADMPlayList").innerHTML = u ;
	geid("ADMVideosRelacionadosTexto").innerHTML ='<div class="imgFlecha"></div><div class="videosrelacionadosTexto">Resultados: </div><div onclick="showPlaylists('+PyIndex+');restoreTitle();" style="width: 30px; height: 20px;position:absolute;left:470px;top:3px;color:#0033CC;font-family:Verdana,Arial,Helvetica,sans-serif;font-size:10px;font-weight:bold; cursor:pointer;text-decoration:underline"  />Volver</div>';	
 }
 
function buscarVideo(PyId) {
	if (typeof(admtv.getPlayerById(PyId))!="undefined") {
	
		var s=geid("admtv_term").value.replace(/^\s*|\s*$/g,"");
		if (s.length>=1) {
			
			geid("ADMPlayList").innerHTML="Buscando...";
			admtv.getPlayerById(PyId).search(s);
		}
	}
 }

function buscarVideoInput(evObj, PyId) {	
	
	var keyCode = evObj.keyCode ? evObj.keyCode : evObj.which ? evObj.which : evObj.charCode; 
	if (keyCode == 13) {
		buscarVideo(PyId);
	}
 }

function generarTop(PyIndex, ChIndex, PlIndex, ItIndex, estado,Details) {

	var player =   admtv.Players[PyIndex];
	var thisCanal = admtv.Players[PyIndex].Content.Channels[ChIndex];
	var thisPlaylist = thisCanal.Playlists[PlIndex];
	var thisItem = thisPlaylist.Items[ItIndex];
	var t="";
	if(isNaN(thisItem.StartDateMS) ==false) t = formatDate(thisItem.StartDateMS); else t="";
	
	var fecha = new Date(t);
	var maxValue = 5 ;
	
	
	var value = (Details.Votes>0) ? Details.Total/Details.Votes : 0;
	var rangeV;	
	rangeV = 	(maxValue*value)/10;
		
	totalImpressions = 0;
	if(estado){
		for (var i in thisItem.Assets) totalImpressions += thisItem.Assets[i].Impressions;
	}else{
		totalImpressions = Details.Impressions;
	}
	
	var u = "<table width='460' height='40' style='cursor:pointer;padding-top:10px;' ";
	u += "onclick='smoothScroll(); admtv.Players["+PyIndex+"].playVideo({ChannelId:"+thisCanal.Id+", PlaylistId:"+thisPlaylist.Id+", Id:"+thisItem.Id+"})' ";
	u += "border='0' cellspacing='0' cellpadding='0'><tr><td width='60'  style='padding-left:10px;'>"
	u += "<img src='"+admtv.getThumbnailURL(player.Content.Id, thisItem, "s")+"'  width='55'/><br \/>";
	u += "<\/td><td>";
	u += "<span class='itemsTituloMost'>"+textEllipsis(thisItem.Title, 45,true)+"<\/span><br \/>";
    var t="";
	if(isNaN(thisItem.StartDateMS) == false) t = formatDate(thisItem.StartDateMS); else t="";
	u += "<span class='itemsDuracion'>&nbsp;"+t+"<\/span><br>";
	u += "<span style='padding-left:10px;font-family:Verdana,Arial,Helvetica,sans-serif; font-size:10px;'>Visto: </span><span class='itemsVisto'>"+totalImpressions+" &nbsp;veces<\/span><span style='padding-left:10px;font-family:Verdana,Arial,Helvetica,sans-serif; font-size:10px;'>&nbsp;Puntuaci&oacute;n: <\/span><span class='itemsVisto'>"+textEllipsis(String(rangeV), 4, false) +"<\/span>";
	u += "<\/td><\/tr>";
	u += "<\/table>";


	return u;
	
 }
 
function mostrarTop(mvObj, id, divHolder, estado) {
	var PyIndex = admtv.getPlayerIndexById(id);
	var it = mvObj.length;
	var u = "";

	for (var i=0; i<it; i++) {
		var chIndex = admtv.Players[PyIndex].getChannelIndexById(mvObj[i]["ChannelId"]);
		var plIndex = admtv.Players[PyIndex].getPlaylistIndexById(mvObj[i]["ChannelId"], mvObj[i]["PlaylistId"]);
		var itIndex = admtv.Players[PyIndex].getItemIndexById(mvObj[i]["ChannelId"], mvObj[i]["PlaylistId"], mvObj[i]["Id"]);
	
		if (typeof(itIndex)!="undefined") u+=generarTop(PyIndex, chIndex, plIndex, itIndex, estado, mvObj[i].Details);
	}
	divHolder.innerHTML=u;
}

function smoothScroll() {
	self.scrollTo(0, 200);
}


//Para los comentarios.//
function showMost(show){
	var masVotadosCon = geid("ADMMasVotadosCont");
	var masVistosCon = geid("ADMMasVistosCont");
	
	if(show){	
		showComents(false);
		masVotadosCon.style.display = "";
		masVistosCon.style.display = "";
	}else{	
		masVotadosCon.style.display = "none";
		masVistosCon.style.display = "none";
		showComents(true);
		
	}
 }


function mostrarComments(PyIndex,co){	
	geid("ADMComentarioEnviado").style.display = "none";
	geid("ADMComentarioEnviado").innerHTML = "Tu comentario ha sido enviado, muy pronto ser&aacute; publicado. Muchas gracias!";

	geid("ADMMostrarForm").innerHTML = "<span id='ADMMostrarFormTexto' >AGREGAR UN COMENTARIO</span>"
	geid("ADMMostrarForm").onclick =function(){ generateForm(PyIndex)}
	geid("ADMComentariosHeader").innerHTML = "<span class='imgFlecha'></span><span class='comentarioTitulo'>Comentarios ("+co.length+")</span>";
	geid("ADMComentariosSendHeader").innerHTML = "<span class='imgFlecha'></span><span class='comentarioTitulo'>Dejanos tu comentario:</span><div style='width: 30px; height: 20px; position: absolute; left:440px; top: 3px; color: rgb(0, 51, 204); font-family: Verdana,Arial,Helvetica,sans-serif; font-size: 10px; font-weight: bold; cursor: pointer; text-decoration: underline;' onclick='showMost("+true+");'>Cerrar</div>";
	
	var u = "";
	if (co.length > 0) {
		var it = co.length, i =-1;
		while(++i < it) {
			u+= genComment(co[i]);}
	} else u = "<br>&nbsp;Este video no posee comentarios.";
	
	geid("ADMComentarios").innerHTML = u;
	
	if(geid("ADMMostrarForm").style.display  == "none")
	{	geid("ADMMostrarForm").style.display  ="";
		geid("ADMForm").style.display = "none";
		geid("fHSMTV_sendButton").style.display = "none";
		geid("fHSMTV_cancelButton").style.display = "none";
		
	}
 }

function generateForm(PyIndex) {

var u =  "<table  width='378' border='0' cellspacing='2' cellpadding='0'>";
	u += "<tr><td align='right'>Tu nombre:</td><td align='left'><input class='CommentForms' name='fHSMTV_username' type='text' id='fHSMTV_username' maxlength='50' style='width:220px'/></td></tr>";
	u += "<tr><td align='right' valign='top'>Comentario:</td>";
	u += "<td align='left'><textarea class='CommentForms' name='fHSMTV_comment' rows='7' id='fHSMTV_comment' style='width:220px'></textarea>";
	u += "</td></tr>";
	u += "<tr><td colspan='2' style='background:#CAC9C9; color:#000000f; padding:5px; font-size:10px' align='center'>Ingresa el siguiente c&oacute;digo:<br />";
	u += "<table border='0' cellspacing='2' cellpadding='0'><tr><td><span id='HSMvalidationKey'></span></td><td><strong>&raquo;</strong></td><td>";
	u += "<input class='CommentForms' name='fHSMTV_keyword' type='text' id='fHSMTV_keyword' maxlength='4' style='width:80px' /></td></tr></table>";
	u += "</td></tr></table>";
	u += "<span name='fHSMTV_sendButton'  id='fHSMTV_sendButton' style='cursor:pointer;border:1px solid #CAC9C9; position:absolute; left:93px;top:230px;'  onmouseover='this.style.color=\"#FF662D\";'   onmouseout='this.style.color=\"#000000\";' >&nbsp;Enviar comentario&nbsp;</span>";
	u +="<span name='fHSMTV_cancelButton'  id='fHSMTV_cancelButton' style='cursor:pointer; border:1px solid #CAC9C9;position:absolute; left:253px;top:230px; 'onmouseover='this.style.color=\"#FF662D\";'   onmouseout='this.style.color=\"#000000\";' >&nbsp;Cancelar&nbsp;</span>";	
		geid("ADMForm").innerHTML =  u ;	
		geid("ADMForm").style.display = "none"
		mostrarForm(PyIndex);
	}


function mostrarForm(PyIndex) {
	 	
	if(geid("ADMForm").style.display == "none")
	{	
		geid("fHSMTV_cancelButton").onclick = function()
				{mostrarForm(PyIndex); }

		geid("ADMForm").style.display = ""; 
		geid("ADMMostrarForm").style.display = "none"; 
		geid("fHSMTV_keyword").value = "";
		geid("fHSMTV_comment").value = "";
		geid("HSMvalidationKey").innerHTML = '<img src="'+admtv.getValidationImg()+'" width="50" height="22" style="border: #666666 solid 1px;" \/>';
		var player = admtv.Players[PyIndex];
		var ItemId = player.getCurrentItemInfo();
		geid("fHSMTV_sendButton").onclick = function () 
		{
		
			var u = geid("fHSMTV_username").value;
			var kw = geid("fHSMTV_keyword").value;
			var co = geid("fHSMTV_comment").value;
			if (u!="") 
			{
				if (kw!="" && kw.length == 4) 
				{
					if (co!="") 
					{
						player.postComment({ChannelId:ItemId[0], PlaylistId:ItemId[1], Id:ItemId[2]}, kw, co,u);
						geid("ADMForm").style.display = "none";
						geid("ADMComentarioEnviado").style.display = "";
					} else alert("No has ingresado un COMENTARIO.");
				} else alert("Revisa el CODIGO DE SEGURIDAD, e intenta nuevamente.");
			} else alert("No has ingresado tu NOMBRE.");
		}
	}else
	{
		geid("ADMForm").style.display = "none"; 
		geid("ADMMostrarForm").style.display = ""; 
		geid("ADMComentarioEnviado").style.display = "none";
	}	
 }
 
function genComment(co) {
	var u = '';
		u+= '<table width="355" cellpadding="0" cellspacing="0">';
		u+= '<tr>';
			u+= '<td><hr style=" background-color:#999999;border:1px solid #CAC9C9;"><strong><span style="padding-left:8px">'+co.User+'</span><\/strong> ';
			var dat = new Date(co.Date);
			u+= '<span style="color:#999999; font-size:10px">('+formatDate(dat)+')<\/span>';
			u+= '<\/td>';
		u+= '<\/tr>';
		u+= '<tr>';
			u+= '<td style="padding:8px; padding-bottom:16px; color:#999999">'+co.Comment+'<\/td>';
		u+= '<\/tr>';
		u+= '<\/table>';
	return u;
}

function traerComents(ItemId, PyIndex){	
	var player = admtv.Players[PyIndex];
	
	player.getComments({ChannelId:ItemId.ChannelId,PlaylistId:ItemId.PlaylistId, Id:ItemId.Id});
 }

function showComents(show){
	var comentariosCont = geid("ADMComentariosCont");
	if(show){
		comentariosCont.style.display = "";
		geid("fHSMTV_sendButton").style.display = "";
		geid("fHSMTV_cancelButton").style.display = "";
		
	}else{
		comentariosCont.style.display = "none";
		
	}
 }

//otros
function formatTime(t) {
	var s = Math.floor((t % 60000) / 1000);
	var m = Math.floor(t / 60000);
	
	if (s<10) {
		s = ("0"+s);
	}
	if (m<10) {
		m = ("0"+m);
	}
	return m+":"+s;
 }

function formatDate(_d) {
		
	var d = new Date(_d);
	var dia = (d.getDate()<10) ? "0"+d.getDate() : d.getDate();
	var mes = (d.getMonth()<9) ? "0"+(d.getMonth()+1) : d.getMonth()+1;
	var hora = (d.getHours()<10) ? "0"+d.getHours() : d.getHours();
	var minu = (d.getMinutes()<10) ? "0"+d.getMinutes() : d.getMinutes();
	
	return dia+"-"+mes+"-"+d.getFullYear();
 }

function textEllipsis(t, l, agregarSuspensivos) {
	var u = t.substr(0, l);
	
	if(agregarSuspensivos){if (u != t) u+="...";}
	
	return u;
 }

function genSWFcode(id, width, height, file, fv, wmode, bgcolor) {
	
	if (typeof(fv)=="undefined") fv="";
	if (typeof(wmode)=="undefined") wmode="window";
	var h = '';
	h+= '<object id="'+id+'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http:\/\/download.macromedia.com\/pub\/shockwave\/cabs\/flash\/swflash.cab#version=8,0,0,0" width="'+width+'" height="'+height+'"><param name=movie value="'+file+'" \/><param name=quality value=high \/><param name=menu value=false \/>';
	if (typeof(bgcolor)!="undefined") h+= '<param name="bgcolor" value="'+bgcolor+'" \/>';
	h+= '<param name="wmode" value="'+wmode+'" \/>';
	h+= '<param name=FlashVars value="'+fv+'" \/>';
	h+= '<param name="allowScriptAccess" value="always" \/><param name="allowFullScreen" value="true" \/>';
	h+= '<embed name="'+id+'" src="'+file+'" menu=false quality=high width="'+width+'" height="'+height+'" type="application\/x-shockwave-flash" pluginspace="http:\/\/www.macromedia.com\/go\/getflashplayer" wmode="'+wmode+'"';
	if (typeof(bgcolor)!="undefined") h+= ' bgcolor="'+bgcolor+'"';
	h+= ' FlashVars="'+fv+'"';
	h+= ' allowScriptAccess="always" allowFullScreen="true"><\/embed>';
	h+= '<\/object>';
	return h;
}
