/**** club ****/
function enviarRegistroClub(pForm)
{
	with(pForm)
	{
		if((apellido.value.length > 0) && (nombres.value.length > 0) && (documento.value.length > 0))
		{
			if(clave.value.length > 0)
			{
					if((domicilio.value.length > 0) &&
						(localidad.value.length > 0) &&
						(provincia.value.length > 0) &&
						(pais.value.length > 0))
					{
						if(telefono.value.length > 0)
						{
							if(validarEmail(email.value))
							{

							x_EnviarRegistroClub(apellido.value, nombres.value,
												tipodoc.value, documento.value,
												clave.value, email.value, telefono.value,
												domicilio.value, localidad.value,
												provincia.value, pais.value,
											    function(pCadena)
													{
														alert("Su solicitud ha sido enviada.");
														pForm.reset();
													});

							}
							else
							{
								alert("Por favor, ingrese un Email válido");
							    email.focus();
							}

						} else
						{
							alert("Por favor, ingrese su telefono.");
							telefono.focus();
						}
					} else
					{
						alert("Por favor, ingrese su domicilio, localidad, provincia y pais.");
						domicilio.focus();
					}
			} else
			{
				alert("Por favor, ingrese su clave.");
				clave.focus();
			}
		} else
		{
			alert("Por favor, ingrese su apellido, nombres y documento.");
			apellido.focus();
		}
	} //end with
	return false;
}

function enviarCanje(pForm)
{
	with(pForm)
	{
		if(validarCheckbox(premio))
		{
			
			x_EnviarCanje(idafiliado.value, toStringCheckbox(premio), function(pCadena)
				{
					pForm.reset();
					if(pCadena)
						alert("Su solicitud ha sido enviada. En breve nos pondremos en contacto con usted.");
					else
						alert("Ocurrio un error al enviar su solicitud. Por favor, intentelo nuevamente.");
				});
		}
		else
		{
			alert("Por favor, seleccione el premio por el cual desea canjear sus puntos.");
			premio[0].focus();
		}
	}
	return false;
}

function validarCheckbox(check)
{
	var result = false;
	for (i=0;i<check.length;++i)
		if (check[i].checked)
			result = true;
	return result;
}


function toStringCheckbox(check)
{
	var result = "";
	for (i=0;i<check.length;++i)
		if (check[i].checked)
			result += check[i].value + ",";
	return result;
}


function validarUsuario(frmLogin)
{
	with(frmLogin)
		x_ValidarUsuario(membresia.value, clave.value, function(pCadena)
		{
			if(pCadena == "S")
				location.href = "club-resumen.php";
			else
				alert("Usuario o Clave incorrecto");
		});
	return false;
}
/****/

function enviarBuzon(pForm)
{
	with(pForm)
	{
		if(nombres.value.length > 0 && pais.value.length > 0 && provincia.value.length > 0 && localidad.value.length > 0  &&  telefono.value.length > 0 && mensaje.value.length > 0)
		{
					if(validarEmail(email.value))
					{
							x_EnviarBuzon(tipoMensaje.value, nombres.value, email.value, pais.value, provincia.value, localidad.value,  telefono.value, fax.value, mensaje.value, function(pCadena)
								{
									pForm.reset();
									alert("Su mensaje. Muchas Gracias.");
								});
							return true;
					}
					else
					{
						alert("Por favor, ingrese un Email válido");
						email.focus();
					}
		}
		else
		{
			alert("Por favor, ingrese todos los campos obligatorios.");
			nombres.focus();
		}
	}
	return false;
}

function enviarFormEmpleo(pForm)
{
	with(pForm)
	{
		if(apellido.value.length > 0 && nombres.value.length > 0 && domicilio.value.length > 0 && localidad.value.length > 0 && provincia.value.length > 0 && pais.value.length > 0 && telefono.value.length > 0)
		{
//			if(validarAlias(usuario.value))
			{
					if(validarEmail(email.value))
					{
							x_EnviarPostulante(apellido.value, nombres.value, domicilio.value, localidad.value, provincia.value, pais.value, telefono.value, email.value, observaciones.value, function(pCadena)
								{
//									pForm.reset();
									alert("Su curriculum ha sido enviado. Muchas Gracias.");
								});
							return true;
					}
					else
					{
						alert("Por favor, ingrese un Email válido");
						email.focus();
					}
			}
		}
		else
		{
			alert("Por favor, ingrese todos los campos obligatorios.");
			apellido.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 dDia = new Date();
	with(dDia)
	{
		var lIDDia = getDay();
		var lDia = getDate();
		var lMes = getMonth();
		var lAno = getYear();
		if(lAno < 1900) lAno += 1900;
	}
	var tFecha = document.getElementById(pDestino);
	tFecha.innerHTML = aDias[lIDDia] + ", " + lDia + " de " + aMeses[lMes] + " de " + lAno;
}

function retornarClima()
{
	var tClima = document.getElementById("tdClima");
	var oCiudad = document.getElementById("cbCiudad");
	if(tClima && oCiudad && oCiudad.length > 0)
	{
		tClima.innerHTML = "<img src=\"images/ajax-loader-1.gif\" align=\"right\" />";
		x_RetornarClima(oCiudad.options[oCiudad.selectedIndex].value,
			function(pCadena)
			{
					tClima.innerHTML = pCadena;
			});
	}
}

function votarEncuesta(pIDEncuesta)
{
	var bOpcion = false;
	for(var lJ = 0; lJ < frmEncuesta.rdOpcion.length; lJ++)
	{
		if(frmEncuesta.rdOpcion[lJ].checked == true)
		{
			var lIDOpcion = frmEncuesta.rdOpcion[lJ].value;
			bOpcion = true;
			break;
		}
	}
	if(!bOpcion)
	{
		alert("Por favor, seleccione una opción");
		frmEncuesta.rdOpcion[0].focus();
	}
	else
	{
		if(validarEmail(frmEncuesta.txtEmail.value))
		{
			x_VotarEncuesta(pIDEncuesta, lIDOpcion, frmEncuesta.txtEmail.value, votarEncuesta_HTML);
		}
		else
		{
			alert("Por favor, ingrese un Email válido");
			frmEncuesta.txtEmail.focus();
		}
	}
}

function votarEncuesta_HTML(pCadena)
{
	var aDatos = pCadena.split(":|:");
	var dEncuesta = document.getElementById("divEncuesta");
	dEncuesta.innerHTML = aDatos[1];
	cargarEncuesta(aDatos[0], "divResultados");
}

function cargarEncuesta(pIDEncuesta, pDestino)
{
	var sXML = "xml.encuesta.php?IDEncuesta=" + pIDEncuesta;
	var oFlash = new SWFObject("grafico-encuesta.swf", "swfEncuesta-" + pIDEncuesta, "185", "150", "7", "", true);
	with(oFlash)
	{
		addVariable("_URL", sXML);
		addParam("wmode", "transparent");
		write(pDestino);
	}
}

function abrirImagen(pIDNoticia, pArchivo, pAncho, pAlto)
{
	var oVentana = new Window(
		{
			className: "alphacube",
			title: "Hoteles Austral - Vista ampliada",
			width: pAncho,
			height: pAlto,
			left: 200,
			top: 250,
			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 abrirGaleriaDeImagenes()
{
	var oVentana = new Window(
		{
			className: "alphacube",
			title: "We Love Tenis - Galería de Imágenes",
			width: 500,
			height: 414,
			left: 125,
			top: 250,
			draggable: true,
			resizable: true,
			minimizable: false,
			maximizable: false,
			destroyOnClose: true
		}
	);
	oVentana.show();
	var oFlash = new SWFObject("visor-imagenes-500x414.swf", "", "500", "414", "7", "", true);
	with(oFlash)
	{
		addParam("menu", "false");
		addParam("wmode", "transparent");
		write(oVentana.getContent().id);
	}	
}

function buscarNoticias(pForm)
{
	with(pForm)
	{
		if(txtBusqueda.value.length == 0)
		{
			alert("Por favor, ingrese una Búsqueda");
			txtBusqueda.focus();
			return false;
		}
	}
	return true;
}

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, "", "330", "275", "7", "", true);
		with(oFlash)
		{
			addParam("menu", "false");
			addParam("wmode", "transparent");
			write("tdVideo-" + pIDVideo);
		}
	}
	else
	{
		tVideo.innerHTML == "&nbsp;"
		tContenedor.className = "oculto";
	}
}

function desplegarMenu()
{
	var dMenu = document.getElementById("divMenuGalerias");
	dMenu.className = (dMenu.className == "oculto") ? "visible" : "oculto";
}

function enviarContacto(pForm)
{
	with(pForm)
	{
		if(nombres.value.length > 0)
		{
			if(validarEmail(txtEmail.value))
			{
				if(mensaje.value.length > 0)
				{
					x_EnviarContacto(nombres.value, email.value,
						localidad.value, pais.value, mensaje.value,provincia.value,telefono.value, function(pCadena)
						{
							alert("Su mensaje ha sido enviado");
							pForm.reset();
						});
				}
				else
				{
					alert("Por favor, ingrese un Mensaje");
					mensaje.focus();
				}
			}
			else
			{
				alert("Por favor, ingrese un Email válido");
				txtEmail.focus();
			}
		}
		else
		{
			alert("Por favor, ingrese su Nombre");
			txtNombres.focus();
		}
	}
	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 validarMensaje(pForm)
{
	with(pForm)
	{
		if(nombres.value.length > 0)
		{
			if(validarEmail(email.value))
			{
				if(mensaje.value.length > 0)
				{
					return true;
				}
				else
				{
					alert("Por favor, ingrese un Mensaje");
					mensaje.focus();
				}
			}
			else
			{
				alert("Por favor, ingrese un Email válido");
				email.focus();
			}
		}
		else
		{
			alert("Por favor, ingrese su Nombre");
			nombres.focus();
		}
	}
	return false;
}

function guardarComentario(pForm)
{
	with(pForm)
	{
		if(nombres.value.length > 0)
		{
			if(validarEmail(email.value))
			{
				if(mensaje.value.length > 0)
				{
					x_GuardarComentario(idregistro.value, nombres.value, email.value, mensaje.value, function(pCadena)
						{
							alert("Su mensaje ha sido enviado.\nEn breve estará en línea");
							mensaje.value = "";
						});
				}
				else
				{
					alert("Por favor, ingrese un Mensaje");
					mensaje.focus();
				}
			}
			else
			{
				alert("Por favor, ingrese un Email válido");
				email.focus();
			}
		}
		else
		{
			alert("Por favor, ingrese su Nombre");
			nombres.focus();
		}
	}
	return false;
}


function GuardarSuscriptor(pForm)
{
	with(pForm)
	{
		if(txtNombres.value.length > 0)
		{
			if(validarEmail(txtEmail.value))
			{
					x_GuardarSuscriptor(txtNombres.value, txtEmail.value, function(pCadena)
						{
							alert("Gracias por suscribirse a nuestro newsletter.\n");
							txtNombres.value = "";
							txtEmail.value = "";

						});
			}

			else
			{
				alert("Por favor, ingrese un Email válido");
				txtEmail.focus();
			}
		}
		else
		{
			alert("Por favor, ingrese su Nombre");
			txtNombres.focus();
		}
	}
	return false;
}

function desplegarRecomendacion()
{
	var tRecomendacion = document.getElementById("trRecomendacion");
	tRecomendacion.className = (tRecomendacion.className == "oculto") ? "visible" : "oculto";
}

function desplegarContenido(contenido)
{
	var tRecomendacion = document.getElementById(contenido);
	tRecomendacion.className = (tRecomendacion.className == "oculto") ? "visible" : "oculto";
}

function desplegarContenidoAlternado(contVisible, contOculto)
{
	var cVisible = document.getElementById(contVisible);
	var cOculto = document.getElementById(contOculto);
	cVisible.className = "visible";
	cOculto.className = "oculto";
}

function recomendarNoticia(pForm, pIDNoticia)
{
	with(pForm)
	{
		if(validarEmail(txtREmail.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("Por favor, ingrese un Email válido");
				txtDEmail.focus();
			}
		}
		else
		{
			alert("Por favor, ingrese un Email válido");
			txtREmail.focus();
		}
	}
	return false;
}


function EnviarReservaHotel(pForm)
{
	with(pForm)
	{
		if((fechaDesde.value.length > 0) && (fechaHasta.value.length > 0))
		{
			if(txtCantPersHotel.value.length > 0)
			{
				if(txtNombres.value.length > 5)
				{
					if((txtDomicilio.value.length > 0) && 
						(txtLocalidad.value.length > 0) && 
						(txtProvincia.value.length > 0) && 
						(txtPais.value.length > 0))
					{
						if(txtTelefono.value.length > 0)
						{
							if(validarEmail(txtEmail.value))
							{

							x_EnviarReservaHotel(fechaDesde.value, fechaHasta.value, 
												hotel.value, txtCantPersHotel.value,
												txtNombres.value, txtEmpresa.value,
												txtDomicilio.value, txtLocalidad.value,
												txtProvincia.value, txtPais.value,
												txtTelefono.value, txtFax.value,
												txtFormaPago.value, txtObservaciones.value,
												txtEmail, function(pCadena)
													{
														alert("Su reserva ha sido enviada.");
														txtObservaciones.value = "";
													});

							}
							else
							{
								alert("Por favor, ingrese un Email válido");
								txtEmail.focus();
							}
					
						} else		
						{
							alert("Por favor, ingrese su telefono.");
							txtTelefono.focus();
						}
					} else		
					{
						alert("Por favor, ingrese su domicilio, localidad, provincia y pais.");
						txtDomicilio.focus();
					}
				} else		
				{
					alert("Por favor, ingrese su Nombre y Apellido.");
					txtNombres.focus();
				}
			} else		
			{
				alert("Por favor, ingrese la cantidad de pasajeros.");
				txtCantPersHotel.focus();
			}
		} else		
		{
			alert("Por favor, seleccione su la fecha de arribo y de partida.");
			fechaDesde.focus();
		}
	} //end with
	return false;
}




function EnviarReservaSalon(pForm)
{
	with(pForm)
	{
		if(fechaSalon.value.length > 0)
		{
			if(txtCantPersSalon.value.length > 0)
			{
				if(txtNombres.value.length > 5)
				{
					if((txtDomicilio.value.length > 0) &&
						(txtLocalidad.value.length > 0) &&
						(txtProvincia.value.length > 0) &&
						(txtPais.value.length > 0))
					{
						if(txtTelefono.value.length > 0)
						{
							if(validarEmail(txtEmail.value))
							{

							x_EnviarReservaSalon(fechaSalon.value, 
												salon.value, txtCantPersSalon.value,
												txtNombres.value, txtEmpresa.value,
												txtDomicilio.value, txtLocalidad.value,
												txtProvincia.value, txtPais.value,
												txtTelefono.value, txtFax.value,
												txtObservaciones.value,
												txtEmail, function(pCadena)
													{
														alert("Su reserva ha sido enviada.");
														txtObservaciones.value = "";
													});

							}
							else
							{
								alert("Por favor, ingrese un Email válido");
								txtEmail.focus();
							}
					
						} else		
						{
							alert("Por favor, ingrese su telefono.");
							txtTelefono.focus();
						}
					} else		
					{
						alert("Por favor, ingrese su domicilio, localidad, provincia y pais.");
						txtDomicilio.focus();
					}
				} else		
				{
					alert("Por favor, ingrese su Nombre y Apellido.");
					txtNombres.focus();
				}
			} else		
			{
				alert("Por favor, ingrese la cantidad de personas.");
				txtCantPersSalon.focus();
			}
		} else		
		{
			alert("Por favor, seleccione la fecha de reserva.");
			fechaSalon.focus();
		}
	} //end with
	return false;
}



function EnviarReservaPromo(pForm)
{
	with(pForm)
	{
		if(fechaPromo.value.length > 0)
		{
			if(txtCantPers.value.length > 0)
			{
				if(txtNombres.value.length > 5)
				{
					if((txtDomicilio.value.length > 0) && 
						(txtLocalidad.value.length > 0) && 
						(txtProvincia.value.length > 0) && 
						(txtPais.value.length > 0))
					{
						if(txtTelefono.value.length > 0)
						{
							if(validarEmail(txtEmail.value))
							{

							x_EnviarReservaPromo(fechaPromo.value, 
												txtPromocion.value, txtCantPers.value,
												txtNombres.value, txtEmpresa.value,
												txtDomicilio.value, txtLocalidad.value,
												txtProvincia.value, txtPais.value,
												txtTelefono.value, txtFax.value,
												txtObservaciones.value,
												txtEmail, function(pCadena)
													{
														alert("Su reserva ha sido enviada.");
														txtObservaciones.value = "";
													});

							}
							else
							{
								alert("Por favor, ingrese un Email válido");
								txtEmail.focus();
							}
					
						} else		
						{
							alert("Por favor, ingrese su telefono.");
							txtTelefono.focus();
						}
					} else		
					{
						alert("Por favor, ingrese su domicilio, localidad, provincia y pais.");
						txtDomicilio.focus();
					}
				} else		
				{
					alert("Por favor, ingrese su Nombre y Apellido.");
					txtNombres.focus();
				}
			} else		
			{
				alert("Por favor, ingrese la cantidad de personas.");
				txtCantPersSalon.focus();
			}
		} else		
		{
			alert("Por favor, seleccione la fecha de reserva.");
			fechaSalon.focus();
		}
	} //end with
	return false;
}