// Esta variable define la funcion que se ejecuta en caso de qwue haya errores o mensajes a mostrar al usuario
var enviar_confirm = function (msg)
                    {
                        // Mostramos las advertencias al usuario
                        if (confirm(msg))
                        {
                            // Acepta
                            //mostrar_splash('splash_nowait.html');
                        	mostrarSplash();
                            document.forms['form'+id_tarifa_frm].submit();
                            return (true);
                        }
                        else return (false); // No acepta
                    };
var id_tarifa_frm = '';
var ida_sel = -1;
var vuelta_sel = -1;
var fijar_ida = false;
var fijar_vuelta = false;

function marcarV(id_tarifa, una_ida, una_vuelta, ida)
{

	if(ida)
	{
		if (ida_sel != -1 && id_tarifa != ida_sel)
		{
			// Desmarcamos la ida seleccionada anteriormente.
			desMarcarVuelo('vida'+ida_sel);
			ida_sel = '';
		}
	}
	if (!ida)
	{
		if (vuelta_sel != -1 && document.getElementsByName('vvuelta'+vuelta_sel) && id_tarifa != vuelta_sel)
		{
			// Desmarcamos la vuelta seleccionada anteriormente.
			desMarcarVuelo('vvuelta'+vuelta_sel);
			vuelta_sel = '';
		}
	}
	
	// Marca la ida o vuelta seleccionada.	
	if (ida)
	{	
		ida_sel = id_tarifa;
	}
	else
	{
		vuelta_sel = id_tarifa;
	}

	if (una_ida && vuelta_sel != -1 && id_tarifa != ida_sel)
	{
		// Si solo hay una ida y solo hay una vuelta y se ha marcado una vuelta, marcamos la ida
		if(!document.getElementsByName('vida'+id_tarifa)[0].checked)
		{
			document.getElementsByName('vida'+id_tarifa)[0].checked = true;
			// Desmarcamos la ida seleccionada anteriormente.
			if (ida_sel != -1)
			{
				desMarcarVuelo('vida'+ida_sel);
				ida_sel = '';
			}
			// Marcamos la nueva ida.
			ida_sel = id_tarifa;
		}
	}	
	if (una_vuelta && ida_sel != -1 && id_tarifa != vuelta_sel)
	{
		// Si solo hay una vuelta y solo hay una ida y se ha marcado una ida, marcamos la vuelta
		if(!document.getElementsByName('vvuelta'+id_tarifa)[0].checked)
		{
			document.getElementsByName('vvuelta'+id_tarifa)[0].checked = true;
			// Desmarcamos la vuelta seleccionada anteriormente.
			if (vuelta_sel != -1 && document.getElementsByName('vvuelta'+vuelta_sel))
			{
				desMarcarVuelo('vvuelta'+vuelta_sel);
				vuelta_sel = '';
			}
			// Marcamos la nueva vuelta.
			vuelta_sel = id_tarifa;
		}
	}

}
// Esta funcion desmarca un vuelo de ida o vuelta.
function desMarcarVuelo(campo)
{
	// Desmarcamos la vuelta seleccionada anteriormente.
	num_radio = document.getElementsByName(campo).length;
	for (i=0;i<num_radio;i++)
	{
		if (document.getElementsByName(campo)[i].checked)
		{
			document.getElementsByName(campo)[i].checked = false;
			break;
		}
	}
}

function enviar(id_tarifa, una_ida, una_vuelta)
{

	var continuar = true;
    texto = '';
	
	var ida_selected = -1;
	var vuelta_selected = -1;
	
	if (document.getElementsByName('vvuelta'+id_tarifa)[0])
		soloida = false;
	else
		soloida = true;
	
	// Si no es mullticaja marcamos la ida y vuelta 
	if (!mcj || soloida)
	{
		document.getElementsByName('vida'+id_tarifa)[0].checked = true;
		if (document.getElementsByName('vvuelta'+id_tarifa)[0])
			document.getElementsByName('vvuelta'+id_tarifa)[0].checked = true;
	}	
	
	// Comprobamos si es ida y vuelta q se haya escojido un vuelo de ida y uno de vuelta.
	for(i=0;i<document.getElementsByName('vida'+id_tarifa).length;i++)
	{
		if (document.getElementsByName('vida'+id_tarifa)[i].checked)
		{
			ida_selected = i;
			break;
		}
	}

	if (document.getElementsByName('vvuelta'+id_tarifa)[0]) // Mas de una vuelta
	{
		for(i=0;i<document.getElementsByName('vvuelta'+id_tarifa).length;i++)
		{
			if (document.getElementsByName('vvuelta'+id_tarifa)[i].checked)
			{
				vuelta_selected = i;
				break;
			}
		}
	}
	

	// Si solo hay una ida y una vuelta y es multicaja marcamos la ida y la vuelta.
	if (((mcj && !soloida) && una_ida) && una_vuelta)
	{
		document.getElementsByName('vida'+id_tarifa)[0].checked = true;
		ida_selected = 0;
		document.getElementsByName('vvuelta'+id_tarifa)[0].checked = true;
		vuelta_selected = 0;
	}
	
	// En caos de que este fijada la ida o la vuelta.
	if (fijar_ida)
		ida_selected = 0;
	if (fijar_vuelta)
		vuelta_selected = 0;
/*
	// En caos de que este fijada la ida o la vuelta.
	if (fv_idvue != '' && fijar_ida)
	{
		ida_selected = fv_idvue;
	}
	if (fv_idvue != '' && fijar_vuelta)
	{
		vuelta_selected = fv_idvue;
	}
*/
	if (((ida_selected == -1) 
		|| ((document.getElementById('vvuelta'+id_tarifa) && (vuelta_selected == -1)))
		) && !soloida)
		{
			//errores.push(new Error('11','150','026'));
			$('err'+id_tarifa).style.display='';
			continuar = false;
		}

	if (!continuar)
	{
		//errores.showAlert();
		return false;
	}

	al_aer_ida = '';
	al_aer_vuelta = '';
	aer_o_ida = '';
	aer_d_ida = '';
	aer_o_vuelta = '';
	aer_d_vuelta = '';
	
	v_i_sel = ''; 
	v_v_sel = '';
	/*
	if (fv_idtar != '' && fijar_ida)
	{
		tmp = id_tarifa;
		id_tarifa = fv_idtar;
		v_i_sel = fv_idvue;
	}
	else
	{*/
	v_i_sel = document.getElementsByName('vida'+id_tarifa)[ida_selected].value; 
	//}
	/*
	if (fv_idtar != '' && fijar_vuelta)
	{
		tmp = id_tarifa;
		id_tarifa = fv_idtar;
		v_v_sel = fv_idvue;
	}
	else
	{*/
	if (vuelta_selected != -1)
		v_v_sel = document.getElementsByName('vvuelta'+id_tarifa)[vuelta_selected].value;
	//}
	if (ida_selected != -1)
	{
		
		al_aer_ida = document.getElementById(id_tarifa+'_alerta_i_'+v_i_sel).value;
		aer_o_ida = document.getElementById(id_tarifa+'_o_i_'+v_i_sel).value;
		aer_d_ida =	document.getElementById(id_tarifa+'_d_i_'+v_i_sel).value;
	
	}
	if (vuelta_selected != -1)
	{
		al_aer_vuelta = document.getElementById(id_tarifa+'_alerta_v_'+v_v_sel).value;
		aer_o_vuelta = document.getElementById(id_tarifa+'_o_v_'+v_v_sel).value;
		aer_d_vuelta = document.getElementById(id_tarifa+'_d_v_'+v_v_sel).value;
	}
	// Asiganmos la alerta aer.
	//document.getElementById(id_tarifa+'alerta_aer').value = document.getElementById(id_tarifa+'alerta_aer_'+document.getElementById('tr_'+id_tarifa+'_'+document.getElementsByName('vida'+id_tarifa)[ida_selected].value).value).value;
	
	// Asiganamos los trayectos.
	document.getElementById('trayecto['+id_tarifa+'-0]').value = document.getElementById('itr_'+id_tarifa+'_'+v_i_sel).value;
	if (document.getElementsByName('vvuelta'+id_tarifa)[0])
	{
		document.getElementById('trayecto['+id_tarifa+'-1]').value = document.getElementById('vtr_'+id_tarifa+'_'+v_v_sel).value;
	}
	/*
	if (fv_it != '' && fijar_ida)
	{
		id_tarifa = tmp;
	}
	if (fv_it != '' && fijar_vuelta)
	{
		id_tarifa = tmp;
	}
	*/
    // Comprobamos si hay una ciudad secundaria para avisar al usuario, caso ida y vuelta
    if ((al_aer_ida.indexOf("6-") != -1) || (al_aer_ida.indexOf("8-") != -1) || (al_aer_vuelta.indexOf("6-") != -1) || (al_aer_vuelta.indexOf("8-") != -1))
    {
        //texto = errores['error_2820'];
        errores.push(new Error('11','150','001'));
    }
    //document.forms['form'+id_tarifa].id_res.value = randomString();
    if ((aer_o_vuelta != '') &&
    	((aer_o_ida != aer_d_vuelta) || (aer_d_ida != aer_o_vuelta))) 
    	errores.push(new Error('11','150','002'));
    
    //document.forms['form'+id_tarifa].id_res.value = randomString();
    if ((al_aer_ida.indexOf("1-") != -1) || ((al_aer_vuelta.indexOf("1-") != -1)))
    {
        errores.push(new Error('11','150','025'));
    }
    // Comprobamos si el vuelo es de iberia 6xxx, para informar al usuario q es un vuelo
    // internacional
    if ((al_aer_ida.indexOf("4-") != -1) || (al_aer_vuelta.indexOf("4-") != -1))
        errores.push(new Error('11','150','021'));
        
    // Comprobamos si el vuelo tiene una escala de mas de 6 horas
    if ((al_aer_ida.indexOf("5-") != -1) || (al_aer_vuelta.indexOf("5-") != -1))
        errores.push(new Error('11','150','029'));        

    if (errores.cuantos() > 0)
    {
        //alert('hola');
        errores.push(new Error('11','150','003'));
        id_tarifa_frm = id_tarifa;
        if (errores.eval(enviar_confirm))
        {
            return true;
        }
        else return false;
    }
    else
    {
        //alert('hola2');
        //mostrar_splash('splash_nowait.html');
    	mostrarSplash();
        document.forms['form'+id_tarifa].submit();
        return (true);
    }

}



function valid_form_mini(form)
{

	//Microsites para Xavi.
  	form.s_hora.disabled = false;
   	form.r_hora.disabled = false;
   	form.adultos.disabled = false;
   	form.ninos.disabled = false;
   	form.bebes.disabled = false;

    //errores_current = new Array();

    var ida_selected = false;
    if (form.soloida[1].checked) ida_selected = true;

    //origenes, destinos y rutas
    var orig = document.forms['busqueda_mini'].origen.value;
    var dest = document.forms['busqueda_mini'].destino.value;

    if (orig=="") errores.push(new Error('11','150','004','',setErrorBackColor(document.forms['busqueda_mini'].origen)));
    if (dest=="") errores.push(new Error('11','150','005','',setErrorBackColor(document.forms['busqueda_mini'].destino)));
    if ((orig!="" && dest!="") && orig.toUpperCase()==dest.toUpperCase()) errores.push(new Error('11','150','006','',setErrorBackColor(document.forms['busqueda_mini'].origen)));

    //viajeros
    /*
    // Edad niños no activo
    if (document.busqueda_mini.adultos[document.busqueda_mini.adultos.selectedIndex].value=="") errores_current.push(errores['error_5909']);
    if (document.busqueda_mini.adultos[document.busqueda_mini.adultos.selectedIndex].value==""
        && document.busqueda_mini.ninos[document.busqueda_mini.ninos.selectedIndex].value>0) errores_current.push(errores['error_5910']);
    if (document.busqueda_mini.adultos[document.busqueda_mini.adultos.selectedIndex].value==""
        && document.busqueda_mini.bebes[document.busqueda_mini.bebes.selectedIndex].value>0) errores_current.push(errores['error_5916']);
    if (document.busqueda_mini.bebes[document.busqueda_mini.bebes.selectedIndex].value
        > document.busqueda_mini.adultos[document.busqueda_mini.adultos.selectedIndex].value) errores_current.push(errores['error_5911']);

    */

     // Comprobamos se haya especificado el numero de viajeros
    if ((form.adultos[form.adultos.selectedIndex].value==0) &&
        (form.ninos[form.ninos.selectedIndex].value==0) &&
        (form.bebes[form.bebes.selectedIndex].value==0))
        errores.push(new Error('11','150','007','',setErrorBackColor(form.adultos)))

    // Comprobamos que si no se han escojido adultos los niños sean mayores de 11 años.
    if ((form.adultos[form.adultos.selectedIndex].value==0) &&
        (form.ninos[form.ninos.selectedIndex].value!=0))
        {
             for (i=1;i<=document.getElementById('ninos').value;i++)
            {

                if ((document.getElementById('edad_ninos_'+i).value <= 11) || (document.getElementById('edad_ninos_'+i).value == -1))
                {
                    errores.push(new Error('11','150','008','',setErrorBackColor(form.adultos)))
                    break;
                }
            }

        }
    // Comprobamos se haya introducido la edad de los niños
    if (!checkEdadNinos()) errores.push(new Error('11','150','018','',''));

    if (form.adultos[form.adultos.selectedIndex].value==0
        && form.bebes[form.bebes.selectedIndex].value>0) errores.push(new Error('11','150','009','',setErrorBackColor(form.adultos)))
    if (form.bebes[form.bebes.selectedIndex].value
        > form.adultos[form.adultos.selectedIndex].value) errores.push(new Error('11','150','010','',setErrorBackColor(form.adultos)))

	// Comprobamos si hay niños, que el numero de niños<5 años + numero de bebes, no sea mayor que el número de adultos + 1
	if (form.ninos[form.ninos.selectedIndex].value!=0)
	{
		var ninos_edad_menos_5 = 0;

		// Obtenemos el número de niños menos de 5 años
		for (i=1;i<=$('ninos').value;i++)
		{
			if (($('edad_ninos_'+i).value <5) && ($('edad_ninos_'+i).value != -1)) ninos_edad_menos_5++;
		}

		if (parseInt(ninos_edad_menos_5) + parseInt(form.bebes[form.bebes.selectedIndex].value) > (parseInt(form.adultos[form.adultos.selectedIndex].value)*2))
		{
			// Indicamos que no pueden viajar mas del doble de niños menores de 5 años + bebes que de adultos.
			errores.push(new Error('11','150','023','',setErrorBackColor(form.adultos)));
		}

	}

    //fechas solo si son fijas
    if (form.tipo_buscador.value=="fechas_fijas")
    {
        if (form.fecha_salida.value=="") errores.push(new Error('11','150','011','',setErrorBackColor(form.fecha_salida)));
        if (!form.soloida[1].checked && form.fecha_regreso.value=="") errores.push(new Error('11','150','012','',setErrorBackColor(form.fecha_regreso)));

        if (form.fecha_salida.value!="")
        {
            var s = form.fecha_salida.value;
            var a_fecha = s.split('/');
            var s_dia = a_fecha[0];
            var s_mes = a_fecha[1];
            var s_any = a_fecha[2];
            var fecha_salida = new Date(s_any, s_mes-1, s_dia);
            var fecha_salida_utime = fecha_salida.getTime();
            var fecha_reserva_utime_mini = "";
            // fecha_reserva_utime y fecha_reserva_uformat inicializadas en home.tpl
            //if(fecha_salida_utime < fecha_reserva_utime_mini) errores_current.push(errores['error_2805']+fecha_reserva_uformat_mini);
            //if(!checkDate(s_dia,s_mes-1,s_any)) errores_current.push(errores['error_2807']);

            if(fecha_salida_utime < fecha_reserva_utime_mini) errores.push(new Error('11','150','013','',setErrorBackColor(form.fecha_salida),new Array(fecha_reserva_uformat_mini)));
            if(!checkDate(s_dia,s_mes-1,s_any)) errores.push(new Error('11','150','014','',setErrorBackColor(form.fecha_salida)));

            if ((!form.soloida[1].checked) && form.fecha_regreso.value!="")
            {
                var r = form.fecha_regreso.value;
                var r_fecha = r.split('/');
                var r_dia = r_fecha[0];
                var r_mes = r_fecha[1];
                var r_any = r_fecha[2];
                var fecha_regreso = new Date(r_any,r_mes-1,r_dia);
                var fecha_regreso_utime = fecha_regreso.getTime();

                if(fecha_salida_utime > fecha_regreso_utime) errores.push(new Error('11','150','015','',setErrorBackColor(form.fecha_salida)));
                if(!checkDate(r_dia,r_mes-1,r_any)) errores.push(new Error('11','150','016','',setErrorBackColor(form.fecha_salida)));
            }
        }
    }

    // Comprobamos que los horarios seleccionados sean correctos, en el caso que ida y vuelta sean en el mismo dia
    if ((!form.soloida[1].checked) && (form.fecha_regreso.value == form.fecha_salida.value))
    {
        // Si la hora de salida es tarde la hora de vuelta solo puede ser tarde o noche
        if ((form.s_hora.value == 2) && (form.r_hora.value == 1))
            errores.push(new Error('11','150','017','',setErrorBackColor(form.fecha_salida)));

        // Si la hora de salida es noche la hora de vuelta solo puede ser noche
        if ((form.s_hora.value == 3) && ((form.r_hora.value == 1) || (form.r_hora.value == 2)))
            errores.push(new Error('11','150','017','',setErrorBackColor(form.fecha_salida)));
    }

    if (errores.cuantos()>0)
    {
        errores.showAlert();
        return(false);
    }
    else
    {
        return(true);
    }
}

function enviar_mini()
{
	if (valid_form_mini(document.forms.busqueda_mini))
    {

		//document.forms['busqueda_mini'].id_home.value = randomString();
        if($('_yuiResizeMonitor')) document.getElementById("_yuiResizeMonitor").style.display       = "none";
        if($('busqueda_actual_mask')) document.getElementById("busqueda_actual_mask").style.display    = "none";
        if($('busqueda_actual_c')) document.getElementById("busqueda_actual_c").style.display       = "none";
        //mostrar_splash('splash_nowait.html');
        mostrarSplash();

		document.forms['busqueda_mini'].id_home.value = randomString();
        document.forms['busqueda_mini'].submit();
    }
}

function enviar_mini_flex()
{
	if (valid_form_mini(document.forms.busqueda_flex))
    {

		//document.forms['busqueda_mini'].id_home.value = randomString();
        if($('_yuiResizeMonitor')) document.getElementById("_yuiResizeMonitor").style.display       = "none";
        if($('busqueda_actual_mask')) document.getElementById("busqueda_actual_mask").style.display    = "none";
        if($('busqueda_actual_c')) document.getElementById("busqueda_actual_c").style.display       = "none";
        //mostrar_splash('splash_nowait.html');
        mostrarSplash();

		document.forms['busqueda_flex'].id_home.value = randomString();
        document.forms['busqueda_flex'].submit();
    }
}

function filtrar(url)
{
    mostrar_splash('splash_nowait.html');
    window.location.href =url
                         +"&ciudades_secundarias="+document.getElementById("input_ciudades_secundarias").checked
                         +"&sin_escalas="+document.getElementById("input_escalas").checked
                         +"&hora_ida_salida="+document.getElementById("hora_ida_salida").value
                         +"&hora_ida_salida2="+document.getElementById("hora_ida_salida2").value
                         +"&hora_vuelta_salida="+document.getElementById("hora_vuelta_salida").value
                         +"&hora_vuelta_salida2="+document.getElementById("hora_vuelta_salida2").value;
}

function filtrar_soloida(url)
{
    mostrar_splash('splash_nowait.html');
    window.location.href =url
                         +"&ciudades_secundarias="+document.getElementById("input_ciudades_secundarias").checked
                         +"&sin_escalas="+document.getElementById("input_escalas").checked
                         +"&hora_ida_salida="+document.getElementById("hora_ida_salida").value
                         +"&hora_ida_salida2="+document.getElementById("hora_ida_salida2").value
}

function paginar(url, pagina)
{
    mostrar_splash('splash_nowait.html');
    window.location.href =url
                         +"&ciudades_secundarias="+document.getElementById("input_ciudades_secundarias").checked
                         +"&sin_escalas="+document.getElementById("input_escalas").checked
                         +"&hora_ida_salida="+document.getElementById("hora_ida_salida").value
                         +"&hora_ida_salida2="+document.getElementById("hora_ida_salida2").value
                         +"&hora_vuelta_salida="+document.getElementById("hora_vuelta_salida").value
                         +"&hora_vuelta_salida2="+document.getElementById("hora_vuelta_salida2").value
                         +"&pagina="+pagina;
}

function paginar_soloida(url, pagina)
{
    mostrar_splash('splash_nowait.html');
    window.location.href =url
                         +"&ciudades_secundarias="+document.getElementById("input_ciudades_secundarias").checked
                         +"&sin_escalas="+document.getElementById("input_escalas").checked
                         +"&hora_ida_salida="+document.getElementById("hora_ida_salida").value
                         +"&hora_ida_salida2="+document.getElementById("hora_ida_salida2").value
                         +"&pagina="+pagina;
}

function toggleCiudadesSecundarias()
{
    if (document.getElementById('input_ciudades_secundarias').checked)
        for (var i=0; i < tarifas_ciudades_secundarias.length; i++)
            if (document.getElementById(tarifas_ciudades_secundarias[i]))
                document.getElementById(tarifas_ciudades_secundarias[i]).style.display = 'none';
    if (!document.getElementById('input_ciudades_secundarias').checked)
        for (var i=0; i < tarifas_ciudades_secundarias.length; i++)
            if (document.getElementById(tarifas_ciudades_secundarias[i]))
                document.getElementById(tarifas_ciudades_secundarias[i]).style.display = '';
}

function toggleEscalas()
{
    if (document.getElementById('input_escalas').checked)
        for (var i=0; i < tarifas_escalas.length; i++)
            if (document.getElementById(tarifas_escalas[i]))
                document.getElementById(tarifas_escalas[i]).style.display = 'none';
    if (!document.getElementById('input_escalas').checked)
       for (var i=0; i < tarifas_escalas.length; i++)
            if (document.getElementById(tarifas_escalas[i]))
                document.getElementById(tarifas_escalas[i]).style.display = '';
}

function toggleHoras(caso)
{
    switch(caso){
        case 'ida_salida':
            for (var i=0; i < tarifas_horas.length; i++)
            {
                if (document.getElementById(tarifas_horas[i]+'_ida_salida').value >= document.getElementById('hora_ida_salida').options[document.getElementById('hora_ida_salida').selectedIndex].value)
                    document.getElementById(tarifas_horas[i]).style.display = '';
                else
                    document.getElementById(tarifas_horas[i]).style.display = 'none';
            }
            break;
        case 'ida_salida2':
            for (var i=0; i < tarifas_horas.length; i++)
            {
                if (document.getElementById(tarifas_horas[i]+'_ida_salida').value <= document.getElementById('hora_ida_salida2').options[document.getElementById('hora_ida_salida2').selectedIndex].value)
                    document.getElementById(tarifas_horas[i]).style.display = '';
                else
                    document.getElementById(tarifas_horas[i]).style.display = 'none';
            }
            break;
        case 'vuelta_salida':
            for (var i=0; i < tarifas_horas.length; i++)
            {
                if (document.getElementById(tarifas_horas[i]+'_vuelta_salida').value >= document.getElementById('hora_vuelta_salida').options[document.getElementById('hora_vuelta_salida').selectedIndex].value)
                    document.getElementById(tarifas_horas[i]).style.display = '';
                else
                    document.getElementById(tarifas_horas[i]).style.display = 'none';
            }
            break;
        case 'vuelta_salida2': {
            for (var i=0; i < tarifas_horas.length; i++)
            {
                if (document.getElementById(tarifas_horas[i]+'_vuelta_salida').value <= document.getElementById('hora_vuelta_salida2').options[document.getElementById('hora_vuelta_salida2').selectedIndex].value)
                    document.getElementById(tarifas_horas[i]).style.display = '';
                else
                    document.getElementById(tarifas_horas[i]).style.display = 'none';
            }
            break;
        }
        default:
            for (var i=0; i < tarifas_horas.length; i++)
            {
                if (document.getElementById(tarifas_horas[i]+'_ida_salida').value >= document.getElementById('hora_ida_salida').options[document.getElementById('hora_ida_salida').selectedIndex].value
                &&  document.getElementById(tarifas_horas[i]+'_ida_salida').value <= document.getElementById('hora_ida_salida2').options[document.getElementById('hora_ida_salida2').selectedIndex].value
                &&  document.getElementById(tarifas_horas[i]+'_vuelta_salida').value >= document.getElementById('hora_vuelta_salida').options[document.getElementById('hora_vuelta_salida').selectedIndex].value
                &&  document.getElementById(tarifas_horas[i]+'_vuelta_salida').value <= document.getElementById('hora_vuelta_salida2').options[document.getElementById('hora_vuelta_salida2').selectedIndex].value)
                    document.getElementById(tarifas_horas[i]).style.display = '';
                else
                    document.getElementById(tarifas_horas[i]).style.display = 'none';
            }
            break;
    }
}





var panel_yahoo="";
function  mostrar_desglose(id_tarifa, id_home, origen, destino){

	var una_ida = true;
	var una_vuelta = true;
	
	if($('desglose_'+id_tarifa).innerHTML != "")
	{
		$('desglose_'+id_tarifa).innerHTML = "";
	}
	else
	{

		// Obtenemos los vuelos marcados com ida y vuelta.
		ida_selected = '';
		vuelta_selected = '';
		
		if (document.getElementsByName('vida'+id_tarifa).length > 1)
			una_ida = false;
		if (document.getElementsByName('vvuelta'+id_tarifa).length > 1)
			una_vuelta = false;
		for(i=0;i<document.getElementsByName('vida'+id_tarifa).length;i++)
		{
			if (document.getElementsByName('vida'+id_tarifa)[i].checked)
			{
				ida_selected = document.getElementsByName('vida'+id_tarifa)[i].value;
				break;
			}
		}
		for(i=0;i<document.getElementsByName('vvuelta'+id_tarifa).length;i++)
		{
			if (document.getElementsByName('vvuelta'+id_tarifa)[i].checked)
			{
				vuelta_selected = document.getElementsByName('vvuelta'+id_tarifa)[i].value;;
				break;
			}
		}		
		// Si no se ha escojido vuelo de ida y de vuelta, escojemos el primer vuelo de ida y el primero de vuelta.
		if ((ida_selected == '') || (document.getElementById('vvuelta'+id_tarifa) && vuelta_selected == ''))
		{
			if (ida_selected == '')
			{
				ida_selected = document.getElementsByName('vida'+id_tarifa)[0].value;
				document.getElementsByName('vida'+id_tarifa)[0].checked = true;
			}
			if (document.getElementById('vvuelta'+id_tarifa) && vuelta_selected == '')
			{
				vuelta_selected = document.getElementsByName('vvuelta'+id_tarifa)[0].value;
				document.getElementsByName('vvuelta'+id_tarifa)[0].checked = true;
			}
		} 

		sUrl  = dir_vuelos+'index.php?pg=desglose_precios&id_home='+id_home+'&vi='+ida_selected+'&vv='+vuelta_selected+'&it='+id_tarifa+'&ori='+origen+'&des='+destino;

    	YAHOO.util.Connect.asyncRequest("GET", sUrl, {
                success: function(o) {
                   //hack rapido
                   url_actual = document.location+""; //forzamos cast a string
                   $('desglose_'+id_tarifa).innerHTML = o.responseText;
                },
                failure: function(o) {
                   respuesta ='Request failed: ' + o.statusText;
                }
            },false);
    	
    	// Desmarcamos el resto de idas/vueltas q se hayan marcado.
    	marcarV(id_tarifa,una_ida, una_vuelta, true);
    	marcarV(id_tarifa,una_ida, una_vuelta, false);
	}

}

function  mostrar_escalas(id_tarifa, id_home, e, posicion){

	var idDetalles = e.id;
    var aIdDetalles =idDetalles.split("_");
    idTarifa  = aIdDetalles[1];

	if($('escalas_'+posicion+'_'+idTarifa.substr(0,idTarifa.length-1)).innerHTML != "")
	{
		$('escalas_'+posicion+'_'+idTarifa.substr(0,idTarifa.length-1)).innerHTML = "";
	}
	else
	{

	    sUrl = document.getElementById("url_"+idTarifa).value+'&posicion='+posicion;

	    YAHOO.util.Connect.asyncRequest("GET", sUrl, {
	            success: function(o) {
	               url_actual = document.location+""; //forzamos cast a string
	               $('escalas_'+posicion+'_'+idTarifa.substr(0,idTarifa.length-1)).innerHTML = o.responseText;
	            },
	            failure: function(o) {
	               respuesta ='Request failed: ' + o.statusText;
	            }
	        },false);
	}
}
