var m_lIDAuspiciante = 0;

Acceso = {
		Estado: false,
		Validar: function(pIDNoticia)
			{
				if(!Acceso.Estado)
					desplegarSeccion("divAcceso", pIDNoticia);
				return Acceso.Estado;
			},
		Visualizar: function()
			{
				var dMensaje = document.getElementById("divMensaje");
				var dContenido = document.getElementById("divContenido");
				if(dMensaje) dMensaje.className = Acceso.Estado ? "oculto" : "visible";
				if(dContenido) dContenido.className = Acceso.Estado ? "visible" : "oculto";
			}
	};

function validarAcceso(pForm)
{
	with(pForm)
	{
		if(txtUsuario.value != "")
		{
			if(txtClave.value != "")
			{
				x_ValidarAcceso(txtUsuario.value, txtClave.value, function(pCadena)
					{
						if(pCadena == "S")
						{
							Acceso.Estado = true;
							retornarLogin("user");
							Acceso.Visualizar();
						}
						else
						{
							Acceso.Estado = false;
							alert("El nombre Usuario o Clave son incorrectos.\nInténtelo nuevamente.");
							txtUsuario.focus();
						}
					});
			}
			else
			{
				alert("Por favor, ingrese una Clave");
				txtClave.focus();
			}
		}
		else
		{
			alert("Por favor, ingrese un Usuario");
			txtUsuario.focus();
		}
	}
	return false;
}

function cerrarSesion()
{
	Acceso.Estado = false;
	retornarLogin("login");
	Acceso.Visualizar();
}

function retornarLogin(pForm)
{
	var dLogin = document.getElementById("divLogin");
	if(dLogin)
	{
		dLogin.innerHTML = "<img src=\"/images/ajax-loader.gif\" width=\"16\" height=\"16\" style=\"margin-bottom: 5px;\" />";
		x_RetornarLogin(pForm, function(pCadena)
			{
				dLogin.innerHTML = pCadena;
			});
	}
}

function desplegarSeccion(pSeccion, pIDRegistro)
{
	if(pIDRegistro != undefined) pSeccion += "-" + pIDRegistro;
	var oSeccion = document.getElementById(pSeccion);
	if(oSeccion != undefined)
	{
		with(oSeccion)
		{
			if(className == "oculto")
			{
				className = "visible";
				if(pSeccion.indexOf("divRecomendar") > -1 && pIDRegistro != undefined)
				{
					var oFlash = new SWFObject("/forms/formulario-send.swf", "", "381", "275", "7", "", true);
					with(oFlash)
					{
						addVariable("IDNoticia", pIDRegistro);
						addParam("wmode", "transparent");
						write(pSeccion);
					}
				}
			}
			else
				className = "oculto";
		}
	}
}

function desplegarAuspiciante(pIDAuspiciante, pArchivo, pURL)
{
	ocultarAuspiciante(m_lIDAuspiciante);
	var dAuspiciante = document.getElementById("divAuspiciante-" + pIDAuspiciante);
	if(dAuspiciante != undefined)
	{
		dAuspiciante.className = "visible";
		m_lIDAuspiciante = pIDAuspiciante;
		var oFlash = new SWFObject("/auspiciantes.swf", "", 506, 506, "7", "", true);
		with(oFlash)
		{
			addVariable("IDAuspiciante", pIDAuspiciante);
			addVariable("Archivo", pArchivo);
			addVariable("URL", pURL);
			addParam("wmode", "transparent");
			write(dAuspiciante.id);
		}
	}
}

function ocultarAuspiciante(pIDAuspiciante)
{
	var dAuspiciante = document.getElementById("divAuspiciante-" + pIDAuspiciante);
	if(dAuspiciante != undefined) dAuspiciante.className = "oculto";
}

function abrirVentana(pURL, pNombre, pWidth, pHeight, pScroll)
{
	var iLeft = (screen.width - pWidth) / 2;
	var iTop = (screen.height - pHeight) / 2;
	if (pScroll == "") pScroll = "no";
	var sPropiedades = "height=" + pHeight + ", width=" + pWidth +
		", top=" + iTop + ",left=" + iLeft +
		", scrollbars=" + pScroll + ", menubar=no, status=no";
	window.open(pURL, pNombre, sPropiedades);
}

function retornarRanking(pTipoDeSeccion, pTipoDeRanking)
{
	var tMasLeidas = document.getElementById("tabMasLeidas");
	var tMasRecomendadas = document.getElementById("tabMasRecomendadas");
	tMasLeidas.src = "/images/btn-mas-leidas-" + ((pTipoDeRanking == "V") ? "2" : "1") + ".jpg";
	tMasRecomendadas.src = "/images/btn-mas-recomendadas-" + ((pTipoDeRanking == "V") ? "1" : "2") + ".jpg";
	var tRanking = document.getElementById("tdRanking");
	tRanking.innerHTML = "<img src=\"/images/ajax-loader.gif\" width=\"16\" height=\"16\" style=\"margin-top: 5px;\" />";
	x_RetornarRanking(pTipoDeSeccion, pTipoDeRanking, function(pCadena)
		{
			tRanking.innerHTML = pCadena;
		});
}

function retornarNoticias(pIDEdicion)
{
	desplegarSeccion("trEdicion-" + pIDEdicion);
	var tContenedor = document.getElementById("trEdicion-" + pIDEdicion);
	if(tContenedor.className == "visible" && tContenedor.innerText == "")
	{
		var tEdicion = document.getElementById("tdEdicion-" + pIDEdicion);
		tEdicion.innerHTML = "<img src=\"/images/ajax-loader.gif\" width=\"16\" height=\"16\" style=\"margin: 2px;\" />";
		x_RetornarNoticias(pIDEdicion, function(pCadena)
			{
				tEdicion.innerHTML = pCadena;
			});
	}
	return false;
}

function retornarClima(pDestino)
{
	x_RetornarClima(function(pCadena)
		{
			var oDestino = document.getElementById(pDestino);
			oDestino.innerHTML = pCadena;
		});
}

function validarBusqueda(pForm)
{
	if(pForm.busqueda.value.length >= 3)
		return true;
	else
	{
		alert("Por favor, ingrese más caracteres de búsqueda");
		pForm.busqueda.focus();
	}
	return false;
}