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/2011';
	notas[2] = 'Desde el 20/12/2011 al 8/1/2012 AM.';
	notas[3] = '';
	notas[4] = '';	
	notas[5] = 'Desde el 17/2/2012 al 22/2/2012 AM.';
	notas[6] = '';
	notas[7] = 'Desde el 1/4/2012 al 9/4/2012 AM.';
	notas[11] = '';
	notas[12] = 'Desde el 1/12/2011 al 19/12/2011';	

	if (hotel=='m'){ // Milano
		// (Doble,DobleTerra,Triple,Cuadruple)
		tarifas[1] = new Array(70,90,99,115);		// Pre-Temporada
		tarifas[2] = new Array(175,195,220,250);		// Fin de a–o
		tarifas[3] = new Array(130,150,160,180);		// Enero 
		tarifas[4] = new Array(105,125,130,145);		// Febrero
		tarifas[5] = new Array(130,150,160,180); 		// Carnaval
		tarifas[6] = new Array(70,85,99,115); 		// Marzo
		tarifas[7] = new Array(99,125,145,160); 		// Semana Santa
	} else { // Florinda
		// (Single,Doble,DobleSup,Comunic,Depto)
		tarifas[11] = new Array(58,78,99,115,138);	// Noviembre 
		tarifas[12] = new Array(80,90,99,115,138);	// Diciembre 
		tarifas[2] = new Array(195,195,225,285,345);	// Fin de a–o
		tarifas[3] = new Array(150,150,170,220,270);	// Enero
		tarifas[4] = new Array(125,125,145,190,210);	// Febrero
		tarifas[5] = new Array(150,150,170,220,270); 	// Carnaval
		tarifas[6] = new Array(65,85,99,115,138); 	// Marzo
		tarifas[7] = new Array(125,125,145,190,210);	// 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];
	}
}

