// Libreria general v0.004.

var sScript = '<scr'+'ipt src="http://217.116.22.243/especiales/libs/msn_i_hits.js" type="text/javascript" language="JavaScript"></scr'+'ipt>'
document.write(sScript);

var versionWeb = "0.105";

if (typeof(oIGZ)!="undefined") 	{
	oIGZ.f_require ("i_core",0.789);
	oIGZ.f_require ("i_igz" ,0.739);
}else{
	alert ("Falta la libreria o el ID de 'i_core.js' o no existe 'i_igz.js'")
}

var BUTTON_A = ["BotA_Bg", "BotA_TopLeft", "BotA_Top", "BotA_TopRight", "BotA_Right", "BotA_BottomRight", "BotA_Bottom", "BotA_BottomLeft", "BotA_Left"];
var BUTTON_B = ["BotB_Bg", "BotB_TopLeft", "BotB_Top", "BotB_TopRight", "BotB_Right", "BotB_BottomRight", "BotB_Bottom", "BotB_BottomLeft", "BotB_Left"];
var BUTTON_C = ["BotC_Bg", "BotC_TopLeft", "BotC_Top", "BotC_TopRight", "BotC_Right", "BotC_BottomRight", "BotC_Bottom", "BotC_BottomLeft", "BotC_Left"];

if ( oIGZ.f_checkLib("i_gfx", 0.185) ) {
	if ( oIGZ.f_checkLib("i_exml", 1.216)) {

		oWinFrame = new IWIN("oWinFrame");

		oWinFrame.f_defineTopEXML("<TABLE cellpadding=0 cellspacing=0 border=0'><TR>"
							   +"<TD class='IWinTopLeftIcoBg IWinTopLeftIcoSize' nowrap='nowrap'>&#160;</TD>"
							   +"<TD class='IWinTopBg IWinMSGTit' width='100%' onmousedown='<MOVE_ON />; return false' ><TITLE /></TD>"
							   +"<TD onclick='<EVENT_CLOSE />' class='IWinTopCloseBg IWinTopCloseSize' nowrap='nowrap' onmouseover='FHON(this)' onmouseout='FHOFF()' fh_tit='Cerrar ventana'>&#160;</TD>"
							   +"</TR></TABLE>"
						       );

		oWinFrame.f_build ("<TABLE cellpadding=0 cellspacing=0 border=0 width=<SIZEX /> >"
						  +"<TR>"
						  +"<TD class='IWinTopLeftBg IWinTopLeftSize' nowrap='nowrap'>&#160;</TD>"
						  +"<TD width='100%'><TOP /></TD>"
						  +"<TD class='IWinTopRightBg IWinTopRightSize' nowrap='nowrap'>&#160;</TD>"
						  +"</TR>"
						  +"<TR>"
						  +"<TD class='IWinMidLeftBg IWinMidLeftSize' nowrap='nowrap'>&#160;</TD>"
						  +"<TD width='100%' style='background: #FFF;'><BODY /></TD>"
						  +"<TD class='IWinMidRightBg IWinMidRightSize' nowrap='nowrap'>&#160;</TD>"
						  +"</TR>"
						  +"<TR>"
						  +"<TD class='IWinBotLeftBg IWinBotLeftSize' nowrap='nowrap'>&#160;</TD>"
						  +"<TD class='IWinBotBg IWinBotSize' width='100%' nowrap='nowrap'>&#160;</TD>"
						  +"<TD class='IWinBotRightBg IWinBotRightSize' nowrap='nowrap'>&#160;</TD>"
						  +"</TR>"
						  +"</TABLE>"
						  );

	}
}

var g_sImgPath = "/files/";
var g_sCategoria = "";
var g_sContenido = "";
var a_vValoracion = ['0', '1', '2', '3', '4', '5'];

function DrawTitulo(sTitulo) {
	return sTitulo;
}
function PrintTitulo(sTitulo) {
	document.write( DrawTitulo(sTitulo) );
}

function DrawComboValoracion(sNombreCombo) {
	var sHTML = DrawCombo(sNombreCombo, "", "", a_vValoracion, a_vValoracion);
	return sHTML;
}
function PrintComboValoracion(sNombreCombo) {
	document.write( DrawComboValoracion(sNombreCombo) );
}

function CloseWinFrame() {
	if (parent.oWinFrame) {
		parent.oWinFrame.f_close();
	}
}

function DrawRobapaginas() {
	return "Robapáginas";
}
function PrintRobapaginas() {
	document.write( DrawRobapaginas() );
}

function DrawValoracion(nValoracion, nHeight) {
	if (nValoracion == null || nValoracion == '' || nValoracion > 5 || nValoracion < 0)  nValoracion = 0;
	return "<IMG src='"+ oIGZ.m_sRootPath +"/pix/star0"+ nValoracion +".gif' "+ (nHeight ? "height='"+ nHeight +"'" : "") +"/>";
}
function PrintValoracion(nValoracion, nHeight) {
	document.write( DrawValoracion(nValoracion, nHeight) );
}

function DrawValoracionMSN(nValoracion, nHeight) {
	var sHTML = "";
	if (nValoracion != 0) {
		sHTML +="<DIV class='parent chrome5 single1 llia'>"
					+		"<H2>Valoración MSN</H2>"
					+		"<DIV class='child c1 first'>"
					+			DrawValoracion(nValoracion, nHeight)
					+		"</DIV>"
					+	"</DIV>";
	}
	return sHTML;
}
function PrintValoracionMSN(nValoracion, nHeight) {
	document.write( DrawValoracionMSN(nValoracion, nHeight) );
}

function GetValoracion(sNombre) {

	var nMouseX = oIGZ.m_nMouseX;
	var nImgX = oGFX.f_getPosX(g_oForm[sNombre]);
	var nImgWidth = g_oForm[sNombre].width;
	var nStarWidth = nImgWidth / 5;
	
	var nOffset = nMouseX - nImgX;
	var nValue = Math.floor(nOffset / nStarWidth) + 1;
	if (nValue > 5) nValue = 5;
	
	return nValue;
}

function RefreshValoracion(sNombre, bDentro, nValue) {

	if (!nValue) nValue = 0;
	if (bDentro) {
		nValue = GetValoracion(sNombre);
	}

	var sImg = "/pix/star0"+ nValue +".gif";
	g_oForm[sNombre].src = sImg;
}


// Funciones para las areas compartidas de las paginas principales

function DrawCampo(sCampo) {
	return g_maContenido.f_getVal(sCampo+"@Contenido", 0);
}
function PrintCampo(sCampo) {
	document.write( DrawCampo(sCampo) );
}

function DrawComentarios(maComentarios, nMax) {
	if (!nMax) nMax = 5;
	nMax = (nMax > maComentarios.f_length() ? maComentarios.f_length() : nMax);
//	var sHTML = "<TABLE border='0' cellpadding='2' cellspacing='2' width='100%'>";
	var sHTML = "";

	if (nMax > 0) {
		var sLink = "... <A href='/comentario_list.aspx/"+ g_sCategoria +"/"+ g_sContenido +"/'>Leer más</A>";
		for (var i = 0; i < nMax; i++) {
			sHTML += "<DIV class='child c1 first'>"
						+	"		<B class='icRndL'><B class='icRndL1'><B></B></B><B class='icRndL2'><B></B></B><B class='icRndL3'></B><B class='icRndL4'></B><B class='icRndL5'></B></B>"
						+ "		<DIV class='icRndLfg'>"
						+ "			<DIV class='iucSnCmCo'>"
						+ "				<DIV class='iucSnCmB2'>"
						+ "					<DIV class='iucSnCmB3'><B>"+ maComentarios.f_getVal("nsAutor@Comentario", i) +"</B></DIV>"
						+ "					<DIV class='iucSnCmB4'>Enviado&nbsp;"+ maComentarios.f_getVal("fcAlta@Comentario", i).f_toDateDraw('nDD/nMM/nYYYY', 'sDD, nDD de sMM de nYYYY') +"</DIV>"
						+ "				</DIV>"
						+ "				<DIV class='iucSnCmB5' style='padding-bottom: 5px;'>" + maComentarios.f_getVal("comentario@Comentario", i).f_maxLength(150, sLink) + "</DIV>"
						+ "				<DIV class='iucSnCmB2'>"
						+ "					<DIV class='iucSnCmB3'><B>Valoración: </B>"+ DrawValoracion( maComentarios.f_getVal("valoracionComentario@Comentario", i), 12) +"</DIV>"
						+ "				</DIV>"
						+	"			</DIV>"
						+ "		</DIV>"
						+ "		<B class='icRndL'><B class='icRndL5'></B><B class='icRndL4'></B><B class='icRndL3'></B><B class='icRndL2'><B></B></B><B class='icRndL1'><B></B></B></B>"
						+	"</DIV>";
		}
		sHTML += "<BR/>";
	} else {
		sHTML += "<DIV class='child c1 first'>Aún no hay comentarios para este contenido</DIV><BR/>"
	}
	//sHTML += "</TABLE>";
	return sHTML;
}
function PrintComentarios(maComentarios, nMax) {
	document.write( DrawComentarios(maComentarios, nMax) );
}

function DrawGaleria(maData) {
	var sHTML = "";
	var sUrlGaleria = maData.f_getVal("galeriaURL@Contenido", 0);
	if (sUrlGaleria != null && sUrlGaleria != undefined && sUrlGaleria != "") {

		var sTextoGaleria = maData.f_getVal("galeriaTexto@Contenido", 0);
		var sImgGaleria = maData.f_getVal("flxGaleriaFoto@Contenido", 0);
		var sTextAlt = "Imagen no disponible";

		if (sUrlGaleria.indexOf("http://") == -1) sUrlGaleria = "http://"+ escape(sUrlGaleria);
		if (sTextoGaleria == null || sTextoGaleria == undefined || sTextoGaleria == "") {
			sTextoGaleria = "Ir a la galería";
		}
		if (sImgGaleria != '' && !IsUndefined(sImgGaleria)) {
			sImgGaleria = "<IMG src='"+ g_sImgPath + sImgGaleria +"' alt='"+ sTextoGaleria +"'/>";
		} else {
			sImgGaleria = "";
		}
		sHTML += "<DIV class='region4 parent chrome5 single1 rcallsc'>"
					+	 "	<H2>En Imágenes</H2>"
					+  "	<DIV class='child c1 first'>"
					+	 "		<TABLE><TR><TD>"+ sImgGaleria +"</TD><TD class='valignT'><A href='"+ sUrlGaleria +"'>"+ sTextoGaleria +"</A></TD></TR></TABLE>"
					+	 "	</DIV>"
					+  "</DIV>"
	}
	return sHTML;
}
function PrintGaleria(maData) {
	document.write( DrawGaleria(maData) );
}

function DrawContenidosRelacionados(maContenidosRelacionados, nMax) {
	if (!nMax) nMax = 5;
	nMax = (nMax > maContenidosRelacionados.f_length() ? maContenidosRelacionados.f_length() : nMax);
	var sHTML = "";
			
	if (nMax > 0) {
		sHTML = "<DIV class='region4 parent chrome5 single1 rcallsc'>"
				+ "<H2>Contenidos Relacionados</H2>"
				+ "<DIV class='child c1 first'>"
	
				+ "<TABLE border='0' cellpadding='2' cellspacing='4'>"
		for (var i = 0; i < nMax; i++) {
			var sURL = maContenidosRelacionados.f_getVal("url@ContenidoRelacionado", i);
			if (sURL.indexOf("http://") == -1) sURL = "http://"+ escape(sURL);
			sHTML += "<TR><TD><A href='"+ sURL +"' target='_blank'>"+ maContenidosRelacionados.f_getVal("descripcion@ContenidoRelacionado", i) +"</A></TD></TR>";
		}
		sHTML += "</TABLE>";
		sHTML += "</DIV></DIV>";
	} else {
		sHTML += "";
	}
	
	return sHTML;
}
function PrintContenidosRelacionados(maContenidosRelacionados, nMax) {
	document.write( DrawContenidosRelacionados(maContenidosRelacionados, nMax) );
}

function DrawVotacion(nPromedio, bVotar) {
	if (!nPromedio || nPromedio == null || nPromedio == '' || nPromedio > 5 || nPromedio < 0) nPromedio = 0;
	var sHTML = "<CENTER><TABLE><TR><TD id='DIV_Votar' align='center' valign='middle'>"+ (bVotar ? "Muy malo&nbsp;<IMG src='/pix/star00.gif' name='IMG_Votar' style='cursor: pointer;' onMouseMove='RefreshValoracion(this.name, 1)' onMouseOut='RefreshValoracion(this.name, 0)' onclick='VotarContenido(this.name)' />&nbsp;Excelente" : "") +"</TD></TR>"
						+ "<TR><TD style='text-align: center; vertical-align: middle; padding-top: 5px;'>Promedio:<IMG src='/pix/star0"+ nPromedio +".gif' name='IMG_Promedio' height='16' /><IMG src='/pix/magic.gif' width='50' height='1'/></TD></TR></TABLE></CENTER>";
	
	return sHTML;
}
function PrintVotacion(nPromedio) {
	document.write( DrawVotacion(nPromedio) );
}

function RefreshPromedio(sImgField, nPromedio) {

	if (nPromedio != null && nPromedio != "" && nPromedio != undefined) {
		RefreshValoracion(sImgField, 0, nPromedio);
	}
}

function LoadVideo(sContentArea, sGuid, bAutoplay) {
	InnerVideo(sContentArea, sGuid, 300,269,bAutoplay +"",null,0,0,null,null);
}

function DrawTablaRanking(sTitle, maData, nCual, nMax) {
	if (!nMax) nMax = maData.f_length();
	nMax = (nMax > maData.f_length() ? maData.f_length() : nMax);
	var sHTML = "", sClass = "", sUrl = "", sUrlRSS = "";
	
	var nIdCategoria = maData.f_getVal("fkIdCategoria@Contenido", 0);
	switch(nCual) {
		case 0:
			sClass = "parent chrome5 single1 llia";
			sUrl = "/comentados.aspx/"+ g_maCategoria.f_getValIf("idCategoria@Categoria", nIdCategoria, "wikiname@Categoria");
			break;
		case 1:
			sClass = "region4 parent chrome5 single1 rcallsc llia";
			sUrl = "/votados.aspx/"+ g_maCategoria.f_getValIf("idCategoria@Categoria", nIdCategoria, "wikiname@Categoria");
			break;
	}
	//sUrlRSS = "/rss/default.aspx?xbd_action="+(nCual+1)+"&idCategoria@Categoria="+nIdCategoria;
	
	sHTML += "<DIV class='"+sClass+"'>"
	sHTML += "	<H2><TABLE width='100%'><TR><TD><A href='"+sUrl+"/'>"+sTitle+"</A></TD><TD align='right'>"+oIGZ.f_drawIco(sTitle, "IcoFeed", "OpenRSS("+(nCual+1)+", "+nIdCategoria+")")+"</TD></TR></TABLE></H2>"
	//sHTML += "	<H2><TABLE width='100%'><TR><TD>"+sTitle+"</TD><TD align='right'>"+oIGZ.f_drawIco(sTitle, "IcoFeed", "OpenRSS("+(nCual+1)+", "+nIdCategoria+")")+"</TD></TR></TABLE></H2>"
	sHTML += "	<DIV class='child c1 first'>"
	sHTML += "		<TABLE border='0' cellpadding='2' cellspacing='0' width='100%'>"

	if (nMax > 0) {
		for (var i = 0; i < nMax; i++) {
			sHTML += "<TR>"
						 + "	<TD>"+ (i+1) +".-</TD>"
						 + "	<TD><A href='/default.aspx/"+ g_maCategoria.f_getValIf("idCategoria@Categoria", maData.f_getVal("fkIdCategoria@Contenido", i), "wikiname@Categoria") +"/"+ maData.f_getVal("wikiname@Contenido", i) +"/'>"+ maData.f_getVal("titulo@Contenido", i) +"</A></TD>"
						 + "	<TD class='alignR'>" + (nCual == 1 ? maData.f_getVal("nsVotos@Contenido", i) +"&nbsp;votos" : maData.f_getVal("nsComentarios@Contenido", i) +"&nbsp;comentarios") +"</TD>"
						 + "</TR>";
		}
	} else {
		sHTML += "<TR><TD>No hay datos</TD></TR>";
	}
	sHTML += "</TABLE>";
	sHTML += "</DIV></DIV>"

	return sHTML;
}

function PrintMasComentados(maData) {
	document.write( DrawTablaRanking("Los más comentados", maData, 0, 5) );
}
function PrintMasVotados(maData) {
	document.write( DrawTablaRanking("Los más votados", maData, 1, 5) );
}

function DrawRanking(sTitle, maData, nCual) {
	
	var sHTML = "", sUrlRSS = "";
	
	var nIdCategoria = maData.f_getVal("fkIdCategoria@Contenido", 0);
	sUrlRSS = "/rss/default.aspx?xbd_action="+(nCual+1)+"&idCategoria@Categoria="+nIdCategoria;
	
	sHTML += "<DIV class='parent chrome5 single1 llia'>"
	//sHTML += "	<H2>"+sTitle+"</A>&nbsp;<A href='"+sUrlRSS+"' target='_blank'>"+oIGZ.f_drawIco("RSS", "IcoFeed")+"</A></H2>"
	sHTML += "	<H2><TABLE width='100%'><TR><TD>"+sTitle+"</TD><TD align='right'>"+oIGZ.f_drawIco("RSS", "IcoFeed", "OpenRSS("+(nCual+1)+", "+nIdCategoria+")")+"</TD></TR></TABLE></H2>"
	sHTML += "	<DIV class='child c1 first'>"
	sHTML += "		<TABLE border='0' cellpadding='2' cellspacing='0' width='100%'>"

	if (maData.f_length() > 0) {
		for (var i = 0; i < maData.f_length(); i++) {
			sHTML += "<TR>"
						 + "	<TD>"+ (i+1) +".-</TD>"
						 + "	<TD><A href='/default.aspx/"+ g_maCategoria.f_getValIf("idCategoria@Categoria", maData.f_getVal("fkIdCategoria@Contenido", i), "wikiname@Categoria") +"/"+ maData.f_getVal("wikiname@Contenido", i) +"/'>"+ maData.f_getVal("titulo@Contenido", i) +"</A></TD>"
						 + "	<TD class='alignR'>" + (nCual == 1 ? maData.f_getVal("nsVotos@Contenido", i) +"&nbsp;votos" : maData.f_getVal("nsComentarios@Contenido", i) +"&nbsp;comentarios") +"</TD>"
						 + "</TR>";
		}
	} else {
		sHTML += "<TR><TD>No hay datos</TD></TR>";
	}
	sHTML += "</TABLE>";
	sHTML += "</DIV></DIV>"

	return sHTML;
}
function PrintRanking(sTitle, maData, nCual) {
	document.write( DrawRanking(sTitle, maData, nCual) );
}
function VotarContenido() {
	var idContenido = g_oForm["n_idContenido@Contenido"].value;
	var nValoracion = GetValoracion("IMG_Votar");
	oXBD.f_submit("/admin/votacion_xbd.aspx?xbd_action=1&fkIdContenido@Votacion="+ idContenido +"&votacion@Votacion="+ nValoracion,
								function() {
									if (g_msgVotacion != '') {
										GetElement("DIV_Votar").innerHTML = "<B>"+ g_msgVotacion.toUpperCase() +"</B>";
									}
									RefreshPromedio("IMG_Promedio", g_nPromedio);

									oXBD.f_submit("/libs/aspx/contenido_datos_js.aspx?idContenido="+ idContenido,
																function() {
																	//GetElement("TD_MasVotados").innerHTML = DrawTablaRanking("Los más votados", g_maVotados, 1, 5);
																	GetElement("TD_MasVotados").innerHTML = g_sHtmlVotados;
																}
									);
								}
	);
}

function DrawWikiname(sCampo, sValue) {
	var sHTML = "<TR>"
						+ "	<TD class='cOblig'>Wikiname</TD>"
						+ "	<TD><INPUT type='text' name='a_"+ sCampo +"' value='"+ sValue +"' maxlength='50' class='cajaXL readonly' readonly /></TD>"
						+ "</TR>";
	return sHTML;	
}
function PrintWikiname(maData, sCampo) {
	if (maData.f_length() > 0) {
		document.write( DrawWikiname( sCampo, maData.f_length(sCampo, 0) ) );
	}
}

function DrawRedesSociales() {
	var sTitulo = "Opiniones sobre "+ g_maContenido.f_getVal("titulo@Contenido", 0) +" – MSN.es";
	var sDescripcion = g_maContenido.f_getVal("introduccion@Contenido", 0);
	sDescripcion = (sDescripcion.length > 500 ? sDescripcion.substring(0, 495) +"..." : sDescripcion);
	var sHTML = "<DIV class='region4 parent chrome5 single1 rcallsc'>"
						+ 	"<H2>¡Comparte!</H2>"
						+ 	"<DIV class='child c1 first'>"
						+			DrawRedes (["reporter","live","delicious","digg","facebook","fresqui","meneame","technorati"], "<A style='padding: 0 5px 0 5px;' href='<sLink>' target='redes'><img SRC='/pix/redes_sociales/<sRed>.png' alt='<sNombre>' width='24' height='24' border='0'></A>" ,{TITULO:sTitulo,URL:null,DESCRIPCION:sDescripcion},8)
						+		"</DIV>"
						+	"</DIV>";
	return sHTML;
}

function DrawComunes(maData, bVotar) {

	var sHTML = "";
	
	var sVideo = maData.f_getVal("videoGUID@Contenido", 0, "");
	sHTML = "<DIV class='region4 parent chrome5 single1 rcallsc' style='width: 298px; min-width: 298px;'>"
				+ "	<H2>Tu valoración</H2>"
				+ "	<DIV id='DIV_Votacion' class='child c1 first' style=' visibility: hidden; '>"
				+ 		DrawVotacion( maData.f_getVal("promedioVotacion@Contenido", 0), bVotar )
				+ "	</DIV>"
				+ "</DIV>"
				+ "<DIV class='parent chrome1 single1 radads'>"
				+ "	<SCRIPT>dap(\"&amp;PG=ES9R13&amp;AP=1089\",300,200);</SCRIPT>"
				+ "</DIV>"
				+ "<DIV class='parent chrome1 single1 radads'>"
				+ "	<DIV id='TD_VIDEO'>"
//				+ "		<SCRIPT>LoadVideo('','"+ maData.f_getVal("videoGUID@Contenido", 0) +"',false);</SCRIPT>"
//				+ "		<SCRIPT type='text/javascript'>Msn.Video.BuildPlayer('player2',{skin:'0',mkt:'es-es',fr:'Channels Inline',fg:'gtlv2',ad:'true',timePlaying:'180',pg:'http://rad.msn-int.com/ADSAdClient31.dll?GetAd?PG=T4VID3',bsbpg:'T4VID4',c:'vcq',vcq:'"+ sVideo +"'},300,269);</script>"
				+ "		<SCRIPT type='text/javascript'>Msn.Video.BuildPlayer('player2',{skin:'0',mkt:'es-es',fr:'Channels Inline',fg:'gtlv2',ad:'true',timePlaying:'180',bsbpg:'T4VID4',c:'vcq',vcq:'"+ sVideo +"'},300,269);</script>"
				+ "	</DIV>"
				+ (sVideo != "" ? "<DIV><A href='http://messengertv.msn.com/launch/video.aspx?http://catalog.video.msn.com/"+ sVideo +"' target='_blank'><IMG src='/pix/boton_comparte_videos.jpg' width='300' height='62' alt='Messenger TV'/></A></DIV>" : "")
				+ "</DIV>"
				+ DrawGaleria(maData)
				+ DrawContenidosRelacionados(g_maContenidoRelacionado)
				+ DrawRedesSociales();
	
	return sHTML;
}
function PrintComunes(maData, bVotar) {
	document.write( DrawComunes(maData, bVotar) );
}

function OpenRSS(nAccion, nCategoria, sTitle, bAdmin) {
	var sUrl = (bAdmin ? ".." : "") + "/rss/default.aspx?xbd_action="+nAccion;
	if (nCategoria) {
		sUrl += "&idCategoria@Categoria="+nCategoria;
	}
	oIWin.f_new("RSSWin", sUrl, null, null, null, null, "yes", 1, 1);
}