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 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 GuardarReserva(pForm)
{
	with(pForm)
	{
		if(txtNombres.value.length > 0)
		{	
		  if(txtApellido.value.length > 0)
		  {
			if(validarEmail(txtEmail.value))
				{
				if(txtLocalidad.value.length > 0)
				{
					if(txtTelefono.value.length > 0)
					{
							if(txtComentario.value.length > 0)
							{
									x_GuardarReserva(txtNombres.value, txtApellido.value, txtEmail.value,
										txtLocalidad.value, txtTelefono.value, txtComentario.value, idpaquete.value, reserva.value, fecha.value, titulo.value, function(pCadena)
											{
												alert("Su mensaje ha sido enviado");
												pForm.reset();
											});
									}
									else
									{
										alert("Por favor, ingrese un Comentario");
										txtComentario.focus();
									}
								
							}
						else
						{
							alert("Por favor, ingrese una Teléfono");
							txtTelefono.focus();
						}
					}
					else
					{
						alert("Por favor, ingrese una Localidad");
						txtLocalidad.focus();
					}
				}
				else
				{
					alert("Por favor, ingrese un Email válido");
					txtEmail.focus();
				}	
			}
			else
			{
				alert("Por favor, ingrese su Apellido");
				txtApellido.focus();
			}
		}
		else
		{
			alert("Por favor, ingrese su Nombre");
			txtNombres.focus();
		}
	}
	return false;
}

function EnviarContacto(pForm)
{
	with(pForm)
	{
		if(txtNombres.value.length > 0)
		{	
			if(validarEmail(txtEmail.value))
			{
				if(txtTelefono.value.length > 0)
				{
					if(txtMensaje.value.length > 0)
					{
							x_EnviarContacto(txtNombres.value, txtEmail.value,
								txtTelefono.value, txtMensaje.value, txtNews.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 número de Teléfono");
					txtTelefono.focus();
				}
			}
			else
			{
				alert("Por favor, ingrese un Email válido");
				txtEmail.focus();
			}
		}
		else
		{
			alert("Por favor, ingrese su Nombre");
			txtNombres.focus();
		}
	}
	return false;
}

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 válido");
			email.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 enviarLunaDeMiel(pForm){
	with(pForm)
	  {
  		  if(desde.value==""){ alert("Por favor, ingrese una fecha de salida!"); desde.focus(); return false;}
  		  if(hasta.value==""){ alert("Por favor, ingrese una fecha de regreso!"); hasta.focus(); return false;}
  		  if(fecha.value==""){ alert("Por favor, ingrese una fecha de casamiento!"); fecha.focus(); return false;}
		  if(novio.value==""){ alert("Por favor, ingrese los nombres y apellidos del novio!"); novio.focus(); return false;}
		  if(novia.value==""){ alert("Por favor, ingrese los nombres y apellidos de la novia!"); novia.focus(); return false;}
		  if(numero.value==""){ alert("Por favor, ingrese un n\u00famero de tel\u00e9fono!"); numero.focus(); return false;}
		  if(!validarEmail(email.value)){ alert("Por favor, ingrese un Email v\u00e1lido"); email.focus(); return false;}
		  if(tel.checked == false  && mail.checked == false ){ alert("Por favor, seleccione un medio de contacto!!"); tel.focus(); return false;}
	   	  if(residencia.value==""){ alert("Por favor, ingrese un lugar de residencia!"); residencia.focus(); return false;}
		  if(comentarios.value==""){ alert("Por favor, ingrese un comentario!"); comentarios.focus(); return false;}		  						  		  
		  x_EnviarLunaDeMiel(destino.value, desde.value, hasta.value, dias.value, fecha.value, novio.value, novia.value, tipo.value, numero.value, email.value, tel.checked, mail.checked, residencia.value, comentarios.value, function(pCadena)
			  {
				  alert("Gracias por contactarse, a la brevedad nos comunicaremos con usted!.\n");
				  pForm.reset();

			  });
	  }
	  return false;
}
