  //deshabilitamos la fecha y hora de vuelta
  //document.getElementById('bloqueregreso').disabled=false;

  var tipocalendario = 'index';

  var daysBefore = 3;
  var daysVuelta = 7;
  var currentDate = new Date();
  currentDate.setDate(currentDate.getDate() + daysBefore);
  var salidaDate;
  var regresoDate ;

  salidaDate=new Date();
  salidaDate=currentDate;
  regresoDate=new Date(salidaDate.getFullYear(),salidaDate.getMonth(),salidaDate.getDate()+daysVuelta)


  window.document.getElementById('salida').value = (salidaDate.getDate()) + '/' + (salidaDate.getMonth()+1).toString() + '/' + salidaDate.getFullYear();
  if(document.formulariohome.idavuelta.value == 1)
  {
  window.document.getElementById('regreso').value=(regresoDate.getDate()) + '/' + (regresoDate.getMonth()+1).toString() + '/' + regresoDate.getFullYear();
  }

  function dateToLocaleString(dt, cal)
  {
  return dt.getDate().toString() + "/" + (dt.getMonth() + 1).toString() + "/" + dt.getFullYear().toString();
  }

  function stringToDate(strdate)
  {
  var arr=strdate.split("/");
  var date=new Date();
  if (arr.length=3)
  {
  date.setFullYear(arr[2]);
  date.setMonth(arr[1]-1);
  date.setDate(arr[0]);
  return date;
  }
  else
  return currentDate;
  }


//PARA EL ENLACE CON LAS OFERTAS
function enlaza_ofertas(origen,destino)
{
    document.location="ofertas.aspx?origenofertas=" + origen + "&checkintrodestino=unchecked&destinofertas=" + destino; 
}

function lanza_busqueda()
{
    validar_campos();
}

function comprobar_validacion() 
{
	if(GlobalAjaxObjectVal.readyState == 4)
	{
		if(GlobalAjaxObjectVal.status == 200)
		{ //200 = success
			text = GlobalAjaxObjectVal.responseText;
			var element = document.getElementById('validaciones');
			element.innerHTML=text;
			
			var totalninos = 0;
            var totaladultos = 0;
            var error = 0 ;
			
			//mostramos los mensajes de error
			if (document.getElementById('horigen').value == 0)
            {
                error=1;
                document.getElementById('avisoorigen').style.display='block';
            }
            else
            {
                document.getElementById('avisoorigen').style.display='none';
                document.getElementById('origen').value= document.getElementById('horigenvalue').value;
            }
            
            if (document.formulariohome.hdestino.value == 0)
            {
                error=1;
                document.getElementById('avisodestino').style.display='block';
            }
            else
            {
                document.getElementById('avisodestino').style.display='none';
                document.getElementById('destino').value= document.getElementById('hdestinovalue').value;
            }

            if (document.formulariohome.hsalida.value == 0)
            {
                error=1;
                document.getElementById('avisosalida').style.display='block';
            }
            else
            {
                document.getElementById('avisosalida').style.display='none';
            }
            
            if (document.getElementById('hregreso').value == 0)
            {
                error=1;
                document.getElementById('avisoregreso').style.display='block';
            }
            else
            {
                document.getElementById('avisoregreso').style.display='none';
            }
            
            if (document.getElementById('regreso').value.length != 11) 
            {
                document.getElementById('idavuelta').value=0;
            }
            else
            {
                document.getElementById('idavuelta').value=1;
            }
            totalninos = parseInt(document.getElementById('ninos').value) + parseInt(document.getElementById('bebes').value );
            totaladultos = (document.getElementById('adultos').value * 2);
      
            if (error==0)
            {
                if (totalninos <= totaladultos)
                {
                }
                else 
                {
                    alert('El número de bebes mas niños no puede ser mayor que el doble de adultos!!');
                    error = 1
                }
            }
            if (error==0)
            {
           	    document.getElementById('btnBuscar').src= '../../images/ES/botones/btn-buscando-pq.png';
                //se lanza la búsqueda en las webs de las agencias chequeadas
                try{
                    lanzar_paralela();
                }catch(err){
                }
                //se lanza la búsqueda en el portal
                document.formulariohome.submit()
            }
		}
	}
}

function validar_campos()
{
	if (window.XMLHttpRequest) //Non-IE Browsers
		GlobalAjaxObjectVal = new XMLHttpRequest(); //Global Variable
	else if(window.ActiveXObject) //IE Browsers
		GlobalAjaxObjectVal = new ActiveXObject("Msxml2.XMLHTTP");  //Global Variable
	else 
	{ //Your browsers is not compatible with AJAX
		alert('Your browser is not supported.')
		return; //exit
	}
	//Initialized the Ajax object to access the URL
    url="../validaciones.aspx?origen=" + document.formulariohome.origen.value.toString() + "&destino=" + document.formulariohome.destino.value.toString() + "&salida=" + document.formulariohome.salida.value.toString() + "&regreso=" + document.formulariohome.regreso.value.toString() + "&idayvuelta=" + document.formulariohome.tipovuelo[0].checked.toString() + "&ofertas=0";

	var url_encode= encodeURI(url);
	
	GlobalAjaxObjectVal.open("GET", url_encode );
	//GlobalAjaxObject.open("POST", document.formulariohome);
	//Sets the function that is run many times.
    GlobalAjaxObjectVal.onreadystatechange = comprobar_validacion;
	//Executes the request
	GlobalAjaxObjectVal.send(null);
}

function validar_campos_landing()
{
	if (window.XMLHttpRequest) //Non-IE Browsers
		GlobalAjaxObjectVal = new XMLHttpRequest(); //Global Variable
	else if(window.ActiveXObject) //IE Browsers
		GlobalAjaxObjectVal = new ActiveXObject("Msxml2.XMLHTTP");  //Global Variable
	else 
	{ //Your browsers is not compatible with AJAX
		alert('Your browser is not supported.')
		return; //exit
	}
	//Initialized the Ajax object to access the URL
    url="../../validaciones.aspx?origen=" + document.formulariohome.origen.value.toString() + "&destino=" + document.formulariohome.destino.value.toString() + "&salida=" + document.formulariohome.salida.value.toString() + "&regreso=" + document.formulariohome.regreso.value.toString() + "&idayvuelta=" + document.formulariohome.tipovuelo[0].checked.toString() + "&ofertas=0";

	var url_encode= encodeURI(url);
	
	GlobalAjaxObjectVal.open("GET", url_encode );
	//GlobalAjaxObject.open("POST", document.formulariohome);
	//Sets the function that is run many times.
    GlobalAjaxObjectVal.onreadystatechange = comprobar_validacion;
	//Executes the request
	GlobalAjaxObjectVal.send(null);
}

function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

function lanzar_paralela()
{
    var origen=document.formulariohome.origen.value.toString();
    origen=Right(origen,3);
    var destino=document.formulariohome.destino.value.toString();
    destino=Right(destino,3)
    var fecha_ida=document.formulariohome.salida.value.toString();
    var fecha_vuelta= document.formulariohome.regreso.value.toString();
    var ninos=parseInt(document.formulariohome.ninos.value);
    var bebes=parseInt(document.formulariohome.bebes.value );
    var adultos=parseInt(document.formulariohome.adultos.value);
    var oneway=1;
    if ((document.formulariohome.regreso.value.toString())!= "")
        oneway=0;
    
    var params="origen="+origen+"&destino="+destino+"&fecha_ida="+fecha_ida+"&fecha_vuelta="+fecha_vuelta+"&adultos="+adultos+"&ninos="+ninos+"&bebes="+bebes+"&hIncluirGastos=0";

    params= params+"&soloida="+oneway;
    
    var lastminute=document.getElementById('checkbox_lastmin').checked;
    var edreams=document.getElementById('checkbox_edreams').checked;
    var rumbo=document.getElementById('checkbox_rumbo').checked;
    
    if (lastminute)
        window.open("/Salto-a-Viajar.aspx?"+params,"viajar.com","fullscreen=no, resizable=yes","");
    if (edreams)    
        window.open("/Salto-a-Edreams.aspx?"+params,"edreams","fullscreen=no, resizable=yes","");
    if (rumbo)
        window.open("/Salto-a-Rumbo.aspx?"+params,"rumbo","fullscreen=no, resizable=yes","");
}

var avanzadas=false;

function ver_avanzadas()
{
    if (!avanzadas)
    {
        avanzadas=true;
        document.getElementById("desplegada-opciones-avanzadas").style.display="block";
    }
    else
    {
        avanzadas=false;
        document.getElementById("desplegada-opciones-avanzadas").style.display="none";
    }
    
}
function MiCuenta()
{
    window.open('../../UserLogin.aspx');
}
function MiCuentaHome()
{
     window.open('../UserLogin.aspx');
}
    
function elegir_aeropuerto(control)
{
    document.getElementById('hcontrol').value=control;
    document.getElementById('listado-aeropuertos').style.display='block';
    if(control=='origen')
    {
    	if(window.ActiveXObject)
		    document.getElementById('listado-aeropuertos').style.left='400px';
	    else 
            document.getElementById('listado-aeropuertos').style.left='275px';
    }
    else
    {
        if(control=='destino')
        {
    	    if(window.ActiveXObject)
		        document.getElementById('listado-aeropuertos').style.left='700px';
	        else
                document.getElementById('listado-aeropuertos').style.left='275px';
        }
    }
}

function EnviaAeropuerto(descripcion)
{        
    var control=document.getElementById('hcontrol').value;
    if (control!=null)
    {
        if(descripcion!='')
        {
            if (control=='origen')
                document.getElementById('origen').value=descripcion;             
            if (control=='destino')
                document.getElementById('destino').value=descripcion;
        }
        document.getElementById('listado-aeropuertos').style.display='none';
        document.getElementById('tipodestinos').innerHTML='Destinos frecuentes:';
        document.getElementById('PaisesLetra').style.display='none';
        document.getElementById('AeropuertosPais').style.display='none';
        document.getElementById('lista-aeropuertos-nacionales1').style.display='block';
        document.getElementById('lista-aeropuertos-nacionales2').style.display='block';
    }
}

function Carga_Paises_Letra(letra)
{
    if (window.XMLHttpRequest) //Non-IE Browsers
		GlobalAjaxObjectVal = new XMLHttpRequest(); //Global Variable
	else if(window.ActiveXObject) //IE Browsers
		GlobalAjaxObjectVal = new ActiveXObject("Msxml2.XMLHTTP");  //Global Variable
	else 
	{ //Your browsers is not compatible with AJAX
		alert('Your browser is not supported.')
		return; //exit
	}
	//Initialized the Ajax object to access the URL
    url="../../Paises_Letra.aspx?letra=" + letra;

	var url_encode= encodeURI(url);
	
	GlobalAjaxObjectVal.open("GET", url_encode );
	//GlobalAjaxObject.open("POST", document.formulariohome);
	//Sets the function that is run many times.
    GlobalAjaxObjectVal.onreadystatechange = mostrar_paises_letra;
	//Executes the request
	GlobalAjaxObjectVal.send(null);
}

function mostrar_paises_letra()
{
    if(GlobalAjaxObjectVal.readyState == 4)
	{
		if(GlobalAjaxObjectVal.status == 200)
		{ //200 = success
			text = GlobalAjaxObjectVal.responseText;
			var element = document.getElementById('PaisesLetra');
			element.innerHTML=text;
			document.getElementById('tipodestinos').innerHTML='Destinos por paises';
			document.getElementById('PaisesLetra').style.display='block';
			document.getElementById('lista-aeropuertos-nacionales1').style.display='none';
			document.getElementById('lista-aeropuertos-nacionales2').style.display='none';
			document.getElementById('AeropuertosPais').style.display='none';
	    }
	}
}

function Carga_Aeropuertos_Pais(pais)
{
    if (window.XMLHttpRequest) //Non-IE Browsers
		GlobalAjaxObjectVal = new XMLHttpRequest(); //Global Variable
	else if(window.ActiveXObject) //IE Browsers
		GlobalAjaxObjectVal = new ActiveXObject("Msxml2.XMLHTTP");  //Global Variable
	else 
	{ //Your browsers is not compatible with AJAX
		alert('Your browser is not supported.')
		return; //exit
	}
	
	document.getElementById('tipodestinos').innerHTML='destinos por paises - ' + pais;
	
	//Initialized the Ajax object to access the URL
    url="../../Aeropuertos_Pais.aspx?pais=" + pais;

	var url_encode= encodeURI(url);
	
	GlobalAjaxObjectVal.open("GET", url_encode );
	//GlobalAjaxObject.open("POST", document.formulariohome);
	//Sets the function that is run many times.
    GlobalAjaxObjectVal.onreadystatechange = mostrar_aeropuertos_pais;
	//Executes the request
	GlobalAjaxObjectVal.send(null);
}

function mostrar_aeropuertos_pais()
{
    if(GlobalAjaxObjectVal.readyState == 4)
	{
		if(GlobalAjaxObjectVal.status == 200)
		{ //200 = success
			text = GlobalAjaxObjectVal.responseText;
			var element = document.getElementById('AeropuertosPais');
			element.innerHTML=text;
			document.getElementById('AeropuertosPais').style.display='block';
	    }
	}
}
function cerrar_calendario(container)
{
    if (document.getElementById(container)!=null)
    {
        if (document.getElementById(container).style.display=='block')
        {
            document.getElementById(container).style.display='none';
        }
    }
}

/* Añadido en referencia al radio button de idayvuelta/soloida */
function selecciona_idavuelta(){
    if(document.getElementById('tipo_vuelo_ida').checked)
    {
        document.getElementById("div_fecha_vuelta").style.display='none';    
        document.getElementById("div_fecha_vuelta2").style.display='none';    
        document.getElementById("regreso").value="";    
    }
    else
    {
        document.getElementById("div_fecha_vuelta").style.display='block';    
        document.getElementById("div_fecha_vuelta2").style.display='block';    
    }
}

function abrir_enlace(tipo,destino)
{
    //pageTracker._trackEvent("LINK_BUILDING", tipo, destino, 0);
    pageTracker._trackPageview("/tvtrip.aspx?destino=" + destino );
}


