/************** FUNCIONES JAVASCRIPT RESERVAS ****************************************************/
/*************************************************************************************************/
/*************************************************************************************************/

/* INICIO PIE */
function contacta(url, cadena, id_hotel)
{
		features="width="+(400)+",height="+(275)+",top=20,left=20,status=yes,scrollbars=yes";
		url_contacto = url + '?action=contactar';
		if (cadena) url_contacto += '&cadena=' + cadena;
		if (id_hotel) url_contacto += '&id_hotel=' + id_hotel
		win=window.open(url_contacto,'bar',features);
}
/* FIN PIE */

/* INICIO PASO_1 */

//INICIO: funcions de inicialitzaci� de la data
function getDaysInMonth(month,year)
{
	var days;
	if(month==1 || month==3 || month==5 || month==7 || month==8 || month==10 || month==12) days=31;
		else if(month==4 || month==6 || month==9 || month==11) days=30;
			else if(month==2)
			{
				if (isLeapYear(year)) days=29;
					else days=28;
			}
	return (days);
}

function isLeapYear (Year)
{
	if(((Year % 4)==0) && ((Year % 100)!=0) || ((Year % 400)==0))
	{
		return (true);
	}else
		{
			return (false);
		}
}

//Displayamos los dias que tiene el mes seleccionado
function DisplayMonthDays(mes, anyo, where)
{
	var days;
	days = getDaysInMonth(mes.selectedIndex+1, anyo.value);

	if (document.step1) frms=eval("document.step1."+where);
	else frms=eval("document.subs."+where);

	//Guardamos el dia seleccionado para seleccionarlo si se puede al recargar el select
	old_selected = frms.selectedIndex;

	//Miramos que no sea negativo
	if(old_selected < 0) old_selected = 0;

	//Construimos la cadena de options a parsear en el combo
	var option = "";
	var n;
	frms.length=0;
	for(n=1;n<=days;n++)
	{
		var no = new Option();
		if (n < 10) n = "0" + n;
		no.value = n;
		no.text = n;
		frms[n-1] = no;
	}

	//Seleccionamos si podemos el indice anterior.
	largo = frms.length;
	if(largo > old_selected)
	{
		//Se puede seleccionar
		frms[old_selected].selected=true;
	}else
	{
		//seleccionamos el ultimo ya que no podemos seleccionar el anterior por ser mas grande que el mayor actual.
		frms[largo-1].selected=true;
	}

}
//END: funcions de inicialitzaci� de la data

function habitaciones(n_hab,max_hab)
{
	var cont, cont2;

	for (cont=1; cont <= n_hab; cont++)
	{
		document.getElementById("capa"+cont).style.display='';
	}

	for (cont2 = cont ; cont2 <= max_hab ; cont2++)
	{
		document.getElementById("capa"+cont2).style.display='none';
	}
}

function registrate()
{
	usuario = document.getElementById("usuario").value;
	password = document.getElementById("password").value;
	sid = document.getElementById("sid").value;
	idioma = document.getElementById("idioma").value;

	if (usuario != '' && password != '') jsrsExecute("club.php", fin_registro, "registro", Array( usuario, password, sid, idioma) );
}

function fin_registro(cadena)
{
	document.getElementById("registrado").innerHTML = cadena;
}

/* FIN PASO_1 */

/* INICIO PASO_2 */

// Funcion para volver del paso 2 al paso 1, manteniendo las fechas y cambiar la distribucion de habitaciones
function redistribuir(url,dia,mes,anyo,noches,hab_totales, idioma, id_referer, id_room, cadena, id_hotel)
{
	if (id_referer)
	{
		if (id_room)
		{
			document.location = (url + '?action=muestra_paso1&dia=' + dia + '&mes=' + mes + '&anyo=' + anyo + '&noches=' + noches + '&n_hab=' + hab_totales + '&idioma=' + idioma + '&id_referer=' + id_referer + '&id_hab=' + id_room + "&cadena=" + cadena + "&id_hotel=" + id_hotel);
		}
		else
		{
			document.location = (url + '?action=muestra_paso1&dia=' + dia + '&mes=' + mes + '&anyo=' + anyo + '&noches=' + noches + '&n_hab=' + hab_totales + '&idioma=' + idioma + '&id_referer=' + id_referer + "&cadena=" + cadena + "&id_hotel=" + id_hotel);
		}
	}
	else
	{
		if (id_room)
		{
			document.location = (url + '?action=muestra_paso1&dia=' + dia + '&mes=' + mes + '&anyo=' + anyo + '&noches=' + noches + '&n_hab=' + hab_totales + '&idioma=' + idioma + '&id_hab=' + id_room + "&cadena=" + cadena + "&id_hotel=" + id_hotel);
		}
		else
		{
			document.location = (url + '?action=muestra_paso1&dia=' + dia + '&mes=' + mes + '&anyo=' + anyo + '&noches=' + noches + '&n_hab=' + hab_totales + '&idioma=' + idioma + "&cadena=" + cadena + "&id_hotel=" + id_hotel);
		}
	}
}

// Funcion para vaciar un desplegable
function borrar_desplegable(objecto)
{
	if(objecto )
	{
		for(i=0; i < objecto.length; i++)
		{
			a=(i+1);
			objecto.options[a]=null;
		}

		objecto.selectedIndex = 0;
	}
}

// Funcion para rellenar el seleccionable de ocupantes adicionales
function puebla_ocupantes_adicionales(objecto, id_habitacion)
{
	if (document.getElementById("ocupantes_desplegable_"+id_habitacion) )
	{
		borrar_desplegable(objecto);

		ocupantes_distintos_txt = document.getElementById("ocupantes_desplegable_"+id_habitacion).value;

		ocupantes_distintos_partes = ocupantes_distintos_txt.split("&#&");

		if (ocupantes_distintos_partes.length > 0 )
		{
			for(i=0;i<ocupantes_distintos_partes.length;i++)
			{
				a=(i+1);
				partes = ocupantes_distintos_partes[i].split("&@&");
				//alert( partes[1] );
				objecto.options[a] = new Option(partes[1],partes[0]);
			}
		}
	}
	else { //alert('puebla_ocupantes');
	}
}

// Funcion para rellenar el seleccionable de pensiones
function puebla_pensiones(id_hab, pensiones)
{
	var seleccionable = document.getElementById(pensiones);
	var q = seleccionable.length;
	for(i=0;i<q;i++)
	{
		a=(q-i);
		seleccionable.options[a]=null;
	}
	seleccionable.selectedIndex = 0;

	var pensiones_valor_str = document.getElementById("pensiones_desplegable_"+id_hab).value;

	pensiones_distintas = pensiones_valor_str.split("&#&");

	if (pensiones_distintas.length > 0 )
	{
		for(i=0;i<pensiones_distintas.length;i++)
		{
			a=(i+1);
			partes = pensiones_distintas[i].split("&@&");
			seleccionable.options[a] = new Option(partes[1],partes[0]);
		}
	}

	seleccionable.selectedIndex = 1;
}

// Funcion para mostrar los precios dia a dia, ya sean por persona o por habitacion
function muestra_precios(n_hab, decimales, moneda_del, moneda_tra)
{
	var array_ocup = new Array();
	var datos = false;
	var i;

	tipo_precio = document.getElementById("tipo_precio").value;
	precio_texto = "<table border=\"0\">";

	var length_hab = eval("document.subs.escoge_hab_"+n_hab+".length");

	if (!length_hab) length_hab = 1;

	for (i=0; i < length_hab; i++)
	{
		if (length_hab == 1)
		{
			datos = eval("document.subs.escoge_hab_"+n_hab+".value");
		}
		else
		{
			if (eval("document.subs.escoge_hab_"+n_hab+"["+i+"].checked"))
			{
				datos = eval("document.subs.escoge_hab_"+n_hab+"["+i+"].value");
			}
		}
	}

	detalle = datos.split("@");
	n_ocupantes = detalle[2];
	n_personas = document.getElementById("n_personas_"+n_hab).value;

	ocupacion_normal = n_personas - n_ocupantes;

	pension = document.getElementById("pension_"+n_hab).value;
	linia_precio = document.getElementById("linia_pr["+detalle[0]+"]["+pension+"]["+n_personas+"]").value;

	precio_tmp = 0;
	precio_dia_ant = 0;
	num_dias = document.getElementById("noches").value;
	inicio = true;

	if (n_ocupantes > 0)
	{
		for (cont = 0; cont<num_dias; cont++)
		{
			if (inicio)
			{
				dia_ini = document.getElementById("precio_dia[" + cont + "][dia]").value;
			}

			dia_fin = document.getElementById("precio_dia[" + cont + "][dia]").value;
			contador = cont + 1;

			precio_tmp = parseFloat(document.getElementById("precio_dia["+linia_precio+"][" + cont + "][" + detalle[0] + "][" + pension + "]").value);
			// Miramos si el precio tiene recargo
			if (document.getElementById("recargo_"+n_hab+"_"+detalle[0]+"_"+cont))
			{
				recargo = document.getElementById("recargo_"+n_hab+"_"+detalle[0]+"_"+cont).value;
			}
			else recargo = 0;
			precio_ini = precio_tmp;

			recargo = recargo / ocupacion_normal;

			precio_sin = parseFloat(precio_tmp) - parseFloat(recargo);

			if (tipo_precio == 1)
			{
				precio_sin = parseFloat(precio_sin / ocupacion_normal);
				precio_tmp = parseFloat(precio_tmp / ocupacion_normal);
			}
			else
			{
				precio_sin = parseFloat(precio_sin / ocupacion_normal);
				//precio_tmp = parseFloat(precio_tmp / ocupacion_normal);
			}

			texto_ocup = "";

			for (i = 1; i <= n_ocupantes; i++)
			{
				id_ocup = document.getElementById("ocupantes_"+n_hab+"_"+i).value;
				array_ocup[id_ocup] = 0;
			}

			for (i = 1; i <= n_ocupantes; i++)
			{
				id_ocupante = document.getElementById("ocupantes_"+n_hab+"_"+i).value;

				<!-- BEGIN esconde_detalle_descuento_ocupantes_adicionales1 -->

				if (document.getElementById('ocupante_porcentaje').value == 1)
				{

					/*******************************************************/
					precio_ocup = document.getElementById("precio_dia["+linia_precio+"][" + cont + "][" + detalle[0] + "][" + pension + "][" + id_ocupante + "]").value;

					if (document.getElementById("precio_dia["+linia_precio+"][" + (cont+1) + "][" + detalle[0] + "][" + pension + "][" + id_ocupante + "]"))
					{
						precio_ocup_sig = document.getElementById("precio_dia["+linia_precio+"][" + (cont+1) + "][" + detalle[0] + "][" + pension + "][" + id_ocupante + "]").value;
					}
					else precio_ocup_sig = precio_ocup;

					pr_ocup = precio_ocup.split("@");
					pr_ocup_sig = precio_ocup_sig.split("@");

					//j = i - 1;
					/*if (pr_ocup[j])
					{
						precio_ocup = pr_ocup[j];
					}*/
					if (pr_ocup[1])
					{
						r = array_ocup[id_ocupante];
						precio_ocup = pr_ocup[r];
						precio_ocup_sig = pr_ocup_sig[r];
						array_ocup[id_ocupante]++;
					}
					else
					{
						precio_ocup = pr_ocup[0];
						precio_ocup_sig = pr_ocup_sig[0];
					}
					/*******************************************************/

					//if (tipo_precio == 0) precio_pax = parseFloat(precio_sin / ocupacion_normal);
					//else precio_pax = precio_sin;
					precio_pax = precio_sin;

					//descuento = (precio_ocup - precio_pax) * 100 / precio_pax;
					descuento = (precio_ocup - precio_tmp) * 100 / precio_tmp;

					opt= document.getElementById("ocupantes_"+ n_hab +"_" + i).selectedIndex;
					ocup = document.getElementById("ocupantes_"+ n_hab +"_" + i).options[opt].text;

					texto_ocup += "<tr><td class=\"textegris\" align=\"right\">" + ocup + "</td>";
					if (descuento == 0)
						texto_ocup += "<td>&nbsp</td><td class=\"texte\" align=\"right\">" + descuento + "%</td></tr>";
					else
						texto_ocup += "<td>&nbsp</td><td class=\"texte\" align=\"right\">" + roundOff(descuento, decimales) + "%</td></tr>";
				}
				else
				{
					/*******************************************************/
					precio_ocup = document.getElementById("precio_dia["+linia_precio+"][" + cont + "][" + detalle[0] + "][" + pension + "][" + id_ocupante + "]").value;
					if (document.getElementById("precio_dia["+linia_precio+"][" + (cont+1) + "][" + detalle[0] + "][" + pension + "][" + id_ocupante + "]"))
					{
						precio_ocup_sig = document.getElementById("precio_dia["+linia_precio+"][" + (cont+1) + "][" + detalle[0] + "][" + pension + "][" + id_ocupante + "]").value;
					}
					else precio_ocup_sig = precio_ocup;

					pr_ocup = precio_ocup.split("@");
					pr_ocup_sig = precio_ocup_sig.split("@");

					//j = i - 1;
					//if (pr_ocup[j]) precio_ocup = pr_ocup[j];
					if (pr_ocup[1])
					{
						r = array_ocup[id_ocupante];
						precio_ocup = pr_ocup[r];
						precio_ocup_sig = pr_ocup_sig[r];
						array_ocup[id_ocupante]++;
					}
					else
					{
						precio_ocup = pr_ocup[0];
						precio_ocup_sig = pr_ocup_sig[0];
					}
					/*******************************************************/

					opt= document.getElementById("ocupantes_"+ n_hab +"_" + i).selectedIndex;
					ocup = document.getElementById("ocupantes_"+ n_hab +"_" + i).options[opt].text;

					texto_ocup += "<tr><td class=\"textegris\" align=\"right\" nowrap>" + ocup + "</td>";
					if (precio_ocup == 0)
						texto_ocup += "<td>&nbsp</td><td class=\"texte\" align=\"right\">" + moneda_del + precio_ocup + moneda_tra + "</td></tr>";
					else
						texto_ocup += "<td>&nbsp</td><td class=\"texte\" align=\"right\">"+ moneda_del + roundOff(precio_ocup, decimales) + moneda_tra + "</td></tr>";
				}
					<!-- END esconde_detalle_descuento_ocupantes_adicionales1 -->
			}

			if (contador == num_dias)
			{
				if (dia_ini == dia_fin)
				{
					precio_texto += "<tr><td class=\"textegris\" align=\"right\">" + dia_ini + "</td>";
				}
				else precio_texto += "<tr><td class=\"textegris\" align=\"right\">" + dia_ini + " - " + dia_fin +"</td>";

				precio_texto += "<td>&nbsp</td><td class=\"texte\" align=\"right\" nowrap>" + moneda_del + roundOff(precio_tmp, decimales) + moneda_tra + "</td></tr>";

				precio_texto += texto_ocup;
			}
			else
			{
				precio_sig = parseFloat(document.getElementById("precio_dia["+linia_precio+"][" + contador + "][" + detalle[0] + "][" + pension + "]").value);
				//afegit 23 gener 2008. Pau.
				if (tipo_precio == 1) precio_sig = parseFloat(precio_sig / ocupacion_normal);
				//s'ha de tenir en compte el preu per ocupant, no nom�s el preu per habitaci�/persona.
				if ( (precio_tmp == precio_sig) && (precio_ocup_sig == precio_ocup) )
				//if (precio_tmp == precio_sig)
				{
					inicio = false;
				}
				else
				{
					if (dia_ini == dia_fin)
					{
						precio_texto += "<tr><td class=\"textegris\" align=\"right\">" + dia_ini + "</td>";
					}
					else precio_texto += "<tr><td class=\"textegris\" align=\"right\">" + dia_ini + " - " + dia_fin +"</td>";

					precio_texto += "<td>&nbsp</td><td class=\"texte\" align=\"right\">" + moneda_del + roundOff(precio_tmp, decimales) + moneda_tra + "</td></tr>";

					precio_texto += texto_ocup;

					inicio = true;
				}
			}
		}
		//precio_texto += texto_ocup;
	}
	else // No hay ocupantes adicionales
	{
		for (cont = 0; cont<num_dias; cont++)
		{
			if (inicio)
			{
				dia_ini = document.getElementById("precio_dia[" + cont + "][dia]").value;
			}
			dia_fin = document.getElementById("precio_dia[" + cont + "][dia]").value;

			precio_tmp = parseFloat(document.getElementById("precio_dia["+linia_precio+"][" + cont + "][" + detalle[0] + "][" + pension + "]").value);

			if (tipo_precio == 1) precio_tmp = parseFloat(precio_tmp / ocupacion_normal);

			contador = cont + 1;
			if (contador == num_dias)
			{
				if (dia_ini == dia_fin)
				{
					precio_texto += "<tr><td class=\"textegris\" align=\"right\">" + dia_ini + "</td>";
				}
				else precio_texto += "<tr><td class=\"textegris\" align=\"right\">" + dia_ini + " - " + dia_fin +"</td>";

				precio_texto += "<td>&nbsp</td><td class=\"texte\" align=\"right\">" + moneda_del + roundOff(precio_tmp, decimales)  + moneda_tra + "</td></tr>";
			}
			else
			{
				precio_sig = parseFloat(document.getElementById("precio_dia["+linia_precio+"][" + contador + "][" + detalle[0] + "][" + pension + "]").value);

				if (tipo_precio == 1) precio_sig = parseFloat(precio_sig / ocupacion_normal);

				if (precio_tmp == precio_sig)
				{
					inicio = false;
				}
				else
				{
					if (dia_ini == dia_fin)
					{
						precio_texto += "<tr><td class=\"textegris\" align=\"right\">" + dia_ini + "</td>";
					}
					else precio_texto += "<tr><td class=\"textegris\" align=\"right\">" + dia_ini + " - " + dia_fin +"</td>";

					precio_texto += "<td>&nbsp</td><td class=\"texte\" align=\"right\">" + moneda_del + roundOff(precio_tmp, decimales) + moneda_tra + "</td></tr>";

					inicio = true;
				}
			}
		}
	}

	precio_texto += "</table>";

	return precio_texto;
}

// Funcion que recalcula el precio de una habitacion
function recalcula(n_hab)
{
	var precio, precio_hab, precio_total;

	if (hab_completa(n_hab))
	{
		precio = calcula_precio(n_hab);
		document.getElementById("completa_"+n_hab).value = 1;

		// Mostramos el precio de la habitacion
		//precio_hab = roundOff(precio, 2);
		precio_hab = precio_dia(n_hab);
		document.getElementById("p_"+n_hab).innerHTML = precio_hab;

		// Calcular el Precio total de la Reserva
		calcula_precio_total(n_hab, precio);
	}
	else
	{
		document.getElementById("completa_"+n_hab).value = 0;

		// Calcular el Precio total de la Reserva
		calcula_precio_total(n_hab, 0);
		document.getElementById("p_"+n_hab).innerHTML = "";
	}
}

// Funcion para calcular el precio total de una habitacion
function calcula_precio(n_hab)
{
	var datos, detalle;
	var pension;
	var n_ocupantes, id_ocupante, n_personas;
	var i;
	var precio_ocup;
	var array_ocup = new Array();
	var datos = false;

	var lenght_hab = eval("document.subs.escoge_hab_"+n_hab+".length");

	if (!lenght_hab) lenght_hab = 1;

	for (i=0; i < lenght_hab; i++)
	{
		if (lenght_hab == 1)
		{
			datos = eval("document.subs.escoge_hab_"+n_hab+".value");
		}
		else
		{
			if (eval("document.subs.escoge_hab_"+n_hab+"["+i+"].checked"))
			{
				datos = eval("document.subs.escoge_hab_"+n_hab+"["+i+"].value");
			}
		}
	}

	detalle = datos.split("@");
	n_ocupantes = detalle[2];
	n_personas = document.getElementById("n_personas_"+n_hab).value;

	pension = document.getElementById("pension_"+n_hab).value;
	linia_precio = document.getElementById("linia_pr["+detalle[0]+"]["+pension+"]["+n_personas+"]").value;
//	alert(linia_precio);
	document.getElementById("linia_precio["+n_hab+"]").value = linia_precio;
	document.getElementById("completa_"+n_hab).value = 1;

	precio = document.getElementById("precio["+linia_precio+"]["+detalle[0]+"]["+pension+"]").value;

	for (i = 1; i <= n_ocupantes; i++)
	{
		id_ocup = document.getElementById("ocupantes_"+n_hab+"_"+i).value;
		array_ocup[id_ocup] = 0;
	}

	for (i = 1; i <= n_ocupantes; i++)
	{
		id_ocupante = document.getElementById("ocupantes_"+n_hab+"_"+i).value;

		precio_ocup = document.getElementById("precio["+linia_precio+"]["+detalle[0]+"]["+pension+"]["+id_ocupante+"]").value;

		pr_ocup = precio_ocup.split("@");
		j = i - 1;

		/*if (pr_ocup[j]) precio_ocup = pr_ocup[j];
		else
		{
			if (pr_ocup[j] == 0) precio_ocup = 0;
			else precio_ocup = pr_ocup[0];
		}*/
		if (pr_ocup[1])
		{
			r = array_ocup[id_ocupante];
			precio_ocup = pr_ocup[r];
			array_ocup[id_ocupante]++;
		}
		else precio_ocup = pr_ocup[0];

		precio = parseFloat(precio) + parseFloat(precio_ocup);
	}

	return precio;
}

// Funcion que calcula el precio total de la reserva


// Funciona para comprobar si una habitacion ha sido completada
function hab_completa(n_hab)
{
	var i;
	var seleccionados = true;
	var completa = false;
	var detalle;
	var datos = false;

	var lenght_hab = eval("document.subs.escoge_hab_"+n_hab+".length");

	if (!lenght_hab) lenght_hab = 1;

	for (i=0; i < lenght_hab; i++)
	{
		if (lenght_hab == 1)
		{
			datos = eval("document.subs.escoge_hab_"+n_hab+".value");
		}
		else
		{
			if (eval("document.subs.escoge_hab_"+n_hab+"["+i+"].checked"))
			{
				datos = eval("document.subs.escoge_hab_"+n_hab+"["+i+"].value");
			}
		}
	}

	if (datos)
	{
		detalle = datos.split("@");

		if (detalle[0] != 0)
		{
			for (i=1 ; i <= detalle[2] ; i++)
			{
				// Comprobamos que todos los ocupantes estan seleccionados
				if (document.getElementById("ocupantes_"+n_hab+"_"+i).value == 0) seleccionados = false;
			}

			if (seleccionados)
			{
				// Comprobamos si la pension esta seleccionda
				if (document.getElementById("pension_"+n_hab).value != 0) completa = true;
			}
		}
	}

	return completa;
}

// Funcion que selecciona la habitacion al cargar la pagina si solo hay una, tambien selecciona siempre la
// primera pension
function selecciona_habitacion(hab_totales, siempre)
{
	var i, j, max_ocup_add, lenght_hab;

	if (hab_totales > 0)
	{
		for (i = 1 ; i <= hab_totales ; i++)
		{
			if (eval("document.subs.escoge_hab_"+i+""))
			{
				lenght_hab = eval("document.subs.escoge_hab_"+i+".length");
				sel_hab = eval("document.subs.escoge_hab_"+i+"");

				if (!lenght_hab) lenght_hab = 1;

				for (j=0; j < lenght_hab; j++)
				{
					if (sel_hab)
					{
						if (j == 0)
						{
							if (lenght_hab == 1)
							{
								sel_hab.checked = true;
								max_ocup_add = document.getElementById("max_ocup_add_" + i);
								escoje_hab(sel_hab.value, i, max_ocup_add);

								ocup = sel_hab.value;
							}
							else
							{
								sel_hab[j].checked = true;
								max_ocup_add = document.getElementById("max_ocup_add_" + i);
								escoje_hab(sel_hab[j].value, i, max_ocup_add);

								ocup = sel_hab[j].value;
							}

							datos_ocup = ocup.split("@");

							if (datos_ocup[2] == 0)
							{
								sel_pen = document.getElementById("pension_" + i);
								sel_pen[1].selected = true;
								recalcula(i);
							}
						}
					}
				}
			}
		}
	}
}

function busca_servicios(sid, n_hab, id_hab, num_personas)
{
	var impuestos = document.getElementById("impuestos_incluidos").value;
	jsrsExecute("getInfoReservas.php", muestra_servicios, "getInfoServicios", Array( sid, n_hab, id_hab, num_personas, impuestos) );
}

function muestra_servicios(resultado)
{
	datos_res = resultado.split("@@@");	
	document.getElementById("capa_servicios_" + datos_res[0]).innerHTML = datos_res[1];

	if (datos_res[1] != "")
	{
		document.getElementById("titulo_servicios").innerHTML= document.getElementById("serv_adicionales").value;
		document.getElementById("total_servicios").innerHTML= document.getElementById("prec_servicios").value;
		
		if (datos_res[2])
		{
			obli = datos_res[2].split("##");
			
			for (i=0 ; i < obli.length; i++)
			{
				if (obli[i] != "")
				{
					serv_obli = obli[i].split("-");
					selecciona_servicio(serv_obli[0],serv_obli[1],serv_obli[2], false);
				}
			}
		}
	}
	else
	{
		document.getElementById("titulo_servicios").innerHTML='';
		document.getElementById("total_servicios").innerHTML='';
	}
}

function selecciona_servicio(n_hab, id_hab, id_servicio, cantidad_serv)
{
	var decimales = document.getElementById("decimales").value;
	var moneda_del = document.getElementById("moneda_del").value;
	var moneda_det = document.getElementById("moneda_det").value;

	total_anterior = parseFloat(document.getElementById("total_servicios_" + n_hab).value);
	document.getElementById("total_servicios_anterior_" + n_hab).value = total_anterior;

	if (document.getElementById("serv_"+ n_hab + "_" + id_servicio).checked)
	{
		// Seleccionamos el servicio

		precio_servicio = document.getElementById("precio_servicios_"+n_hab+"_"+id_hab+"_" + id_servicio).value;

		if (!document.getElementById("cantidad_" + n_hab + "_" + id_servicio)) cantidad = false;
		else cantidad = document.getElementById("cantidad_" + n_hab + "_" + id_servicio).value;

		if (cantidad_serv !== false || cantidad !== false)
		{
			cantidad_anterior = document.getElementById("cantidad_anterior_" + n_hab + "_" + id_servicio).value;
			total_anterior = parseFloat(total_anterior) - parseFloat((precio_servicio * cantidad_anterior));
			document.getElementById("cantidad_anterior_" + n_hab + "_" + id_servicio).value = cantidad_serv;

			precio_servicio = precio_servicio * cantidad;

			document.getElementById("cantidad_anterior_" + n_hab + "_" + id_servicio).value = cantidad;
		}

		total = parseFloat(total_anterior) + parseFloat(precio_servicio);
	}
	else
	{
		// Deseleccionamos el servicio

		if (!cantidad_serv)
		{
			if (!document.getElementById("cantidad_" + n_hab + "_" + id_servicio)) cantidad = 1;
			else cantidad = document.getElementById("cantidad_" + n_hab + "_" + id_servicio).value;

			precio_servicio = document.getElementById("precio_servicios_"+n_hab+"_"+id_hab+"_" + id_servicio).value * cantidad;
			total = parseFloat(total_anterior) - parseFloat(precio_servicio);

			/*alert("tot_anterior:"+total_anterior);
			alert("precio_servicio:"+precio_servicio);
			alert("total:"+total);*/

			if (document.getElementById("cantidad_anterior_" + n_hab + "_" + id_servicio))
				document.getElementById("cantidad_anterior_" + n_hab + "_" + id_servicio).value = 0;
		}
		else
		{
			total = parseFloat(total_anterior);
			document.getElementById("cantidad_anterior_" + n_hab + "_" + id_servicio).value = 0;
		}
	}

	//alert("total_servicios:"+total);
	document.getElementById("total_servicios_" + n_hab).value = total;
	//alert("total_servicios_" + n_hab);
	document.getElementById("capa_total_servicios_" + n_hab).innerHTML = moneda_del + roundOff(total, decimales) + moneda_det;
	//alert("capa_total_servicios_" + n_hab);
	recalcula(n_hab);
	document.getElementById("total_servicios_anterior_" + n_hab).value = total;
}

// Funcion que muestra el precio total de las habitaciones
function calcula_precio_total(n_hab, precio)
{
	var precio_total, fee;
	var precio_anterior;
	var moneda_del = document.getElementById("moneda_del").value;
	var moneda_det = document.getElementById("moneda_det").value;
	var decimales = document.getElementById("decimales").value;

	precio_anterior = document.getElementById("precio_hab["+n_hab+"]").value;
	precio_total = document.getElementById("precio_total").value;

	if (document.getElementById("total_servicios_anterior_" + n_hab))
		precio_servicios_anterior = document.getElementById("total_servicios_anterior_" + n_hab).value;
	else
		precio_servicios_anterior = 0;

	if (document.getElementById("total_servicios_" + n_hab))
		precio_servicios = document.getElementById("total_servicios_" + n_hab).value;
	else
		precio_servicios = 0;

	precio_total = parseFloat(precio_total) - parseFloat(precio_anterior) + parseFloat(precio) - parseFloat(precio_servicios_anterior) + parseFloat(precio_servicios);

	document.getElementById("precio_hab["+n_hab+"]").value = precio;
	document.getElementById("precio_total").value = precio_total;

	fee = document.getElementById("fee").value;
	if (fee != 0)
	{
		subtotal = precio_total;
		if (subtotal == 0) subtotal = roundOff(0, decimales);
		else subtotal = roundOff(subtotal, decimales);

		document.getElementById("capa_subtotal").innerHTML = moneda_del + subtotal + moneda_det;
		precio_total = parseFloat(precio_total) + parseFloat(fee);
	}

	if (precio_total == 0) precio_total = roundOff(0, decimales);
	else precio_total = roundOff(precio_total, decimales);

	/*
		function selecciona(elem_check, nom_elements) {
	var valor = elem_check.checked;
	var elements = document.getElementsByName(nom_elements);
	for (var i = 0; i < elements.length; i++) {
		elements[i].checked = valor;
	}
}
	*/

	var elements = document.getElementsByName("");

	document.getElementById("capa_precio_total").innerHTML = moneda_del + precio_total + moneda_det;
}

// Funcion que ense�a un pop up indicando la restriccion que tiene la habitacion
function restricciones(minimo_dias, recargo, porcentaje, url, idioma)
{
	features="width="+(500)+",height="+(150)+",top=225,left=150,status=yes,scrollbars=yes";
	win=window.open( url + '?action=restricciones&idioma=' + idioma + '&minimo_dias=' + minimo_dias + '&recargo=' + recargo + '&porcentaje=' + porcentaje,'bar',features);
}

function condiciones()
{
	/*features="width="+(450)+",height="+(500)+",top=20,left=20,status=yes,scrollbars=yes";
	win=window.open('', 'condiciones', features);
	document.condiciones.target="condiciones";
	document.condiciones.submit();*/

	if (document.getElementById("condiciones"))
	{
		if (document.getElementById("condiciones").style.display == '')
			document.getElementById("condiciones").style.display = 'none';
		else
			document.getElementById("condiciones").style.display = '';
	}
}

/* FIN PASO_2 */

/* INICIO PASO 5*/
function activa_pago(max_pago)
{
	var i;
	var acepto;

	if (document.getElementById("acepto").checked) acepto = true;
	else acepto = false;
	for (i = 0 ; i < max_pago ; i++)
	{
		if (acepto) document.getElementById("f_pago_" + i).style.cursor = 'pointer';
		else document.getElementById("f_pago_" + i).style.cursor = '';
	}
}
/* FIN PASO 5*/
function popup(url, ample, alt)
{
	var winl = (screen.width-ample)/2;
	var wint = (screen.height-alt)/2;
	var opcions=('top='+wint+',left='+winl+',width='+ample+',height='+alt+',toolbar='+0+',menubar='+0+',status='+0+',scrollbars='+1+',resizable='+1);
	var finestra = 'freetibet';
	window.open(url, finestra, opcions);
}

function acceptNum(evt)
{
	var nav4 = window.Event ? true : false;
	// NOTE: Backspace = 8, Enter = 13, '0' = 48, '9' = 57
	var key = nav4 ? evt.which : evt.keyCode;

	return (key <= 13 || (key >= 48 && key <= 57));
}

