function abrirImagen(pIDNoticia, pArchivo, pAncho, pAlto)
{
	var oVentana = new Window(
		{
			className: "alphacube",
			title: "Coopenet - Vista ampliada",
			width: pAncho,
			height: pAlto,
			left: 220,
			top: 188,
			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 abrirGaleriaDeImagenes()
{
	var oVentana = new Window(
		{
			className: "alphacube",
			title: "Coopenet - 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)
{
	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="clientes.php";
			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 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 E-mail valido");
				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 valido");
						email.focus();
					}
			}
		}
		else
		{
			alert("Por favor, ingrese todos los campos obligatorios.");
			usuario.focus();
		}
	}
	return false;
}

function EnviarContacto(pForm)
{
	with(pForm)
	{
		if(nombres.value.length > 0)
		{
			if(validarEmail(email.value))
			{
				if(nodo.options[nodo.selectedIndex].value != 0)
				{
					if(comentarios.value.length > 0)
					{
						x_EnviarContacto(nombres.value, email.value,
							ciudad.value, telefono.value, comentarios.value,
							nodo.options[nodo.selectedIndex].value,function(pCadena)
								{
									alert("Su mensaje ha sido enviado");
									pForm.reset();
								});
					}
					else
					{
						alert("Por favor, escriba su comentario");
						comentarios.focus();
					}
				}
				else
				{
					alert("Por favor, seleccione un Destinatario");
					nodo.focus();
				}
			}
			else
			{
				alert("Por favor, ingrese un Email valido");
				email.focus();
			}
		}
		else
		{
			alert("Por favor, ingrese su Nombre y Apellido");
			nombres.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 valido");
						email.focus();
					}
				}
			else
				{
					alert("Por favor, ingrese su Apellido");
					apellido.focus();
				}
			}
		else
		{
			alert("Por favor, ingrese su Nombre");
			nombres.focus();
		}
	}
	return false;
}

function desplegarCapa(idCapa)
{
	var tFormVisible = document.getElementById(idCapa);
	
	if (tFormVisible.className == "oculto")
	tFormVisible.className = "visible";
	else
	tFormVisible.className = "oculto";
}

function recuperarClave(pForm)
{
	with(pForm)
	{
		if(usuario.value.length > 0)
		{
			if(validarEmail(email.value))
			{
				x_RecuperarClave(usuario.value, email.value, function(pCadena)
				{
					if(pCadena == "S")
						alert("Su clave ha sido enviada a su email.");
					else
						alert("Usuario o email incorrecto." + pCadena);
					pForm.reset();
				});
			}
			else
			{
				alert("Por favor, ingrese un Email valido");
				email.focus();
			}
		}
		else
		{
			alert("Por favor, ingrese su nombre.");
			usuario.focus();
		}
	}
	return false;
}

function desplegarVideo(pIDVideo, pURL)
{
	var tContenedor = document.getElementById("trVideo" + pIDVideo);
	var tVideo = document.getElementById("tdVideo" + pIDVideo);
	if(tContenedor.className == "oculto")
	{
		tContenedor.className = "visible";
		var oFlash = new SWFObject(pURL, "", "370", "270", "7", "", true);
		with(oFlash)
		{
			addParam("menu", "false");
			addParam("wmode", "transparent");
			write("tdVideo-" + pIDVideo);
		}
	}
	else
	{
		tVideo.innerHTML == "&nbsp;"
		tContenedor.className = "oculto";
	}
}

function GuardarSuscriptor(pForm)
{
	with(pForm)
	{
			if(validarEmail(email.value))
			{
					x_GuardarSuscriptor(email.value, function(pCadena)
						{
							alert("Gracias por suscribirse a nuestro Newsletter.\n");
							pForm.reset();

						});
			}

			else
			{
				alert("Por favor, ingrese un Email valido");
				email.focus();
			}
	}
	return false;
}

function cargarEncuesta(pIDEncuesta, pDestino)
{
	var sXML = "xml.encuesta.php?IDEncuesta=" + pIDEncuesta;
	var oFlash = new SWFObject("encuesta.swf", "", "222", "160", "7", "", true);
	oFlash.addVariable("_URL", sXML);
	oFlash.addParam("wmode", "transparent");
	oFlash.write(pDestino);
}

function guardarVotacion(pForm, pIDEncuesta)
{
	var bOpcion = false;
	with(pForm)
	{
		for(var lJ = 0; lJ < rdOpcion.length; lJ++)
		{
			if(rdOpcion[lJ].checked == true)
			{
				var lIDOpcion = rdOpcion[lJ].value;
				bOpcion = true;
				break;
			}
		}
		if(!bOpcion)
		{
			alert("Por favor, seleccione una opción");
			rdOpcion[0].focus();
		}
		else
		{
			if(validarEmail(txtEmail.value))
			{
				x_GuardarVotacion(pIDEncuesta, lIDOpcion, txtEmail.value, function(pCadena)
					{
						var tEncuesta = document.getElementById("tdEncuesta-" + pIDEncuesta);
						if(tEncuesta) tEncuesta.innerHTML = pCadena;
						cargarResultadoDeEncuesta(pIDEncuesta, "divResultados-" + pIDEncuesta);
					});
			}
			else
			{
				alert("Por favor, ingrese un Email valido");
				txtEmail.focus();
			}
		}
	}
	return false;
}

function cargarResultadoDeEncuesta(pIDEncuesta, pDestino)
{
	var oDestino = document.getElementById(pDestino);
	if(oDestino)
	{
		var oFlash = new SWFObject("encuesta.swf", "", "180", "180", "7", "", true);
		with(oFlash)
		{
			addVariable("_URL", "xml.encuesta.php?IDEncuesta=" + pIDEncuesta);
			addParam("wmode", "transparent");
			write(pDestino);
		}
	}
}

function visualizarSeccion(pSeccion, pVisible)
{
	var oSeccion = document.getElementById(pSeccion);
	if(oSeccion)
	{
		with(oSeccion)
		{
			if(pVisible && oSeccion.className == "oculto")
				className = "visible";
			else if(!pVisible && (className == "" || className == "visible"))
				className = "oculto";
		}
	}
}

function mostrarCapa(idFormVisible, idFormOculto)
{
	var tFormVisible = document.getElementById(idFormVisible);
	var tFormOculto = document.getElementById(idFormOculto);
	tFormVisible.className = "visible";
	tFormOculto.className =  "oculto";
}

//function retornarClima()
//{
//	var tClima = document.getElementById("tdClima");
//	tClima.innerHTML = "<img src=\"images/ajax-loader.gif\" />";
//	x_RetornarClima(document.frmClima.cbCiudad.options[document.frmClima.cbCiudad.selectedIndex].value,
//		function(pCadena)
//		{
//				tClima.innerHTML = pCadena;
//		});
//}

/********************************************************************/
function retornarClima()
{
	var tClima = document.getElementById("tdClima");
	if(tClima)
	{
		tClima.innerHTML = "<img src=\"images/ajax-loader.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;
			});
	}
}