//lunes, 04 de agosto de 2008 17:44:16
//variables globales
var cont = 0;//Nos permite saber los pasos del calendario.

//Ver pestañas////////////////////////////////////////////////////////////////////////////
function vervuelos() {
    document.getElementById("BUSCADOR_HOTELES").style.display = "none";
    document.getElementById("BUSCADOR_VUELOS").style.display = "";
    document.getElementById("BUSCADOR_VH").style.display = "none";
    document.getElementById("BUSCADOR_VAC").style.display = "none";
}

function verhoteles() {
    document.getElementById("BUSCADOR_HOTELES").style.display = "";
    document.getElementById("BUSCADOR_VUELOS").style.display = "none";
    document.getElementById("BUSCADOR_VH").style.display = "none";
    document.getElementById("BUSCADOR_VAC").style.display = "none";
}

function vervh() {
    document.getElementById("BUSCADOR_HOTELES").style.display = "none";
    document.getElementById("BUSCADOR_VUELOS").style.display = "none";
    document.getElementById("BUSCADOR_VH").style.display = "";
    document.getElementById("BUSCADOR_VAC").style.display = "none";
}

function vervac() {
    document.getElementById("BUSCADOR_HOTELES").style.display = "none";
    document.getElementById("BUSCADOR_VUELOS").style.display = "none";
    document.getElementById("BUSCADOR_VH").style.display = "none";
    document.getElementById("BUSCADOR_VAC").style.display = "";
}

//Envío formularios//////////////////////////////////////////////////////////////////////
function goSubmitVuelos (idform) {

		var formulario = document.getElementById(idform);
		formulario.depDate.value = formulario.fecha_dia_entrada_ida.value;
		formulario.depDate.value += "/";
		formulario.depDate.value += (formulario.fecha_mesanio_entrada_ida.value).substring(4,7);
		formulario.depDate.value += "/";
		formulario.depDate.value += (formulario.fecha_mesanio_entrada_ida.value).substring(0,4);

		formulario.retDate.value = formulario.fecha_dia_salida_vuelta.value;
		formulario.retDate.value += "/";
		formulario.retDate.value += (formulario.fecha_mesanio_salida_vuelta.value).substring(4,7);
		formulario.retDate.value += "/";
		formulario.retDate.value += (formulario.fecha_mesanio_salida_vuelta.value).substring(0,4);

		if ( formulario.depTime.value || formulario.retTime.value )
		{
			formulario.resultType.value = 'H';
		}

		formulario.submit();
}

function goSubmitHoteles (idform)
{
	 formulario = document.getElementById(idform);

		formulario.depDate.value = formulario.fecha_mesanio_entrada_ida.value;
		formulario.depDate.value += formulario.fecha_dia_entrada_ida.value;

		formulario.retDate.value = formulario.fecha_mesanio_salida_vuelta.value;
		formulario.retDate.value += formulario.fecha_dia_salida_vuelta.value;

		formulario.paxChd.value = formulario.paxHab.value.substring(2,3);	
		formulario.paxAdt.value = formulario.paxHab.value.substring(0,1);
		if ( (formulario.paxAdt.value == '1') && (formulario.paxChd.value == '1') )//Cambiado a esto por comentario hoteles
		{
			formulario.paxAdt.value = '2';
			formulario.paxChd.value = '0';

		}
		
		formulario.submit();

}

function goSubmitVH (idform) {
		var formulario = document.getElementById(idform);

		formulario.depDate.value = formulario.fecha_dia_entrada_ida.value;
		formulario.depDate.value += "/";
		formulario.depDate.value += formulario.fecha_mesanio_entrada_ida.value.substring(4,7);
		formulario.depDate.value += "/";
		formulario.depDate.value += formulario.fecha_mesanio_entrada_ida.value.substring(0,4);

		formulario.retDate.value = formulario.fecha_dia_salida_vuelta.value;
		formulario.retDate.value += "/";
		formulario.retDate.value += formulario.fecha_mesanio_salida_vuelta.value.substring(4,7);
		formulario.retDate.value += "/";
		formulario.retDate.value += formulario.fecha_mesanio_salida_vuelta.value.substring(0,4);

		if ( formulario.depTime.value || formulario.retTime.value )
		{
			formulario.resultType.value = 'H';
		}

		formulario.submit();
}

function goSubmitVacaciones (idform) {

		var formulario = document.getElementById(idform);

		formulario.fecha.value = formulario.fecha_dia_entrada_ida.value;
		formulario.fecha.value += "/";
		formulario.fecha.value += (formulario.fecha_mesanio_entrada_ida.value).substring(4,7);
		formulario.fecha.value += "/";
		formulario.fecha.value += (formulario.fecha_mesanio_entrada_ida.value).substring(0,4);

		formulario.submit();

}

function soloidavuelos(idayvuelta) {

	var formulario = document.getElementById('flightForm');
	if(idayvuelta)
	{
		formulario.fecha_mesanio_salida_vuelta.disabled = false;//select mes año salida habilitado
		formulario.fecha_dia_salida_vuelta.disabled = false;//select dia salida habilitado
        formulario.retTime.disabled = false;//select mejor precio habilitado
		formulario.retTime.value = "";//select mejor precio - valor defecto "mejor precio"
		formulario.ida_vueltav.src = "http://www.rumbo.es/afiliados/varios/marco1/imagenes/check_on.png";//cambio imagen check
		formulario.idav.src = "http://www.rumbo.es/afiliados/varios/marco1/imagenes/check_off.png";//cambio imagen check
		formulario.queryType.value = 'R';//valor ida y vuelta
	}
	else//lo contrario para ida
	{
		formulario.fecha_mesanio_salida_vuelta.disabled = true;
		formulario.fecha_dia_salida_vuelta.disabled = true;
		formulario.retTime.disabled = true;
		formulario.ida_vueltav.src = "http://www.rumbo.es/afiliados/varios/marco1/imagenes/check_off.png";
		formulario.idav.src = "http://www.rumbo.es/afiliados/varios/marco1/imagenes/check_on.png";
		formulario.queryType.value = 'O';//valor ida
	}

}

function change_lowcost() {

	var formulario = document.getElementById('flightForm');
	if (formulario.lowCost.value == 'true')
	{
		formulario.img_lowcost.src = "http://www.rumbo.es/afiliados/varios/marco1/imagenes/check_off.png";
		formulario.lowCost.value = 'false';
	}else {
		formulario.img_lowcost.src = "http://www.rumbo.es/afiliados/varios/marco1/imagenes/check_on.png";
		formulario.lowCost.value = 'true';
	}
}

function change_train() {

	var formulario = document.getElementById('flightForm');
	if (formulario.train.value == 'true')
	{
		formulario.img_train.src = "http://www.rumbo.es/afiliados/varios/marco1/imagenes/check_off.png";
		formulario.train.value = 'false';
	}else {
		formulario.img_train.src = "http://www.rumbo.es/afiliados/varios/marco1/imagenes/check_on.png";
		formulario.train.value = 'true';
	}
}


function vuelos_directos() {

	var formulario = document.getElementById('flightForm');

	if( formulario.directOnly.value == "" ){//valor a chequeado
		formulario.directOnly.value = 'S';//pongo valor si vuelo directo
		formulario.vd.src = "http://www.rumbo.es/afiliados/varios/marco1/imagenes/check_on.png";//imagen a check
		
	}else {
		formulario.directOnly.value = '';//valor a no vuelo directo
		formulario.vd.src = "http://www.rumbo.es/afiliados/varios/marco1/imagenes/check_off.png";//imagen a check off
		
	}
}

function Validar_Newsletter()	
{
	/*Se comprueba el formato del e-mail*/
	var formu_news = document.getElementById('newsletterForm');
	if(formu_news.email.value != "")
	{
		 var addressPattern = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
	     if (! addressPattern.test(formu_news.email.value)) 
		 {
  		 alert("Sintaxis incorrecta. Por favor, verifique el campo Email");
  	     formu_news.email.focus();
		 }else
		 {
		 window.open('','Boletin','scrollbars=no,toolbars=no,screenX=0,screenY=0,width=375,height=150') ;
		 formu_news.target="Boletin";
		 formu_news.submit();
		 }
	}
	else
	{
		alert("Por favor, rellene el campo Email");
	}
}

function rumbo_crear_fechas(idform,direccion) {
	if (direccion == "entrada_ida")//creamos campo oculto para entrada o ida
	{
    document.write('<input type="hidden" name="depDate" value="" />');
	}
	if (direccion == "salida_vuelta")//creamos campo oculto para salida o vuelta
	{
    document.write('<input type="hidden" name="retDate" value="" />');
	}
    var tabla_meses = new Array('Ene','Feb','Mar','Abr','May','Jun','Jul','Ago','Sep','Oct','Nov','Dic');//meses para mostrar en combo
	var fecha_hoy = new Date();
//	var fecha_hoy = new Date(2008,01,01);
	var dia_actual = fecha_hoy.getDate();
	var mes_actual = fecha_hoy.getMonth ();
    var anio_actual = fecha_hoy.getFullYear ();
		var numero_dias_mes = rumbo_dame_numero_dias_mes(anio_actual,mes_actual);//numero de dias para rellenar >>
	var nombre_mes = tabla_meses[mes_actual];//valor texto mes
	var anio_corto = anio_actual.toString().substring(2,4);//año 2 dígitos

	document.writeln('<select onchange="reset_noches();" class="textos" name="fecha_dia_'+direccion+'">');//creamos select con total días
		 				for (i = dia_actual; i <= numero_dias_mes; i++){
        				var j = (i < 10) ? "0"+i : i;//0 por delante
         				document.write('<option value='+j+'>'+j+'</option>');
						}
	document.write('</select>&nbsp;');

    document.writeln('<select class="textos" name="fecha_mesanio_'+direccion+'"');//creamos select mes y año
	document.writeln('onChange="actualizar_meses(\''+idform+'\',\''+direccion+'\'); reset_noches();">');//si cambiamos de mes actualizamos
    document.write('<option value="'+rumbo_dame_valor_aniomes(anio_actual,mes_actual)+'" selected="selected">'+nombre_mes+' '+anio_corto+'</option>');
         var i = mes_actual + 1;//por js

		 if (direccion == "entrada_ida")//creamos select con mes y año
		 {
			for (k=1; k < 13; k++){//un año y un mes más porque el calendario pop-up está limitado a un año, pero pueden verse días del mes siguiente y los pueden seleccionar.
           			if (i == 12){//es Enero
					i = 0;		//inicio meses
					anio_actual+=1;//siguiente año
					anio_corto = anio_actual.toString().substring(2,4);//para el select 2 cifras
           			}          			
	 			nombre_mes = tabla_meses[i];
         		document.write(' <option value="'+rumbo_dame_valor_aniomes(anio_actual,i)+'">'+nombre_mes+' '+anio_corto+'</option>');
         		i++;//siguiente mes						// ^ cogemos valores						
			}
		 }

		if (direccion == "salida_vuelta")//lo mismo para rellenar, pero un mes mas por si selecciona último día de último mes de entrada_ida y le suma tope de noches
		{								 //de lo contrario ese mes no existiría.
			for (k=1; k < 14; k++){
           			if (i == 12){
					i = 0;
					anio_actual+=1;
					anio_corto = anio_actual.toString().substring(2,4);
           			}          			
	 			nombre_mes = tabla_meses[i];
         		document.write(' <option value='+rumbo_dame_valor_aniomes(anio_actual,i)+'>'+nombre_mes+' '+anio_corto+'</option>');
         		i++;
			}
		}
			
	document.write('</select>');
}

function rumbo_dame_numero_dias_mes(anio_actual, mes_actual){
  	var mes_siguiente = new Date();
  	mes_siguiente.setFullYear(anio_actual,mes_actual + 1,0);//seteo valores hasta final mes para saber total dias mes
	return (mes_siguiente.getDate());
}

function rumbo_dame_valor_aniomes(anio, mes){
  var val_anio = anio.toString();
	mes++;//por js
  var val_mes = mes.toString();
  
  if (mes < 10){
     val_mes = "0" + val_mes;//0 por delante
  }
  return val_anio+val_mes;//valor concatenado - este será el valor del option
}

function actualizar_meses (idform,direccion) {
	
	var	formulario = document.getElementById(idform);
	
	var dia_index = eval("formulario.fecha_dia_"+direccion+".selectedIndex");//dia seleccionado index -- recojo dato para luego ponerlo después de actualizar; por comodidad para el usuario
	var dia_selec = eval("formulario.fecha_dia_"+direccion+".options["+dia_index+"].value");// valor dia seleccionado
	var mes_anio_index = eval("formulario.fecha_mesanio_"+direccion+".selectedIndex");//año mes indice seleccionado
	var mes_anio_value = eval("formulario.fecha_mesanio_"+direccion+".options[mes_anio_index].value");//año mes indice seleccionado valor
	var anio = mes_anio_value.substring(0,4);//año
	var mes = mes_anio_value.substring(4,6);//mes
	var dt_fecha = new Date(anio, mes, 0);//seteo nueva fecha con valores seleccionados
	var dias = dt_fecha.getDate();//obtengo total días
	var dt_fecha_hoy = new Date();//fecha de hoy
	var dia_hoy = dt_fecha_hoy.getDate();//dia de hoy

	var selectbox = eval("formulario.fecha_dia_"+direccion+"");//campo select

	for (i=selectbox.options.length-1; i>=0; i--)//Borrarmos todos los dias para pintarlos de nuevo según corresponda
	{
		selectbox.remove(i);
	}

	for (i=0; i<dias ;i++ ){//creamos de nuevo el select hasta el total de días del mes
			var j = i+1;
			if (j<10)
			{
				j = "0"+j;
			}
			eval("formulario.fecha_dia_"+direccion+".options[i] = new Option (j,j)");
	}
	
	if (mes_anio_index == 0)//si se selecciona el primer mes de la lista
	{
		for (i=0; i<dia_hoy-1; i++)//Borrarmos todos los dias consumidos
		{
		selectbox.remove(0);
		}
	}
	
	//pongo el dia como lo puso el usuario - por comodidad para el - si el dia no existe porque se consumió, simplemente pondrá el de inicio
	for (i=0; i<selectbox.options.length; i++ )
	{
		if (selectbox.options[i].value == dia_selec)
		{
			selectbox.options[i].selected = true;
		}
	}

}

function cambionoches() {//esta función suma las noches seleccionadas al día de entrada y pone la fecha de salida.
	
	var	formulario = document.getElementById('hotel_search');

	var fecha_hoy = new Date();
	var mes_hoy = fecha_hoy.getMonth();
	mes_hoy++;//js
	var anio_hoy = fecha_hoy.getFullYear();
	if (mes_hoy < 10)
	{
		mes_hoy = '0'+mes_hoy;//0 por delante para string
	}
	var anio_mes_hoy = anio_hoy+mes_hoy;//para luego comparar si seguimos en mismo mes y borrar días consumidos

	var anio_seleccionado = formulario.fecha_mesanio_entrada_ida.value.substring(0,4);//año
	var mes_seleccionado = formulario.fecha_mesanio_entrada_ida.value.substring(4,6);//mes
	mes_seleccionado--;//resto uno por js
	var dia_seleccionado = formulario.fecha_dia_entrada_ida.value;//dia
	var noches_seleccionadas = formulario.noches.value;//noches
	
	var dt_fecha_hoy = new Date();//fecha de hoy
	var dia_hoy = dt_fecha_hoy.getDate();//dia de hoy

	var dt_fecha = new Date (anio_seleccionado, mes_seleccionado, dia_seleccionado);//seteo nueva fecha con valores de selección
	dt_fecha.setDate(dia_seleccionado*1+noches_seleccionadas*1);//seteo dias sumando noches con dias actuales. *1 para que no concatene

	var dia_despues = dt_fecha.getDate();//valor dia después suma
	var mes_despues = dt_fecha.getMonth();//valor mes después suma
	var anio_despues = dt_fecha.getFullYear();//valor año después suma

	dt_fechab = new Date (anio_despues, mes_despues+1, 0);//creo nueva fecha para recoger número días mes
	var dias = dt_fechab.getDate();//dias mes

	var selectbox = formulario.fecha_dia_salida_vuelta;//es el campo select dias

	for (i=selectbox.options.length-1; i>=0; i--)//Borrarmos todos los dias para pintarlos de nuevo según corresponda
	{
		selectbox.remove(i);
	}

	for (i=0; i<dias ;i++ ){//creamos de nuevo el select hasta el total de días del mes
		var j = i+1;
		if (j<10)
		{
			j = "0"+j;
		}
		formulario.fecha_dia_salida_vuelta.options[i] = new Option (j,j);
	}
	

	//indice seleccion dia
	if (dia_despues < 10)
	{
		dia_despues = '0'+dia_despues;//0 por delante para string
	}

	for (i=0; i<selectbox.options.length; i++ )//recorremos el select hasta encontrar el día que le corresponde y marcamos seleccionado
	{
		if (selectbox.options[i].value == dia_despues)
		{
			selectbox.options[i].selected = true;
		}
	}

	//indice seleccion mes y año
	mes_despues++;//por js -> valor real del mes, para concatenar
	if (mes_despues < 10)
	{
		mes_despues = '0'+mes_despues;//0 por delante para string
	}

	var anio_mes = anio_despues+mes_despues;//concateno para comparar con valor del option
	selectbox2 = formulario.fecha_mesanio_salida_vuelta;//campo select aniomes

	for (i=0; i<selectbox2.options.length; i++)
	{
		if (selectbox2.options[i].value == anio_mes)
		{
			selectbox2.options[i].selected = true;
		}
	}
	
	if (anio_mes == anio_hoy+mes_hoy)//entonces seguimos estando en el mismo mes y tenemos que borrar días consumidos
	{
		for (i=0; i<dia_hoy-1; i++)
		{
		selectbox.remove(0);
		}
	}

}

function reset_noches() {//lo ponemos a valor inicial porque el valor de la suma de noches ya no sería correcto

	formulario = document.getElementById("hotel_search");
	formulario.noches.value = "";
}

function abrir_calendario(e,que_formulario,que_calendario,str_fecha,mover, valor_sentido){

	cont += valor_sentido;//pasos calendario

	var arr_meses = ["Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre"];
	var arr_dias_semana = ["Do", "Lu", "Ma", "Mi", "Ju", "Vi", "Sa"];
	var n_inicio_semana = 1; // Día de inicio de la semana (Domingo-Lunes  0-1)
	var dt_fecha = (str_fecha == null || str_fecha =="" ?  new Date() : dt_nuevafecha(str_fecha));
	var dt_fecha_hoy = new Date();
	var anio_hoy = dt_fecha_hoy.getFullYear();
	var mes_hoy = dt_fecha_hoy.getMonth();
	var anio_fecha = dt_fecha.getFullYear();
	var mes_fecha = dt_fecha.getMonth();
	
	
	if (anio_fecha == anio_hoy+1 && mes_hoy == mes_fecha)// Un año hacia adelante y ponemos tope -> escondemos botón de avance.
	{
		document.getElementById("boton_adelante").style.visibility = "hidden";
		cont -= 1;//le resto el paso que se ha hecho y no se va a lanzar calendario
		return;
	}

	var dt_fecha_menos_un_mes = new Date(dt_fecha);
	dt_fecha_menos_un_mes.setMonth(dt_fecha.getMonth()-1);
	var dt_fecha_mas_un_mes = new Date(dt_fecha); 
	dt_fecha_mas_un_mes.setMonth(dt_fecha.getMonth()+1);
	var dt_primer_dia_calendario = new Date(dt_fecha);
	dt_primer_dia_calendario.setDate(1);
	dt_primer_dia_calendario.setDate(1-(7+dt_primer_dia_calendario.getDay()-n_inicio_semana)%7);	
	var dt_ultimo_dia_calendario = new Date(dt_fecha_mas_un_mes);
	dt_ultimo_dia_calendario.setDate(0);


var gualdrapa_capa = document.getElementById('gualdrapa_capa');
var gualdrapa_marco = document.getElementById('gualdrapa_marco');
var calendario = document.getElementById('cal');

	var str_buffer = new String ( 
	"<table align='center' class='cal_fondo_TABLA' cellspacing='0' cellpadding='0' border='0' width='100%' height='100%'>"+
		"<tr>"+
			"<td>"+
				"<table align='center' style='border-collapse: collapse;' width='100%' height='100%' border='0'>"+
					"<tr>"+
"<td id='boton_atras' style='cursor: hand; cursor: pointer; visibility: hidden;'"+
"align='left' onclick='abrir_calendario(\"\",\""+que_formulario+"\",\""+que_calendario+"\",\""+fecha_a_fechastr(dt_fecha_menos_un_mes)+"\", \"mover\",-1);'>"+
"<img border='0' src='http://www.rumbo.es/afiliados/varios/marco1/imagenes/anterior.gif' alt='mes anterior' /></td>"+

"<td align='center' class='cal_titulo_CELDA'>"+arr_meses[dt_fecha.getMonth()]+" "+dt_fecha.getFullYear()+"</td>"+

"<td id='boton_adelante' style='cursor: hand; cursor: pointer;' align='right'"+
"onclick='abrir_calendario(\"\",\""+que_formulario+"\",\""+que_calendario+"\",\""+fecha_a_fechastr(dt_fecha_mas_un_mes)+"\", \"mover\",1);'>"+
"<img border='0' src='http://www.rumbo.es/afiliados/varios/marco1/imagenes/siguiente.gif' alt='mes siguiente' /></td>"+

					"</tr>"+
				"</table>"+
			"</td>"+
		"</tr>"+
		"<tr>"+
			"<td>"+
				"<table align='center' width='100%' class='cal_dias_semana_TABLA'>"+
					"<tr>"
	);

	var dt_dia_actual = new Date(dt_primer_dia_calendario);
	str_buffer += "<tr>";
	for (var n=0; n<7; n++)
	if(n==5||n==6)
	{
		str_buffer += "<td align='center' style='color: #FF3333;' >"+arr_dias_semana[(n_inicio_semana+n)%7]+"</td>";
	}
	else
	{
		str_buffer += "<td align='center'>"+arr_dias_semana[(n_inicio_semana+n)%7]+"</td>";
	}
		
	str_buffer += ("</tr>"+
			"</table>"+
		"</td>"+
	"</tr>"+
	"<tr>"+
		"<td>"+
			"<table align='center' width='100%'>");
	var solounavez = true;//solo pinto el número de día de hoy una vez
	while (dt_dia_actual.getMonth() == dt_fecha.getMonth() ||
		dt_dia_actual.getMonth() == dt_primer_dia_calendario.getMonth()) {
		// Imprimir cabecera columna
		str_buffer += "<tr>\n";
		for (var n_actual_dia_semana=0; n_actual_dia_semana<7; n_actual_dia_semana++) {
				
				/*if ( (dt_dia_actual.getTime() == dt_fecha.getTime()) && (mes_hoy == mes_fecha) && solounavez )
				{
					solounavez = false;
					// Imprimir hoy
					str_buffer += "	<td class=\"cal_dia_actual_CELDA\" style='cursor: pointer; cursor: hand;' align=\"center\" ";
					str_buffer += " onclick='dia_calendario(\""+fecha_a_fechastr(dt_dia_actual)+"\",\""+que_formulario+"\",\""+que_calendario+"\")' ";
					str_buffer += " onmouseover='this.style.background = \"#FFDD3F\";' onmouseout='this.style.background = \"#FFFFFF\";' > ";
				}
				else
				
				if (dt_dia_actual.getDate() == dt_fecha.getDate() &&
					mes_hoy == mes_fecha && solounavez)
				{
					solounavez = false;
					// Imprimir hoy
					str_buffer += "	<td class=\"cal_dia_actual_CELDA\" style='cursor: pointer; cursor: hand;' align=\"center\" ";
					str_buffer += " onclick='dia_calendario(\""+fecha_a_fechastr(dt_dia_actual)+"\",\""+que_formulario+"\",\""+que_calendario+"\")' ";
					str_buffer += " onmouseover='this.style.background = \"#FFDD3F\";' onmouseout='this.style.background = \"#FFFFFF\";' > ";
				}
				else */if (dt_dia_actual.getDay() == 0 || dt_dia_actual.getDay() == 6)
				{
					// Fines de semana
					if (( mes_hoy == mes_fecha )&&( dt_dia_actual < dt_fecha ))//si es día pasado deshabilito
					{
					str_buffer += "	<td class=\"cal_finde_CELDA_deshabilitado\" align=\"center\" ";
					str_buffer += " > ";
					}	
					else
					{
					str_buffer += "	<td class=\"cal_finde_CELDA\" style='cursor: pointer; cursor: hand;' align=\"center\" ";
					str_buffer += " onclick='dia_calendario(\""+fecha_a_fechastr(dt_dia_actual)+"\",\""+que_formulario+"\",\""+que_calendario+"\")' ";
					str_buffer += " onmouseover='this.style.background = \"#FFDD3F\";' onmouseout='this.style.background = \"#DDDDDD\";'> ";
					}
				}
				else
				{
					// Días laborables del mes
					if (( mes_hoy == mes_fecha )&&( dt_dia_actual < dt_fecha ))//si es día pasado deshabilito
					{
					str_buffer += "	<td class=\"cal_laborables_CELDA_deshabilitado\" align=\"center\" ";
					str_buffer += " > ";
					}	
					else
					{
					str_buffer += "	<td class=\"cal_laborables_CELDA\" style='cursor: pointer; cursor: hand;' align=\"center\" ";
					str_buffer += " onclick='dia_calendario(\""+fecha_a_fechastr(dt_dia_actual)+"\",\""+que_formulario+"\",\""+que_calendario+"\")' ";
					str_buffer += " onmouseover='this.style.background = \"#FFDD3F\";' onmouseout='this.style.background = \"#CCE3F2\";' > ";
					}
				}
				str_buffer += dt_dia_actual.getDate()+"</td>\n";
				dt_dia_actual.setDate(dt_dia_actual.getDate()+1);
		}
		// Imprimir pie columna
		str_buffer += "</tr>\n";
	}	
str_buffer += "</table></td></tr>";
	
	
	str_buffer += (
					"<tr>"+
						"<td>"+
							"<table align='center' width='100%' border='0'>"+
								"<tr>"+
									"<td align='center'"+
									"colspan='2' class='cal_cierre_CELDA'"+
									"style='cursor: pointer; cursor: hand;' onClick='cerrarCalendario();'>Cerrar</td>"+
								"</tr>"+
							"</table>"+
						"</td>"+
					"</tr>"+
				"</table>"
	);
	
	calendario.innerHTML =  str_buffer;
// Fin cadena calendario


  
    if(document.all){
	
	var x = window.event.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
	var y = window.event.clientY + document.body.scrollTop + document.documentElement.scrollTop;
	
	}else{
			
			var x = e.pageX;
			var y = e.pageY;
		 }

y = y-'10';
//x = '205';
x = x-'70';
x += 'px';
y += 'px';

// Solo definimos coordenadas calendario si es la primera vez. Porque las otras veces se queda en el mismo sitio.
if(!mover){
gualdrapa_capa.style.left = x;	
gualdrapa_capa.style.top = y;
gualdrapa_marco.style.left = x;	
gualdrapa_marco.style.top = y;
calendario.style.left = x;	
calendario.style.top = y;
}

gualdrapa_capa.style.display = 'inline';
gualdrapa_marco.style.display = 'inline';
calendario.style.display = 'inline';

//cuando existe calendario (inline)
gualdrapa_capa.style.width = calendario.style.width;
gualdrapa_marco.style.width = calendario.style.width;
gualdrapa_capa.style.height = calendario.style.height;
gualdrapa_marco.style.height = calendario.style.height;

//escondemos botón cuando es el mes de hoy
if (cont == 0)
{
	document.getElementById("boton_atras").style.visibility = "hidden";
}else{
		
	document.getElementById("boton_atras").style.visibility = "visible";
}

}	 
 
function cerrarCalendario(){

var calendario = document.getElementById('cal');
calendario.style.display = 'none';
var gualdrapa_capa = document.getElementById('gualdrapa_capa');	
gualdrapa_capa.style.display = 'none';
var gualdrapa_marco = document.getElementById('gualdrapa_marco');
gualdrapa_marco.style.display = 'none';

cont = 0;//reset calendario

}

function dia_calendario(fecha,que_formulario,direccion){

	cont= 0;//reset calendario
	reset_noches();

	var formulario = document.getElementById(que_formulario);

	//dividimos fecha para coger valores elegidos
	arr_fecha = fecha.split("/");
	var dia = arr_fecha[0];
	var mes = arr_fecha[1];
	var anio = arr_fecha[2];
	anio = anio.split(" ");//quito espacio al final
	if (dia <10) dia = '0'+dia;
	if (mes <10) mes = '0'+mes;

	var dt_fecha_hoy = new Date();//fecha de hoy
	var dia_de_hoy = dt_fecha_hoy.getDate();//dia de hoy para saber luego si tenemos que borrar días consumidos

	var dt_fecha = new Date(anio[0],mes-1,dia);//nueva fecha con valores elegidos
	dt_fecha.setFullYear(dt_fecha.getFullYear(), dt_fecha.getMonth()+1, 0);//seteo valores hasta final mes para saber total dias mes elegido
	var dias = dt_fecha.getDate();//total dias mes elegido

	var selectbox = eval("formulario.fecha_dia_"+direccion+"");//campo select dias

	for (i=selectbox.options.length-1; i>=0; i--)//Borrarmos todos los dias para pintarlos de nuevo según corresponda
	{
		selectbox.remove(i);
	}

	for (i=0; i<dias ;i++ ){//creamos de nuevo el select dias hasta el total de días del mes
		var j = i+1;
		if (j<10)
		{
			j = "0"+j;
		}
		eval("formulario.fecha_dia_"+direccion+".options[i] = new Option (j,j)");
	}
	
	eval("formulario.fecha_dia_"+direccion+".value = dia");//marco valor dia en el select
	eval("formulario.fecha_mesanio_"+direccion+".value = anio[0]+mes");//marco año mes en el select

	eval("var indice_mes = formulario.fecha_mesanio_"+direccion+".selectedIndex");//indice mes elegido

	if (indice_mes == 0)//si se ha elegido el primer mes - borramos los dias consumidos
	{
		for (i=0; i<dia_de_hoy-1; i++)//Borrarmos todos los dias consumidos
		{
		selectbox.remove(0);
		}
	}

	//cerramos calendario
	var gualdrapa_capa = document.getElementById('gualdrapa_capa');
	var gualdrapa_marco = document.getElementById('gualdrapa_marco');
	var calendario = document.getElementById('cal');
	gualdrapa_capa.style.display = 'none';
	gualdrapa_marco.style.display = 'none';
	calendario.style.display = 'none';
}

function fecha_a_fechastr (dt_mueve_mes) {
	return (new String (dt_mueve_mes.getDate()+"/"+(dt_mueve_mes.getMonth()+1)+"/"+dt_mueve_mes.getFullYear()+" "));
}

function dt_nuevafecha (str_fecha) {
	var re_date = /^(\d+)\/(\d+)\/(\d+)\s/;
	if (!re_date.exec(str_fecha))
		return alert("Invalid Datetime format: "+ str_fecha);
	return (new Date (RegExp.$3, RegExp.$2-1, RegExp.$1, RegExp.$4, RegExp.$5, RegExp.$6));
}


function edadNinhos(){

var formulario = document.getElementById("hotel_search");
document.getElementById("texto_edades").innerHTML = '';
document.getElementById("img_edades").style.display = 'none';

formulario.child1.value = "";
formulario.child2.value = "";
formulario.child3.value = "";
formulario.child4.value = "";
formulario.child5.value = "";
formulario.child6.value = "";
formulario.child7.value = "";
formulario.child8.value = "";
formulario.child9.value = "";
formulario.child10.value = "";

//segun los niños que haya pintamos tantos div como sea necesario

var numHabitaciones = formulario.numRooms.value;
var numNinhos = formulario.paxHab.value.substring(2,3);	

if(numNinhos!=0){		

	document.getElementById("rellenarEdades").style.display = 'inline';
	document.getElementById("gualdrapa_capa2").style.display = 'inline';
	document.getElementById("gualdrapa_marco2").style.display = 'inline';
	
	// Primero mostramos u ocultamos los divs de las habitaciones
	
	if (numHabitaciones == '1'){ document.getElementById("divHabitacion1").style.display = 'inline'; document.getElementById("divHabitacion2").style.display = 'none';
								 document.getElementById("divHabitacion3").style.display = 'none'; document.getElementById("divHabitacion4").style.display = 'none';
								 document.getElementById("divHabitacion5").style.display = 'none'; }

	if (numHabitaciones == '2'){ document.getElementById("divHabitacion1").style.display = 'inline'; document.getElementById("divHabitacion2").style.display = 'inline';
								 document.getElementById("divHabitacion3").style.display = 'none'; document.getElementById("divHabitacion4").style.display = 'none';
								 document.getElementById("divHabitacion5").style.display = 'none'; }

	if (numHabitaciones == '3'){ document.getElementById("divHabitacion1").style.display = 'inline'; document.getElementById("divHabitacion2").style.display = 'inline';
								 document.getElementById("divHabitacion3").style.display = 'inline'; document.getElementById("divHabitacion4").style.display = 'none';
								 document.getElementById("divHabitacion5").style.display = 'none'; }

	if (numHabitaciones == '4'){ document.getElementById("divHabitacion1").style.display = 'inline'; document.getElementById("divHabitacion2").style.display = 'inline'; 
								 document.getElementById("divHabitacion3").style.display = 'inline'; document.getElementById("divHabitacion4").style.display = 'inline';
								 document.getElementById("divHabitacion5").style.display = 'none';}
	
	if (numHabitaciones == '5'){ document.getElementById("divHabitacion1").style.display = 'inline'; document.getElementById("divHabitacion2").style.display = 'inline';
								 document.getElementById("divHabitacion3").style.display = 'inline'; document.getElementById("divHabitacion4").style.display = 'inline';
								 document.getElementById("divHabitacion5").style.display = 'inline';}

	// Ahora, según sean 0 hijos, 1 hijo o 2 hijos 

	if (numNinhos == '0'){	document.getElementById("ninho1").style.display = 'none'; document.getElementById("ninho2").style.display = 'none';
							document.getElementById("ninho3").style.display = 'none'; document.getElementById("ninho4").style.display = 'none';
							document.getElementById("ninho5").style.display = 'none'; document.getElementById("ninho6").style.display = 'none';
							document.getElementById("ninho7").style.display = 'none'; document.getElementById("ninho8").style.display = 'none';
							document.getElementById("ninho9").style.display = 'none'; document.getElementById("ninho10").style.display = 'none';}

	if (numNinhos == '1'){	document.getElementById("ninho1").style.display = 'inline'; document.getElementById("ninho2").style.display = 'none';
							document.getElementById("ninho3").style.display = 'inline';	document.getElementById("ninho4").style.display = 'none';
							document.getElementById("ninho5").style.display = 'inline'; document.getElementById("ninho6").style.display = 'none';
							document.getElementById("ninho7").style.display = 'inline'; document.getElementById("ninho8").style.display = 'none';
							document.getElementById("ninho9").style.display = 'inline'; document.getElementById("ninho10").style.display = 'none';}

	if (numNinhos == '2'){	document.getElementById("ninho1").style.display = 'inline'; document.getElementById("ninho2").style.display = 'inline';
							document.getElementById("ninho3").style.display = 'inline'; document.getElementById("ninho4").style.display = 'inline';
							document.getElementById("ninho5").style.display = 'inline'; document.getElementById("ninho6").style.display = 'inline';
							document.getElementById("ninho7").style.display = 'inline'; document.getElementById("ninho8").style.display = 'inline';
							document.getElementById("ninho9").style.display = 'inline'; document.getElementById("ninho10").style.display = 'inline';}

//Cambio dimensiones capa gualdrapa

	if (numHabitaciones == '1')
	{
		switch (numNinhos)
		{
		case '1': 
		document.getElementById('gualdrapa_capa2').style.height = "64px"; document.getElementById('gualdrapa_marco2').style.height = "64px"; break;
		break;
		case '2':
		document.getElementById('gualdrapa_capa2').style.height = "80px"; document.getElementById('gualdrapa_marco2').style.height = "80px"; break;
		break;
		}
	}
	if (numHabitaciones == '2')
	{
		switch (numNinhos)
		{
		case '1':
		document.getElementById('gualdrapa_capa2').style.height = "90px"; document.getElementById('gualdrapa_marco2').style.height = "90px"; break;
		break;
		case '2':
		document.getElementById('gualdrapa_capa2').style.height = "146px"; document.getElementById('gualdrapa_marco2').style.height = "146px"; break;
		break;
		}
	}
	if (numHabitaciones == '3')
	{
		switch (numNinhos)
		{
		case '1':
		document.getElementById('gualdrapa_capa2').style.height = "146px"; document.getElementById('gualdrapa_marco2').style.height = "146px"; break;
		break;
		case '2':
		document.getElementById('gualdrapa_capa2').style.height = "203px"; document.getElementById('gualdrapa_marco2').style.height = "203px"; break;
		break;
		}
	}
	if (numHabitaciones == '4')
	{
		switch (numNinhos)
		{
		case '1':
		document.getElementById('gualdrapa_capa2').style.height = "180px"; document.getElementById('gualdrapa_marco2').style.height = "180px"; break;
		break;
		case '2':
		document.getElementById('gualdrapa_capa2').style.height = "245px"; document.getElementById('gualdrapa_marco2').style.height = "245px"; break;
		}
	}
	if (numHabitaciones == '5')
	{
		switch (numNinhos)
		{
		case '1':
		document.getElementById('gualdrapa_capa2').style.height = "214px"; document.getElementById('gualdrapa_marco2').style.height = "214px"; break;
		break;
		case '2':
		document.getElementById('gualdrapa_capa2').style.height = "309px"; document.getElementById('gualdrapa_marco2').style.height = "309px"; break;
		}
	}

}
else{ 
	
	document.getElementById("rellenarEdades").style.display = 'none'; 
	document.getElementById("gualdrapa_capa2").style.display = 'none';
	document.getElementById("gualdrapa_marco2").style.display = 'none';
	
	}
}

function cancelarEdades() {

var formulario = document.getElementById("hotel_search");

document.getElementById("rellenarEdades").style.display = 'none';
document.getElementById('gualdrapa_capa2').style.display = 'none';
document.getElementById('gualdrapa_marco2').style.display = 'none';

formulario.child1.value = "";
formulario.child2.value = "";
formulario.child3.value = "";
formulario.child4.value = "";
formulario.child5.value = "";
formulario.child6.value = "";
formulario.child7.value = "";
formulario.child8.value = "";
formulario.child9.value = "";
formulario.child10.value = "";

document.getElementById("texto_edades").innerHTML = "";
document.getElementById("img_edades").display = "none";

formulario.numRooms.options.selectedIndex = '0';
formulario.paxHab.options.selectedIndex = '1';

}

function aceptarEdades() {

var formulario = document.getElementById("hotel_search");
var nChd = document.getElementById("hotel_search").paxHab.value.substring(2,3);
var nRooms = document.getElementById("hotel_search").numRooms.value; 
var edades = 'Edad ni&ntilde;os: /';

var aux = 1;
for(r=1; r<=nRooms; r++)
{
	for (i = 1; i <= nChd; i++)
	{
		if ( (eval("formulario.child"+aux+".value")) == '')
		{
			var mensaje = true;

		}else
		{
			edades += "<span class='texto_edades_edad'>";
			edades += eval("formulario.child"+aux+".value");
			edades += "</span>";
		}
	edades +='/';
	if(nChd==1){aux+=2;} else {aux++;}
	}
}

if (mensaje)
{
	alert("Falta seleccionar la edad de alg\u00FAn ni\u00F1o");
}else {
		document.getElementById("rellenarEdades").style.display = 'none';
		document.getElementById('gualdrapa_capa2').style.display = 'none';
		document.getElementById('gualdrapa_marco2').style.display = 'none';

		for (i=1;i<=10;i++ )
		{
		eval("formulario.child"+i+".value");
		}
		
		document.getElementById("texto_edades").style.display = 'inline';
		document.getElementById("texto_edades").innerHTML = edades;
		document.getElementById("img_edades").style.display = 'inline';
		}
}

function cambia_edades_on () {
document.getElementById("cambia_edades").style.display = "inline";
}
function cambia_edades_off () {
document.getElementById("cambia_edades").style.display = "none";
}


