function abrirImagen(pIDNoticia, pArchivo, pAncho, pAlto)
{
	var oVentana = new Window(
		{
			className: "alphacube",
			title: "Free Pass - Vista ampliada",
			width: pAncho,
			height: pAlto,
			left: 200,
			top: 170,
			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 cerrarSesion()
{
		location.href = "index.php?exit=1";
}

function validarLoginUsuario(pForm, url)
{
	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=url;
			else
				alert(pCadena);
		});
		} else {
			alert("Ingrese su nombre de usuario y contraseña");
			txtUsuario.focus();
			return false;
		}
	return false;
}

function validarAlias(pAlias)
{
		return x_ValidarAlias(pAlias, function(pCadena)
		{
			if(pCadena) {
				 return true;
			}
			else
			{
				alert("Usuario ya existente");	
				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(q.value.length > 0)
			return true;
		else
		{
			alert("Por favor, ingrese un parámetro de búsqueda");
			q.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 = aDias[lIDDia] + ", " + sDia + " de " + aMeses[sMes] + " de " + lAno;
	}
}

function guardarRegistro(pForm)
{
	with(pForm)
	{
		if(validarEmail(txtEmail.value))
		{
			x_GuardarRegistro("", txtEmail.value, function(pCadena)
				{
					alert("Su Email ha sido agregado exitosamente");
					txtEmail.value = "";
				});
		}
		else
		{
			alert("Por favor, ingrese un Email válido");
			txtEmail.focus();
		}
	}
	return false;
}

//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)
//						{
//							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 validarMensaje(pForm)
{
	with(pForm)
	{
				if(mensaje.value.length > 0)
				{
					return true;
				}
				else
				{
					alert("Por favor, ingrese un Mensaje");
					mensaje.focus();
				}
	}
	return false;
}


function RegistroUsuario(pForm)
{
	with(pForm)
	{
		if(apellido.value.length > 0 && nombres.value.length > 0 && usuario.value.length > 0 && clave.value.length > 0 && localidad.value.length > 0)
		{
//			if(validarAlias(usuario.value))
			{
					if(validarEmail(email.value))
					{
							x_GuardarUsuarioRegistrado( apellido.value, nombres.value, usuario.value, email.value, clave.value, localidad.value, ocupacion.value, intereses.value, function(pCadena)
								{
									pForm.reset();
									alert("Nueva Cuenta de Usuario creada!");
								});
					}
					else
					{
						alert("Por favor, ingrese un Email válido");
						email.focus();
					}
			}
		}
		else
		{
			alert("Por favor, ingrese todos los campos obligatorios.");
			usuario.focus();
		}
	}
	return false;
}

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, txtPais.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 EnviarChica(pForm)
{
	with(pForm)
	{
		if(apellido.value.length > 0)
		{
			if(nombre.value.length > 0)
			{
				if(edad.value.length > 0)
				{
					if(telefono.value.length > 0)
					{
						if(validarEmail(email.value))
						{
							if(comentario.value.length > 0)
							{
								if(foto.value.length > 0)
								{
									return true;
								}
									else
									{
										alert("Por favor, ingrese una Foto");
										
									}	
								}
									else
									{
										alert("Por favor, ingrese un Comentario");
										comentario.focus();
									}
								}
								else
								{
									alert("Por favor, ingrese un Email válido");
									email.focus();
								}
							}
						else
						{
							alert("Por favor, ingrese un Telefono");
							telefono.focus();
						}
					}
					else
					{
						alert("Por favor, ingrese su Edad");
						edad.focus();
					}
				}
			else
				{
					alert("Por favor, ingrese su Nombre");
					nombre.focus();
				}
			}
			
		else
		{
			alert("Por favor, ingrese su Apellido");
			apellido.focus();
		}
	}
	return false;
}

//function GuardarNoticia(pForm)
//{
//	with(pForm)
//	{
//				if(titulo.value.length > 0)
//				{
//					return true;
//				}
//				else
//				{
//					alert("Por favor, ingrese un Titulo");
//					titulo.focus();
//				}
//	}
//	return false;
//}


function GuardarNoticia(pForm)
{
	with(pForm)
	{
		if(titulo.value.length > 0)
		{
			if(copete.value.length > 0)
			{
				if(contenido.value.length > 0)
				{
					
					
					return true;
									
					}
					else
					{
						alert("Por favor, ingrese un Contenido");
						contenido.focus();
					}
				}
			else
				{
					alert("Por favor, ingrese un Copete");
					copete.focus();
				}
			}
			
		else
		{
			alert("Por favor, ingrese un Titulo");
			titulo.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 GuardarSuscriptor(pForm)
{
	with(pForm)
	{
		if(nombre.value.length > 0)
		  {
			if(validarEmail(email.value))
			{
					x_GuardarSuscriptor(nombre.value, email.value, function(pCadena)
						{
							alert("Gracias por suscribirse a nuestro Newsletter.\n");
							pForm.reset();

						});
			}

			else
			{
				alert("Por favor, ingrese un Email válido");
				email.focus();
			}
		 }

			else
			{
				alert("Por favor, ingrese su Nombre");
				nombre.focus();
			}
	}
	return false;
}


function recomendarNoticia(pForm, pIDNoticia)
{
	with(pForm)
	{
		if(validarEmail(REmail.value))
		{
			if(validarEmail(txtDEmail.value))
			{
				//x_GuardarRecomendado(txtDNombres.value, txtDEmail.value, function(pCadena) {});

				x_RecomendarNoticia(pIDNoticia, txtRNombres.value, txtREmail.value,
					txtDNombres.value, txtDEmail.value, txtMensaje.value, function(pCadena)
					{
						alert("Su mensaje ha sido enviado");
						txtDNombres.value = "";
						txtDEmail.value = "";
					});
			}
			else
			{
				alert("El email del destinatario es invalido. Por favor, ingreselo nuevamente.");
				txtDEmail.focus();
			}
		}
		else
		{
			alert("Su email es invalido. Por favor, ingreselo nuevamente.");
			txtREmail.focus();
		}
	}
	return false;
}

function desplegarRecomendacion()
{
	var tRecomendacion = document.getElementById("trRecomendacion");
	tRecomendacion.className = (tRecomendacion.className == "oculto") ? "visible" : "oculto";
}

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)
						{
							txtNombres.value = "";
							txtEmail.value = "";
							txtMensaje.value = "";
							alert("Su comentario ha sido enviado.");
						});
				}
				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 guardarComentarioChicaFP()
{
	var pForm = document.getElementById('form_chicaFP');
	with(pForm)
	{
		if(txtNombres.value != "")
		{
			if(validarEmail(txtEmail.value))
			{
				if(txtComentarios.value != "")
				{
					x_GuardarComentarioFP(txtNombres.value, txtEmail.value, txtComentarios.value, function(pCadena)
						{
							txtNombres.value = "";
							txtEmail.value = "";
							txtComentarios.value = "";
							alert("Su comentario ha sido enviado.");
						});
				}
				else
				{
					alert("Por favor, ingrese su Comentario");
					txtComentarios.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 mostrarCapa(idFormVisible, idFormOculto)
{
	var tFormVisible = document.getElementById(idFormVisible);
	var tFormOculto = document.getElementById(idFormOculto);
	tFormVisible.className = "visible";
	tFormOculto.className =  "oculto";
}

function desplegarRecomendacion()
{
	var tRecomendacion = document.getElementById("trRecomendacion");
	tRecomendacion.className = (tRecomendacion.className == "oculto") ? "visible" : "oculto";
}

function guardarParticipante(idC, idU)
{
		x_GuardarParticipante (idC, idU, function(pCadena)
		{
			if(pCadena == "S")
				  alert("Gracias por Participar");
			 else
				alert("Usted ya participo de este sorteo");
		});
	return false;
}


//		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=url;
//			else
//				alert(pCadena);
//		});
