//cambiar select de capacidad alojamientos
function cambiar_select_ninos (num_aloj)
{
	
	capacidad_maxima_adultos = document.getElementById("capacidad_maxima_adultos").value;
	capacidad_maxima_ninos = document.getElementById("capacidad_maxima_ninos").value;
	capacidad_maxima = (capacidad_maxima_adultos*1) + (capacidad_maxima_ninos*1);
	
	n_adultos_seleccionados = document.getElementById("n_adultos_" + num_aloj + "_alojamientos").value;
	n_ninos_restante = (capacidad_maxima*1) - (n_adultos_seleccionados*1);
	
	nombre_select = "n_ninos_" + num_aloj + "_alojamientos"; 
	vaciar_select (nombre_select);
	for (per=0;per<=n_ninos_restante;per++)
	{
		insertar_elemento_select (nombre_select,per, per)
	}
	vac=1;
 

}

//Muestra u oculta el número de alojamientos que se seleccione en el select de n_alojamientos
function mostrar_acomodamientos(maximo)
{
	tipo_sel = getRadioButtonSelectedValue(document.form_reservas.tipo);
	num_habitaciones= document.getElementById("n_alojamientos_"+tipo_sel).value;
	num_habitaciones = (num_habitaciones * 1);
	maximo= (maximo * 1);
	for (i=2;i<=num_habitaciones;i++)
	{
	 capa="hab_" + i + "_" + tipo_sel; 
	 document.getElementById(capa).style.display="block";
	 capan="habn_" + i + "_" + tipo_sel; 
	 document.getElementById(capan).style.display="block";
	}
	num_habitaciones = (num_habitaciones * 1) + 1;
	for (i=num_habitaciones;i<=maximo;i++)
	{
	 capa="hab_" + i + "_" + tipo_sel; 
	 document.getElementById(capa).style.display="none";
	 capan="habn_" + i + "_" + tipo_sel; 
	 document.getElementById(capan).style.display="none";
	}
	
}


//Muestra u oculta el formulario de excursiones, alojamientos o viajes
function mostrar_form_barra_reservas (capa)
{
	if (capa=="excursiones")
	{
	   post_capa = '_barra_reserva';
	   document.getElementById("viajes"+post_capa).style.display="none";
	   document.getElementById("alojamientos"+post_capa).style.display="none";
	   document.getElementById(capa+post_capa).style.display="block";
	}
	if (capa=="alojamientos")
	{
	   post_capa = '_barra_reserva';
	   document.getElementById("viajes"+post_capa).style.display="none";
	   document.getElementById("excursiones"+post_capa).style.display="none";
	   document.getElementById(capa+post_capa).style.display="block";
	}
	if (capa=="viajes")
	{
	   post_capa = '_barra_reserva';
	   document.getElementById("excursiones"+post_capa).style.display="none";
	   document.getElementById("alojamientos"+post_capa).style.display="none";
	   document.getElementById(capa+post_capa).style.display="block";
	}
}



//cambia la fecha de fin dependiendo de la de inicio
function cambia_fecha_fin ()
{
	tipo_sel = getRadioButtonSelectedValue(document.form_reservas.tipo);
	var fecha_ini = document.getElementById("fecha_ini"+tipo_sel).value; // Se asume válida
	var fecha_fin = document.getElementById("fecha_fin"+tipo_sel).value; // Se asume válida
	
	var manana = document.form_reservas.manana.value; // Se asume válida
	if (Comparar_Fecha(manana,fecha_ini)) 
	{
	  if (!Comparar_Fecha(fecha_ini,fecha_fin)) 
		 document.getElementById("fecha_fin"+tipo_sel).value=document.getElementById("fecha_ini"+tipo_sel).value
	  else
		 calcula_noches();
	}
	else
	{
		document.getElementById("fecha_ini"+tipo_sel).value = manana;
		alert (document.form_reservas.error_fecha_hoy.value);
	}
	
}

//calcula noches entre dos fechas   
function calcula_noches()
	{
		
		tipo_sel = getRadioButtonSelectedValue(document.form_reservas.tipo);
	
		var sFc0 = document.getElementById("fecha_ini"+tipo_sel).value; // Se asume válida
	    var sFc1 = document.getElementById("fecha_fin"+tipo_sel).value; // Se asume válida
		if (!Comparar_Fecha(sFc0,sFc1)) 
		{
		   alert (document.form_reservas.error_fecha.value);
		   document.getElementById("fecha_fin"+tipo_sel).value=document.getElementById("fecha_ini"+tipo_sel).value
		   calcula_noches();
		}
		else
		{
		 
			var nDi0 = parseInt(sFc0.substr(0, 2), 10);
			var nMe0 = parseInt(sFc0.substr(3, 2), 10);
			var nAn0 = parseInt(sFc0.substr(6, 4), 10);
			var nDi1 = parseInt(sFc1.substr(0, 2), 10);
			var nMe1 = parseInt(sFc1.substr(3, 2), 10);
			var nAn1 = parseInt(sFc1.substr(6, 4), 10);
			if (mayorOIgual(nDi0, nMe0, nAn0, nDi1, nMe1, nAn1))
			{
				 if (sFc0!=sFc1)
				 {
				 var nAno = anosEntre(nDi0, nMe0, nAn0, nDi1, nMe1, nAn1);
				 var nMes = mesesEntre(nDi0, nMe0, nAn0, nDi1, nMe1, nAn1);
				 var nDia = diasEntre(nDi0, nMe0, nAn0, nDi1, nMe1, nAn1);
				 var nTtM = nAno * 12 + nMes;
				 var nTtD = nDia;
				 for (var i = nAn0; i < nAn0 + nAno; i++) nTtD += diasDelAno(nAno);
				 for (var j = nMe0; j < nMe0 + nMes; j++) nTtD += finMes(j, nAn1);
				 var nTSS = Math.floor(nTtD / 7);
				 var nTSD = nTtD % 7;
				 }
				 else
				 {
					nTtD=1; 
				 }
				 /*document.frm.difDMA.value = String(nAno) + " años, " + String(nMes) + " meses, " + String(nDia) + " días";
				 document.frm.difDM.value = String(nTtM) + " meses, " + String(nDia) + " días";*/
				 if (nTtD==0)
				 {
					 document.getElementById("noches_"+tipo_sel).value = 1; // + " días";
				 }
				 else
				 {
					 //document.getElementById("noches_"+tipo_sel).value = String(nTtD); // + " días";
					 document.getElementById("noches_"+tipo_sel).value = String(nDia); // + " días";
				 }
				 
				 /*document.frm.difSD.value = String(nTSS) + " semanas, " + String(nTSD) + " días";*/
			}
		}
		
	}



function validar_form_barra_reservas() {
  
  tipo_sel = getRadioButtonSelectedValue(document.form_reservas.tipo);
  if (tipo_sel="excursiones")
  {
	  
  }
  
  if (tipo_sel="alojamientos")
  {
	  
  }
  
  
  if (tipo_sel="viajes")
  {
	  
  }  
  
  document.form_reservas.submit();
	
}	


