/*VALIDAR CONTACTO*/

function test(src) {
  var regex = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,9}$/;
  return regex.test(src);
}

function validar() {
	var w = document.formulario;
	var ok = true;
	var mensaje = 'Por favor, corrija los siguientes errores:\n\n';

	if (w.nombre.value.length < 4) {
		mensaje += '    - Escriba por lo menos 4 caracteres de su Nombre\n';
		w.nombre.focus();
		w.nombre.style.background = '#ffeeee';
		ok = false;
	}
	var checkOK = "ABCDEFGHIJKLMNÑOPQRSTUVWXYZÁÉÍÓÚ" + "abcdefghijklmnñopqrstuvwxyzáéíóú " + "'";
	var checkStr = w.nombre.value;
	var allValid = true; 
	for (i = 0; i < checkStr.length; i++) {
		ch = checkStr.charAt(i); 
		for (j = 0; j < checkOK.length; j++)
			if (ch == checkOK.charAt(j))
				break;
		if (j == checkOK.length) { 
			allValid = false;
			ok = false;
			break; 
		}
	}
	if (!allValid) { 
		mensaje += '    - Escriba sólo letras en su Nombre\n'; 
		w.nombre.focus(); 
		w.nombre.style.background = '#ffeeee';
		ok = false; 
	}
  
	if (w.email1.value=='') {
		mensaje += '    - Escriba su e-mail\n';
		ok = false;
		w.email1.style.background = '#ffeeee';
		w.email1.focus();
	}
	else
		if (!test(w.email1.value)) {
			mensaje += '    - Su e-mail no es valido\n';
			ok = false;
			w.email1.style.background = '#ffeeee';
			w.email1.focus();
	};
	
	if (w.email1.value!=w.email2.value) {
		mensaje += '    - Su e-mail y e-mail de confirmación no son iguales\n';
		ok = false;
		w.email2.style.background = '#ffeeee';
		w.email2.focus();
	};
	
	if (!ok) {
		alert(mensaje);
		return false;
	}
	else
		return true;
}


/*VALIDA CONSULTAS*/

function validar_consultas() {
	var w = document.formulario;
	var ok = true;
	var mensaje = 'Por favor, corrija los siguientes errores:\n\n';
	if (w.nombre.value.length < 4) {
		mensaje += '    - Escriba por lo menos 4 caracteres de su Nombre\n';
		w.nombre.focus();
		w.nombre.style.background = '#ffeeee';
		ok = false;
	}
	var checkOK = "ABCDEFGHIJKLMNÑOPQRSTUVWXYZÁÉÍÓÚ" + "abcdefghijklmnñopqrstuvwxyzáéíóú " + ".";
	var checkStr = w.nombre.value;
	var allValid = true; 
	for (i = 0; i < checkStr.length; i++) {
		ch = checkStr.charAt(i); 
		for (j = 0; j < checkOK.length; j++)
			if (ch == checkOK.charAt(j))
				break;
		if (j == checkOK.length) { 
			allValid = false; 
			break; 
		}
	}
	if (!allValid) { 
		mensaje += '    - Escriba sólo letras en su Nombre\n'; 
		w.nombre.focus(); 
		w.nombre.style.background = '#ffeeee';
		ok = false; 
	}
  
	if (w.email1.value=='') {
		mensaje += '    - Escriba su e-mail\n';
		ok = false;
		w.email1.style.background = '#ffeeee';
		w.email1.focus();
	}
	else
		if (!test(w.email1.value)) {
			mensaje += '    - Su e-mail no es valido\n';
			ok = false;
			w.email1.style.background = '#ffeeee';
			w.email1.focus();
	};
	
	if (w.email1.value!=w.email2.value) {
		mensaje += '    - Su e-mail no coincide con el de confirmación\n';
		ok = false;
		w.email2.style.background = '#ffeeee';
		w.email2.focus();
	};

	if (!ok)
		alert(mensaje);

	return ok;
}

function blanco(x) {
	x.style.background='#ffffff';
}


/*VALIDAR RESERVAS DE PROGRAMAS*/

function validar_reserva_programas() {
	var w = document.formulario;
	var ok = true;
	var mensaje = 'Por favor, corrija los siguientes errores:\n\n';

	var out = ' '; // reemplazar la letra a
	var add = ''; // por la letra z
	var temp = '' + w.email1.value;
	
	while (temp.indexOf(out)>-1) {
		pos= temp.indexOf(out);
		temp = '' + (temp.substring(0, pos) + add + temp.substring((pos + out.length), temp.length));
	}
	w.email1.value = temp;

	temp = '' + w.email2.value;
	while (temp.indexOf(out)>-1) {
		pos= temp.indexOf(out);
		temp = '' + (temp.substring(0, pos) + add + temp.substring((pos + out.length), temp.length));
	}
	w.email2.value = temp;

	if (w.nombre.value.length < 4) {
		mensaje += '    - Escriba por lo menos 4 caracteres de su Nombre\n';
		w.nombre.focus();
		w.nombre.style.background = '#ffeeee';
		ok = false;
	}
	var checkOK = "ABCDEFGHIJKLMNÑOPQRSTUVWXYZÁÉÍÓÚ" + "abcdefghijklmnñopqrstuvwxyzáéíóú ";
	var checkStr = w.nombre.value;
	var allValid = true; 
	for (i = 0; i < checkStr.length; i++) {
		ch = checkStr.charAt(i); 
		for (j = 0; j < checkOK.length; j++)
			if (ch == checkOK.charAt(j))
				break;
		if (j == checkOK.length) { 
			allValid = false; 
			break; 
		}
	}
	if (!allValid) { 
		mensaje += '    - Escriba sólo letras en su Nombre\n'; 
		w.nombre.focus(); 
		w.nombre.style.background = '#ffeeee';
		ok = false; 
	}
  
	if (w.email1.value=='') {
		mensaje += '    - Escriba su e-mail\n';
		ok = false;
		w.email1.style.background = '#ffeeee';
		w.email1.focus();
	}
	else
		if (!test(w.email1.value)) {
			mensaje += '    - Su e-mail no es valido\n';
			ok = false;
			w.email1.style.background = '#ffeeee';
			w.email1.focus();
	};
	
	if (w.email1.value!=w.email2.value) {
		mensaje += '    - Su e-mail no coincide con el de confirmación\n';
		ok = false;
		w.email2.style.background = '#ffeeee';
		w.email2.focus();
	};

	
	if (!ok)
		alert(mensaje);

	return ok;
}

/*dateNow = <%=diaHoy%>;
monthNow = <%=mesHoy - 1%>;
yearNow = <%=anoHoy%>;

if (!ns4)
{
	if (!ie) yearNow -= 1900;
}

function blanco(x) {
	x.style.background='#ffffff';
}*/

/*VALIDA ALOJAMIENTO*/

function validar_alojamiento() {
	var w = document.formulario;
	var ok = true;
	var mensaje = 'Por favor, corrija los siguientes errores:\n\n';

	var out = ' '; // reemplazar la letra a
	var add = ''; // por la letra z
	var temp = '' + w.email1.value;
	
	while (temp.indexOf(out)>-1) {
		pos= temp.indexOf(out);
		temp = '' + (temp.substring(0, pos) + add + temp.substring((pos + out.length), temp.length));
	}
	w.email1.value = temp;

	temp = '' + w.email2.value;
	while (temp.indexOf(out)>-1) {
		pos= temp.indexOf(out);
		temp = '' + (temp.substring(0, pos) + add + temp.substring((pos + out.length), temp.length));
	}
	w.email2.value = temp;


	if (w.nombre.value.length < 4) {
		mensaje += '    - Escriba por lo menos 4 caracteres de su Nombre\n';
		w.nombre.focus();
		w.nombre.style.background = '#ffeeee';
		ok = false;
	}
	var checkOK = "ABCDEFGHIJKLMNÑOPQRSTUVWXYZÁÉÍÓÚ" + "abcdefghijklmnñopqrstuvwxyzáéíóú ";
	var checkStr = w.nombre.value;
	var allValid = true; 
	for (i = 0; i < checkStr.length; i++) {
		ch = checkStr.charAt(i); 
		for (j = 0; j < checkOK.length; j++)
			if (ch == checkOK.charAt(j))
				break;
		if (j == checkOK.length) { 
			allValid = false; 
			break; 
		}
	}
	if (!allValid) { 
		mensaje += '    - Escriba sólo letras en su Nombre\n'; 
		w.nombre.focus(); 
		w.nombre.style.background = '#ffeeee';
		ok = false; 
	}
  
	if (w.email1.value=='') {
		mensaje += '    - Escriba su e-mail\n';
		ok = false;
		w.email1.style.background = '#ffeeee';
		w.email1.focus();
	}
	else
		if (!test(w.email1.value)) {
			mensaje += '    - Su e-mail no es valido\n';
			ok = false;
			w.email1.style.background = '#ffeeee';
			w.email1.focus();
	};
	
	if (w.email1.value!=w.email2.value) {
		mensaje += '    - Su e-mail no coincide con el de confirmación\n';
		ok = false;
		w.email2.style.background = '#ffeeee';
		w.email2.focus();
	};

	
	if (!ok)
		alert(mensaje);

	return ok;
}

/*dateNow = <%=diaHoy%>;
monthNow = <%=mesHoy - 1%>;
yearNow = <%=anoHoy%>;

if (!ns4)
{
	if (!ie) yearNow -= 1900;
}*/


/*VALIDACIONES EN INGLES*/

function validar_en() {
	var w = document.formulario;
	var ok = true;
	var mensaje = 'Please, correct the following errors:\n\n';

	if (w.nombre.value.length < 4) {
		mensaje += '    - Write at least 4 leters in \"First and Last name\"\n';
		w.nombre.focus();
		w.nombre.style.background = '#ffeeee';
		ok = false;
	}
	var checkOK = "ABCDEFGHIJKLMNÑOPQRSTUVWXYZÁÉÍÓÚ" + "abcdefghijklmnñopqrstuvwxyzáéíóú " + "'";
	var checkStr = w.nombre.value;
	var allValid = true; 
	for (i = 0; i < checkStr.length; i++) {
		ch = checkStr.charAt(i); 
		for (j = 0; j < checkOK.length; j++)
			if (ch == checkOK.charAt(j))
				break;
		if (j == checkOK.length) { 
			allValid = false; 
			break; 
		}
	}
	if (!allValid) { 
		mensaje += '    - Use only letters for your name\n'; 
		w.nombre.focus(); 
		w.nombre.style.background = '#ffeeee';
		ok = false; 
	}
  
	if (w.email1.value=='') {
		mensaje += '    - Write your e-mail\n';
		ok = false;
		w.email1.style.background = '#ffeeee';
		w.email1.focus();
	}
	else
		if (!test(w.email1.value)) {
			mensaje += '    - Your e-mail is not valid\n';
			ok = false;
			w.email1.style.background = '#ffeeee';
			w.email1.focus();
	};
	
	if (w.email1.value!=w.email2.value) {
		mensaje += '    - Your e-mail and confirmation e-mail must be the same\n';
		ok = false;
		w.email2.style.background = '#ffeeee';
		w.email2.focus();
	};
	
	if (!ok)
		alert(mensaje);

	return ok;
}

/*VALIDAR CONSULTAS EN*/

function validar_consultas_en() {
	var w = document.formulario;
	var ok = true;
	var mensaje = 'Please, correct the following errors:\n\n';



	if (w.nombre.value.length < 4) {
		mensaje += '    - Your name must be at least 3 characters long\n';
		w.nombre.focus();
		w.nombre.style.background = '#ffeeee';
		ok = false;
	}
	var checkOK = "ABCDEFGHIJKLMNÑOPQRSTUVWXYZÁÉÍÓÚ" + "abcdefghijklmnñopqrstuvwxyzáéíóú ";
	var checkStr = w.nombre.value;
	var allValid = true; 
	for (i = 0; i < checkStr.length; i++) {
		ch = checkStr.charAt(i); 
		for (j = 0; j < checkOK.length; j++)
			if (ch == checkOK.charAt(j))
				break;
		if (j == checkOK.length) { 
			allValid = false; 
			break; 
		}
	}
	if (!allValid) { 
		mensaje += '    - Your name must contain only letters\n'; 
		w.nombre.focus(); 
		w.nombre.style.background = '#ffeeee';
		ok = false; 
	}
  
	if (w.email1.value=='') {
		mensaje += '    - Write your e-mail\n';
		ok = false;
		w.email1.style.background = '#ffeeee';
		w.email1.focus();
	}
	else
		if (!test(w.email1.value)) {
			mensaje += '    - Your e-mail is not valid\n';
			ok = false;
			w.email1.style.background = '#ffeeee';
			w.email1.focus();
	};
	
	if (w.email1.value!=w.email2.value) {
		mensaje += '    - Both e-mails must be the same\n';
		ok = false;
		w.email2.style.background = '#ffeeee';
		w.email2.focus();
	};

	
	if (!ok)
		alert(mensaje);

	return ok;
}


/*RESERVA HOTELES INGLES*/

function validar_alojamiento_en() {
	var w = document.formulario;
	var ok = true;
	var mensaje = 'Please, correct the following errors:\n\n';



	if (w.nombre.value.length < 3) {
		mensaje += '    - Your name must be at least 3 characters long\n';
		w.nombre.focus();
		w.nombre.style.background = '#ffeeee';
		ok = false;
	}
	var checkOK = "ABCDEFGHIJKLMNÑOPQRSTUVWXYZÁÉÍÓÚ" + "abcdefghijklmnñopqrstuvwxyzáéíóú ";
	var checkStr = w.nombre.value;
	var allValid = true; 
	for (i = 0; i < checkStr.length; i++) {
		ch = checkStr.charAt(i); 
		for (j = 0; j < checkOK.length; j++)
			if (ch == checkOK.charAt(j))
				break;
		if (j == checkOK.length) { 
			allValid = false; 
			break; 
		}
	}
	if (!allValid) { 
		mensaje += '    - Your name must contain only letters\n'; 
		w.nombre.focus(); 
		w.nombre.style.background = '#ffeeee';
		ok = false; 
	}
  
	if (w.email1.value=='') {
		mensaje += '    - Write your e-mail\n';
		ok = false;
		w.email1.style.background = '#ffeeee';
		w.email1.focus();
	}
	else
		if (!test(w.email1.value)) {
			mensaje += '    - Your e-mail is not valid\n';
			ok = false;
			w.email1.style.background = '#ffeeee';
			w.email1.focus();
	};
	
	if (w.email1.value!=w.email2.value) {
		mensaje += '    - Both e-mails must be the same\n';
		ok = false;
		w.email2.style.background = '#ffeeee';
		w.email2.focus();
	};

	
	if (!ok)
		alert(mensaje);

	return ok;
}

/*dateNow = <%=diaHoy%>;
monthNow = <%=mesHoy - 1%>;
yearNow = <%=anoHoy%>;

if (!ns4)
{
	if (!ie) yearNow -= 1900;
}*/

/*VALIDA PROGRAMAS EN INGLES*/

function validar_reserva_programas_en() {
	var w = document.formulario;
	var ok = true;
	var mensaje = 'Please, correct the following errors:\n\n';



	if (w.nombre.value.length < 3) {
		mensaje += '    - Your name must be at least 3 characters long\n';
		w.nombre.focus();
		w.nombre.style.background = '#ffeeee';
		ok = false;
	}
	var checkOK = "ABCDEFGHIJKLMNÑOPQRSTUVWXYZÁÉÍÓÚ" + "abcdefghijklmnñopqrstuvwxyzáéíóú ";
	var checkStr = w.nombre.value;
	var allValid = true; 
	for (i = 0; i < checkStr.length; i++) {
		ch = checkStr.charAt(i); 
		for (j = 0; j < checkOK.length; j++)
			if (ch == checkOK.charAt(j))
				break;
		if (j == checkOK.length) { 
			allValid = false; 
			break; 
		}
	}
	if (!allValid) { 
		mensaje += '    - Your name must contain only letters\n'; 
		w.nombre.focus(); 
		w.nombre.style.background = '#ffeeee';
		ok = false; 
	}
  
	if (w.email1.value=='') {
		mensaje += '    - Write your e-mail\n';
		ok = false;
		w.email1.style.background = '#ffeeee';
		w.email1.focus();
	}
	else
		if (!test(w.email1.value)) {
			mensaje += '    - Your e-mail is not valid\n';
			ok = false;
			w.email1.style.background = '#ffeeee';
			w.email1.focus();
	};
	
	if (w.email1.value!=w.email2.value) {
		mensaje += '    - Both e-mails must be the same\n';
		ok = false;
		w.email2.style.background = '#ffeeee';
		w.email2.focus();
	};

	
	if (!ok)
		alert(mensaje);

	return ok;
}

/*dateNow = <%=diaHoy%>;
monthNow = <%=mesHoy - 1%>;
yearNow = <%=anoHoy%>;

if (!ns4)
{
	if (!ie) yearNow -= 1900;
}*/

