function validar() {
	errores='';
	fechaingreso=document.reservas.ingresodia.value+document.reservas.ingresomesanio.value;
	ingreso=fechaingreso.substring(6,10)+fechaingreso.substring(3,5)+fechaingreso.substring(0,2);
	fechasalida=document.reservas.salidadia.value+document.reservas.salidamesanio.value;
	salida=fechasalida.substring(6,10)+fechasalida.substring(3,5)+fechasalida.substring(0,2);
	hoy=document.reservas.fechahoy.value;	
	if (document.reservas.nombre.value=='') errores+='Ingrese su nombre\n';
	if (document.reservas.telefono.value=='') errores+='Ingrese su teléfono\n';
	if (document.reservas.email.value=='' || !checkE(document.reservas.email.value)) errores+='Debe ingresar un e-mail válido\n';	
	if (fechaingreso=='' || fechasalida=='') {
		errores+='Debe ingresar la fecha de ingreso y salida\n';
	} else {
		if (!checkD(fechaingreso) || (ingreso<=hoy)) {
			errores+='Debe ingresar una fecha de ingreso válida';
		} else {
			if (!checkD(fechasalida)) {
				errores+='Debe ingresar una fecha de salida válida';
			} else {
				if (salida<=ingreso) errores+='La fecha de salida debe ser mayor que la de ingreso';
			}
		}
	}
	if (errores=='') {
		return true;
	} else {
		alert('Atención:\n'+errores);
		return false;
	}
}

function toggleContacto(){
	if (document.getElementById('contacto').style.display=='block')
		document.getElementById('contacto').style.display='none';
	else
		document.getElementById('contacto').style.display='block';
}

function validarContacto() {
	var errores = '';
	if (document.contacto.nombre.value == '') {
	   errores = errores + '* Ingrese su nombre\n';
	}
	if (document.contacto.email.value == '') {
	   errores = errores + '* Ingrese su e-mail\n';
	}
	else {
	atPos = document.contacto.email.value.indexOf('@');
		 if (atPos < 1 || atPos == (document.contacto.email.value.length - 1))
	   errores = errores + '* Ingrese un e-mail válido\n';
	}
	if (document.contacto.mensaje.value == '') {
	   errores = errores + '* Ingrese el mensaje\n';
	}
	if (errores != '') {
	   alert(errores);
	   return false;
	}
	else {
	   return true;
	}
}

var emailexp = /^[a-z][a-z_0-9\-\.]+@[a-z_0-9\.\-]+\.[a-z]{2,4}$/i
function validateEmail(str) {	
	return emailexp.test(str)
}
function checkE(campo) {
	if (!validateEmail(campo) && campo != "") {
		return false;
	} else {
		return true;
	}
}

function y2k(number) { return (number < 1000) ? number + 1900 : number; }
function checkD(myDate) {
	sep='/';
	if (myDate != "") {
		if (myDate.substring(1,2)==sep) myDate='0'+myDate;
		if (myDate.substring(4,5)==sep) myDate=myDate.substring(0,3)+'0'+myDate.substring(3,9);
		if (myDate.length == 10) {
			if (myDate.substring(2,3) == sep && myDate.substring(5,6) == sep) {
				var date = myDate.substring(0,2);
				var month = myDate.substring(3,5);
				var year  = myDate.substring(6,10);
				var test = new Date(year,month-1,date);

				if (year == y2k(test.getYear()) && (month-1 == test.getMonth()) && (date == test.getDate())) {
					return true;
				}
				else {
					return false;
				}
			}
			else {
				return false;
			}
		}
		else {
			return false;
		}
	} else {
		return false;
	}
}

function checkH(campo) {
	sep=':';alerta='* Debe ingresar una hora válida en formato HH:MM';
	if (campo != "") {	
		if (campo.length == 5) {
			if (campo.substring(2,3) == sep) {
				var hours = campo.substring(0,2);
				var minutes = campo.substring(3,5);

				if (hours<23 && minutes<59) {
					return true;
				}
				else {
					alert(alerta);
					return false;
				}
			}
			else {
				alert(alerta);
				return false;
			}
		}
		else {
			alert(alerta);
			return false;
		}
	} else {
		return true;
	}    
}


function imprimir() {
	if (window.print) window.print();
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function contacto(){
	window.open('contacto.php','Contacto','width=420,height=320,scrollbars=yes');
}

function terminos(){
	window.open('terminos.php','Terminos','width=500,height=480,scrollbars=yes');
}

function recomendar(){
	window.open('recomendar.php','Recomendar','width=420,height=300,scrollbars=yes');
}

function ubicacion(){
	window.open('ubicacion.html','Ubicacion','width=590,height=600,scrollbars=no');
}
function popfoto(hotel){
	window.open(hotel+'_fotos.html','Fotos','width=780,height=550,scrollbars=yes');
}
function checkHotel() {
	if (document.reservas.habitacion.options[document.reservas.habitacion.selectedIndex].value=='Penthouse') {
		document.reservas.hotel.selectedIndex=0;
		document.reservas.hotel.disabled=true;
	} else {
		document.reservas.hotel.disabled=false;
	}
}

function toggleFaq(id,maxid) {
	for(i=1;i<=maxid;i++){
		faq = document.getElementById('faq'+i);
		faq.style.display = 'none';
	}
	faq = document.getElementById('faq'+id);
	if (faq.style.display=='none'){
		faq.style.display = 'block';
	} else {
		faq.style.display = 'none';
	}
}

function swapTarifas(combo) {
	var seltarifas = document.getElementById('selhotel');
	if (combo.options[combo.selectedIndex].value=='Hotel Florinda') {
		seltarifas.selectedIndex = 0;
		loadTarifas(document.getElementById('selperiodo_florinda'),'f');
		document.getElementById("tarifas_florinda").style.display = "block";
		document.getElementById("tarifas_milano").style.display = "none";		
	} else {
		seltarifas.selectedIndex = 1;
		loadTarifas(document.getElementById('selperiodo_milano'),'m');
		document.getElementById("tarifas_florinda").style.display = "none";
		document.getElementById("tarifas_milano").style.display = "block";	
	}

}

function loadTarifas(selperiodo,hotel){
	var periodo = selperiodo.options[selperiodo.selectedIndex].value;
	var tarifas = new Array();
	var notas = new Array();

	notas[1] = 'Hasta el 20/12/2010';
	notas[2] = 'Desde el 20/12/2010 al 09/01/2011 AM.<br/>Pago adelantado sin devolución de importe';
	notas[3] = '';
	notas[4] = '';	
	notas[5] = 'Desde el 01/03/2011 al 13/03/2011 AM';
	notas[6] = '';
	notas[7] = 'Desde el 21/04/2011 al 24/04/2011 AM';

	if (hotel=='m'){ // Milano
		// (Single,Doble,DobleSup,Comunic)
		tarifas[1] = new Array(68,68,90,103);		// Pre-Temporada
		tarifas[2] = new Array(154,154,180,216);		// Fin de ańo
		tarifas[3] = new Array(130,130,154,180);		// Enero 
		tarifas[4] = new Array(103,103,127,143);		// Febrero
		tarifas[5] = new Array(130,130,154,180); 		// Carnaval
	} else { // Florinda
		// (Single,Doble,DobleSup,Comunic,Depto)
		tarifas[1] = new Array(54,68,90,103,118);	// Pre-Temporada 
		tarifas[2] = new Array(166,166,190,238,298);	// Fin de ańo
		tarifas[3] = new Array(138,138,158,199,250);	// Enero
		tarifas[4] = new Array(110,110,127,160,199);	// Febrero
		tarifas[5] = new Array(138,138,158,199,250); 	// Carnaval
		tarifas[6] = new Array(54,68,90,103,118); 	// Marzo
		tarifas[7] = new Array(110,110,127,160,199);	// Semana Santa
	}
	var tarifa = tarifas[periodo];
	for(i=0;i<tarifa.length;i++){
		var td = document.getElementById('tar'+hotel+i);
		td.innerHTML = 'U$S '+tarifa[i];
	}
	
	var td = document.getElementById('notas_'+hotel);	
	if (notas[periodo]){	
		td.innerHTML = notas[periodo];
	} else {
		td.innerHTML = notas[periodo];
	}
}
