function abrirImagen(pIDNoticia, pArchivo, pAncho, pAlto)
{
	var oVentana = new Window(
		{
			className: "alphacube",
			title: "MiradorNacional.com - Vista ampliada",
			width: pAncho,
			height: pAlto,
			left: 275,
			top: 180,
			draggable: true,
			resizable: true,
			minimizable: false,
			maximizable: false,
			destroyOnClose: true
		}
	);
	oVentana.show();
	var sURL = "ver-imagen.php?idregistro=" + pIDNoticia + "&archivo=" + pArchivo;
	oVentana.setAjaxContent(sURL);
}

function GuardarClic(pIDBanner)
{
	x_GuardarClic(pIDBanner, function(pCadena)
		{
		});
}

function cerrarSesion()
{
		location.href = "index.php?exit=1";
}

function abrirGaleriaDeImagenes()
{
	var oVentana = new Window(
		{
			className: "alphacube",
			title: "PrimeraNoticia.com - Galería de Imágenes",
			width: 500,
			height: 414,
			left: 150,
			top: 170,
			draggable: true,
			resizable: true,
			minimizable: false,
			maximizable: false,
			destroyOnClose: true
		}
	);
	oVentana.show();
	var oFlash = new SWFObject("visor-imagenes-500x375.swf", "", "500", "375", "7", "", true);
//	var oFlash = new SWFObject("visor-imagenes-268x201.swf", "", "268", "201", "7", "", true);
	with(oFlash)
	{
		addParam("menu", "false");
		addParam("wmode", "transparent");
		write(oVentana.getContent().id);
	}	
}

function validarLoginUsuario(pForm, $sURL)
{
	with(pForm)
		if (txtUsuario.value.length > 0 && txtClave.value.length > 0) {
		x_ValidarLoginUsuario(txtUsuario.value, txtClave.value, function(pCadena)
		{
			if(pCadena == "S")
				//location.reload(true);
				location.href= "blog-personal.php?autor=1";
			else
				alert(pCadena);
		});
		} else {
			alert("Ingrese su nombre de usuario y contraseña");
			txtUsuario.focus();
			return false;
		}
	return false;
}

function validarEmail(pEmail)
{
	var oRegExp = /^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$/;
	return oRegExp.test(pEmail);
}

function validarBusqueda(pForm)
{
	with(pForm)
	{
		if(txtBusqueda.value.length > 0)
			return true;
		else
		{
			alert("Por favor, ingrese un parámetro de búsqueda");
			txtBusqueda.focus();
		}
	}
	return false;
}

function retornarFecha(pDestino)
{
	var aDias = new Array("domingo", "lunes", "martes",
		"mi&eacute;rcoles",  "jueves", "viernes", "s&aacute;bado");
	var aMeses = new Array("enero", "febrero", "marzo", "abril", "mayo", "junio", "julio", "agosto", "septiembre", "octubre", "noviembre", "diciembre");
	
	var dFecha = new Date();
	with(dFecha)
	{
		var lIDDia = getDay();
		var sDia = new String(getDate());
		//var sMes = new String(getMonth() + 1);
		var sMes = getMonth();
		var lAno = getYear();
		var sHora = new String(getHours());
		var sMinutos = new String(getMinutes());
	}
	if(sDia.length == 1) sDia = "0" + sDia;
	if(sMes.length == 1) sMes = "0" + sMes;
	if(lAno < 1900) lAno += 1900;
	if(sHora.length == 1) sHora = "0" + sHora;
	if(sMinutos.length == 1) sMinutos = "0" + sMinutos;
	pDestino = document.getElementById(pDestino);
	if(pDestino)
	{
		pDestino.innerHTML =sHora + ":" + sMinutos + " | " + aDias[lIDDia] + " " + sDia + ", " + aMeses[sMes] + " " + lAno;
	}
}

function guardarComentario(pForm, pIDNoticia)
{
	with(pForm)
	{
		if(txtNombres.value != "")
		{
			if(validarEmail(txtEmail.value))
			{
				if(txtMensaje.value != "")
				{
					x_GuardarComentario(pIDNoticia, txtNombres.value, txtEmail.value, txtMensaje.value, function(pCadena)
						{
							alert("Su comentario ha sido enviado con éxito.");
							txtNombres.value = "";
							txtEmail.value = "";
							txtMensaje.value = "";
							retornarComentarios(pIDNoticia);
						});
				}
				else
				{
					alert("Por favor, ingrese su Comentario");
					txtMensaje.focus();
				}
			}
			else
			{
				alert("Por favor, ingrese un Email válido");
				txtEmail.focus();
			}
		}
		else
		{
			alert("Por favor, ingrese su Nombre");
			txtNombres.focus();
		}
	}
	return false;
}

function retornarComentarios(pIDNoticia)
{
	x_RetornarComentarios(pIDNoticia, function(pCadena)
		{
			var tdComentarios = document.getElementById("tdComentarios");
			if(tdComentarios) tdComentarios.innerHTML = pCadena;
		});
}

function EnviarContacto(pForm)
{
	with(pForm)
	{

		if(txtNombres.value.length > 0)
		{
			if(txtDomicilio.value.length > 0)
			{
				if(txtCiudad.value.length > 0)
				{
					if(txtProvincia.value.length > 0)
					{
						if(validarEmail(txtEmail.value))
						{
							if(txtMensaje.value.length > 0)
							{
									x_EnviarContacto(txtNombres.value, txtEmail.value,
										txtCiudad.value, txtDomicilio.value, txtProvincia.value, txtTelefono.value, txtMensaje.value, function(pCadena)
											{
												alert("Su mensaje ha sido enviado");
												pForm.reset();
											});
									}
									else
									{
										alert("Por favor, ingrese un Mensaje");
										txtMensaje.focus();
									}
								}
								else
								{
									alert("Por favor, ingrese un Email válido");
									txtEmail.focus();
								}
							}
						else
						{
							alert("Por favor, ingrese una Provincia");
							txtProvincia.focus();
						}
					}
					else
					{
						alert("Por favor, ingrese una Localidad");
						txtCiudad.focus();
					}
				}
			else
				{
					alert("Por favor, ingrese un Domicilio");
					txtDomicilio.focus();
				}
			}
			
		else
		{
			alert("Por favor, ingrese su Nombre");
			txtNombres.focus();
		}
	}
	return false;
}

function guardarRegistro(pForm)
{
	with(pForm)
	{
		if(nombres.value.length > 0)
		{
			if(apellido.value.length > 0)
			{
				if(validarEmail(email.value))
				{
					if(usuario.value.length > 0)
					{
						if(clave.value.length > 0)
						{
							if(localidad.value.length > 0)
							{
								if(provincia.value.length > 0)
								{
										
											x_GuardarRegistro(nombres.value, apellido.value, email.value, usuario.value, clave.value, localidad.value, provincia.value, function(pCadena)
													{
														alert("Gracias por Registrarse");
														pForm.reset();
													});									
			
									}
									else
									{
										alert("Por favor, ingrese una Provincia");
										provincia.focus();
									}
			
								}
								else
								{
									alert("Por favor, ingrese una Ciudad");
									localidad.focus();
								}
								
							}
							else
							{
								alert("Por favor, ingrese una Clave");
								clave.focus();
							}
					}
					else
					{
						alert("Por favor, ingrese un Usuario");
						usuario.focus();
					}
				}
				else
					{
						alert("Por favor, ingrese un Email válido");
						email.focus();
					}
				}
			else
				{
					alert("Por favor, ingrese su Apellido");
					apellido.focus();
				}
			}
		else
		{
			alert("Por favor, ingrese su Nombre");
			nombres.focus();
		}
	}
	return false;
}

function validarMensajeBlog(pForm)
{
	with(pForm)
	{
						if(mensaje.value.length > 0)
						{
							return true;
							
						}
						else
						{
							alert("Por favor, ingrese un Mensaje");
							mensaje.focus();
						}
	}
	return false;
}

function cargarImagenNext(pIDNoticia, pImagenes)
{
	var oVisor = document.getElementById("imgVisor-" + pIDNoticia);
	var iActual =  document.getElementById("idImg");
	vActual = parseInt(iActual.innerHTML);
	
	if (vActual == pImagenes.length)
		vActual = 0;
		
	if(oVisor) oVisor.src = pImagenes[vActual];
	iActual.innerHTML = vActual + 1;
}

function cargarImagenPrev(pIDNoticia, pImagenes)
{
	var oVisor = document.getElementById("imgVisor-" + pIDNoticia);
	var iActual =  document.getElementById("idImg");
	vActual = parseInt(iActual.innerHTML);
	
	vActual -= 1;
	
	if (vActual <= 0)
		vActual = pImagenes.length;
		
	if(oVisor) oVisor.src = pImagenes[vActual-1];
	iActual.innerHTML = vActual;
}

function retornarClima()
{
	var tClima = document.getElementById("tdClima");
	if(tClima)
	{
		tClima.innerHTML = "<img src=\"images/ajax-loader-2.gif\" align=\"right\" />";
		valor = document.frmClima.cbCiudad.options[document.frmClima.cbCiudad.selectedIndex].value;
		valor = valor.split("|");
		
		x_RetornarClima(valor[0], valor[1], function(pCadena)
			{
					tClima.innerHTML = pCadena;
			});
	}
}

function enviarComentarioBlog(pForm){
	with(pForm)
		if (comentario.value.length > 0) {
		x_EnviarComenentarioBlog(comentario.value, idusuario.value, idpost.value, function(pCadena)
		{
			alert("Comentario enviado. Gracias por participar!.");
			pForm.reset();
		});
		} else {
			alert("Ingrese un comentario.");
			comentario.focus();
			return false;
		}
	return false;
}